nghttp2_frame.h 21 KB

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