include/erroutines.h

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. EXTINI
  2. EXTINI
  3. DEFFAC
  4. ERDUP
  5. ER_dbg_eq
  6. ERR

   1 /***************************************
   2   $Revision: 1.19 $
   3 
   4   Error reporting (er) erroutines.h  - header file for error reporting.
   5 
   6   Status: NOT REVUED, TESTED, 
   7 
   8   Design and implementation by: Marek Bukowy
   9 
  10   ******************/ /******************
  11   Copyright (c) 1999                              RIPE NCC
  12  
  13   All Rights Reserved
  14   
  15   Permission to use, copy, modify, and distribute this software and its
  16   documentation for any purpose and without fee is hereby granted,
  17   provided that the above copyright notice appear in all copies and that
  18   both that copyright notice and this permission notice appear in
  19   supporting documentation, and that the name of the author not be
  20   used in advertising or publicity pertaining to distribution of the
  21   software without specific, written prior permission.
  22   
  23   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  24   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  25   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  26   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  27   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  28   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  29   ***************************************/
  30 
  31 #ifndef ER_H
  32 #define ER_H
  33 
  34 
  35 typedef unsigned int er_mask_t;
  36 typedef int er_ret_t;
  37 
  38 #include <stdio.h>
  39 #include <unistd.h>
  40 #include <stdlib.h>
  41 #include <assert.h>
  42 #include <time.h>
  43 #include <stdarg.h>
  44 #include <strings.h>
  45 
  46 #include <glib.h>
  47 #include <pthread.h>
  48 
  49 #include <bitmask.h>
  50 #include <stubs.h>
  51 
  52 #include "thread.h"
  53 
  54 #ifdef HAVE_PTHREAD_H
  55 #include <pthread.h>
  56 #endif
  57 
  58 #ifdef ER_IMPL
  59 #define EXTDEF
  60 #define EXTINI(a,b) a = b;
     /* [<][>][^][v][top][bottom][index][help] */
  61 #else
  62 #define EXTDEF extern 
  63 #define EXTINI(a,b) extern a;
     /* [<][>][^][v][top][bottom][index][help] */
  64 #endif
  65 
  66 #ifdef __cplusplus
  67 extern "C" {
  68 #endif
  69 
  70 typedef enum {
  71   ER_PATH_SOCK,   /* unbuffered file/socket access via a file descriptor */
  72   ER_PATH_BUFPTR,   /* buffered   file access via a FILE structure  */
  73   ER_PATH_NAME,     /* buffered   file access via a file name 
  74                        (file reopened for every message) */
  75   ER_PATH_EXEC,     /* message constructed, send to stdin of the command
  76                        at the end or after one message depending on options */
  77   ER_PATH_SYSLOG,   /* syslog msg sent at every message */
  78   ER_PATH_CIRC
  79 } er_path_mt;
  80 
  81 EXTDEF char *er_pathtypes[]
  82 #ifdef ER_IMPL
  83   = {
  84   "SOCK",           /* MUST BE IN SYNC WITH THE ABOVE */
  85   "BUFPTR",
  86   "NAME",
  87   "EXEC",
  88   "SYSLOG",
  89   "CIRC",
  90   NULL
  91   }
  92 #endif
  93 ;
  94 
  95 typedef union {
  96     struct {
  97       int    fd;                /* int filedescr */
  98     } sock;
  99     struct {
 100       FILE  *fp;                /* FILE* fp for FILEBUFPTR */
 101     } bufptr;
 102     struct {
 103       char  filename[80];       /* filename for FILEBUFNAM */
 104       int   date;               /* 'DATE' option - construct a filename */
 105     } name;
 106     struct {
 107       int usepath;
 108       char **argv;              /* parameters for exec - XXX DYNAMIC!!!! */
 109     } exec;
 110     struct {
 111       int facility;             /* openlog(3) parameters for SYSLOG */
 112       int logopt;
 113       char ident[32];
 114     } syslog;
 115 } er_path_descr_t;
 116 
 117 typedef struct {
 118   char              name[32];
 119   char              active;
 120   int               format;
 121   pthread_mutex_t   mutex;
 122   er_path_mt        type;  
 123   er_path_descr_t   descr;
 124   GList            *filters;
 125 } er_path_t;
 126 
 127 typedef struct {
 128   mask_t fac_mask;
 129   er_mask_t asp_mask;
 130   int    sev_min;
 131   int    sev_max;
 132   pthread_t thr_id;
 133 /*  unsigned err;     -- a specific error code - or 0 to mean all errors */
 134 } er_filter_t;
 135 
 136 typedef struct {
 137   char errtxt[1024];
 138   int  errpos;
 139   char *token;
 140   er_path_t path;
 141   er_filter_t curfilt;
 142   int sock;
 143 } lexerr_t;
 144 
 145 
 146 
 147 #define MNELEN 16
 148 typedef struct {
 149    er_ret_t     code;
 150    char         mnem[MNELEN];
 151    char         text[80];
 152 } er_list_t;
 153 
 154 
 155 typedef struct {
 156    er_ret_t     code;
 157    char         name[4];
 158    char         desc[80];
 159    er_list_t   *errs;
 160 } er_fac_t;
 161 
 162 
 163 #define ER_SEV_F 0x20000000     /*+ fatal error +*/
 164 #define ER_SEV_E 0x10000000     /*+ error +*/
 165 #define ER_SEV_W 0x08000000     /*+ warning +*/
 166 #define ER_SEV_I 0x04000000     /*+ information +*/
 167 #define ER_SEV_D 0x02000000     /*+ debug message +*/
 168 #define ER_SEV_L 0x01000000     /*+ library error +*/
 169 
 170 
 171 /*  macro to see if the code is OK -- masks out the facility and compares,
 172     assuming all OK codes within the facilities are 0
 173 */
 174 
 175 
 176 
 177 #define ER_SEV_TXT 20
 178 
 179 #define ER_MSGLEN 384
 180 #define ER_ERRLEN 2048
 181 
 182 typedef struct {
 183     int         sev;
 184     char        chr[2];
 185     char        txt[ER_SEV_TXT];
 186 } er_level_t;
 187 
 188 #define DEFFAC(a,b) { FAC_##a, #a, b, a##_mod_err }
     /* [<][>][^][v][top][bottom][index][help] */
 189 #define ER_LASTTXT {-1} /* macro for use in error text arrays */
 190 #define ERDUP(a) a, #a      
     /* [<][>][^][v][top][bottom][index][help] */
 191 #include "er_facilities.h"
 192 /* the macro expects two arguments:
 193          capital letters symbol of the facility
 194          short (<80 chars) description
 195    which then are expanded, eg. DEFFAC(TT, "test facility") expands to:
 196   { FAC_TT , "TT",   "test facility" ,  NULL} ,
 197   Therefore, the FAC_TT must be defined in the enum below.
 198   The  er_fac_code_t enum   must begin with FAC_NONE=0 
 199                         and must end   with FAC_LAST.
 200   The  er_fac_err array    must end   with FAC_NONE.
 201 
 202   The user code must contain INITFAC(a) call early in the code that
 203   sets the pointer to the respective ??_mod_err array. There is nothing
 204   wrong in calling it twice, so don't hesitate if you must do it.
 205  
 206   After a facility number changes (eg. because another one was added or
 207   deleted before yours) ALL your code must be recompiled before linking. 
 208 */
 209 
 210 
 211 #include "er_aspects.h"
 212 #include "er_formats.h"
 213 
 214 #ifndef ER_IMPL /* for client modules */
 215 extern er_level_t er_level_a[];
 216 #else /* full definition */
 217 er_level_t er_level_a[] = {
 218   { ER_SEV_F,   "F" , "fatal error" },
 219   { ER_SEV_E,   "E" , "error" },
 220   { ER_SEV_W,   "W" , "warning" },
 221   { ER_SEV_I,   "I" , "information" },
 222   { ER_SEV_D,   "D" , "debug msg" },
 223   { ER_SEV_L,   "L" , "library err" },
 224   { 0,          "-" , "BUG! no such sev 0" }
 225 };
 226 #endif /* ER_IMPL */
 227 
 228 
 229 /*************************************************************************/
 230 
 231 EXTINI(GList  *er_pathlist , NULL)
 232 EXTDEF er_mask_t        er_asparray[FAC_LAST];
 233 EXTDEF rw_lock_t   er_paths_lock;
 234 EXTINI(GHashTable *er_macro_hash, NULL)
 235 
 236 #ifdef ER_IMPL
 237 
 238 /* global vars !!!!! must be set for reporting purposes. 
 239    Must be initialised in main() by ER_init().
 240 */
 241 char er_progname[32];
 242 char er_pid[16];
 243 
 244 /* those are private variables */
 245 pthread_mutex_t  er_pathlist_mutex = PTHREAD_MUTEX_INITIALIZER;
 246 #endif
 247 
 248 
 249 
 250 
 251 void ER_init(char *progname, int processdefs);
 252 
 253 #define ER_dbg_eq(mod, asp, typ, expr)  \
     /* [<][>][^][v][top][bottom][index][help] */
 254                 ER_dbg_va (mod, asp, #expr " = " typ, expr)
 255 
 256 void ER_perror(er_fac_code_t facwhere, int errcode, char *format,...)
 257 #ifdef __GNUC__  /* let gcc check the format string for problems */
 258      __attribute__ ((format (printf, 3, 4)))
 259 #endif
 260 ;
 261 void ER_dbg_va(er_fac_code_t facwhere, er_mask_t asp, char *txt, ...);
 262 void ER_inf_va(er_fac_code_t facwhere, er_mask_t asp, char *txt, ...);
 263 int ER_anybody_wants(er_fac_code_t facwhere, int errcode, er_mask_t asp );
 264 int ER_is_traced(er_fac_code_t facwhere, er_mask_t asp);
 265 
 266 void ER_setpath(er_path_t *newset);
 267 
 268 int NOERR(er_ret_t a);
 269 #define ERR(a) (!NOERR(a))
     /* [<][>][^][v][top][bottom][index][help] */
 270 
 271 char *er_getsevsym( int sev, int mode );
 272 char *er_getfacsym(er_fac_code_t faccode);
 273 er_mask_t er_getfacval(char *key);
 274 unsigned int er_getaspval(char *key);
 275 er_path_mt er_getpathval(char *key);
 276 
 277 er_ret_t er_add_filter( er_path_t *pathptr, er_filter_t *filter );
 278 er_ret_t er_add_path(  er_path_t *pathptr, char *key );
 279 
 280 #ifdef __cplusplus
 281 }
 282 #endif
 283 
 284 #undef EXTDEF
 285 #undef EXTINI
 286 #endif /* ER_H */

/* [<][>][^][v][top][bottom][index][help] */