📄 plugin~1.c
字号:
/*** Modular Logfile Analyzer** Copyright 2000 Jan Kneschke <jan@kneschke.de>**** Homepage: http://www.kneschke.de/projekte/modlogan** 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: plugin_config.c,v 1.1 2000/08/27 21:44:49 jk Exp $*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <time.h>#include <ctype.h>#include <errno.h>#include "mlocale.h"#include "mplugins.h"#include "mrecord.h"#include "mdatatypes.h"#include "misc.h"#include "plugin_config.h"int mplugins_input_dlinit(mconfig *ext_conf) { config_input *conf = NULL; const char *errptr; int erroffset = 0; conf = malloc(sizeof(config_input)); memset(conf, 0, sizeof(config_input)); conf->inputfilename = NULL; conf->inputfile = stdin; conf->buf_len = 256; conf->buf_inc = 128; conf->buffer = malloc(conf->buf_len * sizeof(char)); if ((conf->match_clf = pcre_compile( /* client-ip timestamp status-code (empty) request transfersize */ "^(.*?) (\\-) (\\-) \\[(.*?)\\] +\"(.*?)\" ([0-9]{1,3}) ([-0-9]+)" /* client_info client_uid statistic */ " \\[(.*?)\\] \\[(.*?)\\] \\[(.*?)\\] ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)$", 0, &errptr, &erroffset, NULL)) == NULL) { fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr); return -1; } conf->match_clf_extra = pcre_study(conf->match_clf, 0, &errptr); if (errptr != NULL) { fprintf(stderr, "%s.%d: rexexp studying error at %s\n", __FILE__, __LINE__, errptr); return -1; } if ((conf->match_timestamp = pcre_compile( "^([0-9]{2})/([a-zA-Z]{3})/([0-9]{4}):([0-9]{2}):([0-9]{2}):([0-9]{2})", 0, &errptr, &erroffset, NULL)) == NULL) { fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr); return -1; } if ((conf->match_url = pcre_compile( "^([A-Za-z]+) (.+?)(\\?(.*?))*( (.*))*$", 0, &errptr, &erroffset, NULL)) == NULL) { fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr); return -1; } conf->match_timestamp_extra = pcre_study(conf->match_timestamp, 0, &errptr); if (errptr != NULL) { fprintf(stderr, "%s.%d: rexexp studying error at %s\n", __FILE__, __LINE__, errptr); return -1; } conf->match_url_extra = pcre_study(conf->match_url, 0, &errptr); if (errptr != NULL) { fprintf(stderr, "%s.%d: rexexp studying error at %s\n", __FILE__, __LINE__, errptr); return -1; } ext_conf->input = conf; return 0;}int mplugins_input_dlclose(mconfig *ext_conf) { config_input *conf = ext_conf->input; if (conf->inputfilename && strcmp(conf->inputfilename, "-")) { fclose(conf->inputfile); } free(conf->match_clf); free(conf->buffer); free(ext_conf->input); ext_conf->input = NULL; return 0;}int mplugins_input_parse_config(mconfig *ext_conf, const char *key, char *value) { int i = 0; config_input *conf = ext_conf->input; const mconfig_values config_values[] = { {"inputfile", M_CONFIG_TYPE_STRING, M_CONFIG_VALUE_OVERWRITE, &(conf->inputfilename)}, {NULL, M_CONFIG_TYPE_INT, 0, NULL} }; while (config_values[i].string) { if (!strcmp(config_values[i].string, key)) break; i++; } if (!config_values[i].string) return -1; mconfig_insert_value(config_values[i].dest, config_values[i].type, value, config_values[i].value_def); return 0;}int mplugins_input_set_defaults(mconfig *ext_conf) { config_input *conf = ext_conf->input; if (conf->inputfilename && strcmp(conf->inputfilename, "-")) { if (!(conf->inputfile = fopen(conf->inputfilename, "r"))) { fprintf(stderr, "%s %s: %s\n", _("Can't open inputfile "), conf->inputfilename, strerror(errno)); return -1; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -