nxt_http_parse.c (2084:7d479274f334) nxt_http_parse.c (2139:99d792169ffb)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 * Copyright (C) Valentin V. Bartenev
5 */
6
7#include <nxt_main.h>
8
9
10static nxt_int_t nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp,
1
2/*
3 * Copyright (C) NGINX, Inc.
4 * Copyright (C) Valentin V. Bartenev
5 */
6
7#include <nxt_main.h>
8
9
10static nxt_int_t nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp,
11 u_char **pos, u_char *end);
11 u_char **pos, const u_char *end);
12static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp,
12static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp,
13 u_char **pos, u_char *end);
13 u_char **pos, const u_char *end);
14static nxt_int_t nxt_http_parse_field_name(nxt_http_request_parse_t *rp,
14static nxt_int_t nxt_http_parse_field_name(nxt_http_request_parse_t *rp,
15 u_char **pos, u_char *end);
15 u_char **pos, const u_char *end);
16static nxt_int_t nxt_http_parse_field_value(nxt_http_request_parse_t *rp,
16static nxt_int_t nxt_http_parse_field_value(nxt_http_request_parse_t *rp,
17 u_char **pos, u_char *end);
18static u_char *nxt_http_lookup_field_end(u_char *p, u_char *end);
17 u_char **pos, const u_char *end);
18static u_char *nxt_http_lookup_field_end(u_char *p, const u_char *end);
19static nxt_int_t nxt_http_parse_field_end(nxt_http_request_parse_t *rp,
19static nxt_int_t nxt_http_parse_field_end(nxt_http_request_parse_t *rp,
20 u_char **pos, u_char *end);
20 u_char **pos, const u_char *end);
21
22static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp);
23
24static nxt_int_t nxt_http_field_hash_test(nxt_lvlhsh_query_t *lhq, void *data);
25
26static nxt_int_t nxt_http_field_hash_collision(nxt_lvlhsh_query_t *lhq,
27 void *data);
28

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

57 1, 0, 0, 2, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 6, 5,
58
59 /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
61};
62
63
64nxt_inline nxt_http_target_traps_e
21
22static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp);
23
24static nxt_int_t nxt_http_field_hash_test(nxt_lvlhsh_query_t *lhq, void *data);
25
26static nxt_int_t nxt_http_field_hash_collision(nxt_lvlhsh_query_t *lhq,
27 void *data);
28

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

57 1, 0, 0, 2, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 6, 5,
58
59 /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
61};
62
63
64nxt_inline nxt_http_target_traps_e
65nxt_http_parse_target(u_char **pos, u_char *end)
65nxt_http_parse_target(u_char **pos, const u_char *end)
66{
67 u_char *p;
68 nxt_uint_t trap;
69
70 p = *pos;
71
72 while (nxt_fast_path(end - p >= 10)) {
73

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

153 } while (rc == NXT_OK);
154
155 return rc;
156}
157
158
159static nxt_int_t
160nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
66{
67 u_char *p;
68 nxt_uint_t trap;
69
70 p = *pos;
71
72 while (nxt_fast_path(end - p >= 10)) {
73

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

153 } while (rc == NXT_OK);
154
155 return rc;
156}
157
158
159static nxt_int_t
160nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
161 u_char *end)
161 const u_char *end)
162{
163 u_char *p, ch, *after_slash, *args;
164 nxt_int_t rc;
165 nxt_bool_t rest;
166 nxt_http_ver_t ver;
167 nxt_http_target_traps_e trap;
168
169 static const nxt_http_ver_t http11 = { "HTTP/1.1" };

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

474 }
475
476 return NXT_HTTP_PARSE_INVALID;
477}
478
479
480static nxt_int_t
481nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos,
162{
163 u_char *p, ch, *after_slash, *args;
164 nxt_int_t rc;
165 nxt_bool_t rest;
166 nxt_http_ver_t ver;
167 nxt_http_target_traps_e trap;
168
169 static const nxt_http_ver_t http11 = { "HTTP/1.1" };

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

474 }
475
476 return NXT_HTTP_PARSE_INVALID;
477}
478
479
480static nxt_int_t
481nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos,
482 u_char *end)
482 const u_char *end)
483{
484 u_char *p, ch;
485
486 p = *pos;
487
488 ch = *p;
489
490 if (ch == ' ') {

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

512 /* TODO */
513
514 return NXT_HTTP_PARSE_INVALID;
515}
516
517
518static nxt_int_t
519nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos,
483{
484 u_char *p, ch;
485
486 p = *pos;
487
488 ch = *p;
489
490 if (ch == ' ') {

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

512 /* TODO */
513
514 return NXT_HTTP_PARSE_INVALID;
515}
516
517
518static nxt_int_t
519nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos,
520 u_char *end)
520 const u_char *end)
521{
522 u_char *p, c;
523 size_t len;
524 uint32_t hash;
525
526 static const u_char normal[256] nxt_aligned(64) =
527 "\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"
528 /* \s ! " # $ % & ' ( ) * + , . / : ; < = > ? */

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

619 }
620
621 return nxt_http_parse_field_end(rp, pos, end);
622}
623
624
625static nxt_int_t
626nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
521{
522 u_char *p, c;
523 size_t len;
524 uint32_t hash;
525
526 static const u_char normal[256] nxt_aligned(64) =
527 "\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"
528 /* \s ! " # $ % & ' ( ) * + , . / : ; < = > ? */

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

619 }
620
621 return nxt_http_parse_field_end(rp, pos, end);
622}
623
624
625static nxt_int_t
626nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
627 u_char *end)
627 const u_char *end)
628{
629 u_char *p, *start, ch;
630 size_t len;
631
632 p = *pos;
633
634 for ( ;; ) {
635 if (nxt_slow_path(p == end)) {

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

699 rp->field_value.length = len;
700 rp->field_value.start = start;
701
702 return nxt_http_parse_field_end(rp, pos, end);
703}
704
705
706static u_char *
628{
629 u_char *p, *start, ch;
630 size_t len;
631
632 p = *pos;
633
634 for ( ;; ) {
635 if (nxt_slow_path(p == end)) {

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

699 rp->field_value.length = len;
700 rp->field_value.start = start;
701
702 return nxt_http_parse_field_end(rp, pos, end);
703}
704
705
706static u_char *
707nxt_http_lookup_field_end(u_char *p, u_char *end)
707nxt_http_lookup_field_end(u_char *p, const u_char *end)
708{
709 while (nxt_fast_path(end - p >= 16)) {
710
711#define nxt_field_end_test_char(ch) \
712 \
713 if (nxt_slow_path((ch) < 0x20)) { \
714 return &(ch); \
715 }

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

766 }
767
768 return p;
769}
770
771
772static nxt_int_t
773nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos,
708{
709 while (nxt_fast_path(end - p >= 16)) {
710
711#define nxt_field_end_test_char(ch) \
712 \
713 if (nxt_slow_path((ch) < 0x20)) { \
714 return &(ch); \
715 }

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

766 }
767
768 return p;
769}
770
771
772static nxt_int_t
773nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos,
774 u_char *end)
774 const u_char *end)
775{
776 u_char *p;
777 nxt_http_field_t *field;
778
779 p = *pos;
780
781 if (nxt_fast_path(*p == '\r')) {
782 p++;

--- 493 unchanged lines hidden ---
775{
776 u_char *p;
777 nxt_http_field_t *field;
778
779 p = *pos;
780
781 if (nxt_fast_path(*p == '\r')) {
782 p++;

--- 493 unchanged lines hidden ---