comparison src/http/v3/ngx_http_v3_parse.c @ 8772:345370fdd32d quic

HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c. Previously it was parsed in ngx_http_v3_streams.c, while the streams were parsed in ngx_http_v3_parse.c. Now all parsing is done in one file. This simplifies parsing API and cleans up ngx_http_v3_streams.c.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 05 May 2021 15:00:17 +0300
parents 0981329169ea
children 3509b9dcfb47
comparison
equal deleted inserted replaced
8771:0981329169ea 8772:345370fdd32d
11 11
12 12
13 #define ngx_http_v3_is_v2_frame(type) \ 13 #define ngx_http_v3_is_v2_frame(type) \
14 ((type) == 0x02 || (type) == 0x06 || (type) == 0x08 || (type) == 0x09) 14 ((type) == 0x02 || (type) == 0x06 || (type) == 0x08 || (type) == 0x09)
15 15
16
17 static ngx_int_t ngx_http_v3_parse_settings(ngx_connection_t *c,
18 ngx_http_v3_parse_settings_t *st, u_char ch);
19 16
20 static ngx_int_t ngx_http_v3_parse_varlen_int(ngx_connection_t *c, 17 static ngx_int_t ngx_http_v3_parse_varlen_int(ngx_connection_t *c,
21 ngx_http_v3_parse_varlen_int_t *st, u_char ch); 18 ngx_http_v3_parse_varlen_int_t *st, u_char ch);
22 static ngx_int_t ngx_http_v3_parse_prefix_int(ngx_connection_t *c, 19 static ngx_int_t ngx_http_v3_parse_prefix_int(ngx_connection_t *c,
23 ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, u_char ch); 20 ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, u_char ch);
37 static ngx_int_t ngx_http_v3_parse_header_pbi(ngx_connection_t *c, 34 static ngx_int_t ngx_http_v3_parse_header_pbi(ngx_connection_t *c,
38 ngx_http_v3_parse_header_t *st, u_char ch); 35 ngx_http_v3_parse_header_t *st, u_char ch);
39 static ngx_int_t ngx_http_v3_parse_header_lpbi(ngx_connection_t *c, 36 static ngx_int_t ngx_http_v3_parse_header_lpbi(ngx_connection_t *c,
40 ngx_http_v3_parse_header_t *st, u_char ch); 37 ngx_http_v3_parse_header_t *st, u_char ch);
41 38
39 static ngx_int_t ngx_http_v3_parse_control(ngx_connection_t *c,
40 ngx_http_v3_parse_control_t *st, u_char ch);
41 static ngx_int_t ngx_http_v3_parse_settings(ngx_connection_t *c,
42 ngx_http_v3_parse_settings_t *st, u_char ch);
43
44 static ngx_int_t ngx_http_v3_parse_encoder(ngx_connection_t *c,
45 ngx_http_v3_parse_encoder_t *st, u_char ch);
42 static ngx_int_t ngx_http_v3_parse_header_inr(ngx_connection_t *c, 46 static ngx_int_t ngx_http_v3_parse_header_inr(ngx_connection_t *c,
43 ngx_http_v3_parse_header_t *st, u_char ch); 47 ngx_http_v3_parse_header_t *st, u_char ch);
44 static ngx_int_t ngx_http_v3_parse_header_iwnr(ngx_connection_t *c, 48 static ngx_int_t ngx_http_v3_parse_header_iwnr(ngx_connection_t *c,
45 ngx_http_v3_parse_header_t *st, u_char ch); 49 ngx_http_v3_parse_header_t *st, u_char ch);
50
51 static ngx_int_t ngx_http_v3_parse_decoder(ngx_connection_t *c,
52 ngx_http_v3_parse_decoder_t *st, u_char ch);
46 53
47 static ngx_int_t ngx_http_v3_parse_lookup(ngx_connection_t *c, 54 static ngx_int_t ngx_http_v3_parse_lookup(ngx_connection_t *c,
48 ngx_uint_t dynamic, ngx_uint_t index, ngx_str_t *name, ngx_str_t *value); 55 ngx_uint_t dynamic, ngx_uint_t index, ngx_str_t *name, ngx_str_t *value);
49 56
50 57
984 991
985 return NGX_OK; 992 return NGX_OK;
986 } 993 }
987 994
988 995
989 ngx_int_t 996 static ngx_int_t
990 ngx_http_v3_parse_control(ngx_connection_t *c, void *data, u_char ch) 997 ngx_http_v3_parse_control(ngx_connection_t *c, ngx_http_v3_parse_control_t *st,
991 { 998 u_char ch)
992 ngx_http_v3_parse_control_t *st = data; 999 {
993
994 ngx_int_t rc; 1000 ngx_int_t rc;
995 enum { 1001 enum {
996 sw_start = 0, 1002 sw_start = 0,
997 sw_first_type, 1003 sw_first_type,
998 sw_type, 1004 sw_type,
1206 st->state = sw_start; 1212 st->state = sw_start;
1207 return NGX_DONE; 1213 return NGX_DONE;
1208 } 1214 }
1209 1215
1210 1216
1211 ngx_int_t 1217 static ngx_int_t
1212 ngx_http_v3_parse_encoder(ngx_connection_t *c, void *data, u_char ch) 1218 ngx_http_v3_parse_encoder(ngx_connection_t *c, ngx_http_v3_parse_encoder_t *st,
1213 { 1219 u_char ch)
1214 ngx_http_v3_parse_encoder_t *st = data; 1220 {
1215
1216 ngx_int_t rc; 1221 ngx_int_t rc;
1217 enum { 1222 enum {
1218 sw_start = 0, 1223 sw_start = 0,
1219 sw_inr, 1224 sw_inr,
1220 sw_iwnr, 1225 sw_iwnr,
1498 st->state = sw_start; 1503 st->state = sw_start;
1499 return NGX_DONE; 1504 return NGX_DONE;
1500 } 1505 }
1501 1506
1502 1507
1503 ngx_int_t 1508 static ngx_int_t
1504 ngx_http_v3_parse_decoder(ngx_connection_t *c, void *data, u_char ch) 1509 ngx_http_v3_parse_decoder(ngx_connection_t *c, ngx_http_v3_parse_decoder_t *st,
1505 { 1510 u_char ch)
1506 ngx_http_v3_parse_decoder_t *st = data; 1511 {
1507
1508 ngx_int_t rc; 1512 ngx_int_t rc;
1509 enum { 1513 enum {
1510 sw_start = 0, 1514 sw_start = 0,
1511 sw_ack_header, 1515 sw_ack_header,
1512 sw_cancel_stream, 1516 sw_cancel_stream,
1672 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data done"); 1676 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data done");
1673 1677
1674 st->state = sw_start; 1678 st->state = sw_start;
1675 return NGX_DONE; 1679 return NGX_DONE;
1676 } 1680 }
1681
1682
1683 ngx_int_t
1684 ngx_http_v3_parse_uni(ngx_connection_t *c, ngx_http_v3_parse_uni_t *st,
1685 u_char ch)
1686 {
1687 ngx_int_t rc;
1688 enum {
1689 sw_start = 0,
1690 sw_type,
1691 sw_control,
1692 sw_encoder,
1693 sw_decoder,
1694 sw_unknown
1695 };
1696
1697 switch (st->state) {
1698 case sw_start:
1699
1700 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse uni");
1701
1702 st->state = sw_type;
1703
1704 /* fall through */
1705
1706 case sw_type:
1707
1708 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch);
1709 if (rc != NGX_DONE) {
1710 return rc;
1711 }
1712
1713 rc = ngx_http_v3_register_uni_stream(c, st->vlint.value);
1714 if (rc != NGX_OK) {
1715 return rc;
1716 }
1717
1718 switch (st->vlint.value) {
1719 case NGX_HTTP_V3_STREAM_CONTROL:
1720 st->state = sw_control;
1721 break;
1722
1723 case NGX_HTTP_V3_STREAM_ENCODER:
1724 st->state = sw_encoder;
1725 break;
1726
1727 case NGX_HTTP_V3_STREAM_DECODER:
1728 st->state = sw_decoder;
1729 break;
1730
1731 default:
1732 st->state = sw_unknown;
1733 }
1734
1735 break;
1736
1737 case sw_control:
1738
1739 rc = ngx_http_v3_parse_control(c, &st->u.control, ch);
1740 if (rc != NGX_OK) {
1741 return rc;
1742 }
1743
1744 break;
1745
1746 case sw_encoder:
1747
1748 rc = ngx_http_v3_parse_encoder(c, &st->u.encoder, ch);
1749 if (rc != NGX_OK) {
1750 return rc;
1751 }
1752
1753 break;
1754
1755 case sw_decoder:
1756
1757 rc = ngx_http_v3_parse_decoder(c, &st->u.decoder, ch);
1758 if (rc != NGX_OK) {
1759 return rc;
1760 }
1761
1762 break;
1763
1764 case sw_unknown:
1765 break;
1766 }
1767
1768 return NGX_AGAIN;
1769 }