rpm  5.2.1
rpmlog.h
Go to the documentation of this file.
1 #ifndef H_RPMLOG
2 #define H_RPMLOG 1
3 
9 #include <stdarg.h>
10 
21 /*@-typeuse@*/
22 typedef enum rpmlogLvl_e {
26  RPMLOG_ERR = 3,
31 } rpmlogLvl;
32 /*@=typeuse@*/
33 
34 #define RPMLOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
35  /* extract priority */
36 #define RPMLOG_PRI(p) ((p) & RPMLOG_PRIMASK)
37 #define RPMLOG_MAKEPRI(fac, pri) ((((unsigned)(fac)) << 3) | (pri))
38 
39 #ifdef RPMLOG_NAMES
40 #define _RPMLOG_NOPRI 0x10 /* the "no priority" priority */
41  /* mark "facility" */
42 #define _RPMLOG_MARK RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
43 typedef struct _rpmcode {
44  const char *c_name;
45  int c_val;
46 } RPMCODE;
47 
48 RPMCODE rpmprioritynames[] =
49  {
50  { "alert", RPMLOG_ALERT },
51  { "crit", RPMLOG_CRIT },
52  { "debug", RPMLOG_DEBUG },
53  { "emerg", RPMLOG_EMERG },
54  { "err", RPMLOG_ERR },
55  { "error", RPMLOG_ERR }, /* DEPRECATED */
56  { "info", RPMLOG_INFO },
57  { "none", _RPMLOG_NOPRI }, /* INTERNAL */
58  { "notice", RPMLOG_NOTICE },
59  { "panic", RPMLOG_EMERG }, /* DEPRECATED */
60  { "warn", RPMLOG_WARNING }, /* DEPRECATED */
61  { "warning",RPMLOG_WARNING },
62  { NULL, -1 }
63  };
64 #endif
65 
69 /*@-enummemuse -typeuse@*/
70 typedef enum rpmlogFac_e {
71  RPMLOG_KERN = (0<<3),
72  RPMLOG_USER = (1<<3),
73  RPMLOG_MAIL = (2<<3),
74  RPMLOG_DAEMON = (3<<3),
75  RPMLOG_AUTH = (4<<3),
76  RPMLOG_SYSLOG = (5<<3),
77  RPMLOG_LPR = (6<<3),
78  RPMLOG_NEWS = (7<<3),
79  RPMLOG_UUCP = (8<<3),
80  RPMLOG_CRON = (9<<3),
81  RPMLOG_AUTHPRIV = (10<<3),
82  RPMLOG_FTP = (11<<3),
84  /* other codes through 15 reserved for system use */
85  RPMLOG_LOCAL0 = (16<<3),
86  RPMLOG_LOCAL1 = (17<<3),
87  RPMLOG_LOCAL2 = (18<<3),
88  RPMLOG_LOCAL3 = (19<<3),
89  RPMLOG_LOCAL4 = (20<<3),
90  RPMLOG_LOCAL5 = (21<<3),
91  RPMLOG_LOCAL6 = (22<<3),
92  RPMLOG_LOCAL7 = (23<<3),
94 #define RPMLOG_NFACILITIES 24
95  RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
96 } rpmlogFac;
97 /*@=enummemuse =typeuse@*/
98 
99 #define RPMLOG_FACMASK 0x03f8
100 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
101 
102 
103 #ifdef RPMLOG_NAMES
104 RPMCODE facilitynames[] =
105  {
106  { "auth", RPMLOG_AUTH },
107  { "authpriv",RPMLOG_AUTHPRIV },
108  { "cron", RPMLOG_CRON },
109  { "daemon", RPMLOG_DAEMON },
110  { "ftp", RPMLOG_FTP },
111  { "kern", RPMLOG_KERN },
112  { "lpr", RPMLOG_LPR },
113  { "mail", RPMLOG_MAIL },
114  { "mark", _RPMLOG_MARK }, /* INTERNAL */
115  { "news", RPMLOG_NEWS },
116  { "security",RPMLOG_AUTH }, /* DEPRECATED */
117  { "syslog", RPMLOG_SYSLOG },
118  { "user", RPMLOG_USER },
119  { "uucp", RPMLOG_UUCP },
120  { "local0", RPMLOG_LOCAL0 },
121  { "local1", RPMLOG_LOCAL1 },
122  { "local2", RPMLOG_LOCAL2 },
123  { "local3", RPMLOG_LOCAL3 },
124  { "local4", RPMLOG_LOCAL4 },
125  { "local5", RPMLOG_LOCAL5 },
126  { "local6", RPMLOG_LOCAL6 },
127  { "local7", RPMLOG_LOCAL7 },
128  { NULL, -1 }
129  };
130 #endif
131 
132 /*
133  * arguments to setlogmask.
134  */
135 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))
136 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)
138 /*
139  * Option flags for openlog.
140  *
141  * RPMLOG_ODELAY no longer does anything.
142  * RPMLOG_NDELAY is the inverse of what it used to be.
143  */
144 #define RPMLOG_PID 0x01
145 #define RPMLOG_CONS 0x02
146 #define RPMLOG_ODELAY 0x04
147 #define RPMLOG_NDELAY 0x08
148 #define RPMLOG_NOWAIT 0x10
149 #define RPMLOG_PERROR 0x20
153 typedef /*@abstract@*/ struct rpmlogRec_s * rpmlogRec;
154 
157 typedef /*@abstract@*/ void * rpmlogCallbackData;
158 
167 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data)
168  /*@*/;
169 
173 #define RPMLOG_DEFAULT 0x01
174 #define RPMLOG_EXIT 0x02
176 #if defined(_RPMLOG_INTERNAL)
177 
179 struct rpmlogRec_s {
180  int code;
181  rpmlogLvl pri; /* priority */
182 /*@owned@*/ /*@relnull@*/
183  const char * message;
184 };
185 #endif
186 
187 #ifdef __cplusplus
188 extern "C" {
189 #endif
190 
196 /*@observer@*/
197 const char * rpmlogLevelPrefix(rpmlogLvl pri)
198  /*@*/;
199 
206 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data)
207  /*@globals internalState@*/
208  /*@modifies internalState @*/;
209 
216 void rpmlogGetCallback(rpmlogCallback *cb, rpmlogCallbackData *data)
217  /*@globals internalState @*/
218  /*@modifies *cb, *data, internalState @*/;
219 
224 int rpmlogGetNrecs(void)
225  /*@*/;
226 
232 /*@observer@*/ /*@retexpose@*/
233 const char * rpmlogRecMessage(rpmlogRec rec)
234  /*@*/;
235 
242  /*@*/;
243 
248 void rpmlogPrint(/*@null@*/ FILE *f)
249  /*@modifies *f @*/;
250 
255 /*@unused@*/
256 void rpmlogClose (void)
257  /*@globals internalState@*/
258  /*@modifies internalState @*/;
259 
264 /*@unused@*/
265 void rpmlogOpen (const char * ident, int option, int facility)
266  /*@globals internalState@*/
267  /*@modifies internalState @*/;
268 
274 int rpmlogSetMask (int mask)
275  /*@globals internalState@*/
276  /*@modifies internalState @*/;
277 
282 /*@mayexit@*/ /*@printflike@*/
283 void _rpmlog (int code, const char *fmt, ...)
284 #if defined(__GNUC__) && __GNUC__ >= 2
285  /* issue a warning if the format string doesn't match arguments */
286  __attribute__((format (printf, 2, 3)))
287 #endif
288  /*@*/;
289 
293 void vrpmlog (unsigned code, const char * fmt, va_list ap)
294  /*@*/;
295 
296 /*@mayexit@*/ /*@printflike@*/
297 static inline
298 void rpmlog (int code, const char *fmt, ...)
299  /*@*/
300 {
301  unsigned pri = RPMLOG_PRI(code);
302  unsigned mask = RPMLOG_MASK(pri);
303 
304  if (mask & rpmlogSetMask(0)) {
305  va_list ap;
306  va_start(ap, fmt);
307  vrpmlog(code, fmt, ap);
308  va_end(ap);
309  }
310 }
311 
312 /*@-exportlocal@*/
317 /*@-redecl@*/
318 /*@observer@*/ /*@null@*/ const char * rpmlogMessage(void)
319  /*@*/;
320 /*@=redecl@*/
321 
329 int rpmlogCode(void)
330  /*@*/;
331 
337 /*@null@*/
338 FILE * rpmlogSetFile(/*@null@*/ FILE * fp)
339  /*@globals internalState@*/
340  /*@modifies internalState @*/;
341 /*@=exportlocal@*/
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 
347 #endif /* H_RPMLOG */