/* ** Modular Logfile Analyzer ** Copyright 2000 Jan Kneschke ** ** Homepage: http://www.modlogan.org ** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version, and provided that the above copyright and permission notice is included with all distributed copies of this or derived software. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ** ** $Id: parse.c,v 1.2 2004/08/27 20:07:38 ostborn Exp $ */ #include #include #include #include #include #include #include "mlocale.h" #include "mplugins.h" #include "mrecord.h" #include "mdatatypes.h" #include "misc.h" #include "plugin_config.h" #define DEBUG_PCRE int parse_record_pcre(mconfig *ext_conf, mlogrec *record, buffer *b) { #define N 20 + 1 const char **list; int ovector[3 * N], n; #ifdef DEBUG_PCRE int i; #endif config_input *conf = ext_conf->plugin_conf; mlogrec_web *recweb = NULL; if (record->ext_type != M_RECORD_TYPE_WEB) { if (record->ext_type != M_RECORD_TYPE_UNSET) { mrecord_free_ext(record); } record->ext_type = M_RECORD_TYPE_WEB; record->ext = mrecord_init_web(); } recweb = record->ext; if (recweb == NULL) return M_RECORD_HARD_ERROR; recweb->ext = mrecord_init_web_squid(); recweb->ext_type = M_RECORD_TYPE_WEB_SQUID; if ((n = pcre_exec(conf->match_cp_ims_login, conf->match_cp_ims_login_extra, b->ptr, b->used - 1, 0, 0, ovector, 3 * N)) < 0) { if (n == PCRE_ERROR_NOMATCH) { fprintf(stderr, "%s.%d: string doesn't match: %s\n", __FILE__, __LINE__, b->ptr); } else { fprintf(stderr, "%s.%d: execution error while matching: %d\n", __FILE__, __LINE__, n); } return M_RECORD_HARD_ERROR; } if (n) { pcre_get_substring_list(b->ptr, ovector, n, &list); /* the meaning of the different fields (squid) */ /* 1 - timestamp in sec 2 - +timestamp in msec 3 - duration in msec 4 - client-ip 5,6 - status 7 - xfersize 8 - request method (GET, ...) 9 - requested url 10 - authentication-user-id (RFC931) 11 - hierachary code 12 - ... sub cody 13 - type */ /* record->timestamp = strtol(list[1], NULL, 10); recweb->req_host = malloc(strlen((char *)list[4])+1); strcpy(recweb->req_host, (char *)list[4]); recweb->req_status = strtol(list[6], NULL,10); recweb->xfersize = strtol(list[7], NULL,10); recweb->req_method = malloc(strlen((char *)list[8])+1); strcpy(recweb->req_method, (char *)list[8]); recweb->req_url = malloc(strlen((char *)list[9])+1); strcpy(recweb->req_url, (char *)list[9]); */ for (i = 0; i < n; i++) { printf("%d: %s\n", i, list[i]); } free(list); } return M_RECORD_NO_ERROR; #undef N } int mplugins_input_cp_ims_login_get_next_record(mconfig *ext_conf, mlogrec *record) { int ret = 0; config_input *conf = ext_conf->plugin_conf; if (record == NULL) return M_RECORD_HARD_ERROR; /* fill the line buffer */ if (NULL == mgets(&(conf->inputfile), conf->buf)) return M_RECORD_EOF; ret = parse_record_pcre (ext_conf, record, conf->buf); if (ret == M_RECORD_CORRUPT) { M_DEBUG1(ext_conf->debug_level, M_DEBUG_SECTION_PARSING, M_DEBUG_LEVEL_WARNINGS, "affected Record: %s\n", conf->buf->ptr ); } return ret; /* the Skeleton itself should do nothing although it compiles fine * that's why we return M_RECORD_EOF here */ #if 0 return ret; #else return M_RECORD_EOF; #endif }