Source File modules/er/er_print.c

    1    | /***************************************
    2    |   $Revision: 1.2 $
    3    |
    4    |   Error reporting (er) er_print.c - routines to print the currently registered
    5    |                                     paths and filters in a syntax compliant
    6    | 				    to the one of the interpreter.
    7    |
    8    |   Status: NOT REVUED, PARTLY TESTED
    9    |
    10   |   Design and implementation by: Marek Bukowy
    11   |
    12   |   ******************/ /******************
    13   |   Copyright (c) 1999,2000                             RIPE NCC
    14   |
    15   |   All Rights Reserved
    16   |
    17   |   Permission to use, copy, modify, and distribute this software and its
    18   |   documentation for any purpose and without fee is hereby granted,
    19   |   provided that the above copyright notice appear in all copies and that
    20   |   both that copyright notice and this permission notice appear in
    21   |   supporting documentation, and that the name of the author not be
    22   |   used in advertising or publicity pertaining to distribution of the
    23   |   software without specific, written prior permission.
    24   |
    25   |   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
    26   |   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
    27   |   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
    28   |   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
    29   |   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    30   |   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    31   |   ***************************************/
    32   |
    33   | #include "memwrap.h"
    34   | #include "erroutines.h"
    35   |
    36   | #include "er_paths.h"
    37   | #include "er_arrays.h"
    38   |
    39   | #include "sk.h"
    40   | /**************** PRINTING PATHS ********************************************/
    41   | static
    42   | void er_print_format(int format, GString *g_reply )
    43   | {
    44   |   int i;
    45   |
    46   |   for(i=0;  er_formarr[i].n != NULL; i++) {
    47   |     if( format & er_formarr[i].v ) {
    48   |       g_string_sprintfa(g_reply, "%s|",er_formarr[i].n);
    49   |     }
    50   |   }
    51   |   /* cut the last "|" */
    52   |   g_string_truncate(g_reply, (int) strlen(g_reply->str)-1);
    53   | }
    54   |
    55   |
    56   | static
    57   | void er_print_one_path_descr(er_path_t *pathptr, GString *g_reply )
    58   | {
    59   |   er_path_descr_t *d = &(pathptr->descr);
    60   |
    61   |   switch(pathptr->type) {
    62   |   case  ER_PATH_NAME:
    63   |     g_string_sprintfa(g_reply, "NAME %s%s", d->name.filename,
    64   | 		      d->name.date ? " DATE" : ""
    65   | 		      );
    66   |     break;
    67   |   case  ER_PATH_SOCK:
    68   |     g_string_sprintfa(g_reply, "SOCK %d", d->sock.fd );
    69   |
    70   |     break;
    71   |
    72   |   case  ER_PATH_EXEC:
    73   |     g_string_sprintfa(g_reply, "EXEC ");
    74   |     if( d->exec.usepath ) {
    75   |       g_string_sprintfa(g_reply, "PATH ");
    76   |     }
    77   |     {
    78   |       char **argv = d->exec.argv;
    79   |       int len=0;
    80   |
    81   |       if( argv != NULL ) {
    82   | 	while( argv[len] != NULL ) {
    83   | 	  g_string_sprintfa(g_reply, "%s ", argv[len]);
    84   | 	  len++;
    85   | 	}
    86   |       }
    87   |     }
    88   |     break;
    89   |
    90   |   default:
    91   |     /* XXX other path descriptions missing */
    92   |     break;
    93   |   }
    94   | }
    95   |
    96   | static
    97   | void er_print_aspmask(mask_t facmask, unsigned aspmask, GString *g_reply)
    98   | {
    99   |   int i = 31;
    100  |
    101  |   while(i >= 0) {
    102  |     if( aspmask & (1<<i) ) {
    103  |       er_getaspsym(facmask, 1<<i, g_reply);
    104  |       g_string_append(g_reply, "|");
    105  |     }
    106  |
    107  |     i--;
    108  |   }
    109  |   /* cut the last "|" */
    110  |   g_string_truncate(g_reply, (int) strlen(g_reply->str)-1);
    111  | }
    112  |
    113  | static
    114  | void er_print_facmask(mask_t facmask, GString *g_reply)
    115  | {
    116  |   int i = FAC_NONE;
    117  |
    118  |   while( ++i != FAC_LAST ) {
    119  |     if( MA_isset(facmask, er_fac_err[i].code) ) {
    120  |       g_string_sprintfa(g_reply, "%s|", er_fac_err[i].name);
    121  |     }
    122  |   }
    123  |   /* cut the last "|" */
    124  |   g_string_truncate(g_reply, (int) strlen(g_reply->str)-1);
    125  |
    126  | }
    127  |
    128  | static
    129  | void er_print_one_filter(er_filter_t *filtptr, GString *g_reply )
    130  | {
    131  |   g_string_sprintfa(g_reply, "( FAC ");
    132  |   er_print_facmask( filtptr->fac_mask, g_reply);
    133  |
    134  |   if( filtptr->asp_mask != 0 ) {
    135  |     g_string_sprintfa(g_reply, "  ASP ");
    136  |     er_print_aspmask(  filtptr->fac_mask, filtptr->asp_mask, g_reply);
    137  |   }
    138  |
    139  |   g_string_sprintfa(g_reply, "  SEV %s-%s ",
    140  | 		    er_getsevsym( filtptr->sev_min, ER_M_SEVCHAR),
    141  | 		    er_getsevsym( filtptr->sev_max, ER_M_SEVCHAR)
    142  | 		    );
    143  |   if( filtptr->thr_id != 0 ) {
    144  |     g_string_sprintfa(g_reply, "   THR %u ", filtptr->thr_id);
    145  |   }
    146  |   g_string_sprintfa(g_reply, " )" );
    147  | }
    148  |
    149  | static
    150  | void er_print_one_path(er_path_t *pathptr, GString *g_reply )
    151  | {
    152  |   GList   *qitem;
    153  |   int f=1;
    154  |
    155  |   g_string_sprintfa(g_reply,"%s { ", pathptr->name );
    156  |   g_string_sprintfa(g_reply," FORMAT ");
    157  |   er_print_format(pathptr->format, g_reply );
    158  |   g_string_sprintfa(g_reply,"  ");
    159  |
    160  |   er_print_one_path_descr(pathptr, g_reply);
    161  |   g_string_sprintfa(g_reply," }\n");
    162  |
    163  |   for(qitem = g_list_first(pathptr->filters);
    164  |       qitem != NULL;
    165  |       qitem = g_list_next(qitem)) {
    166  |     er_filter_t *filtptr = (er_filter_t *) qitem -> data;
    167  |
    168  |     g_string_sprintfa(g_reply,"\t");
    169  |     er_print_one_filter(filtptr, g_reply) ;
    170  |     g_string_sprintfa(g_reply,"\n");
    171  |     f++;
    172  |   }
    173  |
    174  | }
    175  |
    176  | void er_print_paths(char **retbuf)
    177  | {
    178  |   GList   *qitem;
    179  |   GString *g_reply = g_string_sized_new(2048); /* initial size */
    180  |
    181  |   for( qitem = g_list_first(er_pathlist);
    182  |        qitem != NULL;
    183  |        qitem = g_list_next(qitem)) {
    184  |     er_path_t *pathptr = qitem -> data;
    185  |
    186  |     /*   g_string_sprintfa(g_reply, "path type %d (%s) with %d filters\n",
    187  | 	   pathptr->type, er_pathtypes[pathptr->type],
    188  | 	   g_list_length(pathptr->filters));
    189  |     */
    190  |     er_print_one_path(pathptr, g_reply);
    191  |
    192  |   }
    193  |
    194  |   *retbuf = g_reply->str;
    195  |
    196  |   g_string_free( g_reply, /* CONSTCOND */ FALSE);
    197  | }