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 <rpmficl.h>
#include <rpmjs.h>
#include <rpmlua.h>
#include <rpmperl.h>
#include <rpmpython.h>
#include <rpmruby.h>
#include <rpmtcl.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 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.
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 = TIMEOUT_SECS
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 2986 of file rpmio.c.

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

Definition at line 2990 of file rpmio.c.

Referenced by rpmioAccess().

#define DM   ((unsigned char)242)

Definition at line 1663 of file rpmio.c.

Referenced by ftpAbort().

#define fdClose   __fdClose

Definition at line 121 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 136 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 2376 of file rpmio.c.

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

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

Definition at line 138 of file rpmio.c.

#define fdOpen   __fdOpen

Definition at line 115 of file rpmio.c.

Referenced by Fopen(), and ufdOpen().

#define fdRead   __fdRead

Definition at line 117 of file rpmio.c.

Referenced by fdFgets(), and ufdRead().

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

Definition at line 135 of file rpmio.c.

#define fdWrite   __fdWrite

Definition at line 119 of file rpmio.c.

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

#define IAC   ((unsigned char)255)

Definition at line 1657 of file rpmio.c.

Referenced by ftpAbort().

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

Definition at line 94 of file rpmio.c.

Referenced by ftpReq(), and getHostAddress().

#define IP   ((unsigned char)244)

Definition at line 1660 of file rpmio.c.

Referenced by ftpAbort(), and runScript().

#define IPPORT_FTP   21

Definition at line 87 of file rpmio.c.

Referenced by ftpLogin().

#define IPPORT_HTTP   80

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

Referenced by ftpAbort().

#define TIMEOUT_SECS   60

Definition at line 153 of file rpmio.c.

#define UFDONLY (   fd )

Definition at line 140 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 503 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 2564 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 2929 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 311 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 605 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 
) [inline, static]

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

References c2f(), and FDSANE.

int fdWritable ( FD_t  fd,
int  secs 
)

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

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

Referenced by copyFile(), cpio_doio(), extractRegular(), rpmdcPrintFile(), 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 2424 of file rpmio.c.

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

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 1733 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 2333 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 820 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 1752 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 802 of file rpmio.c.

Referenced by getHostAddress().

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

Definition at line 95 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 2992 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   )

Free all memory allocated by rpmio usage.

Definition at line 3133 of file rpmio.c.

References _digPool, _htPool, _mirePool, _rpmiobPool, _rpmluaPool, _rpmluavPool, _rpmmgPool, _urlPool, _xarPool, davDestroy(), rpmioFreePool(), rpmlogClose(), rpmluaFree(), and urlFreeCache().

Referenced by rpmcliFini(), and rpmioFini().

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

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

Referenced by db3open(), doSetupMacro(), packageBinaries(), packageSources(), repoMkdir(), 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 1626 of file rpmio.c.

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

Referenced by urlGetFile().

void* ufdGetUrlinfo ( FD_t  fd )

Definition at line 1895 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]
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 168 of file rpmio.c.

Referenced by avClosedir(), avContextAdd(), avOpendir(), and avReaddir().

int _dav_debug = 0

Definition at line 178 of file rpmio.c.

Definition at line 309 of file rpmio.c.

Referenced by fdGetPool().

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

Definition at line 2988 of file rpmio.c.

Referenced by rpmioAccess().

int _rpmio_debug = 0

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

Definition at line 3203 of file rpmio.c.

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

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

Definition at line 3198 of file rpmio.c.

int ftpTimeoutSecs = TIMEOUT_SECS [static]

Definition at line 158 of file rpmio.c.

Referenced by ftpOpen(), and urlConnect().

int noLibio = 1

Definition at line 150 of file rpmio.c.

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

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