--------------------- PatchSet 5994 Date: 2003/10/27 18:04:10 Author: dwsquid Branch: icap-2_5 Tag: (none) Log: added comments for each function, also removed getICAPReqModString() and merged it into the only place where it was called. Members: src/icap_reqmod.c:1.1.2.7->1.1.2.8 Index: squid/src/icap_reqmod.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_reqmod.c,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- squid/src/icap_reqmod.c 23 Oct 2003 18:54:42 -0000 1.1.2.7 +++ squid/src/icap_reqmod.c 27 Oct 2003 18:04:10 -0000 1.1.2.8 @@ -1,5 +1,5 @@ /* - * $Id: icap_reqmod.c,v 1.1.2.7 2003/10/23 18:54:42 uid131750 Exp $ + * $Id: icap_reqmod.c,v 1.1.2.8 2003/10/27 18:04:10 dwsquid Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -50,6 +50,12 @@ #define EXPECTED_ICAP_HEADER_LEN 256 static const char *crlf = "\r\n"; +/* + * icapExpectedHttpReqHdrSize + * + * calculate the size of the HTTP headers that we expect + * to read from the ICAP server. + */ static int icapExpectedHttpReqHdrSize(IcapStateData * icap) { @@ -62,9 +68,13 @@ } /* - * http->log_uri = xstrdup(urlCanonicalClean(request)); + * 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) { @@ -118,12 +128,23 @@ clientProcessRequest(http); } +/* + * icapReqModParseHttpError + * + * Handle an error when parsing the new HTTP request we read + * from the ICAP server. + */ static void icapReqModParseHttpError(IcapStateData * icap, const char *reason) { debug(81, 1) ("icapReqModParseHttpError: %s\n", reason); } +/* + * icapEntryError + * + * A wrapper for errorCon() and errorAppendEntry(). + */ static void icapEntryError(IcapStateData * icap, err_type et, http_status hs, int xerrno) { @@ -153,6 +174,12 @@ errorAppendEntry(http->entry, err); } +/* + * icapReqModParseHttpRequest + * + * Parse the HTTP request that we read from the ICAP server. + * Creates and fills in the request_t structure. + */ static void icapReqModParseHttpRequest(IcapStateData * icap) { @@ -240,7 +267,7 @@ xfree(inbuf); return; } - debug(81, 3) ("wow it worked\n"); + debug(81, 3) ("icapReqModParseHttpRequest: successfully parsed the HTTP request\n"); request->http_ver = http_ver; request->client_addr = icap->request->client_addr; request->my_addr = icap->request->my_addr; @@ -250,11 +277,13 @@ } /* - * This function handles the case where a REQMOD request results - * in an HTTP REPLY (instead of an ICAP REPLY that contains a new - * HTTP REQUEST). We prepare the IcapStateData for passing off - * to the icap_reqmod code, where we have functions for reading - * HTTP replies in ICAP messages. + * icapReqModHandoffRespMod + * + * Handles the case where a REQMOD request results in an HTTP REPLY + * (instead of an ICAP REPLY that contains a new HTTP REQUEST). We + * prepare the IcapStateData for passing off to the icap_reqmod + * code, where we have functions for reading HTTP replies in ICAP + * messages. */ static void icapReqModHandoffRespMod(IcapStateData * icap) @@ -292,6 +321,13 @@ icapReadReply(icap->icap_fd, icap); } +/* + * icapReqModReadHttpPart + * + * Read the HTTP reply from the ICAP server. Uses the values + * from the ICAP Encapsulation header to know how many bytes + * to read. + */ static void icapReqModReadHttpPart(int fd, void *data) { @@ -335,7 +371,9 @@ /* - * Read data from the ICAP server for REQMOD + * icapReqModReadIcapPart + * + * Read the ICAP reply header. */ static void icapReqModReadIcapPart(int fd, void *data) @@ -414,7 +452,12 @@ return; } -/* Type should be CWCB */ +/* + * icapSendReqModDone + * + * Called after we've sent the ICAP request. Checks for errors + * and installs the handler functions for the next step. + */ static void icapSendReqModDone(int fd, char *bufnotused, size_t size, int errflag, void *data) @@ -449,24 +492,11 @@ } -static void -getICAPReqModString(MemBuf * mb, int hdrLen, int bodyLen, char *service, char *client_addr) -{ - memBufPrintf(mb, "REQMOD %s ICAP/1.0\r\n", service); - memBufPrintf(mb, "Encapsulated: req-hdr=0"); - /* TODO: Change the offset using 'request' if needed */ - if (bodyLen > 0) - memBufPrintf(mb, ", req-body=%d", hdrLen); - else - memBufPrintf(mb, ", null-body=%d", hdrLen); - memBufAppend(mb, crlf, 2); - if (Config.icapcfg.send_client_ip) { - memBufPrintf(mb, "X-Client-IP: %s\r\n", client_addr); - } -} - -/* commConnect callback will be called with "callback(fd, status, data);" in - * commConnectCallback(ConnectStateData * cs, int status) +/* + * icapSendReqMod + * + * Send the ICAP request, including HTTP request, to the ICAP server + * after connection has been established. */ static void icapSendReqMod(int fd, int status, void *data) @@ -528,7 +558,16 @@ assert(service); client_addr = inet_ntoa(icap->request->client_addr); - getICAPReqModString(&mb, mb_hdr.size, blen, service->uri, client_addr); + memBufPrintf(mb, "REQMOD %s ICAP/1.0\r\n", service->uri); + memBufPrintf(mb, "Encapsulated: req-hdr=0"); + /* TODO: Change the offset using 'request' if needed */ + if (blen > 0) + memBufPrintf(mb, ", req-body=%d", mb_hdr.size); + else + memBufPrintf(mb, ", null-body=%d", mb_hdr.size); + memBufAppend(mb, crlf, 2); + if (Config.icapcfg.send_client_ip) + memBufPrintf(mb, "X-Client-IP: %s\r\n", client_addr); memBufAppend(&mb, "Connection: close\r\n", 19); memBufAppend(&mb, crlf, 2); memBufAppend(&mb, mb_hdr.buf, mb_hdr.size); @@ -546,7 +585,12 @@ comm_write_mbuf(icap_fd, mb, icapSendReqModDone, icap); } - +/* + * icapReqModStart + * + * Initiate an ICAP REQMOD transaction. Create and fill in IcapStateData + * structure and request a TCP connection to the server. + */ IcapStateData * icapReqModStart(icap_service_t type, const char *uri, request_t * request, int fd) {