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.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c
index e495cc72..620dc219 100644
--- a/src/spdy2http/proxy.c
+++ b/src/spdy2http/proxy.c
@@ -48,6 +48,7 @@ struct global_options
48 char *http_backend; 48 char *http_backend;
49 char *cert; 49 char *cert;
50 char *cert_key; 50 char *cert_key;
51 char *listen_host;
51 uint16_t listen_port; 52 uint16_t listen_port;
52 bool verbose; 53 bool verbose;
53 bool curl_verbose; 54 bool curl_verbose;
@@ -584,7 +585,7 @@ standard_request_handler(void *cls,
584 DIE("No memory"); 585 DIE("No memory");
585 } 586 }
586 587
587 free(uri); 588 free_uri(uri);
588 589
589 PRINT_VERBOSE2("curl will request '%s'", proxy->url); 590 PRINT_VERBOSE2("curl will request '%s'", proxy->url);
590 591
@@ -642,7 +643,13 @@ run()
642 CURLMsg *msg; 643 CURLMsg *msg;
643 int msgs_left; 644 int msgs_left;
644 struct Proxy *proxy; 645 struct Proxy *proxy;
645 646 struct sockaddr_in *addr;
647 struct sockaddr_in addr4;
648 struct in_addr inaddr4;
649 struct addrinfo hints;
650 char service[NI_MAXSERV];
651 struct addrinfo *gai;
652
646 signal(SIGPIPE, SIG_IGN); 653 signal(SIGPIPE, SIG_IGN);
647 654
648 if (signal(SIGINT, catch_signal) == SIG_ERR) 655 if (signal(SIGINT, catch_signal) == SIG_ERR)
@@ -653,8 +660,35 @@ run()
653 DIE("Regexp compilation failed"); 660 DIE("Regexp compilation failed");
654 661
655 SPDY_init(); 662 SPDY_init();
656 663
657 daemon = SPDY_start_daemon(glob_opt.listen_port, 664 if(NULL == glob_opt.listen_host)
665 {
666 daemon = SPDY_start_daemon(glob_opt.listen_port,
667 glob_opt.cert,
668 glob_opt.cert_key,
669 NULL,
670 NULL,
671 &standard_request_handler,
672 NULL,
673 NULL,
674 SPDY_DAEMON_OPTION_SESSION_TIMEOUT,
675 1800,
676 SPDY_DAEMON_OPTION_END);
677 }
678 else
679 {
680 snprintf(service, sizeof(service), "%u", glob_opt.listen_port);
681 memset(&hints, 0, sizeof(struct addrinfo));
682 hints.ai_family = AF_UNSPEC;
683 hints.ai_socktype = SOCK_STREAM;
684
685 ret = getaddrinfo(glob_opt.listen_host, service, &hints, &gai);
686 if(ret != 0)
687 DIE("problem with specified host");
688
689 addr=gai->ai_addr;
690
691 daemon = SPDY_start_daemon(0,
658 glob_opt.cert, 692 glob_opt.cert,
659 glob_opt.cert_key, 693 glob_opt.cert_key,
660 NULL, 694 NULL,
@@ -664,7 +698,10 @@ run()
664 NULL, 698 NULL,
665 SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 699 SPDY_DAEMON_OPTION_SESSION_TIMEOUT,
666 1800, 700 1800,
701 SPDY_DAEMON_OPTION_SOCK_ADDR,
702 addr,
667 SPDY_DAEMON_OPTION_END); 703 SPDY_DAEMON_OPTION_END);
704 }
668 705
669 if(NULL==daemon){ 706 if(NULL==daemon){
670 printf("no daemon\n"); 707 printf("no daemon\n");
@@ -801,9 +838,11 @@ void
801display_usage() 838display_usage()
802{ 839{
803 printf( 840 printf(
804 "Usage: microspdy2http [-vh0t] [-b <HTTP-SERVER>] -p <PORT> -c <CERTIFICATE> -k <CERT-KEY>\n\n" 841 "Usage: microspdy2http -p <PORT> -c <CERTIFICATE> -k <CERT-KEY>\n"
842 " [-vh0t] [-b <HTTP-SERVER>] [-l <HOST>]\n\n"
805 "OPTIONS:\n" 843 "OPTIONS:\n"
806 " -p, --port Listening port.\n" 844 " -p, --port Listening port.\n"
845 " -l, --host Listening host. If not set, will listen on [::]\n"
807 " -c, --certificate Path to a certificate file.\n" 846 " -c, --certificate Path to a certificate file.\n"
808 " -k, --certificate-key Path to a key file for the certificate.\n" 847 " -k, --certificate-key Path to a key file for the certificate.\n"
809 " -b, --backend-server If set, the proxy will connect always to it.\n" 848 " -b, --backend-server If set, the proxy will connect always to it.\n"
@@ -839,7 +878,7 @@ main (int argc, char *const *argv)
839 878
840 while (1) 879 while (1)
841 { 880 {
842 getopt_ret = getopt_long( argc, argv, "p:c:k:b:v0t", long_options, &option_index); 881 getopt_ret = getopt_long( argc, argv, "p:l:c:k:b:v0t", long_options, &option_index);
843 if (getopt_ret == -1) 882 if (getopt_ret == -1)
844 break; 883 break;
845 884
@@ -849,6 +888,12 @@ main (int argc, char *const *argv)
849 glob_opt.listen_port = atoi(optarg); 888 glob_opt.listen_port = atoi(optarg);
850 break; 889 break;
851 890
891 case 'l':
892 glob_opt.listen_host= strdup(optarg);
893 if(NULL == glob_opt.listen_host)
894 return 1;
895 break;
896
852 case 'c': 897 case 'c':
853 glob_opt.cert = strdup(optarg); 898 glob_opt.cert = strdup(optarg);
854 if(NULL == glob_opt.cert) 899 if(NULL == glob_opt.cert)