aboutsummaryrefslogtreecommitdiff
path: root/src/spdy2http/proxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/spdy2http/proxy.c')
-rw-r--r--src/spdy2http/proxy.c71
1 files changed, 39 insertions, 32 deletions
diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c
index c5457977..ebc29492 100644
--- a/src/spdy2http/proxy.c
+++ b/src/spdy2http/proxy.c
@@ -275,6 +275,8 @@ parse_uri(regex_t * preg, const char * full_uri, struct URI ** uri)
275 275
276static void catch_signal(int signal) 276static void catch_signal(int signal)
277{ 277{
278 (void)signal;
279
278 loop = 0; 280 loop = 0;
279} 281}
280 282
@@ -282,6 +284,8 @@ static void
282new_session_cb (void * cls, 284new_session_cb (void * cls,
283 struct SPDY_Session * session) 285 struct SPDY_Session * session)
284{ 286{
287 (void)cls;
288
285 bool *session_alive; 289 bool *session_alive;
286 290
287 PRINT_VERBOSE("new session"); 291 PRINT_VERBOSE("new session");
@@ -300,6 +304,8 @@ session_closed_cb (void * cls,
300 struct SPDY_Session * session, 304 struct SPDY_Session * session,
301 int by_client) 305 int by_client)
302{ 306{
307 (void)cls;
308
303 bool *session_alive; 309 bool *session_alive;
304 310
305 PRINT_VERBOSE2("session closed; by client: %i", by_client); 311 PRINT_VERBOSE2("session closed; by client: %i", by_client);
@@ -406,8 +412,8 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
406 char *name; 412 char *name;
407 char *value; 413 char *value;
408 char *status; 414 char *status;
409 int i; 415 unsigned int i;
410 int pos; 416 unsigned int pos;
411 int ret; 417 int ret;
412 int num_values; 418 int num_values;
413 const char * const * values; 419 const char * const * values;
@@ -516,7 +522,7 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
516 { 522 {
517 abort_it=true; 523 abort_it=true;
518 if(NULL != (values = SPDY_name_value_lookup(proxy->headers, name, &num_values))) 524 if(NULL != (values = SPDY_name_value_lookup(proxy->headers, name, &num_values)))
519 for(i=0; i<num_values; ++i) 525 for(i=0; i<(unsigned int)num_values; ++i)
520 if(0 == strcasecmp(value, values[i])) 526 if(0 == strcasecmp(value, values[i]))
521 { 527 {
522 abort_it=false; 528 abort_it=false;
@@ -753,6 +759,7 @@ run ()
753 enum SPDY_IO_SUBSYSTEM io = glob_opt.notls ? SPDY_IO_SUBSYSTEM_RAW : SPDY_IO_SUBSYSTEM_OPENSSL; 759 enum SPDY_IO_SUBSYSTEM io = glob_opt.notls ? SPDY_IO_SUBSYSTEM_RAW : SPDY_IO_SUBSYSTEM_OPENSSL;
754 enum SPDY_DAEMON_FLAG flags = SPDY_DAEMON_FLAG_NO; 760 enum SPDY_DAEMON_FLAG flags = SPDY_DAEMON_FLAG_NO;
755 struct SPDY_Response *error_response; 761 struct SPDY_Response *error_response;
762 char *curl_private;
756 763
757 signal(SIGPIPE, SIG_IGN); 764 signal(SIGPIPE, SIG_IGN);
758 765
@@ -842,17 +849,17 @@ run ()
842 timeoutlong = 5000; 849 timeoutlong = 5000;
843 else 850 else
844 timeoutlong = timeout_spdy; 851 timeoutlong = timeout_spdy;
845 PRINT_VERBOSE2("SPDY timeout %i; %i", timeout_spdy, ret_spdy); 852 PRINT_VERBOSE2("SPDY timeout %lld; %i", timeout_spdy, ret_spdy);
846 853
847 if(CURLM_OK != (ret_curl = curl_multi_timeout(multi_handle, &timeout_curl))) 854 if(CURLM_OK != (ret_curl = curl_multi_timeout(multi_handle, &timeout_curl)))
848 { 855 {
849 PRINT_VERBOSE2("curl_multi_timeout failed (%i)", ret_curl); 856 PRINT_VERBOSE2("curl_multi_timeout failed (%i)", ret_curl);
850 //curl_timeo = timeoutlong; 857 //curl_timeo = timeoutlong;
851 } 858 }
852 else if(timeoutlong > timeout_curl) 859 else if(timeout_curl >= 0 && timeoutlong > (unsigned long)timeout_curl)
853 timeoutlong = timeout_curl; 860 timeoutlong = (unsigned long)timeout_curl;
854 861
855 PRINT_VERBOSE2("curl timeout %i", timeout_curl); 862 PRINT_VERBOSE2("curl timeout %ld", timeout_curl);
856 863
857 timeout.tv_sec = timeoutlong / 1000; 864 timeout.tv_sec = timeoutlong / 1000;
858 timeout.tv_usec = (timeoutlong % 1000) * 1000; 865 timeout.tv_usec = (timeoutlong % 1000) * 1000;
@@ -874,9 +881,9 @@ run ()
874 if(maxfd_curl > maxfd) 881 if(maxfd_curl > maxfd)
875 maxfd = maxfd_curl; 882 maxfd = maxfd_curl;
876 883
877 PRINT_VERBOSE2("timeout before %i %i", timeout.tv_sec, timeout.tv_usec); 884 PRINT_VERBOSE2("timeout before %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec);
878 ret = select(maxfd+1, &rs, &ws, &es, &timeout); 885 ret = select(maxfd+1, &rs, &ws, &es, &timeout);
879 PRINT_VERBOSE2("timeout after %i %i; ret is %i", timeout.tv_sec, timeout.tv_usec, ret); 886 PRINT_VERBOSE2("timeout after %lld %lld; ret is %i", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec, ret);
880 887
881 /*switch(ret) { 888 /*switch(ret) {
882 case -1: 889 case -1:
@@ -910,11 +917,13 @@ run ()
910 917
911 while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) { 918 while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
912 if (msg->msg == CURLMSG_DONE) { 919 if (msg->msg == CURLMSG_DONE) {
913 if(CURLE_OK != (ret = curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &proxy))) 920 if(CURLE_OK != (ret = curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &curl_private)))
914 { 921 {
915 PRINT_INFO2("err %i",ret); 922 PRINT_INFO2("err %i",ret);
916 abort(); 923 abort();
917 } 924 }
925 assert(NULL != curl_private);
926 proxy = (struct Proxy *)curl_private;
918 if(CURLE_OK == msg->data.result) 927 if(CURLE_OK == msg->data.result)
919 { 928 {
920 proxy->done = true; 929 proxy->done = true;
@@ -926,23 +935,26 @@ run ()
926 if(NULL == proxy->response) 935 if(NULL == proxy->response)
927 { 936 {
928 SPDY_name_value_destroy(proxy->headers); 937 SPDY_name_value_destroy(proxy->headers);
929 if(NULL == (error_response = SPDY_build_response(SPDY_HTTP_BAD_GATEWAY, 938 if(!*(proxy->session_alive))
930 NULL,
931 SPDY_HTTP_VERSION_1_1,
932 NULL,
933 ERROR_RESPONSE,
934 strlen(ERROR_RESPONSE))))
935 DIE("no response");
936 if(SPDY_YES != SPDY_queue_response(proxy->request,
937 error_response,
938 true,
939 false,
940 &response_done_callback,
941 proxy))
942 { 939 {
943 //clean and forget 940 if(NULL == (error_response = SPDY_build_response(SPDY_HTTP_BAD_GATEWAY,
944 //TODO 941 NULL,
945 DIE("no queue"); 942 SPDY_HTTP_VERSION_1_1,
943 NULL,
944 ERROR_RESPONSE,
945 strlen(ERROR_RESPONSE))))
946 DIE("no response");
947 if(SPDY_YES != SPDY_queue_response(proxy->request,
948 error_response,
949 true,
950 false,
951 &response_done_callback,
952 proxy))
953 {
954 //clean and forget
955 //TODO
956 DIE("no queue");
957 }
946 } 958 }
947 } 959 }
948 else 960 else
@@ -968,7 +980,7 @@ run ()
968 980
969 struct timespec ts; 981 struct timespec ts;
970 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 982 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
971 PRINT_VERBOSE2("time now %i %i", ts.tv_sec, ts.tv_nsec); 983 PRINT_VERBOSE2("time now %lld %lld", (unsigned long long)ts.tv_sec, (unsigned long long)ts.tv_nsec);
972 } 984 }
973 } 985 }
974 while(loop); 986 while(loop);
@@ -1110,11 +1122,6 @@ main (int argc, char *const *argv)
1110 1122
1111 case 'T': 1123 case 'T':
1112 glob_opt.timeout = atoi(optarg); 1124 glob_opt.timeout = atoi(optarg);
1113 if(glob_opt.timeout < 0)
1114 {
1115 display_usage();
1116 return 1;
1117 }
1118 break; 1125 break;
1119 1126
1120 case 0: 1127 case 0: