--------------------- PatchSet 2719 Date: 2001/08/05 16:30:21 Author: adri Branch: newhttp Tag: (none) Log: * add http_client_conn_state_t - basically its ConnStateData .. * flesh out the accept routine * add timeout/close routines This code is looking a lot like the code in the old client_side.c. Thats fine for now. :) Members: src/modules/new_http_client/client_side.c:1.1.2.3->1.1.2.4 src/modules/new_http_client/client_side.h:1.1.2.1->1.1.2.2 Index: squid/src/modules/new_http_client/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/modules/new_http_client/Attic/client_side.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/modules/new_http_client/client_side.c 5 Aug 2001 15:49:46 -0000 1.1.2.3 +++ squid/src/modules/new_http_client/client_side.c 5 Aug 2001 16:30:21 -0000 1.1.2.4 @@ -7,9 +7,13 @@ static int new_http_sockets[MAXHTTPPORTS]; static int new_http_nsockets = 0; +CBDATA_TYPE(http_client_conn_state_t); + static void new_http_client_connections_open(void); static void new_http_client_connections_close(void); static PF new_http_client_accept; +static PF new_http_client_conn_free; +static PF new_http_client_conn_timeout; void @@ -33,6 +37,11 @@ void new_http_client_setup(void) { + /* Setup our memory pools */ + + /* Setup our cbdata pools */ + CBDATA_INIT_TYPE(http_client_conn_state_t); + /* Attempt to open the new http connections, fail if none open */ new_http_client_connections_open(); if (new_http_nsockets < 1) @@ -108,6 +117,7 @@ { int newfd; struct sockaddr_in peer, me; + http_client_conn_state_t *conn; /* Accept the incoming connection */ newfd = comm_accept(fd, &peer, &me); @@ -125,9 +135,58 @@ } /* We've got a valid connection - create local state */ + conn = cbdataAlloc(http_client_conn_state_t); + + /* Update local state */ + conn->fd = fd; + conn->peer = peer; + conn->me = me; + conn->log_addr = peer.sin_addr; + /* This implements logged client IP masking */ + conn->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; + conn->nrequests = 0; + + /* Perform FQDN lookup if we need to */ + if (Config.onoff.log_fqdn) + fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); /* Account */ + clientdbEstablished(peer.sin_addr, 1); + + /* Add a close handler */ + comm_add_close_handler(fd, new_http_client_conn_free, conn); + + /* Set a request timeout handler */ + commSetTimeout(fd, Config.Timeout.request, new_http_client_conn_timeout, conn); /* Initiate the read */ } + + +/* + * handle a connection that has timed out + */ +static void +new_http_client_conn_timeout(int fd, void *data) +{ + /* For now, just close the connection */ + comm_close(fd); +} + +/* + * close a connection + */ +static void +new_http_client_conn_free(int fd, void *data) +{ + http_client_conn_state_t *conn = data; + + /* Account */ + clientdbEstablished(conn->peer.sin_addr, -1); + + /* Close any pending http client connections */ + + /* Deallocate */ + cbdataFree(conn); +} Index: squid/src/modules/new_http_client/client_side.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/modules/new_http_client/Attic/client_side.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/modules/new_http_client/client_side.h 4 Aug 2001 16:28:14 -0000 1.1.2.1 +++ squid/src/modules/new_http_client/client_side.h 5 Aug 2001 16:30:21 -0000 1.1.2.2 @@ -1,9 +1,23 @@ #ifndef __CLIENT_SIDE_H__ #define __CLIENT_SIDE_H__ + +/* Local structs */ + +struct http_client_conn_state { + int fd; + struct sockaddr_in peer; + struct sockaddr_in me; + struct in_addr log_addr; + char rfc931[USER_IDENT_SZ]; + int nrequests; +}; + +/* Local typedefs */ +typedef struct http_client_conn_state http_client_conn_state_t; + /* Local http sockets */ extern int new_http_sockets[MAXHTTPPORTS]; extern int new_http_nsockets; - #endif