Mercurial > hg > nginx
comparison src/http/v3/ngx_http_v3.c @ 8226:268f4389130d quic
Refactored HTTP/3 parser.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 18 Mar 2020 13:46:35 +0300 |
parents | 38c0898b6df7 |
children | b13176e717ba |
comparison
equal
deleted
inserted
replaced
8225:714a19dba6af | 8226:268f4389130d |
---|---|
92 | 92 |
93 *p++ = value & 0x7f; | 93 *p++ = value & 0x7f; |
94 | 94 |
95 return (uintptr_t) p; | 95 return (uintptr_t) p; |
96 } | 96 } |
97 | |
98 | |
99 uint64_t | |
100 ngx_http_v3_decode_varlen_int(u_char *p) | |
101 { | |
102 uint64_t value; | |
103 ngx_uint_t len; | |
104 | |
105 len = *p >> 6; | |
106 value = *p & 0x3f; | |
107 | |
108 while (len--) { | |
109 value = (value << 8) + *p++; | |
110 } | |
111 | |
112 return value; | |
113 } | |
114 | |
115 | |
116 int64_t | |
117 ngx_http_v3_decode_prefix_int(u_char **src, size_t len, ngx_uint_t prefix) | |
118 { | |
119 u_char *p; | |
120 int64_t value, thresh; | |
121 | |
122 if (len == 0) { | |
123 return NGX_ERROR; | |
124 } | |
125 | |
126 p = *src; | |
127 | |
128 thresh = (1 << prefix) - 1; | |
129 value = *p++ & thresh; | |
130 | |
131 if (value != thresh) { | |
132 *src = p; | |
133 return value; | |
134 } | |
135 | |
136 value = 0; | |
137 | |
138 /* XXX handle overflows */ | |
139 | |
140 while (--len) { | |
141 value = (value << 7) + (*p & 0x7f); | |
142 if ((*p++ & 0x80) == 0) { | |
143 *src = p; | |
144 return value + thresh; | |
145 } | |
146 } | |
147 | |
148 return NGX_ERROR; | |
149 } | |
150 | |
151 | |
152 ngx_int_t | |
153 ngx_http_v3_decode_huffman(ngx_connection_t *c, ngx_str_t *s) | |
154 { | |
155 u_char state, *p, *data; | |
156 | |
157 state = 0; | |
158 | |
159 p = ngx_pnalloc(c->pool, s->len * 8 / 5); | |
160 if (p == NULL) { | |
161 return NGX_ERROR; | |
162 } | |
163 | |
164 data = p; | |
165 | |
166 if (ngx_http_v2_huff_decode(&state, s->data, s->len, &p, 1, c->log) | |
167 != NGX_OK) | |
168 { | |
169 return NGX_ERROR; | |
170 } | |
171 | |
172 s->len = p - data; | |
173 s->data = data; | |
174 | |
175 return NGX_OK; | |
176 } |