diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-06-14 14:36:55 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-06-20 23:22:53 +0300 |
commit | 4e8e5e653d7862378e4f3522905e2f4b4ed4067b (patch) | |
tree | 1231117d7efe247381ef40f007bd81372f0c624d /src/microhttpd | |
parent | eaf1fa0889e9f9621f115ad5f13084e693ddb981 (diff) | |
download | libmicrohttpd-4e8e5e653d7862378e4f3522905e2f4b4ed4067b.tar.gz libmicrohttpd-4e8e5e653d7862378e4f3522905e2f4b4ed4067b.zip |
Removed request line and headers processing old functions and variables
Diffstat (limited to 'src/microhttpd')
-rw-r--r-- | src/microhttpd/connection.c | 222 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 17 | ||||
-rw-r--r-- | src/microhttpd/test_auth_parse.c | 13 |
3 files changed, 6 insertions, 246 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 2020b76b..eacf7411 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -2749,8 +2749,6 @@ transmit_error_response_len (struct MHD_Connection *connection, | |||
2749 | connection->rq.method = NULL; | 2749 | connection->rq.method = NULL; |
2750 | connection->rq.url = NULL; | 2750 | connection->rq.url = NULL; |
2751 | connection->rq.url_len = 0; | 2751 | connection->rq.url_len = 0; |
2752 | connection->rq.last = NULL; | ||
2753 | connection->rq.colon = NULL; | ||
2754 | connection->rq.headers_received = NULL; | 2752 | connection->rq.headers_received = NULL; |
2755 | connection->rq.headers_received_tail = NULL; | 2753 | connection->rq.headers_received_tail = NULL; |
2756 | connection->write_buffer = NULL; | 2754 | connection->write_buffer = NULL; |
@@ -2985,81 +2983,6 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2985 | 2983 | ||
2986 | 2984 | ||
2987 | /** | 2985 | /** |
2988 | * Parse a single line of the HTTP header. Advance read_buffer (!) | ||
2989 | * appropriately. If the current line does not fit, consider growing | ||
2990 | * the buffer. If the line is far too long, close the connection. If | ||
2991 | * no line is found (incomplete, buffer too small, line too long), | ||
2992 | * return NULL. Otherwise return a pointer to the line. | ||
2993 | * | ||
2994 | * @param connection connection we're processing | ||
2995 | * @param[out] line_len pointer to variable that receive | ||
2996 | * length of line or NULL | ||
2997 | * @return NULL if no full line is available; note that the returned | ||
2998 | * string will not be 0-termianted | ||
2999 | */ | ||
3000 | static char * | ||
3001 | get_next_header_line (struct MHD_Connection *connection, | ||
3002 | size_t *line_len) | ||
3003 | { | ||
3004 | char *rbuf; | ||
3005 | size_t pos; | ||
3006 | |||
3007 | if (0 == connection->read_buffer_offset) | ||
3008 | return NULL; | ||
3009 | pos = 0; | ||
3010 | rbuf = connection->read_buffer; | ||
3011 | mhd_assert (NULL != rbuf); | ||
3012 | |||
3013 | do | ||
3014 | { | ||
3015 | const char c = rbuf[pos]; | ||
3016 | bool found; | ||
3017 | found = false; | ||
3018 | if ( ('\r' == c) && (pos < connection->read_buffer_offset - 1) && | ||
3019 | ('\n' == rbuf[pos + 1]) ) | ||
3020 | { /* Found CRLF */ | ||
3021 | found = true; | ||
3022 | if (line_len) | ||
3023 | *line_len = pos; | ||
3024 | rbuf[pos++] = 0; /* Replace CR with zero */ | ||
3025 | rbuf[pos++] = 0; /* Replace LF with zero */ | ||
3026 | } | ||
3027 | else if ('\n' == c) /* TODO: Add MHD option to disallow */ | ||
3028 | { /* Found bare LF */ | ||
3029 | found = true; | ||
3030 | if (line_len) | ||
3031 | *line_len = pos; | ||
3032 | rbuf[pos++] = 0; /* Replace LF with zero */ | ||
3033 | } | ||
3034 | if (found) | ||
3035 | { | ||
3036 | connection->read_buffer += pos; | ||
3037 | connection->read_buffer_size -= pos; | ||
3038 | connection->read_buffer_offset -= pos; | ||
3039 | return rbuf; | ||
3040 | } | ||
3041 | } while (++pos < connection->read_buffer_offset); | ||
3042 | |||
3043 | /* not found, consider growing... */ | ||
3044 | if ( (connection->read_buffer_offset == connection->read_buffer_size) && | ||
3045 | (! try_grow_read_buffer (connection, true)) ) | ||
3046 | { | ||
3047 | if (NULL != connection->rq.url) | ||
3048 | transmit_error_response_static (connection, | ||
3049 | MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, | ||
3050 | REQUEST_TOO_BIG); | ||
3051 | else | ||
3052 | transmit_error_response_static (connection, | ||
3053 | MHD_HTTP_URI_TOO_LONG, | ||
3054 | REQUEST_TOO_BIG); | ||
3055 | } | ||
3056 | if (line_len) | ||
3057 | *line_len = 0; | ||
3058 | return NULL; | ||
3059 | } | ||
3060 | |||
3061 | |||
3062 | /** | ||
3063 | * Add an entry to the HTTP headers of a connection. If this fails, | 2986 | * Add an entry to the HTTP headers of a connection. If this fails, |
3064 | * transmit an error response (request too big). | 2987 | * transmit an error response (request too big). |
3065 | * | 2988 | * |
@@ -3879,150 +3802,6 @@ check_write_done (struct MHD_Connection *connection, | |||
3879 | 3802 | ||
3880 | 3803 | ||
3881 | /** | 3804 | /** |
3882 | * We have received (possibly the beginning of) a line in the | ||
3883 | * header (or footer). Validate (check for ":") and prepare | ||
3884 | * to process. | ||
3885 | * | ||
3886 | * @param connection connection we're processing | ||
3887 | * @param line line from the header to process | ||
3888 | * @return #MHD_YES on success, #MHD_NO on error (malformed @a line) | ||
3889 | */ | ||
3890 | static enum MHD_Result | ||
3891 | process_header_line (struct MHD_Connection *connection, | ||
3892 | char *line) | ||
3893 | { | ||
3894 | char *colon; | ||
3895 | |||
3896 | /* line should be normal header line, find colon */ | ||
3897 | colon = strchr (line, ':'); | ||
3898 | if (NULL == colon) | ||
3899 | { | ||
3900 | /* error in header line, die hard */ | ||
3901 | return MHD_NO; | ||
3902 | } | ||
3903 | if (-3 < connection->daemon->client_discipline) | ||
3904 | { | ||
3905 | /* check for whitespace before colon, which is not allowed | ||
3906 | by RFC 7230 section 3.2.4; we count space ' ' and | ||
3907 | tab '\t', but not '\r\n' as those would have ended the line. */ | ||
3908 | const char *white; | ||
3909 | |||
3910 | white = strchr (line, ' '); | ||
3911 | if ( (NULL != white) && | ||
3912 | (white < colon) ) | ||
3913 | return MHD_NO; | ||
3914 | white = strchr (line, '\t'); | ||
3915 | if ( (NULL != white) && | ||
3916 | (white < colon) ) | ||
3917 | return MHD_NO; | ||
3918 | } | ||
3919 | /* zero-terminate header */ | ||
3920 | colon[0] = '\0'; | ||
3921 | colon++; /* advance to value */ | ||
3922 | while ( ('\0' != colon[0]) && | ||
3923 | ( (' ' == colon[0]) || | ||
3924 | ('\t' == colon[0]) ) ) | ||
3925 | colon++; | ||
3926 | /* we do the actual adding of the connection | ||
3927 | header at the beginning of the while | ||
3928 | loop since we need to be able to inspect | ||
3929 | the *next* header line (in case it starts | ||
3930 | with a space...) */ | ||
3931 | connection->rq.last = line; | ||
3932 | connection->rq.colon = colon; | ||
3933 | return MHD_YES; | ||
3934 | } | ||
3935 | |||
3936 | |||
3937 | /** | ||
3938 | * Process a header value that spans multiple lines. | ||
3939 | * The previous line(s) are in connection->last. | ||
3940 | * | ||
3941 | * @param connection connection we're processing | ||
3942 | * @param line the current input line | ||
3943 | * @param kind if the line is complete, add a header | ||
3944 | * of the given kind | ||
3945 | * @return #MHD_YES if the line was processed successfully | ||
3946 | */ | ||
3947 | static enum MHD_Result | ||
3948 | process_broken_line (struct MHD_Connection *connection, | ||
3949 | char *line, | ||
3950 | enum MHD_ValueKind kind) | ||
3951 | { | ||
3952 | char *last; | ||
3953 | char *tmp; | ||
3954 | size_t last_len; | ||
3955 | size_t tmp_len; | ||
3956 | |||
3957 | last = connection->rq.last; | ||
3958 | if ( (' ' == line[0]) || | ||
3959 | ('\t' == line[0]) ) | ||
3960 | { | ||
3961 | /* value was continued on the next line, see | ||
3962 | http://www.jmarshall.com/easy/http/ */ | ||
3963 | last_len = strlen (last); | ||
3964 | /* skip whitespace at start of 2nd line */ | ||
3965 | tmp = line; | ||
3966 | while ( (' ' == tmp[0]) || | ||
3967 | ('\t' == tmp[0]) ) | ||
3968 | tmp++; | ||
3969 | tmp_len = strlen (tmp); | ||
3970 | /* FIXME: we might be able to do this better (faster!), as most | ||
3971 | likely 'last' and 'line' should already be adjacent in | ||
3972 | memory; however, doing this right gets tricky if we have a | ||
3973 | value continued over multiple lines (in which case we need to | ||
3974 | record how often we have done this so we can check for | ||
3975 | adjacency); also, in the case where these are not adjacent | ||
3976 | (not sure how it can happen!), we would want to allocate from | ||
3977 | the end of the pool, so as to not destroy the read-buffer's | ||
3978 | ability to grow nicely. */ | ||
3979 | last = MHD_pool_reallocate (connection->pool, | ||
3980 | last, | ||
3981 | last_len + 1, | ||
3982 | last_len + tmp_len + 1); | ||
3983 | if (NULL == last) | ||
3984 | { | ||
3985 | transmit_error_response_static (connection, | ||
3986 | MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, | ||
3987 | REQUEST_TOO_BIG); | ||
3988 | return MHD_NO; | ||
3989 | } | ||
3990 | memcpy (&last[last_len], | ||
3991 | tmp, | ||
3992 | tmp_len + 1); | ||
3993 | connection->rq.last = last; | ||
3994 | return MHD_YES; /* possibly more than 2 lines... */ | ||
3995 | } | ||
3996 | mhd_assert ( (NULL != last) && | ||
3997 | (NULL != connection->rq.colon) ); | ||
3998 | if (MHD_NO == | ||
3999 | connection_add_header (connection, | ||
4000 | last, | ||
4001 | strlen (last), | ||
4002 | connection->rq.colon, | ||
4003 | strlen (connection->rq.colon), | ||
4004 | kind)) | ||
4005 | { | ||
4006 | /* Error has been queued by connection_add_header() */ | ||
4007 | return MHD_NO; | ||
4008 | } | ||
4009 | /* we still have the current line to deal with... */ | ||
4010 | if (0 != line[0]) | ||
4011 | { | ||
4012 | if (MHD_NO == process_header_line (connection, | ||
4013 | line)) | ||
4014 | { | ||
4015 | transmit_error_response_static (connection, | ||
4016 | MHD_HTTP_BAD_REQUEST, | ||
4017 | REQUEST_MALFORMED); | ||
4018 | return MHD_NO; | ||
4019 | } | ||
4020 | } | ||
4021 | return MHD_YES; | ||
4022 | } | ||
4023 | |||
4024 | |||
4025 | /** | ||
4026 | * Parse the various headers; figure out the size | 3805 | * Parse the various headers; figure out the size |
4027 | * of the upload and make sure the headers follow | 3806 | * of the upload and make sure the headers follow |
4028 | * the protocol. Advance to the appropriate state. | 3807 | * the protocol. Advance to the appropriate state. |
@@ -6369,7 +6148,6 @@ enum MHD_Result | |||
6369 | MHD_connection_handle_idle (struct MHD_Connection *connection) | 6148 | MHD_connection_handle_idle (struct MHD_Connection *connection) |
6370 | { | 6149 | { |
6371 | struct MHD_Daemon *daemon = connection->daemon; | 6150 | struct MHD_Daemon *daemon = connection->daemon; |
6372 | char *line; | ||
6373 | enum MHD_Result ret; | 6151 | enum MHD_Result ret; |
6374 | #ifdef MHD_USE_THREADS | 6152 | #ifdef MHD_USE_THREADS |
6375 | mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \ | 6153 | mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \ |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index e07ad6de..0ea0953e 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1199,23 +1199,6 @@ struct MHD_Request | |||
1199 | * The data of the request line / request headers processing | 1199 | * The data of the request line / request headers processing |
1200 | */ | 1200 | */ |
1201 | union MHD_HeadersProcessing hdrs; | 1201 | union MHD_HeadersProcessing hdrs; |
1202 | |||
1203 | /** | ||
1204 | * Last incomplete header line during parsing of headers. | ||
1205 | * Allocated in pool. Only valid if state is | ||
1206 | * either #MHD_CONNECTION_REQ_HEADERS_RECEIVING or | ||
1207 | * #MHD_CONNECTION_FOOTERS_RECEIVING. | ||
1208 | */ | ||
1209 | char *last; | ||
1210 | |||
1211 | /** | ||
1212 | * Position after the colon on the last incomplete header | ||
1213 | * line during parsing of headers. | ||
1214 | * Allocated in pool. Only valid if state is | ||
1215 | * either #MHD_CONNECTION_REQ_HEADERS_RECEIVING or | ||
1216 | * #MHD_CONNECTION_FOOTERS_RECEIVING. | ||
1217 | */ | ||
1218 | char *colon; | ||
1219 | }; | 1202 | }; |
1220 | 1203 | ||
1221 | 1204 | ||
diff --git a/src/microhttpd/test_auth_parse.c b/src/microhttpd/test_auth_parse.c index 8c11499b..459c8286 100644 --- a/src/microhttpd/test_auth_parse.c +++ b/src/microhttpd/test_auth_parse.c | |||
@@ -160,7 +160,7 @@ MHD_DLOG (const struct MHD_Daemon *daemon, | |||
160 | ...) | 160 | ...) |
161 | { | 161 | { |
162 | (void) daemon; | 162 | (void) daemon; |
163 | if (NULL == conn.rq.last) | 163 | if (! conn.rq.client_aware) |
164 | { | 164 | { |
165 | fprintf (stderr, "Unexpected call of 'MHD_LOG(), format is '%s'.\n", | 165 | fprintf (stderr, "Unexpected call of 'MHD_LOG(), format is '%s'.\n", |
166 | format); | 166 | format); |
@@ -169,7 +169,7 @@ MHD_DLOG (const struct MHD_Daemon *daemon, | |||
169 | "NULL" : (conn.rq.headers_received->value)); | 169 | "NULL" : (conn.rq.headers_received->value)); |
170 | mhdErrorExit (); | 170 | mhdErrorExit (); |
171 | } | 171 | } |
172 | conn.rq.last = NULL; /* Clear the flag */ | 172 | conn.rq.client_aware = false; /* Clear the flag */ |
173 | return; | 173 | return; |
174 | } | 174 | } |
175 | 175 | ||
@@ -319,7 +319,7 @@ clean_AuthHeaders (void) | |||
319 | 319 | ||
320 | conn.read_buffer = NULL; | 320 | conn.read_buffer = NULL; |
321 | conn.write_buffer = NULL; | 321 | conn.write_buffer = NULL; |
322 | conn.rq.last = NULL; | 322 | conn.rq.client_aware = false; |
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
@@ -338,15 +338,14 @@ expect_result_type_n (const char *hdr, size_t hdr_len, | |||
338 | int expect_log, | 338 | int expect_log, |
339 | unsigned int line_num) | 339 | unsigned int line_num) |
340 | { | 340 | { |
341 | static char marker1[] = "Expected log call"; | ||
342 | unsigned int ret; | 341 | unsigned int ret; |
343 | 342 | ||
344 | ret = 0; | 343 | ret = 0; |
345 | add_AuthHeader (hdr, hdr_len); | 344 | add_AuthHeader (hdr, hdr_len); |
346 | if (expect_log) | 345 | if (expect_log) |
347 | conn.rq.last = marker1; /* Use like a flag */ | 346 | conn.rq.client_aware = true; /* Use like a flag */ |
348 | else | 347 | else |
349 | conn.rq.last = NULL; | 348 | conn.rq.client_aware = false; |
350 | #ifdef BAUTH_SUPPORT | 349 | #ifdef BAUTH_SUPPORT |
351 | if (MHD_TEST_AUTHTYPE_BASIC == expected_type) | 350 | if (MHD_TEST_AUTHTYPE_BASIC == expected_type) |
352 | { | 351 | { |
@@ -394,7 +393,7 @@ expect_result_type_n (const char *hdr, size_t hdr_len, | |||
394 | #endif /* DAUTH_SUPPORT */ | 393 | #endif /* DAUTH_SUPPORT */ |
395 | } | 394 | } |
396 | #if defined(BAUTH_SUPPORT) && defined(DAUTH_SUPPORT) | 395 | #if defined(BAUTH_SUPPORT) && defined(DAUTH_SUPPORT) |
397 | if (conn.rq.last) | 396 | if (conn.rq.client_aware) |
398 | { | 397 | { |
399 | fprintf (stderr, | 398 | fprintf (stderr, |
400 | "'Authorization' header parsing ERROR:\n" | 399 | "'Authorization' header parsing ERROR:\n" |