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.c103
1 files changed, 27 insertions, 76 deletions
diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c
index f1f20814..46b25255 100644
--- a/src/spdy2http/proxy.c
+++ b/src/spdy2http/proxy.c
@@ -30,6 +30,8 @@
30 * to curl. 30 * to curl.
31 * - curl does not close sockets when connection is closed and no 31 * - curl does not close sockets when connection is closed and no
32 * new sockets are opened (they stay in CLOSE_WAIT) 32 * new sockets are opened (they stay in CLOSE_WAIT)
33 * - add '/' when a user requests http://example.com . Now this is a bad
34 * request
33 * @author Andrey Uzunov 35 * @author Andrey Uzunov
34 */ 36 */
35 37
@@ -393,20 +395,6 @@ spdy_post_data_cb (void * cls,
393 PRINT_INFO("not enough memory (malloc/realloc returned NULL)"); 395 PRINT_INFO("not enough memory (malloc/realloc returned NULL)");
394 return 0; 396 return 0;
395 } 397 }
396 /*
397 if(NULL == proxy->received_body)
398 proxy->received_body = malloc(size);
399 else
400 proxy->received_body = realloc(proxy->received_body, proxy->received_body_size + size);
401 if(NULL == proxy->received_body)
402 {
403 PRINT_INFO("not enough memory (realloc returned NULL)");
404 return 0;
405 }
406
407 memcpy(proxy->received_body + proxy->received_body_size, buf, size);
408 proxy->received_body_size += size;
409 */
410 398
411 proxy->receiving_done = !more; 399 proxy->receiving_done = !more;
412 400
@@ -436,9 +424,6 @@ response_callback (void *cls,
436{ 424{
437 ssize_t ret; 425 ssize_t ret;
438 struct Proxy *proxy = (struct Proxy *)cls; 426 struct Proxy *proxy = (struct Proxy *)cls;
439 //void *newbody;
440
441 //printf("response_callback\n");
442 427
443 *more = true; 428 *more = true;
444 429
@@ -461,27 +446,6 @@ response_callback (void *cls,
461 return -1; 446 return -1;
462 } 447 }
463 448
464 /*
465 if(max >= proxy->http_body_size)
466 {
467 ret = proxy->http_body_size;
468 newbody = NULL;
469 }
470 else
471 {
472 ret = max;
473 if(NULL == (newbody = malloc(proxy->http_body_size - max)))
474 {
475 PRINT_INFO("no memory");
476 return -1;
477 }
478 memcpy(newbody, proxy->http_body + max, proxy->http_body_size - max);
479 }
480 memcpy(buffer, proxy->http_body, ret);
481 free(proxy->http_body);
482 proxy->http_body = newbody;
483 proxy->http_body_size -= ret;
484 */
485 if(proxy->done && 0 == proxy->http_body_size) *more = false; 449 if(proxy->done && 0 == proxy->http_body_size) *more = false;
486 450
487 PRINT_VERBOSE2("given bytes to microspdy: %zd", ret); 451 PRINT_VERBOSE2("given bytes to microspdy: %zd", ret);
@@ -503,7 +467,7 @@ response_done_callback(void *cls,
503 467
504 if(SPDY_RESPONSE_RESULT_SUCCESS != status) 468 if(SPDY_RESPONSE_RESULT_SUCCESS != status)
505 { 469 {
506 printf("answer was NOT sent, %i\n",status); 470 PRINT_VERBOSE2("answer was NOT sent, %i\n",status);
507 free(proxy->http_body); 471 free(proxy->http_body);
508 proxy->http_body = NULL; 472 proxy->http_body = NULL;
509 } 473 }
@@ -522,7 +486,6 @@ response_done_callback(void *cls,
522} 486}
523 487
524 488
525
526static size_t 489static size_t
527curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp) 490curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
528{ 491{
@@ -559,6 +522,7 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
559 &response_callback, 522 &response_callback,
560 proxy, 523 proxy,
561 0))) 524 0)))
525 //256)))
562 DIE("no response"); 526 DIE("no response");
563 527
564 SPDY_name_value_destroy(proxy->headers); 528 SPDY_name_value_destroy(proxy->headers);
@@ -571,7 +535,12 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
571 false, 535 false,
572 &response_done_callback, 536 &response_done_callback,
573 proxy)) 537 proxy))
574 DIE("no queue"); 538 {
539 //DIE("no queue");
540 //TODO right?
541 proxy->error = true;
542 return 0;
543 }
575 544
576 call_spdy_run = true; 545 call_spdy_run = true;
577 546
@@ -1036,6 +1005,8 @@ run ()
1036 flags, 1005 flags,
1037 SPDY_DAEMON_OPTION_SOCK_ADDR, 1006 SPDY_DAEMON_OPTION_SOCK_ADDR,
1038 addr, 1007 addr,
1008 //SPDY_DAEMON_OPTION_MAX_NUM_FRAMES,
1009 //1,
1039 SPDY_DAEMON_OPTION_END); 1010 SPDY_DAEMON_OPTION_END);
1040 } 1011 }
1041 1012
@@ -1152,41 +1123,21 @@ run ()
1152 SPDY_name_value_destroy(proxy->headers); 1123 SPDY_name_value_destroy(proxy->headers);
1153 if(!*(proxy->session_alive)) 1124 if(!*(proxy->session_alive))
1154 { 1125 {
1155 /*if(NULL == (error_response = SPDY_build_response(SPDY_HTTP_BAD_GATEWAY, 1126 free(proxy->http_body);
1156 NULL, 1127 proxy->http_body = NULL;
1157 SPDY_HTTP_VERSION_1_1, 1128
1158 NULL, 1129 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle)))
1159 ERROR_RESPONSE,
1160 strlen(ERROR_RESPONSE))))
1161 DIE("no response");
1162 if(SPDY_YES != SPDY_queue_response(proxy->request,
1163 error_response,
1164 true,
1165 false,
1166 &response_done_callback,
1167 proxy))
1168 { 1130 {
1169 //clean and forget 1131 PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret);
1170 //TODO 1132 }
1171 DIE("no queue"); 1133 debug_num_curls--;
1172 }*/ 1134 curl_slist_free_all(proxy->curl_headers);
1135 curl_easy_cleanup(proxy->curl_handle);
1173 1136
1174 free(proxy->http_body); 1137 SPDY_destroy_request(proxy->request);
1175 proxy->http_body = NULL; 1138 //SPDY_destroy_response(proxy->response);
1176 1139 free(proxy->url);
1177 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle))) 1140 free(proxy);
1178 {
1179 PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret);
1180 }
1181 debug_num_curls--;
1182 curl_slist_free_all(proxy->curl_headers);
1183 curl_easy_cleanup(proxy->curl_handle);
1184
1185 SPDY_destroy_request(proxy->request);
1186 //SPDY_destroy_response(proxy->response);
1187 free(proxy->url);
1188 free(proxy);
1189
1190 } 1141 }
1191 else 1142 else
1192 proxy->error = true; 1143 proxy->error = true;
@@ -1216,11 +1167,11 @@ run ()
1216 } 1167 }
1217 } 1168 }
1218 while(loop); 1169 while(loop);
1219
1220 curl_multi_cleanup(multi_handle);
1221 1170
1222 SPDY_stop_daemon(daemon); 1171 SPDY_stop_daemon(daemon);
1223 1172
1173 curl_multi_cleanup(multi_handle);
1174
1224 SPDY_deinit(); 1175 SPDY_deinit();
1225 1176
1226 deinit_parse_uri(&uri_preg); 1177 deinit_parse_uri(&uri_preg);