X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=popproxy.c;h=5e3a91f909015b3081e71e51311a522adccbfe85;hb=d2906090b274ce2698952608ccf737912f7725d5;hp=34a1c908d10855f2c7875d00743801ffcf439ed2;hpb=268611d2bf7a824189cd6a8f3f492847a55ec785;p=cascardo%2Frnetproxy.git diff --git a/popproxy.c b/popproxy.c index 34a1c90..5e3a91f 100644 --- a/popproxy.c +++ b/popproxy.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "log.h" #include "pop.h" @@ -129,11 +130,34 @@ push_other (HCConn *conn, HCEvent event, gpointer data) } } +static void +ssl_connected (HCConn *client_conn, HCEvent event, gpointer data) +{ + struct pop_address *address = data; + HCConn *server_conn; + if (event != HC_EVENT_CONNECT) + { + g_debug ("Did not get connect event when trying to handshake:" + " got %d", event); + hc_conn_close (client_conn); + return; + } + server_conn = server_conn_new (address->server, address->port, + address->ssl); + if (server_conn == NULL) + { + g_debug ("Failure to create connection to server."); + hc_conn_close (client_conn); + return; + } + hc_conn_set_callback (client_conn, push_other, server_conn); + hc_conn_set_callback (server_conn, push_other, client_conn); +} + static void new_client (int fd, struct sockaddr *addr, socklen_t saddr, gpointer data) { HCConn *client_conn; - HCConn *server_conn; struct pop_address *address = data; if (fd < 0) { @@ -145,21 +169,16 @@ new_client (int fd, struct sockaddr *addr, socklen_t saddr, gpointer data) g_message ("Received connection from %s.", inet_ntoa (((struct sockaddr_in *) addr)->sin_addr)); - server_conn = server_conn_new (address->server, address->port, - address->ssl); - if (server_conn == NULL) - { - return; - } client_conn = client_conn_new (fd); if (client_conn == NULL) { - hc_conn_close (server_conn); return; } - hc_conn_set_callback (client_conn, push_other, server_conn); - hc_conn_set_callback (server_conn, push_other, client_conn); + if (address->ssl) + hc_conn_set_callback (client_conn, ssl_connected, address); + else + ssl_connected (client_conn, HC_EVENT_CONNECT, address); } @@ -192,6 +211,8 @@ int main (int argc, char **argv) gchar *policy; struct pop_address pop_address; + signal (SIGPIPE, SIG_IGN); + gnutls_global_init (); configfile = CONFFILE;