diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 421 |
1 files changed, 219 insertions, 202 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 83540622..318439a8 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -152,7 +152,8 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
152 | if ((connection == NULL) || | 152 | if ((connection == NULL) || |
153 | (response == NULL) || | 153 | (response == NULL) || |
154 | (connection->response != NULL) || | 154 | (connection->response != NULL) || |
155 | (connection->have_received_body == MHD_NO) || (connection->have_received_headers == MHD_NO)) | 155 | (connection->have_received_body == MHD_NO) |
156 | || (connection->have_received_headers == MHD_NO)) | ||
156 | return MHD_NO; | 157 | return MHD_NO; |
157 | MHD_increment_response_rc (response); | 158 | MHD_increment_response_rc (response); |
158 | connection->response = response; | 159 | connection->response = response; |
@@ -184,7 +185,8 @@ MHD_need_100_continue (struct MHD_Connection *connection) | |||
184 | MHD_HEADER_KIND, | 185 | MHD_HEADER_KIND, |
185 | MHD_HTTP_HEADER_EXPECT))) | 186 | MHD_HTTP_HEADER_EXPECT))) |
186 | && (0 == strcasecmp (expect, "100-continue")) | 187 | && (0 == strcasecmp (expect, "100-continue")) |
187 | && (connection->continue_message_write_offset < strlen (HTTP_100_CONTINUE))); | 188 | && (connection->continue_message_write_offset < |
189 | strlen (HTTP_100_CONTINUE))); | ||
188 | } | 190 | } |
189 | 191 | ||
190 | /** | 192 | /** |
@@ -224,11 +226,12 @@ ready_response (struct MHD_Connection *connection) | |||
224 | connection->response_write_position, | 226 | connection->response_write_position, |
225 | response->data, | 227 | response->data, |
226 | MIN (response->data_buffer_size, | 228 | MIN (response->data_buffer_size, |
227 | response->total_size - connection->response_write_position)); | 229 | response->total_size - |
230 | connection->response_write_position)); | ||
228 | if (ret == -1) | 231 | if (ret == -1) |
229 | { | 232 | { |
230 | /* end of message, signal other side by closing! */ | 233 | /* end of message, signal other side by closing! */ |
231 | #if DEBUG_CLOSE | 234 | #if DEBUG_CLOSE |
232 | #if HAVE_MESSAGES | 235 | #if HAVE_MESSAGES |
233 | MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); | 236 | MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); |
234 | #endif | 237 | #endif |
@@ -608,9 +611,9 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
608 | unsigned long long cval; | 611 | unsigned long long cval; |
609 | struct MHD_Response *response; | 612 | struct MHD_Response *response; |
610 | 613 | ||
611 | if ( ( (connection->have_received_body == MHD_YES) && | 614 | if (((connection->have_received_body == MHD_YES) && |
612 | (connection->have_chunked_upload == MHD_NO) ) || | 615 | (connection->have_chunked_upload == MHD_NO)) || |
613 | (connection->have_received_headers == MHD_YES) ) | 616 | (connection->have_received_headers == MHD_YES)) |
614 | abort (); | 617 | abort (); |
615 | colon = NULL; /* make gcc happy */ | 618 | colon = NULL; /* make gcc happy */ |
616 | last = NULL; | 619 | last = NULL; |
@@ -689,24 +692,25 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
689 | } | 692 | } |
690 | else | 693 | else |
691 | { | 694 | { |
692 | if (connection->have_chunked_upload == MHD_NO) | 695 | if (connection->have_chunked_upload == MHD_NO) |
693 | { | 696 | { |
694 | connection->remaining_upload_size = -1; /* unknown size */ | 697 | connection->remaining_upload_size = -1; /* unknown size */ |
695 | if (0 == strcasecmp(MHD_lookup_connection_value(connection, | 698 | if (0 == |
696 | MHD_HEADER_KIND, | 699 | strcasecmp (MHD_lookup_connection_value |
697 | MHD_HTTP_HEADER_TRANSFER_ENCODING), | 700 | (connection, MHD_HEADER_KIND, |
698 | "chunked")) | 701 | MHD_HTTP_HEADER_TRANSFER_ENCODING), |
699 | connection->have_chunked_upload = MHD_YES; | 702 | "chunked")) |
700 | } | 703 | connection->have_chunked_upload = MHD_YES; |
701 | else | 704 | } |
702 | { | 705 | else |
703 | /* we were actually processing the footers at the | 706 | { |
704 | END of a chunked encoding; give connection | 707 | /* we were actually processing the footers at the |
705 | handler an extra chance... */ | 708 | END of a chunked encoding; give connection |
706 | connection->have_chunked_upload = MHD_NO; /* no more! */ | 709 | handler an extra chance... */ |
707 | MHD_call_connection_handler(connection); | 710 | connection->have_chunked_upload = MHD_NO; /* no more! */ |
708 | } | 711 | MHD_call_connection_handler (connection); |
709 | } | 712 | } |
713 | } | ||
710 | } | 714 | } |
711 | if ((0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) | 715 | if ((0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) |
712 | && (NULL != connection->version) | 716 | && (NULL != connection->version) |
@@ -807,166 +811,167 @@ MHD_call_connection_handler (struct MHD_Connection *connection) | |||
807 | return; /* already queued a response */ | 811 | return; /* already queued a response */ |
808 | if (connection->have_received_headers == MHD_NO) | 812 | if (connection->have_received_headers == MHD_NO) |
809 | abort (); /* bad timing... */ | 813 | abort (); /* bad timing... */ |
810 | do | 814 | do |
811 | { | 815 | { |
812 | instant_retry = MHD_NO; | 816 | instant_retry = MHD_NO; |
813 | available = connection->read_buffer_offset; | 817 | available = connection->read_buffer_offset; |
814 | if (connection->have_chunked_upload == MHD_YES) | 818 | if (connection->have_chunked_upload == MHD_YES) |
815 | { | 819 | { |
816 | if ( (connection->current_chunk_offset == connection->current_chunk_size) && | 820 | if ((connection->current_chunk_offset == |
817 | (connection->current_chunk_offset != 0) && | 821 | connection->current_chunk_size) |
818 | (available >= 2) ) | 822 | && (connection->current_chunk_offset != 0) && (available >= 2)) |
819 | { | 823 | { |
820 | /* skip new line at the *end* of a chunk */ | 824 | /* skip new line at the *end* of a chunk */ |
821 | i = 0; | 825 | i = 0; |
822 | if ( (connection->read_buffer[i] == '\r') || | 826 | if ((connection->read_buffer[i] == '\r') || |
823 | (connection->read_buffer[i] == '\n') ) | 827 | (connection->read_buffer[i] == '\n')) |
824 | i++; /* skip 1st part of line feed */ | 828 | i++; /* skip 1st part of line feed */ |
825 | if ( (connection->read_buffer[i] == '\r') || | 829 | if ((connection->read_buffer[i] == '\r') || |
826 | (connection->read_buffer[i] == '\n') ) | 830 | (connection->read_buffer[i] == '\n')) |
827 | i++; /* skip 2nd part of line feed */ | 831 | i++; /* skip 2nd part of line feed */ |
828 | if (i == 0) | 832 | if (i == 0) |
829 | { | 833 | { |
830 | /* malformed encoding */ | 834 | /* malformed encoding */ |
831 | #if HAVE_MESSAGES | 835 | #if HAVE_MESSAGES |
832 | MHD_DLOG (connection->daemon, | 836 | MHD_DLOG (connection->daemon, |
833 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); | 837 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); |
834 | #endif | 838 | #endif |
835 | connection_close_error (connection); | 839 | connection_close_error (connection); |
836 | return; | 840 | return; |
837 | } | 841 | } |
838 | connection->read_buffer_offset -= i; | 842 | connection->read_buffer_offset -= i; |
839 | available -= i; | 843 | available -= i; |
840 | memmove(connection->read_buffer, | 844 | memmove (connection->read_buffer, |
841 | &connection->read_buffer[i], | 845 | &connection->read_buffer[i], available); |
842 | available); | 846 | connection->current_chunk_offset = 0; |
843 | connection->current_chunk_offset = 0; | 847 | connection->current_chunk_size = 0; |
844 | connection->current_chunk_size = 0; | 848 | } |
845 | } | 849 | if (connection->current_chunk_offset < |
846 | if (connection->current_chunk_offset < connection->current_chunk_size) | 850 | connection->current_chunk_size) |
847 | { | 851 | { |
848 | /* we are in the middle of a chunk, give | 852 | /* we are in the middle of a chunk, give |
849 | as much as possible to the client (without | 853 | as much as possible to the client (without |
850 | crossing chunk boundaries) */ | 854 | crossing chunk boundaries) */ |
851 | processed = connection->current_chunk_size - connection->current_chunk_offset; | 855 | processed = |
852 | if (processed > available) | 856 | connection->current_chunk_size - |
853 | processed = available; | 857 | connection->current_chunk_offset; |
854 | available -= processed; | 858 | if (processed > available) |
855 | if (available > 0) | 859 | processed = available; |
856 | instant_retry = MHD_YES; | 860 | available -= processed; |
857 | } | 861 | if (available > 0) |
858 | else | 862 | instant_retry = MHD_YES; |
859 | { | 863 | } |
860 | /* we need to read chunk boundaries */ | 864 | else |
861 | i = 0; | 865 | { |
862 | while (i < available) | 866 | /* we need to read chunk boundaries */ |
863 | { | 867 | i = 0; |
864 | if ( (connection->read_buffer[i] == '\r') || | 868 | while (i < available) |
865 | (connection->read_buffer[i] == '\n') ) | 869 | { |
866 | break; | 870 | if ((connection->read_buffer[i] == '\r') || |
867 | i++; | 871 | (connection->read_buffer[i] == '\n')) |
868 | if (i >= 6) | 872 | break; |
869 | break; | 873 | i++; |
870 | } | 874 | if (i >= 6) |
871 | if (i >= available) | 875 | break; |
872 | return; /* need more data... */ | 876 | } |
873 | /* The following if-statement is a bit crazy -- we | 877 | if (i >= available) |
874 | use the second clause only for the side-effect, | 878 | return; /* need more data... */ |
875 | 0-terminating the buffer for the following sscanf | 879 | /* The following if-statement is a bit crazy -- we |
876 | attempts; yes, there should be only a single | 880 | use the second clause only for the side-effect, |
877 | "="-sign (assignment!) in the read_buffer[i]-line. */ | 881 | 0-terminating the buffer for the following sscanf |
878 | if ( (i >= 6) || | 882 | attempts; yes, there should be only a single |
879 | ((connection->read_buffer[i] = '\0')) || | 883 | "="-sign (assignment!) in the read_buffer[i]-line. */ |
880 | ( (1 != sscanf(connection->read_buffer, | 884 | if ((i >= 6) || |
881 | "%X", | 885 | ((connection->read_buffer[i] = '\0')) || |
882 | &connection->current_chunk_size)) && | 886 | ((1 != sscanf (connection->read_buffer, |
883 | (1 != sscanf(connection->read_buffer, | 887 | "%X", |
884 | "%x", | 888 | &connection->current_chunk_size)) && |
885 | &connection->current_chunk_size)) ) ) | 889 | (1 != sscanf (connection->read_buffer, |
886 | { | 890 | "%x", &connection->current_chunk_size)))) |
887 | /* malformed encoding */ | 891 | { |
892 | /* malformed encoding */ | ||
888 | #if HAVE_MESSAGES | 893 | #if HAVE_MESSAGES |
889 | MHD_DLOG (connection->daemon, | 894 | MHD_DLOG (connection->daemon, |
890 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); | 895 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); |
891 | #endif | 896 | #endif |
892 | connection_close_error (connection); | 897 | connection_close_error (connection); |
893 | return; | 898 | return; |
894 | } | 899 | } |
895 | i++; | 900 | i++; |
896 | if ( (connection->read_buffer[i] == '\r') || | 901 | if ((connection->read_buffer[i] == '\r') || |
897 | (connection->read_buffer[i] == '\n') ) | 902 | (connection->read_buffer[i] == '\n')) |
898 | i++; /* skip 2nd part of line feed */ | 903 | i++; /* skip 2nd part of line feed */ |
899 | memmove(connection->read_buffer, | 904 | memmove (connection->read_buffer, |
900 | &connection->read_buffer[i], | 905 | &connection->read_buffer[i], available - i); |
901 | available - i); | 906 | connection->read_buffer_offset -= i; |
902 | connection->read_buffer_offset -= i; | 907 | connection->current_chunk_offset = 0; |
903 | connection->current_chunk_offset = 0; | 908 | instant_retry = MHD_YES; |
904 | instant_retry = MHD_YES; | 909 | if (connection->current_chunk_size == 0) |
905 | if (connection->current_chunk_size == 0) | 910 | { |
906 | { | 911 | /* we're back to reading HEADERS (footers!) */ |
907 | /* we're back to reading HEADERS (footers!) */ | 912 | connection->have_received_body = MHD_YES; |
908 | connection->have_received_body = MHD_YES; | 913 | connection->remaining_upload_size = 0; |
909 | connection->remaining_upload_size = 0; | 914 | connection->have_received_headers = MHD_NO; |
910 | connection->have_received_headers = MHD_NO; | 915 | MHD_parse_connection_headers (connection); |
911 | MHD_parse_connection_headers(connection); | 916 | return; |
912 | return; | 917 | } |
913 | } | 918 | continue; |
914 | continue; | 919 | } |
915 | } | 920 | } |
916 | } | ||
917 | else | 921 | else |
918 | { | 922 | { |
919 | /* no chunked encoding, give all to the client */ | 923 | /* no chunked encoding, give all to the client */ |
920 | processed = available; | 924 | processed = available; |
921 | available = 0; | 925 | available = 0; |
922 | } | 926 | } |
923 | used = processed; | 927 | used = processed; |
924 | ah = MHD_find_access_handler (connection); | 928 | ah = MHD_find_access_handler (connection); |
925 | if (MHD_NO == ah->dh (ah->dh_cls, | 929 | if (MHD_NO == ah->dh (ah->dh_cls, |
926 | connection, | 930 | connection, |
927 | connection->url, | 931 | connection->url, |
928 | connection->method, | 932 | connection->method, |
929 | connection->version, | 933 | connection->version, |
930 | connection->read_buffer, &processed, | 934 | connection->read_buffer, &processed, |
931 | &connection->client_context)) | 935 | &connection->client_context)) |
932 | { | 936 | { |
933 | /* serious internal error, close connection */ | 937 | /* serious internal error, close connection */ |
934 | #if HAVE_MESSAGES | 938 | #if HAVE_MESSAGES |
935 | MHD_DLOG (connection->daemon, | 939 | MHD_DLOG (connection->daemon, |
936 | "Internal application error, closing connection.\n"); | 940 | "Internal application error, closing connection.\n"); |
937 | #endif | 941 | #endif |
938 | connection_close_error (connection); | 942 | connection_close_error (connection); |
939 | return; | 943 | return; |
940 | } | 944 | } |
941 | if (processed != 0) | 945 | if (processed != 0) |
942 | instant_retry = MHD_NO; /* client did not process everything */ | 946 | instant_retry = MHD_NO; /* client did not process everything */ |
943 | used -= processed; | 947 | used -= processed; |
944 | if (connection->have_chunked_upload == MHD_YES) | 948 | if (connection->have_chunked_upload == MHD_YES) |
945 | connection->current_chunk_offset += used; | 949 | connection->current_chunk_offset += used; |
946 | /* dh left "processed" bytes in buffer for next time... */ | 950 | /* dh left "processed" bytes in buffer for next time... */ |
947 | if (used > 0) | 951 | if (used > 0) |
948 | memmove (connection->read_buffer, | 952 | memmove (connection->read_buffer, |
949 | &connection->read_buffer[used], | 953 | &connection->read_buffer[used], processed + available); |
950 | processed + available); | 954 | if (connection->remaining_upload_size != -1) |
951 | if (connection->remaining_upload_size != -1) | 955 | connection->remaining_upload_size -= used; |
952 | connection->remaining_upload_size -= used; | ||
953 | connection->read_buffer_offset = processed + available; | 956 | connection->read_buffer_offset = processed + available; |
954 | if ((connection->remaining_upload_size == 0) || | 957 | if ((connection->remaining_upload_size == 0) || |
955 | ((connection->read_buffer_offset == 0) && | 958 | ((connection->read_buffer_offset == 0) && |
956 | (connection->remaining_upload_size == -1) && (connection->socket_fd == -1))) | 959 | (connection->remaining_upload_size == -1) |
957 | { | 960 | && (connection->socket_fd == -1))) |
958 | connection->have_received_body = MHD_YES; | 961 | { |
959 | if (connection->read_buffer != NULL) | 962 | connection->have_received_body = MHD_YES; |
960 | MHD_pool_reallocate (connection->pool, | 963 | if (connection->read_buffer != NULL) |
961 | connection->read_buffer, | 964 | MHD_pool_reallocate (connection->pool, |
962 | (connection->read_buffer == | 965 | connection->read_buffer, |
963 | NULL) ? 0 : connection->read_buffer_size + 1, | 966 | (connection->read_buffer == |
964 | 0); | 967 | NULL) ? 0 : connection->read_buffer_size + |
965 | connection->read_buffer_offset = 0; | 968 | 1, 0); |
966 | connection->read_buffer_size = 0; | 969 | connection->read_buffer_offset = 0; |
967 | connection->read_buffer = NULL; | 970 | connection->read_buffer_size = 0; |
968 | } | 971 | connection->read_buffer = NULL; |
969 | } while (instant_retry == MHD_YES); | 972 | } |
973 | } | ||
974 | while (instant_retry == MHD_YES); | ||
970 | } | 975 | } |
971 | 976 | ||
972 | /** | 977 | /** |
@@ -1023,8 +1028,8 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
1023 | } | 1028 | } |
1024 | bytes_read = RECV (connection->socket_fd, | 1029 | bytes_read = RECV (connection->socket_fd, |
1025 | &connection->read_buffer[connection->read_buffer_offset], | 1030 | &connection->read_buffer[connection->read_buffer_offset], |
1026 | connection->read_buffer_size - connection->read_buffer_offset, | 1031 | connection->read_buffer_size - |
1027 | MSG_NOSIGNAL); | 1032 | connection->read_buffer_offset, MSG_NOSIGNAL); |
1028 | if (bytes_read < 0) | 1033 | if (bytes_read < 0) |
1029 | { | 1034 | { |
1030 | if (errno == EINTR) | 1035 | if (errno == EINTR) |
@@ -1040,7 +1045,8 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
1040 | { | 1045 | { |
1041 | /* other side closed connection */ | 1046 | /* other side closed connection */ |
1042 | connection->read_close = MHD_YES; | 1047 | connection->read_close = MHD_YES; |
1043 | if ((connection->have_received_headers == MHD_YES) && (connection->read_buffer_offset > 0)) | 1048 | if ((connection->have_received_headers == MHD_YES) |
1049 | && (connection->read_buffer_offset > 0)) | ||
1044 | MHD_call_connection_handler (connection); | 1050 | MHD_call_connection_handler (connection); |
1045 | #if DEBUG_CLOSE | 1051 | #if DEBUG_CLOSE |
1046 | #if HAVE_MESSAGES | 1052 | #if HAVE_MESSAGES |
@@ -1049,18 +1055,20 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
1049 | #endif | 1055 | #endif |
1050 | #endif | 1056 | #endif |
1051 | shutdown (connection->socket_fd, SHUT_RD); | 1057 | shutdown (connection->socket_fd, SHUT_RD); |
1052 | if ( (connection->have_received_headers == MHD_NO) || | 1058 | if ((connection->have_received_headers == MHD_NO) || |
1053 | (connection->have_received_body == MHD_NO) ) { | 1059 | (connection->have_received_body == MHD_NO)) |
1054 | /* no request => no response! */ | 1060 | { |
1055 | CLOSE (connection->socket_fd); | 1061 | /* no request => no response! */ |
1056 | connection->socket_fd = -1; | 1062 | CLOSE (connection->socket_fd); |
1057 | } | 1063 | connection->socket_fd = -1; |
1064 | } | ||
1058 | return MHD_YES; | 1065 | return MHD_YES; |
1059 | } | 1066 | } |
1060 | connection->read_buffer_offset += bytes_read; | 1067 | connection->read_buffer_offset += bytes_read; |
1061 | if (connection->have_received_headers == MHD_NO) | 1068 | if (connection->have_received_headers == MHD_NO) |
1062 | MHD_parse_connection_headers (connection); | 1069 | MHD_parse_connection_headers (connection); |
1063 | if ((connection->have_received_headers == MHD_YES) && (connection->method != NULL)) | 1070 | if ((connection->have_received_headers == MHD_YES) |
1071 | && (connection->method != NULL)) | ||
1064 | MHD_call_connection_handler (connection); | 1072 | MHD_call_connection_handler (connection); |
1065 | return MHD_YES; | 1073 | return MHD_YES; |
1066 | } | 1074 | } |
@@ -1134,8 +1142,9 @@ MHD_build_header_response (struct MHD_Connection *connection) | |||
1134 | char *data; | 1142 | char *data; |
1135 | 1143 | ||
1136 | MHD_add_extra_headers (connection); | 1144 | MHD_add_extra_headers (connection); |
1137 | const char* reason_phrase = MHD_get_reason_phrase_for(connection->responseCode); | 1145 | const char *reason_phrase = |
1138 | _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, | 1146 | MHD_get_reason_phrase_for (connection->responseCode); |
1147 | _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, | ||
1139 | connection->responseCode, reason_phrase); | 1148 | connection->responseCode, reason_phrase); |
1140 | off = strlen (code); | 1149 | off = strlen (code); |
1141 | /* estimate size */ | 1150 | /* estimate size */ |
@@ -1193,14 +1202,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1193 | { | 1202 | { |
1194 | struct MHD_Response *response; | 1203 | struct MHD_Response *response; |
1195 | int ret; | 1204 | int ret; |
1196 | const char * end; | 1205 | const char *end; |
1197 | 1206 | ||
1198 | if (MHD_need_100_continue (connection)) | 1207 | if (MHD_need_100_continue (connection)) |
1199 | { | 1208 | { |
1200 | ret = SEND (connection->socket_fd, | 1209 | ret = SEND (connection->socket_fd, |
1201 | &HTTP_100_CONTINUE[connection->continue_message_write_offset], | 1210 | &HTTP_100_CONTINUE[connection-> |
1202 | strlen (HTTP_100_CONTINUE) - connection->continue_message_write_offset, | 1211 | continue_message_write_offset], |
1203 | MSG_NOSIGNAL); | 1212 | strlen (HTTP_100_CONTINUE) - |
1213 | connection->continue_message_write_offset, MSG_NOSIGNAL); | ||
1204 | if (ret < 0) | 1214 | if (ret < 0) |
1205 | { | 1215 | { |
1206 | if (errno == EINTR) | 1216 | if (errno == EINTR) |
@@ -1215,7 +1225,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1215 | #if DEBUG_SEND_DATA | 1225 | #if DEBUG_SEND_DATA |
1216 | fprintf (stderr, | 1226 | fprintf (stderr, |
1217 | "Sent 100 continue response: `%.*s'\n", | 1227 | "Sent 100 continue response: `%.*s'\n", |
1218 | ret, &HTTP_100_CONTINUE[connection->continue_message_write_offset]); | 1228 | ret, |
1229 | &HTTP_100_CONTINUE[connection->continue_message_write_offset]); | ||
1219 | #endif | 1230 | #endif |
1220 | connection->continue_message_write_offset += ret; | 1231 | connection->continue_message_write_offset += ret; |
1221 | return MHD_YES; | 1232 | return MHD_YES; |
@@ -1242,9 +1253,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1242 | return MHD_NO; | 1253 | return MHD_NO; |
1243 | } | 1254 | } |
1244 | ret = SEND (connection->socket_fd, | 1255 | ret = SEND (connection->socket_fd, |
1245 | &connection->write_buffer[connection->write_buffer_send_offset], | 1256 | &connection->write_buffer[connection-> |
1246 | connection->write_buffer_append_offset - connection->write_buffer_send_offset, | 1257 | write_buffer_send_offset], |
1247 | MSG_NOSIGNAL); | 1258 | connection->write_buffer_append_offset - |
1259 | connection->write_buffer_send_offset, MSG_NOSIGNAL); | ||
1248 | if (ret < 0) | 1260 | if (ret < 0) |
1249 | { | 1261 | { |
1250 | if (errno == EINTR) | 1262 | if (errno == EINTR) |
@@ -1259,10 +1271,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1259 | #if DEBUG_SEND_DATA | 1271 | #if DEBUG_SEND_DATA |
1260 | fprintf (stderr, | 1272 | fprintf (stderr, |
1261 | "Sent HEADER response: `%.*s'\n", | 1273 | "Sent HEADER response: `%.*s'\n", |
1262 | ret, &connection->write_buffer[connection->write_buffer_send_offset]); | 1274 | ret, |
1275 | &connection->write_buffer[connection-> | ||
1276 | write_buffer_send_offset]); | ||
1263 | #endif | 1277 | #endif |
1264 | connection->write_buffer_send_offset += ret; | 1278 | connection->write_buffer_send_offset += ret; |
1265 | if (connection->write_buffer_append_offset == connection->write_buffer_send_offset) | 1279 | if (connection->write_buffer_append_offset == |
1280 | connection->write_buffer_send_offset) | ||
1266 | { | 1281 | { |
1267 | connection->write_buffer_append_offset = 0; | 1282 | connection->write_buffer_append_offset = 0; |
1268 | connection->write_buffer_send_offset = 0; | 1283 | connection->write_buffer_send_offset = 0; |
@@ -1284,17 +1299,18 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1284 | if ((response->crc != NULL) && | 1299 | if ((response->crc != NULL) && |
1285 | ((response->data_start > connection->response_write_position) || | 1300 | ((response->data_start > connection->response_write_position) || |
1286 | (response->data_start + response->data_size <= | 1301 | (response->data_start + response->data_size <= |
1287 | connection->response_write_position)) && (MHD_YES != ready_response (connection))) | 1302 | connection->response_write_position)) |
1303 | && (MHD_YES != ready_response (connection))) | ||
1288 | { | 1304 | { |
1289 | pthread_mutex_unlock (&response->mutex); | 1305 | pthread_mutex_unlock (&response->mutex); |
1290 | return MHD_YES; | 1306 | return MHD_YES; |
1291 | } | 1307 | } |
1292 | /* transmit */ | 1308 | /* transmit */ |
1293 | ret = SEND (connection->socket_fd, | 1309 | ret = SEND (connection->socket_fd, |
1294 | &response->data[connection->response_write_position - response->data_start], | 1310 | &response->data[connection->response_write_position - |
1311 | response->data_start], | ||
1295 | response->data_size - (connection->response_write_position - | 1312 | response->data_size - (connection->response_write_position - |
1296 | response->data_start), | 1313 | response->data_start), MSG_NOSIGNAL); |
1297 | MSG_NOSIGNAL); | ||
1298 | if (response->crc != NULL) | 1314 | if (response->crc != NULL) |
1299 | pthread_mutex_unlock (&response->mutex); | 1315 | pthread_mutex_unlock (&response->mutex); |
1300 | if (ret < 0) | 1316 | if (ret < 0) |
@@ -1312,7 +1328,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1312 | fprintf (stderr, | 1328 | fprintf (stderr, |
1313 | "Sent DATA response: `%.*s'\n", | 1329 | "Sent DATA response: `%.*s'\n", |
1314 | ret, | 1330 | ret, |
1315 | &response->data[connection->response_write_position - response->data_start]); | 1331 | &response->data[connection->response_write_position - |
1332 | response->data_start]); | ||
1316 | #endif | 1333 | #endif |
1317 | connection->response_write_position += ret; | 1334 | connection->response_write_position += ret; |
1318 | if (connection->response_write_position > response->total_size) | 1335 | if (connection->response_write_position > response->total_size) |
@@ -1330,8 +1347,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1330 | &connection->client_context, | 1347 | &connection->client_context, |
1331 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | 1348 | MHD_REQUEST_TERMINATED_COMPLETED_OK); |
1332 | end = MHD_lookup_connection_value (connection, | 1349 | end = MHD_lookup_connection_value (connection, |
1333 | MHD_HEADER_KIND, | 1350 | MHD_HEADER_KIND, |
1334 | MHD_HTTP_HEADER_CONNECTION); | 1351 | MHD_HTTP_HEADER_CONNECTION); |
1335 | connection->client_context = NULL; | 1352 | connection->client_context = NULL; |
1336 | connection->continue_message_write_offset = 0; | 1353 | connection->continue_message_write_offset = 0; |
1337 | connection->responseCode = 0; | 1354 | connection->responseCode = 0; |
@@ -1343,14 +1360,14 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1343 | connection->response_write_position = 0; | 1360 | connection->response_write_position = 0; |
1344 | connection->have_chunked_upload = MHD_NO; | 1361 | connection->have_chunked_upload = MHD_NO; |
1345 | connection->method = NULL; | 1362 | connection->method = NULL; |
1346 | connection->url = NULL; | 1363 | connection->url = NULL; |
1347 | if ((end != NULL) && (0 == strcasecmp (end, "close"))) | 1364 | if ((end != NULL) && (0 == strcasecmp (end, "close"))) |
1348 | { | 1365 | { |
1349 | /* other side explicitly requested | 1366 | /* other side explicitly requested |
1350 | that we close the connection after | 1367 | that we close the connection after |
1351 | this request */ | 1368 | this request */ |
1352 | connection->read_close = MHD_YES; | 1369 | connection->read_close = MHD_YES; |
1353 | } | 1370 | } |
1354 | if ((connection->read_close == MHD_YES) || | 1371 | if ((connection->read_close == MHD_YES) || |
1355 | (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) | 1372 | (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) |
1356 | { | 1373 | { |