From: Siddhesh P. <sid...@us...> - 2009-06-27 20:46:38
|
Update of /cvsroot/ayttm/ayttm/libproxy In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv566/libproxy Modified Files: Tag: netv2 net_constants.h networking.c networking.h Log Message: * Added Server connection to accept connections * Fixed synchronous connection code * Moved yahoo to netv2 Index: net_constants.h =================================================================== RCS file: /cvsroot/ayttm/ayttm/libproxy/Attic/net_constants.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- net_constants.h 17 Apr 2009 11:29:30 -0000 1.1.2.1 +++ net_constants.h 27 Jun 2009 20:45:57 -0000 1.1.2.2 @@ -53,7 +53,8 @@ typedef enum { AY_CONNECTION_TYPE_PLAIN = 1, - AY_CONNECTION_TYPE_SSL = 2 + AY_CONNECTION_TYPE_SSL = 2, + AY_CONNECTION_TYPE_SERVER = 3 } AyConnectionType ; Index: networking.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/libproxy/Attic/networking.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- networking.c 17 Apr 2009 11:29:30 -0000 1.1.2.1 +++ networking.c 27 Jun 2009 20:45:57 -0000 1.1.2.2 @@ -71,6 +71,7 @@ typedef struct { int sockfd; + int listenfd; #ifdef HAVE_OPENSSL SSL *ssl; #endif @@ -216,7 +217,20 @@ con->status_callback(message, con->cb_data); } - if (!con->connect) { + /* If it's a server connection then just wait for a connection */ + if ( con->connection->priv->type == AY_CONNECTION_TYPE_SERVER ) { + int newfd = 0; + + if ( (newfd = accept(con->connection->priv->fd.listenfd, NULL, 0)) < 0 ) { + con->connection->priv->status = errno; + con->connection->priv->fd.sockfd = -1; + } + else { + con->connection->priv->fd.sockfd = newfd; + } + } + /* Direct Connection */ + else if (!con->connect) { con->connection->priv->fd.sockfd = connect_address(con->connection->priv->host, con->connection->priv->port); if( !ay_check_continue_connecting(con, leash) ) @@ -225,6 +239,7 @@ if(con->connection->priv->fd.sockfd<0) con->connection->priv->status = errno; } + /* Proxy */ else { int proxyfd = 0; @@ -359,6 +374,32 @@ } +int ay_connection_listen(AyConnection *con) +{ + struct sockaddr_in addr; + + con->priv->fd.listenfd = socket(AF_INET, SOCK_STREAM, 0); + + if (con->priv->fd.listenfd == -1 ) + return -1; + + memset (&addr, 0, sizeof(struct sockaddr_in)); + + addr.sin_family = AF_INET; + addr.sin_port = htons(con->priv->port); + + /* Bind and listen to the socket */ + if(bind( con->priv->fd.listenfd, (struct sockaddr *)(&addr), sizeof(addr)) < 0 + || listen(con->priv->fd.listenfd, 1) < 0 ) + { + close(con->priv->fd.listenfd); + return -1; + } + + return 0; +} + + int ay_connection_connect( AyConnection *con, AyConnectCallback cb, AyStatusCallback scb, AyCertVerifyCallback vfy_cb, void *data ) { @@ -397,15 +438,9 @@ return connector->source; } else { - int sockfd; - _do_connect(connector); - sockfd = connector->connection->priv->fd.sockfd; - - g_free(connector); - - return sockfd; + return 0; } } @@ -426,6 +461,11 @@ close(con->priv->fd.sockfd); con->priv->fd.sockfd = -1; } + + if ( con->priv->fd.listenfd >= 0 ) { + close(con->priv->fd.listenfd); + con->priv->fd.listenfd = -1; + } } Index: networking.h =================================================================== RCS file: /cvsroot/ayttm/ayttm/libproxy/Attic/networking.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- networking.h 17 Apr 2009 11:29:30 -0000 1.1.2.1 +++ networking.h 27 Jun 2009 20:45:57 -0000 1.1.2.2 @@ -53,6 +53,8 @@ * Returning a non-zero value results in validation of certificate */ typedef int ( *AyCertVerifyCallback )(const char *message, const char *title); +#define AY_CONNECTION(con) ((AyConnection *)con) + #ifdef __cplusplus extern "C" { #endif @@ -75,6 +77,8 @@ AyCertVerifyCallback verify_callback, void *cb_data ) ; +#define ay_connection_accept ay_connection_connect + void ay_connection_disconnect (AyConnection *con); void ay_connection_cancel_connect (AyConnection *con); |