X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=popproxy.c;h=3a12f715eea183160a560302486e3573729970db;hb=7d2ac978e497f976b43f35af1ab27b82c842c182;hp=3217b006f4fc437aeee1cca6ecbb36898e98bb47;hpb=2f6f433ac65fb6f4208a3ac8519cf53941745cc4;p=cascardo%2Frnetproxy.git diff --git a/popproxy.c b/popproxy.c index 3217b00..3a12f71 100644 --- a/popproxy.c +++ b/popproxy.c @@ -45,11 +45,30 @@ server_conn_new (char *server, char *port) int fd; HCConn *conn; HCConn *ssl_conn; + int r; + fd = hc_tcp_connect (server, port); + if (fd < 0) + { + g_warning ("Could not connect to server at %s:%s.", server, port); + return NULL; + } conn = hc_conn_new (NULL, NULL); ssl_conn = hc_conn_new (NULL, NULL); - fd = hc_tcp_connect (server, port); - hc_conn_set_driver_channel (conn, fd); - hc_conn_set_driver_ssl (ssl_conn, conn); + r = hc_conn_set_driver_channel (conn, fd); + if (r != 0) + { + hc_conn_close (ssl_conn); + hc_conn_close (conn); + close (fd); + return NULL; + } + r = hc_conn_set_driver_ssl_client (ssl_conn, conn); + if (r != 0) + { + hc_conn_close (ssl_conn); + hc_conn_close (conn); + return NULL; + } return ssl_conn; } @@ -75,21 +94,47 @@ static void new_client (int fd, struct sockaddr *addr, socklen_t saddr, gpointer data) { HCConn *conn; + HCConn *pop_conn; HCConn *server_conn; - net_hook_t *hook; struct pop_address *address = data; + int r; if (fd < 0) { g_critical ("Server has received an error event."); return; } + + /* FIXME: Should be independent of address type. */ g_message ("Received connection from %s.", inet_ntoa (((struct sockaddr_in *) addr)->sin_addr)); - conn = hc_conn_new (NULL, NULL); - hc_conn_set_driver_channel (conn, fd); + server_conn = server_conn_new (address->server, address->port); - hc_conn_set_callback (conn, push_other, server_conn); - hc_conn_set_callback (server_conn, push_other, conn); + if (server_conn == NULL) + { + return; + } + + conn = hc_conn_new (NULL, NULL); + r = hc_conn_set_driver_channel (conn, fd); + if (r != 0) + { + hc_conn_close (server_conn); + hc_conn_close (conn); + close (fd); + return; + } + pop_conn = hc_conn_new (NULL, NULL); + r = hc_conn_set_driver_pop (pop_conn, conn); + if (r != 0) + { + hc_conn_close (server_conn); + hc_conn_close (pop_conn); + hc_conn_close (conn); + return; + } + hc_conn_set_callback (pop_conn, push_other, server_conn); + hc_conn_set_callback (server_conn, push_other, pop_conn); + } static gchar *configfile;