| 1 |
%{ |
|---|
| 2 |
/* ====================================================================== |
|---|
| 3 |
* Copyright (c) 2000 Theo Schlossnagle |
|---|
| 4 |
* All rights reserved. |
|---|
| 5 |
* The following code was written by Theo Schlossnagle <jesus@omniti.com> |
|---|
| 6 |
* This code was written to facilitate clustered logging via Spread. |
|---|
| 7 |
* More information on Spread can be found at http://www.spread.org/ |
|---|
| 8 |
* Please refer to the LICENSE file before using this software. |
|---|
| 9 |
* ====================================================================== |
|---|
| 10 |
*/ |
|---|
| 11 |
|
|---|
| 12 |
#include "sld_config.h" |
|---|
| 13 |
|
|---|
| 14 |
extern int line_num, semantic_errors; |
|---|
| 15 |
extern int buffsize; |
|---|
| 16 |
extern char *sld_text; |
|---|
| 17 |
extern char *module_dir; |
|---|
| 18 |
|
|---|
| 19 |
static SpreadConfiguration *current_sc = NULL; |
|---|
| 20 |
static LogFacility *current_lf = NULL; |
|---|
| 21 |
|
|---|
| 22 |
int sld_error(char *str); |
|---|
| 23 |
|
|---|
| 24 |
#define NEW_SC_IFNEEDED if(!current_sc) current_sc=config_new_spread_conf(); |
|---|
| 25 |
|
|---|
| 26 |
#define NEW_LF_IFNEEDED if(!current_sc) current_sc=config_new_spread_conf(); \ |
|---|
| 27 |
if(!current_lf) current_lf=config_new_logfacility(); |
|---|
| 28 |
%} |
|---|
| 29 |
%start Config |
|---|
| 30 |
%token BUFFERSIZE SPREAD PORT HOST LOG GROUP FILENAME MATCH VHOSTGROUP VHOSTDIR |
|---|
| 31 |
%token OPENBRACE CLOSEBRACE EQUALS STRING CLF REWRITETIMES |
|---|
| 32 |
%token PERLLIB PERLUSE PERLLOG PERLHUP PYTHONIMPORT PYTHONLOG PYTHONLIB |
|---|
| 33 |
%token MODULEDIR LOADMODULE MODULELOG |
|---|
| 34 |
%% |
|---|
| 35 |
Config : Globals SpreadConfs |
|---|
| 36 |
{ config_start(); } |
|---|
| 37 |
; |
|---|
| 38 |
|
|---|
| 39 |
Globals : GlobalParam Globals |
|---|
| 40 |
| |
|---|
| 41 |
; |
|---|
| 42 |
|
|---|
| 43 |
GlobalParam : BUFFERSIZE EQUALS STRING |
|---|
| 44 |
{ if(buffsize<0) { |
|---|
| 45 |
buffsize = atoi($3); |
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
| MODULEDIR EQUALS STRING |
|---|
| 49 |
{ module_dir = strdup($3); } |
|---|
| 50 |
| LOADMODULE STRING |
|---|
| 51 |
{ module_load($2, NULL); } |
|---|
| 52 |
| LOADMODULE STRING STRING |
|---|
| 53 |
{ module_load($2, $3); } |
|---|
| 54 |
| PERLLIB STRING |
|---|
| 55 |
{ |
|---|
| 56 |
#ifdef PERL |
|---|
| 57 |
perl_inc($2); |
|---|
| 58 |
#else |
|---|
| 59 |
fprintf(stderr, "PERL not compiled in\n"); |
|---|
| 60 |
exit(0); |
|---|
| 61 |
#endif |
|---|
| 62 |
} |
|---|
| 63 |
| PERLUSE STRING |
|---|
| 64 |
{ |
|---|
| 65 |
#ifdef PERL |
|---|
| 66 |
perl_use($2); |
|---|
| 67 |
#else |
|---|
| 68 |
fprintf(stderr, "PERL not compiled in\n"); |
|---|
| 69 |
exit(0); |
|---|
| 70 |
#endif |
|---|
| 71 |
} |
|---|
| 72 |
| PYTHONLIB STRING |
|---|
| 73 |
{ |
|---|
| 74 |
#ifdef PYTHON |
|---|
| 75 |
python_inc($2); |
|---|
| 76 |
#else |
|---|
| 77 |
fprintf(stderr, "PYTHON not compiled in\n"); |
|---|
| 78 |
exit(0); |
|---|
| 79 |
#endif |
|---|
| 80 |
} |
|---|
| 81 |
| PYTHONIMPORT STRING |
|---|
| 82 |
{ |
|---|
| 83 |
#ifdef PYTHON |
|---|
| 84 |
python_import($2); |
|---|
| 85 |
#else |
|---|
| 86 |
fprintf(stderr, "PYTHON not compiled in\n"); |
|---|
| 87 |
exit(0); |
|---|
| 88 |
#endif |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
SpreadConfs : SpreadConf SpreadConfs |
|---|
| 92 |
| SpreadConf |
|---|
| 93 |
; |
|---|
| 94 |
|
|---|
| 95 |
SpreadConf : SPREAD OPENBRACE SPparams LogStructs CLOSEBRACE |
|---|
| 96 |
{ config_add_spreadconf(current_sc); |
|---|
| 97 |
current_sc = NULL; } |
|---|
| 98 |
; |
|---|
| 99 |
|
|---|
| 100 |
SPparams : SPparam SPparams |
|---|
| 101 |
| |
|---|
| 102 |
; |
|---|
| 103 |
|
|---|
| 104 |
SPparam : PORT EQUALS STRING |
|---|
| 105 |
{ NEW_SC_IFNEEDED; |
|---|
| 106 |
config_set_spread_port(current_sc, $3); } |
|---|
| 107 |
| HOST EQUALS STRING |
|---|
| 108 |
{ NEW_SC_IFNEEDED; |
|---|
| 109 |
config_set_spread_host(current_sc, $3); } |
|---|
| 110 |
; |
|---|
| 111 |
|
|---|
| 112 |
LogStructs : LogStruct LogStructs |
|---|
| 113 |
| |
|---|
| 114 |
; |
|---|
| 115 |
|
|---|
| 116 |
LogStruct : LOG OPENBRACE Logparams CLOSEBRACE |
|---|
| 117 |
{ config_add_logfacility(current_sc, current_lf); |
|---|
| 118 |
current_lf = NULL; } |
|---|
| 119 |
; |
|---|
| 120 |
|
|---|
| 121 |
Logparams : Logparams Logparam |
|---|
| 122 |
| |
|---|
| 123 |
; |
|---|
| 124 |
|
|---|
| 125 |
Logparam : GROUP EQUALS STRING |
|---|
| 126 |
{ NEW_LF_IFNEEDED; |
|---|
| 127 |
config_set_logfacility_group(current_lf, $3); } |
|---|
| 128 |
| FILENAME EQUALS STRING |
|---|
| 129 |
{ NEW_LF_IFNEEDED; |
|---|
| 130 |
config_set_logfacility_filename(current_lf, $3); } |
|---|
| 131 |
| MODULELOG STRING |
|---|
| 132 |
{ NEW_LF_IFNEEDED; |
|---|
| 133 |
config_set_logfacility_external_module(current_lf, $2); |
|---|
| 134 |
} |
|---|
| 135 |
| PERLLOG STRING |
|---|
| 136 |
{ NEW_LF_IFNEEDED; |
|---|
| 137 |
#ifdef PERL |
|---|
| 138 |
config_set_logfacility_external_perl(current_lf, $2); |
|---|
| 139 |
#else |
|---|
| 140 |
fprintf(stderr, "PERL not compiled in\n"); |
|---|
| 141 |
exit(0); |
|---|
| 142 |
#endif |
|---|
| 143 |
} |
|---|
| 144 |
| PERLHUP STRING |
|---|
| 145 |
{ NEW_LF_IFNEEDED; |
|---|
| 146 |
#ifdef PERL |
|---|
| 147 |
config_set_hupfacility_external_perl(current_lf, $2); |
|---|
| 148 |
#else |
|---|
| 149 |
fprintf(stderr, "PERL not compiled in\n"); |
|---|
| 150 |
exit(0); |
|---|
| 151 |
#endif |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
| PYTHONLOG STRING |
|---|
| 155 |
{ NEW_LF_IFNEEDED; |
|---|
| 156 |
#ifdef PYTHON |
|---|
| 157 |
config_set_logfacility_external_python(current_lf, $2); |
|---|
| 158 |
#else |
|---|
| 159 |
fprintf(stderr, "PYTHON not compiled in\n"); |
|---|
| 160 |
exit(0); |
|---|
| 161 |
#endif |
|---|
| 162 |
} |
|---|
| 163 |
| MATCH EQUALS STRING |
|---|
| 164 |
{ NEW_LF_IFNEEDED; |
|---|
| 165 |
config_add_logfacility_match(current_lf, $3); } |
|---|
| 166 |
| VHOSTDIR EQUALS STRING |
|---|
| 167 |
{ NEW_LF_IFNEEDED; |
|---|
| 168 |
config_set_logfacility_vhostdir(current_lf, $3); } |
|---|
| 169 |
| REWRITETIMES EQUALS CLF |
|---|
| 170 |
{ NEW_LF_IFNEEDED; |
|---|
| 171 |
config_set_logfaclity_rewritetimes_clf(current_lf); } |
|---|
| 172 |
| REWRITETIMES EQUALS STRING |
|---|
| 173 |
{ NEW_LF_IFNEEDED; |
|---|
| 174 |
config_set_logfaclity_rewritetimes_user(current_lf, |
|---|
| 175 |
$3); } |
|---|
| 176 |
; |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
%% |
|---|
| 180 |
int sld_error(char *str) { |
|---|
| 181 |
fprintf(stderr, "Parser error on or before line %d\n", line_num); |
|---|
| 182 |
fprintf(stderr, "Offending token: %s\n", sld_text); |
|---|
| 183 |
return -1; |
|---|
| 184 |
} |
|---|