From 94dd9f796e8c8fa7b59e9690d8d0cf476313e5a5 Mon Sep 17 00:00:00 2001 From: jbj Date: Wed, 3 Nov 1999 20:33:53 +0000 Subject: [PATCH] First use of libio. CVS patchset: 3416 CVS date: 1999/11/03 20:33:53 --- build/pack.c | 8 +++++ lib/ftp.c | 33 ++++++++++--------- lib/install.c | 4 +++ lib/rpminstall.c | 2 +- lib/rpmio.h | 57 +++++++++++++++++++++++++-------- lib/rpmurl.h | 4 +-- lib/url.c | 15 +++++---- po/rpm.pot | 97 ++++++++++++++++++++++++++++---------------------------- rpm2cpio.c | 4 +++ 9 files changed, 138 insertions(+), 86 deletions(-) diff --git a/build/pack.c b/build/pack.c index 7f050c3..7e734de 100644 --- a/build/pack.c +++ b/build/pack.c @@ -416,7 +416,11 @@ static int cpio_bzip2(FD_t fdo, CSA_t *csa) int rc; const char *failedFile = NULL; +#if 0 cfd = bzdFdopen(fdDup(Fileno(fdo)), "w9"); +#else + cfd = Fdopen(fdDup(Fileno(fdo)), "w9.bzdio"); +#endif rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL, &csa->cpioArchiveSize, &failedFile); if (rc) { @@ -439,7 +443,11 @@ static int cpio_gzip(FD_t fdo, CSA_t *csa) int rc; const char *failedFile = NULL; +#if 0 cfd = gzdFdopen(fdDup(Fileno(fdo)), "w9"); +#else + cfd = Fdopen(fdDup(Fileno(fdo)), "w9.gzdio"); +#endif rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL, &csa->cpioArchiveSize, &failedFile); if (rc) { diff --git a/lib/ftp.c b/lib/ftp.c index d1ec483..175b342 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -178,7 +178,7 @@ static int checkResponse(int fd, int secs, int *ecp, /*@out@*/ char ** str) { int ftpCheckResponse(urlinfo u, /*@out@*/ char ** str) { int ec = 0; - int rc = checkResponse(u->ftpControl, ftpTimeoutSecs, &ec, str); + int rc = checkResponse(Fileno(u->ftpControl), ftpTimeoutSecs, &ec, str); switch (ec) { case 550: @@ -228,7 +228,7 @@ static int ftpCommand(urlinfo u, char * command, ...) { buf[len] = '\0'; DBG(0, (stderr, "-> %s", buf)); - if (write(u->ftpControl, buf, len) != len) + if (fdio->write(u->ftpControl, buf, len) != len) return FTPERR_SERVER_IO_ERROR; return ftpCheckResponse(u, NULL); @@ -378,11 +378,12 @@ int ftpOpen(urlinfo u) } } - if ((u->ftpControl = tcpConnect(host, port)) < 0) - return u->ftpControl; + fdSetFdno(u->ftpControl, tcpConnect(host, port)); + if (Fileno(u->ftpControl) < 0) + return Fileno(u->ftpControl); /* ftpCheckResponse() assumes the socket is nonblocking */ - if (fcntl(u->ftpControl, F_SETFL, O_NONBLOCK)) { + if (fcntl(Fileno(u->ftpControl), F_SETFL, O_NONBLOCK)) { rc = FTPERR_FAILED_CONNECT; goto errxit; } @@ -400,11 +401,10 @@ int ftpOpen(urlinfo u) if ((rc = ftpCommand(u, "TYPE", "I", NULL))) goto errxit; - return u->ftpControl; + return Fileno(u->ftpControl); errxit: - close(u->ftpControl); - u->ftpControl = -1; + fdio->close(u->ftpControl); return rc; } @@ -440,8 +440,8 @@ int ftpFileDesc(urlinfo u, const char *cmd, FD_t fd) if (u->ftpFileDoneNeeded) rc = ftpFileDone(u); - DBG(fdDebug(fd), (stderr, "-> PASV\n")); - if (write(u->ftpControl, "PASV\r\n", 6) != 6) + DBG(0, (stderr, "-> PASV\n")); + if (fdio->write(u->ftpControl, "PASV\r\n", 6) != 6) return FTPERR_SERVER_IO_ERROR; if ((rc = ftpCheckResponse(u, &passReply))) @@ -479,25 +479,28 @@ int ftpFileDesc(urlinfo u, const char *cmd, FD_t fd) if (!inet_aton(passReply, &dataAddress.sin_addr)) return FTPERR_PASSIVE_ERROR; - ufdSetFd(fd, socket(AF_INET, SOCK_STREAM, IPPROTO_IP)); + fdSetFdno(fd, socket(AF_INET, SOCK_STREAM, IPPROTO_IP)); if (Fileno(fd) < 0) return FTPERR_FAILED_CONNECT; + /* XXX setsockopt SO_LINGER */ + /* XXX setsockopt SO_KEEPALIVE */ + /* XXX setsockopt SO_TOS IPTOS_THROUGHPUT */ while (connect(Fileno(fd), (struct sockaddr *) &dataAddress, sizeof(dataAddress)) < 0) { if (errno == EINTR) continue; - Fclose(fd); + fdio->close(fd); return FTPERR_FAILED_DATA_CONNECT; } - DBG(fdDebug(fd), (stderr, "-> %s", cmd)); + DBG(0, (stderr, "-> %s", cmd)); i = strlen(cmd); - if (write(u->ftpControl, cmd, i) != i) + if (fdio->write(u->ftpControl, cmd, i) != i) return FTPERR_SERVER_IO_ERROR; if ((rc = ftpCheckResponse(u, NULL))) { - Fclose(fd); + fdio->close(fd); return rc; } diff --git a/lib/install.c b/lib/install.c index 0073f25..ac2b961 100644 --- a/lib/install.c +++ b/lib/install.c @@ -342,7 +342,11 @@ static int installArchive(FD_t fd, struct fileInfo * files, (void)notify(h, RPMCALLBACK_INST_PROGRESS, 0, archiveSize, pkgKey, notifyData); +#if 0 cfd = gzdFdopen(fdDup(Fileno(fd)), "r"); +#else + cfd = Fdopen(fdDup(Fileno(fd)), "r.gzdio"); +#endif rc = cpioInstallArchive(cfd, map, mappedFiles, ((notify && archiveSize) || specFile) ? callback : NULL, &info, &failedFile); diff --git a/lib/rpminstall.c b/lib/rpminstall.c index e9ad3b5..dc018ff 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -159,7 +159,7 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, } rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn); - myrc = urlFile(*filename, tfn, 0); + myrc = urlGetFile(*filename, tfn); if (myrc < 0) { rpmMessage(RPMMESS_ERROR, _("skipping %s - transfer failed - %s\n"), diff --git a/lib/rpmio.h b/lib/rpmio.h index 50f5170..52db3ee 100644 --- a/lib/rpmio.h +++ b/lib/rpmio.h @@ -47,13 +47,11 @@ struct FDIO_s { fdio_ffileno_function_t *ffileno; fdio_fflush_function_t *fflush; -#ifdef NOTYET fdio_mkdir_function_t *mkdir; fdio_chdir_function_t *chdir; fdio_rmdir_function_t *rmdir; fdio_rename_function_t *rename; fdio_unlink_function_t *unlink; -#endif }; /*@observer@*/ const char * Fstrerror(FD_t fd); @@ -62,6 +60,7 @@ size_t Fread (/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd); size_t Fwrite (const void *buf, size_t size, size_t nmemb, FD_t fd); int Fseek (FD_t fd, long int offset, int whence); int Fclose ( /*@killref@*/ FD_t fd); +FD_t Fdopen (FD_t fd, const char * fmode); FILE * Fopen (const char * path, const char * fmode); int Ferror (FD_t fd); @@ -77,36 +76,68 @@ int Rename (const char * oldpath, const char * newpath); int Chroot (const char * path); int Unlink (const char * path); +/*@observer@*/ extern FDIO_t gzdio; + int timedRead(FD_t fd, /*@out@*/void * bufptr, int length); +void fdSetFdno(FD_t fd, int fdno); /*@null@*/ const FDIO_t fdGetIoCookie(FD_t fd); void fdSetIoCookie(FD_t fd, FDIO_t iop); -#define fdLink(_fd, _msg) fdio->ref(_fd, _msg, __FILE__, __LINE__) -#define fdFree(_fd, _msg) fdio->deref(_fd, _msg, __FILE__, __LINE__) -#define fdNew(_iop, _msg) fdio->new(_iop, _msg, __FILE__, __LINE__) +long int fdGetCpioPos(FD_t fd); extern /*@null@*/ FD_t fdDup(int fdno); +void fdSetCpioPos(FD_t fd, long int cpioPos); extern /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode); -long int fdGetCpioPos(FD_t fd); -void fdSetCpioPos(FD_t fd, long int cpioPos); -int fdDebug(FD_t fd); -void fdDebugOn(FD_t fd); -void fdDebugOff(FD_t fd); +#if 0 +#define fdRead fdio->read +#define fdWrite fdio->write +#define fdSeek fdio->seek +#define fdClose fdio->close +#endif + +#define fdLink(_fd, _msg) fdio->ref(_fd, _msg, __FILE__, __LINE__) +#define fdFree(_fd, _msg) fdio->deref(_fd, _msg, __FILE__, __LINE__) +#define fdNew(_iop, _msg) fdio->new(_iop, _msg, __FILE__, __LINE__) + +#if 0 +#define fdFileno fdio->fileno +#define fdOpen fdio->open +#endif /*@observer@*/ extern FDIO_t fdio; +/*@observer@*/ extern FDIO_t fpio; /* * Support for FTP and HTTP I/O. */ /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd); -void ufdSetFd(FD_t fd, int fdno); /*@observer@*/ const char * urlStrerror(const char * url); -int httpFile( /*@killref@*/ FD_t sfd, FD_t tfd, int dir); -int ftpFile( /*@killref@*/ FD_t sfd, FD_t tfd, int dir); +int httpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd); +int ftpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd); const char *const ftpStrerror(int errorNumber); +#if 0 +#define ufdRead ufdio->read +#define ufdWrite ufdio->write +#define ufdSeek ufdio->seek +#define ufdClose ufdio->close +#define ufdLink ufdio->ref +#define ufdFree ufdio->deref +#define ufdNew ufdio->new +#define ufdFileno ufdio->fileno +#define ufdOpen ufdio->open +#define ufdFopen ufdio->fopen +#define ufdFfileno ufdio->ffileno +#define ufdFflush ufdio->fflush +#define ufdMkdir ufdio->mkdir +#define ufdChdir ufdio->chdir +#define ufdRmdir ufdio->rmdir +#define ufdRename ufdio->rename +#define ufdUnlink ufdio->unlink +#endif + /*@observer@*/ extern FDIO_t ufdio; /* diff --git a/lib/rpmurl.h b/lib/rpmurl.h index a9a4665..477c051 100644 --- a/lib/rpmurl.h +++ b/lib/rpmurl.h @@ -42,7 +42,7 @@ typedef /*@abstract@*/ /*@refcounted@*/ struct urlinfo { const char *proxyh; /* FTP/HTTP: proxy host */ int proxyp; /* FTP/HTTP: proxy port */ int port; - int ftpControl; + FD_t ftpControl; int ftpFileDoneNeeded; int openError; /* Type of open failure */ } *urlinfo; @@ -75,7 +75,7 @@ void urlFreeCache(void); urltype urlIsURL(const char * url); int urlSplit(const char *url, /*@out@*/ urlinfo *u); -int urlFile(const char * url, const char * dest, int push); +int urlGetFile(const char * url, const char * dest); #ifdef __cplusplus } diff --git a/lib/url.c b/lib/url.c index 840f387..7357c3b 100644 --- a/lib/url.c +++ b/lib/url.c @@ -42,7 +42,7 @@ urlinfo XurlNew(const char *msg, const char *file, unsigned line) memset(u, 0, sizeof(*u)); u->proxyp = -1; u->port = -1; - u->ftpControl = -1; + u->ftpControl = fdio->new(fdio, "ftpControl", __FILE__, __LINE__); u->ftpFileDoneNeeded = 0; u->nrefs = 0; return XurlLink(u, msg, file, line); @@ -53,8 +53,11 @@ void XurlFree(urlinfo u, const char *msg, const char *file, unsigned line) DBGREFS(0, (stderr, "--> url %p -- %d %s at %s:%u\n", u, u->nrefs, msg, file, line)); if (--u->nrefs > 0) return; - if (u->ftpControl >= 0) - close(u->ftpControl); + if (u->ftpControl) { + fdio->close(u->ftpControl); + fdio->deref(u->ftpControl, "ftpControl", __FILE__, __LINE__); + u->ftpControl = NULL; + } FREE(u->url); FREE(u->service); FREE(u->user); @@ -358,7 +361,7 @@ int urlSplit(const char * url, urlinfo *uret) return 0; } -int urlFile(const char * url, const char * dest, int dir) { +int urlGetFile(const char * url, const char * dest) { int rc; FD_t sfd = NULL; FD_t tfd = NULL; @@ -393,7 +396,7 @@ int urlFile(const char * url, const char * dest, int dir) { switch (urlIsURL(url)) { case URL_IS_FTP: - if ((rc = ftpFile(sfd, tfd, dir))) { + if ((rc = ftpGetFile(sfd, tfd))) { unlink(dest); /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ; } @@ -402,7 +405,7 @@ int urlFile(const char * url, const char * dest, int dir) { case URL_IS_HTTP: case URL_IS_PATH: case URL_IS_DASH: - if ((rc = httpFile(sfd, tfd, dir))) { + if ((rc = httpGetFile(sfd, tfd))) { unlink(dest); /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ; } diff --git a/po/rpm.pot b/po/rpm.pot index 77c35eb..360e90b 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1999-11-02 12:41-0500\n" +"POT-Creation-Date: 1999-11-03 15:27-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1407,7 +1407,7 @@ msgstr "" msgid "Could not open %%files file: %s" msgstr "" -#: build/files.c:1190 build/pack.c:495 +#: build/files.c:1190 build/pack.c:503 #, c-format msgid "line: %s" msgstr "" @@ -1526,47 +1526,47 @@ msgstr "" msgid "Wrote: %s\n" msgstr "" -#: build/pack.c:423 build/pack.c:446 +#: build/pack.c:427 build/pack.c:454 #, c-format msgid "create archive failed on file %s: %s" msgstr "" -#: build/pack.c:465 +#: build/pack.c:473 #, c-format msgid "cpio_copy write failed: %s" msgstr "" -#: build/pack.c:472 +#: build/pack.c:480 #, c-format msgid "cpio_copy read failed: %s" msgstr "" -#: build/pack.c:551 +#: build/pack.c:559 #, c-format msgid "Could not open PreIn file: %s" msgstr "" -#: build/pack.c:558 +#: build/pack.c:566 #, c-format msgid "Could not open PreUn file: %s" msgstr "" -#: build/pack.c:565 +#: build/pack.c:573 #, c-format msgid "Could not open PostIn file: %s" msgstr "" -#: build/pack.c:572 +#: build/pack.c:580 #, c-format msgid "Could not open PostUn file: %s" msgstr "" -#: build/pack.c:580 +#: build/pack.c:588 #, c-format msgid "Could not open VerifyScript file: %s" msgstr "" -#: build/pack.c:596 +#: build/pack.c:604 #, c-format msgid "Could not open Trigger script file: %s" msgstr "" @@ -2208,86 +2208,86 @@ msgstr "" #. this would probably be a good place to check if disk space #. was used up - if so, we should return a different error -#: lib/install.c:355 +#: lib/install.c:359 #, c-format msgid "unpacking of archive failed%s%s: %s" msgstr "" -#: lib/install.c:356 +#: lib/install.c:360 msgid " on file " msgstr "" -#: lib/install.c:399 +#: lib/install.c:403 msgid "installing a source package\n" msgstr "" -#: lib/install.c:410 +#: lib/install.c:414 #, c-format msgid "cannot create %s: %s" msgstr "" -#: lib/install.c:418 lib/install.c:440 +#: lib/install.c:422 lib/install.c:444 #, c-format msgid "cannot write to %s" msgstr "" -#: lib/install.c:422 +#: lib/install.c:426 #, c-format msgid "sources in: %s\n" msgstr "" -#: lib/install.c:433 +#: lib/install.c:437 #, c-format msgid "cannot create %s" msgstr "" -#: lib/install.c:444 +#: lib/install.c:448 #, c-format msgid "spec file in: %s\n" msgstr "" -#: lib/install.c:478 lib/install.c:506 +#: lib/install.c:482 lib/install.c:510 msgid "source package contains no .spec file" msgstr "" -#: lib/install.c:527 +#: lib/install.c:531 #, c-format msgid "renaming %s to %s\n" msgstr "" -#: lib/install.c:529 lib/install.c:807 lib/uninstall.c:27 +#: lib/install.c:533 lib/install.c:811 lib/uninstall.c:27 #, c-format msgid "rename of %s to %s failed: %s" msgstr "" -#: lib/install.c:619 +#: lib/install.c:623 msgid "source package expected, binary found" msgstr "" -#: lib/install.c:676 +#: lib/install.c:680 #, c-format msgid "package: %s-%s-%s files test = %d\n" msgstr "" -#: lib/install.c:737 +#: lib/install.c:741 msgid "stopping install as we're running --test\n" msgstr "" -#: lib/install.c:742 +#: lib/install.c:746 msgid "running preinstall script (if any)\n" msgstr "" -#: lib/install.c:767 +#: lib/install.c:771 #, c-format msgid "warning: %s created as %s" msgstr "" -#: lib/install.c:803 +#: lib/install.c:807 #, c-format msgid "warning: %s saved as %s" msgstr "" -#: lib/install.c:877 +#: lib/install.c:881 msgid "running postinstall scripts (if any)\n" msgstr "" @@ -2827,7 +2827,7 @@ msgid "opening database mode 0x%x in %s\n" msgstr "" #. XXX Fstrerror -#: lib/rpmdb.c:156 lib/url.c:370 +#: lib/rpmdb.c:156 lib/url.c:373 #, c-format msgid "failed to open %s\n" msgstr "" @@ -3021,60 +3021,59 @@ msgstr "" msgid "Installing %s\n" msgstr "" -#: lib/rpmio.c:200 +#: lib/rpmio.c:229 msgid "Success" msgstr "" -#: lib/rpmio.c:203 +#: lib/rpmio.c:232 msgid "Bad server response" msgstr "" -#: lib/rpmio.c:206 +#: lib/rpmio.c:235 msgid "Server IO error" msgstr "" -#: lib/rpmio.c:209 +#: lib/rpmio.c:238 msgid "Server timeout" msgstr "" -#: lib/rpmio.c:212 +#: lib/rpmio.c:241 msgid "Unable to lookup server host address" msgstr "" -#: lib/rpmio.c:215 +#: lib/rpmio.c:244 msgid "Unable to lookup server host name" msgstr "" -#: lib/rpmio.c:218 +#: lib/rpmio.c:247 msgid "Failed to connect to server" msgstr "" -#: lib/rpmio.c:221 +#: lib/rpmio.c:250 msgid "Failed to establish data connection to server" msgstr "" -#: lib/rpmio.c:224 +#: lib/rpmio.c:253 msgid "IO error to local file" msgstr "" -#: lib/rpmio.c:227 +#: lib/rpmio.c:256 msgid "Error setting remote server to passive mode" msgstr "" -#: lib/rpmio.c:230 +#: lib/rpmio.c:259 msgid "File not found on server" msgstr "" -#: lib/rpmio.c:233 +#: lib/rpmio.c:262 msgid "Abort in progress" msgstr "" -#: lib/rpmio.c:237 +#: lib/rpmio.c:266 msgid "Unknown or unexpected error" msgstr "" -#. XXX PARANOIA -#: lib/rpmio.c:272 +#: lib/rpmio.c:301 #, c-format msgid "logging into %s as %s, pw %s\n" msgstr "" @@ -3374,22 +3373,22 @@ msgstr "" msgid "execution of script failed" msgstr "" -#: lib/url.c:173 +#: lib/url.c:176 #, c-format msgid "Password for %s@%s: " msgstr "" -#: lib/url.c:198 lib/url.c:224 +#: lib/url.c:201 lib/url.c:227 #, c-format msgid "error: %sport must be a number\n" msgstr "" -#: lib/url.c:333 +#: lib/url.c:336 msgid "url port must be a number\n" msgstr "" #. XXX Fstrerror -#: lib/url.c:388 +#: lib/url.c:391 #, c-format msgid "failed to create %s\n" msgstr "" diff --git a/rpm2cpio.c b/rpm2cpio.c index a791f0d..4913fe0 100644 --- a/rpm2cpio.c +++ b/rpm2cpio.c @@ -40,7 +40,11 @@ int main(int argc, char **argv) break; } +#if 0 gzdi = gzdFdopen(fdi, "r"); /* XXX gzdi == fdi */ +#else + gzdi = Fdopen(fdi, "r.gzdio"); /* XXX gzdi == fdi */ +#endif while ((ct = Fread(buffer, sizeof(buffer), 1, gzdi)) > 0) { Fwrite(buffer, ct, 1, fdo); -- 2.7.4