aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Uzunov <andrey.uzunov@gmail.com>2013-07-21 16:40:32 +0000
committerAndrey Uzunov <andrey.uzunov@gmail.com>2013-07-21 16:40:32 +0000
commitf862cd4954d45b35fd3cacb4ef8c519f10014177 (patch)
tree94a5ab4ba0d8a408e9d55149490085875d8aab65
parentfe9c5596035ef069dd258dee825d1cc44139c6ab (diff)
downloadlibmicrohttpd-f862cd4954d45b35fd3cacb4ef8c519f10014177.tar.gz
libmicrohttpd-f862cd4954d45b35fd3cacb4ef8c519f10014177.zip
microspdy2http: minor changes
-rw-r--r--src/spdy2http/proxy.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c
index ebc29492..19cb26f6 100644
--- a/src/spdy2http/proxy.c
+++ b/src/spdy2http/proxy.c
@@ -24,6 +24,10 @@
24 * TODO: 24 * TODO:
25 * - test all options! 25 * - test all options!
26 * - don't abort on lack of memory 26 * - don't abort on lack of memory
27 * - Memory leak: in rare cases the proxy object is not freed (and there
28 * is a lot of data pointed from it)
29 * - Correct recapitalizetion of header names before giving the headers
30 * to curl.
27 * @author Andrey Uzunov 31 * @author Andrey Uzunov
28 */ 32 */
29 33
@@ -80,16 +84,16 @@ struct URI
80 84
81 85
82#define PRINT_INFO(msg) do{\ 86#define PRINT_INFO(msg) do{\
83 printf("%i:%s\n", __LINE__, msg);\ 87 fprintf(stdout, "%i:%s\n", __LINE__, msg);\
84 fflush(stdout);\ 88 fflush(stdout);\
85 }\ 89 }\
86 while(0) 90 while(0)
87 91
88 92
89#define PRINT_INFO2(fmt, ...) do{\ 93#define PRINT_INFO2(fmt, ...) do{\
90 printf("%i\n", __LINE__);\ 94 fprintf(stdout, "%i\n", __LINE__);\
91 printf(fmt,##__VA_ARGS__);\ 95 fprintf(stdout, fmt,##__VA_ARGS__);\
92 printf("\n");\ 96 fprintf(stdout, "\n");\
93 fflush(stdout);\ 97 fflush(stdout);\
94 }\ 98 }\
95 while(0) 99 while(0)
@@ -97,7 +101,7 @@ struct URI
97 101
98#define PRINT_VERBOSE(msg) do{\ 102#define PRINT_VERBOSE(msg) do{\
99 if(glob_opt.verbose){\ 103 if(glob_opt.verbose){\
100 printf("%i:%s\n", __LINE__, msg);\ 104 fprintf(stdout, "%i:%s\n", __LINE__, msg);\
101 fflush(stdout);\ 105 fflush(stdout);\
102 }\ 106 }\
103 }\ 107 }\
@@ -106,9 +110,9 @@ struct URI
106 110
107#define PRINT_VERBOSE2(fmt, ...) do{\ 111#define PRINT_VERBOSE2(fmt, ...) do{\
108 if(glob_opt.verbose){\ 112 if(glob_opt.verbose){\
109 printf("%i\n", __LINE__);\ 113 fprintf(stdout, "%i\n", __LINE__);\
110 printf(fmt,##__VA_ARGS__);\ 114 fprintf(stdout, fmt,##__VA_ARGS__);\
111 printf("\n");\ 115 fprintf(stdout, "\n");\
112 fflush(stdout);\ 116 fflush(stdout);\
113 }\ 117 }\
114 }\ 118 }\
@@ -159,12 +163,12 @@ struct Proxy
159 char *version; 163 char *version;
160 char *status_msg; 164 char *status_msg;
161 void *http_body; 165 void *http_body;
166 bool *session_alive;
162 size_t http_body_size; 167 size_t http_body_size;
163 //ssize_t length; 168 //ssize_t length;
164 int status; 169 int status;
165 bool done; 170 bool done;
166 bool error; 171 bool error;
167 bool *session_alive;
168}; 172};
169 173
170 174
@@ -526,7 +530,7 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
526 if(0 == strcasecmp(value, values[i])) 530 if(0 == strcasecmp(value, values[i]))
527 { 531 {
528 abort_it=false; 532 abort_it=false;
529 PRINT_INFO2("header appears more than once with same value '%s: %s'", name, value); 533 PRINT_VERBOSE2("header appears more than once with same value '%s: %s'", name, value);
530 break; 534 break;
531 } 535 }
532 536
@@ -596,17 +600,19 @@ iterate_cb (void *cls, const char *name, const char * const * value, int num_val
596 DIE("No memory"); 600 DIE("No memory");
597 line[0] = 0; 601 line[0] = 0;
598 602
599 strcat(line, name); 603 strcat(line, name);
600 strcat(line, ": "); 604 strcat(line, ": ");
601 //all spdy header names are lower case; 605 //all spdy header names are lower case;
602 //for simplicity here we just capitalize the first letter 606 //for simplicity here we just capitalize the first letter
603 line[0] = toupper(line[0]); 607 line[0] = toupper(line[0]);
604 608
605 for(i=0; i<num_values; ++i) 609 for(i=0; i<num_values; ++i)
606 { 610 {
607 if(i) strcat(line, ", "); 611 if(i) strcat(line, ", ");
612 PRINT_VERBOSE2("Adding request header: '%s' len %ld", value[i], strlen(value[i]));
608 strcat(line, value[i]); 613 strcat(line, value[i]);
609 } 614 }
615 PRINT_VERBOSE2("Adding request header: '%s'", line);
610 if(NULL == (*curl_headers = curl_slist_append(*curl_headers, line))) 616 if(NULL == (*curl_headers = curl_slist_append(*curl_headers, line)))
611 DIE("curl_slist_append failed"); 617 DIE("curl_slist_append failed");
612 free(line); 618 free(line);
@@ -638,8 +644,9 @@ standard_request_handler(void *cls,
638 644
639 PRINT_VERBOSE2("received request for '%s %s %s'\n", method, path, version); 645 PRINT_VERBOSE2("received request for '%s %s %s'\n", method, path, version);
640 646
647 //TODO not freed once in a while
641 if(NULL == (proxy = malloc(sizeof(struct Proxy)))) 648 if(NULL == (proxy = malloc(sizeof(struct Proxy))))
642 DIE("No memory"); 649 DIE("No memory");
643 memset(proxy, 0, sizeof(struct Proxy)); 650 memset(proxy, 0, sizeof(struct Proxy));
644 651
645 session = SPDY_get_session_for_request(request); 652 session = SPDY_get_session_for_request(request);
@@ -842,7 +849,7 @@ run ()
842 FD_ZERO(&ws); 849 FD_ZERO(&ws);
843 FD_ZERO(&es); 850 FD_ZERO(&es);
844 851
845 PRINT_INFO2("num curls %i", debug_num_curls); 852 PRINT_VERBOSE2("num curls %i", debug_num_curls);
846 853
847 ret_spdy = SPDY_get_timeout(daemon, &timeout_spdy); 854 ret_spdy = SPDY_get_timeout(daemon, &timeout_spdy);
848 if(SPDY_NO == ret_spdy || timeout_spdy > 5000) 855 if(SPDY_NO == ret_spdy || timeout_spdy > 5000)
@@ -956,11 +963,11 @@ run ()
956 DIE("no queue"); 963 DIE("no queue");
957 } 964 }
958 } 965 }
966 else
967 proxy->error = true;
959 } 968 }
960 else 969 else
961 {
962 proxy->error = true; 970 proxy->error = true;
963 }
964 call_spdy_run = true; 971 call_spdy_run = true;
965 //TODO spdy should be notified to send RST_STREAM 972 //TODO spdy should be notified to send RST_STREAM
966 } 973 }