diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-12-16 10:28:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-12-16 10:28:22 +0000 |
commit | f794d6b09631610e4473d6e356f24b09195105bf (patch) | |
tree | b1b6b713478d0f2b52f10e921ffd16093a12c60f | |
parent | baeae167a103b40a032e005b50ae13e49ac0ceed (diff) | |
download | libmicrohttpd-f794d6b09631610e4473d6e356f24b09195105bf.tar.gz libmicrohttpd-f794d6b09631610e4473d6e356f24b09195105bf.zip |
formatting
-rw-r--r-- | src/daemon/connection.c | 421 | ||||
-rw-r--r-- | src/daemon/daemon.c | 24 | ||||
-rw-r--r-- | src/daemon/daemontest_post_loop.c | 385 | ||||
-rw-r--r-- | src/daemon/daemontest_postform.c | 66 | ||||
-rw-r--r-- | src/daemon/daemontest_put_chunked.c | 38 | ||||
-rw-r--r-- | src/daemon/postprocessor.c | 8 | ||||
-rw-r--r-- | src/daemon/reason_phrase.c | 36 | ||||
-rw-r--r-- | src/daemon/reason_phrase.h | 3 |
8 files changed, 499 insertions, 482 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 | { |
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 09a37255..19c614a1 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -171,7 +171,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon, | |||
171 | } | 171 | } |
172 | #if DEBUG_CONNECT | 172 | #if DEBUG_CONNECT |
173 | MHD_DLOG (daemon, "Maximum socket in select set: %d\n", *max_fd); | 173 | MHD_DLOG (daemon, "Maximum socket in select set: %d\n", *max_fd); |
174 | #endif | 174 | #endif |
175 | return MHD_YES; | 175 | return MHD_YES; |
176 | } | 176 | } |
177 | 177 | ||
@@ -264,7 +264,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
264 | socklen_t addrlen; | 264 | socklen_t addrlen; |
265 | int s; | 265 | int s; |
266 | #if OSX | 266 | #if OSX |
267 | static int on=1; | 267 | static int on = 1; |
268 | #endif | 268 | #endif |
269 | 269 | ||
270 | 270 | ||
@@ -287,7 +287,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
287 | } | 287 | } |
288 | #if DEBUG_CONNECT | 288 | #if DEBUG_CONNECT |
289 | MHD_DLOG (daemon, "Accepted connection on socket %d\n", s); | 289 | MHD_DLOG (daemon, "Accepted connection on socket %d\n", s); |
290 | #endif | 290 | #endif |
291 | if (daemon->max_connections == 0) | 291 | if (daemon->max_connections == 0) |
292 | { | 292 | { |
293 | /* above connection limit - reject */ | 293 | /* above connection limit - reject */ |
@@ -314,11 +314,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
314 | #if OSX | 314 | #if OSX |
315 | #ifdef SOL_SOCKET | 315 | #ifdef SOL_SOCKET |
316 | #ifdef SO_NOSIGPIPE | 316 | #ifdef SO_NOSIGPIPE |
317 | setsockopt(s, | 317 | setsockopt (s, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof (on)); |
318 | SOL_SOCKET, | ||
319 | SO_NOSIGPIPE, | ||
320 | &on, | ||
321 | sizeof(on)); | ||
322 | #endif | 318 | #endif |
323 | #endif | 319 | #endif |
324 | #endif | 320 | #endif |
@@ -437,8 +433,9 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
437 | continue; | 433 | continue; |
438 | } | 434 | } |
439 | 435 | ||
440 | if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 436 | if ((0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
441 | ((pos->have_received_headers == MHD_YES) && (pos->response == NULL)) ) | 437 | ((pos->have_received_headers == MHD_YES) |
438 | && (pos->response == NULL))) | ||
442 | MHD_call_connection_handler (pos); | 439 | MHD_call_connection_handler (pos); |
443 | 440 | ||
444 | prev = pos; | 441 | prev = pos; |
@@ -680,11 +677,12 @@ MHD_start_daemon (unsigned int options, | |||
680 | if ((SETSOCKOPT (socket_fd, | 677 | if ((SETSOCKOPT (socket_fd, |
681 | SOL_SOCKET, | 678 | SOL_SOCKET, |
682 | SO_REUSEADDR, | 679 | SO_REUSEADDR, |
683 | &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) { | 680 | &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) |
681 | { | ||
684 | #if HAVE_MESSAGES | 682 | #if HAVE_MESSAGES |
685 | fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); | 683 | fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); |
686 | #endif | 684 | #endif |
687 | } | 685 | } |
688 | if ((options & MHD_USE_IPv6) != 0) | 686 | if ((options & MHD_USE_IPv6) != 0) |
689 | { | 687 | { |
690 | memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); | 688 | memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); |
diff --git a/src/daemon/daemontest_post_loop.c b/src/daemon/daemontest_post_loop.c index 588a02d3..f1555c16 100644 --- a/src/daemon/daemontest_post_loop.c +++ b/src/daemon/daemontest_post_loop.c | |||
@@ -78,19 +78,17 @@ ahc_echo (void *cls, | |||
78 | printf ("METHOD: %s\n", method); | 78 | printf ("METHOD: %s\n", method); |
79 | return MHD_NO; /* unexpected method */ | 79 | return MHD_NO; /* unexpected method */ |
80 | } | 80 | } |
81 | if ( (*mptr != NULL) && | 81 | if ((*mptr != NULL) && (0 == *upload_data_size)) |
82 | (0 == *upload_data_size) ) { | 82 | { |
83 | if (*mptr != &marker) | 83 | if (*mptr != &marker) |
84 | abort(); | 84 | abort (); |
85 | response = MHD_create_response_from_data (2, | 85 | response = MHD_create_response_from_data (2, "OK", MHD_NO, MHD_NO); |
86 | "OK", | 86 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
87 | MHD_NO, MHD_NO); | 87 | MHD_destroy_response (response); |
88 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 88 | *mptr = NULL; |
89 | MHD_destroy_response (response); | 89 | return ret; |
90 | *mptr = NULL; | 90 | } |
91 | return ret; | 91 | if (strlen (POST_DATA) != *upload_data_size) |
92 | } | ||
93 | if (strlen(POST_DATA) != *upload_data_size) | ||
94 | return MHD_YES; | 92 | return MHD_YES; |
95 | *upload_data_size = 0; | 93 | *upload_data_size = 0; |
96 | *mptr = ▮ | 94 | *mptr = ▮ |
@@ -115,48 +113,49 @@ testInternalPost () | |||
115 | 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 113 | 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
116 | if (d == NULL) | 114 | if (d == NULL) |
117 | return 1; | 115 | return 1; |
118 | for (i=0;i<LOOPCOUNT;i++) { | 116 | for (i = 0; i < LOOPCOUNT; i++) |
119 | if (0 == i % 100) | 117 | { |
120 | fprintf(stderr, "."); | 118 | if (0 == i % 100) |
121 | c = curl_easy_init (); | 119 | fprintf (stderr, "."); |
122 | cbc.pos = 0; | 120 | c = curl_easy_init (); |
123 | buf[0] = '\0'; | 121 | cbc.pos = 0; |
124 | sprintf(url, "http://localhost:1080/hw%d", i); | 122 | buf[0] = '\0'; |
125 | curl_easy_setopt (c, CURLOPT_URL, url); | 123 | sprintf (url, "http://localhost:1080/hw%d", i); |
126 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 124 | curl_easy_setopt (c, CURLOPT_URL, url); |
127 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 125 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
128 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 126 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
129 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | 127 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
130 | curl_easy_setopt (c, CURLOPT_POST, 1L); | 128 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); |
131 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 129 | curl_easy_setopt (c, CURLOPT_POST, 1L); |
132 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); | 130 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
133 | if (oneone) | 131 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); |
134 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 132 | if (oneone) |
135 | else | 133 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
136 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | 134 | else |
137 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 2L); | 135 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
138 | // NOTE: use of CONNECTTIMEOUT without also | 136 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 2L); |
139 | // setting NOSIGNAL results in really weird | 137 | // NOTE: use of CONNECTTIMEOUT without also |
140 | // crashes on my system! | 138 | // setting NOSIGNAL results in really weird |
141 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | 139 | // crashes on my system! |
142 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 140 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); |
143 | { | 141 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
144 | fprintf (stderr, | 142 | { |
145 | "curl_easy_perform failed: `%s'\n", | 143 | fprintf (stderr, |
146 | curl_easy_strerror (errornum)); | 144 | "curl_easy_perform failed: `%s'\n", |
147 | curl_easy_cleanup (c); | 145 | curl_easy_strerror (errornum)); |
148 | MHD_stop_daemon (d); | 146 | curl_easy_cleanup (c); |
149 | return 2; | 147 | MHD_stop_daemon (d); |
150 | } | 148 | return 2; |
151 | curl_easy_cleanup (c); | 149 | } |
152 | if ( (buf[0] != 'O') || | 150 | curl_easy_cleanup (c); |
153 | (buf[1] != 'K') ) { | 151 | if ((buf[0] != 'O') || (buf[1] != 'K')) |
154 | MHD_stop_daemon (d); | 152 | { |
155 | return 4; | 153 | MHD_stop_daemon (d); |
154 | return 4; | ||
155 | } | ||
156 | } | 156 | } |
157 | } | ||
158 | MHD_stop_daemon (d); | 157 | MHD_stop_daemon (d); |
159 | fprintf(stderr, "\n"); | 158 | fprintf (stderr, "\n"); |
160 | return 0; | 159 | return 0; |
161 | } | 160 | } |
162 | 161 | ||
@@ -177,48 +176,49 @@ testMultithreadedPost () | |||
177 | 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 176 | 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
178 | if (d == NULL) | 177 | if (d == NULL) |
179 | return 16; | 178 | return 16; |
180 | for (i=0;i<LOOPCOUNT;i++) { | 179 | for (i = 0; i < LOOPCOUNT; i++) |
181 | if (0 == i % 100) | 180 | { |
182 | fprintf(stderr, "."); | 181 | if (0 == i % 100) |
183 | c = curl_easy_init (); | 182 | fprintf (stderr, "."); |
184 | cbc.pos = 0; | 183 | c = curl_easy_init (); |
185 | buf[0] = '\0'; | 184 | cbc.pos = 0; |
186 | sprintf(url, "http://localhost:1081/hw%d", i); | 185 | buf[0] = '\0'; |
187 | curl_easy_setopt (c, CURLOPT_URL, url); | 186 | sprintf (url, "http://localhost:1081/hw%d", i); |
188 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 187 | curl_easy_setopt (c, CURLOPT_URL, url); |
189 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 188 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
190 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 189 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
191 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | 190 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
192 | curl_easy_setopt (c, CURLOPT_POST, 1L); | 191 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); |
193 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 192 | curl_easy_setopt (c, CURLOPT_POST, 1L); |
194 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); | 193 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
195 | if (oneone) | 194 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); |
196 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 195 | if (oneone) |
197 | else | 196 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
198 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | 197 | else |
199 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 2L); | 198 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
200 | // NOTE: use of CONNECTTIMEOUT without also | 199 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 2L); |
201 | // setting NOSIGNAL results in really weird | 200 | // NOTE: use of CONNECTTIMEOUT without also |
202 | // crashes on my system! | 201 | // setting NOSIGNAL results in really weird |
203 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | 202 | // crashes on my system! |
204 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 203 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); |
205 | { | 204 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
206 | fprintf (stderr, | 205 | { |
207 | "curl_easy_perform failed: `%s'\n", | 206 | fprintf (stderr, |
208 | curl_easy_strerror (errornum)); | 207 | "curl_easy_perform failed: `%s'\n", |
209 | curl_easy_cleanup (c); | 208 | curl_easy_strerror (errornum)); |
210 | MHD_stop_daemon (d); | 209 | curl_easy_cleanup (c); |
211 | return 32; | 210 | MHD_stop_daemon (d); |
212 | } | 211 | return 32; |
213 | curl_easy_cleanup (c); | 212 | } |
214 | if ( (buf[0] != 'O') || | 213 | curl_easy_cleanup (c); |
215 | (buf[1] != 'K') ) { | 214 | if ((buf[0] != 'O') || (buf[1] != 'K')) |
216 | MHD_stop_daemon (d); | 215 | { |
217 | return 64; | 216 | MHD_stop_daemon (d); |
217 | return 64; | ||
218 | } | ||
218 | } | 219 | } |
219 | } | ||
220 | MHD_stop_daemon (d); | 220 | MHD_stop_daemon (d); |
221 | fprintf(stderr, "\n"); | 221 | fprintf (stderr, "\n"); |
222 | return 0; | 222 | return 0; |
223 | } | 223 | } |
224 | 224 | ||
@@ -259,106 +259,109 @@ testExternalPost () | |||
259 | MHD_stop_daemon (d); | 259 | MHD_stop_daemon (d); |
260 | return 512; | 260 | return 512; |
261 | } | 261 | } |
262 | for (i=0;i<LOOPCOUNT;i++) { | 262 | for (i = 0; i < LOOPCOUNT; i++) |
263 | if (0 == i % 100) | 263 | { |
264 | fprintf(stderr, "."); | 264 | if (0 == i % 100) |
265 | c = curl_easy_init (); | 265 | fprintf (stderr, "."); |
266 | cbc.pos = 0; | 266 | c = curl_easy_init (); |
267 | buf[0] = '\0'; | 267 | cbc.pos = 0; |
268 | sprintf(url, "http://localhost:1082/hw%d", i); | 268 | buf[0] = '\0'; |
269 | curl_easy_setopt (c, CURLOPT_URL, url); | 269 | sprintf (url, "http://localhost:1082/hw%d", i); |
270 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 270 | curl_easy_setopt (c, CURLOPT_URL, url); |
271 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 271 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
272 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 272 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
273 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | 273 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
274 | curl_easy_setopt (c, CURLOPT_POST, 1L); | 274 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); |
275 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 275 | curl_easy_setopt (c, CURLOPT_POST, 1L); |
276 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L); | 276 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
277 | if (oneone) | 277 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L); |
278 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 278 | if (oneone) |
279 | else | 279 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
280 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | 280 | else |
281 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); | 281 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
282 | // NOTE: use of CONNECTTIMEOUT without also | 282 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); |
283 | // setting NOSIGNAL results in really weird | 283 | // NOTE: use of CONNECTTIMEOUT without also |
284 | // crashes on my system! | 284 | // setting NOSIGNAL results in really weird |
285 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | 285 | // crashes on my system! |
286 | mret = curl_multi_add_handle (multi, c); | 286 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); |
287 | if (mret != CURLM_OK) | 287 | mret = curl_multi_add_handle (multi, c); |
288 | { | 288 | if (mret != CURLM_OK) |
289 | curl_multi_cleanup (multi); | 289 | { |
290 | curl_easy_cleanup (c); | 290 | curl_multi_cleanup (multi); |
291 | MHD_stop_daemon (d); | 291 | curl_easy_cleanup (c); |
292 | return 1024; | 292 | MHD_stop_daemon (d); |
293 | } | 293 | return 1024; |
294 | start = time (NULL); | 294 | } |
295 | while ((time (NULL) - start < 5) && (multi != NULL)) | 295 | start = time (NULL); |
296 | { | 296 | while ((time (NULL) - start < 5) && (multi != NULL)) |
297 | max = 0; | 297 | { |
298 | FD_ZERO (&rs); | 298 | max = 0; |
299 | FD_ZERO (&ws); | 299 | FD_ZERO (&rs); |
300 | FD_ZERO (&es); | 300 | FD_ZERO (&ws); |
301 | while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform (multi, &running)); | 301 | FD_ZERO (&es); |
302 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 302 | while (CURLM_CALL_MULTI_PERFORM == |
303 | if (mret != CURLM_OK) | 303 | curl_multi_perform (multi, &running)); |
304 | { | 304 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); |
305 | curl_multi_remove_handle (multi, c); | 305 | if (mret != CURLM_OK) |
306 | curl_multi_cleanup (multi); | 306 | { |
307 | curl_easy_cleanup (c); | 307 | curl_multi_remove_handle (multi, c); |
308 | MHD_stop_daemon (d); | 308 | curl_multi_cleanup (multi); |
309 | return 2048; | 309 | curl_easy_cleanup (c); |
310 | } | 310 | MHD_stop_daemon (d); |
311 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | 311 | return 2048; |
312 | { | 312 | } |
313 | curl_multi_remove_handle (multi, c); | 313 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) |
314 | curl_multi_cleanup (multi); | 314 | { |
315 | curl_easy_cleanup (c); | 315 | curl_multi_remove_handle (multi, c); |
316 | MHD_stop_daemon (d); | 316 | curl_multi_cleanup (multi); |
317 | return 4096; | 317 | curl_easy_cleanup (c); |
318 | } | 318 | MHD_stop_daemon (d); |
319 | if (MHD_NO == MHD_get_timeout(d, &timeout)) | 319 | return 4096; |
320 | timeout = 1000000; /* 1000s == INFTY */ | 320 | } |
321 | if ( (CURLM_OK == curl_multi_timeout(multi, &ctimeout)) && | 321 | if (MHD_NO == MHD_get_timeout (d, &timeout)) |
322 | (ctimeout < timeout) && | 322 | timeout = 1000000; /* 1000s == INFTY */ |
323 | (ctimeout >= 0) ) | 323 | if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && |
324 | timeout = ctimeout; | 324 | (ctimeout < timeout) && (ctimeout >= 0)) |
325 | tv.tv_sec = timeout / 1000; | 325 | timeout = ctimeout; |
326 | tv.tv_usec = (timeout % 1000) * 1000; | 326 | tv.tv_sec = timeout / 1000; |
327 | select (max + 1, &rs, &ws, &es, &tv); | 327 | tv.tv_usec = (timeout % 1000) * 1000; |
328 | while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform (multi, &running)); | 328 | select (max + 1, &rs, &ws, &es, &tv); |
329 | if (running == 0) | 329 | while (CURLM_CALL_MULTI_PERFORM == |
330 | { | 330 | curl_multi_perform (multi, &running)); |
331 | msg = curl_multi_info_read (multi, &running); | 331 | if (running == 0) |
332 | if (msg == NULL) | 332 | { |
333 | break; | 333 | msg = curl_multi_info_read (multi, &running); |
334 | if (msg->msg == CURLMSG_DONE) | 334 | if (msg == NULL) |
335 | { | 335 | break; |
336 | if (msg->data.result != CURLE_OK) | 336 | if (msg->msg == CURLMSG_DONE) |
337 | printf ("%s failed at %s:%d: `%s'\n", | 337 | { |
338 | "curl_multi_perform", | 338 | if (msg->data.result != CURLE_OK) |
339 | __FILE__, | 339 | printf ("%s failed at %s:%d: `%s'\n", |
340 | __LINE__, curl_easy_strerror (msg->data.result)); | 340 | "curl_multi_perform", |
341 | curl_multi_remove_handle (multi, c); | 341 | __FILE__, |
342 | curl_easy_cleanup (c); | 342 | __LINE__, curl_easy_strerror (msg->data.result)); |
343 | c = NULL; | 343 | curl_multi_remove_handle (multi, c); |
344 | } | 344 | curl_easy_cleanup (c); |
345 | } | 345 | c = NULL; |
346 | MHD_run (d); | 346 | } |
347 | } | 347 | } |
348 | if (c != NULL) { | 348 | MHD_run (d); |
349 | curl_multi_remove_handle (multi, c); | 349 | } |
350 | curl_easy_cleanup (c); | 350 | if (c != NULL) |
351 | { | ||
352 | curl_multi_remove_handle (multi, c); | ||
353 | curl_easy_cleanup (c); | ||
354 | } | ||
355 | if ((buf[0] != 'O') || (buf[1] != 'K')) | ||
356 | { | ||
357 | curl_multi_cleanup (multi); | ||
358 | MHD_stop_daemon (d); | ||
359 | return 8192; | ||
360 | } | ||
351 | } | 361 | } |
352 | if ( (buf[0] != 'O') || | 362 | curl_multi_cleanup (multi); |
353 | (buf[1] != 'K') ) { | ||
354 | curl_multi_cleanup (multi); | ||
355 | MHD_stop_daemon (d); | ||
356 | return 8192; | ||
357 | } | ||
358 | } | ||
359 | curl_multi_cleanup (multi); | ||
360 | MHD_stop_daemon (d); | 363 | MHD_stop_daemon (d); |
361 | fprintf(stderr, "\n"); | 364 | fprintf (stderr, "\n"); |
362 | return 0; | 365 | return 0; |
363 | } | 366 | } |
364 | 367 | ||
diff --git a/src/daemon/daemontest_postform.c b/src/daemon/daemontest_postform.c index 0da5a74d..d02e8111 100644 --- a/src/daemon/daemontest_postform.c +++ b/src/daemon/daemontest_postform.c | |||
@@ -106,7 +106,7 @@ ahc_echo (void *cls, | |||
106 | eok = 0; | 106 | eok = 0; |
107 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); | 107 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); |
108 | if (pp == NULL) | 108 | if (pp == NULL) |
109 | abort(); | 109 | abort (); |
110 | *unused = pp; | 110 | *unused = pp; |
111 | } | 111 | } |
112 | MHD_post_process (pp, upload_data, *upload_data_size); | 112 | MHD_post_process (pp, upload_data, *upload_data_size); |
@@ -125,15 +125,16 @@ ahc_echo (void *cls, | |||
125 | return MHD_YES; | 125 | return MHD_YES; |
126 | } | 126 | } |
127 | 127 | ||
128 | static struct curl_httppost * | 128 | static struct curl_httppost * |
129 | make_form() { | 129 | make_form () |
130 | struct curl_httppost* post = NULL; | 130 | { |
131 | struct curl_httppost* last = NULL; | 131 | struct curl_httppost *post = NULL; |
132 | 132 | struct curl_httppost *last = NULL; | |
133 | curl_formadd(&post, &last, CURLFORM_COPYNAME, "name", | 133 | |
134 | CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END); | 134 | curl_formadd (&post, &last, CURLFORM_COPYNAME, "name", |
135 | curl_formadd(&post, &last, CURLFORM_COPYNAME, "project", | 135 | CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END); |
136 | CURLFORM_COPYCONTENTS, "curl", CURLFORM_END); | 136 | curl_formadd (&post, &last, CURLFORM_COPYNAME, "project", |
137 | CURLFORM_COPYCONTENTS, "curl", CURLFORM_END); | ||
137 | return post; | 138 | return post; |
138 | } | 139 | } |
139 | 140 | ||
@@ -146,7 +147,7 @@ testInternalPost () | |||
146 | char buf[2048]; | 147 | char buf[2048]; |
147 | struct CBC cbc; | 148 | struct CBC cbc; |
148 | CURLcode errornum; | 149 | CURLcode errornum; |
149 | struct curl_httppost * pd; | 150 | struct curl_httppost *pd; |
150 | 151 | ||
151 | cbc.buf = buf; | 152 | cbc.buf = buf; |
152 | cbc.size = 2048; | 153 | cbc.size = 2048; |
@@ -159,8 +160,8 @@ testInternalPost () | |||
159 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); | 160 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); |
160 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 161 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
161 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 162 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
162 | pd = make_form(); | 163 | pd = make_form (); |
163 | curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); | 164 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); |
164 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 165 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
165 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); | 166 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); |
166 | if (oneone) | 167 | if (oneone) |
@@ -178,12 +179,12 @@ testInternalPost () | |||
178 | "curl_easy_perform failed: `%s'\n", | 179 | "curl_easy_perform failed: `%s'\n", |
179 | curl_easy_strerror (errornum)); | 180 | curl_easy_strerror (errornum)); |
180 | curl_easy_cleanup (c); | 181 | curl_easy_cleanup (c); |
181 | curl_formfree(pd); | 182 | curl_formfree (pd); |
182 | MHD_stop_daemon (d); | 183 | MHD_stop_daemon (d); |
183 | return 2; | 184 | return 2; |
184 | } | 185 | } |
185 | curl_easy_cleanup (c); | 186 | curl_easy_cleanup (c); |
186 | curl_formfree(pd); | 187 | curl_formfree (pd); |
187 | MHD_stop_daemon (d); | 188 | MHD_stop_daemon (d); |
188 | if (cbc.pos != strlen ("/hello_world")) | 189 | if (cbc.pos != strlen ("/hello_world")) |
189 | return 4; | 190 | return 4; |
@@ -200,7 +201,7 @@ testMultithreadedPost () | |||
200 | char buf[2048]; | 201 | char buf[2048]; |
201 | struct CBC cbc; | 202 | struct CBC cbc; |
202 | CURLcode errornum; | 203 | CURLcode errornum; |
203 | struct curl_httppost * pd; | 204 | struct curl_httppost *pd; |
204 | 205 | ||
205 | cbc.buf = buf; | 206 | cbc.buf = buf; |
206 | cbc.size = 2048; | 207 | cbc.size = 2048; |
@@ -213,8 +214,8 @@ testMultithreadedPost () | |||
213 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); | 214 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); |
214 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 215 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
215 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 216 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
216 | pd = make_form(); | 217 | pd = make_form (); |
217 | curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); | 218 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); |
218 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 219 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
219 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); | 220 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); |
220 | if (oneone) | 221 | if (oneone) |
@@ -232,12 +233,12 @@ testMultithreadedPost () | |||
232 | "curl_easy_perform failed: `%s'\n", | 233 | "curl_easy_perform failed: `%s'\n", |
233 | curl_easy_strerror (errornum)); | 234 | curl_easy_strerror (errornum)); |
234 | curl_easy_cleanup (c); | 235 | curl_easy_cleanup (c); |
235 | curl_formfree(pd); | 236 | curl_formfree (pd); |
236 | MHD_stop_daemon (d); | 237 | MHD_stop_daemon (d); |
237 | return 32; | 238 | return 32; |
238 | } | 239 | } |
239 | curl_easy_cleanup (c); | 240 | curl_easy_cleanup (c); |
240 | curl_formfree(pd); | 241 | curl_formfree (pd); |
241 | MHD_stop_daemon (d); | 242 | MHD_stop_daemon (d); |
242 | if (cbc.pos != strlen ("/hello_world")) | 243 | if (cbc.pos != strlen ("/hello_world")) |
243 | return 64; | 244 | return 64; |
@@ -264,7 +265,7 @@ testExternalPost () | |||
264 | struct CURLMsg *msg; | 265 | struct CURLMsg *msg; |
265 | time_t start; | 266 | time_t start; |
266 | struct timeval tv; | 267 | struct timeval tv; |
267 | struct curl_httppost * pd; | 268 | struct curl_httppost *pd; |
268 | 269 | ||
269 | multi = NULL; | 270 | multi = NULL; |
270 | cbc.buf = buf; | 271 | cbc.buf = buf; |
@@ -278,8 +279,8 @@ testExternalPost () | |||
278 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); | 279 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); |
279 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 280 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
280 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 281 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
281 | pd = make_form(); | 282 | pd = make_form (); |
282 | curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); | 283 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); |
283 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 284 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
284 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L); | 285 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L); |
285 | if (oneone) | 286 | if (oneone) |
@@ -297,7 +298,7 @@ testExternalPost () | |||
297 | if (multi == NULL) | 298 | if (multi == NULL) |
298 | { | 299 | { |
299 | curl_easy_cleanup (c); | 300 | curl_easy_cleanup (c); |
300 | curl_formfree(pd); | 301 | curl_formfree (pd); |
301 | MHD_stop_daemon (d); | 302 | MHD_stop_daemon (d); |
302 | return 512; | 303 | return 512; |
303 | } | 304 | } |
@@ -305,7 +306,7 @@ testExternalPost () | |||
305 | if (mret != CURLM_OK) | 306 | if (mret != CURLM_OK) |
306 | { | 307 | { |
307 | curl_multi_cleanup (multi); | 308 | curl_multi_cleanup (multi); |
308 | curl_formfree(pd); | 309 | curl_formfree (pd); |
309 | curl_easy_cleanup (c); | 310 | curl_easy_cleanup (c); |
310 | MHD_stop_daemon (d); | 311 | MHD_stop_daemon (d); |
311 | return 1024; | 312 | return 1024; |
@@ -325,7 +326,7 @@ testExternalPost () | |||
325 | curl_multi_cleanup (multi); | 326 | curl_multi_cleanup (multi); |
326 | curl_easy_cleanup (c); | 327 | curl_easy_cleanup (c); |
327 | MHD_stop_daemon (d); | 328 | MHD_stop_daemon (d); |
328 | curl_formfree(pd); | 329 | curl_formfree (pd); |
329 | return 2048; | 330 | return 2048; |
330 | } | 331 | } |
331 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | 332 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) |
@@ -333,7 +334,7 @@ testExternalPost () | |||
333 | curl_multi_remove_handle (multi, c); | 334 | curl_multi_remove_handle (multi, c); |
334 | curl_multi_cleanup (multi); | 335 | curl_multi_cleanup (multi); |
335 | curl_easy_cleanup (c); | 336 | curl_easy_cleanup (c); |
336 | curl_formfree(pd); | 337 | curl_formfree (pd); |
337 | MHD_stop_daemon (d); | 338 | MHD_stop_daemon (d); |
338 | return 4096; | 339 | return 4096; |
339 | } | 340 | } |
@@ -368,7 +369,7 @@ testExternalPost () | |||
368 | curl_easy_cleanup (c); | 369 | curl_easy_cleanup (c); |
369 | curl_multi_cleanup (multi); | 370 | curl_multi_cleanup (multi); |
370 | } | 371 | } |
371 | curl_formfree(pd); | 372 | curl_formfree (pd); |
372 | MHD_stop_daemon (d); | 373 | MHD_stop_daemon (d); |
373 | if (cbc.pos != strlen ("/hello_world")) | 374 | if (cbc.pos != strlen ("/hello_world")) |
374 | return 8192; | 375 | return 8192; |
@@ -388,10 +389,11 @@ main (int argc, char *const *argv) | |||
388 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 389 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
389 | return 2; | 390 | return 2; |
390 | errorCount += testInternalPost (); | 391 | errorCount += testInternalPost (); |
391 | if (0) { | 392 | if (0) |
392 | errorCount += testMultithreadedPost (); | 393 | { |
393 | errorCount += testExternalPost (); | 394 | errorCount += testMultithreadedPost (); |
394 | } | 395 | errorCount += testExternalPost (); |
396 | } | ||
395 | if (errorCount != 0) | 397 | if (errorCount != 0) |
396 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 398 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
397 | curl_global_cleanup (); | 399 | curl_global_cleanup (); |
diff --git a/src/daemon/daemontest_put_chunked.c b/src/daemon/daemontest_put_chunked.c index 2abe4bd2..e4f9aa16 100644 --- a/src/daemon/daemontest_put_chunked.c +++ b/src/daemon/daemontest_put_chunked.c | |||
@@ -53,7 +53,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | |||
53 | if (wrt > 8 - (*pos)) | 53 | if (wrt > 8 - (*pos)) |
54 | wrt = 8 - (*pos); | 54 | wrt = 8 - (*pos); |
55 | if (wrt > 4) | 55 | if (wrt > 4) |
56 | wrt = 4; /* only send half at first => force multiple chunks! */ | 56 | wrt = 4; /* only send half at first => force multiple chunks! */ |
57 | memcpy (stream, &("Hello123"[*pos]), wrt); | 57 | memcpy (stream, &("Hello123"[*pos]), wrt); |
58 | (*pos) += wrt; | 58 | (*pos) += wrt; |
59 | return wrt; | 59 | return wrt; |
@@ -91,19 +91,17 @@ ahc_echo (void *cls, | |||
91 | { | 91 | { |
92 | have = *upload_data_size; | 92 | have = *upload_data_size; |
93 | if (have + *done > 8) | 93 | if (have + *done > 8) |
94 | { | 94 | { |
95 | printf ("Invalid upload data `%8s'!\n", upload_data); | 95 | printf ("Invalid upload data `%8s'!\n", upload_data); |
96 | return MHD_NO; | 96 | return MHD_NO; |
97 | } | 97 | } |
98 | if (0 == memcmp(upload_data, | 98 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) |
99 | &"Hello123"[*done], | 99 | { |
100 | have)) | 100 | *done += have; |
101 | { | 101 | *upload_data_size = 0; |
102 | *done += have; | 102 | } |
103 | *upload_data_size = 0; | ||
104 | } | ||
105 | else | 103 | else |
106 | { | 104 | { |
107 | printf ("Invalid upload data `%8s'!\n", upload_data); | 105 | printf ("Invalid upload data `%8s'!\n", upload_data); |
108 | return MHD_NO; | 106 | return MHD_NO; |
109 | } | 107 | } |
@@ -144,9 +142,9 @@ testInternalPut () | |||
144 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | 142 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
145 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | 143 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); |
146 | /* | 144 | /* |
147 | // by not giving the file size, we force chunking! | 145 | // by not giving the file size, we force chunking! |
148 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | 146 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); |
149 | */ | 147 | */ |
150 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 148 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
151 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); | 149 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); |
152 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 150 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
@@ -200,9 +198,9 @@ testMultithreadedPut () | |||
200 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | 198 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
201 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | 199 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); |
202 | /* | 200 | /* |
203 | // by not giving the file size, we force chunking! | 201 | // by not giving the file size, we force chunking! |
204 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | 202 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); |
205 | */ | 203 | */ |
206 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 204 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
207 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); | 205 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); |
208 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 206 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
@@ -268,9 +266,9 @@ testExternalPut () | |||
268 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | 266 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
269 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | 267 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); |
270 | /* | 268 | /* |
271 | // by not giving the file size, we force chunking! | 269 | // by not giving the file size, we force chunking! |
272 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | 270 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); |
273 | */ | 271 | */ |
274 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 272 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
275 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); | 273 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); |
276 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 274 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c index 3ce715ee..87de25a0 100644 --- a/src/daemon/postprocessor.c +++ b/src/daemon/postprocessor.c | |||
@@ -164,7 +164,7 @@ MHD_create_post_processor (struct MHD_Connection *connection, | |||
164 | if ((0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, | 164 | if ((0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, |
165 | encoding)) && | 165 | encoding)) && |
166 | (0 != strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding, | 166 | (0 != strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding, |
167 | strlen(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))) | 167 | strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))) |
168 | return NULL; | 168 | return NULL; |
169 | ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1); | 169 | ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1); |
170 | if (ret == NULL) | 170 | if (ret == NULL) |
@@ -430,7 +430,7 @@ post_process_multipart (struct MHD_PostProcessor *pp, | |||
430 | pp->state = PP_Headers; | 430 | pp->state = PP_Headers; |
431 | break; | 431 | break; |
432 | } | 432 | } |
433 | /* fall through! */ | 433 | /* fall through! */ |
434 | case PP_Headers: | 434 | case PP_Headers: |
435 | newline = 0; | 435 | newline = 0; |
436 | while ((newline + ioff < pp->buffer_pos) && | 436 | while ((newline + ioff < pp->buffer_pos) && |
@@ -476,8 +476,8 @@ post_process_multipart (struct MHD_PostProcessor *pp, | |||
476 | try_match_header ("Content-Type: ", &buf[ioff], &pp->content_type); | 476 | try_match_header ("Content-Type: ", &buf[ioff], &pp->content_type); |
477 | try_match_header ("Content-Transfer-Encoding: ", | 477 | try_match_header ("Content-Transfer-Encoding: ", |
478 | &buf[ioff], &pp->transfer_encoding); | 478 | &buf[ioff], &pp->transfer_encoding); |
479 | ioff += newline + 1; | 479 | ioff += newline + 1; |
480 | pp->state = PP_ExpectNewLineNOPT; | 480 | pp->state = PP_ExpectNewLineNOPT; |
481 | break; | 481 | break; |
482 | case PP_SkipRN: | 482 | case PP_SkipRN: |
483 | if (buf[ioff] == '\r') | 483 | if (buf[ioff] == '\r') |
diff --git a/src/daemon/reason_phrase.c b/src/daemon/reason_phrase.c index 403bd6cf..2dc5a826 100644 --- a/src/daemon/reason_phrase.c +++ b/src/daemon/reason_phrase.c | |||
@@ -28,15 +28,15 @@ | |||
28 | 28 | ||
29 | #include "reason_phrase.h" | 29 | #include "reason_phrase.h" |
30 | 30 | ||
31 | static const char * invalid_hundred[] = { }; | 31 | static const char *invalid_hundred[] = { }; |
32 | 32 | ||
33 | static const char * one_hundred[] = { | 33 | static const char *one_hundred[] = { |
34 | "Continue", | 34 | "Continue", |
35 | "Switching Protocols", | 35 | "Switching Protocols", |
36 | "Processing" | 36 | "Processing" |
37 | }; | 37 | }; |
38 | 38 | ||
39 | static const char* two_hundred[] = { | 39 | static const char *two_hundred[] = { |
40 | "OK", | 40 | "OK", |
41 | "Created", | 41 | "Created", |
42 | "Accepted", | 42 | "Accepted", |
@@ -46,7 +46,7 @@ static const char* two_hundred[] = { | |||
46 | "Partial Content" | 46 | "Partial Content" |
47 | }; | 47 | }; |
48 | 48 | ||
49 | static const char* three_hundred[] = { | 49 | static const char *three_hundred[] = { |
50 | "Multiple Choices", | 50 | "Multiple Choices", |
51 | "Moved Permanently", | 51 | "Moved Permanently", |
52 | "Moved Temporarily", | 52 | "Moved Temporarily", |
@@ -55,7 +55,7 @@ static const char* three_hundred[] = { | |||
55 | "Use Proxy" | 55 | "Use Proxy" |
56 | }; | 56 | }; |
57 | 57 | ||
58 | static const char* four_hundred[] = { | 58 | static const char *four_hundred[] = { |
59 | "Bad Request", | 59 | "Bad Request", |
60 | "Unauthorized", | 60 | "Unauthorized", |
61 | "Payment Required", | 61 | "Payment Required", |
@@ -74,7 +74,7 @@ static const char* four_hundred[] = { | |||
74 | "Unsupported Media Type" | 74 | "Unsupported Media Type" |
75 | }; | 75 | }; |
76 | 76 | ||
77 | static const char* five_hundred[] = { | 77 | static const char *five_hundred[] = { |
78 | "Internal Server Error", | 78 | "Internal Server Error", |
79 | "Bad Gateway", | 79 | "Bad Gateway", |
80 | "Service Unavailable", | 80 | "Service Unavailable", |
@@ -83,27 +83,27 @@ static const char* five_hundred[] = { | |||
83 | }; | 83 | }; |
84 | 84 | ||
85 | 85 | ||
86 | struct MHD_Reason_Block { | 86 | struct MHD_Reason_Block |
87 | { | ||
87 | unsigned int max; | 88 | unsigned int max; |
88 | const char ** data; | 89 | const char **data; |
89 | }; | 90 | }; |
90 | 91 | ||
91 | #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m } | 92 | #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m } |
92 | 93 | ||
93 | static const struct MHD_Reason_Block reasons[] = { | 94 | static const struct MHD_Reason_Block reasons[] = { |
94 | BLOCK(invalid_hundred), | 95 | BLOCK (invalid_hundred), |
95 | BLOCK(one_hundred), | 96 | BLOCK (one_hundred), |
96 | BLOCK(two_hundred), | 97 | BLOCK (two_hundred), |
97 | BLOCK(three_hundred), | 98 | BLOCK (three_hundred), |
98 | BLOCK(four_hundred), | 99 | BLOCK (four_hundred), |
99 | BLOCK(five_hundred), | 100 | BLOCK (five_hundred), |
100 | }; | 101 | }; |
101 | 102 | ||
102 | const char * | 103 | const char * |
103 | MHD_get_reason_phrase_for(unsigned int code) | 104 | MHD_get_reason_phrase_for (unsigned int code) |
104 | { | 105 | { |
105 | if ( (code >= 100 && code < 600) && | 106 | if ((code >= 100 && code < 600) && (reasons[code / 100].max > code % 100)) |
106 | (reasons[code / 100].max > code % 100) ) | ||
107 | return reasons[code / 100].data[code % 100]; | 107 | return reasons[code / 100].data[code % 100]; |
108 | return "Unknown"; | 108 | return "Unknown"; |
109 | } | 109 | } |
diff --git a/src/daemon/reason_phrase.h b/src/daemon/reason_phrase.h index b6376a2f..20c11d52 100644 --- a/src/daemon/reason_phrase.h +++ b/src/daemon/reason_phrase.h | |||
@@ -32,7 +32,6 @@ | |||
32 | * If we don't have a string for a status code, we give the first | 32 | * If we don't have a string for a status code, we give the first |
33 | * message in that status code class. | 33 | * message in that status code class. |
34 | */ | 34 | */ |
35 | const char* | 35 | const char *MHD_get_reason_phrase_for (unsigned int code); |
36 | MHD_get_reason_phrase_for(unsigned int code); | ||
37 | 36 | ||
38 | #endif | 37 | #endif |