diff options
author | jbj <devnull@localhost> | 1999-11-03 20:33:53 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 1999-11-03 20:33:53 +0000 |
commit | 94dd9f796e8c8fa7b59e9690d8d0cf476313e5a5 (patch) | |
tree | 4f780c9b46898133105da7b2454d85ae8003edb7 /lib | |
parent | 85d4129c7bedafd466625fd4400ea5607e2f09a1 (diff) | |
download | rpm-94dd9f796e8c8fa7b59e9690d8d0cf476313e5a5.tar.gz rpm-94dd9f796e8c8fa7b59e9690d8d0cf476313e5a5.tar.bz2 rpm-94dd9f796e8c8fa7b59e9690d8d0cf476313e5a5.zip |
First use of libio.
CVS patchset: 3416
CVS date: 1999/11/03 20:33:53
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ftp.c | 33 | ||||
-rw-r--r-- | lib/install.c | 4 | ||||
-rw-r--r-- | lib/rpminstall.c | 2 | ||||
-rw-r--r-- | lib/rpmio.h | 57 | ||||
-rw-r--r-- | lib/rpmurl.h | 4 | ||||
-rw-r--r-- | lib/url.c | 15 |
6 files changed, 78 insertions, 37 deletions
@@ -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 0073f2572..ac2b9610e 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 e9ad3b5ba..dc018ff6f 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 50f5170de..52db3eeb7 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 a9a4665dd..477c051ad 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 } @@ -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@*/ ; } |