nghttp2_frame.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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_priority_update priority_update;
  65. } nghttp2_ext_frame_payload;
  66. void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd);
  67. void nghttp2_frame_unpack_frame_hd(nghttp2_frame_hd *hd, const uint8_t *buf);
  68. /**
  69. * Initializes frame header |hd| with given parameters. Reserved bit
  70. * is set to 0.
  71. */
  72. void nghttp2_frame_hd_init(nghttp2_frame_hd *hd, size_t length, uint8_t type,
  73. uint8_t flags, int32_t stream_id);
  74. /**
  75. * Returns the number of priority field depending on the |flags|. If
  76. * |flags| has neither NGHTTP2_FLAG_PRIORITY_GROUP nor
  77. * NGHTTP2_FLAG_PRIORITY_DEPENDENCY set, return 0.
  78. */
  79. size_t nghttp2_frame_priority_len(uint8_t flags);
  80. /**
  81. * Packs the |pri_spec| in |buf|. This function assumes |buf| has
  82. * enough space for serialization.
  83. */
  84. void nghttp2_frame_pack_priority_spec(uint8_t *buf,
  85. const nghttp2_priority_spec *pri_spec);
  86. /**
  87. * Unpacks the priority specification from payload |payload| of length
  88. * |payloadlen| to |pri_spec|. The |flags| is used to determine what
  89. * kind of priority specification is in |payload|. This function
  90. * assumes the |payload| contains whole priority specification.
  91. */
  92. void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
  93. const uint8_t *payload);
  94. /*
  95. * Returns the offset from the HEADERS frame payload where the
  96. * compressed header block starts. The frame payload does not include
  97. * frame header.
  98. */
  99. size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
  100. /*
  101. * Packs HEADERS frame |frame| in wire format and store it in |bufs|.
  102. * This function expands |bufs| as necessary to store frame.
  103. *
  104. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  105. * before calling this function.
  106. *
  107. * frame->hd.length is assigned after length is determined during
  108. * packing process. CONTINUATION frames are also serialized in this
  109. * function. This function does not handle padding.
  110. *
  111. * This function returns 0 if it succeeds, or returns one of the
  112. * following negative error codes:
  113. *
  114. * NGHTTP2_ERR_HEADER_COMP
  115. * The deflate operation failed.
  116. * NGHTTP2_ERR_NOMEM
  117. * Out of memory.
  118. */
  119. int nghttp2_frame_pack_headers(nghttp2_bufs *bufs, nghttp2_headers *frame,
  120. nghttp2_hd_deflater *deflater);
  121. /*
  122. * Unpacks HEADERS frame byte sequence into |frame|. This function
  123. * only unapcks bytes that come before name/value header block and
  124. * after possible Pad Length field.
  125. */
  126. void nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
  127. const uint8_t *payload);
  128. /*
  129. * Packs PRIORITY frame |frame| in wire format and store it in
  130. * |bufs|.
  131. *
  132. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  133. * before calling this function.
  134. */
  135. void nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame);
  136. /*
  137. * Unpacks PRIORITY wire format into |frame|.
  138. */
  139. void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
  140. const uint8_t *payload);
  141. /*
  142. * Packs RST_STREAM frame |frame| in wire frame format and store it in
  143. * |bufs|.
  144. *
  145. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  146. * before calling this function.
  147. */
  148. void nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
  149. nghttp2_rst_stream *frame);
  150. /*
  151. * Unpacks RST_STREAM frame byte sequence into |frame|.
  152. */
  153. void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
  154. const uint8_t *payload);
  155. /*
  156. * Packs SETTINGS frame |frame| in wire format and store it in
  157. * |bufs|.
  158. *
  159. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  160. * before calling this function.
  161. *
  162. * This function returns 0 if it succeeds, or returns one of the
  163. * following negative error codes:
  164. *
  165. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  166. * The length of the frame is too large.
  167. */
  168. int nghttp2_frame_pack_settings(nghttp2_bufs *bufs, nghttp2_settings *frame);
  169. /*
  170. * Packs the |iv|, which includes |niv| entries, in the |buf|,
  171. * assuming the |buf| has at least 8 * |niv| bytes.
  172. *
  173. * Returns the number of bytes written into the |buf|.
  174. */
  175. size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
  176. const nghttp2_settings_entry *iv,
  177. size_t niv);
  178. void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
  179. const uint8_t *payload);
  180. /*
  181. * Initializes payload of frame->settings. The |frame| takes
  182. * ownership of |iv|.
  183. */
  184. void nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
  185. nghttp2_settings_entry *iv,
  186. size_t niv);
  187. /*
  188. * Unpacks SETTINGS payload into |*iv_ptr|. The number of entries are
  189. * assigned to the |*niv_ptr|. This function allocates enough memory
  190. * to store the result in |*iv_ptr|. The caller is responsible to free
  191. * |*iv_ptr| after its use.
  192. *
  193. * This function returns 0 if it succeeds or one of the following
  194. * negative error codes:
  195. *
  196. * NGHTTP2_ERR_NOMEM
  197. * Out of memory.
  198. */
  199. int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
  200. size_t *niv_ptr,
  201. const uint8_t *payload,
  202. size_t payloadlen, nghttp2_mem *mem);
  203. /*
  204. * Packs PUSH_PROMISE frame |frame| in wire format and store it in
  205. * |bufs|. This function expands |bufs| as necessary to store
  206. * frame.
  207. *
  208. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  209. * before calling this function.
  210. *
  211. * frame->hd.length is assigned after length is determined during
  212. * packing process. CONTINUATION frames are also serialized in this
  213. * function. This function does not handle padding.
  214. *
  215. * This function returns 0 if it succeeds, or returns one of the
  216. * following negative error codes:
  217. *
  218. * NGHTTP2_ERR_HEADER_COMP
  219. * The deflate operation failed.
  220. * NGHTTP2_ERR_NOMEM
  221. * Out of memory.
  222. */
  223. int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
  224. nghttp2_push_promise *frame,
  225. nghttp2_hd_deflater *deflater);
  226. /*
  227. * Unpacks PUSH_PROMISE frame byte sequence into |frame|. This
  228. * function only unapcks bytes that come before name/value header
  229. * block and after possible Pad Length field.
  230. */
  231. void nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
  232. const uint8_t *payload);
  233. /*
  234. * Packs PING frame |frame| in wire format and store it in
  235. * |bufs|.
  236. *
  237. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  238. * before calling this function.
  239. */
  240. void nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame);
  241. /*
  242. * Unpacks PING wire format into |frame|.
  243. */
  244. void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
  245. const uint8_t *payload);
  246. /*
  247. * Packs GOAWAY frame |frame| in wire format and store it in |bufs|.
  248. * This function expands |bufs| as necessary to store frame.
  249. *
  250. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  251. * before calling this function.
  252. *
  253. * This function returns 0 if it succeeds or one of the following
  254. * negative error codes:
  255. *
  256. * NGHTTP2_ERR_NOMEM
  257. * Out of memory.
  258. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  259. * The length of the frame is too large.
  260. */
  261. int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame);
  262. /*
  263. * Unpacks GOAWAY wire format into |frame|. The |payload| of length
  264. * |payloadlen| contains first 8 bytes of payload. The
  265. * |var_gift_payload| of length |var_gift_payloadlen| contains
  266. * remaining payload and its buffer is gifted to the function and then
  267. * |frame|. The |var_gift_payloadlen| must be freed by
  268. * nghttp2_frame_goaway_free().
  269. */
  270. void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
  271. const uint8_t *payload,
  272. uint8_t *var_gift_payload,
  273. size_t var_gift_payloadlen);
  274. /*
  275. * Unpacks GOAWAY wire format into |frame|. This function only exists
  276. * for unit test. After allocating buffer for debug data, this
  277. * function internally calls nghttp2_frame_unpack_goaway_payload().
  278. *
  279. * This function returns 0 if it succeeds, or one of the following
  280. * negative error codes:
  281. *
  282. * NGHTTP2_ERR_NOMEM
  283. * Out of memory.
  284. */
  285. int nghttp2_frame_unpack_goaway_payload2(nghttp2_goaway *frame,
  286. const uint8_t *payload,
  287. size_t payloadlen, nghttp2_mem *mem);
  288. /*
  289. * Packs WINDOW_UPDATE frame |frame| in wire frame format and store it
  290. * in |bufs|.
  291. *
  292. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  293. * before calling this function.
  294. */
  295. void nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
  296. nghttp2_window_update *frame);
  297. /*
  298. * Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
  299. */
  300. void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
  301. const uint8_t *payload);
  302. /*
  303. * Packs ALTSVC frame |frame| in wire frame format and store it in
  304. * |bufs|.
  305. *
  306. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  307. * before calling this function.
  308. */
  309. void nghttp2_frame_pack_altsvc(nghttp2_bufs *bufs, nghttp2_extension *ext);
  310. /*
  311. * Unpacks ALTSVC wire format into |frame|. The |payload| of
  312. * |payloadlen| bytes contains frame payload. This function assumes
  313. * that frame->payload points to the nghttp2_ext_altsvc object.
  314. */
  315. void nghttp2_frame_unpack_altsvc_payload(nghttp2_extension *frame,
  316. size_t origin_len, uint8_t *payload,
  317. size_t payloadlen);
  318. /*
  319. * Unpacks ALTSVC wire format into |frame|. This function only exists
  320. * for unit test. After allocating buffer for fields, this function
  321. * internally calls nghttp2_frame_unpack_altsvc_payload().
  322. *
  323. * This function returns 0 if it succeeds, or one of the following
  324. * negative error codes:
  325. *
  326. * NGHTTP2_ERR_NOMEM
  327. * Out of memory.
  328. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  329. * The payload is too small.
  330. */
  331. int nghttp2_frame_unpack_altsvc_payload2(nghttp2_extension *frame,
  332. const uint8_t *payload,
  333. size_t payloadlen, nghttp2_mem *mem);
  334. /*
  335. * Packs ORIGIN frame |frame| in wire frame format and store it in
  336. * |bufs|.
  337. *
  338. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  339. * before calling this function.
  340. *
  341. * This function returns 0 if it succeeds, or one of the following
  342. * negative error codes:
  343. *
  344. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  345. * The length of the frame is too large.
  346. */
  347. int nghttp2_frame_pack_origin(nghttp2_bufs *bufs, nghttp2_extension *ext);
  348. /*
  349. * Unpacks ORIGIN wire format into |frame|. The |payload| of length
  350. * |payloadlen| contains the frame payload.
  351. *
  352. * This function returns 0 if it succeeds, or one of the following
  353. * negative error codes:
  354. *
  355. * NGHTTP2_ERR_NOMEM
  356. * Out of memory.
  357. * NGHTTP2_ERR_FRAME_SIZE_ERROR
  358. * The payload is too small.
  359. */
  360. int nghttp2_frame_unpack_origin_payload(nghttp2_extension *frame,
  361. const uint8_t *payload,
  362. size_t payloadlen, nghttp2_mem *mem);
  363. /*
  364. * Packs PRIORITY_UPDATE frame |frame| in wire frame format and store
  365. * it in |bufs|.
  366. *
  367. * The caller must make sure that nghttp2_bufs_reset(bufs) is called
  368. * before calling this function.
  369. */
  370. void nghttp2_frame_pack_priority_update(nghttp2_bufs *bufs,
  371. nghttp2_extension *ext);
  372. /*
  373. * Unpacks PRIORITY_UPDATE wire format into |frame|. The |payload| of
  374. * |payloadlen| bytes contains frame payload. This function assumes
  375. * that frame->payload points to the nghttp2_ext_priority_update
  376. * object.
  377. */
  378. void nghttp2_frame_unpack_priority_update_payload(nghttp2_extension *frame,
  379. uint8_t *payload,
  380. size_t payloadlen);
  381. /*
  382. * Initializes HEADERS frame |frame| with given values. |frame| takes
  383. * ownership of |nva|, so caller must not free it. If |stream_id| is
  384. * not assigned yet, it must be -1.
  385. */
  386. void nghttp2_frame_headers_init(nghttp2_headers *frame, uint8_t flags,
  387. int32_t stream_id, nghttp2_headers_category cat,
  388. const nghttp2_priority_spec *pri_spec,
  389. nghttp2_nv *nva, size_t nvlen);
  390. void nghttp2_frame_headers_free(nghttp2_headers *frame, nghttp2_mem *mem);
  391. void nghttp2_frame_priority_init(nghttp2_priority *frame, int32_t stream_id,
  392. const nghttp2_priority_spec *pri_spec);
  393. void nghttp2_frame_priority_free(nghttp2_priority *frame);
  394. void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id,
  395. uint32_t error_code);
  396. void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame);
  397. /*
  398. * Initializes PUSH_PROMISE frame |frame| with given values. |frame|
  399. * takes ownership of |nva|, so caller must not free it.
  400. */
  401. void nghttp2_frame_push_promise_init(nghttp2_push_promise *frame, uint8_t flags,
  402. int32_t stream_id,
  403. int32_t promised_stream_id,
  404. nghttp2_nv *nva, size_t nvlen);
  405. void nghttp2_frame_push_promise_free(nghttp2_push_promise *frame,
  406. nghttp2_mem *mem);
  407. /*
  408. * Initializes SETTINGS frame |frame| with given values. |frame| takes
  409. * ownership of |iv|, so caller must not free it. The |flags| are
  410. * bitwise-OR of one or more of nghttp2_settings_flag.
  411. */
  412. void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags,
  413. nghttp2_settings_entry *iv, size_t niv);
  414. void nghttp2_frame_settings_free(nghttp2_settings *frame, nghttp2_mem *mem);
  415. /*
  416. * Initializes PING frame |frame| with given values. If the
  417. * |opqeue_data| is not NULL, it must point to 8 bytes memory region
  418. * of data. The data pointed by |opaque_data| is copied. It can be
  419. * NULL. In this case, 8 bytes NULL is used.
  420. */
  421. void nghttp2_frame_ping_init(nghttp2_ping *frame, uint8_t flags,
  422. const uint8_t *opque_data);
  423. void nghttp2_frame_ping_free(nghttp2_ping *frame);
  424. /*
  425. * Initializes GOAWAY frame |frame| with given values. On success,
  426. * this function takes ownership of |opaque_data|, so caller must not
  427. * free it. If the |opaque_data_len| is 0, opaque_data could be NULL.
  428. */
  429. void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id,
  430. uint32_t error_code, uint8_t *opaque_data,
  431. size_t opaque_data_len);
  432. void nghttp2_frame_goaway_free(nghttp2_goaway *frame, nghttp2_mem *mem);
  433. void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
  434. uint8_t flags, int32_t stream_id,
  435. int32_t window_size_increment);
  436. void nghttp2_frame_window_update_free(nghttp2_window_update *frame);
  437. void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type,
  438. uint8_t flags, int32_t stream_id,
  439. void *payload);
  440. void nghttp2_frame_extension_free(nghttp2_extension *frame);
  441. /*
  442. * Initializes ALTSVC frame |frame| with given values. This function
  443. * assumes that frame->payload points to nghttp2_ext_altsvc object.
  444. * Also |origin| and |field_value| are allocated in single buffer,
  445. * starting |origin|. On success, this function takes ownership of
  446. * |origin|, so caller must not free it.
  447. */
  448. void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id,
  449. uint8_t *origin, size_t origin_len,
  450. uint8_t *field_value, size_t field_value_len);
  451. /*
  452. * Frees up resources under |frame|. This function does not free
  453. * nghttp2_ext_altsvc object pointed by frame->payload. This function
  454. * only frees origin pointed by nghttp2_ext_altsvc.origin. Therefore,
  455. * other fields must be allocated in the same buffer with origin.
  456. */
  457. void nghttp2_frame_altsvc_free(nghttp2_extension *frame, nghttp2_mem *mem);
  458. /*
  459. * Initializes ORIGIN frame |frame| with given values. This function
  460. * assumes that frame->payload points to nghttp2_ext_origin object.
  461. * Also |ov| and the memory pointed by the field of its elements are
  462. * allocated in single buffer, starting with |ov|. On success, this
  463. * function takes ownership of |ov|, so caller must not free it.
  464. */
  465. void nghttp2_frame_origin_init(nghttp2_extension *frame,
  466. nghttp2_origin_entry *ov, size_t nov);
  467. /*
  468. * Frees up resources under |frame|. This function does not free
  469. * nghttp2_ext_origin object pointed by frame->payload. This function
  470. * only frees nghttp2_ext_origin.ov. Therefore, other fields must be
  471. * allocated in the same buffer with ov.
  472. */
  473. void nghttp2_frame_origin_free(nghttp2_extension *frame, nghttp2_mem *mem);
  474. /*
  475. * Initializes PRIORITY_UPDATE frame |frame| with given values. This
  476. * function assumes that frame->payload points to
  477. * nghttp2_ext_priority_update object. On success, this function
  478. * takes ownership of |field_value|, so caller must not free it.
  479. */
  480. void nghttp2_frame_priority_update_init(nghttp2_extension *frame,
  481. int32_t stream_id, uint8_t *field_value,
  482. size_t field_value_len);
  483. /*
  484. * Frees up resources under |frame|. This function does not free
  485. * nghttp2_ext_priority_update object pointed by frame->payload. This
  486. * function only frees field_value pointed by
  487. * nghttp2_ext_priority_update.field_value.
  488. */
  489. void nghttp2_frame_priority_update_free(nghttp2_extension *frame,
  490. nghttp2_mem *mem);
  491. /*
  492. * Returns the number of padding bytes after payload. The total
  493. * padding length is given in the |padlen|. The returned value does
  494. * not include the Pad Length field. If |padlen| is 0, this function
  495. * returns 0, regardless of frame->hd.flags.
  496. */
  497. size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen);
  498. void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags,
  499. int32_t stream_id);
  500. void nghttp2_frame_data_free(nghttp2_data *frame);
  501. /*
  502. * Makes copy of |iv| and return the copy. The |niv| is the number of
  503. * entries in |iv|. This function returns the pointer to the copy if
  504. * it succeeds, or NULL.
  505. */
  506. nghttp2_settings_entry *nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
  507. size_t niv, nghttp2_mem *mem);
  508. /*
  509. * Sorts the |nva| in ascending order of name and value. If names are
  510. * equivalent, sort them by value.
  511. */
  512. void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
  513. /*
  514. * Copies name/value pairs from |nva|, which contains |nvlen| pairs,
  515. * to |*nva_ptr|, which is dynamically allocated so that all items can
  516. * be stored. The resultant name and value in nghttp2_nv are
  517. * guaranteed to be NULL-terminated even if the input is not
  518. * null-terminated.
  519. *
  520. * The |*nva_ptr| must be freed using nghttp2_nv_array_del().
  521. *
  522. * This function returns 0 if it succeeds or one of the following
  523. * negative error codes:
  524. *
  525. * NGHTTP2_ERR_NOMEM
  526. * Out of memory.
  527. */
  528. int nghttp2_nv_array_copy(nghttp2_nv **nva_ptr, const nghttp2_nv *nva,
  529. size_t nvlen, nghttp2_mem *mem);
  530. /*
  531. * Returns nonzero if the name/value pair |a| equals to |b|. The name
  532. * is compared in case-sensitive, because we ensure that this function
  533. * is called after the name is lower-cased.
  534. */
  535. int nghttp2_nv_equal(const nghttp2_nv *a, const nghttp2_nv *b);
  536. /*
  537. * Frees |nva|.
  538. */
  539. void nghttp2_nv_array_del(nghttp2_nv *nva, nghttp2_mem *mem);
  540. /*
  541. * Checks that the |iv|, which includes |niv| entries, does not have
  542. * invalid values.
  543. *
  544. * This function returns nonzero if it succeeds, or 0.
  545. */
  546. int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv);
  547. /*
  548. * Sets Pad Length field and flags and adjusts frame header position
  549. * of each buffers in |bufs|. The number of padding is given in the
  550. * |padlen| including Pad Length field. The |hd| is the frame header
  551. * for the serialized data. This function fills zeros padding region
  552. * unless framehd_only is nonzero.
  553. */
  554. void nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
  555. size_t padlen, int framehd_only);
  556. #endif /* NGHTTP2_FRAME_H */