rpmio/rpmio.c File Reference

#include "system.h"
#include <stdarg.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rpmio_internal.h>
#include <rpmdav.h>
#include "ugid.h"
#include "rpmmessages.h"
#include "debug.h"

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)

Functions

static int inet_aton (const char *cp, struct in_addr *inp)
static void * _free (const void *p)
 Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
static 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)
static FD_t XfdLink (void *cookie, const char *msg, const char *file, unsigned line)
static FD_t XfdFree (FD_t fd, const char *msg, const char *file, unsigned line)
static 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 *const 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)
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 httpOpen (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.
char * rpmEscapeSpaces (const char *s)
 Escape isspace(3) characters in string.
int rpmioMkpath (const char *path, mode_t mode, uid_t uid, gid_t gid)
 Insure that directories in path exist, creating as needed.
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
static int httpTimeoutSecs = 60
int _rpmio_debug = 0
int _av_debug = 0
int _ftp_debug = 0
int _dav_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 struct FDIO_s fpio_s
FDIO_t fpio = &fpio_s


Detailed Description

Definition in file rpmio.c.


Define Documentation

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

Definition at line 86 of file rpmio.c.

#define DM   242

Definition at line 1638 of file rpmio.c.

Referenced by ftpAbort().

#define fdClose   __fdClose

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

#define fdGetFILE ( _fd   )     ((FILE *)fdGetFp(_fd))

Definition at line 90 of file rpmio.c.

Referenced by Fclose(), Ferror(), Fflush(), Fread(), Fseek(), Fwrite(), rdcl(), and ufdClose().

#define FDIOVEC ( _fd,
_vec   )     ((fdGetIo(_fd) && fdGetIo(_fd)->_vec) ? fdGetIo(_fd)->_vec : NULL)

Definition at line 2821 of file rpmio.c.

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

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

Definition at line 80 of file rpmio.c.

Referenced by XfdFree(), and XfdLink().

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

Definition at line 84 of file rpmio.c.

#define fdOpen   __fdOpen

Definition at line 62 of file rpmio.c.

Referenced by Fopen(), and ufdOpen().

#define fdRead   __fdRead

Definition at line 64 of file rpmio.c.

Referenced by fdFgets(), and ufdRead().

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

Definition at line 81 of file rpmio.c.

#define fdWrite   __fdWrite

Definition at line 66 of file rpmio.c.

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

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

Definition at line 85 of file rpmio.c.

#define IAC   255

Definition at line 1632 of file rpmio.c.

Referenced by ftpAbort().

#define IP   244

Definition at line 1635 of file rpmio.c.

Referenced by ftpAbort().

#define IPPORT_FTP   21

Definition at line 35 of file rpmio.c.

Referenced by ftpLogin(), and urlSplit().

#define IPPORT_HTTP   80

Definition at line 38 of file rpmio.c.

Referenced by urlSplit().

#define SHUT_RDWR   1+1

Definition at line 1641 of file rpmio.c.

Referenced by ftpAbort().

#define TIMEOUT_SECS   60

Definition at line 101 of file rpmio.c.

#define UFDONLY ( fd   ) 

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

References DBGIO, fdbg(), fdNew, fdSetFdno(), 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 void* _free ( const void *  p  )  [inline, static]

Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.

Parameters:
p memory to free
Return values:
NULL always

Definition at line 139 of file rpmio.c.

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.

  • 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 3005 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 3335 of file rpmio.c.

References Fileno().

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

FD_t fdDup ( int  fdno  ) 

FD_t Fdopen ( FD_t  ofd,
const char *  fmode 
)

int fdReadable ( FD_t  fd,
int  secs 
)

Definition at line 570 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 431 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 250 of file rpmio.c.

References c2f(), and FDSANE.

off_t fdSize ( FD_t  fd  ) 

int fdWritable ( FD_t  fd,
int  secs 
)

Definition at line 515 of file rpmio.c.

References _rpmio_debug, errno, fdFileno, _FD_s::req, and strerror.

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

int Ferror ( FD_t  fd  ) 

int Fflush ( FD_t  fd  ) 

fflush(3) clone.

Definition at line 3257 of file rpmio.c.

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

Referenced by copyFile(), cpio_doio(), expandRegular(), 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 2871 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 1707 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* const 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 2787 of file rpmio.c.

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

Referenced by Fstrerror().

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

Definition at line 792 of file rpmio.c.

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

Referenced by tcpConnect().

static FD_t httpOpen ( const char *  url,
int  flags,
mode_t  mode,
urlinfo uret 
) [static]

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

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

Referenced by httpReq().

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

Definition at line 42 of file rpmio.c.

Referenced by ftpReq(), and getHostAddress().

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

Definition at line 771 of file rpmio.c.

Referenced by getHostAddress().

char* rpmEscapeSpaces ( const char *  s  ) 

Escape isspace(3) characters in string.

Parameters:
s string
Returns:
escaped string

Definition at line 3344 of file rpmio.c.

References xmalloc().

Referenced by rpmgiGlobArgv(), and rpmInstall().

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

Insure that directories in path exist, creating as needed.

Parameters:
path diretory path
mode directory mode (if created)
uid directory uid (if created), or -1 to skip
gid directory uid (if created), or -1 to skip
Returns:
0 on success, errno (or -1) on error

Definition at line 3369 of file rpmio.c.

References alloca(), 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:
fn file name to read
Return values:
*bp (malloc'd) buffer address
*blenp (malloc'd) buffer length
Returns:
0 on success

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

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

Referenced by ftpLogin(), and httpReq().

int ufdCopy ( FD_t  sfd,
FD_t  tfd 
)

int ufdGetFile ( FD_t  sfd,
FD_t  tfd 
)

Definition at line 1601 of file rpmio.c.

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

Referenced by urlGetFile().

void* ufdGetUrlinfo ( FD_t  fd  ) 

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

const char* urlStrerror ( const char *  url  ) 

static FD_t XfdFree ( FD_t  fd,
const char *  msg,
const char *  file,
unsigned  line 
) [inline, static]

static FD_t XfdLink ( void *  cookie,
const char *  msg,
const char *  file,
unsigned  line 
) [inline, static]

Definition at line 278 of file rpmio.c.

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

Referenced by XfdNew().

static FD_t XfdNew ( const char *  msg,
const char *  file,
unsigned  line 
) [inline, static]


Variable Documentation

int _av_debug = 0

Definition at line 121 of file rpmio.c.

int _dav_debug = 0

Definition at line 131 of file rpmio.c.

int _ftp_debug = 0

int _rpmio_debug = 0

Definition at line 513 of file rpmio.c.

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

struct FDIO_s fdio_s [static]

Initial value:

 {
   __fdRead ,  __fdWrite , fdSeek,  __fdClose , XfdLink, XfdFree, XfdNew, fdFileno,
   __fdOpen , NULL, fdGetFp, NULL,      mkdir, chdir, rmdir, rename, unlink
}

Definition at line 508 of file rpmio.c.

Definition at line 3479 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:

Definition at line 3474 of file rpmio.c.

int ftpTimeoutSecs = 60 [static]

Definition at line 106 of file rpmio.c.

Referenced by ftpOpen(), and urlConnect().

int httpTimeoutSecs = 60 [static]

Definition at line 111 of file rpmio.c.

Referenced by httpOpen().

int noLibio = 1

Definition at line 98 of file rpmio.c.

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

Definition at line 2351 of file rpmio.c.

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

struct FDIO_s ufdio_s [static]

Initial value:

Definition at line 2346 of file rpmio.c.

rpmCallbackFunction urlNotify = NULL [static]

Definition at line 1477 of file rpmio.c.

int urlNotifyCount = -1 [static]

Definition at line 1483 of file rpmio.c.

void* urlNotifyData = NULL [static]

Definition at line 1480 of file rpmio.c.


Generated on Fri Dec 12 13:02:11 2008 for rpm by  doxygen 1.5.6