00001 #ifndef H_RPMIO
00002 #define H_RPMIO
00003
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <dirent.h>
00012
00013 #include "glob.h"
00014
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <unistd.h>
00018
00021 typedef struct pgpDig_s * pgpDig;
00022
00025 typedef struct pgpDigParams_s * pgpDigParams;
00026
00034 #if !defined(__LCLINT__) && defined(__GLIBC__) && \
00035 (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
00036 #define USE_COOKIE_SEEK_POINTER 1
00037 typedef _IO_off64_t _libio_off_t;
00038 typedef _libio_off_t * _libio_pos_t;
00039 #else
00040 typedef off_t _libio_off_t;
00041 typedef off_t _libio_pos_t;
00042 #endif
00043
00047 typedef struct _FD_s * FD_t;
00048
00051 typedef struct FDIO_s * FDIO_t;
00052
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056
00061
00064 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
00065
00066
00067
00068 ;
00069
00072 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00073
00074 ;
00075
00078 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00079
00080 ;
00081
00084 typedef int (*fdio_close_function_t) (void *cookie)
00085
00086 ;
00087
00088
00091 typedef FD_t (*fdio_ref_function_t) ( void * cookie,
00092 const char * msg, const char * file, unsigned line)
00093
00094 ;
00095
00098 typedef FD_t (*fdio_deref_function_t) ( FD_t fd,
00099 const char * msg, const char * file, unsigned line)
00100
00101 ;
00102
00103
00106 typedef FD_t (*fdio_new_function_t) (const char * msg,
00107 const char * file, unsigned line)
00108
00109 ;
00110
00111
00114 typedef int (*fdio_fileno_function_t) (void * cookie)
00115
00116 ;
00117
00118
00121 typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
00122
00123 ;
00124
00127 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00128
00129 ;
00130
00133 typedef void * (*fdio_ffileno_function_t) (FD_t fd)
00134
00135 ;
00136
00139 typedef int (*fdio_fflush_function_t) (FD_t fd)
00140
00141 ;
00149
00152 typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
00153
00154 ;
00155
00158 typedef int (*fdio_chdir_function_t) (const char * path)
00159
00160 ;
00161
00164 typedef int (*fdio_rmdir_function_t) (const char * path)
00165
00166 ;
00167
00170 typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
00171
00172 ;
00173
00176 typedef int (*fdio_unlink_function_t) (const char * path)
00177
00178 ;
00179
00180
00183 typedef int (*fdio_stat_function_t) (const char * path, struct stat * st)
00184
00185 ;
00186
00189 typedef int (*fdio_lstat_function_t) (const char * path, struct stat * st)
00190
00191 ;
00192
00195 typedef int (*fdio_access_function_t) (const char * path, int amode)
00196
00197 ;
00198
00204 struct FDIO_s {
00205 fdio_read_function_t read;
00206 fdio_write_function_t write;
00207 fdio_seek_function_t seek;
00208 fdio_close_function_t close;
00209
00210 fdio_ref_function_t _fdref;
00211 fdio_deref_function_t _fdderef;
00212 fdio_new_function_t _fdnew;
00213 fdio_fileno_function_t _fileno;
00214
00215 fdio_open_function_t _open;
00216 fdio_fopen_function_t _fopen;
00217 fdio_ffileno_function_t _ffileno;
00218 fdio_fflush_function_t _fflush;
00219
00220 fdio_mkdir_function_t _mkdir;
00221 fdio_chdir_function_t _chdir;
00222 fdio_rmdir_function_t _rmdir;
00223 fdio_rename_function_t _rename;
00224 fdio_unlink_function_t _unlink;
00225 };
00226
00227
00232
00236 const char * Fstrerror( FD_t fd)
00237 ;
00238
00242
00243 size_t Fread( void * buf, size_t size, size_t nmemb, FD_t fd)
00244
00245
00246
00247 ;
00248
00249
00253
00254 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00255
00256
00257 ;
00258
00259
00263 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00264
00265 ;
00266
00270 int Fclose( FD_t fd)
00271
00272 ;
00273
00276 FD_t Fdopen(FD_t ofd, const char * fmode)
00277
00278 ;
00279
00283 FD_t Fopen( const char * path,
00284 const char * fmode)
00285
00286 ;
00287
00288
00292 int Fflush( FD_t fd)
00293
00294 ;
00295
00299 int Ferror( FD_t fd)
00300 ;
00301
00305 int Fileno(FD_t fd)
00306
00307 ;
00308
00312
00313 int Fcntl(FD_t fd, int op, void *lip)
00314
00315 ;
00316
00323
00327 int Mkdir(const char * path, mode_t mode)
00328
00329 ;
00330
00334 int Chdir(const char * path)
00335
00336 ;
00337
00341 int Rmdir(const char * path)
00342
00343 ;
00344
00349 int Chroot(const char * path)
00350
00351 ;
00352
00356 int Rename(const char * oldpath, const char * newpath)
00357
00358 ;
00359
00363 int Link(const char * oldpath, const char * newpath)
00364
00365 ;
00366
00370 int Unlink(const char * path)
00371
00372 ;
00373
00377 int Stat(const char * path, struct stat * st)
00378
00379 ;
00380
00384 int Lstat(const char * path, struct stat * st)
00385
00386 ;
00387
00392 int Chown(const char * path, uid_t owner, gid_t group)
00393
00394 ;
00395
00400 int Lchown(const char * path, uid_t owner, gid_t group)
00401
00402 ;
00403
00408 int Chmod(const char * path, mode_t mode)
00409
00410 ;
00411
00416 int Mkfifo(const char * path, mode_t mode)
00417
00418 ;
00419
00424 int Mknod(const char * path, mode_t mode, dev_t dev)
00425
00426 ;
00427
00432 int Utime(const char * path, const struct utimbuf * buf)
00433
00434 ;
00435
00440 int Utimes(const char * path, const struct timeval * times)
00441
00442 ;
00443
00448 int Symlink(const char * oldpath, const char * newpath)
00449
00450 ;
00451
00456
00457 int Readlink(const char * path, char * buf, size_t bufsiz)
00458
00459
00460
00461 ;
00462
00463
00468 int Access(const char * path, int amode)
00469
00470 ;
00471
00475 int Glob_pattern_p (const char *pattern, int quote)
00476 ;
00477
00481 int Glob_error(const char * epath, int eerrno)
00482 ;
00483
00487 int Glob(const char * pattern, int flags,
00488 int errfunc(const char * epath, int eerrno),
00489 glob_t * pglob)
00490
00491 ;
00492
00496 void Globfree( glob_t * pglob)
00497
00498 ;
00499
00500
00504
00505 DIR * Opendir(const char * path)
00506
00507 ;
00508
00512
00513 struct dirent * Readdir(DIR * dir)
00514
00515 ;
00516
00520 int Closedir( DIR * dir)
00521
00522 ;
00523
00528 off_t Lseek(int fdno, off_t offset, int whence)
00529
00530 ;
00531
00539
00542 off_t fdSize(FD_t fd)
00543
00544 ;
00545
00548 FD_t fdDup(int fdno)
00549
00550 ;
00551
00552 #ifdef UNUSED
00553 FILE *fdFdopen( void * cookie, const char * mode);
00554 #endif
00555
00556
00557
00558
00561 #ifndef H_RPMIO_INTERNAL
00562 int fdFileno(void * cookie)
00563 ;
00564 #define fdFileno(_fd) fdio->_fileno(_fd)
00565 #endif
00566
00569 FD_t fdOpen(const char *path, int flags, mode_t mode)
00570
00571 ;
00572 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
00573
00576
00577 ssize_t fdRead(void * cookie, char * buf, size_t count)
00578
00579
00580
00581 ;
00582 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
00583
00584
00587 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00588
00589 ;
00590 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
00591
00594 int fdClose( void * cookie)
00595
00596 ;
00597 #define fdClose(_fd) fdio->close(_fd)
00598
00601
00602
00603 FD_t fdLink ( void * cookie, const char * msg)
00604
00605 ;
00606 #define fdLink(_fd, _msg) fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00607
00610
00611
00612 FD_t fdFree( FD_t fd, const char * msg)
00613
00614 ;
00615 #define fdFree(_fd, _msg) fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00616
00619
00620
00621 FD_t fdNew (const char * msg)
00622
00623 ;
00624 #define fdNew(_msg) fdio->_fdnew(_msg, __FILE__, __LINE__)
00625
00628 int fdWritable(FD_t fd, int secs)
00629
00630 ;
00631
00634 int fdReadable(FD_t fd, int secs)
00635
00636 ;
00637
00638
00647 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
00648
00649 ;
00650
00658 int rpmioAccess(const char *FN, const char * path, int mode)
00659
00660 ;
00661
00667 char * (*Getpass) (const char * prompt)
00668 ;
00669 char * _GetPass (const char * prompt)
00670 ;
00671 char * _RequestPass (const char * prompt)
00672 ;
00673
00677
00678 typedef enum ftperrCode_e {
00679 FTPERR_NE_ERROR = -1,
00680 FTPERR_NE_LOOKUP = -2,
00681 FTPERR_NE_AUTH = -3,
00682 FTPERR_NE_PROXYAUTH = -4,
00683 FTPERR_NE_CONNECT = -5,
00684 FTPERR_NE_TIMEOUT = -6,
00685 FTPERR_NE_FAILED = -7,
00686 FTPERR_NE_RETRY = -8,
00687 FTPERR_NE_REDIRECT = -9,
00689 FTPERR_BAD_SERVER_RESPONSE = -81,
00690 FTPERR_SERVER_IO_ERROR = -82,
00691 FTPERR_SERVER_TIMEOUT = -83,
00692 FTPERR_BAD_HOST_ADDR = -84,
00693 FTPERR_BAD_HOSTNAME = -85,
00694 FTPERR_FAILED_CONNECT = -86,
00695 FTPERR_FILE_IO_ERROR = -87,
00696 FTPERR_PASSIVE_ERROR = -88,
00697 FTPERR_FAILED_DATA_CONNECT = -89,
00698 FTPERR_FILE_NOT_FOUND = -90,
00699 FTPERR_NIC_ABORT_IN_PROGRESS= -91,
00700 FTPERR_UNKNOWN = -100
00701 } ftperrCode;
00702
00703
00706
00707 const char * ftpStrerror(int errorNumber)
00708 ;
00709
00710
00713
00714 void * ufdGetUrlinfo(FD_t fd)
00715 ;
00716
00719
00720
00721 const char * urlStrerror(const char * url)
00722
00723 ;
00724
00725
00728
00729 int ufdCopy(FD_t sfd, FD_t tfd)
00730
00731 ;
00732
00733
00736 int ufdGetFile( FD_t sfd, FD_t tfd)
00737
00738 ;
00739
00742 int timedRead(FD_t fd, void * bufptr, int length)
00743
00744 ;
00745 #define timedRead (ufdio->read)
00746
00747
00750 extern FDIO_t fdio;
00751
00754 extern FDIO_t fpio;
00755
00758 extern FDIO_t ufdio;
00759
00762 extern FDIO_t gzdio;
00763
00766 extern FDIO_t bzdio;
00767
00770 extern FDIO_t lzdio;
00771
00774 extern FDIO_t fadio;
00775
00778 static inline int xislower(int c) {
00779 return (c >= 'a' && c <= 'z');
00780 }
00781 static inline int xisupper(int c) {
00782 return (c >= 'A' && c <= 'Z');
00783 }
00784 static inline int xisalpha(int c) {
00785 return (xislower(c) || xisupper(c));
00786 }
00787 static inline int xisdigit(int c) {
00788 return (c >= '0' && c <= '9');
00789 }
00790 static inline int xisalnum(int c) {
00791 return (xisalpha(c) || xisdigit(c));
00792 }
00793 static inline int xisblank(int c) {
00794 return (c == ' ' || c == '\t');
00795 }
00796 static inline int xisspace(int c) {
00797 return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
00798 }
00799 static inline int xiscntrl(int c) {
00800 return (c < ' ');
00801 }
00802 static inline int xisascii(int c) {
00803 return ((c & 0x80) != 0x80);
00804 }
00805 static inline int xisprint(int c) {
00806 return (c >= ' ' && xisascii(c));
00807 }
00808 static inline int xisgraph(int c) {
00809 return (c > ' ' && xisascii(c));
00810 }
00811 static inline int xispunct(int c) {
00812 return (xisgraph(c) && !xisalnum(c));
00813 }
00814
00815 static inline int xtolower(int c) {
00816 return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00817 }
00818 static inline int xtoupper(int c) {
00819 return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
00820 }
00821
00825 int xstrcasecmp(const char * s1, const char * s2) ;
00826
00830 int xstrncasecmp(const char *s1, const char * s2, size_t n) ;
00831
00835
00836 const char * xstrtolocale( const char *str)
00837 ;
00838 #ifdef __cplusplus
00839 }
00840 #endif
00841
00842 #endif