--------------------- PatchSet 5998 Date: 2003/10/29 17:24:57 Author: dwsquid Branch: icap-2_5 Tag: (none) Log: combine replicated code into icapReqModCreateClientState(). Members: src/icap_reqmod.c:1.1.2.10->1.1.2.11 Index: squid/src/icap_reqmod.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_reqmod.c,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- squid/src/icap_reqmod.c 29 Oct 2003 16:18:07 -0000 1.1.2.10 +++ squid/src/icap_reqmod.c 29 Oct 2003 17:24:57 -0000 1.1.2.11 @@ -1,5 +1,5 @@ /* - * $Id: icap_reqmod.c,v 1.1.2.10 2003/10/29 16:18:07 dwsquid Exp $ + * $Id: icap_reqmod.c,v 1.1.2.11 2003/10/29 17:24:57 dwsquid Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -68,32 +68,45 @@ } /* - * icapReqModInterpretHttpRequest + * icapReqModCreateClientState * - * Interpret an HTTP request that we read from the ICAP server. - * Create some "fake" clientHttpRequest and ConnStateData structures - * so we can pass this new request off to the routines in - * client_side.c. + * Creates fake client_side data structures so we can use + * that module to read/parse the HTTP request that we read + * from the ICAP server. */ -static void -icapReqModInterpretHttpRequest(IcapStateData * icap, request_t * request) +static clientHttpRequest * +icapReqModCreateClientState(IcapStateData *icap) { clientHttpRequest *http; - http = cbdataAlloc(clientHttpRequest); - http->uri = xstrdup(urlCanonicalClean(request)); + http->uri = xstrdup(urlCanonicalClean(icap->request)); http->log_uri = xstrndup(http->uri, MAX_URL); http->range_iter.boundary = StringNull; - http->request = requestLink(request); + http->request = requestLink(icap->request); http->flags.did_icap_reqmod = 1; - + http->start = current_time; http->conn = cbdataAlloc(ConnStateData); http->conn->fd = icap->reqmod.client_fd; http->conn->in.size = 0; http->conn->in.buf = NULL; http->conn->chr = http; - comm_add_close_handler(http->conn->fd, connStateFree, http->conn); + return http; +} + +/* + * icapReqModInterpretHttpRequest + * + * Interpret an HTTP request that we read from the ICAP server. + * Create some "fake" clientHttpRequest and ConnStateData structures + * so we can pass this new request off to the routines in + * client_side.c. + */ +static void +icapReqModInterpretHttpRequest(IcapStateData * icap, request_t * request) +{ + clientHttpRequest *http = icapReqModCreateClientState(icap); + assert(http); /* * bits from clientReadRequest */ @@ -149,25 +162,11 @@ icapEntryError(IcapStateData * icap, err_type et, http_status hs, int xerrno) { ErrorState *err; - clientHttpRequest *http; - - http = cbdataAlloc(clientHttpRequest); - http->uri = xstrdup(urlCanonicalClean(icap->request)); - http->log_uri = xstrndup(http->uri, MAX_URL); - http->range_iter.boundary = StringNull; - http->request = requestLink(icap->request); - http->flags.did_icap_reqmod = 1; - - http->conn = cbdataAlloc(ConnStateData); - http->conn->fd = icap->reqmod.client_fd; - http->conn->in.size = 0; - http->conn->in.buf = NULL; - http->conn->chr = http; + clientHttpRequest *http = icapReqModCreateClientState(icap); + assert(http); http->entry = clientCreateStoreEntry(http, icap->request->method, null_request_flags); - comm_add_close_handler(http->conn->fd, connStateFree, http->conn); - err = errorCon(et, hs); err->xerrno = xerrno; err->request = requestLink(icap->request); @@ -289,26 +288,10 @@ icapReqModHandoffRespMod(IcapStateData * icap) { extern PF icapReadReply; - clientHttpRequest *http; + clientHttpRequest *http = icapReqModCreateClientState(icap); + assert(http); assert(icap->request); - /* - * duplicate code from icapReqModInterpretHttpRequest() - */ - http = cbdataAlloc(clientHttpRequest); - http->uri = xstrdup(urlCanonicalClean(icap->request)); - http->log_uri = xstrndup(http->uri, MAX_URL); - http->range_iter.boundary = StringNull; - http->request = requestLink(icap->request); - http->flags.did_icap_reqmod = 1; - - http->conn = cbdataAlloc(ConnStateData); - http->conn->fd = icap->reqmod.client_fd; - http->conn->in.size = 0; - http->conn->in.buf = NULL; - http->conn->chr = http; - comm_add_close_handler(http->conn->fd, connStateFree, http->conn); - http->entry = clientCreateStoreEntry(http, icap->request->method, icap->request->flags);