2012-01-24 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* Spdylay - SPDY Library
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef SPDYLAY_FRAME_H
|
|
|
|
#define SPDYLAY_FRAME_H
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2012-01-25 13:31:28 +01:00
|
|
|
#include <spdylay/spdylay.h>
|
2012-01-24 14:02:24 +01:00
|
|
|
#include "spdylay_zlib.h"
|
|
|
|
#include "spdylay_buffer.h"
|
|
|
|
|
2012-01-25 13:35:48 +01:00
|
|
|
#define SPDYLAY_STREAM_ID_MASK 0x7fffffff
|
|
|
|
#define SPDYLAY_LENGTH_MASK 0xffffff
|
|
|
|
#define SPDYLAY_VERSION_MASK 0x7fff
|
2012-02-24 17:47:37 +01:00
|
|
|
#define SPDYLAY_DELTA_WINDOW_SIZE_MASK 0x7fffffff
|
2012-03-08 15:49:26 +01:00
|
|
|
#define SPDYLAY_SETTINGS_ID_MASK 0xffffff
|
2012-01-25 13:35:48 +01:00
|
|
|
|
2012-02-22 15:58:33 +01:00
|
|
|
/* The length of DATA frame payload. */
|
|
|
|
#define SPDYLAY_DATA_PAYLOAD_LENGTH 4096
|
2012-01-26 17:17:40 +01:00
|
|
|
|
2012-01-27 10:21:14 +01:00
|
|
|
/* The number of bytes of frame header. */
|
|
|
|
#define SPDYLAY_FRAME_HEAD_LENGTH 8
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2012-02-16 12:54:30 +01:00
|
|
|
* Packs SYN_STREAM frame |frame| in wire format and store it in
|
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr| bytes.
|
|
|
|
* The |*nvbuf_ptr| is used to store inflated name/value pairs in wire
|
|
|
|
* format temporarily. Its length is |*nvbuflen_ptr| bytes. This
|
|
|
|
* function expands |*buf_ptr| and |*nvbuf_ptr| as necessary to store
|
|
|
|
* frame and name/value pairs. When expansion occurred, memory
|
|
|
|
* previously pointed by |*buf_ptr| and |*nvbuf_ptr| is freed.
|
|
|
|
* |*buf_ptr|, |*buflen_ptr|, |*nvbuf_ptr| and |*nvbuflen_ptr| are
|
|
|
|
* updated accordingly.
|
|
|
|
*
|
2012-02-21 15:56:51 +01:00
|
|
|
* frame->hd.length is assigned after length is determined during
|
|
|
|
* packing process.
|
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* returns one of the following negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The deflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
|
|
|
ssize_t spdylay_frame_pack_syn_stream(uint8_t **buf_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2012-01-24 14:02:24 +01:00
|
|
|
spdylay_syn_stream *frame,
|
|
|
|
spdylay_zlib *deflater);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpacks SYN_STREAM frame byte sequence into |frame|. Header is
|
|
|
|
* given in head and headlen. In spdy/2 spec, headlen is 8
|
|
|
|
* bytes. |payload| is the data after length field of the header.
|
2012-02-16 14:01:34 +01:00
|
|
|
*
|
|
|
|
* |inflatebuf| is used to buffer name/value pairs while inflating
|
|
|
|
* them using |inflater|. The caller must reset |inflatebuf| before
|
|
|
|
* the call. |*nvbuf_ptr|, |*nvbuflen_ptr| is used to store temporal
|
|
|
|
* inflated name/value pairs. This function expands |*nvbuf_ptr| as
|
|
|
|
* necessary and updates these variables.
|
|
|
|
*
|
2012-02-21 15:56:51 +01:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The inflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_syn_stream(spdylay_syn_stream *frame,
|
2012-02-16 14:01:34 +01:00
|
|
|
spdylay_buffer *inflatebuf,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2012-01-24 14:02:24 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen,
|
|
|
|
spdylay_zlib *inflater);
|
|
|
|
|
2012-01-25 13:31:28 +01:00
|
|
|
/*
|
|
|
|
* Packs SYN_REPLY frame |frame| in wire frame format and store it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr| bytes.
|
|
|
|
* The |*nvbuf_ptr| is used to store inflated name/value pairs in wire
|
|
|
|
* format temporarily. Its length is |*nvbuflen_ptr| bytes. This
|
|
|
|
* function expands |*buf_ptr| and |*nvbuf_ptr| as necessary to store
|
|
|
|
* frame and name/value pairs. When expansion occurred, memory
|
|
|
|
* previously pointed by |*buf_ptr| and |*nvbuf_ptr| is freed.
|
|
|
|
* |*buf_ptr|, |*buflen_ptr|, |*nvbuf_ptr| and |*nvbuflen_ptr| are
|
2012-02-21 15:56:51 +01:00
|
|
|
* updated accordingly.
|
|
|
|
*
|
|
|
|
* frame->hd.length is assigned after length is determined during
|
|
|
|
* packing process.
|
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* returns one of the following negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The deflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-25 13:31:28 +01:00
|
|
|
*/
|
|
|
|
ssize_t spdylay_frame_pack_syn_reply(uint8_t **buf_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2012-01-25 13:31:28 +01:00
|
|
|
spdylay_syn_reply *frame,
|
|
|
|
spdylay_zlib *deflater);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2012-02-16 14:01:34 +01:00
|
|
|
* Unpacks SYN_REPLY frame byte sequence into |frame|.
|
|
|
|
*
|
|
|
|
* |inflatebuf| is used to buffer name/value pairs while inflating
|
|
|
|
* them using |inflater|. The caller must reset |inflatebuf| before
|
|
|
|
* the call. |*nvbuf_ptr|, |*nvbuflen_ptr| is used to store temporal
|
|
|
|
* inflated name/value pairs. This function expands |*nvbuf_ptr| as
|
|
|
|
* necessary and updates these variables.
|
|
|
|
*
|
2012-02-21 15:56:51 +01:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The inflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_syn_reply(spdylay_syn_reply *frame,
|
2012-02-16 14:01:34 +01:00
|
|
|
spdylay_buffer *inflatebuf,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2012-01-24 14:02:24 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen,
|
|
|
|
spdylay_zlib *inflater);
|
|
|
|
|
2012-01-27 11:35:05 +01:00
|
|
|
/*
|
|
|
|
* Packs PING frame |frame| in wire format and store it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
|
|
|
* length. This function expands |*buf_ptr| as necessary to store
|
2012-02-21 15:56:51 +01:00
|
|
|
* given |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-27 11:35:05 +01:00
|
|
|
*/
|
2012-02-16 12:54:30 +01:00
|
|
|
ssize_t spdylay_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
spdylay_ping *frame);
|
2012-01-27 11:35:05 +01:00
|
|
|
|
|
|
|
/*
|
2012-02-21 15:56:51 +01:00
|
|
|
* Unpacks PING wire format into |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
2012-01-27 11:35:05 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_ping(spdylay_ping *frame,
|
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen);
|
|
|
|
|
2012-01-28 11:22:38 +01:00
|
|
|
/*
|
|
|
|
* Packs GOAWAY frame |frame | in wire format and store it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
|
|
|
* length. This function expands |*buf_ptr| as necessary to store
|
2012-02-21 15:56:51 +01:00
|
|
|
* given |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-28 11:22:38 +01:00
|
|
|
*/
|
2012-02-16 12:54:30 +01:00
|
|
|
ssize_t spdylay_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
spdylay_goaway *frame);
|
2012-01-28 11:22:38 +01:00
|
|
|
|
|
|
|
/*
|
2012-02-21 15:56:51 +01:00
|
|
|
* Unpacks GOAWAY wire format into |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
2012-01-28 11:22:38 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_goaway(spdylay_goaway *frame,
|
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen);
|
|
|
|
|
2012-01-27 10:21:14 +01:00
|
|
|
/*
|
|
|
|
* Packs HEADERS frame |frame| in wire format and store it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr| bytes.
|
|
|
|
* The |*nvbuf_ptr| is used to store inflated name/value pairs in wire
|
|
|
|
* format temporarily. Its length is |*nvbuflen_ptr| bytes. This
|
|
|
|
* function expands |*buf_ptr| and |*nvbuf_ptr| as necessary to store
|
|
|
|
* frame and name/value pairs. When expansion occurred, memory
|
|
|
|
* previously pointed by |*buf_ptr| and |*nvbuf_ptr| is freed.
|
|
|
|
* |*buf_ptr|, |*buflen_ptr|, |*nvbuf_ptr| and |*nvbuflen_ptr| are
|
2012-02-21 15:56:51 +01:00
|
|
|
* updated accordingly.
|
|
|
|
*
|
|
|
|
* frame->hd.length is assigned after length is determined during
|
|
|
|
* packing process.
|
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* returns one of the following negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The deflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-27 10:21:14 +01:00
|
|
|
*/
|
2012-02-16 12:54:30 +01:00
|
|
|
ssize_t spdylay_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr,
|
2012-01-27 10:21:14 +01:00
|
|
|
spdylay_headers *frame,
|
|
|
|
spdylay_zlib *deflater);
|
|
|
|
|
|
|
|
/*
|
2012-02-16 14:01:34 +01:00
|
|
|
* Unpacks HEADERS wire format into |frame|.
|
|
|
|
*
|
|
|
|
* |inflatebuf| is used to buffer name/value pairs while inflating
|
|
|
|
* them using |inflater|. The caller must reset |inflatebuf| before
|
|
|
|
* the call. |*nvbuf_ptr|, |*nvbuflen_ptr| is used to store temporal
|
|
|
|
* inflated name/value pairs. This function expands |*nvbuf_ptr| as
|
|
|
|
* necessary and updates these variables.
|
|
|
|
*
|
2012-02-21 15:56:51 +01:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2012-02-24 17:17:03 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The inflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-27 10:21:14 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_headers(spdylay_headers *frame,
|
2012-02-16 14:01:34 +01:00
|
|
|
spdylay_buffer *inflatebuf,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2012-01-27 10:21:14 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen,
|
|
|
|
spdylay_zlib *inflater);
|
2012-01-27 11:35:05 +01:00
|
|
|
|
2012-01-25 13:31:28 +01:00
|
|
|
/*
|
|
|
|
* Packs RST_STREAM frame |frame| in wire frame format and store it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
|
|
|
* length. This function expands |*buf_ptr| as necessary to store
|
2012-02-24 17:47:37 +01:00
|
|
|
* given |frame|. In spdy/2 spec, RST_STREAM wire format is always 16
|
2012-02-21 15:56:51 +01:00
|
|
|
* bytes long.
|
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* returns one of the following negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-25 13:31:28 +01:00
|
|
|
*/
|
2012-02-16 12:54:30 +01:00
|
|
|
ssize_t spdylay_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
2012-01-25 13:31:28 +01:00
|
|
|
spdylay_rst_stream *frame);
|
|
|
|
|
|
|
|
/*
|
2012-02-21 15:56:51 +01:00
|
|
|
* Unpacks RST_STREAM frame byte sequence into |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
2012-01-25 13:31:28 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_rst_stream(spdylay_rst_stream *frame,
|
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen);
|
|
|
|
|
2012-02-24 17:47:37 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Packs WINDOW_UPDATE frame |frame| in wire frame format and store it
|
|
|
|
* in |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
|
|
|
* length. This function expands |*buf_ptr| as necessary to store
|
|
|
|
* given |frame|. In SPDY/3 spec, WINDOW_UPDATE wire format is always 16
|
|
|
|
* bytes long.
|
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* returns one of the following negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
|
|
|
ssize_t spdylay_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
spdylay_window_update *frame);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_window_update(spdylay_window_update *frame,
|
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-01-31 16:26:26 +01:00
|
|
|
/*
|
|
|
|
* Packs SETTINGS frame |frame| in wire format and store it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
|
|
|
* length. This function expands |*buf_ptr| as necessary to store
|
2012-02-21 15:56:51 +01:00
|
|
|
* given |frame|.
|
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* returns one of the following negative error codes:
|
|
|
|
*
|
2012-03-08 15:49:26 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-31 16:26:26 +01:00
|
|
|
*/
|
2012-02-16 12:54:30 +01:00
|
|
|
ssize_t spdylay_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
spdylay_settings *frame);
|
2012-01-31 16:26:26 +01:00
|
|
|
|
|
|
|
/*
|
2012-02-21 15:56:51 +01:00
|
|
|
* Unpacks SETTINGS wire format into |frame|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2012-03-08 15:49:26 +01:00
|
|
|
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
|
|
* The version is not supported.
|
2012-02-21 15:56:51 +01:00
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-31 16:26:26 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_unpack_settings(spdylay_settings *frame,
|
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* Returns number of bytes to pack name/value pairs |nv|. This
|
2012-02-24 15:05:49 +01:00
|
|
|
* function expects |nv| is sorted in ascending order of key.
|
|
|
|
* |len_size| is the number of bytes in length of name/value pair and
|
|
|
|
* it must be 2 or 4.
|
|
|
|
*
|
|
|
|
* This function can handles duplicate keys and concatenation of thier
|
2012-02-21 15:56:51 +01:00
|
|
|
* values with '\0'.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
2012-02-24 15:05:49 +01:00
|
|
|
size_t spdylay_frame_count_nv_space(char **nv, size_t len_size);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Packs name/value pairs in |nv| in |buf|. |buf| must have at least
|
2012-02-24 15:05:49 +01:00
|
|
|
* spdylay_frame_count_nv_space(nv) bytes. |len_size| is the number
|
|
|
|
* of bytes in length of name/value pair and it must be 2 or 4.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
2012-02-24 15:05:49 +01:00
|
|
|
ssize_t spdylay_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-03-01 15:52:15 +01:00
|
|
|
/*
|
|
|
|
* Packs name/value pairs in |nv| in |*buf_ptr| with offset
|
|
|
|
* |nv_offset|. It means first byte of packed name/value pairs is
|
|
|
|
* stored in |*buf_ptr|+|nv_offset|. |*buf_ptr| and |*nvbuf_ptr| are
|
|
|
|
* expanded as necessary.
|
|
|
|
*
|
|
|
|
* This function returns the number of the bytes for the frame
|
|
|
|
* containing this name/value pairs if it succeeds, or one of the
|
|
|
|
* following negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The deflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
|
|
|
ssize_t spdylay_frame_alloc_pack_nv(uint8_t **buf_ptr,
|
|
|
|
size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
|
|
|
char **nv, size_t nv_offset,
|
|
|
|
size_t len_size,
|
|
|
|
spdylay_zlib *deflater);
|
|
|
|
|
2012-02-04 15:09:03 +01:00
|
|
|
/*
|
|
|
|
* Counts number of name/value pair in |in| and computes length of
|
|
|
|
* buffers to store unpacked name/value pair and store them in
|
2012-02-24 15:05:49 +01:00
|
|
|
* |*num_nv_ptr| and |*buf_size_ptr| respectively. |len_size| is the
|
|
|
|
* number of bytes in length of name/value pair and it must be 2 or
|
|
|
|
* 4. We use folloing data structure in |*buf_size_ptr|. First part
|
|
|
|
* of the data is array of pointer to name/value pair. Supporse the
|
|
|
|
* buf pointer points to the data region and N is the number of
|
|
|
|
* name/value pair. First (N*2+1)*sizeof(char*) bytes contain array
|
|
|
|
* of pointer to name/value pair and terminating NULL. Each pointer
|
|
|
|
* to name/value pair points to the string in remaining data. For
|
|
|
|
* each name/value pair, the name is copied to the remaining data with
|
|
|
|
* terminating NULL character. The value is also copied to the
|
|
|
|
* position after the data with terminating NULL character. The
|
|
|
|
* corresponding index is assigned to these pointers. If the value
|
|
|
|
* contains multiple values (delimited by single NULL), for each such
|
|
|
|
* data, corresponding index is assigned to name/value pointers. In
|
|
|
|
* this case, the name string is reused.
|
2012-02-04 15:09:03 +01:00
|
|
|
*
|
|
|
|
* With the above stragety, |*buf_size_ptr| is calculated as
|
|
|
|
* (N*2+1)*sizeof(char*)+sum(strlen(name)+1+strlen(value)+1){for each
|
|
|
|
* name/value pair}.
|
|
|
|
*
|
2012-02-21 15:56:51 +01:00
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_INVALID_FRAME
|
|
|
|
* The input data are invalid.
|
2012-02-04 15:09:03 +01:00
|
|
|
*/
|
|
|
|
int spdylay_frame_count_unpack_nv_space
|
2012-02-24 15:05:49 +01:00
|
|
|
(size_t *num_nv_ptr, size_t *buf_size_ptr, const uint8_t *in, size_t inlen,
|
|
|
|
size_t len_size);
|
2012-02-04 15:09:03 +01:00
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* Unpacks name/value pairs in wire format |in| with length |inlen|
|
|
|
|
* and stores them in |*nv_ptr|. Thif function allocates enough
|
2012-02-24 15:05:49 +01:00
|
|
|
* memory to store name/value pairs in |*nv_ptr|. |len_size| is the
|
|
|
|
* number of bytes in length of name/value pair and it must be 2 or 4.
|
2012-02-21 15:56:51 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
2012-02-24 15:05:49 +01:00
|
|
|
int spdylay_frame_unpack_nv(char ***nv_ptr, const uint8_t *in, size_t inlen,
|
|
|
|
size_t len_size);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-03-01 15:52:15 +01:00
|
|
|
/*
|
|
|
|
* Unpacks name/value pairs from buffer |in| with length |inlen|. The
|
|
|
|
* necessary memory area required for output is allocated and its
|
|
|
|
* pointer is assigned to |nv_ptr|. |inflatebuf| is used for inflate
|
|
|
|
* operation. |*nvbuf_ptr| is used for temporarily stored inflated
|
|
|
|
* name/value pair in wire format. It is expanded as necessary.
|
|
|
|
* |len_size| is the number of bytes used in name/value length. It
|
|
|
|
* must be either 2 or 4.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* SPDYLAY_ERR_ZLIB
|
|
|
|
* The inflate operation failed.
|
|
|
|
* SPDYLAY_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
|
|
|
int spdylay_frame_alloc_unpack_nv(char ***nv_ptr,
|
|
|
|
spdylay_buffer *inflatebuf,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
|
|
|
const uint8_t *in, size_t inlen,
|
|
|
|
size_t len_size,
|
|
|
|
spdylay_zlib *inflater);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* Initializes SYN_STREAM frame |frame| with given values. |frame|
|
|
|
|
* takes ownership of |nv|, so caller must not free it. If stream_id
|
|
|
|
* is not assigned yet, it must be 0.
|
|
|
|
*/
|
2012-02-24 15:33:06 +01:00
|
|
|
void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame,
|
|
|
|
uint16_t version, uint8_t flags,
|
2012-01-24 14:02:24 +01:00
|
|
|
int32_t stream_id, int32_t assoc_stream_id,
|
|
|
|
uint8_t pri, char **nv);
|
|
|
|
|
|
|
|
void spdylay_frame_syn_stream_free(spdylay_syn_stream *frame);
|
|
|
|
|
2012-02-24 15:33:06 +01:00
|
|
|
void spdylay_frame_syn_reply_init(spdylay_syn_reply *frame,
|
|
|
|
uint16_t version, uint8_t flags,
|
2012-01-25 13:31:28 +01:00
|
|
|
int32_t stream_id, char **nv);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
void spdylay_frame_syn_reply_free(spdylay_syn_reply *frame);
|
|
|
|
|
2012-02-24 15:33:06 +01:00
|
|
|
void spdylay_frame_ping_init(spdylay_ping *frame, uint16_t version,
|
|
|
|
uint32_t unique_id);
|
2012-01-27 11:35:05 +01:00
|
|
|
|
|
|
|
void spdylay_frame_ping_free(spdylay_ping *frame);
|
|
|
|
|
2012-02-26 08:26:38 +01:00
|
|
|
/*
|
|
|
|
* Initializes GOAWAY frame |frame| with given values. The
|
|
|
|
* |status_code| is ignored if |version| == SPDYLAY_PROTO_SPDY2.
|
|
|
|
*/
|
2012-02-24 15:33:06 +01:00
|
|
|
void spdylay_frame_goaway_init(spdylay_goaway *frame, uint16_t version,
|
2012-02-26 08:26:38 +01:00
|
|
|
int32_t last_good_stream_id,
|
|
|
|
uint32_t status_code);
|
2012-01-28 11:22:38 +01:00
|
|
|
|
|
|
|
void spdylay_frame_goaway_free(spdylay_goaway *frame);
|
|
|
|
|
2012-02-24 15:33:06 +01:00
|
|
|
void spdylay_frame_headers_init(spdylay_headers *frame, uint16_t version,
|
|
|
|
uint8_t flags,
|
2012-01-27 10:21:14 +01:00
|
|
|
int32_t stream_id, char **nv);
|
|
|
|
|
|
|
|
void spdylay_frame_headers_free(spdylay_headers *frame);
|
|
|
|
|
2012-01-25 13:31:28 +01:00
|
|
|
void spdylay_frame_rst_stream_init(spdylay_rst_stream *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version,
|
2012-01-25 13:31:28 +01:00
|
|
|
int32_t stream_id, uint32_t status_code);
|
|
|
|
|
|
|
|
void spdylay_frame_rst_stream_free(spdylay_rst_stream *frame);
|
|
|
|
|
2012-02-24 17:47:37 +01:00
|
|
|
void spdylay_frame_window_update_init(spdylay_window_update *frame,
|
|
|
|
uint16_t version,
|
|
|
|
int32_t stream_id,
|
|
|
|
int32_t delta_window_size);
|
|
|
|
|
|
|
|
void spdylay_frame_window_update_free(spdylay_window_update *frame);
|
|
|
|
|
2012-01-31 16:26:26 +01:00
|
|
|
/*
|
|
|
|
* Initializes SETTINGS frame |frame| with given values. |frame| takes
|
|
|
|
* ownership of |iv|, so caller must not free it.
|
|
|
|
*/
|
2012-02-24 15:33:06 +01:00
|
|
|
void spdylay_frame_settings_init(spdylay_settings *frame,
|
|
|
|
uint16_t version, uint8_t flags,
|
2012-01-31 16:26:26 +01:00
|
|
|
spdylay_settings_entry *iv, size_t niv);
|
|
|
|
|
|
|
|
void spdylay_frame_settings_free(spdylay_settings *frame);
|
|
|
|
|
2012-01-26 17:17:40 +01:00
|
|
|
void spdylay_frame_data_init(spdylay_data *frame, int32_t stream_id,
|
2012-02-23 15:22:58 +01:00
|
|
|
uint8_t flags,
|
|
|
|
const spdylay_data_provider *data_prd);
|
2012-01-26 17:17:40 +01:00
|
|
|
|
|
|
|
void spdylay_frame_data_free(spdylay_data *frame);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* Returns 1 if the first byte of this frame indicates it is a control
|
|
|
|
* frame.
|
|
|
|
*/
|
|
|
|
int spdylay_frame_is_ctrl_frame(uint8_t first_byte);
|
|
|
|
|
|
|
|
/*
|
2012-02-04 15:09:03 +01:00
|
|
|
* Deallocates memory of name/value pair |nv|.
|
2012-01-24 14:02:24 +01:00
|
|
|
*/
|
2012-02-04 15:09:03 +01:00
|
|
|
void spdylay_frame_nv_del(char **nv);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-01-26 17:17:40 +01:00
|
|
|
/*
|
|
|
|
* Makes a deep copy of |nv| and returns the copy. This function
|
2012-02-04 15:09:03 +01:00
|
|
|
* returns the pointer to the copy if it succeeds, or NULL. To free
|
|
|
|
* allocated memory, use spdylay_frame_nv_del().
|
2012-01-26 17:17:40 +01:00
|
|
|
*/
|
|
|
|
char** spdylay_frame_nv_copy(const char **nv);
|
|
|
|
|
2012-01-27 16:09:01 +01:00
|
|
|
/*
|
|
|
|
* Sorts |nv| in the ascending order of name.
|
|
|
|
*/
|
|
|
|
void spdylay_frame_nv_sort(char **nv);
|
|
|
|
|
2012-02-15 15:54:42 +01:00
|
|
|
/*
|
|
|
|
* Makes names in |nv| lower cased.
|
|
|
|
*/
|
|
|
|
void spdylay_frame_nv_downcase(char **nv);
|
|
|
|
|
2012-02-28 15:38:40 +01:00
|
|
|
/*
|
|
|
|
* This function first makes a copy of |nv| using
|
|
|
|
* spdylay_frame_nv_copy(). If it succeeds, then call
|
|
|
|
* spdylay_frame_nv_downcase() and spdylay_frame_nv_sort() with the
|
|
|
|
* copied name/value pairs.
|
|
|
|
*
|
|
|
|
* This function returns the copied name/value pairs if it succeeds,
|
|
|
|
* or NULL.
|
|
|
|
*/
|
|
|
|
char** spdylay_frame_nv_norm_copy(const char **nv);
|
|
|
|
|
2012-03-06 15:43:45 +01:00
|
|
|
/*
|
|
|
|
* Translates the |nv| in SPDY/3 header names into SPDY/2.
|
|
|
|
*/
|
|
|
|
void spdylay_frame_nv_3to2(char **nv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translates the |nv| in SPDY/2 header names into SPDY/3.
|
|
|
|
*/
|
|
|
|
void spdylay_frame_nv_2to3(char **nv);
|
|
|
|
|
2012-01-31 16:26:26 +01:00
|
|
|
/*
|
|
|
|
* Makes copy of |iv| and return the copy. The |niv| is the number of
|
|
|
|
* entries in |iv|. This function returns the pointer to the copy if
|
|
|
|
* it succeeds, or NULL.
|
|
|
|
*/
|
|
|
|
spdylay_settings_entry* spdylay_frame_iv_copy(const spdylay_settings_entry *iv,
|
|
|
|
size_t niv);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
#endif /* SPDYLAY_FRAME_H */
|