--------------------- PatchSet 4472 Date: 2007/05/08 13:31:15 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Rollout to ErrorPages. Remove soe unneeded code in FTP. Members: src/errorpage.cc:1.23.6.6->1.23.6.7 src/errorpage.h:1.2.10.2->1.2.10.3 src/ftp.cc:1.26.2.20->1.26.2.21 Index: squid3/src/errorpage.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/errorpage.cc,v retrieving revision 1.23.6.6 retrieving revision 1.23.6.7 diff -u -r1.23.6.6 -r1.23.6.7 --- squid3/src/errorpage.cc 1 May 2007 08:32:30 -0000 1.23.6.6 +++ squid3/src/errorpage.cc 8 May 2007 13:31:15 -0000 1.23.6.7 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.23.6.6 2007/05/01 08:32:30 amosjeffries Exp $ + * $Id: errorpage.cc,v 1.23.6.7 2007/05/08 13:31:15 amosjeffries Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -499,6 +499,8 @@ HttpRequest *r = err->request; MemBuf str; const char *p = NULL; /* takes priority over mb if set */ + char ntoabuf[MAX_IPSTRLEN]; + str.reset(); /* email subject line */ str.Printf("CacheErrorInfo - %s", errorPageName(err->type)); @@ -526,7 +528,7 @@ str.Printf("TimeStamp: %s\r\n\r\n", mkrfc1123(squid_curtime)); /* - IP stuff */ - str.Printf("ClientIP: %s\r\n", inet_ntoa(err->src_addr)); + str.Printf("ClientIP: %s\r\n", err->src_addr.NtoA(ntoabuf,MAX_IPSTRLEN)); if (r && r->hier.host) { str.Printf("ServerIP: %s\r\n", r->hier.host); @@ -610,6 +612,7 @@ static MemBuf mb; const char *p = NULL; /* takes priority over mb if set */ int do_quote = 1; + char ntoabuf[MAX_IPSTRLEN]; mb.reset(); @@ -690,7 +693,7 @@ break; case 'i': - mb.Printf("%s", inet_ntoa(err->src_addr)); + mb.Printf("%s", err->src_addr.NtoA(ntoabuf,MAX_IPSTRLEN)); break; Index: squid3/src/errorpage.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/errorpage.h,v retrieving revision 1.2.10.2 retrieving revision 1.2.10.3 diff -u -r1.2.10.2 -r1.2.10.3 --- squid3/src/errorpage.h 5 Jan 2007 16:59:17 -0000 1.2.10.2 +++ squid3/src/errorpage.h 8 May 2007 13:31:15 -0000 1.2.10.3 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.h,v 1.2.10.2 2007/01/05 16:59:17 hno Exp $ + * $Id: errorpage.h,v 1.2.10.3 2007/05/08 13:31:15 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -37,6 +37,7 @@ #include "squid.h" #include "cbdata.h" +#include "IPAddress.h" class ErrorState { @@ -53,7 +54,7 @@ char *dnsserver_msg; time_t ttl; - struct IN_ADDR src_addr; + IPAddress src_addr; char *redirect_url; ERCB *callback; void *callback_data; Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.26.2.20 retrieving revision 1.26.2.21 diff -u -r1.26.2.20 -r1.26.2.21 --- squid3/src/ftp.cc 8 May 2007 12:45:39 -0000 1.26.2.20 +++ squid3/src/ftp.cc 8 May 2007 13:31:15 -0000 1.26.2.21 @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.26.2.20 2007/05/08 12:45:39 amosjeffries Exp $ + * $Id: ftp.cc,v 1.26.2.21 2007/05/08 13:31:15 amosjeffries Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -2201,7 +2201,7 @@ ftpReadSize(FtpStateData * ftpState) { int code = ftpState->ctrl.replycode; - debugs(9, 3, HERE); + debugs(9, 3, HERE << "ftpReadSize()"); if (code == 213) { ftpState->unhack(); @@ -2277,7 +2277,7 @@ return; } - if( addr.IsIPv4() ) { + if( addr.IsIPv4() ) { struct sockaddr_in s4addr; addr.GetSockAddr(s4addr); socklen_t addr_len = sizeof(s4addr); @@ -2352,7 +2352,7 @@ int fd = ftpState->data.fd; char *buf; LOCAL_ARRAY(char, ipaddr, 1024); - debugs(9, 3, HERE); + debugs(9, 3, HERE << "ftpReadSize started"); if (code != 227) { debugs(9, 3, "PASV not supported by remote end"); @@ -2530,7 +2530,7 @@ socklen_t addr_len; unsigned char *addrptr; unsigned char *portptr; - debugs(9, 3, HERE); + debugs(9, 3, HERE << "ftpSendPORT started"); ftpState->flags.pasv_supported = 0; fd = ftpOpenListenSocket(ftpState, 0); addr_len = sizeof(addr); @@ -2566,7 +2566,7 @@ ftpReadPORT(FtpStateData * ftpState) { int code = ftpState->ctrl.replycode; - debugs(9, 3, HERE); + debugs(9, 3, HERE << "ftpReadPORT started"); if (code != 200) { /* Fall back on using the same port as the control connection */ @@ -2584,7 +2584,7 @@ IPAddress addr; char buf[MAX_IPSTRLEN]; - debugs(9, 3, HERE); + debugs(9, 3, HERE << "ftpSendEPRT started"); ftpState->flags.pasv_supported = 0; fd = ftpOpenListenSocket(ftpState, 0); @@ -2623,7 +2623,7 @@ ftpReadEPRT(FtpStateData * ftpState) { int code = ftpState->ctrl.replycode; - debugs(9, 3, HERE); + debugs(9, 3, HERE << " ftpReadEPRT started"); if (code != 200) { /* Failover to attempting old PORT command. */ @@ -3362,56 +3362,41 @@ return newrep; } -char * -ftpUrlWith2f(const HttpRequest * request) +/** + * Construct an URI with leading / in PATH portion for use by CWD command + * possibly others. FTP encodes absolute paths as beginning with '/' + * after the initial URI path delimiter, which happens to be / itself. + * This makes FTP absolute URI appear as: ftp:host:port//root/path + * To encompass older software which compacts multiple // to / in transit + * We use standard URI-encoding on the second / making it + * ftp:host:port/%2froot/path AKA 'the FTP %2f hack'. + */ +const char * +ftpUrlWith2f(HttpRequest * request) { - LOCAL_ARRAY(char, buf, MAX_URL); - LOCAL_ARRAY(char, loginbuf, MAX_LOGIN_SZ + 1); - LOCAL_ARRAY(char, portbuf, 32); - char *t; - portbuf[0] = '\0'; + char *newbuf = NULL; if (request->protocol != PROTO_FTP) return NULL; - if (request->port != urlDefaultPort(request->protocol)) - snprintf(portbuf, 32, ":%d", request->port); - - loginbuf[0] = '\0'; - - if ((int) strlen(request->login) > 0) { - xstrncpy(loginbuf, request->login, sizeof(loginbuf) - 2); +/* FIXME : use of string will be much cleaner and safer here. + But squid still uses its own string for now. Cope with it. */ - if ((t = strchr(loginbuf, ':'))) - *t = '\0'; - - strcat(loginbuf, "@"); - } - -#ifdef INET6 - snprintf(buf, MAX_URL, "%s://%s%s%s%s%s%s%s", - ProtocolStr[request->protocol], - NEEDS_BRACKETS(request->host) ? "[": null_string, - loginbuf, - request->host, - NEEDS_BRACKETS(request->host) ? "]": null_string, - portbuf, - "/%2f", - request->urlpath.buf()); -#else - snprintf(buf, MAX_URL, "%s://%s%s%s%s%s", - ProtocolStr[request->protocol], - loginbuf, - request->host, - portbuf, - "/%2f", - request->urlpath.buf()); -#endif - - if ((t = strchr(buf, '?'))) - *t = '\0'; - - return buf; + if( !request->urlpath.cmp("/",1) ) { + newbuf = new char[MAXPATHLEN]; + snprintf(newbuf,MAXPATHLEN,"%%2f%s", request->urlpath.buf() ); + request->urlpath.buf(newbuf); + safe_free(request->canonical); + } + else if( !request->urlpath.cmp("%2f",3) ) { + const char *tmp = request->urlpath.buf(); + newbuf = new char[MAXPATHLEN]; + snprintf(newbuf,MAXPATHLEN,"%%2f%s", &tmp[1]); + request->urlpath.buf(newbuf); + safe_free(request->canonical); + } + + return urlCanonical(request); } void