rpm  4.5
Defines | Functions | Variables
rpmio/rpmio.c File Reference
#include "system.h"
#include <stdarg.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rpmmacro.h>
#include <rpmio_internal.h>
#include <rpmdav.h>
#include "ugid.h"
#include "rpmmessages.h"
#include "debug.h"
Include dependency graph for rpmio.c:

Go to the source code of this file.

Defines

#define IPPORT_FTP   21
#define IPPORT_HTTP   80
#define fdOpen   __fdOpen
#define fdRead   __fdRead
#define fdWrite   __fdWrite
#define fdClose   __fdClose
#define FDNREFS(fd)   (fd ? ((FD_t)fd)->nrefs : -9)
#define FDTO(fd)   (fd ? ((FD_t)fd)->rd_timeoutsecs : -99)
#define FDCPIOPOS(fd)   (fd ? ((FD_t)fd)->fd_cpioPos : -99)
#define FDONLY(fd)   assert(fdGetIo(fd) == fdio)
#define GZDONLY(fd)   assert(fdGetIo(fd) == gzdio)
#define BZDONLY(fd)   assert(fdGetIo(fd) == bzdio)
#define UFDONLY(fd)
#define fdGetFILE(_fd)   ((FILE *)fdGetFp(_fd))
#define TIMEOUT_SECS   60
#define IAC   255
#define IP   244
#define DM   242
#define SHUT_RDWR   1+1
#define FDIOVEC(_fd, _vec)   ((fdGetIo(_fd) && fdGetIo(_fd)->_vec) ? fdGetIo(_fd)->_vec : NULL)
#define _PATH   "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:~/bin"
#define alloca_strdup(_s)   strcpy(alloca(strlen(_s)+1), (_s))

Functions

static int inet_aton (const char *cp, struct in_addr *inp)
const char * fdbg (FD_t fd)
off_t fdSize (FD_t fd)
FD_t fdDup (int fdno)
static int fdSeekNot (void *cookie, _libio_pos_t pos, int whence)
FD_t XfdLink (void *cookie, const char *msg, const char *file, unsigned line)
FD_t XfdFree (FD_t fd, const char *msg, const char *file, unsigned line)
FD_t XfdNew (const char *msg, const char *file, unsigned line)
static ssize_t __fdRead (void *cookie, char *buf, size_t count)
static ssize_t __fdWrite (void *cookie, const char *buf, size_t count)
static int fdSeek (void *cookie, _libio_pos_t pos, int whence)
static int __fdClose (void *cookie)
static FD_t __fdOpen (const char *path, int flags, mode_t mode)
int fdWritable (FD_t fd, int secs)
int fdReadable (FD_t fd, int secs)
int fdFgets (FD_t fd, char *buf, size_t len)
const char * ftpStrerror (int errorNumber)
const char * urlStrerror (const char *url)
static int mygethostbyname (const char *host, struct in_addr *address)
static int getHostAddress (const char *host, struct in_addr *address)
static int tcpConnect (FD_t ctrl, const char *host, int port)
static int checkResponse (void *uu, FD_t ctrl, int *ecp, char **str)
static int ftpCheckResponse (urlinfo u, char **str)
static int ftpCommand (urlinfo u, char **str,...)
static int ftpLogin (urlinfo u)
int ftpReq (FD_t data, const char *ftpCmd, const char *ftpArg)
void urlSetCallback (rpmCallbackFunction notify, void *notifyData, int notifyCount)
int ufdCopy (FD_t sfd, FD_t tfd)
static int urlConnect (const char *url, urlinfo *uret)
int ufdGetFile (FD_t sfd, FD_t tfd)
int ftpCmd (const char *cmd, const char *url, const char *arg2)
static int ftpAbort (urlinfo u, FD_t data)
static int ftpFileDone (urlinfo u, FD_t data)
void * ufdGetUrlinfo (FD_t fd)
static ssize_t ufdRead (void *cookie, char *buf, size_t count)
static ssize_t ufdWrite (void *cookie, const char *buf, size_t count)
static int ufdSeek (void *cookie, _libio_pos_t pos, int whence)
int ufdClose (void *cookie)
FD_t ftpOpen (const char *url, int flags, mode_t mode, urlinfo *uret)
static FD_t ufdOpen (const char *url, int flags, mode_t mode)
static const char * getFdErrstr (FD_t fd)
const char * Fstrerror (FD_t fd)
 strerror(3) clone.
size_t Fread (void *buf, size_t size, size_t nmemb, FD_t fd)
 fread(3) clone.
size_t Fwrite (const void *buf, size_t size, size_t nmemb, FD_t fd)
 fwrite(3) clone.
int Fseek (FD_t fd, _libio_off_t offset, int whence)
 fseek(3) clone.
int Fclose (FD_t fd)
 fclose(3) clone.
static void cvtfmode (const char *m, char *stdio, size_t nstdio, char *other, size_t nother, const char **end, int *f)
 Convert stdio fmode to open(2) mode, filtering out zlib/bzlib flags.
FD_t Fdopen (FD_t ofd, const char *fmode)
FD_t Fopen (const char *path, const char *fmode)
 fopen(3) clone.
int Fflush (FD_t fd)
 fflush(3) clone.
int Ferror (FD_t fd)
 ferror(3) clone.
int Fileno (FD_t fd)
 fileno(3) clone.
int Fcntl (FD_t fd, int op, void *lip)
 fcntl(2) clone.
int rpmioMkpath (const char *path, mode_t mode, uid_t uid, gid_t gid)
 Insure that directories in path exist, creating as needed.
int rpmioAccess (const char *FN, const char *path, int mode)
 Check FN access, expanding relative paths and twiddles.
int rpmioSlurp (const char *fn, const byte **bp, ssize_t *blenp)
 Read an entire file into a buffer.

Variables

int noLibio = 1
static int ftpTimeoutSecs = 60
int _rpmio_debug = 0
int _av_debug = 0
int _ftp_debug = 0
static struct FDIO_s fdio_s
FDIO_t fdio = &fdio_s
static rpmCallbackFunction urlNotify = NULL
static void * urlNotifyData = NULL
static int urlNotifyCount = -1
static struct FDIO_s ufdio_s
FDIO_t ufdio = &ufdio_s
static const char * _path = "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:~/bin"
static struct FDIO_s fpio_s
FDIO_t fpio = &fpio_s

Detailed Description

Definition in file rpmio.c.


Define Documentation

#define _PATH   "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:~/bin"

Definition at line 3316 of file rpmio.c.

#define alloca_strdup (   _s)    strcpy(alloca(strlen(_s)+1), (_s))

Definition at line 3320 of file rpmio.c.

Referenced by rpmioAccess().

#define BZDONLY (   fd)    assert(fdGetIo(fd) == bzdio)

Definition at line 121 of file rpmio.c.

#define DM   242

Definition at line 1642 of file rpmio.c.

Referenced by ftpAbort().

#define fdClose   __fdClose

Definition at line 103 of file rpmio.c.

Referenced by Fopen(), ftpAbort(), ftpLogin(), ftpReq(), and ufdClose().

#define FDCPIOPOS (   fd)    (fd ? ((FD_t)fd)->fd_cpioPos : -99)

Definition at line 117 of file rpmio.c.

#define fdGetFILE (   _fd)    ((FILE *)fdGetFp(_fd))
#define FDIOVEC (   _fd,
  _vec 
)    ((fdGetIo(_fd) && fdGetIo(_fd)->_vec) ? fdGetIo(_fd)->_vec : NULL)

Definition at line 2754 of file rpmio.c.

Referenced by Fclose(), Fread(), Fseek(), and Fwrite().

#define FDNREFS (   fd)    (fd ? ((FD_t)fd)->nrefs : -9)

Definition at line 115 of file rpmio.c.

Referenced by XfdFree(), and XfdLink().

#define FDONLY (   fd)    assert(fdGetIo(fd) == fdio)

Definition at line 119 of file rpmio.c.

#define fdOpen   __fdOpen

Definition at line 97 of file rpmio.c.

Referenced by Fopen(), and ufdOpen().

#define fdRead   __fdRead

Definition at line 99 of file rpmio.c.

Referenced by fdFgets(), and ufdRead().

#define FDTO (   fd)    (fd ? ((FD_t)fd)->rd_timeoutsecs : -99)

Definition at line 116 of file rpmio.c.

#define fdWrite   __fdWrite

Definition at line 101 of file rpmio.c.

Referenced by ftpAbort(), ftpCommand(), ftpReq(), and ufdWrite().

#define GZDONLY (   fd)    assert(fdGetIo(fd) == gzdio)

Definition at line 120 of file rpmio.c.

#define IAC   255

Definition at line 1636 of file rpmio.c.

Referenced by ftpAbort().

#define IP   244

Definition at line 1639 of file rpmio.c.

Referenced by ftpAbort().

#define IPPORT_FTP   21

Definition at line 70 of file rpmio.c.

Referenced by ftpLogin().

#define IPPORT_HTTP   80

Definition at line 73 of file rpmio.c.

#define SHUT_RDWR   1+1

Definition at line 1645 of file rpmio.c.

Referenced by ftpAbort().

#define TIMEOUT_SECS   60

Definition at line 136 of file rpmio.c.

#define UFDONLY (   fd)

Definition at line 123 of file rpmio.c.

Referenced by ufdClose(), ufdRead(), and ufdWrite().


Function Documentation

static int __fdClose ( void *  cookie) [static]

Definition at line 442 of file rpmio.c.

References c2f(), DBGIO, fdbg(), fdFileno(), fdFree(), fdSetFdno(), FDSTAT_CLOSE, fdstat_enter(), and fdstat_exit().

static FD_t __fdOpen ( const char *  path,
int  flags,
mode_t  mode 
) [static]

Definition at line 467 of file rpmio.c.

References DBGIO, fdbg(), fdNew(), fdSetFdno(), fdSetOpen(), and _FD_s::flags.

static ssize_t __fdRead ( void *  cookie,
char *  buf,
size_t  count 
) [static]
static ssize_t __fdWrite ( void *  cookie,
const char *  buf,
size_t  count 
) [static]
static int checkResponse ( void *  uu,
FD_t  ctrl,
int *  ecp,
char **  str 
) [static]
static void cvtfmode ( const char *  m,
char *  stdio,
size_t  nstdio,
char *  other,
size_t  nother,
const char **  end,
int *  f 
) [inline, static]

Convert stdio fmode to open(2) mode, filtering out zlib/bzlib flags.

returns stdio[0] = NUL on error.

Todo:
glibc also supports ",ccs="
  • glibc: m use mmap'd input
  • glibc: c no cancel
  • gzopen: [0-9] is compession level
  • gzopen: 'f' is filtered (Z_FILTERED)
  • gzopen: 'h' is Huffman encoding (Z_HUFFMAN_ONLY)
  • bzopen: [1-9] is block size (modulo 100K)
  • bzopen: 's' is smallmode
  • HACK: '.' terminates, rest is type of I/O

Definition at line 2923 of file rpmio.c.

Referenced by Fdopen(), and Fopen().

int Fclose ( FD_t  fd)
int Fcntl ( FD_t  fd,
int  op,
void *  lip 
)

fcntl(2) clone.

Definition at line 3256 of file rpmio.c.

References Fileno().

Referenced by rpmShowProgress().

FD_t fdDup ( int  fdno)
FD_t Fdopen ( FD_t  ofd,
const char *  fmode 
)
int fdReadable ( FD_t  fd,
int  secs 
)

Definition at line 564 of file rpmio.c.

References errno, and fdFileno().

Referenced by fdFgets(), ftpAbort(), ufdClose(), and ufdRead().

static int fdSeek ( void *  cookie,
_libio_pos_t  pos,
int  whence 
) [inline, static]

Definition at line 420 of file rpmio.c.

References _FD_s::bytesRemain, c2f(), DBGIO, fdbg(), fdFileno(), fdstat_enter(), fdstat_exit(), and FDSTAT_SEEK.

Referenced by ufdSeek().

static int fdSeekNot ( void *  cookie,
_libio_pos_t  pos,
int  whence 
) [inline, static]

Definition at line 264 of file rpmio.c.

References c2f(), and FDSANE.

off_t fdSize ( FD_t  fd)
int fdWritable ( FD_t  fd,
int  secs 
)

Definition at line 513 of file rpmio.c.

References _rpmio_debug, errno, and fdFileno().

Referenced by checkResponse(), ftpLogin(), and ufdWrite().

int Ferror ( FD_t  fd)
int Fflush ( FD_t  fd)

fflush(3) clone.

Definition at line 3183 of file rpmio.c.

References fdGetFILE, fdGetFp(), fdGetIo(), and fpio.

Referenced by copyFile(), cpio_doio(), extractRegular(), rpmpsmStage(), and writeRPM().

int Fileno ( FD_t  fd)
FD_t Fopen ( const char *  path,
const char *  fmode 
)
size_t Fread ( void *  buf,
size_t  size,
size_t  nmemb,
FD_t  fd 
)
int Fseek ( FD_t  fd,
_libio_off_t  offset,
int  whence 
)

fseek(3) clone.

Definition at line 2804 of file rpmio.c.

References DBGIO, fdbg(), fdGetFILE, fdGetIo(), FDIOVEC, FDSANE, fpio, and FDIO_s::seek.

Referenced by readRPM(), and writeRPM().

const char* Fstrerror ( FD_t  fd)
static int ftpAbort ( urlinfo  u,
FD_t  data 
) [static]
static int ftpCheckResponse ( urlinfo  u,
char **  str 
) [static]
static int ftpCommand ( urlinfo  u,
char **  str,
  ... 
) [static]
static int ftpFileDone ( urlinfo  u,
FD_t  data 
) [static]

Definition at line 1711 of file rpmio.c.

References urlinfo_s::ctrl, fdFree(), ftpCheckResponse(), _FD_s::ftpFileDoneNeeded, and URLSANE.

Referenced by ufdClose().

static int ftpLogin ( urlinfo  u) [static]
const char* ftpStrerror ( int  errorNumber)
size_t Fwrite ( const void *  buf,
size_t  size,
size_t  nmemb,
FD_t  fd 
)

fwrite(3) clone.

Definition at line 2779 of file rpmio.c.

References DBGIO, fdbg(), fdGetFILE, fdGetIo(), FDIOVEC, FDSANE, fpio, and FDIO_s::write.

Referenced by copyFile(), cpio_copy(), fsmStage(), rpmWriteSignature(), runScript(), ufdCopy(), writeLead(), and writeRPM().

static const char* getFdErrstr ( FD_t  fd) [static]

Definition at line 2718 of file rpmio.c.

References _FD_s::errcookie, fdGetIo(), lzdio, and _FD_s::syserrno.

Referenced by Fstrerror().

static int getHostAddress ( const char *  host,
struct in_addr *  address 
) [static]

Definition at line 782 of file rpmio.c.

References errno, FTPERR_BAD_HOST_ADDR, FTPERR_BAD_HOSTNAME, inet_aton(), mygethostbyname(), and xisdigit().

Referenced by tcpConnect().

static int inet_aton ( const char *  cp,
struct in_addr *  inp 
) [static]

Definition at line 77 of file rpmio.c.

Referenced by ftpReq(), and getHostAddress().

static int mygethostbyname ( const char *  host,
struct in_addr *  address 
) [static]

Definition at line 761 of file rpmio.c.

Referenced by getHostAddress().

int rpmioAccess ( const char *  FN,
const char *  path,
int  mode 
)

Check FN access, expanding relative paths and twiddles.

Parameters:
FNfile path to check
pathcolon separated search path (NULL uses $PATH)
modetype of access(2) to check (0 uses X_OK)
Returns:
0 if accessible

Definition at line 3322 of file rpmio.c.

References _path, _rpmio_debug, Access(), alloca_strdup, F_OK, getenv(), R_OK, rpmCleanPath(), stpcpy(), W_OK, and X_OK.

Referenced by rpmtsCreate(), and unsatisfiedDepend().

int rpmioMkpath ( const char *  path,
mode_t  mode,
uid_t  uid,
gid_t  gid 
)

Insure that directories in path exist, creating as needed.

Parameters:
pathdirectory path
modedirectory mode (if created)
uiddirectory uid (if created), or -1 to skip
giddirectory uid (if created), or -1 to skip
Returns:
0 on success, errno (or -1) on error

Definition at line 3265 of file rpmio.c.

References alloca(), D_, errno, Mkdir(), RPMMESS_DEBUG, rpmMessage, Stat(), and stpcpy().

Referenced by db3open(), and makeTempFile().

int rpmioSlurp ( const char *  fn,
const unsigned char **  bp,
ssize_t *  blenp 
)

Read an entire file into a buffer.

Parameters:
fnfile name to read
Return values:
*bp(malloc'd) buffer address
*blenp(malloc'd) buffer length
Returns:
0 on success

Definition at line 3457 of file rpmio.c.

References Fclose(), fdSize(), Ferror(), Fopen(), Fread(), xmalloc(), and xrealloc().

Referenced by pgpReadPkts(), processMetadataFile(), and rpmPlatform().

static int tcpConnect ( FD_t  ctrl,
const char *  host,
int  port 
) [static]

Definition at line 812 of file rpmio.c.

References _ftp_debug, errno, fdSetFdno(), fdSetSyserrno(), FTPERR_FAILED_CONNECT, ftpStrerror(), and getHostAddress().

Referenced by ftpLogin().

int ufdCopy ( FD_t  sfd,
FD_t  tfd 
)
int ufdGetFile ( FD_t  sfd,
FD_t  tfd 
)

Definition at line 1605 of file rpmio.c.

References Fclose(), FDSANE, and ufdCopy().

Referenced by urlGetFile().

void* ufdGetUrlinfo ( FD_t  fd)

Definition at line 1883 of file rpmio.c.

References FDSANE, _FD_s::url, and urlLink().

static FD_t ufdOpen ( const char *  url,
int  flags,
mode_t  mode 
) [static]
static ssize_t ufdRead ( void *  cookie,
char *  buf,
size_t  count 
) [static]
static int ufdSeek ( void *  cookie,
_libio_pos_t  pos,
int  whence 
) [inline, static]
static ssize_t ufdWrite ( void *  cookie,
const char *  buf,
size_t  count 
) [static]
static int urlConnect ( const char *  url,
urlinfo uret 
) [static]
void urlSetCallback ( rpmCallbackFunction  notify,
void *  notifyData,
int  notifyCount 
)

Definition at line 1488 of file rpmio.c.

const char* urlStrerror ( const char *  url)
FD_t XfdFree ( FD_t  fd,
const char *  msg,
const char *  file,
unsigned  line 
)
FD_t XfdLink ( void *  cookie,
const char *  msg,
const char *  file,
unsigned  line 
)

Definition at line 276 of file rpmio.c.

References c2f(), DBGREFS, fdbg(), FDNREFS, and _FD_s::nrefs.

Referenced by XfdNew().

FD_t XfdNew ( const char *  msg,
const char *  file,
unsigned  line 
)

Variable Documentation

int _av_debug = 0

Definition at line 151 of file rpmio.c.

int _ftp_debug = 0
const char* _path = "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:~/bin" [static]

Definition at line 3318 of file rpmio.c.

Referenced by rpmioAccess().

int _rpmio_debug = 0

Definition at line 511 of file rpmio.c.

Referenced by fdbg(), Fdopen(), and XurlFree().

struct FDIO_s fdio_s [static]
Initial value:
 {
   __fdRead ,  __fdWrite , fdSeek,  __fdClose , NULL, NULL,
}

Definition at line 506 of file rpmio.c.

Definition at line 3516 of file rpmio.c.

Referenced by Fclose(), fdbg(), Fdopen(), Ferror(), Fflush(), Fopen(), Fread(), Fseek(), Fwrite(), and XurlFree().

struct FDIO_s fpio_s [static]
Initial value:
 {
  ufdRead, ufdWrite, fdSeek, ufdClose, NULL, NULL,
}

Definition at line 3511 of file rpmio.c.

int ftpTimeoutSecs = 60 [static]

Definition at line 141 of file rpmio.c.

Referenced by ftpOpen(), and urlConnect().

int noLibio = 1

Definition at line 133 of file rpmio.c.

Referenced by Fclose(), Fdopen(), and ufdClose().

Definition at line 2286 of file rpmio.c.

Referenced by fdbg(), Fdopen(), ftpOpen(), ufdOpen(), urlConnect(), and XfdNew().

struct FDIO_s ufdio_s [static]
Initial value:
 {
  ufdRead, ufdWrite, ufdSeek, ufdClose, NULL, NULL,
}

Definition at line 2281 of file rpmio.c.

rpmCallbackFunction urlNotify = NULL [static]

Definition at line 1480 of file rpmio.c.

int urlNotifyCount = -1 [static]

Definition at line 1486 of file rpmio.c.

Referenced by ufdCopy().

void* urlNotifyData = NULL [static]

Definition at line 1483 of file rpmio.c.

Referenced by ufdCopy().