Doxygen annotations for config files.
[tools/librpm-tizen.git] / rpmio / rpmlog.h
1 #ifndef H_RPMLOG
2 #define H_RPMLOG 1
3
4 /** \ingroup rpmio
5  * \file rpmio/rpmlog.h
6  * Yet Another syslog(3) API clone.
7  * Used to unify rpmError() and rpmMessage() interfaces in rpm.
8  */
9
10 #include <stdarg.h>
11
12 /**
13  * RPM Log levels.
14  * priorities/facilities are encoded into a single 32-bit quantity, where the
15  * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
16  * (0-big number).  Both the priorities and the facilities map roughly
17  * one-to-one to strings in the syslogd(8) source code.  This mapping is
18  * included in this file.
19  *
20  * priorities (these are ordered)
21  */
22 typedef enum rpmlogLvl_e {
23     RPMLOG_EMERG        = 0,    /*!< system is unusable */
24     RPMLOG_ALERT        = 1,    /*!< action must be taken immediately */
25     RPMLOG_CRIT         = 2,    /*!< critical conditions */
26     RPMLOG_ERR          = 3,    /*!< error conditions */
27     RPMLOG_WARNING      = 4,    /*!< warning conditions */
28     RPMLOG_NOTICE       = 5,    /*!< normal but significant condition */
29     RPMLOG_INFO         = 6,    /*!< informational */
30     RPMLOG_DEBUG        = 7     /*!< debug-level messages */
31 } rpmlogLvl;
32
33 #define RPMLOG_PRIMASK  0x07    /* mask to extract priority part (internal) */
34                                 /* extract priority */
35 #define RPMLOG_PRI(p)   ((p) & RPMLOG_PRIMASK)
36 #define RPMLOG_MAKEPRI(fac, pri)        ((((unsigned)(fac)) << 3) | (pri))
37
38 #ifdef RPMLOG_NAMES
39 #define _RPMLOG_NOPRI   0x10    /* the "no priority" priority */
40                                 /* mark "facility" */
41 #define _RPMLOG_MARK    RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
42 typedef struct _rpmcode {
43         const char      *c_name;
44         int             c_val;
45 } RPMCODE;
46
47 RPMCODE rpmprioritynames[] =
48   {
49     { "alert",  RPMLOG_ALERT },
50     { "crit",   RPMLOG_CRIT },
51     { "debug",  RPMLOG_DEBUG },
52     { "emerg",  RPMLOG_EMERG },
53     { "err",    RPMLOG_ERR },
54     { "error",  RPMLOG_ERR },           /* DEPRECATED */
55     { "info",   RPMLOG_INFO },
56     { "none",   _RPMLOG_NOPRI },        /* INTERNAL */
57     { "notice", RPMLOG_NOTICE },
58     { "panic",  RPMLOG_EMERG },         /* DEPRECATED */
59     { "warn",   RPMLOG_WARNING },       /* DEPRECATED */
60     { "warning",RPMLOG_WARNING },
61     { NULL, -1 }
62   };
63 #endif
64
65 /**
66  * facility codes
67  */
68 typedef enum rpmlogFac_e {
69     RPMLOG_KERN         = (0<<3),       /*!< kernel messages */
70     RPMLOG_USER         = (1<<3),       /*!< random user-level messages */
71     RPMLOG_MAIL         = (2<<3),       /*!< mail system */
72     RPMLOG_DAEMON       = (3<<3),       /*!< system daemons */
73     RPMLOG_AUTH         = (4<<3),       /*!< security/authorization messages */
74     RPMLOG_SYSLOG       = (5<<3),       /*!< messages generated internally by syslogd */
75     RPMLOG_LPR          = (6<<3),       /*!< line printer subsystem */
76     RPMLOG_NEWS         = (7<<3),       /*!< network news subsystem */
77     RPMLOG_UUCP         = (8<<3),       /*!< UUCP subsystem */
78     RPMLOG_CRON         = (9<<3),       /*!< clock daemon */
79     RPMLOG_AUTHPRIV     = (10<<3),      /*!< security/authorization messages (private) */
80     RPMLOG_FTP          = (11<<3),      /*!< ftp daemon */
81
82         /* other codes through 15 reserved for system use */
83     RPMLOG_LOCAL0       = (16<<3),      /*!< reserved for local use */
84     RPMLOG_LOCAL1       = (17<<3),      /*!< reserved for local use */
85     RPMLOG_LOCAL2       = (18<<3),      /*!< reserved for local use */
86     RPMLOG_LOCAL3       = (19<<3),      /*!< reserved for local use */
87     RPMLOG_LOCAL4       = (20<<3),      /*!< reserved for local use */
88     RPMLOG_LOCAL5       = (21<<3),      /*!< reserved for local use */
89     RPMLOG_LOCAL6       = (22<<3),      /*!< reserved for local use */
90     RPMLOG_LOCAL7       = (23<<3),      /*!< reserved for local use */
91
92 #define RPMLOG_NFACILITIES 24   /*!< current number of facilities */
93     RPMLOG_ERRMSG       = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
94 } rpmlogFac;
95
96 #define RPMLOG_FACMASK  0x03f8  /*!< mask to extract facility part */
97 #define RPMLOG_FAC(p)   (((p) & RPMLOG_FACMASK) >> 3)
98
99
100 #ifdef RPMLOG_NAMES
101 CODE facilitynames[] =
102   {
103     { "auth",   RPMLOG_AUTH },
104     { "authpriv",RPMLOG_AUTHPRIV },
105     { "cron",   RPMLOG_CRON },
106     { "daemon", RPMLOG_DAEMON },
107     { "ftp",    RPMLOG_FTP },
108     { "kern",   RPMLOG_KERN },
109     { "lpr",    RPMLOG_LPR },
110     { "mail",   RPMLOG_MAIL },
111     { "mark",   _RPMLOG_MARK },         /* INTERNAL */
112     { "news",   RPMLOG_NEWS },
113     { "security",RPMLOG_AUTH },         /* DEPRECATED */
114     { "syslog", RPMLOG_SYSLOG },
115     { "user",   RPMLOG_USER },
116     { "uucp",   RPMLOG_UUCP },
117     { "local0", RPMLOG_LOCAL0 },
118     { "local1", RPMLOG_LOCAL1 },
119     { "local2", RPMLOG_LOCAL2 },
120     { "local3", RPMLOG_LOCAL3 },
121     { "local4", RPMLOG_LOCAL4 },
122     { "local5", RPMLOG_LOCAL5 },
123     { "local6", RPMLOG_LOCAL6 },
124     { "local7", RPMLOG_LOCAL7 },
125     { NULL, -1 }
126   };
127 #endif
128
129 /*
130  * arguments to setlogmask.
131  */
132 #define RPMLOG_MASK(pri) (1 << (pri))           /*!< mask for one priority */
133 #define RPMLOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /*!< all priorities through pri */
134
135 /*
136  * Option flags for openlog.
137  *
138  * RPMLOG_ODELAY no longer does anything.
139  * RPMLOG_NDELAY is the inverse of what it used to be.
140  */
141 #define RPMLOG_PID      0x01    /*!< log the pid with each message */
142 #define RPMLOG_CONS     0x02    /*!< log on the console if errors in sending */
143 #define RPMLOG_ODELAY   0x04    /*!< delay open until first syslog() (default) */
144 #define RPMLOG_NDELAY   0x08    /*!< don't delay open */
145 #define RPMLOG_NOWAIT   0x10    /*!< don't wait for console forks: DEPRECATED */
146 #define RPMLOG_PERROR   0x20    /*!< log to stderr as well */
147
148 /**
149  * @todo Add argument(s), integrate with other types of callbacks.
150  */
151 typedef void (*rpmlogCallback) (void);
152
153 /**
154  */
155 typedef /*@abstract@*/ struct rpmlogRec_s {
156     int         code;
157     const char  * message;
158 } * rpmlogRec;
159
160 #ifdef __cplusplus
161 extern "C" {
162 #endif
163
164 /**
165  * Return number of rpmError() ressages.
166  * @return              number of messages
167  */
168 int rpmlogGetNrecs(void);
169
170 /**
171  * Return text of last rpmError() message.
172  * @return              text of last message
173  */
174 /*@observer@*/ const char * rpmlogMessage(void);
175
176 /**
177  * Return error code from last rpmError() message.
178  * @deprecated Perl-RPM needs, what's really needed is predictable, non-i18n
179  *      encumbered, error text that can be retrieved through rpmlogMessage()
180  *      and parsed IMHO.
181  * @return              code from last message
182  */
183 int rpmlogCode(void);
184
185 /**
186  * Print all rpmError() messages.
187  * @param f             file handle (NULL uses stderr)
188  */
189 void rpmlogPrint(FILE *f);
190
191 /**
192  * Close desriptor used to write to system logger.
193  * @todo Implement.
194  */
195 void rpmlogClose (void);
196
197 /**
198  * Open connection to system logger.
199  * @todo Implement.
200  */
201 void rpmlogOpen (const char *ident, int option, int facility);
202
203 /**
204  * Set the log mask level.
205  */
206 int rpmlogSetMask (int mask);
207
208 /**
209  * Generate a log message using FMT string and option arguments.
210  */
211 void rpmlog (int pri, const char *fmt, ...);
212
213 /**
214  * Set rpmlog callback function.
215  */
216 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb);
217
218 /**
219  * Set rpmlog callback function.
220  * @deprecated gnorpm needs, use rpmlogSetCallback() instead.
221  */
222 rpmlogCallback rpmErrorSetCallback(rpmlogCallback cb);
223
224 /**
225  * Return error code from last rpmError() message.
226  * @deprecated Perl-RPM needs, use rpmlogCode() instead.
227  * @return              code from last message
228  */
229 int rpmErrorCode(void);
230
231 /**
232  * Return text of last rpmError() message.
233  * @deprecated gnorpm needs, use rpmlogMessage() instead.
234  * @return              text of last message
235  */
236 /*@observer@*/ const char * rpmErrorString(void);
237
238 #ifdef __cplusplus
239 }
240 #endif
241
242 #endif /* H_RPMLOG */