Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_frame.h
3153 views
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
28
#ifdef HAVE_CONFIG_H
29
# include <config.h>
30
#endif /* HAVE_CONFIG_H */
31
32
#include <nghttp2/nghttp2.h>
33
#include "nghttp2_hd.h"
34
#include "nghttp2_buf.h"
35
36
#define NGHTTP2_STREAM_ID_MASK ((1u << 31) - 1)
37
#define NGHTTP2_PRI_GROUP_ID_MASK ((1u << 31) - 1)
38
#define NGHTTP2_PRIORITY_MASK ((1u << 31) - 1)
39
#define NGHTTP2_WINDOW_SIZE_INCREMENT_MASK ((1u << 31) - 1)
40
#define NGHTTP2_SETTINGS_ID_MASK ((1 << 24) - 1)
41
42
/* The number of bytes of frame header. */
43
#define NGHTTP2_FRAME_HDLEN 9
44
45
#define NGHTTP2_MAX_FRAME_SIZE_MAX ((1 << 24) - 1)
46
#define NGHTTP2_MAX_FRAME_SIZE_MIN (1 << 14)
47
48
#define NGHTTP2_MAX_PAYLOADLEN 16384
49
/* The one frame buffer length for transmission. We may use several of
50
them to support CONTINUATION. To account for Pad Length field, we
51
allocate extra 1 byte, which saves extra large memcopying. */
52
#define NGHTTP2_FRAMEBUF_CHUNKLEN \
53
(NGHTTP2_FRAME_HDLEN + 1 + NGHTTP2_MAX_PAYLOADLEN)
54
55
/* The default length of DATA frame payload. */
56
#define NGHTTP2_DATA_PAYLOADLEN NGHTTP2_MAX_FRAME_SIZE_MIN
57
58
/* Maximum headers block size to send, calculated using
59
nghttp2_hd_deflate_bound(). This is the default value, and can be
60
overridden by nghttp2_option_set_max_send_header_block_length(). */
61
#define NGHTTP2_MAX_HEADERSLEN 65536
62
63
/* The number of bytes for each SETTINGS entry */
64
#define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 6
65
66
/* Length of priority related fields in HEADERS/PRIORITY frames */
67
#define NGHTTP2_PRIORITY_SPECLEN 5
68
69
/* Maximum length of padding in bytes. */
70
#define NGHTTP2_MAX_PADLEN 256
71
72
/* Union of extension frame payload */
73
typedef union {
74
nghttp2_ext_altsvc altsvc;
75
nghttp2_ext_origin origin;
76
nghttp2_ext_priority_update priority_update;
77
} nghttp2_ext_frame_payload;
78
79
void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd);
80
81
void nghttp2_frame_unpack_frame_hd(nghttp2_frame_hd *hd, const uint8_t *buf);
82
83
/**
84
* Initializes frame header |hd| with given parameters. Reserved bit
85
* is set to 0.
86
*/
87
void nghttp2_frame_hd_init(nghttp2_frame_hd *hd, size_t length, uint8_t type,
88
uint8_t flags, int32_t stream_id);
89
90
/**
91
* Returns the number of priority field depending on the |flags|. If
92
* |flags| has neither NGHTTP2_FLAG_PRIORITY_GROUP nor
93
* NGHTTP2_FLAG_PRIORITY_DEPENDENCY set, return 0.
94
*/
95
size_t nghttp2_frame_priority_len(uint8_t flags);
96
97
/**
98
* Packs the |pri_spec| in |buf|. This function assumes |buf| has
99
* enough space for serialization.
100
*/
101
void nghttp2_frame_pack_priority_spec(uint8_t *buf,
102
const nghttp2_priority_spec *pri_spec);
103
104
/**
105
* Unpacks the priority specification from payload |payload| of length
106
* |payloadlen| to |pri_spec|. The |flags| is used to determine what
107
* kind of priority specification is in |payload|. This function
108
* assumes the |payload| contains whole priority specification.
109
*/
110
void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
111
const uint8_t *payload);
112
113
/*
114
* Returns the offset from the HEADERS frame payload where the
115
* compressed header block starts. The frame payload does not include
116
* frame header.
117
*/
118
size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
119
120
/*
121
* Packs HEADERS frame |frame| in wire format and store it in |bufs|.
122
* This function expands |bufs| as necessary to store frame.
123
*
124
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
125
* before calling this function.
126
*
127
* frame->hd.length is assigned after length is determined during
128
* packing process. CONTINUATION frames are also serialized in this
129
* function. This function does not handle padding.
130
*
131
* This function returns 0 if it succeeds, or returns one of the
132
* following negative error codes:
133
*
134
* NGHTTP2_ERR_HEADER_COMP
135
* The deflate operation failed.
136
* NGHTTP2_ERR_NOMEM
137
* Out of memory.
138
*/
139
int nghttp2_frame_pack_headers(nghttp2_bufs *bufs, nghttp2_headers *frame,
140
nghttp2_hd_deflater *deflater);
141
142
/*
143
* Unpacks HEADERS frame byte sequence into |frame|. This function
144
* only unapcks bytes that come before name/value header block and
145
* after possible Pad Length field.
146
*
147
* This function always succeeds and returns 0.
148
*/
149
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
150
const uint8_t *payload);
151
152
/*
153
* Packs PRIORITY frame |frame| in wire format and store it in
154
* |bufs|.
155
*
156
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
157
* before calling this function.
158
*
159
* This function always succeeds and returns 0.
160
*/
161
int nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame);
162
163
/*
164
* Unpacks PRIORITY wire format into |frame|.
165
*/
166
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
167
const uint8_t *payload);
168
169
/*
170
* Packs RST_STREAM frame |frame| in wire frame format and store it in
171
* |bufs|.
172
*
173
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
174
* before calling this function.
175
*
176
* This function always succeeds and returns 0.
177
*/
178
int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
179
nghttp2_rst_stream *frame);
180
181
/*
182
* Unpacks RST_STREAM frame byte sequence into |frame|.
183
*/
184
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
185
const uint8_t *payload);
186
187
/*
188
* Packs SETTINGS frame |frame| in wire format and store it in
189
* |bufs|.
190
*
191
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
192
* before calling this function.
193
*
194
* This function returns 0 if it succeeds, or returns one of the
195
* following negative error codes:
196
*
197
* NGHTTP2_ERR_FRAME_SIZE_ERROR
198
* The length of the frame is too large.
199
*/
200
int nghttp2_frame_pack_settings(nghttp2_bufs *bufs, nghttp2_settings *frame);
201
202
/*
203
* Packs the |iv|, which includes |niv| entries, in the |buf|,
204
* assuming the |buf| has at least 8 * |niv| bytes.
205
*
206
* Returns the number of bytes written into the |buf|.
207
*/
208
size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
209
const nghttp2_settings_entry *iv,
210
size_t niv);
211
212
void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
213
const uint8_t *payload);
214
215
/*
216
* Initializes payload of frame->settings. The |frame| takes
217
* ownership of |iv|.
218
*/
219
void nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
220
nghttp2_settings_entry *iv,
221
size_t niv);
222
223
/*
224
* Unpacks SETTINGS payload into |*iv_ptr|. The number of entries are
225
* assigned to the |*niv_ptr|. This function allocates enough memory
226
* to store the result in |*iv_ptr|. The caller is responsible to free
227
* |*iv_ptr| after its use.
228
*
229
* This function returns 0 if it succeeds or one of the following
230
* negative error codes:
231
*
232
* NGHTTP2_ERR_NOMEM
233
* Out of memory.
234
*/
235
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
236
size_t *niv_ptr,
237
const uint8_t *payload,
238
size_t payloadlen, nghttp2_mem *mem);
239
240
/*
241
* Packs PUSH_PROMISE frame |frame| in wire format and store it in
242
* |bufs|. This function expands |bufs| as necessary to store
243
* frame.
244
*
245
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
246
* before calling this function.
247
*
248
* frame->hd.length is assigned after length is determined during
249
* packing process. CONTINUATION frames are also serialized in this
250
* function. This function does not handle padding.
251
*
252
* This function returns 0 if it succeeds, or returns one of the
253
* following negative error codes:
254
*
255
* NGHTTP2_ERR_HEADER_COMP
256
* The deflate operation failed.
257
* NGHTTP2_ERR_NOMEM
258
* Out of memory.
259
*/
260
int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
261
nghttp2_push_promise *frame,
262
nghttp2_hd_deflater *deflater);
263
264
/*
265
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. This
266
* function only unapcks bytes that come before name/value header
267
* block and after possible Pad Length field.
268
*
269
* This function returns 0 if it succeeds or one of the following
270
* negative error codes:
271
*
272
* NGHTTP2_ERR_PROTO
273
* TODO END_HEADERS flag is not set
274
*/
275
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
276
const uint8_t *payload);
277
278
/*
279
* Packs PING frame |frame| in wire format and store it in
280
* |bufs|.
281
*
282
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
283
* before calling this function.
284
*
285
* This function always succeeds and returns 0.
286
*/
287
int nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame);
288
289
/*
290
* Unpacks PING wire format into |frame|.
291
*/
292
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
293
const uint8_t *payload);
294
295
/*
296
* Packs GOAWAY frame |frame| in wire format and store it in |bufs|.
297
* This function expands |bufs| as necessary to store frame.
298
*
299
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
300
* before calling this function.
301
*
302
* This function returns 0 if it succeeds or one of the following
303
* negative error codes:
304
*
305
* NGHTTP2_ERR_NOMEM
306
* Out of memory.
307
* NGHTTP2_ERR_FRAME_SIZE_ERROR
308
* The length of the frame is too large.
309
*/
310
int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame);
311
312
/*
313
* Unpacks GOAWAY wire format into |frame|. The |payload| of length
314
* |payloadlen| contains first 8 bytes of payload. The
315
* |var_gift_payload| of length |var_gift_payloadlen| contains
316
* remaining payload and its buffer is gifted to the function and then
317
* |frame|. The |var_gift_payloadlen| must be freed by
318
* nghttp2_frame_goaway_free().
319
*/
320
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
321
const uint8_t *payload,
322
uint8_t *var_gift_payload,
323
size_t var_gift_payloadlen);
324
325
/*
326
* Unpacks GOAWAY wire format into |frame|. This function only exists
327
* for unit test. After allocating buffer for debug data, this
328
* function internally calls nghttp2_frame_unpack_goaway_payload().
329
*
330
* This function returns 0 if it succeeds, or one of the following
331
* negative error codes:
332
*
333
* NGHTTP2_ERR_NOMEM
334
* Out of memory.
335
*/
336
int nghttp2_frame_unpack_goaway_payload2(nghttp2_goaway *frame,
337
const uint8_t *payload,
338
size_t payloadlen, nghttp2_mem *mem);
339
340
/*
341
* Packs WINDOW_UPDATE frame |frame| in wire frame format and store it
342
* in |bufs|.
343
*
344
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
345
* before calling this function.
346
*
347
* This function always succeeds and returns 0.
348
*/
349
int nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
350
nghttp2_window_update *frame);
351
352
/*
353
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
354
*/
355
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
356
const uint8_t *payload);
357
358
/*
359
* Packs ALTSVC frame |frame| in wire frame format and store it in
360
* |bufs|.
361
*
362
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
363
* before calling this function.
364
*
365
* This function always succeeds and returns 0.
366
*/
367
int nghttp2_frame_pack_altsvc(nghttp2_bufs *bufs, nghttp2_extension *ext);
368
369
/*
370
* Unpacks ALTSVC wire format into |frame|. The |payload| of
371
* |payloadlen| bytes contains frame payload. This function assumes
372
* that frame->payload points to the nghttp2_ext_altsvc object.
373
*
374
* This function always succeeds and returns 0.
375
*/
376
void nghttp2_frame_unpack_altsvc_payload(nghttp2_extension *frame,
377
size_t origin_len, uint8_t *payload,
378
size_t payloadlen);
379
380
/*
381
* Unpacks ALTSVC wire format into |frame|. This function only exists
382
* for unit test. After allocating buffer for fields, this function
383
* internally calls nghttp2_frame_unpack_altsvc_payload().
384
*
385
* This function returns 0 if it succeeds, or one of the following
386
* negative error codes:
387
*
388
* NGHTTP2_ERR_NOMEM
389
* Out of memory.
390
* NGHTTP2_ERR_FRAME_SIZE_ERROR
391
* The payload is too small.
392
*/
393
int nghttp2_frame_unpack_altsvc_payload2(nghttp2_extension *frame,
394
const uint8_t *payload,
395
size_t payloadlen, nghttp2_mem *mem);
396
397
/*
398
* Packs ORIGIN frame |frame| in wire frame format and store it in
399
* |bufs|.
400
*
401
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
402
* before calling this function.
403
*
404
* This function returns 0 if it succeeds, or one of the following
405
* negative error codes:
406
*
407
* NGHTTP2_ERR_FRAME_SIZE_ERROR
408
* The length of the frame is too large.
409
*/
410
int nghttp2_frame_pack_origin(nghttp2_bufs *bufs, nghttp2_extension *ext);
411
412
/*
413
* Unpacks ORIGIN wire format into |frame|. The |payload| of length
414
* |payloadlen| contains the frame payload.
415
*
416
* This function returns 0 if it succeeds, or one of the following
417
* negative error codes:
418
*
419
* NGHTTP2_ERR_NOMEM
420
* Out of memory.
421
* NGHTTP2_ERR_FRAME_SIZE_ERROR
422
* The payload is too small.
423
*/
424
int nghttp2_frame_unpack_origin_payload(nghttp2_extension *frame,
425
const uint8_t *payload,
426
size_t payloadlen, nghttp2_mem *mem);
427
428
/*
429
* Packs PRIORITY_UPDATE frame |frame| in wire frame format and store
430
* it in |bufs|.
431
*
432
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
433
* before calling this function.
434
*
435
* This function always succeeds and returns 0.
436
*/
437
int nghttp2_frame_pack_priority_update(nghttp2_bufs *bufs,
438
nghttp2_extension *ext);
439
440
/*
441
* Unpacks PRIORITY_UPDATE wire format into |frame|. The |payload| of
442
* |payloadlen| bytes contains frame payload. This function assumes
443
* that frame->payload points to the nghttp2_ext_priority_update
444
* object.
445
*
446
* This function always succeeds and returns 0.
447
*/
448
void nghttp2_frame_unpack_priority_update_payload(nghttp2_extension *frame,
449
uint8_t *payload,
450
size_t payloadlen);
451
452
/*
453
* Initializes HEADERS frame |frame| with given values. |frame| takes
454
* ownership of |nva|, so caller must not free it. If |stream_id| is
455
* not assigned yet, it must be -1.
456
*/
457
void nghttp2_frame_headers_init(nghttp2_headers *frame, uint8_t flags,
458
int32_t stream_id, nghttp2_headers_category cat,
459
const nghttp2_priority_spec *pri_spec,
460
nghttp2_nv *nva, size_t nvlen);
461
462
void nghttp2_frame_headers_free(nghttp2_headers *frame, nghttp2_mem *mem);
463
464
void nghttp2_frame_priority_init(nghttp2_priority *frame, int32_t stream_id,
465
const nghttp2_priority_spec *pri_spec);
466
467
void nghttp2_frame_priority_free(nghttp2_priority *frame);
468
469
void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id,
470
uint32_t error_code);
471
472
void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame);
473
474
/*
475
* Initializes PUSH_PROMISE frame |frame| with given values. |frame|
476
* takes ownership of |nva|, so caller must not free it.
477
*/
478
void nghttp2_frame_push_promise_init(nghttp2_push_promise *frame, uint8_t flags,
479
int32_t stream_id,
480
int32_t promised_stream_id,
481
nghttp2_nv *nva, size_t nvlen);
482
483
void nghttp2_frame_push_promise_free(nghttp2_push_promise *frame,
484
nghttp2_mem *mem);
485
486
/*
487
* Initializes SETTINGS frame |frame| with given values. |frame| takes
488
* ownership of |iv|, so caller must not free it. The |flags| are
489
* bitwise-OR of one or more of nghttp2_settings_flag.
490
*/
491
void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags,
492
nghttp2_settings_entry *iv, size_t niv);
493
494
void nghttp2_frame_settings_free(nghttp2_settings *frame, nghttp2_mem *mem);
495
496
/*
497
* Initializes PING frame |frame| with given values. If the
498
* |opqeue_data| is not NULL, it must point to 8 bytes memory region
499
* of data. The data pointed by |opaque_data| is copied. It can be
500
* NULL. In this case, 8 bytes NULL is used.
501
*/
502
void nghttp2_frame_ping_init(nghttp2_ping *frame, uint8_t flags,
503
const uint8_t *opque_data);
504
505
void nghttp2_frame_ping_free(nghttp2_ping *frame);
506
507
/*
508
* Initializes GOAWAY frame |frame| with given values. On success,
509
* this function takes ownership of |opaque_data|, so caller must not
510
* free it. If the |opaque_data_len| is 0, opaque_data could be NULL.
511
*/
512
void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id,
513
uint32_t error_code, uint8_t *opaque_data,
514
size_t opaque_data_len);
515
516
void nghttp2_frame_goaway_free(nghttp2_goaway *frame, nghttp2_mem *mem);
517
518
void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
519
uint8_t flags, int32_t stream_id,
520
int32_t window_size_increment);
521
522
void nghttp2_frame_window_update_free(nghttp2_window_update *frame);
523
524
void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type,
525
uint8_t flags, int32_t stream_id,
526
void *payload);
527
528
void nghttp2_frame_extension_free(nghttp2_extension *frame);
529
530
/*
531
* Initializes ALTSVC frame |frame| with given values. This function
532
* assumes that frame->payload points to nghttp2_ext_altsvc object.
533
* Also |origin| and |field_value| are allocated in single buffer,
534
* starting |origin|. On success, this function takes ownership of
535
* |origin|, so caller must not free it.
536
*/
537
void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id,
538
uint8_t *origin, size_t origin_len,
539
uint8_t *field_value, size_t field_value_len);
540
541
/*
542
* Frees up resources under |frame|. This function does not free
543
* nghttp2_ext_altsvc object pointed by frame->payload. This function
544
* only frees origin pointed by nghttp2_ext_altsvc.origin. Therefore,
545
* other fields must be allocated in the same buffer with origin.
546
*/
547
void nghttp2_frame_altsvc_free(nghttp2_extension *frame, nghttp2_mem *mem);
548
549
/*
550
* Initializes ORIGIN frame |frame| with given values. This function
551
* assumes that frame->payload points to nghttp2_ext_origin object.
552
* Also |ov| and the memory pointed by the field of its elements are
553
* allocated in single buffer, starting with |ov|. On success, this
554
* function takes ownership of |ov|, so caller must not free it.
555
*/
556
void nghttp2_frame_origin_init(nghttp2_extension *frame,
557
nghttp2_origin_entry *ov, size_t nov);
558
559
/*
560
* Frees up resources under |frame|. This function does not free
561
* nghttp2_ext_origin object pointed by frame->payload. This function
562
* only frees nghttp2_ext_origin.ov. Therefore, other fields must be
563
* allocated in the same buffer with ov.
564
*/
565
void nghttp2_frame_origin_free(nghttp2_extension *frame, nghttp2_mem *mem);
566
567
/*
568
* Initializes PRIORITY_UPDATE frame |frame| with given values. This
569
* function assumes that frame->payload points to
570
* nghttp2_ext_priority_update object. On success, this function
571
* takes ownership of |field_value|, so caller must not free it.
572
*/
573
void nghttp2_frame_priority_update_init(nghttp2_extension *frame,
574
int32_t stream_id, uint8_t *field_value,
575
size_t field_value_len);
576
577
/*
578
* Frees up resources under |frame|. This function does not free
579
* nghttp2_ext_priority_update object pointed by frame->payload. This
580
* function only frees field_value pointed by
581
* nghttp2_ext_priority_update.field_value.
582
*/
583
void nghttp2_frame_priority_update_free(nghttp2_extension *frame,
584
nghttp2_mem *mem);
585
586
/*
587
* Returns the number of padding bytes after payload. The total
588
* padding length is given in the |padlen|. The returned value does
589
* not include the Pad Length field. If |padlen| is 0, this function
590
* returns 0, regardless of frame->hd.flags.
591
*/
592
size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen);
593
594
void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags,
595
int32_t stream_id);
596
597
void nghttp2_frame_data_free(nghttp2_data *frame);
598
599
/*
600
* Makes copy of |iv| and return the copy. The |niv| is the number of
601
* entries in |iv|. This function returns the pointer to the copy if
602
* it succeeds, or NULL.
603
*/
604
nghttp2_settings_entry *nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
605
size_t niv, nghttp2_mem *mem);
606
607
/*
608
* Sorts the |nva| in ascending order of name and value. If names are
609
* equivalent, sort them by value.
610
*/
611
void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
612
613
/*
614
* Copies name/value pairs from |nva|, which contains |nvlen| pairs,
615
* to |*nva_ptr|, which is dynamically allocated so that all items can
616
* be stored. The resultant name and value in nghttp2_nv are
617
* guaranteed to be NULL-terminated even if the input is not
618
* null-terminated.
619
*
620
* The |*nva_ptr| must be freed using nghttp2_nv_array_del().
621
*
622
* This function returns 0 if it succeeds or one of the following
623
* negative error codes:
624
*
625
* NGHTTP2_ERR_NOMEM
626
* Out of memory.
627
*/
628
int nghttp2_nv_array_copy(nghttp2_nv **nva_ptr, const nghttp2_nv *nva,
629
size_t nvlen, nghttp2_mem *mem);
630
631
/*
632
* Returns nonzero if the name/value pair |a| equals to |b|. The name
633
* is compared in case-sensitive, because we ensure that this function
634
* is called after the name is lower-cased.
635
*/
636
int nghttp2_nv_equal(const nghttp2_nv *a, const nghttp2_nv *b);
637
638
/*
639
* Frees |nva|.
640
*/
641
void nghttp2_nv_array_del(nghttp2_nv *nva, nghttp2_mem *mem);
642
643
/*
644
* Checks that the |iv|, which includes |niv| entries, does not have
645
* invalid values.
646
*
647
* This function returns nonzero if it succeeds, or 0.
648
*/
649
int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv);
650
651
/*
652
* Sets Pad Length field and flags and adjusts frame header position
653
* of each buffers in |bufs|. The number of padding is given in the
654
* |padlen| including Pad Length field. The |hd| is the frame header
655
* for the serialized data. This function fills zeros padding region
656
* unless framehd_only is nonzero.
657
*
658
* This function returns 0 if it succeeds, or one of the following
659
* negative error codes:
660
*
661
* NGHTTP2_ERR_NOMEM
662
* Out of memory.
663
* NGHTTP2_ERR_FRAME_SIZE_ERROR
664
* The length of the resulting frame is too large.
665
*/
666
int nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
667
size_t padlen, int framehd_only);
668
669
#endif /* NGHTTP2_FRAME_H */
670
671