diff options
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/Makefile.am | 4 | ||||
-rw-r--r-- | rpmio/messages.c | 94 | ||||
-rw-r--r-- | rpmio/rpmerr.c | 56 | ||||
-rw-r--r-- | rpmio/rpmerr.h | 163 | ||||
-rw-r--r-- | rpmio/rpmmessages.h | 73 |
5 files changed, 95 insertions, 295 deletions
diff --git a/rpmio/Makefile.am b/rpmio/Makefile.am index 0e1e44b2b..3756e1eed 100644 --- a/rpmio/Makefile.am +++ b/rpmio/Makefile.am @@ -6,12 +6,12 @@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/build -I$(top_srcdir)/lib \ -I$(top_srcdir)/popt @INCPATH@ pkgincdir = $(pkgincludedir) -pkginc_HEADERS = rpmio.h rpmurl.h rpmmacro.h rpmmessages.h rpmerr.h +pkginc_HEADERS = rpmio.h rpmurl.h rpmmacro.h rpmlog.h rpmmessages.h rpmerr.h noinst_HEADERS = rpmio_internal.h ugid.h lib_LTLIBRARIES = librpmio.la librpmio_la_SOURCES = rpmrpc.c rpmio.c rpmio_api.c url.c macro.c \ - ugid.c rpmmalloc.c rpmerr.c messages.c + ugid.c rpmmalloc.c rpmlog.c # XXX Add internal libtool dependence install-data-local: diff --git a/rpmio/messages.c b/rpmio/messages.c deleted file mode 100644 index 45c782f00..000000000 --- a/rpmio/messages.c +++ /dev/null @@ -1,94 +0,0 @@ -#include "system.h" - -/** \ingroup rpmio - * \file rpmio/messages.c - */ - -#include <stdarg.h> - -#include <rpmmessages.h> - -static int minLevel = RPMMESS_NORMAL; - -void rpmIncreaseVerbosity(void) { - minLevel--; -} - -void rpmSetVerbosity(int level) { - minLevel = level; -} - -int rpmGetVerbosity(void) -{ - return minLevel; -} - -int rpmIsDebug(void) -{ - return (minLevel <= RPMMESS_DEBUG); -} - -int rpmIsVerbose(void) -{ - return (minLevel <= RPMMESS_VERBOSE); -} - -void rpmMessage(rpmmsgLevel level, const char * format, ...) { - va_list args; - - va_start(args, format); - if (level >= minLevel) { - switch (level) { - case RPMMESS_VERBOSE: - case RPMMESS_NORMAL: - vfprintf(stdout, format, args); - fflush(stdout); - break; - - case RPMMESS_DEBUG: - if (*format != '+') - fprintf(stdout, "D: "); - else - format++; - vfprintf(stdout, format, args); - fflush(stdout); - break; - - case RPMMESS_WARNING: - if (*format != '+') - fprintf(stderr, _("warning: ")); - else - format++; - vfprintf(stderr, format, args); - fflush(stderr); - break; - - case RPMMESS_ERROR: - if (*format != '+') - fprintf(stderr, _("error: ")); - else - format++; - vfprintf(stderr, format, args); - fflush(stderr); - break; - - case RPMMESS_FATALERROR: - if (*format != '+') - fprintf(stderr, _("fatal error: ")); - else - format++; - vfprintf(stderr, format, args); - fflush(stderr); - exit(EXIT_FAILURE); - /*@notreached@*/ break; - - default: - fprintf(stderr, _("internal error (rpm bug?): ")); - vfprintf(stderr, format, args); - fflush(stderr); - exit(EXIT_FAILURE); - /*@notreached@*/ break; - - } - } -} diff --git a/rpmio/rpmerr.c b/rpmio/rpmerr.c deleted file mode 100644 index d447e7ec1..000000000 --- a/rpmio/rpmerr.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "system.h" - -/** \ingroup rpmio - * \file rpmio/rpmerr.c - */ - -#include <stdarg.h> - -#include <rpmerr.h> -/*@access rpmerrRec @*/ - -static struct rpmerrRec_s _rpmerrRec; - -static rpmErrorCallBackType errorCallback = NULL; - -int rpmErrorCode(void) -{ - return _rpmerrRec.code; -} - -const char *rpmErrorCodeString(rpmerrCode code) -{ - return NULL; -} - -char *rpmErrorString(void) -{ - return _rpmerrRec.string; -} - -rpmErrorCallBackType rpmErrorSetCallback(rpmErrorCallBackType cb) -{ - rpmErrorCallBackType ocb; - - ocb = errorCallback; - errorCallback = cb; - - return ocb; -} - -void rpmError(rpmerrCode code, const char *format, ...) -{ - va_list args; - - va_start(args, format); - - _rpmerrRec.code = code; - vsprintf(_rpmerrRec.string, format, args); - - if (errorCallback) { - errorCallback(); - } else { - fputs(_rpmerrRec.string, stderr); - fputs("\n", stderr); - } -} diff --git a/rpmio/rpmerr.h b/rpmio/rpmerr.h index c3867e3e0..17b554731 100644 --- a/rpmio/rpmerr.h +++ b/rpmio/rpmerr.h @@ -3,118 +3,81 @@ /** \ingroup rpmio * \file rpmio/rpmerr.h + * @todo Eliminate from API. */ +#include "rpmlog.h" + +#define _em(_e) \ + (0x80000000 | ((_e) << 16) | RPMLOG_MAKEPRI(RPMLOG_ERRMSG, RPMLOG_ERR)) + /** * Tokens used by rpmError(). */ typedef enum rpmerrCode_e { - RPMERR_GDBMOPEN = -2, /*!< gdbm open failed */ - RPMERR_GDBMREAD = -3, /*!< gdbm read failed */ - RPMERR_GDBMWRITE = -4, /*!< gdbm write failed */ - RPMERR_INTERNAL = -5, /*!< internal RPM error */ - RPMERR_DBCORRUPT = -6, /*!< rpm database is corrupt */ - RPMERR_OLDDBCORRUPT = -7, /*!< old style rpm database is corrupt */ - RPMERR_OLDDBMISSING = -8, /*!< old style rpm database is missing */ - RPMERR_NOCREATEDB = -9, /*!< cannot create new database */ - RPMERR_DBOPEN = -10, /*!< database open failed */ - RPMERR_DBGETINDEX = -11, /*!< database get from index failed */ - RPMERR_DBPUTINDEX = -12, /*!< database get from index failed */ - RPMERR_NEWPACKAGE = -13, /*!< package is too new to handle */ - RPMERR_BADMAGIC = -14, /*!< bad magic for an RPM */ - RPMERR_RENAME = -15, /*!< rename(2) failed */ - RPMERR_UNLINK = -16, /*!< unlink(2) failed */ - RPMERR_RMDIR = -17, /*!< rmdir(2) failed */ - RPMERR_PKGINSTALLED = -18, /*!< package already installed */ - RPMERR_CHOWN = -19, /*!< chown() call failed */ - RPMERR_NOUSER = -20, /*!< user does not exist */ - RPMERR_NOGROUP = -21, /*!< group does not exist */ - RPMERR_MKDIR = -22, /*!< mkdir() call failed */ - RPMERR_FILECONFLICT = -23, /*!< file being installed exists */ - RPMERR_RPMRC = -24, /*!< bad line in rpmrc */ - RPMERR_NOSPEC = -25, /*!< .spec file is missing */ - RPMERR_NOTSRPM = -26, /*!< a source rpm was expected */ - RPMERR_FLOCK = -27, /*!< locking the database failed */ - RPMERR_OLDPACKAGE = -28, /*!< trying upgrading to old version */ -/* RPMERR_BADARCH = -29, bad architecture or arch mismatch */ - RPMERR_CREATE = -30, /*!< failed to create a file */ - RPMERR_NOSPACE = -31, /*!< out of disk space */ - RPMERR_NORELOCATE = -32, /*!< tried to do improper relocatation */ -/* RPMERR_BADOS = -33, bad architecture or arch mismatch */ - RPMMESS_BACKUP = -34, /*!< backup made during [un]install */ - RPMERR_MTAB = -35, /*!< failed to read mount table */ - RPMERR_STAT = -36, /*!< failed to stat something */ - RPMERR_BADDEV = -37, /*!< file on device not listed in mtab */ - RPMMESS_ALTNAME = -38, /*!< file written as .rpmnew */ - RPMMESS_PREREQLOOP = -39, /*!< loop in prerequisites */ - RPMERR_BADRELOCATE = -40, /*!< bad relocation was specified */ - RPMERR_OLDDB = -41, /*!< old format database */ + RPMERR_GDBMOPEN = _em(2), /*!< gdbm open failed */ + RPMERR_GDBMREAD = _em(3), /*!< gdbm read failed */ + RPMERR_GDBMWRITE = _em(4), /*!< gdbm write failed */ + RPMERR_INTERNAL = _em(5), /*!< internal RPM error */ + RPMERR_DBCORRUPT = _em(6), /*!< rpm database is corrupt */ + RPMERR_OLDDBCORRUPT = _em(7), /*!< old style rpm database is corrupt */ + RPMERR_OLDDBMISSING = _em(8), /*!< old style rpm database is missing */ + RPMERR_NOCREATEDB = _em(9), /*!< cannot create new database */ + RPMERR_DBOPEN = _em(10), /*!< database open failed */ + RPMERR_DBGETINDEX = _em(11), /*!< database get from index failed */ + RPMERR_DBPUTINDEX = _em(12), /*!< database get from index failed */ + RPMERR_NEWPACKAGE = _em(13), /*!< package is too new to handle */ + RPMERR_BADMAGIC = _em(14), /*!< bad magic for an RPM */ + RPMERR_RENAME = _em(15), /*!< rename(2) failed */ + RPMERR_UNLINK = _em(16), /*!< unlink(2) failed */ + RPMERR_RMDIR = _em(17), /*!< rmdir(2) failed */ + RPMERR_PKGINSTALLED = _em(18), /*!< package already installed */ + RPMERR_CHOWN = _em(19), /*!< chown() call failed */ + RPMERR_NOUSER = _em(20), /*!< user does not exist */ + RPMERR_NOGROUP = _em(21), /*!< group does not exist */ + RPMERR_MKDIR = _em(22), /*!< mkdir() call failed */ + RPMERR_FILECONFLICT = _em(23), /*!< file being installed exists */ + RPMERR_RPMRC = _em(24), /*!< bad line in rpmrc */ + RPMERR_NOSPEC = _em(25), /*!< .spec file is missing */ + RPMERR_NOTSRPM = _em(26), /*!< a source rpm was expected */ + RPMERR_FLOCK = _em(27), /*!< locking the database failed */ + RPMERR_OLDPACKAGE = _em(28), /*!< trying upgrading to old version */ +/* RPMERR_BADARCH = _em(29), bad architecture or arch mismatch */ + RPMERR_CREATE = _em(30), /*!< failed to create a file */ + RPMERR_NOSPACE = _em(31), /*!< out of disk space */ + RPMERR_NORELOCATE = _em(32), /*!< tried to do improper relocatation */ +/* RPMERR_BADOS = _em(33), bad architecture or arch mismatch */ + RPMMESS_BACKUP = _em(34), /*!< backup made during [un]install */ + RPMERR_MTAB = _em(35), /*!< failed to read mount table */ + RPMERR_STAT = _em(36), /*!< failed to stat something */ + RPMERR_BADDEV = _em(37), /*!< file on device not listed in mtab */ + RPMMESS_ALTNAME = _em(38), /*!< file written as .rpmnew */ + RPMMESS_PREREQLOOP = _em(39), /*!< loop in prerequisites */ + RPMERR_BADRELOCATE = _em(40), /*!< bad relocation was specified */ + RPMERR_OLDDB = _em(41), /*!< old format database */ /* spec.c build.c pack.c */ - RPMERR_UNMATCHEDIF = -107, /*!< unclosed %ifarch or %ifos */ - RPMERR_BADARG = -109, /*!< @todo Document. */ - RPMERR_SCRIPT = -110, /*!< errors related to script exec */ - RPMERR_READERROR = -111, /*!< @todo Document. */ - RPMERR_UNKNOWNOS = -112, /*!< @todo Document. */ - RPMERR_UNKNOWNARCH = -113, /*!< @todo Document. */ - RPMERR_EXEC = -114, /*!< @todo Document. */ - RPMERR_FORK = -115, /*!< @todo Document. */ - RPMERR_CPIO = -116, /*!< @todo Document. */ - RPMERR_GZIP = -117, /*!< @todo Document. */ - RPMERR_BADSPEC = -118, /*!< @todo Document. */ - RPMERR_LDD = -119, /*!< couldn't understand ldd output */ - RPMERR_BADFILENAME = -120, /*!< @todo Document. */ + RPMERR_UNMATCHEDIF = _em(107), /*!< unclosed %ifarch or %ifos */ + RPMERR_BADARG = _em(109), /*!< @todo Document. */ + RPMERR_SCRIPT = _em(110), /*!< errors related to script exec */ + RPMERR_READERROR = _em(111), /*!< @todo Document. */ + RPMERR_UNKNOWNOS = _em(112), /*!< @todo Document. */ + RPMERR_UNKNOWNARCH = _em(113), /*!< @todo Document. */ + RPMERR_EXEC = _em(114), /*!< @todo Document. */ + RPMERR_FORK = _em(115), /*!< @todo Document. */ + RPMERR_CPIO = _em(116), /*!< @todo Document. */ + RPMERR_GZIP = _em(117), /*!< @todo Document. */ + RPMERR_BADSPEC = _em(118), /*!< @todo Document. */ + RPMERR_LDD = _em(119), /*!< couldn't understand ldd output */ + RPMERR_BADFILENAME = _em(120), /*!< @todo Document. */ - RPMERR_BADSIGTYPE = -200, /*!< Unknown signature type */ - RPMERR_SIGGEN = -201 /*!< Error generating signature */ + RPMERR_BADSIGTYPE = _em(200), /*!< Unknown signature type */ + RPMERR_SIGGEN = _em(201) /*!< Error generating signature */ } rpmerrCode; -#ifdef __cplusplus -extern "C" { -#endif - -/** - */ -typedef void (*rpmErrorCallBackType)(void); - -/** - */ -#if defined(__GNUC__) -void rpmError(rpmerrCode code, const char * format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); -#else -void rpmError(rpmerrCode code, const char * format, ...); -#endif - -/** - * @todo Implement or eliminate. - * @return NULL always - */ -/*@observer@*/ /*@null@*/ const char * rpmErrorCodeString( /*@unused@*/ rpmerrCode code); - -/** - * @todo Implement or eliminate. - */ -typedef /*@abstract@*/ struct rpmerrRec_s { - rpmerrCode code; - char string[1024]; -} * rpmerrRec; - /** - * @return error record code + * Retrofit rpmError() onto rpmlog sub-system. */ -rpmerrCode rpmErrorCode(void); - -/** - * @return error record string - */ -char * rpmErrorString(void); - -/** - */ -rpmErrorCallBackType rpmErrorSetCallback(rpmErrorCallBackType); - -#ifdef __cplusplus -} -#endif +#define rpmError rpmlog #endif /* H_RPMERR */ diff --git a/rpmio/rpmmessages.h b/rpmio/rpmmessages.h index d2eaeef89..2830c5d34 100644 --- a/rpmio/rpmmessages.h +++ b/rpmio/rpmmessages.h @@ -3,20 +3,36 @@ /** \ingroup rpmio * \file rpmio/rpmmessages.h + * @todo Eliminate from API. */ +#include "rpmlog.h" + +#define RPMMESS_DEBUG RPMLOG_DEBUG +#define RPMMESS_VERBOSE RPMLOG_INFO +#define RPMMESS_NORMAL RPMLOG_NOTICE +#define RPMMESS_WARNING RPMLOG_WARNING +#define RPMMESS_ERROR RPMLOG_ERR +#define RPMMESS_FATALERROR RPMLOG_CRIT + +#define RPMMESS_QUIET RPMMESS_WARNING + +#define rpmMessage rpmlog +#define rpmSetVerbosity(_lvl) \ + ((void)rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(_lvl)))) +#define rpmIncreaseVerbosity() \ + ((void)rpmlogSetMask((((rpmlogSetMask(0) & 0xff) << 1) | 1))) +#define rpmDecreaseVerbosity() \ + ((void)rpmlogSetMask(((rpmlogSetMask(0) & 0xff) >> 1))) +#define rpmIsNormal() \ + (rpmlogSetMask(0) & RPMLOG_MASK( RPMMESS_NORMAL )) +#define rpmIsVerbose() \ + (rpmlogSetMask(0) & RPMLOG_MASK( RPMMESS_VERBOSE )) +#define rpmIsDebug() \ + (rpmlogSetMask(0) & RPMLOG_MASK( RPMMESS_DEBUG )) + /** */ -typedef enum rpmmsgLevel_e { - RPMMESS_DEBUG = 1, /*!< */ - RPMMESS_VERBOSE = 2, /*!< */ - RPMMESS_NORMAL = 3, /*!< */ - RPMMESS_WARNING = 4, /*!< */ - RPMMESS_ERROR = 5, /*!< */ - RPMMESS_FATALERROR = 6 /*!< */ -} rpmmsgLevel; -#define RPMMESS_QUIET (RPMMESS_NORMAL + 1) - typedef enum rpmCallbackType_e { RPMCALLBACK_INST_PROGRESS, RPMCALLBACK_INST_START, @@ -30,14 +46,14 @@ typedef enum rpmCallbackType_e { RPMCALLBACK_UNINST_STOP } rpmCallbackType; -#ifdef __cplusplus -extern "C" { -#endif - /** */ typedef void * rpmCallbackData; +#ifdef __cplusplus +extern "C" { +#endif + /** */ typedef void * (*rpmCallbackFunction)(const void * h, @@ -52,35 +68,6 @@ typedef void * (*rpmCallbackFunction)(const void * h, void urlSetCallback(rpmCallbackFunction notify, rpmCallbackData notifyData, int notifyCount); -/** - */ -void rpmIncreaseVerbosity(void); - -/** - */ -void rpmSetVerbosity(int level); - -/** - */ -int rpmGetVerbosity(void); - -/** - */ -int rpmIsVerbose(void); - -/** - */ -int rpmIsDebug(void); - -/** - */ -#if defined(__GNUC__) -void rpmMessage(rpmmsgLevel level, const char * format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); -#else -void rpmMessage(rpmmsgLevel level, const char * format, ...); -#endif - - #ifdef __cplusplus } #endif |