2012-01-24 13:02:24 +00:00
|
|
|
/*
|
2014-03-30 10:09:21 +00:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-01-24 13:02:24 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-07-12 15:19:03 +00:00
|
|
|
#ifndef NGHTTP2_FRAME_H
|
|
|
|
#define NGHTTP2_FRAME_H
|
2012-01-24 13:02:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2013-07-12 15:19:03 +00:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2013-07-19 15:08:14 +00:00
|
|
|
#include "nghttp2_hd.h"
|
2014-03-10 16:47:38 +00:00
|
|
|
#include "nghttp2_buf.h"
|
2013-07-15 12:45:59 +00:00
|
|
|
|
2013-10-27 14:09:10 +00:00
|
|
|
#define NGHTTP2_FRAME_LENGTH_MASK ((1 << 14) - 1)
|
|
|
|
#define NGHTTP2_STREAM_ID_MASK ((1u << 31) - 1)
|
2014-03-25 17:04:24 +00:00
|
|
|
#define NGHTTP2_PRI_GROUP_ID_MASK ((1u << 31) - 1)
|
2013-10-27 14:09:10 +00:00
|
|
|
#define NGHTTP2_PRIORITY_MASK ((1u << 31) - 1)
|
|
|
|
#define NGHTTP2_WINDOW_SIZE_INCREMENT_MASK ((1u << 31) - 1)
|
|
|
|
#define NGHTTP2_SETTINGS_ID_MASK ((1 << 24) - 1)
|
|
|
|
|
2014-03-13 13:11:02 +00:00
|
|
|
/* The number of bytes of frame header. */
|
|
|
|
#define NGHTTP2_FRAME_HDLEN 8
|
|
|
|
|
2014-04-02 11:33:01 +00:00
|
|
|
#define NGHTTP2_MAX_PAYLOADLEN 16383
|
|
|
|
/* The one frame buffer length for tranmission. We may use several of
|
2014-06-07 09:15:36 +00:00
|
|
|
them to support CONTINUATION. To account for Pad Length field, we
|
|
|
|
allocate extra 1 byte, which saves extra large memcopying. */
|
2014-04-02 11:33:01 +00:00
|
|
|
#define NGHTTP2_FRAMEBUF_CHUNKLEN \
|
2014-06-07 09:15:36 +00:00
|
|
|
(NGHTTP2_FRAME_HDLEN + 1 + NGHTTP2_MAX_PAYLOADLEN)
|
2012-01-25 12:35:48 +00:00
|
|
|
|
2014-04-02 11:33:01 +00:00
|
|
|
/* The maximum length of DATA frame payload. */
|
2014-04-06 08:56:48 +00:00
|
|
|
#define NGHTTP2_DATA_PAYLOADLEN 4096
|
2012-01-27 09:21:14 +00:00
|
|
|
|
2014-02-06 13:06:42 +00:00
|
|
|
/* The number of bytes for each SETTINGS entry */
|
2014-06-07 07:37:29 +00:00
|
|
|
#define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 6
|
2014-02-06 13:06:42 +00:00
|
|
|
|
2014-05-12 12:28:49 +00:00
|
|
|
/* The maximum header table size in SETTINGS_HEADER_TABLE_SIZE */
|
|
|
|
#define NGHTTP2_MAX_HEADER_TABLE_SIZE ((1u << 31) - 1)
|
|
|
|
|
2014-05-22 12:41:43 +00:00
|
|
|
/* Length of priority related fields in HEADERS/PRIORITY frames */
|
|
|
|
#define NGHTTP2_PRIORITY_SPECLEN 5
|
2014-05-22 12:36:12 +00:00
|
|
|
|
|
|
|
/* Length of fixed part in ALTSVC frame, that is the sum of fields of
|
2014-06-07 10:10:09 +00:00
|
|
|
Max-Age, Port and Proto-Len. */
|
|
|
|
#define NGHTTP2_ALTSVC_FIXED_PARTLEN 7
|
2014-05-22 12:36:12 +00:00
|
|
|
|
2014-06-09 14:16:54 +00:00
|
|
|
/* Minimum length of ALTSVC extension frame payload.
|
|
|
|
NGHTTP2_ALTSVC_FIXED_PARTLEN + Host-Len. */
|
2014-06-07 10:10:09 +00:00
|
|
|
#define NGHTTP2_ALTSVC_MINLEN 8
|
2014-05-22 12:36:12 +00:00
|
|
|
|
2013-07-15 12:45:59 +00:00
|
|
|
/* Category of frames. */
|
2012-03-29 14:59:51 +00:00
|
|
|
typedef enum {
|
2013-07-15 12:45:59 +00:00
|
|
|
/* non-DATA frame */
|
|
|
|
NGHTTP2_CAT_CTRL,
|
2012-03-29 14:59:51 +00:00
|
|
|
/* DATA frame */
|
2013-07-15 12:45:59 +00:00
|
|
|
NGHTTP2_CAT_DATA
|
2013-07-12 15:19:03 +00:00
|
|
|
} nghttp2_frame_category;
|
2012-03-29 14:59:51 +00:00
|
|
|
|
2014-06-09 14:16:54 +00:00
|
|
|
/* Union of extension frame payload */
|
|
|
|
typedef union {
|
|
|
|
nghttp2_ext_altsvc altsvc;
|
|
|
|
} nghttp2_ext_frame_payload;
|
|
|
|
|
2012-03-29 14:59:51 +00:00
|
|
|
/**
|
|
|
|
* @struct
|
2014-01-27 12:22:33 +00:00
|
|
|
*
|
|
|
|
* The DATA frame used in the library privately. It has the following
|
|
|
|
* members:
|
2012-03-29 14:59:51 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2013-07-15 12:45:59 +00:00
|
|
|
nghttp2_frame_hd hd;
|
2013-12-06 14:17:38 +00:00
|
|
|
/**
|
|
|
|
* The data to be sent for this DATA frame.
|
|
|
|
*/
|
|
|
|
nghttp2_data_provider data_prd;
|
2014-02-07 14:22:17 +00:00
|
|
|
/**
|
2014-06-07 09:15:36 +00:00
|
|
|
* The number of bytes added as padding. This includes Pad Length
|
|
|
|
* field (1 byte).
|
2014-02-07 14:22:17 +00:00
|
|
|
*/
|
|
|
|
size_t padlen;
|
2012-03-29 14:59:51 +00:00
|
|
|
/**
|
|
|
|
* The flag to indicate whether EOF was reached or not. Initially
|
2013-07-15 12:45:59 +00:00
|
|
|
* |eof| is 0. It becomes 1 after all data were read. This is used
|
|
|
|
* exclusively by nghttp2 library and not in the spec.
|
2012-03-29 14:59:51 +00:00
|
|
|
*/
|
|
|
|
uint8_t eof;
|
2014-01-27 12:22:33 +00:00
|
|
|
} nghttp2_private_data;
|
2012-03-29 14:59:51 +00:00
|
|
|
|
2013-07-15 12:45:59 +00:00
|
|
|
int nghttp2_frame_is_data_frame(uint8_t *head);
|
|
|
|
|
|
|
|
void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd);
|
|
|
|
|
|
|
|
void nghttp2_frame_unpack_frame_hd(nghttp2_frame_hd *hd, const uint8_t* buf);
|
2012-03-26 14:19:58 +00:00
|
|
|
|
2014-03-25 17:04:24 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of priority field depending on the |flags|. If
|
|
|
|
* |flags| has neither NGHTTP2_FLAG_PRIORITY_GROUP nor
|
|
|
|
* NGHTTP2_FLAG_PRIORITY_DEPENDENCY set, return 0.
|
|
|
|
*/
|
|
|
|
size_t nghttp2_frame_priority_len(uint8_t flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Packs the |pri_spec| in |buf|. This function assumes |buf| has
|
|
|
|
* enough space for serialization.
|
|
|
|
*/
|
|
|
|
void nghttp2_frame_pack_priority_spec(uint8_t *buf,
|
|
|
|
const nghttp2_priority_spec *pri_spec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unpacks the priority specification from payload |payload| of length
|
|
|
|
* |payloadlen| to |pri_spec|. The |flags| is used to determine what
|
|
|
|
* kind of priority specification is in |payload|. This function
|
|
|
|
* assumes the |payload| contains whole priority specification.
|
|
|
|
*/
|
|
|
|
void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
|
|
|
|
uint8_t flags,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2014-01-16 14:41:13 +00:00
|
|
|
/*
|
|
|
|
* Returns the offset from the HEADERS frame payload where the
|
|
|
|
* compressed header block starts. The frame payload does not include
|
|
|
|
* frame header.
|
|
|
|
*/
|
|
|
|
size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
|
|
|
|
|
2012-01-24 13:02:24 +00:00
|
|
|
/*
|
2014-03-13 13:11:02 +00:00
|
|
|
* Packs HEADERS frame |frame| in wire format and store it in |bufs|.
|
|
|
|
* This function expands |bufs| as necessary to store frame.
|
2012-02-16 11:54:30 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
2014-02-08 15:35:21 +00:00
|
|
|
*
|
2012-02-21 14:56:51 +00:00
|
|
|
* frame->hd.length is assigned after length is determined during
|
2014-05-06 09:02:26 +00:00
|
|
|
* packing process. CONTINUATION frames are also serialized in this
|
2014-03-13 13:11:02 +00:00
|
|
|
* function. This function does not handle padding.
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* This function returns 0 if it succeeds, or returns one of the
|
2014-02-08 15:35:21 +00:00
|
|
|
* following negative error codes:
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2013-07-19 15:08:14 +00:00
|
|
|
* NGHTTP2_ERR_HEADER_COMP
|
2012-02-21 14:56:51 +00:00
|
|
|
* The deflate operation failed.
|
2013-07-12 15:19:03 +00:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-21 14:56:51 +00:00
|
|
|
* Out of memory.
|
2012-01-24 13:02:24 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_headers(nghttp2_bufs *bufs,
|
|
|
|
nghttp2_headers *frame,
|
|
|
|
nghttp2_hd_deflater *deflater);
|
2012-01-24 13:02:24 +00:00
|
|
|
|
2012-05-25 04:49:18 +00:00
|
|
|
/*
|
2014-05-06 09:02:26 +00:00
|
|
|
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
2014-04-14 14:53:54 +00:00
|
|
|
* only unapcks bytes that come before name/value header block and
|
2014-06-07 09:15:36 +00:00
|
|
|
* after possible Pad Length field.
|
2012-05-25 04:49:18 +00:00
|
|
|
*
|
2014-05-06 09:02:26 +00:00
|
|
|
* This function always succeeds and returns 0.
|
2012-05-25 04:49:18 +00:00
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-01-24 13:02:24 +00:00
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Packs PRIORITY frame |frame| in wire format and store it in
|
2014-03-13 13:11:02 +00:00
|
|
|
* |bufs|.
|
|
|
|
*
|
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
2012-03-26 14:19:58 +00:00
|
|
|
*
|
2014-05-06 09:02:26 +00:00
|
|
|
* This function always succeeds and returns 0.
|
2012-01-24 13:02:24 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_priority(nghttp2_bufs *bufs,
|
|
|
|
nghttp2_priority *frame);
|
2012-01-24 13:02:24 +00:00
|
|
|
|
2012-05-25 04:49:18 +00:00
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Unpacks PRIORITY wire format into |frame|.
|
2012-05-25 04:49:18 +00:00
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-01-27 10:35:05 +00:00
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Packs RST_STREAM frame |frame| in wire frame format and store it in
|
2014-03-13 13:11:02 +00:00
|
|
|
* |bufs|.
|
|
|
|
*
|
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2014-05-06 09:02:26 +00:00
|
|
|
* This function always succeeds and returns 0.
|
2012-01-27 10:35:05 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
|
|
|
|
nghttp2_rst_stream *frame);
|
2012-01-27 10:35:05 +00:00
|
|
|
|
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Unpacks RST_STREAM frame byte sequence into |frame|.
|
2012-01-27 10:35:05 +00:00
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-01-28 10:22:38 +00:00
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Packs SETTINGS frame |frame| in wire format and store it in
|
2014-03-13 13:11:02 +00:00
|
|
|
* |bufs|.
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or returns one of the
|
|
|
|
* following negative error codes:
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
|
|
|
* The length of the frame is too large.
|
2012-01-28 10:22:38 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_settings(nghttp2_bufs *bufs, nghttp2_settings *frame);
|
2012-01-28 10:22:38 +00:00
|
|
|
|
2013-08-03 09:05:14 +00:00
|
|
|
/*
|
|
|
|
* Packs the |iv|, which includes |niv| entries, in the |buf|,
|
|
|
|
* assuming the |buf| has at least 8 * |niv| bytes.
|
|
|
|
*
|
|
|
|
* Returns the number of bytes written into the |buf|.
|
|
|
|
*/
|
|
|
|
size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
|
2013-09-09 12:30:39 +00:00
|
|
|
const nghttp2_settings_entry *iv,
|
2013-08-03 09:05:14 +00:00
|
|
|
size_t niv);
|
|
|
|
|
2014-01-26 07:46:18 +00:00
|
|
|
void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
|
|
|
|
const uint8_t *payload);
|
|
|
|
|
2012-01-28 10:22:38 +00:00
|
|
|
/*
|
2014-01-26 07:46:18 +00:00
|
|
|
* Makes a copy of |iv| in frame->settings.iv. The |niv| is assigned
|
|
|
|
* to frame->settings.niv.
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 15:19:03 +00:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-21 14:56:51 +00:00
|
|
|
* Out of memory.
|
2012-01-27 09:21:14 +00:00
|
|
|
*/
|
2014-01-26 07:46:18 +00:00
|
|
|
int nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
|
|
|
|
nghttp2_settings_entry *iv,
|
|
|
|
size_t niv);
|
2014-01-26 06:44:43 +00:00
|
|
|
|
2013-08-03 09:05:14 +00:00
|
|
|
/*
|
|
|
|
* Unpacks SETTINGS payload into |*iv_ptr|. The number of entries are
|
|
|
|
* assigned to the |*niv_ptr|. This function allocates enough memory
|
|
|
|
* to store the result in |*iv_ptr|. The caller is responsible to free
|
|
|
|
* |*iv_ptr| after its use.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
2014-01-26 07:46:18 +00:00
|
|
|
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
|
|
|
|
size_t *niv_ptr,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
2013-08-03 09:05:14 +00:00
|
|
|
|
2013-07-24 16:49:05 +00:00
|
|
|
/*
|
|
|
|
* Packs PUSH_PROMISE frame |frame| in wire format and store it in
|
2014-03-13 13:11:02 +00:00
|
|
|
* |bufs|. This function expands |bufs| as necessary to store
|
|
|
|
* frame.
|
2013-07-24 16:49:05 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
2014-02-15 07:30:43 +00:00
|
|
|
*
|
2013-07-24 16:49:05 +00:00
|
|
|
* frame->hd.length is assigned after length is determined during
|
2014-05-06 09:02:26 +00:00
|
|
|
* packing process. CONTINUATION frames are also serialized in this
|
2014-03-13 13:11:02 +00:00
|
|
|
* function. This function does not handle padding.
|
2013-07-24 16:49:05 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* This function returns 0 if it succeeds, or returns one of the
|
2014-02-15 07:30:43 +00:00
|
|
|
* following negative error codes:
|
|
|
|
*
|
2013-07-24 16:49:05 +00:00
|
|
|
* NGHTTP2_ERR_HEADER_COMP
|
|
|
|
* The deflate operation failed.
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
|
|
|
|
nghttp2_push_promise *frame,
|
|
|
|
nghttp2_hd_deflater *deflater);
|
2013-07-24 16:49:05 +00:00
|
|
|
|
|
|
|
/*
|
2014-05-06 09:02:26 +00:00
|
|
|
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. This
|
|
|
|
* function only unapcks bytes that come before name/value header
|
2014-06-07 09:15:36 +00:00
|
|
|
* block and after possible Pad Length field.
|
2013-07-24 16:49:05 +00:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2014-01-26 07:46:18 +00:00
|
|
|
* NGHTTP2_ERR_PROTO
|
|
|
|
* TODO END_HEADERS flag is not set
|
2013-07-24 16:49:05 +00:00
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-01-27 09:21:14 +00:00
|
|
|
/*
|
2014-03-13 13:11:02 +00:00
|
|
|
* Packs PING frame |frame| in wire format and store it in
|
|
|
|
* |bufs|.
|
|
|
|
*
|
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
2012-03-26 14:19:58 +00:00
|
|
|
*
|
2014-05-06 09:02:26 +00:00
|
|
|
* This function always succeeds and returns 0.
|
2012-01-27 09:21:14 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame);
|
2012-01-27 10:35:05 +00:00
|
|
|
|
2012-05-25 04:49:18 +00:00
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Unpacks PING wire format into |frame|.
|
2012-05-25 04:49:18 +00:00
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-01-25 12:31:28 +00:00
|
|
|
/*
|
2014-03-13 13:11:02 +00:00
|
|
|
* Packs GOAWAY frame |frame| in wire format and store it in |bufs|.
|
|
|
|
* This function expands |bufs| as necessary to store frame.
|
|
|
|
*
|
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2013-07-15 12:45:59 +00:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
2012-02-21 14:56:51 +00:00
|
|
|
*
|
2013-07-12 15:19:03 +00:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-21 14:56:51 +00:00
|
|
|
* Out of memory.
|
2014-03-13 13:11:02 +00:00
|
|
|
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
|
|
|
* The length of the frame is too large.
|
2012-01-25 12:31:28 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame);
|
2012-01-25 12:31:28 +00:00
|
|
|
|
|
|
|
/*
|
2014-03-22 09:59:59 +00:00
|
|
|
* Unpacks GOAWAY wire format into |frame|. The |payload| of length
|
|
|
|
* |payloadlen| contains first 8 bytes of payload. The
|
|
|
|
* |var_gift_payload| of length |var_gift_payloadlen| contains
|
|
|
|
* remaining payload and its buffer is gifted to the function and then
|
|
|
|
* |frame|. The |var_gift_payloadlen| must be freed by
|
|
|
|
* nghttp2_frame_goaway_free().
|
2012-01-25 12:31:28 +00:00
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
|
2014-03-22 09:59:59 +00:00
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen,
|
|
|
|
uint8_t *var_gift_payload,
|
|
|
|
size_t var_gift_payloadlen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpacks GOAWAY wire format into |frame|. This function only exists
|
|
|
|
* for unit test. After allocating buffer for debug data, this
|
|
|
|
* function internally calls nghttp2_frame_unpack_goaway_payload().
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
|
|
|
int nghttp2_frame_unpack_goaway_payload2(nghttp2_goaway *frame,
|
2014-01-26 06:44:43 +00:00
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2012-02-24 16:47:37 +00:00
|
|
|
/*
|
|
|
|
* Packs WINDOW_UPDATE frame |frame| in wire frame format and store it
|
2014-03-13 13:11:02 +00:00
|
|
|
* in |bufs|.
|
2012-02-24 16:47:37 +00:00
|
|
|
*
|
2014-03-13 13:11:02 +00:00
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
|
|
|
*
|
2014-05-06 09:02:26 +00:00
|
|
|
* This function always succeeds and returns 0.
|
2012-02-24 16:47:37 +00:00
|
|
|
*/
|
2014-03-13 13:11:02 +00:00
|
|
|
int nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
|
|
|
|
nghttp2_window_update *frame);
|
2012-02-24 16:47:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
|
|
|
|
*/
|
2014-01-26 06:44:43 +00:00
|
|
|
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen);
|
|
|
|
|
2014-04-01 12:47:51 +00:00
|
|
|
/*
|
|
|
|
* Packs ALTSVC frame |frame| in wire format and store it in |bufs|.
|
|
|
|
* This function expands |bufs| as necessary to store frame.
|
|
|
|
*
|
|
|
|
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
|
|
|
* before calling this function.
|
|
|
|
*
|
2014-06-09 14:16:54 +00:00
|
|
|
* The caller must make sure that frame->payload points to
|
|
|
|
* nghttp2_ext_altsvc object.
|
|
|
|
*
|
2014-04-01 12:47:51 +00:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2014-05-06 09:02:26 +00:00
|
|
|
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
|
|
|
* The length of the frame is too large.
|
2014-04-01 12:47:51 +00:00
|
|
|
*/
|
2014-06-09 14:16:54 +00:00
|
|
|
int nghttp2_frame_pack_altsvc(nghttp2_bufs *bufs, nghttp2_extension *frame);
|
2014-04-01 12:47:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpacks ALTSVC frame byte sequence into |frame|.
|
|
|
|
* The |payload| of length |payloadlen| contains first 8 bytes of
|
|
|
|
* payload. The |var_gift_payload| of length |var_gift_payloadlen|
|
|
|
|
* contains remaining payload and its buffer is gifted to the function
|
|
|
|
* and then |frame|. The |var_gift_payloadlen| must be freed by
|
|
|
|
* nghttp2_frame_altsvc_free().
|
|
|
|
*
|
2014-06-09 14:16:54 +00:00
|
|
|
* The caller must make sure that frame->payload points to
|
|
|
|
* nghttp2_ext_altsvc object.
|
|
|
|
*
|
2014-04-01 12:47:51 +00:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
|
|
|
* The |var_gift_payload| does not contain required data.
|
|
|
|
*/
|
2014-06-09 14:16:54 +00:00
|
|
|
int nghttp2_frame_unpack_altsvc_payload(nghttp2_extension *frame,
|
2014-04-01 12:47:51 +00:00
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen,
|
|
|
|
uint8_t *var_gift_payload,
|
|
|
|
size_t var_gift_payloadlen);
|
|
|
|
|
2012-01-24 13:02:24 +00:00
|
|
|
/*
|
2013-07-19 15:08:14 +00:00
|
|
|
* Initializes HEADERS frame |frame| with given values. |frame| takes
|
|
|
|
* ownership of |nva|, so caller must not free it. If |stream_id| is
|
|
|
|
* not assigned yet, it must be -1.
|
2012-01-24 13:02:24 +00:00
|
|
|
*/
|
2013-07-15 12:45:59 +00:00
|
|
|
void nghttp2_frame_headers_init(nghttp2_headers *frame,
|
2014-03-25 17:04:24 +00:00
|
|
|
uint8_t flags, int32_t stream_id,
|
2014-05-07 14:24:07 +00:00
|
|
|
nghttp2_headers_category cat,
|
2014-03-25 17:04:24 +00:00
|
|
|
const nghttp2_priority_spec *pri_spec,
|
2013-07-19 15:08:14 +00:00
|
|
|
nghttp2_nv *nva, size_t nvlen);
|
2012-01-27 10:35:05 +00:00
|
|
|
|
2013-07-15 12:45:59 +00:00
|
|
|
void nghttp2_frame_headers_free(nghttp2_headers *frame);
|
2012-01-28 10:22:38 +00:00
|
|
|
|
|
|
|
|
2013-07-15 12:45:59 +00:00
|
|
|
void nghttp2_frame_priority_init(nghttp2_priority *frame, int32_t stream_id,
|
2014-03-25 17:04:24 +00:00
|
|
|
const nghttp2_priority_spec *pri_spec);
|
2012-01-27 09:21:14 +00:00
|
|
|
|
2013-07-15 12:45:59 +00:00
|
|
|
void nghttp2_frame_priority_free(nghttp2_priority *frame);
|
2012-01-27 09:21:14 +00:00
|
|
|
|
2013-07-12 15:19:03 +00:00
|
|
|
void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame,
|
2013-07-15 12:45:59 +00:00
|
|
|
int32_t stream_id,
|
|
|
|
nghttp2_error_code error_code);
|
2012-01-25 12:31:28 +00:00
|
|
|
|
2013-07-12 15:19:03 +00:00
|
|
|
void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame);
|
2012-01-25 12:31:28 +00:00
|
|
|
|
2013-07-24 16:49:05 +00:00
|
|
|
/*
|
|
|
|
* Initializes PUSH_PROMISE frame |frame| with given values. |frame|
|
|
|
|
* takes ownership of |nva|, so caller must not free it.
|
|
|
|
*/
|
|
|
|
void nghttp2_frame_push_promise_init(nghttp2_push_promise *frame,
|
|
|
|
uint8_t flags, int32_t stream_id,
|
|
|
|
int32_t promised_stream_id,
|
|
|
|
nghttp2_nv *nva, size_t nvlen);
|
|
|
|
|
|
|
|
void nghttp2_frame_push_promise_free(nghttp2_push_promise *frame);
|
|
|
|
|
2012-01-31 15:26:26 +00:00
|
|
|
/*
|
|
|
|
* Initializes SETTINGS frame |frame| with given values. |frame| takes
|
2012-05-11 13:58:12 +00:00
|
|
|
* ownership of |iv|, so caller must not free it. The |flags| are
|
2013-07-12 15:19:03 +00:00
|
|
|
* bitwise-OR of one or more of nghttp2_settings_flag.
|
2012-01-31 15:26:26 +00:00
|
|
|
*/
|
2013-10-27 10:22:51 +00:00
|
|
|
void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags,
|
2013-07-12 15:19:03 +00:00
|
|
|
nghttp2_settings_entry *iv, size_t niv);
|
2012-01-31 15:26:26 +00:00
|
|
|
|
2013-07-12 15:19:03 +00:00
|
|
|
void nghttp2_frame_settings_free(nghttp2_settings *frame);
|
2012-01-31 15:26:26 +00:00
|
|
|
|
2012-04-05 16:45:39 +00:00
|
|
|
/*
|
2013-07-15 12:45:59 +00:00
|
|
|
* Initializes PING frame |frame| with given values. If the
|
|
|
|
* |opqeue_data| is not NULL, it must point to 8 bytes memory region
|
|
|
|
* of data. The data pointed by |opaque_data| is copied. It can be
|
|
|
|
* NULL. In this case, 8 bytes NULL is used.
|
|
|
|
*/
|
|
|
|
void nghttp2_frame_ping_init(nghttp2_ping *frame, uint8_t flags,
|
|
|
|
const uint8_t *opque_data);
|
|
|
|
|
|
|
|
void nghttp2_frame_ping_free(nghttp2_ping *frame);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes GOAWAY frame |frame| with given values. On success,
|
|
|
|
* this function takes ownership of |opaque_data|, so caller must not
|
|
|
|
* free it. If the |opaque_data_len| is 0, opaque_data could be NULL.
|
2012-04-05 16:45:39 +00:00
|
|
|
*/
|
2013-07-15 12:45:59 +00:00
|
|
|
void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id,
|
|
|
|
nghttp2_error_code error_code,
|
|
|
|
uint8_t *opaque_data, size_t opaque_data_len);
|
|
|
|
|
|
|
|
void nghttp2_frame_goaway_free(nghttp2_goaway *frame);
|
|
|
|
|
|
|
|
void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
|
|
|
|
uint8_t flags,
|
|
|
|
int32_t stream_id,
|
|
|
|
int32_t window_size_increment);
|
2012-04-05 16:45:39 +00:00
|
|
|
|
2013-07-15 12:45:59 +00:00
|
|
|
void nghttp2_frame_window_update_free(nghttp2_window_update *frame);
|
2012-04-05 16:45:39 +00:00
|
|
|
|
2014-04-01 12:47:51 +00:00
|
|
|
/* protocol_id, host and origin must be allocated to the one chunk of
|
|
|
|
memory region and protocol_id must point to it. We only free
|
|
|
|
protocol_id. This means that |protocol_id| is not NULL even if
|
|
|
|
|protocol_id_len| == 0 and |host_len| + |origin_len| > 0. If
|
|
|
|
|protocol_id_len|, |host_len| and |origin_len| are all zero,
|
|
|
|
|protocol_id| can be NULL. */
|
2014-06-09 14:16:54 +00:00
|
|
|
void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id,
|
2014-04-01 12:47:51 +00:00
|
|
|
uint32_t max_age,
|
|
|
|
uint16_t port,
|
|
|
|
uint8_t *protocol_id,
|
|
|
|
size_t protocol_id_len,
|
|
|
|
uint8_t *host, size_t host_len,
|
|
|
|
uint8_t *origin, size_t origin_len);
|
|
|
|
|
2014-06-09 14:16:54 +00:00
|
|
|
/*
|
|
|
|
* Frees resources used by |frame|. This function does not free
|
|
|
|
* frame->payload itself.
|
|
|
|
*/
|
|
|
|
void nghttp2_frame_altsvc_free(nghttp2_extension *frame);
|
2014-04-01 12:47:51 +00:00
|
|
|
|
2014-01-27 14:28:45 +00:00
|
|
|
void nghttp2_frame_data_init(nghttp2_data *frame, nghttp2_private_data *pdata);
|
|
|
|
|
2014-02-07 14:22:17 +00:00
|
|
|
/*
|
2014-06-07 09:15:36 +00:00
|
|
|
* Returns the number of padding bytes after payload. The total
|
|
|
|
* padding length is given in the |padlen|. The returned value does
|
|
|
|
* not include the Pad Length field.
|
2014-02-07 14:22:17 +00:00
|
|
|
*/
|
2014-02-08 15:35:21 +00:00
|
|
|
size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen);
|
2014-02-07 14:22:17 +00:00
|
|
|
|
2014-01-27 13:13:41 +00:00
|
|
|
void nghttp2_frame_private_data_init(nghttp2_private_data *frame,
|
|
|
|
uint8_t flags,
|
|
|
|
int32_t stream_id,
|
|
|
|
const nghttp2_data_provider *data_prd);
|
2012-01-26 16:17:40 +00:00
|
|
|
|
2014-01-27 13:13:41 +00:00
|
|
|
void nghttp2_frame_private_data_free(nghttp2_private_data *frame);
|
2012-01-26 16:17:40 +00:00
|
|
|
|
2012-01-31 15:26:26 +00: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.
|
|
|
|
*/
|
2013-07-12 15:19:03 +00:00
|
|
|
nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
2012-01-31 15:26:26 +00:00
|
|
|
size_t niv);
|
|
|
|
|
2013-07-19 15:08:14 +00:00
|
|
|
/*
|
2013-11-13 14:56:02 +00:00
|
|
|
* Sorts the |nva| in ascending order of name and value. If names are
|
|
|
|
* equivalent, sort them by value.
|
2013-07-19 15:08:14 +00:00
|
|
|
*/
|
|
|
|
void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
|
|
|
|
|
2013-09-10 15:55:35 +00:00
|
|
|
/*
|
|
|
|
* Copies name/value pairs from |nva|, which contains |nvlen| pairs,
|
|
|
|
* to |*nva_ptr|, which is dynamically allocated so that all items can
|
|
|
|
* be stored.
|
|
|
|
*
|
|
|
|
* The |*nva_ptr| must be freed using nghttp2_nv_array_del().
|
|
|
|
*
|
2014-06-11 14:37:16 +00:00
|
|
|
* This function returns 0 if it succeeds or one of the following
|
|
|
|
* negative error codes:
|
2013-09-10 15:55:35 +00:00
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
2014-06-11 14:37:16 +00:00
|
|
|
int nghttp2_nv_array_copy(nghttp2_nv **nva_ptr,
|
|
|
|
const nghttp2_nv *nva, size_t nvlen);
|
2013-09-10 15:55:35 +00:00
|
|
|
|
2013-07-19 07:50:31 +00:00
|
|
|
/*
|
|
|
|
* Returns nonzero if the name/value pair |a| equals to |b|. The name
|
|
|
|
* is compared in case-sensitive, because we ensure that this function
|
|
|
|
* is called after the name is lower-cased.
|
|
|
|
*/
|
|
|
|
int nghttp2_nv_equal(const nghttp2_nv *a, const nghttp2_nv *b);
|
|
|
|
|
2013-07-19 15:08:14 +00:00
|
|
|
/*
|
|
|
|
* Frees |nva|.
|
|
|
|
*/
|
|
|
|
void nghttp2_nv_array_del(nghttp2_nv *nva);
|
|
|
|
|
2013-08-03 09:05:14 +00:00
|
|
|
/*
|
|
|
|
* Checks that the |iv|, which includes |niv| entries, does not have
|
2014-02-05 15:23:20 +00:00
|
|
|
* invalid values.
|
2013-08-03 09:05:14 +00:00
|
|
|
*
|
|
|
|
* This function returns nonzero if it succeeds, or 0.
|
|
|
|
*/
|
2014-02-05 15:23:20 +00:00
|
|
|
int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv);
|
2013-08-03 09:05:14 +00:00
|
|
|
|
2014-02-08 08:46:21 +00:00
|
|
|
/*
|
2014-06-07 09:15:36 +00:00
|
|
|
* Sets Pad Length field and flags and adjusts frame header position
|
|
|
|
* of each buffers in |bufs|. The number of padding is given in the
|
|
|
|
* |padlen| including Pad Length field. The |hd| is the frame header
|
|
|
|
* for the serialized data.
|
2014-03-13 13:11:02 +00:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
2014-05-06 09:02:26 +00:00
|
|
|
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
|
|
|
* The length of the resulting frame is too large.
|
2014-03-13 13:11:02 +00:00
|
|
|
*/
|
|
|
|
int nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
|
2014-06-07 09:15:36 +00:00
|
|
|
size_t padlen);
|
2014-02-08 08:46:21 +00:00
|
|
|
|
2013-07-12 15:19:03 +00:00
|
|
|
#endif /* NGHTTP2_FRAME_H */
|