From: wessels <> Date: Thu, 13 Nov 1997 05:50:22 +0000 (+0000) Subject: Added ``SLASH_HACK.'' If CWD to the first directory fails, then try X-Git-Tag: SQUID_3_0_PRE1~4547 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2761b2be7adcda008309a385e9297f04803be24e;p=thirdparty%2Fsquid.git Added ``SLASH_HACK.'' If CWD to the first directory fails, then try it again with a slash in front. Removed some unused code --- diff --git a/src/ftp.cc b/src/ftp.cc index 76862c762f..fcea09c35c 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,5 +1,5 @@ /* - * $Id: ftp.cc,v 1.167 1997/11/12 00:08:50 wessels Exp $ + * $Id: ftp.cc,v 1.168 1997/11/12 22:50:22 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -42,12 +42,12 @@ enum { FTP_USE_BASE, FTP_ROOT_DIR, FTP_NO_DOTDOT, - FTP_HTML_HEADER_SENT + FTP_HTML_HEADER_SENT, + FTP_MAYBE_TRY_SLASH_HACK }; static const char *const crlf = "\r\n"; static char cbuf[1024]; -static char auth_msg[AUTH_MSG_SZ]; typedef enum { BEGIN, @@ -798,65 +798,6 @@ ftpCheckUrlpath(FtpStateData * ftpState) } } -#ifdef OLD_FTP_CLEANUP -static void -ftpCleanupUrlpath(FtpStateData * ftpState) -{ - request_t *request = ftpState->request; - int again; - int l; - char *t = NULL; - char *s = NULL; - do { - again = 0; - l = strlen(request->urlpath); - /* check for null path */ - if (*request->urlpath == '\0') { - xstrncpy(request->urlpath, ".", MAX_URL); - EBIT_SET(ftpState->flags, FTP_ROOT_DIR); - EBIT_SET(ftpState->flags, FTP_ISDIR); - again = 1; - } else if ((l >= 1) && (*(request->urlpath + l - 1) == '/')) { - /* remove any trailing slashes from path */ - *(request->urlpath + l - 1) = '\0'; - EBIT_SET(ftpState->flags, FTP_ISDIR); - EBIT_CLR(ftpState->flags, FTP_USE_BASE); - again = 1; - } else if ((l >= 2) && (!strcmp(request->urlpath + l - 2, "/."))) { - /* remove trailing /. */ - *(request->urlpath + l - 2) = '\0'; - EBIT_SET(ftpState->flags, FTP_ISDIR); - EBIT_CLR(ftpState->flags, FTP_USE_BASE); - again = 1; - } else if (*request->urlpath == '/') { - /* remove any leading slashes from path */ - t = xstrdup(request->urlpath + 1); - xstrncpy(request->urlpath, t, MAX_URL); - xfree(t); - again = 1; - } else if (!strncmp(request->urlpath, "./", 2)) { - /* remove leading ./ */ - t = xstrdup(request->urlpath + 2); - xstrncpy(request->urlpath, t, MAX_URL); - xfree(t); - again = 1; - } else if ((t = strstr(request->urlpath, "/./"))) { - /* remove /./ */ - s = xstrdup(t + 2); - xstrncpy(t, s, strlen(s)); - xfree(s); - again = 1; - } else if ((t = strstr(request->urlpath, "//"))) { - /* remove // */ - s = xstrdup(t + 1); - xstrncpy(t, s, strlen(s)); - xfree(s); - again = 1; - } - } while (again); -} -#endif - static void ftpBuildTitleUrl(FtpStateData * ftpState) { @@ -877,13 +818,7 @@ ftpBuildTitleUrl(FtpStateData * ftpState) strcat(t, request->host); if (request->port != urlDefaultPort(PROTO_FTP)) snprintf(&t[strlen(t)], len - strlen(t), ":%d", request->port); -#ifdef OLD_FTP_CLEANUP - strcat(t, "/"); - if (!EBIT_TEST(ftpState->flags, FTP_ROOT_DIR)) - strcat(t, request->urlpath); -#else strcat(t, request->urlpath); -#endif } void @@ -919,11 +854,7 @@ ftpStart(request_t * request, StoreEntry * entry) ftpStateFree(-1, ftpState); return; } -#ifdef OLD_FTP_CLEANUP - ftpCleanupUrlpath(ftpState); -#else ftpCheckUrlpath(ftpState); -#endif ftpBuildTitleUrl(ftpState); debug(9, 5) ("FtpStart: host=%s, path=%s, user=%s, passwd=%s\n", ftpState->request->host, ftpState->request->urlpath, @@ -1233,9 +1164,11 @@ ftpReadType(FtpStateData * ftpState) T = &w->next; } xfree(path); - if (ftpState->pathcomps) + if (ftpState->pathcomps) { + if (*ftpState->pathcomps->key != '/') + EBIT_SET(ftpState->flags, FTP_MAYBE_TRY_SLASH_HACK); ftpSendCwd(ftpState); - else + } else ftpSendPasv(ftpState); } else { ftpFail(ftpState); @@ -1274,6 +1207,7 @@ ftpReadCwd(FtpStateData * ftpState) int code = ftpState->ctrl.replycode; size_t len = 0; wordlist *w; + char *t; debug(9, 3) ("This is ftpReadCwd\n"); w = ftpState->pathcomps; assert(w != NULL); @@ -1283,10 +1217,19 @@ ftpReadCwd(FtpStateData * ftpState) ftpState->cwd_message = ftpState->ctrl.message; ftpState->ctrl.message = NULL; /* CWD OK */ + EBIT_CLR(ftpState->flags, FTP_MAYBE_TRY_SLASH_HACK); ftpState->pathcomps = w->next; xfree(w->key); xfree(w); ftpSendCwd(ftpState); + } else if (EBIT_TEST(ftpState->flags, FTP_MAYBE_TRY_SLASH_HACK)) { + EBIT_CLR(ftpState->flags, FTP_MAYBE_TRY_SLASH_HACK); + len = strlen(w->key) + 2; + t = xmalloc(len); + snprintf(t, len, "/%s", w->key); + xfree(w->key); + w->key = t; + ftpSendCwd(ftpState); } else if (EBIT_TEST(ftpState->flags, FTP_ISDIR)) { /* CWD FAILED */ ftpFail(ftpState); @@ -1647,39 +1590,35 @@ ftpAbort(void *data) comm_close(ftpState->ctrl.fd); } -const char *ftpAuthText = -"
Sorry, you have to authorize yourself to request:\n" -"
ftp://%s@%s%256.256s\n" -"
from this cache. Please check with the\n" -"cache administrator\n" -"if you believe this is incorrect.\n" -"
\n" -"%s\n" -"
Sorry, you have to authorize yourself to request:\n" + "
ftp://%s@%s%256.256s\n" + "
from this cache. Please check with the\n" + "cache administrator\n" + "if you believe this is incorrect.\n" + "
\n" + "%s\n" + "
\n%s\n", - Config.errHtmlText); - l += snprintf(content + l, s - l, - "