rpm 5.3.7
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 <rpmiotypes.h>
#include <rpmmacro.h>
#include <rpmaug.h>
#include <rpmficl.h>
#include <rpmjs.h>
#include <rpmlua.h>
#include <rpmnix.h>
#include <rpmperl.h>
#include <rpmpython.h>
#include <rpmruby.h>
#include <rpmsql.h>
#include <rpmsquirrel.h>
#include <rpmtcl.h>
#include <rpmhkp.h>
#include <rpmsm.h>
#include <rpmsp.h>
#include <rpmsx.h>
#include <rpmio_internal.h>
#include <ugid.h>
#include <rpmcb.h>
#include <rpmdav.h>
#include "debug.h"
Include dependency graph for rpmio.c:

Go to the source code of this file.

Defines

#define NI_MAXHOST   1025
#define _RPMHKP_INTERNAL
#define IPPORT_FTP   21
#define IPPORT_HTTP   80
#define inet_aton(cp, inp)   rpm_inet_aton(cp,inp)
#define fdOpen   __fdOpen
#define fdRead   __fdRead
#define fdWrite   __fdWrite
#define fdClose   __fdClose
#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 UFDONLY(fd)
#define fdGetFILE(_fd)   ((FILE *)fdGetFp(_fd))
#define TIMEOUT_SECS   60
#define IAC   ((unsigned char)255)
#define IP   ((unsigned char)244)
#define DM   ((unsigned char)242)
#define SHUT_RDWR   1+1
#define FDIOVEC(_fd, _vec)   ((fdGetIo(_fd) && fdGetIo(_fd)->_vec) ? fdGetIo(_fd)->_vec : NULL)
#define _PATH   "/bin:/usr/bin:/sbin:/usr/sbin"
#define alloca_strdup(_s)   strcpy(alloca(strlen(_s)+1), (_s))

Functions

static int rpm_inet_aton (const char *cp, struct in_addr *inp)
const char * fdbg (FD_t fd)
FD_t fdDup (int fdno)
static int fdSeekNot (void *cookie, _libio_pos_t pos, int whence)
static void fdFini (void *_fd)
static FD_t fdGetPool (rpmioPool pool)
FD_t XfdNew (const char *msg, const char *fn, unsigned ln)
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)
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)
static int httpResp (urlinfo u, FD_t ctrl, char **str)
static int httpReq (FD_t ctrl, const char *httpCmd, const char *httpArg)
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.
long Ftell (FD_t fd)
void Rewind (FD_t fd)
int Fgetpos (FD_t fd, fpos_t *pos)
int Fsetpos (FD_t fd, fpos_t *pos)
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.
void rpmioClean (void)
 Free all memory allocated by rpmio usage.

Variables

int noLibio = 1
static int ftpTimeoutSecs = 60
int _rpmio_debug = 0
int _av_debug = 0
int _ftp_debug = 0
int _dav_debug = 0
rpmioPool _fdPool
static struct FDIO_s fdio_s
FDIO_t fdio = &fdio_s
static struct FDIO_s ufdio_s
FDIO_t ufdio = &ufdio_s
static const char * _path = "/bin:/usr/bin:/sbin:/usr/sbin"
static struct FDIO_s fpio_s
FDIO_t fpio = &fpio_s

Detailed Description

Definition in file rpmio.c.


Define Documentation

#define _PATH   "/bin:/usr/bin:/sbin:/usr/sbin"

Definition at line 3051 of file rpmio.c.

#define _RPMHKP_INTERNAL

Definition at line 80 of file rpmio.c.

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

Definition at line 3055 of file rpmio.c.

Referenced by rpmioAccess().

#define DM   ((unsigned char)242)

Definition at line 1688 of file rpmio.c.

Referenced by ftpAbort().

#define fdClose   __fdClose

Definition at line 132 of file rpmio.c.

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

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

Definition at line 147 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 2396 of file rpmio.c.

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

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

Definition at line 149 of file rpmio.c.

#define fdOpen   __fdOpen

Definition at line 126 of file rpmio.c.

Referenced by Fopen(), and ufdOpen().

#define fdRead   __fdRead

Definition at line 128 of file rpmio.c.

Referenced by fdFgets(), and ufdRead().

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

Definition at line 146 of file rpmio.c.

#define fdWrite   __fdWrite

Definition at line 130 of file rpmio.c.

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

#define IAC   ((unsigned char)255)

Definition at line 1682 of file rpmio.c.

Referenced by ftpAbort().

#define inet_aton (   cp,
  inp 
)    rpm_inet_aton(cp,inp)

Definition at line 105 of file rpmio.c.

Referenced by ftpReq(), and getHostAddress().

#define IP   ((unsigned char)244)

Definition at line 1685 of file rpmio.c.

Referenced by ftpAbort(), and runScript().

#define IPPORT_FTP   21

Definition at line 98 of file rpmio.c.

Referenced by ftpLogin().

#define IPPORT_HTTP   80

Definition at line 101 of file rpmio.c.

#define NI_MAXHOST   1025

Definition at line 17 of file rpmio.c.

Referenced by ftpReq(), httpReq(), and tcpConnect().

#define SHUT_RDWR   1+1

Definition at line 1691 of file rpmio.c.

Referenced by ftpAbort().

#define TIMEOUT_SECS   60

Definition at line 164 of file rpmio.c.

#define UFDONLY (   fd)

Definition at line 151 of file rpmio.c.

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


Function Documentation

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

Definition at line 525 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 compression level
  • gzopen: 'f' is filtered (Z_FILTERED)
  • gzopen: 'h' is Huffman encoding (Z_HUFFMAN_ONLY)
  • bzopen: [1-9] is block size (in 100K units)
  • bzopen: 's' is smallmode
  • bzopen: 'q' sets verbosity to 0
  • bzopen: 'v' does verbosity++ (up to 4)
  • HACK: '.' terminates, rest is type of I/O

Definition at line 2629 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 2994 of file rpmio.c.

References Fileno().

FD_t fdDup ( int  fdno)
static void fdFini ( void *  _fd) [static]
static FD_t fdGetPool ( rpmioPool  pool) [static]

Definition at line 333 of file rpmio.c.

References _fdPool, _rpmio_debug, fdbg(), fdFini(), rpmioGetPool(), and rpmioNewPool().

Referenced by XfdNew().

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

Definition at line 627 of file rpmio.c.

References errno, fdFileno(), and _FD_s::req.

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

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

Definition at line 471 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 279 of file rpmio.c.

References c2f(), and FDSANE.

int fdWritable ( FD_t  fd,
int  secs 
)

Definition at line 572 of file rpmio.c.

References _rpmio_debug, errno, fdFileno(), and _FD_s::req.

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

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

fflush(3) clone.

Definition at line 2901 of file rpmio.c.

References FDIO_s::_flush, bzdio, fdGetFILE, fdGetFp(), fdGetIo(), fpio, gzdio, lzdio, and xzdio.

Referenced by copyFile(), cpio_doio(), rpmdcPrintFile(), rpmpsmStage(), rpmsqlRun(), and writeRPM().

int Fgetpos ( FD_t  fd,
fpos_t *  pos 
)

Definition at line 2493 of file rpmio.c.

References DBGIO, errno, fdbg(), fdGetFILE, fdGetIo(), FDSANE, and fpio.

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 2444 of file rpmio.c.

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

int Fsetpos ( FD_t  fd,
fpos_t *  pos 
)

Definition at line 2507 of file rpmio.c.

References DBGIO, errno, fdbg(), fdGetFILE, fdGetIo(), FDSANE, and fpio.

const char* Fstrerror ( FD_t  fd)
long Ftell ( FD_t  fd)

Definition at line 2470 of file rpmio.c.

References DBGIO, errno, fdbg(), fdGetFILE, fdGetIo(), FDSANE, and fpio.

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 1758 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 
)
static const char* getFdErrstr ( FD_t  fd) [static]

Definition at line 2353 of file rpmio.c.

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

Referenced by Fstrerror().

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

Definition at line 842 of file rpmio.c.

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

Referenced by tcpConnect().

static int httpReq ( FD_t  ctrl,
const char *  httpCmd,
const char *  httpArg 
) [static]
static int httpResp ( urlinfo  u,
FD_t  ctrl,
char **  str 
) [static]

Definition at line 1777 of file rpmio.c.

References _ftp_debug, checkResponse(), FTPERR_FILE_NOT_FOUND, FTPERR_UNKNOWN, _FD_s::syserrno, and URLSANE.

Referenced by httpReq().

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

Definition at line 824 of file rpmio.c.

Referenced by getHostAddress().

void Rewind ( FD_t  fd)

Definition at line 2484 of file rpmio.c.

References DBGIO, fdbg(), fdGetFILE, fdGetIo(), FDSANE, and fpio.

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

Definition at line 106 of file rpmio.c.

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 3057 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 rpmtsPRCO(), and unsatisfiedDepend().

void rpmioClean ( void  )
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 3002 of file rpmio.c.

References alloca(), Chown(), D_, errno, Mkdir(), rpmlog(), RPMLOG_DEBUG, Stat(), and stpcpy().

Referenced by db3open(), doSetupMacro(), packageBinaries(), packageSources(), rpmdbExportInfo(), rpmrepoMkdir(), rpmTempFile(), and sql_open().

static int tcpConnect ( FD_t  ctrl,
const char *  host,
int  port 
) [static]
int ufdCopy ( FD_t  sfd,
FD_t  tfd 
)
int ufdGetFile ( FD_t  sfd,
FD_t  tfd 
)

Definition at line 1651 of file rpmio.c.

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

Referenced by urlGetFile().

void* ufdGetUrlinfo ( FD_t  fd)

Definition at line 1920 of file rpmio.c.

References FDSANE, _FD_s::u, 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 
) [static]
static ssize_t ufdWrite ( void *  cookie,
const char *  buf,
size_t  count 
) [static]
static int urlConnect ( const char *  url,
urlinfo uret 
) [static]
const char* urlStrerror ( const char *  url)
FD_t XfdNew ( const char *  msg,
const char *  fn,
unsigned  ln 
)

Variable Documentation

int _av_debug = 0

Definition at line 179 of file rpmio.c.

int _dav_debug = 0

Definition at line 189 of file rpmio.c.

Definition at line 331 of file rpmio.c.

Referenced by fdGetPool().

int _ftp_debug = 0
const char* _path = "/bin:/usr/bin:/sbin:/usr/sbin" [static]

Definition at line 3053 of file rpmio.c.

Referenced by rpmioAccess().

Definition at line 570 of file rpmio.c.

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

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

Definition at line 565 of file rpmio.c.

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

Definition at line 3318 of file rpmio.c.

int ftpTimeoutSecs = 60 [static]

Definition at line 169 of file rpmio.c.

Referenced by ftpOpen(), and urlConnect().

int noLibio = 1

Definition at line 161 of file rpmio.c.

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

Definition at line 2349 of file rpmio.c.

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

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

Definition at line 2344 of file rpmio.c.