From a79bc883fc1b3a669f637f8552bcb04cac07cde8 Mon Sep 17 00:00:00 2001 From: jbj Date: Fri, 19 Feb 1999 23:17:17 +0000 Subject: [PATCH] Tighter constraints on urlinfo cache-hits. Force ftp control channel close in ufdClose. CVS patchset: 2816 CVS date: 1999/02/19 23:17:17 --- ftp.c | 79 +++++++++++++++---------------- po/rpm.pot | 153 +++++++++++++++++++++++++++++++------------------------------ url.c | 54 ++++++++++++++++------ 3 files changed, 157 insertions(+), 129 deletions(-) diff --git a/ftp.c b/ftp.c index db91daa..75b6288 100644 --- a/ftp.c +++ b/ftp.c @@ -225,7 +225,7 @@ static int ftpCommand(urlinfo *u, char * command, ...) { if (ftpDebug) fprintf(stderr, "-> %s", buf); if (write(u->ftpControl, buf, len) != len) { - return FTPERR_SERVER_IO_ERROR; + return FTPERR_SERVER_IO_ERROR; } return ftpCheckResponse(u, NULL); @@ -273,12 +273,12 @@ static int tcpConnect(const char *host, int port) break; if ((sock = socket(sin.sin_family, SOCK_STREAM, IPPROTO_IP)) < 0) { - rc = FTPERR_FAILED_CONNECT; + rc = FTPERR_FAILED_CONNECT; break; } if (connect(sock, (struct sockaddr *) &sin, sizeof(sin))) { - rc = FTPERR_FAILED_CONNECT; + rc = FTPERR_FAILED_CONNECT; break; } } while (0); @@ -380,34 +380,29 @@ int ftpOpen(urlinfo *u) /* ftpCheckResponse() assumes the socket is nonblocking */ if (fcntl(u->ftpControl, F_SETFL, O_NONBLOCK)) { - close(u->ftpControl); - u->ftpControl = -1; - return FTPERR_FAILED_CONNECT; + rc = FTPERR_FAILED_CONNECT; + goto errxit; } if ((rc = ftpCheckResponse(u, NULL))) { - return rc; + return rc; } - if ((rc = ftpCommand(u, "USER", user, NULL))) { - close(u->ftpControl); - u->ftpControl = -1; - return rc; - } + if ((rc = ftpCommand(u, "USER", user, NULL))) + goto errxit; - if ((rc = ftpCommand(u, "PASS", password, NULL))) { - close(u->ftpControl); - u->ftpControl = -1; - return rc; - } + if ((rc = ftpCommand(u, "PASS", password, NULL))) + goto errxit; - if ((rc = ftpCommand(u, "TYPE", "I", NULL))) { - close(u->ftpControl); - u->ftpControl = -1; - return rc; - } + if ((rc = ftpCommand(u, "TYPE", "I", NULL))) + goto errxit; return u->ftpControl; + +errxit: + close(u->ftpControl); + u->ftpControl = -1; + return rc; } static int copyData(FD_t sfd, FD_t tfd) { @@ -487,7 +482,9 @@ fprintf(stderr, "-> ABOR\n"); send(u->ftpControl, buf, 3, MSG_OOB); sprintf(buf, "%cABOR\r\n", DM); if (write(u->ftpControl, buf, 7) != 7) { - return FTPERR_SERVER_IO_ERROR; + close(u->ftpControl); + u->ftpControl = -1; + return FTPERR_SERVER_IO_ERROR; } if (fdFileno(fd) >= 0) { while(read(fdFileno(fd), buf, sizeof(buf)) > 0) @@ -538,9 +535,9 @@ int ftpGetFileDesc(FD_t fd) if (ftpDebug) fprintf(stderr, "-> PASV\n"); - if (write(u->ftpControl, "PASV\r\n", 6) != 6) { - return FTPERR_SERVER_IO_ERROR; - } + if (write(u->ftpControl, "PASV\r\n", 6) != 6) + return FTPERR_SERVER_IO_ERROR; + if ((rc = ftpCheckResponse(u, &passReply))) return FTPERR_PASSIVE_ERROR; @@ -579,7 +576,7 @@ fprintf(stderr, "-> PASV\n"); fd->fd_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (fdFileno(fd) < 0) { - return FTPERR_FAILED_CONNECT; + return FTPERR_FAILED_CONNECT; } retrCommand = alloca(strlen(remotename) + 20); @@ -591,13 +588,13 @@ fprintf(stderr, "-> PASV\n"); if (errno == EINTR) continue; fdClose(fd); - return FTPERR_FAILED_DATA_CONNECT; + return FTPERR_FAILED_DATA_CONNECT; } if (ftpDebug) fprintf(stderr, "-> %s", retrCommand); if (write(u->ftpControl, retrCommand, i) != i) { - return FTPERR_SERVER_IO_ERROR; + return FTPERR_SERVER_IO_ERROR; } if ((rc = ftpCheckResponse(u, NULL))) { @@ -647,41 +644,41 @@ const char *ftpStrerror(int errorNumber) { return _("Success"); case FTPERR_BAD_SERVER_RESPONSE: - return _("Bad server response"); + return _("Bad server response"); case FTPERR_SERVER_IO_ERROR: - return _("Server IO error"); + return _("Server IO error"); case FTPERR_SERVER_TIMEOUT: - return _("Server timeout"); + return _("Server timeout"); case FTPERR_BAD_HOST_ADDR: - return _("Unable to lookup server host address"); + return _("Unable to lookup server host address"); case FTPERR_BAD_HOSTNAME: - return _("Unable to lookup server host name"); + return _("Unable to lookup server host name"); case FTPERR_FAILED_CONNECT: - return _("Failed to connect to server"); + return _("Failed to connect to server"); case FTPERR_FAILED_DATA_CONNECT: - return _("Failed to establish data connection to server"); + return _("Failed to establish data connection to server"); case FTPERR_FILE_IO_ERROR: - return _("IO error to local file"); + return _("IO error to local file"); case FTPERR_PASSIVE_ERROR: - return _("Error setting remote server to passive mode"); + return _("Error setting remote server to passive mode"); case FTPERR_FILE_NOT_FOUND: - return _("File not found on server"); + return _("File not found on server"); case FTPERR_NIC_ABORT_IN_PROGRESS: - return _("Abort in progress"); + return _("Abort in progress"); case FTPERR_UNKNOWN: default: - return _("Unknown or unexpected error"); + return _("Unknown or unexpected error"); } } diff --git a/po/rpm.pot b/po/rpm.pot index 13f5c37..06cba8f 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1999-02-16 01:14-0500\n" +"POT-Creation-Date: 1999-02-19 11:36-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -256,107 +256,107 @@ msgstr "" msgid "Unknown or unexpected error" msgstr "" -#: ../install.c:114 +#: ../install.c:110 msgid "counting packages to install\n" msgstr "" -#: ../install.c:118 +#: ../install.c:114 #, c-format msgid "found %d packages\n" msgstr "" -#: ../install.c:127 +#: ../install.c:123 msgid "looking for packages to download\n" msgstr "" -#: ../install.c:138 +#: ../install.c:134 #, c-format msgid "Retrieving %s\n" msgstr "" -#: ../install.c:147 +#: ../install.c:143 #, c-format msgid " ... as %s\n" msgstr "" -#: ../install.c:151 +#: ../install.c:147 #, c-format msgid "skipping %s - transfer failed - %s\n" msgstr "" -#: ../install.c:168 +#: ../install.c:164 #, c-format msgid "retrieved %d packages\n" msgstr "" -#: ../install.c:177 ../install.c:287 +#: ../install.c:173 ../install.c:283 #, c-format msgid "cannot open file %s\n" msgstr "" -#: ../install.c:189 ../lib/query.c:478 +#: ../install.c:185 ../lib/query.c:478 #, c-format msgid "%s does not appear to be a RPM package\n" msgstr "" -#: ../install.c:193 ../install.c:428 +#: ../install.c:189 ../install.c:420 #, c-format msgid "%s cannot be installed\n" msgstr "" -#: ../install.c:210 ../install.c:341 +#: ../install.c:206 ../install.c:333 #, c-format msgid "cannot open %s/packages.rpm\n" msgstr "" -#: ../install.c:228 +#: ../install.c:224 #, c-format msgid "found %d source and %d binary packages\n" msgstr "" -#: ../install.c:238 +#: ../install.c:234 msgid "failed dependencies:\n" msgstr "" -#: ../install.c:254 +#: ../install.c:250 msgid "installing binary packages\n" msgstr "" -#: ../install.c:352 ../lib/query.c:614 ../verify.c:243 +#: ../install.c:344 ../lib/query.c:614 ../verify.c:243 #, c-format msgid "package %s is not installed\n" msgstr "" -#: ../install.c:356 +#: ../install.c:348 #, c-format msgid "searching for package %s\n" msgstr "" -#: ../install.c:365 +#: ../install.c:357 #, c-format msgid "\"%s\" specifies multiple packages\n" msgstr "" -#: ../install.c:391 +#: ../install.c:383 msgid "removing these packages would break dependencies:\n" msgstr "" -#: ../install.c:418 +#: ../install.c:410 #, c-format msgid "cannot open %s\n" msgstr "" -#: ../install.c:423 +#: ../install.c:415 #, c-format msgid "Installing %s\n" msgstr "" -#: ../install.c:467 +#: ../install.c:459 #, c-format msgid " is needed by %s-%s-%s\n" msgstr "" -#: ../install.c:470 +#: ../install.c:462 #, c-format msgid " conflicts with %s-%s-%s\n" msgstr "" @@ -1336,65 +1336,65 @@ msgid "" "http options can only be used during package queries, installs, and upgrades" msgstr "" -#: ../rpm.c:1068 +#: ../rpm.c:1065 msgid "--nopgp may only be used during signature checking" msgstr "" -#: ../rpm.c:1071 +#: ../rpm.c:1068 msgid "--nogpg may only be used during signature checking" msgstr "" -#: ../rpm.c:1074 +#: ../rpm.c:1071 msgid "" "--nomd5 may only be used during signature checking and package verification" msgstr "" -#: ../rpm.c:1104 +#: ../rpm.c:1101 #, c-format msgid "cannot access file %s\n" msgstr "" -#: ../rpm.c:1118 +#: ../rpm.c:1115 msgid "Pass phrase check failed\n" msgstr "" -#: ../rpm.c:1121 +#: ../rpm.c:1118 msgid "Pass phrase is good.\n" msgstr "" -#: ../rpm.c:1133 +#: ../rpm.c:1130 msgid "--sign may only be used during package building" msgstr "" -#: ../rpm.c:1149 +#: ../rpm.c:1146 msgid "exec failed\n" msgstr "" -#: ../rpm.c:1168 +#: ../rpm.c:1165 msgid "unexpected arguments to --querytags " msgstr "" -#: ../rpm.c:1179 +#: ../rpm.c:1176 msgid "no packages given for signature check" msgstr "" -#: ../rpm.c:1187 +#: ../rpm.c:1184 msgid "no packages given for signing" msgstr "" -#: ../rpm.c:1196 +#: ../rpm.c:1193 msgid "no packages files given for rebuild" msgstr "" -#: ../rpm.c:1253 +#: ../rpm.c:1250 msgid "no spec files given for build" msgstr "" -#: ../rpm.c:1255 +#: ../rpm.c:1252 msgid "no tar files given for build" msgstr "" -#: ../rpm.c:1268 +#: ../rpm.c:1265 msgid "no packages given for uninstall" msgstr "" @@ -2180,37 +2180,47 @@ msgstr "" msgid "line %d: Bad %s number: %s\n" msgstr "" -#: ../lib/cpio.c:532 +#: ../lib/cpio.c:362 +#, c-format +msgid "can't rename %s to %x: %s\n" +msgstr "" + +#: ../lib/cpio.c:368 +#, c-format +msgid "can't unlink %s: %s\n" +msgstr "" + +#: ../lib/cpio.c:547 #, c-format msgid "getNextHeader: %s\n" msgstr "" -#: ../lib/cpio.c:985 +#: ../lib/cpio.c:1000 #, c-format msgid "(error 0x%x)" msgstr "" -#: ../lib/cpio.c:988 +#: ../lib/cpio.c:1003 msgid "Bad magic" msgstr "" -#: ../lib/cpio.c:989 +#: ../lib/cpio.c:1004 msgid "Bad/unreadable header" msgstr "" -#: ../lib/cpio.c:1007 +#: ../lib/cpio.c:1022 msgid "Internal error" msgstr "" -#: ../lib/cpio.c:1008 +#: ../lib/cpio.c:1023 msgid "Header size too big" msgstr "" -#: ../lib/cpio.c:1009 +#: ../lib/cpio.c:1024 msgid "Unknown file type" msgstr "" -#: ../lib/cpio.c:1018 +#: ../lib/cpio.c:1033 msgid " failed - " msgstr "" @@ -2269,8 +2279,8 @@ msgid "free list corrupt (%u)- contact support@redhat.com\n" msgstr "" #: ../lib/formats.c:97 ../lib/formats.c:114 ../lib/formats.c:134 -#: ../lib/formats.c:166 ../lib/header.c:1971 ../lib/header.c:1987 -#: ../lib/header.c:2007 +#: ../lib/formats.c:166 ../lib/header.c:1973 ../lib/header.c:1989 +#: ../lib/header.c:2009 msgid "(not a number)" msgstr "" @@ -2300,78 +2310,78 @@ msgid "Data type %d not supprted\n" msgstr "" #. This should not be allowed -#: ../lib/header.c:904 +#: ../lib/header.c:906 msgid "grabData() RPM_STRING_TYPE count must be 1.\n" msgstr "" -#: ../lib/header.c:934 +#: ../lib/header.c:936 #, c-format msgid "Data type %d not supported\n" msgstr "" -#: ../lib/header.c:993 +#: ../lib/header.c:995 #, c-format msgid "Bad count for headerAddEntry(): %d\n" msgstr "" -#: ../lib/header.c:1327 +#: ../lib/header.c:1329 msgid "? expected in expression" msgstr "" -#: ../lib/header.c:1334 +#: ../lib/header.c:1336 msgid "{ expected after ? in expression" msgstr "" -#: ../lib/header.c:1344 ../lib/header.c:1376 +#: ../lib/header.c:1346 ../lib/header.c:1378 msgid "} expected in expression" msgstr "" -#: ../lib/header.c:1351 +#: ../lib/header.c:1353 msgid ": expected following ? subexpression" msgstr "" -#: ../lib/header.c:1364 +#: ../lib/header.c:1366 msgid "{ expected after : in expression" msgstr "" -#: ../lib/header.c:1383 +#: ../lib/header.c:1385 msgid "| expected at end of expression" msgstr "" -#: ../lib/header.c:1477 +#: ../lib/header.c:1479 #, c-format msgid "missing { after %" msgstr "" -#: ../lib/header.c:1505 +#: ../lib/header.c:1507 msgid "missing } after %{" msgstr "" -#: ../lib/header.c:1517 +#: ../lib/header.c:1519 msgid "empty tag format" msgstr "" -#: ../lib/header.c:1527 +#: ../lib/header.c:1529 msgid "empty tag name" msgstr "" -#: ../lib/header.c:1542 +#: ../lib/header.c:1544 msgid "unknown tag" msgstr "" -#: ../lib/header.c:1568 +#: ../lib/header.c:1570 msgid "] expected at end of array" msgstr "" -#: ../lib/header.c:1584 +#: ../lib/header.c:1586 msgid "unexpected ]" msgstr "" -#: ../lib/header.c:1586 +#: ../lib/header.c:1588 msgid "unexpected }" msgstr "" -#: ../lib/header.c:1761 +#: ../lib/header.c:1763 msgid "(unknown type)" msgstr "" @@ -2474,11 +2484,6 @@ msgstr "" msgid "renaming %s to %s\n" msgstr "" -#: ../lib/install.c:884 -#, c-format -msgid "package %s-%s-%s (which is newer) is already installed" -msgstr "" - #: ../lib/lookup.c:83 #, c-format msgid "cannot read header at %d for lookup" @@ -3137,17 +3142,17 @@ msgstr "" msgid "Invalid signature spec in rc file" msgstr "" -#: ../lib/transaction.c:576 +#: ../lib/transaction.c:581 #, c-format msgid "relocating %s to %s\n" msgstr "" -#: ../lib/transaction.c:582 +#: ../lib/transaction.c:587 #, c-format msgid "excluding %s\n" msgstr "" -#: ../lib/transaction.c:669 +#: ../lib/transaction.c:675 #, c-format msgid "%s skipped due to missingok flag\n" msgstr "" diff --git a/url.c b/url.c index 5466072..4e892d1 100644 --- a/url.c +++ b/url.c @@ -69,17 +69,26 @@ static void findUrlinfo(urlinfo **uret, int mustAsk) empty = &uCache[i]; continue; } - if (u->service && ou->service && strcmp(ou->service, u->service)) - continue; - if (u->host && ou->host && strcmp(ou->host, u->host)) - continue; - if (u->user && ou->user && strcmp(ou->user, u->user)) - continue; - if (u->password && ou->password && strcmp(ou->password, u->password)) - continue; - if (u->portstr && ou->portstr && strcmp(ou->portstr, u->portstr)) - continue; - break; + /* Check for cache-miss condition. A cache miss is + * a) both items are not NULL and don't compare. + * b) either of the items is not NULL. + */ + if ((u->service && ou->service && strcmp(u->service, ou->service)) || + (u->service != ou->service)) + continue; + if ((u->host && ou->host && strcmp(u->host, ou->host)) || + (u->host != ou->host)) + continue; + if ((u->user && ou->user && strcmp(u->user, ou->user)) || + (u->user != ou->user)) + continue; + if ((u->password && ou->password && strcmp(u->password, ou->password))|| + (u->password != ou->password)) + continue; + if ((u->portstr && ou->portstr && strcmp(u->portstr, ou->portstr)) || + (u->portstr != ou->portstr)) + continue; + break; /* Found item in cache */ } if (i == uCount) { @@ -166,6 +175,10 @@ static void findUrlinfo(urlinfo **uret, int mustAsk) return; } +/* + * Split URL into components. The URL can look like + * service://user:password@host:port/path + */ int urlSplit(const char * url, urlinfo **uret) { urlinfo *u; @@ -181,8 +194,11 @@ int urlSplit(const char * url, urlinfo **uret) freeUrlinfo(u); return -1; } + u->url = strdup(url); + do { + /* Point to end of next item */ while (*se && *se != '/') se++; if (*se == '\0') { /* XXX can't find path */ @@ -190,23 +206,28 @@ int urlSplit(const char * url, urlinfo **uret) freeUrlinfo(u); return -1; } + /* Item was service. Save service and go for the rest ...*/ if ((se != s) && se[-1] == ':' && se[0] == '/' && se[1] == '/') { se[-1] = '\0'; u->service = strdup(s); - se += 2; + se += 2; /* skip over "//" */ s = se++; continue; } - u->path = strdup(se); + + /* Item was everything-but-path. Save path and continue parse on rest */ + u->path = strdup(se); *se = '\0'; break; } while (1); + /* Look for ...@host... */ fe = f = s; while (*fe && *fe != '@') fe++; if (*fe == '@') { s = fe + 1; *fe = '\0'; + /* Look for user:password@host... */ while (fe > f && *fe != ':') fe--; if (*fe == ':') { *fe++ = '\0'; @@ -215,6 +236,7 @@ int urlSplit(const char * url, urlinfo **uret) u->user = strdup(f); } + /* Look for ...host:port */ fe = f = s; while (*fe && *fe != ':') fe++; if (*fe == ':') { @@ -308,8 +330,12 @@ int ufdClose(FD_t fd) { if (fd != NULL && fd->fd_url) { urlinfo *u = (urlinfo *)fd->fd_url; - if (u->ftpControl >= 0) + /* Close the ftp control channel (not strictly necessary, but ... */ + if (u->ftpControl >= 0) { ftpAbort(fd); + close(u->ftpControl); + u->ftpControl = -1; + } } return fdClose(fd); } -- 2.7.4