diff options
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 222 |
1 files changed, 0 insertions, 222 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)) || \ |