# rpmio/rpmio.c File Reference

`#include "system.h"`
`#include <stdarg.h>`
`#include <netinet/in.h>`
`#include <arpa/inet.h>`
`#include <rpmio_internal.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 | 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)
ssize_t | fdRead (void *cookie, char *buf, size_t count)
ssize_t | fdWrite (void *cookie, const char *buf, size_t count)
static int | fdSeek (void *cookie, _libio_pos_t pos, int whence)
int | fdClose (void *cookie)
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.
int | rpmioSlurp (const char *fn, const byte **bp, ssize_t *blenp)

## Variables

int | noLibio = 1
static int | ftpTimeoutSecs = 60
static int | httpTimeoutSecs = 60
int | _ftp_debug = 0
int | _rpmio_debug = 0
static struct FDIO_s | fdio_s
FDIO_t | fdio = &fdio_s
FDIO_t | fadio
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 88 of file rpmio.c.

#define DM 242

Definition at line 1439 of file rpmio.c.

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

Definition at line 84 of file rpmio.c.

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

Definition at line 92 of file rpmio.c.

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

Definition at line 2610 of file rpmio.c.

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

Definition at line 82 of file rpmio.c.

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

Definition at line 86 of file rpmio.c.

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

Definition at line 83 of file rpmio.c.

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

Definition at line 87 of file rpmio.c.

#define IAC 255

Definition at line 1433 of file rpmio.c.

#define IP 244

Definition at line 1436 of file rpmio.c.

#define IPPORT_FTP 21

Definition at line 43 of file rpmio.c.

#define IPPORT_HTTP 80

Definition at line 46 of file rpmio.c.

#define SHUT_RDWR 1+1

Definition at line 1442 of file rpmio.c.

#define TIMEOUT_SECS 60

Definition at line 103 of file rpmio.c.

#define UFDONLY | ( | fd |  | ) |

Definition at line 90 of file rpmio.c.

## Function Documentation

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

static int checkResponse | ( | void * | uu,
|  | FD_t | ctrl,
|  | int * | ecp,
|  | char ** | str |
| ) |  |  | `[static]`

Definition at line 833 of file rpmio.c.

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] = '' 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 2780 of file rpmio.c.

int Fclose | ( | FD_t | fd | ) |

fclose(3) clone.

Definition at line 2699 of file rpmio.c.

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

fcntl(2) clone.

Definition at line 3108 of file rpmio.c.

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

Definition at line 141 of file rpmio.c.

int fdClose | ( | void * | cookie | ) |

Definition at line 456 of file rpmio.c.

FD_t fdDup | ( | int | fdno | ) |

Definition at line 229 of file rpmio.c.

FD_t Fdopen | ( | FD_t | ofd,
|  | const char * | fmode |
| ) |  |  |

Definition at line 2850 of file rpmio.c.

FD_t fdOpen | ( | const char * | path,
|  | int | flags,
|  | mode_t | mode |
| ) |  |  |

Definition at line 482 of file rpmio.c.

ssize_t fdRead | ( | void * | cookie,
|  | char * | buf,
|  | size_t | count |
| ) |  |  |

Definition at line 373 of file rpmio.c.

int fdReadable | ( | FD_t | fd,
|  | int | secs |
| ) |  |  |

Definition at line 567 of file rpmio.c.

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

Definition at line 431 of file rpmio.c.

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

Definition at line 244 of file rpmio.c.

off_t fdSize | ( | FD_t | fd | ) |

Definition at line 204 of file rpmio.c.

int fdWritable | ( | FD_t | fd,
|  | int | secs |
| ) |  |  |

Definition at line 527 of file rpmio.c.

ssize_t fdWrite | ( | void * | cookie,
|  | const char * | buf,
|  | size_t | count |
| ) |  |  |

Definition at line 395 of file rpmio.c.

int Ferror | ( | FD_t | fd | ) |

ferror(3) clone.

Definition at line 3059 of file rpmio.c.

int Fflush | ( | FD_t | fd | ) |

fflush(3) clone.

Definition at line 3039 of file rpmio.c.

int Fileno | ( | FD_t | fd | ) |

fileno(3) clone.

Definition at line 3094 of file rpmio.c.

FD_t Fopen | ( | const char * | path,
|  | const char * | fmode |
| ) |  |  |

fopen(3) clone.

Definition at line 2962 of file rpmio.c.

size_t Fread | ( | void * | buf,
|  | size_t | size,
|  | size_t | nmemb,
|  | FD_t | fd |
| ) |  |  |

fread(3) clone.

Definition at line 2613 of file rpmio.c.

int Fseek | ( | FD_t | fd,
|  | _libio_off_t | offset,
|  | int | whence |
| ) |  |  |

fseek(3) clone.

Definition at line 2665 of file rpmio.c.

const char* Fstrerror | ( | FD_t | fd | ) |

strerror(3) clone.

Definition at line 2602 of file rpmio.c.

static int ftpAbort | ( | urlinfo | u,
|  | FD_t | data |
| ) |  |  | `[static]`

Definition at line 1445 of file rpmio.c.

static int ftpCheckResponse | ( | urlinfo | u,
|  | char ** | str |
| ) |  |  | `[static]`

Definition at line 996 of file rpmio.c.

static int ftpCommand | ( | urlinfo | u,
|  | char ** | str,
|  |  | ... |
| ) |  |  | `[static]`

Definition at line 1022 of file rpmio.c.

static int ftpFileDone | ( | urlinfo | u,
|  | FD_t | data |
| ) |  |  | `[static]`

Definition at line 1508 of file rpmio.c.

static int ftpLogin | ( | urlinfo | u | ) | `[static]`

Definition at line 1060 of file rpmio.c.

const char* const ftpStrerror | ( | int | errorNumber | ) |

Definition at line 671 of file rpmio.c.

size_t Fwrite | ( | const void * | buf,
|  | size_t | size,
|  | size_t | nmemb,
|  | FD_t | fd |
| ) |  |  |

fwrite(3) clone.

Definition at line 2640 of file rpmio.c.

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

Definition at line 2576 of file rpmio.c.

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

Definition at line 759 of file rpmio.c.

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

Definition at line 1986 of file rpmio.c.

static int httpReq | ( | FD_t | ctrl,
|  | const char * | httpCmd,
|  | const char * | httpArg |
| ) |  |  | `[static]`

Definition at line 1550 of file rpmio.c.

static int httpResp | ( | urlinfo | u,
|  | FD_t | ctrl,
|  | char ** | str |
| ) |  |  | `[static]`

Definition at line 1526 of file rpmio.c.

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

Definition at line 50 of file rpmio.c.

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

Definition at line 738 of file rpmio.c.

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

Definition at line 3117 of file rpmio.c.

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

Definition at line 781 of file rpmio.c.

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

Definition at line 1298 of file rpmio.c.

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

Definition at line 1402 of file rpmio.c.

void* ufdGetUrlinfo | ( | FD_t | fd | ) |

Definition at line 1665 of file rpmio.c.

static FD_t ufdOpen | ( | const char * | url,
|  | int | flags,
|  | mode_t | mode |
| ) |  |  | `[static]`

Definition at line 2030 of file rpmio.c.

static ssize_t ufdRead | ( | void * | cookie,
|  | char * | buf,
|  | size_t | count |
| ) |  |  | `[static]`

Definition at line 1674 of file rpmio.c.

static int ufdSeek | ( | void * | cookie,
|  | _libio_pos_t | pos,
|  | int | whence |
| ) |  |  | `[inline, static]`

Definition at line 1803 of file rpmio.c.

static ssize_t ufdWrite | ( | void * | cookie,
|  | const char * | buf,
|  | size_t | count |
| ) |  |  | `[static]`

Definition at line 1738 of file rpmio.c.

static int urlConnect | ( | const char * | url,
|  | urlinfo * | uret |
| ) |  |  | `[static]`

Definition at line 1358 of file rpmio.c.

void urlSetCallback | ( | rpmCallbackFunction | notify,
|  | void * | notifyData,
|  | int | notifyCount |
| ) |  |  |

Definition at line 1292 of file rpmio.c.

const char* urlStrerror | ( | const char * | url | ) |

Definition at line 715 of file rpmio.c.

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

Definition at line 301 of file rpmio.c.

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

Definition at line 281 of file rpmio.c.

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

Definition at line 329 of file rpmio.c.

## Variable Documentation

int _ftp_debug = 0

Definition at line 118 of file rpmio.c.

int _rpmio_debug = 0

Definition at line 123 of file rpmio.c.

FDIO_t fadio

Definition at line 524 of file rpmio.c.

FDIO_t fdio = &fdio_s

Definition at line 521 of file rpmio.c.

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

FDIO_t fpio = &fpio_s

Definition at line 3173 of file rpmio.c.

struct FDIO_s fpio_s `[static]`

Initial value:

     {
      ufdRead, ufdWrite, fdSeek, ufdClose, XfdLink, XfdFree, XfdNew, fdFileno,
      ufdOpen, NULL, fdGetFp, NULL, Mkdir, Chdir, Rmdir, Rename, Unlink
    }

Definition at line 3169 of file rpmio.c.

int ftpTimeoutSecs = 60`[static]`

Definition at line 108 of file rpmio.c.

int httpTimeoutSecs = 60`[static]`

Definition at line 113 of file rpmio.c.

int noLibio = 1

Definition at line 100 of file rpmio.c.

FDIO_t ufdio = &ufdio_s

Definition at line 2124 of file rpmio.c.

struct FDIO_s ufdio_s `[static]`

Initial value:

     {
      ufdRead, ufdWrite, ufdSeek, ufdClose, XfdLink, XfdFree, XfdNew, fdFileno,
      ufdOpen, NULL, fdGetFp, NULL, Mkdir, Chdir, Rmdir, Rename, Unlink
    }

Definition at line 2120 of file rpmio.c.

rpmCallbackFunction urlNotify = NULL`[static]`

Definition at line 1284 of file rpmio.c.

int urlNotifyCount = -1`[static]`

Definition at line 1290 of file rpmio.c.

void* urlNotifyData = NULL`[static]`

Definition at line 1287 of file rpmio.c.