nxt_http_parse.c (112:6f1809436b10) nxt_http_parse.c (409:703c6b2bb0ac)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 * Copyright (C) Valentin V. Bartenev
5 */
6
7#include <nxt_main.h>
8

--- 75 unchanged lines hidden (view full) ---

84nxt_inline nxt_http_target_traps_e
85nxt_http_parse_target(u_char **pos, u_char *end)
86{
87 u_char *p;
88 nxt_uint_t trap;
89
90 p = *pos;
91
1
2/*
3 * Copyright (C) NGINX, Inc.
4 * Copyright (C) Valentin V. Bartenev
5 */
6
7#include <nxt_main.h>
8

--- 75 unchanged lines hidden (view full) ---

84nxt_inline nxt_http_target_traps_e
85nxt_http_parse_target(u_char **pos, u_char *end)
86{
87 u_char *p;
88 nxt_uint_t trap;
89
90 p = *pos;
91
92 for ( ;; ) {
93 if (nxt_slow_path(end - p < 10)) {
94 return NXT_HTTP_TARGET_AGAIN;
95 }
92 while (nxt_fast_path(end - p >= 10)) {
96
93
97#define nxt_http_parse_target_step \
98 { \
99 trap = nxt_http_target_chars[*p]; \
94#define nxt_target_test_char(ch) \
100 \
95 \
101 if (nxt_slow_path(trap != 0)) { \
102 break; \
103 } \
96 trap = nxt_http_target_chars[ch]; \
104 \
97 \
105 p++; \
98 if (nxt_slow_path(trap != 0)) { \
99 *pos = &(ch); \
100 return trap; \
106 }
107
101 }
102
108 nxt_http_parse_target_step
109 nxt_http_parse_target_step
110 nxt_http_parse_target_step
111 nxt_http_parse_target_step
103/* enddef */
112
104
113 nxt_http_parse_target_step
114 nxt_http_parse_target_step
115 nxt_http_parse_target_step
116 nxt_http_parse_target_step
105 nxt_target_test_char(p[0]);
106 nxt_target_test_char(p[1]);
107 nxt_target_test_char(p[2]);
108 nxt_target_test_char(p[3]);
117
109
118 nxt_http_parse_target_step
119 nxt_http_parse_target_step
110 nxt_target_test_char(p[4]);
111 nxt_target_test_char(p[5]);
112 nxt_target_test_char(p[6]);
113 nxt_target_test_char(p[7]);
120
114
121#undef nxt_http_parse_target_step
115 nxt_target_test_char(p[8]);
116 nxt_target_test_char(p[9]);
117
118 p += 10;
122 }
123
119 }
120
124 *pos = p;
125
126 return trap;
121 return NXT_HTTP_TARGET_AGAIN;
127}
128
129
130nxt_int_t
131nxt_http_parse_request(nxt_http_request_parse_t *rp, nxt_buf_mem_t *b)
132{
133 nxt_int_t rc;
134

--- 20 unchanged lines hidden (view full) ---

155
156 static const nxt_http_ver_t http11 = { "HTTP/1.1" };
157 static const nxt_http_ver_t http10 = { "HTTP/1.0" };
158
159 p = *pos;
160
161 rp->method.start = p;
162
122}
123
124
125nxt_int_t
126nxt_http_parse_request(nxt_http_request_parse_t *rp, nxt_buf_mem_t *b)
127{
128 nxt_int_t rc;
129

--- 20 unchanged lines hidden (view full) ---

150
151 static const nxt_http_ver_t http11 = { "HTTP/1.1" };
152 static const nxt_http_ver_t http10 = { "HTTP/1.0" };
153
154 p = *pos;
155
156 rp->method.start = p;
157
163 for ( ;; p++) {
158 for ( ;; ) {
164
159
165 for ( ;; ) {
166 if (nxt_slow_path(end - p < 12)) {
167 return NXT_AGAIN;
168 }
160 while (nxt_fast_path(end - p >= 8)) {
169
161
170#define nxt_http_parse_request_line_step \
171 { \
172 ch = *p; \
162#define nxt_method_test_char(ch) \
173 \
163 \
174 if (nxt_slow_path(ch < 'A' || ch > 'Z')) { \
175 break; \
176 } \
177 \
178 p++; \
164 if (nxt_slow_path((ch) < 'A' || (ch) > 'Z')) { \
165 p = &(ch); \
166 goto method_unusual_char; \
179 }
180
167 }
168
181 nxt_http_parse_request_line_step
182 nxt_http_parse_request_line_step
183 nxt_http_parse_request_line_step
184 nxt_http_parse_request_line_step
169/* enddef */
185
170
186 nxt_http_parse_request_line_step
187 nxt_http_parse_request_line_step
188 nxt_http_parse_request_line_step
189 nxt_http_parse_request_line_step
171 nxt_method_test_char(p[0]);
172 nxt_method_test_char(p[1]);
173 nxt_method_test_char(p[2]);
174 nxt_method_test_char(p[3]);
190
175
191#undef nxt_http_parse_request_line_step
176 nxt_method_test_char(p[4]);
177 nxt_method_test_char(p[5]);
178 nxt_method_test_char(p[6]);
179 nxt_method_test_char(p[7]);
180
181 p += 8;
192 }
193
182 }
183
184 return NXT_AGAIN;
185
186 method_unusual_char:
187
188 ch = *p;
189
194 if (nxt_fast_path(ch == ' ')) {
195 rp->method.length = p - rp->method.start;
196 break;
197 }
198
199 if (ch == '_' || ch == '-') {
190 if (nxt_fast_path(ch == ' ')) {
191 rp->method.length = p - rp->method.start;
192 break;
193 }
194
195 if (ch == '_' || ch == '-') {
196 p++;
200 continue;
201 }
202
203 if (rp->method.start == p && (ch == NXT_CR || ch == NXT_LF)) {
204 rp->method.start++;
197 continue;
198 }
199
200 if (rp->method.start == p && (ch == NXT_CR || ch == NXT_LF)) {
201 rp->method.start++;
202 p++;
205 continue;
206 }
207
208 return NXT_ERROR;
209 }
210
211 p++;
212

--- 243 unchanged lines hidden (view full) ---

456 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
457 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
458
459 p = *pos;
460
461 size = end - p;
462 i = rp->field_name.length;
463
203 continue;
204 }
205
206 return NXT_ERROR;
207 }
208
209 p++;
210

--- 243 unchanged lines hidden (view full) ---

454 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
455 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
456
457 p = *pos;
458
459 size = end - p;
460 i = rp->field_name.length;
461
464#define nxt_http_parse_field_name_step \
465 { \
462 while (nxt_fast_path(size - i >= 8)) {
463
464#define nxt_field_name_test_char(i) \
465 \
466 ch = p[i]; \
467 c = normal[ch]; \
468 \
469 if (nxt_slow_path(c == '\0')) { \
470 goto name_end; \
471 } \
472 \
466 ch = p[i]; \
467 c = normal[ch]; \
468 \
469 if (nxt_slow_path(c == '\0')) { \
470 goto name_end; \
471 } \
472 \
473 rp->field_key.str[i % 32] = c; \
474 i++; \
475 }
473 rp->field_key.str[i % 32] = c;
476
474
477 while (nxt_fast_path(size - i >= 8)) {
478 nxt_http_parse_field_name_step
479 nxt_http_parse_field_name_step
480 nxt_http_parse_field_name_step
481 nxt_http_parse_field_name_step
475/* enddef */
482
476
483 nxt_http_parse_field_name_step
484 nxt_http_parse_field_name_step
485 nxt_http_parse_field_name_step
486 nxt_http_parse_field_name_step
477 nxt_field_name_test_char(i); i++;
478 nxt_field_name_test_char(i); i++;
479 nxt_field_name_test_char(i); i++;
480 nxt_field_name_test_char(i); i++;
481
482 nxt_field_name_test_char(i); i++;
483 nxt_field_name_test_char(i); i++;
484 nxt_field_name_test_char(i); i++;
485 nxt_field_name_test_char(i); i++;
487 }
488
489 while (nxt_fast_path(i != size)) {
486 }
487
488 while (nxt_fast_path(i != size)) {
490 nxt_http_parse_field_name_step
489 nxt_field_name_test_char(i); i++;
491 }
492
490 }
491
493#undef nxt_http_parse_field_name_step
494
495 rp->field_name.length = i;
496 rp->handler = &nxt_http_parse_field_name;
497
498 return NXT_AGAIN;
499
500name_end:
501
502 if (nxt_fast_path(ch == ':')) {

--- 76 unchanged lines hidden (view full) ---

579
580 return nxt_http_parse_field_end(rp, pos, end);
581}
582
583
584static u_char *
585nxt_http_lookup_field_end(u_char *p, u_char *end)
586{
492 rp->field_name.length = i;
493 rp->handler = &nxt_http_parse_field_name;
494
495 return NXT_AGAIN;
496
497name_end:
498
499 if (nxt_fast_path(ch == ':')) {

--- 76 unchanged lines hidden (view full) ---

576
577 return nxt_http_parse_field_end(rp, pos, end);
578}
579
580
581static u_char *
582nxt_http_lookup_field_end(u_char *p, u_char *end)
583{
587 nxt_uint_t n;
584 while (nxt_fast_path(end - p >= 16)) {
588
585
589#define nxt_http_lookup_field_end_step \
590 { \
591 if (nxt_slow_path(*p < 0x10)) { \
592 return p; \
593 } \
586#define nxt_field_end_test_char(ch) \
594 \
587 \
595 p++; \
596 }
588 if (nxt_slow_path((ch) < 0x10)) { \
589 return &(ch); \
590 }
597
591
598 for (n = (end - p) / 16; nxt_fast_path(n != 0); n--) {
599 nxt_http_lookup_field_end_step
600 nxt_http_lookup_field_end_step
601 nxt_http_lookup_field_end_step
602 nxt_http_lookup_field_end_step
592/* enddef */
603
593
604 nxt_http_lookup_field_end_step
605 nxt_http_lookup_field_end_step
606 nxt_http_lookup_field_end_step
607 nxt_http_lookup_field_end_step
594 nxt_field_end_test_char(p[0]);
595 nxt_field_end_test_char(p[1]);
596 nxt_field_end_test_char(p[2]);
597 nxt_field_end_test_char(p[3]);
608
598
609 nxt_http_lookup_field_end_step
610 nxt_http_lookup_field_end_step
611 nxt_http_lookup_field_end_step
612 nxt_http_lookup_field_end_step
599 nxt_field_end_test_char(p[4]);
600 nxt_field_end_test_char(p[5]);
601 nxt_field_end_test_char(p[6]);
602 nxt_field_end_test_char(p[7]);
613
603
614 nxt_http_lookup_field_end_step
615 nxt_http_lookup_field_end_step
616 nxt_http_lookup_field_end_step
617 nxt_http_lookup_field_end_step
604 nxt_field_end_test_char(p[8]);
605 nxt_field_end_test_char(p[9]);
606 nxt_field_end_test_char(p[10]);
607 nxt_field_end_test_char(p[11]);
608
609 nxt_field_end_test_char(p[12]);
610 nxt_field_end_test_char(p[13]);
611 nxt_field_end_test_char(p[14]);
612 nxt_field_end_test_char(p[15]);
613
614 p += 16;
618 }
619
615 }
616
620 for (n = (end - p) / 4; nxt_fast_path(n != 0); n--) {
621 nxt_http_lookup_field_end_step
622 nxt_http_lookup_field_end_step
623 nxt_http_lookup_field_end_step
624 nxt_http_lookup_field_end_step
617 while (nxt_fast_path(end - p >= 4)) {
618
619 nxt_field_end_test_char(p[0]);
620 nxt_field_end_test_char(p[1]);
621 nxt_field_end_test_char(p[2]);
622 nxt_field_end_test_char(p[3]);
623
624 p += 4;
625 }
626
627 switch (end - p) {
628 case 3:
625 }
626
627 switch (end - p) {
628 case 3:
629 nxt_http_lookup_field_end_step
629 nxt_field_end_test_char(*p); p++;
630 /* Fall through. */
631 case 2:
630 /* Fall through. */
631 case 2:
632 nxt_http_lookup_field_end_step
632 nxt_field_end_test_char(*p); p++;
633 /* Fall through. */
634 case 1:
633 /* Fall through. */
634 case 1:
635 nxt_http_lookup_field_end_step
635 nxt_field_end_test_char(*p); p++;
636 /* Fall through. */
637 case 0:
638 break;
639 default:
640 nxt_unreachable();
641 }
642
636 /* Fall through. */
637 case 0:
638 break;
639 default:
640 nxt_unreachable();
641 }
642
643#undef nxt_http_lookup_field_end_step
644
645 return p;
646}
647
648
649static nxt_int_t
650nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos,
651 u_char *end)
652{

--- 570 unchanged lines hidden ---
643 return p;
644}
645
646
647static nxt_int_t
648nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos,
649 u_char *end)
650{

--- 570 unchanged lines hidden ---