Mercurial > hg > nginx-quic
annotate src/http/v3/ngx_http_v3_parse.c @ 7950:b0e81f49d7c0 quic
HTTP/3: fixed prefixed integer encoding and decoding.
Previously bytes were ordered from MSB to LSB, but the right order is the
reverse.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 02 Jul 2020 15:15:55 +0300 |
parents | 032cb35ce758 |
children | c9538aef3211 |
rev | line source |
---|---|
7692 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 ngx_int_t | |
14 ngx_http_v3_parse_varlen_int(ngx_connection_t *c, | |
15 ngx_http_v3_parse_varlen_int_t *st, u_char ch) | |
16 { | |
17 enum { | |
18 sw_start = 0, | |
19 sw_length_2, | |
20 sw_length_3, | |
21 sw_length_4, | |
22 sw_length_5, | |
23 sw_length_6, | |
24 sw_length_7, | |
25 sw_length_8 | |
26 }; | |
27 | |
28 switch (st->state) { | |
29 | |
30 case sw_start: | |
31 | |
32 st->value = ch; | |
33 if (st->value & 0xc0) { | |
34 st->state = sw_length_2; | |
35 break; | |
36 } | |
37 | |
38 goto done; | |
39 | |
40 case sw_length_2: | |
41 | |
42 st->value = (st->value << 8) + ch; | |
43 if ((st->value & 0xc000) == 0x4000) { | |
44 st->value &= 0x3fff; | |
45 goto done; | |
46 } | |
47 | |
48 st->state = sw_length_3; | |
49 break; | |
50 | |
51 case sw_length_4: | |
52 | |
53 st->value = (st->value << 8) + ch; | |
54 if ((st->value & 0xc0000000) == 0x80000000) { | |
55 st->value &= 0x3fffffff; | |
56 goto done; | |
57 } | |
58 | |
59 st->state = sw_length_5; | |
60 break; | |
61 | |
62 case sw_length_3: | |
63 case sw_length_5: | |
64 case sw_length_6: | |
65 case sw_length_7: | |
66 | |
67 st->value = (st->value << 8) + ch; | |
68 st->state++; | |
69 break; | |
70 | |
71 case sw_length_8: | |
72 | |
73 st->value = (st->value << 8) + ch; | |
74 st->value &= 0x3fffffffffffffff; | |
75 goto done; | |
76 } | |
77 | |
78 return NGX_AGAIN; | |
79 | |
80 done: | |
81 | |
82 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
83 "http3 parse varlen int %uL", st->value); | |
84 | |
85 st->state = sw_start; | |
86 return NGX_DONE; | |
87 } | |
88 | |
89 | |
90 ngx_int_t | |
91 ngx_http_v3_parse_prefix_int(ngx_connection_t *c, | |
92 ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, u_char ch) | |
93 { | |
7950
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
94 ngx_uint_t mask; |
7692 | 95 enum { |
96 sw_start = 0, | |
97 sw_value | |
98 }; | |
99 | |
100 switch (st->state) { | |
101 | |
102 case sw_start: | |
103 | |
7950
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
104 mask = (1 << prefix) - 1; |
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
105 st->value = ch & mask; |
7692 | 106 |
7950
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
107 if (st->value != mask) { |
7692 | 108 goto done; |
109 } | |
110 | |
7950
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
111 st->shift = 0; |
7692 | 112 st->state = sw_value; |
113 break; | |
114 | |
115 case sw_value: | |
116 | |
7950
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
117 st->value += (ch & 0x7f) << st->shift; |
7692 | 118 if (ch & 0x80) { |
7950
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
119 st->shift += 7; |
7692 | 120 break; |
121 } | |
122 | |
123 goto done; | |
124 } | |
125 | |
126 return NGX_AGAIN; | |
127 | |
128 done: | |
129 | |
130 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
131 "http3 parse prefix int %uL", st->value); | |
132 | |
133 st->state = sw_start; | |
134 return NGX_DONE; | |
135 } | |
136 | |
137 | |
138 ngx_int_t | |
139 ngx_http_v3_parse_headers(ngx_connection_t *c, ngx_http_v3_parse_headers_t *st, | |
140 u_char ch) | |
141 { | |
142 ngx_int_t rc; | |
143 enum { | |
144 sw_start = 0, | |
145 sw_length, | |
146 sw_prefix, | |
147 sw_header_rep, | |
148 sw_done | |
149 }; | |
150 | |
151 switch (st->state) { | |
152 | |
153 case sw_start: | |
154 | |
155 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse headers"); | |
156 | |
157 if (ch != NGX_HTTP_V3_FRAME_HEADERS) { | |
158 return NGX_ERROR; | |
159 } | |
160 | |
161 st->state = sw_length; | |
162 break; | |
163 | |
164 case sw_length: | |
165 | |
166 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { | |
167 break; | |
168 } | |
169 | |
170 st->length = st->vlint.value; | |
171 | |
172 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
173 "http3 parse headers len:%ui", st->length); | |
174 | |
175 st->state = sw_prefix; | |
176 break; | |
177 | |
178 case sw_prefix: | |
179 | |
180 if (st->length-- == 0) { | |
181 return NGX_ERROR; | |
182 } | |
183 | |
184 rc = ngx_http_v3_parse_header_block_prefix(c, &st->prefix, ch); | |
185 | |
186 if (rc == NGX_ERROR) { | |
187 return NGX_ERROR; | |
188 } | |
189 | |
190 if (rc != NGX_DONE) { | |
191 break; | |
192 } | |
193 | |
194 if (st->length == 0) { | |
195 return NGX_ERROR; | |
196 } | |
197 | |
198 st->state = sw_header_rep; | |
199 break; | |
200 | |
201 case sw_header_rep: | |
202 | |
203 rc = ngx_http_v3_parse_header_rep(c, &st->header_rep, st->prefix.base, | |
204 ch); | |
205 | |
206 if (rc == NGX_ERROR) { | |
207 return NGX_ERROR; | |
208 } | |
209 | |
210 if (--st->length == 0) { | |
211 if (rc != NGX_DONE) { | |
212 return NGX_ERROR; | |
213 } | |
214 | |
215 goto done; | |
216 } | |
217 | |
218 if (rc == NGX_DONE) { | |
219 return NGX_OK; | |
220 } | |
221 | |
222 break; | |
223 } | |
224 | |
225 return NGX_AGAIN; | |
226 | |
227 done: | |
228 | |
229 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse headers done"); | |
230 | |
231 st->state = sw_start; | |
232 return NGX_DONE; | |
233 } | |
234 | |
235 | |
236 ngx_int_t | |
237 ngx_http_v3_parse_header_block_prefix(ngx_connection_t *c, | |
238 ngx_http_v3_parse_header_block_prefix_t *st, u_char ch) | |
239 { | |
240 enum { | |
241 sw_start = 0, | |
242 sw_req_insert_count, | |
243 sw_delta_base, | |
244 sw_read_delta_base | |
245 }; | |
246 | |
247 switch (st->state) { | |
248 | |
249 case sw_start: | |
250 | |
251 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
252 "http3 parse header block prefix"); | |
253 | |
254 st->state = sw_req_insert_count; | |
255 | |
256 /* fall through */ | |
257 | |
258 case sw_req_insert_count: | |
259 | |
260 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 8, ch) != NGX_DONE) { | |
261 break; | |
262 } | |
263 | |
264 st->insert_count = st->pint.value; | |
265 st->state = sw_delta_base; | |
266 break; | |
267 | |
268 case sw_delta_base: | |
269 | |
270 st->sign = (ch & 0x80) ? 1 : 0; | |
271 st->state = sw_read_delta_base; | |
272 | |
273 /* fall through */ | |
274 | |
275 case sw_read_delta_base: | |
276 | |
277 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { | |
278 break; | |
279 } | |
280 | |
281 st->delta_base = st->pint.value; | |
282 goto done; | |
283 } | |
284 | |
285 return NGX_AGAIN; | |
286 | |
287 done: | |
288 | |
289 if (st->sign) { | |
290 st->base = st->insert_count - st->delta_base - 1; | |
291 } else { | |
292 st->base = st->insert_count + st->delta_base; | |
293 } | |
294 | |
295 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
296 "http3 parse header block prefix done " | |
297 "i:%ui, s:%ui, d:%ui, base:%uL", | |
298 st->insert_count, st->sign, st->delta_base, st->base); | |
299 | |
300 st->state = sw_start; | |
301 return NGX_DONE; | |
302 } | |
303 | |
304 | |
305 ngx_int_t | |
306 ngx_http_v3_parse_header_rep(ngx_connection_t *c, | |
307 ngx_http_v3_parse_header_rep_t *st, ngx_uint_t base, u_char ch) | |
308 { | |
309 ngx_int_t rc; | |
310 enum { | |
311 sw_start = 0, | |
312 sw_header_ri, | |
313 sw_header_lri, | |
314 sw_header_l, | |
315 sw_header_pbi, | |
316 sw_header_lpbi | |
317 }; | |
318 | |
319 if (st->state == sw_start) { | |
320 | |
321 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
322 "http3 parse header representation"); | |
323 | |
324 ngx_memzero(&st->header, sizeof(ngx_http_v3_parse_header_t)); | |
325 | |
326 st->header.base = base; | |
327 | |
328 if (ch & 0x80) { | |
329 /* Indexed Header Field */ | |
330 | |
331 st->state = sw_header_ri; | |
332 | |
333 } else if (ch & 0x40) { | |
334 /* Literal Header Field With Name Reference */ | |
335 | |
336 st->state = sw_header_lri; | |
337 | |
338 } else if (ch & 0x20) { | |
339 /* Literal Header Field Without Name Reference */ | |
340 | |
341 st->state = sw_header_l; | |
342 | |
343 } else if (ch & 0x10) { | |
344 /* Indexed Header Field With Post-Base Index */ | |
345 | |
346 st->state = sw_header_pbi; | |
347 | |
348 } else { | |
349 /* Literal Header Field With Post-Base Name Reference */ | |
350 | |
351 st->state = sw_header_lpbi; | |
352 } | |
353 } | |
354 | |
355 switch (st->state) { | |
356 | |
357 case sw_header_ri: | |
358 rc = ngx_http_v3_parse_header_ri(c, &st->header, ch); | |
359 break; | |
360 | |
361 case sw_header_lri: | |
362 rc = ngx_http_v3_parse_header_lri(c, &st->header, ch); | |
363 break; | |
364 | |
365 case sw_header_l: | |
366 rc = ngx_http_v3_parse_header_l(c, &st->header, ch); | |
367 break; | |
368 | |
369 case sw_header_pbi: | |
370 rc = ngx_http_v3_parse_header_pbi(c, &st->header, ch); | |
371 break; | |
372 | |
373 case sw_header_lpbi: | |
374 rc = ngx_http_v3_parse_header_lpbi(c, &st->header, ch); | |
375 break; | |
376 | |
377 default: | |
378 rc = NGX_OK; | |
379 } | |
380 | |
381 if (rc == NGX_ERROR) { | |
382 return NGX_ERROR; | |
383 } | |
384 | |
385 if (rc == NGX_AGAIN) { | |
386 return NGX_AGAIN; | |
387 } | |
388 | |
389 /* rc == NGX_DONE */ | |
390 | |
391 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
392 "http3 parse header representation done"); | |
393 | |
394 st->state = sw_start; | |
395 return NGX_DONE; | |
396 } | |
397 | |
398 | |
399 ngx_int_t | |
400 ngx_http_v3_parse_literal(ngx_connection_t *c, ngx_http_v3_parse_literal_t *st, | |
401 u_char ch) | |
402 { | |
7949
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
403 ngx_uint_t n; |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
404 ngx_http_v3_srv_conf_t *v3cf; |
7692 | 405 enum { |
406 sw_start = 0, | |
407 sw_value | |
408 }; | |
409 | |
410 switch (st->state) { | |
411 | |
412 case sw_start: | |
413 | |
414 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
415 "http3 parse literal huff:%ui, len:%ui", | |
416 st->huffman, st->length); | |
417 | |
418 n = st->length; | |
419 | |
7949
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
420 v3cf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
421 |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
422 if (n > v3cf->max_field_size) { |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
423 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
424 "client exceeded http3_max_field_size limit"); |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
425 return NGX_ERROR; |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
426 } |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
427 |
7692 | 428 if (st->huffman) { |
429 n = n * 8 / 5; | |
430 st->huffstate = 0; | |
431 } | |
432 | |
433 st->last = ngx_pnalloc(c->pool, n + 1); | |
434 if (st->last == NULL) { | |
435 return NGX_ERROR; | |
436 } | |
437 | |
438 st->value.data = st->last; | |
439 st->state = sw_value; | |
440 | |
441 /* fall through */ | |
442 | |
443 case sw_value: | |
444 | |
445 if (st->huffman) { | |
446 if (ngx_http_v2_huff_decode(&st->huffstate, &ch, 1, &st->last, | |
447 st->length == 1, c->log) | |
448 != NGX_OK) | |
449 { | |
450 return NGX_ERROR; | |
451 } | |
452 | |
453 } else { | |
454 *st->last++ = ch; | |
455 } | |
456 | |
457 if (--st->length) { | |
458 break; | |
459 } | |
460 | |
461 st->value.len = st->last - st->value.data; | |
462 *st->last = '\0'; | |
463 goto done; | |
464 } | |
465 | |
466 return NGX_AGAIN; | |
467 | |
468 done: | |
469 | |
470 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
471 "http3 parse literal done \"%V\"", &st->value); | |
472 | |
473 st->state = sw_start; | |
474 return NGX_DONE; | |
475 } | |
476 | |
477 | |
478 ngx_int_t | |
479 ngx_http_v3_parse_header_ri(ngx_connection_t *c, ngx_http_v3_parse_header_t *st, | |
480 u_char ch) | |
481 { | |
482 ngx_http_v3_header_t *h; | |
483 enum { | |
484 sw_start = 0, | |
485 sw_index | |
486 }; | |
487 | |
488 switch (st->state) { | |
489 | |
490 case sw_start: | |
491 | |
492 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header ri"); | |
493 | |
494 st->dynamic = (ch & 0x40) ? 0 : 1; | |
495 st->state = sw_index; | |
496 | |
497 /* fall through */ | |
498 | |
499 case sw_index: | |
500 | |
501 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { | |
502 break; | |
503 } | |
504 | |
505 st->index = st->pint.value; | |
506 goto done; | |
507 } | |
508 | |
509 return NGX_AGAIN; | |
510 | |
511 done: | |
512 | |
513 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
514 "http3 parse header ri done %s%ui]", | |
515 st->dynamic ? "dynamic[-" : "static[", st->index); | |
516 | |
517 if (st->dynamic) { | |
518 st->index = st->base - st->index - 1; | |
519 } | |
520 | |
521 h = ngx_http_v3_lookup_table(c, st->dynamic, st->index); | |
522 if (h == NULL) { | |
523 return NGX_ERROR; | |
524 } | |
525 | |
526 st->name = h->name; | |
527 st->value = h->value; | |
528 st->state = sw_start; | |
529 | |
530 return NGX_DONE; | |
531 } | |
532 | |
533 | |
534 ngx_int_t | |
535 ngx_http_v3_parse_header_lri(ngx_connection_t *c, | |
536 ngx_http_v3_parse_header_t *st, u_char ch) | |
537 { | |
538 ngx_int_t rc; | |
539 ngx_http_v3_header_t *h; | |
540 enum { | |
541 sw_start = 0, | |
542 sw_index, | |
543 sw_value_len, | |
544 sw_read_value_len, | |
545 sw_value | |
546 }; | |
547 | |
548 switch (st->state) { | |
549 | |
550 case sw_start: | |
551 | |
552 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header lri"); | |
553 | |
554 st->dynamic = (ch & 0x10) ? 0 : 1; | |
555 st->state = sw_index; | |
556 | |
557 /* fall through */ | |
558 | |
559 case sw_index: | |
560 | |
561 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch) != NGX_DONE) { | |
562 break; | |
563 } | |
564 | |
565 st->index = st->pint.value; | |
566 st->state = sw_value_len; | |
567 break; | |
568 | |
569 case sw_value_len: | |
570 | |
571 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
572 st->state = sw_read_value_len; | |
573 | |
574 /* fall through */ | |
575 | |
576 case sw_read_value_len: | |
577 | |
578 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { | |
579 break; | |
580 } | |
581 | |
582 st->literal.length = st->pint.value; | |
583 if (st->literal.length == 0) { | |
584 goto done; | |
585 } | |
586 | |
587 st->state = sw_value; | |
588 break; | |
589 | |
590 case sw_value: | |
591 | |
592 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
593 | |
594 if (rc == NGX_ERROR) { | |
595 return NGX_ERROR; | |
596 } | |
597 | |
598 if (rc == NGX_DONE) { | |
599 st->value = st->literal.value; | |
600 goto done; | |
601 } | |
602 | |
603 break; | |
604 } | |
605 | |
606 return NGX_AGAIN; | |
607 | |
608 done: | |
609 | |
610 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
611 "http3 parse header lri done %s%ui] \"%V\"", | |
612 st->dynamic ? "dynamic[-" : "static[", | |
613 st->index, &st->value); | |
614 | |
615 if (st->dynamic) { | |
616 st->index = st->base - st->index - 1; | |
617 } | |
618 | |
619 h = ngx_http_v3_lookup_table(c, st->dynamic, st->index); | |
620 if (h == NULL) { | |
621 return NGX_ERROR; | |
622 } | |
623 | |
624 st->name = h->name; | |
625 st->state = sw_start; | |
626 return NGX_DONE; | |
627 } | |
628 | |
629 | |
630 ngx_int_t | |
631 ngx_http_v3_parse_header_l(ngx_connection_t *c, | |
632 ngx_http_v3_parse_header_t *st, u_char ch) | |
633 { | |
634 ngx_int_t rc; | |
635 enum { | |
636 sw_start = 0, | |
637 sw_name_len, | |
638 sw_name, | |
639 sw_value_len, | |
640 sw_read_value_len, | |
641 sw_value | |
642 }; | |
643 | |
644 switch (st->state) { | |
645 | |
646 case sw_start: | |
647 | |
648 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header l"); | |
649 | |
650 st->literal.huffman = (ch & 0x08) ? 1 : 0; | |
651 st->state = sw_name_len; | |
652 | |
653 /* fall through */ | |
654 | |
655 case sw_name_len: | |
656 | |
657 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch) != NGX_DONE) { | |
658 break; | |
659 } | |
660 | |
661 st->literal.length = st->pint.value; | |
662 if (st->literal.length == 0) { | |
663 return NGX_ERROR; | |
664 } | |
665 | |
666 st->state = sw_name; | |
667 break; | |
668 | |
669 case sw_name: | |
670 | |
671 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
672 | |
673 if (rc == NGX_ERROR) { | |
674 return NGX_ERROR; | |
675 } | |
676 | |
677 if (rc == NGX_DONE) { | |
678 st->name = st->literal.value; | |
679 st->state = sw_value_len; | |
680 } | |
681 | |
682 break; | |
683 | |
684 case sw_value_len: | |
685 | |
686 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
687 st->state = sw_read_value_len; | |
688 | |
689 /* fall through */ | |
690 | |
691 case sw_read_value_len: | |
692 | |
693 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { | |
694 break; | |
695 } | |
696 | |
697 st->literal.length = st->pint.value; | |
698 if (st->literal.length == 0) { | |
699 goto done; | |
700 } | |
701 | |
702 st->state = sw_value; | |
703 break; | |
704 | |
705 case sw_value: | |
706 | |
707 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
708 | |
709 if (rc == NGX_ERROR) { | |
710 return NGX_ERROR; | |
711 } | |
712 | |
713 if (rc == NGX_DONE) { | |
714 st->value = st->literal.value; | |
715 goto done; | |
716 } | |
717 | |
718 break; | |
719 } | |
720 | |
721 return NGX_AGAIN; | |
722 | |
723 done: | |
724 | |
725 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
726 "http3 parse header l done \"%V\" \"%V\"", | |
727 &st->name, &st->value); | |
728 | |
729 st->state = sw_start; | |
730 return NGX_DONE; | |
731 } | |
732 | |
733 | |
734 ngx_int_t | |
735 ngx_http_v3_parse_header_pbi(ngx_connection_t *c, | |
736 ngx_http_v3_parse_header_t *st, u_char ch) | |
737 { | |
738 ngx_http_v3_header_t *h; | |
739 enum { | |
740 sw_start = 0, | |
741 sw_index | |
742 }; | |
743 | |
744 switch (st->state) { | |
745 | |
746 case sw_start: | |
747 | |
748 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header pbi"); | |
749 | |
750 st->state = sw_index; | |
751 | |
752 /* fall through */ | |
753 | |
754 case sw_index: | |
755 | |
756 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch) != NGX_DONE) { | |
757 break; | |
758 } | |
759 | |
760 st->index = st->pint.value; | |
761 goto done; | |
762 } | |
763 | |
764 return NGX_AGAIN; | |
765 | |
766 done: | |
767 | |
768 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
769 "http3 parse header pbi done dynamic[+%ui]", st->index); | |
770 | |
771 h = ngx_http_v3_lookup_table(c, 1, st->base + st->index); | |
772 if (h == NULL) { | |
773 return NGX_ERROR; | |
774 } | |
775 | |
776 st->name = h->name; | |
777 st->value = h->value; | |
778 st->state = sw_start; | |
779 return NGX_DONE; | |
780 } | |
781 | |
782 | |
783 ngx_int_t | |
784 ngx_http_v3_parse_header_lpbi(ngx_connection_t *c, | |
785 ngx_http_v3_parse_header_t *st, u_char ch) | |
786 { | |
787 ngx_int_t rc; | |
788 ngx_http_v3_header_t *h; | |
789 enum { | |
790 sw_start = 0, | |
791 sw_index, | |
792 sw_value_len, | |
793 sw_read_value_len, | |
794 sw_value | |
795 }; | |
796 | |
797 switch (st->state) { | |
798 | |
799 case sw_start: | |
800 | |
801 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
802 "http3 parse header lpbi"); | |
803 | |
804 st->state = sw_index; | |
805 | |
806 /* fall through */ | |
807 | |
808 case sw_index: | |
809 | |
810 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch) != NGX_DONE) { | |
811 break; | |
812 } | |
813 | |
814 st->index = st->pint.value; | |
815 st->state = sw_value_len; | |
816 break; | |
817 | |
818 case sw_value_len: | |
819 | |
820 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
821 st->state = sw_read_value_len; | |
822 | |
823 /* fall through */ | |
824 | |
825 case sw_read_value_len: | |
826 | |
827 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { | |
828 break; | |
829 } | |
830 | |
831 st->literal.length = st->pint.value; | |
832 if (st->literal.length == 0) { | |
833 goto done; | |
834 } | |
835 | |
836 st->state = sw_value; | |
837 break; | |
838 | |
839 case sw_value: | |
840 | |
841 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
842 | |
843 if (rc == NGX_ERROR) { | |
844 return NGX_ERROR; | |
845 } | |
846 | |
847 if (rc == NGX_DONE) { | |
848 st->value = st->literal.value; | |
849 goto done; | |
850 } | |
851 | |
852 break; | |
853 } | |
854 | |
855 return NGX_AGAIN; | |
856 | |
857 done: | |
858 | |
859 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
860 "http3 parse header lpbi done dynamic[+%ui] \"%V\"", | |
861 st->index, &st->value); | |
862 | |
863 h = ngx_http_v3_lookup_table(c, 1, st->base + st->index); | |
864 if (h == NULL) { | |
865 return NGX_ERROR; | |
866 } | |
867 | |
868 st->name = h->name; | |
869 st->state = sw_start; | |
870 return NGX_DONE; | |
871 } | |
872 | |
873 | |
874 ngx_int_t | |
875 ngx_http_v3_parse_control(ngx_connection_t *c, void *data, u_char ch) | |
876 { | |
877 ngx_http_v3_parse_control_t *st = data; | |
878 | |
879 ngx_int_t rc; | |
880 enum { | |
881 sw_start = 0, | |
882 sw_type, | |
883 sw_length, | |
884 sw_settings, | |
885 sw_max_push_id, | |
886 sw_skip | |
887 }; | |
888 | |
889 switch (st->state) { | |
890 | |
891 case sw_start: | |
892 | |
893 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse control"); | |
894 | |
895 st->state = sw_type; | |
896 | |
897 /* fall through */ | |
898 | |
899 case sw_type: | |
900 | |
901 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { | |
902 break; | |
903 } | |
904 | |
905 st->type = st->vlint.value; | |
906 | |
907 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
908 "http3 parse frame type:%ui", st->type); | |
909 | |
910 st->state = sw_length; | |
911 break; | |
912 | |
913 case sw_length: | |
914 | |
915 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { | |
916 break; | |
917 } | |
918 | |
919 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
920 "http3 parse frame len:%uL", st->vlint.value); | |
921 | |
922 st->length = st->vlint.value; | |
923 if (st->length == 0) { | |
924 st->state = sw_type; | |
925 break; | |
926 } | |
927 | |
928 switch (st->type) { | |
929 | |
930 case NGX_HTTP_V3_FRAME_SETTINGS: | |
931 st->state = sw_settings; | |
932 break; | |
933 | |
934 case NGX_HTTP_V3_FRAME_MAX_PUSH_ID: | |
935 st->state = sw_max_push_id; | |
936 break; | |
937 | |
938 default: | |
939 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
940 "http3 parse skip unknown frame"); | |
941 st->state = sw_skip; | |
942 } | |
943 | |
944 break; | |
945 | |
946 case sw_settings: | |
947 | |
948 rc = ngx_http_v3_parse_settings(c, &st->settings, ch); | |
949 | |
950 if (rc == NGX_ERROR) { | |
951 return NGX_ERROR; | |
952 } | |
953 | |
954 if (--st->length > 0) { | |
955 break; | |
956 } | |
957 | |
958 if (rc != NGX_DONE) { | |
959 return NGX_ERROR; | |
960 } | |
961 | |
962 st->state = sw_type; | |
963 break; | |
964 | |
965 case sw_max_push_id: | |
966 | |
967 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { | |
968 break; | |
969 } | |
970 | |
971 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
972 "http3 parse MAX_PUSH_ID:%uL", st->vlint.value); | |
973 | |
974 st->state = sw_type; | |
975 break; | |
976 | |
977 case sw_skip: | |
978 | |
979 if (--st->length == 0) { | |
980 st->state = sw_type; | |
981 } | |
982 | |
983 break; | |
984 } | |
985 | |
986 return NGX_AGAIN; | |
987 } | |
988 | |
989 | |
990 ngx_int_t | |
991 ngx_http_v3_parse_settings(ngx_connection_t *c, | |
992 ngx_http_v3_parse_settings_t *st, u_char ch) | |
993 { | |
994 enum { | |
995 sw_start = 0, | |
996 sw_id, | |
997 sw_value | |
998 }; | |
999 | |
1000 switch (st->state) { | |
1001 | |
1002 case sw_start: | |
1003 | |
1004 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse settings"); | |
1005 | |
1006 st->state = sw_id; | |
1007 | |
1008 /* fall through */ | |
1009 | |
1010 case sw_id: | |
1011 | |
1012 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { | |
1013 break; | |
1014 } | |
1015 | |
1016 st->id = st->vlint.value; | |
1017 st->state = sw_value; | |
1018 break; | |
1019 | |
1020 case sw_value: | |
1021 | |
1022 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { | |
1023 break; | |
1024 } | |
1025 | |
1026 if (ngx_http_v3_set_param(c, st->id, st->vlint.value) != NGX_OK) { | |
1027 return NGX_ERROR; | |
1028 } | |
1029 | |
1030 goto done; | |
1031 } | |
1032 | |
1033 return NGX_AGAIN; | |
1034 | |
1035 done: | |
1036 | |
1037 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse settings done"); | |
1038 | |
1039 st->state = sw_start; | |
1040 return NGX_DONE; | |
1041 } | |
1042 | |
1043 | |
1044 ngx_int_t | |
1045 ngx_http_v3_parse_encoder(ngx_connection_t *c, void *data, u_char ch) | |
1046 { | |
1047 ngx_http_v3_parse_encoder_t *st = data; | |
1048 | |
1049 ngx_int_t rc; | |
1050 enum { | |
1051 sw_start = 0, | |
1052 sw_inr, | |
1053 sw_iwnr, | |
1054 sw_capacity, | |
1055 sw_duplicate | |
1056 }; | |
1057 | |
1058 if (st->state == sw_start) { | |
1059 | |
1060 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1061 "http3 parse encoder instruction"); | |
1062 | |
1063 if (ch & 0x80) { | |
1064 /* Insert With Name Reference */ | |
1065 | |
1066 st->state = sw_inr; | |
1067 | |
1068 } else if (ch & 0x40) { | |
1069 /* Insert Without Name Reference */ | |
1070 | |
1071 st->state = sw_iwnr; | |
1072 | |
1073 } else if (ch & 0x20) { | |
1074 /* Set Dynamic Table Capacity */ | |
1075 | |
1076 st->state = sw_capacity; | |
1077 | |
1078 } else { | |
1079 /* Duplicate */ | |
1080 | |
1081 st->state = sw_duplicate; | |
1082 } | |
1083 } | |
1084 | |
1085 switch (st->state) { | |
1086 | |
1087 case sw_inr: | |
1088 | |
1089 rc = ngx_http_v3_parse_header_inr(c, &st->header, ch); | |
1090 | |
1091 if (rc == NGX_ERROR) { | |
1092 return NGX_ERROR; | |
1093 } | |
1094 | |
1095 if (rc != NGX_DONE) { | |
1096 break; | |
1097 } | |
1098 | |
1099 goto done; | |
1100 | |
1101 case sw_iwnr: | |
1102 | |
1103 rc = ngx_http_v3_parse_header_iwnr(c, &st->header, ch); | |
1104 | |
1105 if (rc == NGX_ERROR) { | |
1106 return NGX_ERROR; | |
1107 } | |
1108 | |
1109 if (rc != NGX_DONE) { | |
1110 break; | |
1111 } | |
1112 | |
1113 goto done; | |
1114 | |
1115 case sw_capacity: | |
1116 | |
1117 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch) != NGX_DONE) { | |
1118 break; | |
1119 } | |
1120 | |
1121 if (ngx_http_v3_set_capacity(c, st->pint.value) != NGX_OK) { | |
1122 return NGX_ERROR; | |
1123 } | |
1124 | |
1125 goto done; | |
1126 | |
1127 case sw_duplicate: | |
1128 | |
1129 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch) != NGX_DONE) { | |
1130 break; | |
1131 } | |
1132 | |
1133 if (ngx_http_v3_duplicate(c, st->pint.value) != NGX_OK) { | |
1134 return NGX_ERROR; | |
1135 } | |
1136 | |
1137 goto done; | |
1138 } | |
1139 | |
1140 return NGX_AGAIN; | |
1141 | |
1142 done: | |
1143 | |
1144 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1145 "http3 parse encoder instruction done"); | |
1146 | |
1147 st->state = sw_start; | |
1148 return NGX_DONE; | |
1149 } | |
1150 | |
1151 | |
1152 ngx_int_t | |
1153 ngx_http_v3_parse_header_inr(ngx_connection_t *c, | |
1154 ngx_http_v3_parse_header_t *st, u_char ch) | |
1155 { | |
1156 ngx_int_t rc; | |
1157 enum { | |
1158 sw_start = 0, | |
1159 sw_name_index, | |
1160 sw_value_len, | |
1161 sw_read_value_len, | |
1162 sw_value | |
1163 }; | |
1164 | |
1165 switch (st->state) { | |
1166 | |
1167 case sw_start: | |
1168 | |
1169 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header inr"); | |
1170 | |
1171 st->dynamic = (ch & 0x40) ? 0 : 1; | |
1172 st->state = sw_name_index; | |
1173 | |
1174 /* fall through */ | |
1175 | |
1176 case sw_name_index: | |
1177 | |
1178 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { | |
1179 break; | |
1180 } | |
1181 | |
1182 st->index = st->pint.value; | |
1183 st->state = sw_value_len; | |
1184 break; | |
1185 | |
1186 case sw_value_len: | |
1187 | |
1188 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
1189 st->state = sw_read_value_len; | |
1190 | |
1191 /* fall through */ | |
1192 | |
1193 case sw_read_value_len: | |
1194 | |
1195 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { | |
1196 break; | |
1197 } | |
1198 | |
1199 st->literal.length = st->pint.value; | |
1200 if (st->literal.length == 0) { | |
1201 goto done; | |
1202 } | |
1203 | |
1204 st->state = sw_value; | |
1205 break; | |
1206 | |
1207 case sw_value: | |
1208 | |
1209 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
1210 | |
1211 if (rc == NGX_ERROR) { | |
1212 return NGX_ERROR; | |
1213 } | |
1214 | |
1215 if (rc == NGX_DONE) { | |
1216 st->value = st->literal.value; | |
1217 goto done; | |
1218 } | |
1219 | |
1220 break; | |
1221 } | |
1222 | |
1223 return NGX_AGAIN; | |
1224 | |
1225 done: | |
1226 | |
1227 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1228 "http3 parse header inr done %s[%ui] \"%V\"", | |
1229 st->dynamic ? "dynamic" : "static", | |
1230 st->index, &st->value); | |
1231 | |
1232 if (ngx_http_v3_ref_insert(c, st->dynamic, st->index, &st->value) != NGX_OK) | |
1233 { | |
1234 return NGX_ERROR; | |
1235 } | |
1236 | |
1237 st->state = sw_start; | |
1238 return NGX_DONE; | |
1239 } | |
1240 | |
1241 | |
1242 ngx_int_t | |
1243 ngx_http_v3_parse_header_iwnr(ngx_connection_t *c, | |
1244 ngx_http_v3_parse_header_t *st, u_char ch) | |
1245 { | |
1246 ngx_int_t rc; | |
1247 enum { | |
1248 sw_start = 0, | |
1249 sw_name_len, | |
1250 sw_name, | |
1251 sw_value_len, | |
1252 sw_read_value_len, | |
1253 sw_value | |
1254 }; | |
1255 | |
1256 switch (st->state) { | |
1257 | |
1258 case sw_start: | |
1259 | |
1260 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1261 "http3 parse header iwnr"); | |
1262 | |
1263 st->literal.huffman = (ch & 0x20) ? 1 : 0; | |
1264 st->state = sw_name_len; | |
1265 | |
1266 /* fall through */ | |
1267 | |
1268 case sw_name_len: | |
1269 | |
1270 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch) != NGX_DONE) { | |
1271 break; | |
1272 } | |
1273 | |
1274 st->literal.length = st->pint.value; | |
1275 if (st->literal.length == 0) { | |
1276 return NGX_ERROR; | |
1277 } | |
1278 | |
1279 st->state = sw_name; | |
1280 break; | |
1281 | |
1282 case sw_name: | |
1283 | |
1284 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
1285 | |
1286 if (rc == NGX_ERROR) { | |
1287 return NGX_ERROR; | |
1288 } | |
1289 | |
1290 if (rc == NGX_DONE) { | |
1291 st->name = st->literal.value; | |
1292 st->state = sw_value_len; | |
1293 } | |
1294 | |
1295 break; | |
1296 | |
1297 case sw_value_len: | |
1298 | |
1299 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
1300 st->state = sw_read_value_len; | |
1301 | |
1302 /* fall through */ | |
1303 | |
1304 case sw_read_value_len: | |
1305 | |
1306 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { | |
1307 break; | |
1308 } | |
1309 | |
1310 st->literal.length = st->pint.value; | |
1311 if (st->literal.length == 0) { | |
1312 goto done; | |
1313 } | |
1314 | |
1315 st->state = sw_value; | |
1316 break; | |
1317 | |
1318 case sw_value: | |
1319 | |
1320 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
1321 | |
1322 if (rc == NGX_ERROR) { | |
1323 return NGX_ERROR; | |
1324 } | |
1325 | |
1326 if (rc == NGX_DONE) { | |
1327 st->value = st->literal.value; | |
1328 goto done; | |
1329 } | |
1330 | |
1331 break; | |
1332 } | |
1333 | |
1334 return NGX_AGAIN; | |
1335 | |
1336 done: | |
1337 | |
1338 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1339 "http3 parse header iwnr done \"%V\":\"%V\"", | |
1340 &st->name, &st->value); | |
1341 | |
1342 if (ngx_http_v3_insert(c, &st->name, &st->value) != NGX_OK) { | |
1343 return NGX_ERROR; | |
1344 } | |
1345 | |
1346 st->state = sw_start; | |
1347 return NGX_DONE; | |
1348 } | |
1349 | |
1350 | |
1351 ngx_int_t | |
1352 ngx_http_v3_parse_decoder(ngx_connection_t *c, void *data, u_char ch) | |
1353 { | |
1354 ngx_http_v3_parse_decoder_t *st = data; | |
1355 | |
1356 enum { | |
1357 sw_start = 0, | |
1358 sw_ack_header, | |
1359 sw_cancel_stream, | |
1360 sw_inc_insert_count | |
1361 }; | |
1362 | |
1363 if (st->state == sw_start) { | |
1364 | |
1365 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1366 "http3 parse decoder instruction"); | |
1367 | |
1368 if (ch & 0x80) { | |
1369 /* Header Acknowledgement */ | |
1370 | |
1371 st->state = sw_ack_header; | |
1372 | |
1373 } else if (ch & 0x40) { | |
1374 /* Stream Cancellation */ | |
1375 | |
1376 st->state = sw_cancel_stream; | |
1377 | |
1378 } else { | |
1379 /* Insert Count Increment */ | |
1380 | |
1381 st->state = sw_inc_insert_count; | |
1382 } | |
1383 } | |
1384 | |
1385 switch (st->state) { | |
1386 | |
1387 case sw_ack_header: | |
1388 | |
1389 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { | |
1390 break; | |
1391 } | |
1392 | |
1393 if (ngx_http_v3_ack_header(c, st->pint.value) != NGX_OK) { | |
1394 return NGX_ERROR; | |
1395 } | |
1396 | |
1397 goto done; | |
1398 | |
1399 case sw_cancel_stream: | |
1400 | |
1401 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { | |
1402 break; | |
1403 } | |
1404 | |
1405 if (ngx_http_v3_cancel_stream(c, st->pint.value) != NGX_OK) { | |
1406 return NGX_ERROR; | |
1407 } | |
1408 | |
1409 goto done; | |
1410 | |
1411 case sw_inc_insert_count: | |
1412 | |
1413 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { | |
1414 break; | |
1415 } | |
1416 | |
1417 if (ngx_http_v3_inc_insert_count(c, st->pint.value) != NGX_OK) { | |
1418 return NGX_ERROR; | |
1419 } | |
1420 | |
1421 goto done; | |
1422 } | |
1423 | |
1424 return NGX_AGAIN; | |
1425 | |
1426 done: | |
1427 | |
1428 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1429 "http3 parse decoder instruction done"); | |
1430 | |
1431 st->state = sw_start; | |
1432 return NGX_DONE; | |
1433 } | |
7761
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1434 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1435 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1436 ngx_int_t |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1437 ngx_http_v3_parse_data(ngx_connection_t *c, ngx_http_v3_parse_data_t *st, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1438 u_char ch) |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1439 { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1440 enum { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1441 sw_start = 0, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1442 sw_type, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1443 sw_length |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1444 }; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1445 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1446 switch (st->state) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1447 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1448 case sw_start: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1449 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1450 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data"); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1451 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1452 st->state = sw_type; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1453 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1454 /* fall through */ |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1455 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1456 case sw_type: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1457 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1458 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1459 break; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1460 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1461 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1462 if (st->vlint.value != NGX_HTTP_V3_FRAME_DATA) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1463 return NGX_ERROR; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1464 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1465 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1466 st->state = sw_length; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1467 break; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1468 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1469 case sw_length: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1470 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1471 if (ngx_http_v3_parse_varlen_int(c, &st->vlint, ch) != NGX_DONE) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1472 break; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1473 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1474 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1475 st->length = st->vlint.value; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1476 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1477 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1478 "http3 parse data frame len:%ui", st->length); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1479 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1480 goto done; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1481 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1482 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1483 return NGX_AGAIN; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1484 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1485 done: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1486 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1487 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data done"); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1488 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1489 st->state = sw_start; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1490 return NGX_DONE; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7693
diff
changeset
|
1491 } |