nghttp2_frame.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * nghttp2 - HTTP/2 C Library
  3. *
  4. * Copyright (c) 2012 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGHTTP2_FRAME_H
  26. #define NGHTTP2_FRAME_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* HAVE_CONFIG_H */
  30. #include <nghttp2/nghttp2.h>
  31. #include "nghttp2_hd.h"
  32. #include "nghttp2_buf.h"
  33. #define NGHTTP2_STREAM_ID_MASK ((1u << 31) - 1)
  34. #define NGHTTP2_PRI_GROUP_ID_MASK ((1u << 31) - 1)
  35. #define NGHTTP2_PRIORITY_MASK ((1u << 31) - 1)
  36. #define NGHTTP2_WINDOW_SIZE_INCREMENT_MASK ((1u << 31) - 1)
  37. #define NGHTTP2_SETTINGS_ID_MASK ((1 << 24) - 1)
  38. /* The number of bytes of frame header. */
  39. #define NGHTTP2_FRAME_HDLEN 9
  40. #define NGHTTP2_MAX_FRAME_SIZE_MAX ((1 << 24) - 1)
  41. #define NGHTTP2_MAX_FRAME_SIZE_MIN (1 << 14)
  42. #define NGHTTP2_MAX_PAYLOADLEN 16384
  43. /* The one frame buffer length for transmission. We may use several of
  44. them to support CONTINUATION. To account for Pad Length field, we
  45. allocate extra 1 byte, which saves extra large memcopying. */
  46. #define NGHTTP2_FRAMEBUF_CHUNKLEN \
  47. (NGHTTP2_FRAME_HDLEN + 1 + NGHTTP2_MAX_PAYLOADLEN)
  48. /* The default length of DATA frame payload. */
  49. #define NGHTTP2_DATA_PAYLOADLEN NGHTTP2_MAX_FRAME_SIZE_MIN
  50. /* Maximum headers block size to send, calculated using
  51. nghttp2_hd_deflate_bound(). This is the default value, and can be
  52. overridden by nghttp2_option_set_max_send_header_block_length(). */
  53. #define NGHTTP2_MAX_HEADERSLEN 65536
  54. /* The number of bytes for each SETTINGS entry */
  55. #define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 6
  56. /* Length of priority related fields in HEADERS/PRIORITY frames */
  57. #define NGHTTP2_PRIORITY_SPECLEN 5
  58. /* Maximum length of padding in bytes. */
  59. #define NGHTTP2_MAX_PADLEN 256
  60. /* Union of extension frame payload */
  61. typedef union {
  62. nghttp2_ext_altsvc altsvc;
  63. nghttp2_ext_origin origin;
  64. } nghttp2_ext_frame_payload;
  65. void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd);
  66. void nghttp2_frame_unpack_frame_hd(nghttp2_frame_hd *hd, const uint8_t *buf);
  67. /**
  68. * Initializes frame header |hd| with given parameters. Reserved bit
  69. * is set to 0.
  70. */
  71. void nghttp2_frame_hd_init(nghttp2_frame_hd *hd, size_t length, uint8_t type,
  72. uint8_t flags, int32_t stream_id);
  73. /**
  74. * Returns the number of priority field depending on the |flags|. If
  75. * |flags| has neither NGHTTP2_FLAG_PRIORITY_GROUP nor
  76. * NGHTTP2_FLAG_PRIORITY_DEPENDENCY set, return 0.
  77. */
  78. size_t nghttp2_frame_priority_len(uint8_t flags);
  79. /**
  80. * Packs the |pri_spec| in |buf|. This function assumes |buf| has
  81. * enough space for serialization.
  82. */
  83. void nghttp2_frame_pack_priority_spec(uint8_t *buf,
  84. const nghttp2_priority_spec *pri_spec);
  85. /**
  86. * Unpacks the priority specification from payload |payload| of length
  87. * |payloadlen| to |pri_spec|. The |flags| is used to determine what
  88. * kind of priority specification is in |payload|. This function
  89. * assumes the |payload| contains whole priority specification.
  90. */
  91. void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
  92. const uint8_t *payload);
  93. /*
  94. * Returns the offset from the HEADERS frame payload where the
  95. * compressed header block starts. The frame payload does not include
  96. * frame header.
  97. */
  98. size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
  99. /*
  100. * Packs HEADERS frame |frame| in wire format and store it in |bufs|.
  101. * This function expands |bufs| as necessary to store frame.
  102. *
  103. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  104. * before calling this function.
  105. *
  106. * frame->hd.length is assigned after length is determined during
  107. * packing process. CONTINUATION frames are also serialized in this
  108. * function. This function does not handle padding.
  109. *
  110. * This function returns 0 if it succeeds, or returns one of the
  111. * following negative error codes:
  112. *
  113. * NGHTTP2_ERR_HEADER_COMP
  114. * The deflate operation failed.
  115. * NGHTTP2_ERR_NOMEM
  116. * Out of memory.
  117. */
  118. int nghttp2_frame_pack_headers(nghttp2_bufs *bufs, nghttp2_headers *frame,
  119. nghttp2_hd_deflater *deflater);
  120. /*
  121. * Unpacks HEADERS frame byte sequence into |frame|. This function
  122. * only unapcks bytes that come before name/value header block and
  123. * after possible Pad Length field.
  124. *
  125. * This function always succeeds and returns 0.
  126. */
  127. int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
  128. const uint8_t *payload);
  129. /*
  130. * Packs PRIORITY frame |frame| in wire format and store it in
  131. * |bufs|.
  132. *
  133. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  134. * before calling this function.
  135. *
  136. * This function always succeeds and returns 0.
  137. */
  138. int nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame);
  139. /*
  140. * Unpacks PRIORITY wire format into |frame|.
  141. */
  142. void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
  143. const uint8_t *payload);
  144. /*
  145. * Packs RST_STREAM frame |frame| in wire frame format and store it in
  146. * |bufs|.
  147. *
  148. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  149. * before calling this function.
  150. *
  151. * This function always succeeds and returns 0.
  152. */
  153. int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
  154. nghttp2_rst_stream *frame);
  155. /*
  156. * Unpacks RST_STREAM frame byte sequence into |frame|.
  157. */
  158. void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
  159. const uint8_t *payload);
  160. /*
  161. * Packs SETTINGS frame |frame| in wire format and store it in
  162. * |bufs|.
  163. *
  164. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  165. * before calling this function.
  166. *
  167. * This function returns 0 if it succeeds, or returns one of the
  168. * following negative error codes:
  169. *
  170. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  171. * The length of the frame is too large.
  172. */
  173. int nghttp2_frame_pack_settings(nghttp2_bufs *bufs, nghttp2_settings *frame);
  174. /*
  175. * Packs the |iv|, which includes |niv| entries, in the |buf|,
  176. * assuming the |buf| has at least 8 * |niv| bytes.
  177. *
  178. * Returns the number of bytes written into the |buf|.
  179. */
  180. size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
  181. const nghttp2_settings_entry *iv,
  182. size_t niv);
  183. void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
  184. const uint8_t *payload);
  185. /*
  186. * Initializes payload of frame->settings. The |frame| takes
  187. * ownership of |iv|.
  188. */
  189. void nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
  190. nghttp2_settings_entry *iv,
  191. size_t niv);
  192. /*
  193. * Unpacks SETTINGS payload into |*iv_ptr|. The number of entries are
  194. * assigned to the |*niv_ptr|. This function allocates enough memory
  195. * to store the result in |*iv_ptr|. The caller is responsible to free
  196. * |*iv_ptr| after its use.
  197. *
  198. * This function returns 0 if it succeeds or one of the following
  199. * negative error codes:
  200. *
  201. * NGHTTP2_ERR_NOMEM
  202. * Out of memory.
  203. */
  204. int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
  205. size_t *niv_ptr,
  206. const uint8_t *payload,
  207. size_t payloadlen, nghttp2_mem *mem);
  208. /*
  209. * Packs PUSH_PROMISE frame |frame| in wire format and store it in
  210. * |bufs|. This function expands |bufs| as necessary to store
  211. * frame.
  212. *
  213. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  214. * before calling this function.
  215. *
  216. * frame->hd.length is assigned after length is determined during
  217. * packing process. CONTINUATION frames are also serialized in this
  218. * function. This function does not handle padding.
  219. *
  220. * This function returns 0 if it succeeds, or returns one of the
  221. * following negative error codes:
  222. *
  223. * NGHTTP2_ERR_HEADER_COMP
  224. * The deflate operation failed.
  225. * NGHTTP2_ERR_NOMEM
  226. * Out of memory.
  227. */
  228. int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
  229. nghttp2_push_promise *frame,
  230. nghttp2_hd_deflater *deflater);
  231. /*
  232. * Unpacks PUSH_PROMISE frame byte sequence into |frame|. This
  233. * function only unapcks bytes that come before name/value header
  234. * block and after possible Pad Length field.
  235. *
  236. * This function returns 0 if it succeeds or one of the following
  237. * negative error codes:
  238. *
  239. * NGHTTP2_ERR_PROTO
  240. * TODO END_HEADERS flag is not set
  241. */
  242. int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
  243. const uint8_t *payload);
  244. /*
  245. * Packs PING frame |frame| in wire format and store it in
  246. * |bufs|.
  247. *
  248. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  249. * before calling this function.
  250. *
  251. * This function always succeeds and returns 0.
  252. */
  253. int nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame);
  254. /*
  255. * Unpacks PING wire format into |frame|.
  256. */
  257. void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
  258. const uint8_t *payload);
  259. /*
  260. * Packs GOAWAY frame |frame| in wire format and store it in |bufs|.
  261. * This function expands |bufs| as necessary to store frame.
  262. *
  263. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  264. * before calling this function.
  265. *
  266. * This function returns 0 if it succeeds or one of the following
  267. * negative error codes:
  268. *
  269. * NGHTTP2_ERR_NOMEM
  270. * Out of memory.
  271. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  272. * The length of the frame is too large.
  273. */
  274. int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame);
  275. /*
  276. * Unpacks GOAWAY wire format into |frame|. The |payload| of length
  277. * |payloadlen| contains first 8 bytes of payload. The
  278. * |var_gift_payload| of length |var_gift_payloadlen| contains
  279. * remaining payload and its buffer is gifted to the function and then
  280. * |frame|. The |var_gift_payloadlen| must be freed by
  281. * nghttp2_frame_goaway_free().
  282. */
  283. void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
  284. const uint8_t *payload,
  285. uint8_t *var_gift_payload,
  286. size_t var_gift_payloadlen);
  287. /*
  288. * Unpacks GOAWAY wire format into |frame|. This function only exists
  289. * for unit test. After allocating buffer for debug data, this
  290. * function internally calls nghttp2_frame_unpack_goaway_payload().
  291. *
  292. * This function returns 0 if it succeeds, or one of the following
  293. * negative error codes:
  294. *
  295. * NGHTTP2_ERR_NOMEM
  296. * Out of memory.
  297. */
  298. int nghttp2_frame_unpack_goaway_payload2(nghttp2_goaway *frame,
  299. const uint8_t *payload,
  300. size_t payloadlen, nghttp2_mem *mem);
  301. /*
  302. * Packs WINDOW_UPDATE frame |frame| in wire frame format and store it
  303. * in |bufs|.
  304. *
  305. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  306. * before calling this function.
  307. *
  308. * This function always succeeds and returns 0.
  309. */
  310. int nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
  311. nghttp2_window_update *frame);
  312. /*
  313. * Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
  314. */
  315. void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
  316. const uint8_t *payload);
  317. /*
  318. * Packs ALTSVC frame |frame| in wire frame format and store it in
  319. * |bufs|.
  320. *
  321. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  322. * before calling this function.
  323. *
  324. * This function always succeeds and returns 0.
  325. */
  326. int nghttp2_frame_pack_altsvc(nghttp2_bufs *bufs, nghttp2_extension *ext);
  327. /*
  328. * Unpacks ALTSVC wire format into |frame|. The |payload| of
  329. * |payloadlen| bytes contains frame payload. This function assumes
  330. * that frame->payload points to the nghttp2_ext_altsvc object.
  331. *
  332. * This function always succeeds and returns 0.
  333. */
  334. void nghttp2_frame_unpack_altsvc_payload(nghttp2_extension *frame,
  335. size_t origin_len, uint8_t *payload,
  336. size_t payloadlen);
  337. /*
  338. * Unpacks ALTSVC wire format into |frame|. This function only exists
  339. * for unit test. After allocating buffer for fields, this function
  340. * internally calls nghttp2_frame_unpack_altsvc_payload().
  341. *
  342. * This function returns 0 if it succeeds, or one of the following
  343. * negative error codes:
  344. *
  345. * NGHTTP2_ERR_NOMEM
  346. * Out of memory.
  347. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  348. * The payload is too small.
  349. */
  350. int nghttp2_frame_unpack_altsvc_payload2(nghttp2_extension *frame,
  351. const uint8_t *payload,
  352. size_t payloadlen, nghttp2_mem *mem);
  353. /*
  354. * Packs ORIGIN frame |frame| in wire frame format and store it in
  355. * |bufs|.
  356. *
  357. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  358. * before calling this function.
  359. *
  360. * This function returns 0 if it succeeds, or one of the following
  361. * negative error codes:
  362. *
  363. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  364. * The length of the frame is too large.
  365. */
  366. int nghttp2_frame_pack_origin(nghttp2_bufs *bufs, nghttp2_extension *ext);
  367. /*
  368. * Unpacks ORIGIN wire format into |frame|. The |payload| of length
  369. * |payloadlen| contains the frame payload.
  370. *
  371. * This function returns 0 if it succeeds, or one of the following
  372. * negative error codes:
  373. *
  374. * NGHTTP2_ERR_NOMEM
  375. * Out of memory.
  376. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  377. * The payload is too small.
  378. */
  379. int nghttp2_frame_unpack_origin_payload(nghttp2_extension *frame,
  380. const uint8_t *payload,
  381. size_t payloadlen, nghttp2_mem *mem);
  382. /*
  383. * Initializes HEADERS frame |frame| with given values. |frame| takes
  384. * ownership of |nva|, so caller must not free it. If |stream_id| is
  385. * not assigned yet, it must be -1.
  386. */
  387. void nghttp2_frame_headers_init(nghttp2_headers *frame, uint8_t flags,
  388. int32_t stream_id, nghttp2_headers_category cat,
  389. const nghttp2_priority_spec *pri_spec,
  390. nghttp2_nv *nva, size_t nvlen);
  391. void nghttp2_frame_headers_free(nghttp2_headers *frame, nghttp2_mem *mem);
  392. void nghttp2_frame_priority_init(nghttp2_priority *frame, int32_t stream_id,
  393. const nghttp2_priority_spec *pri_spec);
  394. void nghttp2_frame_priority_free(nghttp2_priority *frame);
  395. void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id,
  396. uint32_t error_code);
  397. void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame);
  398. /*
  399. * Initializes PUSH_PROMISE frame |frame| with given values. |frame|
  400. * takes ownership of |nva|, so caller must not free it.
  401. */
  402. void nghttp2_frame_push_promise_init(nghttp2_push_promise *frame, uint8_t flags,
  403. int32_t stream_id,
  404. int32_t promised_stream_id,
  405. nghttp2_nv *nva, size_t nvlen);
  406. void nghttp2_frame_push_promise_free(nghttp2_push_promise *frame,
  407. nghttp2_mem *mem);
  408. /*
  409. * Initializes SETTINGS frame |frame| with given values. |frame| takes
  410. * ownership of |iv|, so caller must not free it. The |flags| are
  411. * bitwise-OR of one or more of nghttp2_settings_flag.
  412. */
  413. void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags,
  414. nghttp2_settings_entry *iv, size_t niv);
  415. void nghttp2_frame_settings_free(nghttp2_settings *frame, nghttp2_mem *mem);
  416. /*
  417. * Initializes PING frame |frame| with given values. If the
  418. * |opqeue_data| is not NULL, it must point to 8 bytes memory region
  419. * of data. The data pointed by |opaque_data| is copied. It can be
  420. * NULL. In this case, 8 bytes NULL is used.
  421. */
  422. void nghttp2_frame_ping_init(nghttp2_ping *frame, uint8_t flags,
  423. const uint8_t *opque_data);
  424. void nghttp2_frame_ping_free(nghttp2_ping *frame);
  425. /*
  426. * Initializes GOAWAY frame |frame| with given values. On success,
  427. * this function takes ownership of |opaque_data|, so caller must not
  428. * free it. If the |opaque_data_len| is 0, opaque_data could be NULL.
  429. */
  430. void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id,
  431. uint32_t error_code, uint8_t *opaque_data,
  432. size_t opaque_data_len);
  433. void nghttp2_frame_goaway_free(nghttp2_goaway *frame, nghttp2_mem *mem);
  434. void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
  435. uint8_t flags, int32_t stream_id,
  436. int32_t window_size_increment);
  437. void nghttp2_frame_window_update_free(nghttp2_window_update *frame);
  438. void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type,
  439. uint8_t flags, int32_t stream_id,
  440. void *payload);
  441. void nghttp2_frame_extension_free(nghttp2_extension *frame);
  442. /*
  443. * Initializes ALTSVC frame |frame| with given values. This function
  444. * assumes that frame->payload points to nghttp2_ext_altsvc object.
  445. * Also |origin| and |field_value| are allocated in single buffer,
  446. * starting |origin|. On success, this function takes ownership of
  447. * |origin|, so caller must not free it.
  448. */
  449. void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id,
  450. uint8_t *origin, size_t origin_len,
  451. uint8_t *field_value, size_t field_value_len);
  452. /*
  453. * Frees up resources under |frame|. This function does not free
  454. * nghttp2_ext_altsvc object pointed by frame->payload. This function
  455. * only frees origin pointed by nghttp2_ext_altsvc.origin. Therefore,
  456. * other fields must be allocated in the same buffer with origin.
  457. */
  458. void nghttp2_frame_altsvc_free(nghttp2_extension *frame, nghttp2_mem *mem);
  459. /*
  460. * Initializes ORIGIN frame |frame| with given values. This function
  461. * assumes that frame->payload points to nghttp2_ext_origin object.
  462. * Also |ov| and the memory pointed by the field of its elements are
  463. * allocated in single buffer, starting with |ov|. On success, this
  464. * function takes ownership of |ov|, so caller must not free it.
  465. */
  466. void nghttp2_frame_origin_init(nghttp2_extension *frame,
  467. nghttp2_origin_entry *ov, size_t nov);
  468. /*
  469. * Frees up resources under |frame|. This function does not free
  470. * nghttp2_ext_origin object pointed by frame->payload. This function
  471. * only frees nghttp2_ext_origin.ov. Therefore, other fields must be
  472. * allocated in the same buffer with ov.
  473. */
  474. void nghttp2_frame_origin_free(nghttp2_extension *frame, nghttp2_mem *mem);
  475. /*
  476. * Returns the number of padding bytes after payload. The total
  477. * padding length is given in the |padlen|. The returned value does
  478. * not include the Pad Length field. If |padlen| is 0, this function
  479. * returns 0, regardless of frame->hd.flags.
  480. */
  481. size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen);
  482. void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags,
  483. int32_t stream_id);
  484. void nghttp2_frame_data_free(nghttp2_data *frame);
  485. /*
  486. * Makes copy of |iv| and return the copy. The |niv| is the number of
  487. * entries in |iv|. This function returns the pointer to the copy if
  488. * it succeeds, or NULL.
  489. */
  490. nghttp2_settings_entry *nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
  491. size_t niv, nghttp2_mem *mem);
  492. /*
  493. * Sorts the |nva| in ascending order of name and value. If names are
  494. * equivalent, sort them by value.
  495. */
  496. void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
  497. /*
  498. * Copies name/value pairs from |nva|, which contains |nvlen| pairs,
  499. * to |*nva_ptr|, which is dynamically allocated so that all items can
  500. * be stored. The resultant name and value in nghttp2_nv are
  501. * guaranteed to be NULL-terminated even if the input is not
  502. * null-terminated.
  503. *
  504. * The |*nva_ptr| must be freed using nghttp2_nv_array_del().
  505. *
  506. * This function returns 0 if it succeeds or one of the following
  507. * negative error codes:
  508. *
  509. * NGHTTP2_ERR_NOMEM
  510. * Out of memory.
  511. */
  512. int nghttp2_nv_array_copy(nghttp2_nv **nva_ptr, const nghttp2_nv *nva,
  513. size_t nvlen, nghttp2_mem *mem);
  514. /*
  515. * Returns nonzero if the name/value pair |a| equals to |b|. The name
  516. * is compared in case-sensitive, because we ensure that this function
  517. * is called after the name is lower-cased.
  518. */
  519. int nghttp2_nv_equal(const nghttp2_nv *a, const nghttp2_nv *b);
  520. /*
  521. * Frees |nva|.
  522. */
  523. void nghttp2_nv_array_del(nghttp2_nv *nva, nghttp2_mem *mem);
  524. /*
  525. * Checks that the |iv|, which includes |niv| entries, does not have
  526. * invalid values.
  527. *
  528. * This function returns nonzero if it succeeds, or 0.
  529. */
  530. int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv);
  531. /*
  532. * Sets Pad Length field and flags and adjusts frame header position
  533. * of each buffers in |bufs|. The number of padding is given in the
  534. * |padlen| including Pad Length field. The |hd| is the frame header
  535. * for the serialized data. This function fills zeros padding region
  536. * unless framehd_only is nonzero.
  537. *
  538. * This function returns 0 if it succeeds, or one of the following
  539. * negative error codes:
  540. *
  541. * NGHTTP2_ERR_NOMEM
  542. * Out of memory.
  543. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  544. * The length of the resulting frame is too large.
  545. */
  546. int nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
  547. size_t padlen, int framehd_only);
  548. #endif /* NGHTTP2_FRAME_H */