Changeset 186 for trunk/src/sh_log_parse_apache.c
- Timestamp:
- Oct 31, 2008, 8:22:45 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_log_parse_apache.c
r185 r186 47 47 int pos_status; 48 48 int pos_time; 49 intformat_time;49 char * format_time; 50 50 }; 51 51 … … 60 60 */ 61 61 static void * sh_dummy_new = NULL; 62 static void * sh_dummy_fti = NULL; 62 63 63 64 void * sh_eval_fileinfo_apache(char * str) … … 75 76 volatile int p_status = -1; 76 77 volatile int p_time = -1; 77 volatile int f_time = -1;78 char * f_time = NULL; 78 79 const char * error; 79 80 int erroffset; … … 83 84 */ 84 85 sh_dummy_new = (void*) &new; 86 sh_dummy_fti = (void*) &f_time; 85 87 86 88 if (0 == strncmp("common", str, 6)) … … 149 151 strstr(token, _("{User-Agent}")) == 0) 150 152 { 151 p = _("\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\""); 153 /* 154 p = "\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\""; 152 155 sh_string_add_from_char(re_string, p); 156 */ 157 sh_string_add_from_char(re_string, "\"([^"); 158 sh_string_add_from_char(re_string, "\"\\\\"); 159 sh_string_add_from_char(re_string, "]*"); 160 sh_string_add_from_char(re_string, "(?:"); 161 sh_string_add_from_char(re_string, "\\\\."); 162 sh_string_add_from_char(re_string, "[^\""); 163 sh_string_add_from_char(re_string, "\\\\]*"); 164 sh_string_add_from_char(re_string, ")*)\""); 153 165 } 154 166 else 155 167 { 156 p = _("(\\S+)"); 157 sh_string_add_from_char(re_string, p); 168 sh_string_add_from_char(re_string, "("); 169 sh_string_add_from_char(re_string, "\\S+"); 170 sh_string_add_from_char(re_string, ")"); 158 171 } 159 172 } 160 173 else if (token[0] == '%' && token[strlen(token)-1] == 't') 161 174 { 162 p = _("\\[([^\\]]+)\\]"); 175 char * lb = strchr(token, '{'); 176 char * rb = strchr(token, '}'); 177 178 sh_string_add_from_char(re_string, "\\["); 179 sh_string_add_from_char(re_string, "([^"); 180 sh_string_add_from_char(re_string, "(\\]"); 181 sh_string_add_from_char(re_string, "]+)"); 182 sh_string_add_from_char(re_string, "\\]"); 183 184 p_time = i+1; 185 if (lb && rb) 186 { 187 ++lb; *rb = '\0'; 188 f_time = sh_util_strdup(lb); 189 } 190 else 191 { 192 f_time = sh_util_strdup(_("%d/%b/%Y:%T")); 193 } 194 } 195 else if (token[0] == '%' && token[1] == 'e' && 0 == strcmp(token, _("%error"))) 196 { 197 sh_string_add_from_char(re_string, "\\["); 198 sh_string_add_from_char(re_string, "([^"); 199 sh_string_add_from_char(re_string, "]"); 200 sh_string_add_from_char(re_string, "]+)"); 201 sh_string_add_from_char(re_string, "\\]"); 202 203 p_time = i+1; f_time = sh_util_strdup(_("%a %b %d %T %Y")); ++i; 204 sh_string_add_from_char(re_string, " "); 205 206 sh_string_add_from_char(re_string, "\\["); 207 sh_string_add_from_char(re_string, "([^"); 208 sh_string_add_from_char(re_string, "]"); 209 sh_string_add_from_char(re_string, "]+)"); 210 sh_string_add_from_char(re_string, "\\]"); 211 212 p_status = i+1; 213 sh_string_add_from_char(re_string, " "); 214 215 p = "(.+)"; 163 216 sh_string_add_from_char(re_string, p); 164 p_time = i+1; 165 f_time = 1; 166 } 167 else if (token[0] == '%' && token[1] == 'e' && 0 == strcmp(token, _("%error"))) 168 { 169 p = _("\\[([^\\]]+)\\]"); 170 sh_string_add_from_char(re_string, p); 171 p_time = i+1; f_time = 2; ++i; 172 173 sh_string_add_from_char(re_string, " "); 174 p = _("\\[([^\\]]+)\\]"); 175 sh_string_add_from_char(re_string, p); 176 p_status = i+1; 177 178 sh_string_add_from_char(re_string, " "); 179 p = _("(.*)"); 180 sh_string_add_from_char(re_string, p); 217 218 nfields = 3; 181 219 182 220 break; … … 184 222 else 185 223 { 186 p = _("(\\S+)"); 187 sh_string_add_from_char(re_string, p); 224 sh_string_add_from_char(re_string, "("); 225 sh_string_add_from_char(re_string, "\\S+"); 226 sh_string_add_from_char(re_string, ")"); 188 227 if (token[0] == '%' && token[strlen(token)-1] == 's') 189 228 p_status = i+1; … … 288 327 res = 0; 289 328 timestamp = 0; 290 info->format_time = 1;329 info->format_time = sh_util_strdup(_("%d/%b/%Y:%T")); 291 330 sl_strlcpy(tstr, _("01/Jan/1970:00:00:00"), sizeof(tstr)); 292 331 } … … 295 334 { 296 335 struct tm btime; 297 char * ptr = NULL , * q;336 char * ptr = NULL; 298 337 299 338 /* example: 01/Jun/2008:07:55:28 +0200 */ 300 339 301 if (info->format_time == 1) 302 { 303 q = strchr(tstr, ' '); 304 if (q) *q = '\0'; 305 306 ptr = /*@i@*/strptime(tstr, "%d/%b/%Y:%T", &btime); 307 } 308 else if (info->format_time == 2) 309 { 310 ptr = /*@i@*/strptime(tstr, "%a %b %d %T %Y", &btime); 311 } 312 313 if (ptr && *ptr == '\0') 340 ptr = /*@i@*/strptime(tstr, info->format_time, &btime); 341 342 if (ptr) 314 343 { 315 344 timestamp = conv_timestamp(&btime, &old_tm, &old_time); … … 349 378 record->timestamp = timestamp; 350 379 record->timestr = sh_string_new_from_lchar(tstr, strlen(tstr)); 351 record->prefix = sh_string_new_from_lchar(sstr, strlen(sstr));352 380 353 381 if (hstr)
Note:
See TracChangeset
for help on using the changeset viewer.