/* ** 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: plugin_config.c,v 1.8 2003/07/18 11:38:10 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" #ifdef HAVE_FLOWTOOLS #include "ftlib.h" #endif /* this code is taken from the squid plugin */ /* init the plugin */ int mplugins_input_flowraw_dlinit(mconfig *ext_conf) { config_input *conf = NULL; if (0 != strcmp(ext_conf->version, VERSION)) { M_DEBUG2(ext_conf->debug_level, M_DEBUG_SECTION_INIT, M_DEBUG_LEVEL_ERRORS, "version string doesn't match: (mla) %s != (plugin) %s\n", ext_conf->version, VERSION); return -1; } /* get the neccesary space */ conf = malloc(sizeof(config_input)); memset(conf, 0, sizeof(config_input)); /* set some defaults */ conf->inputfilename = NULL; conf->inputfile = stdin; ext_conf->plugin_conf = conf; return 0; } /* destructor */ int mplugins_input_flowraw_dlclose(mconfig *ext_conf) { config_input *conf = ext_conf->plugin_conf; #ifdef HAVE_FLOWTOOLS ftio_close(&(conf->ftio)); #endif if (conf->inputfilename && strcmp(conf->inputfilename, "-")) { fclose(conf->inputfile); } if (conf->inputfilename) free(conf->inputfilename); free(ext_conf->plugin_conf); ext_conf->plugin_conf = NULL; return 0; } int mplugins_input_flowraw_parse_config(mconfig *ext_conf, const char *filename, const char *section) { config_input *conf = ext_conf->plugin_conf; const mconfig_values config_values[] = { {"inputfile", M_CONFIG_TYPE_STRING, M_CONFIG_VALUE_OVERWRITE, &(conf->inputfilename)}, /* terminate the array of options */ {NULL, M_CONFIG_TYPE_INT, 0, NULL} }; return mconfig_parse_section(ext_conf, filename, section, config_values); } int mplugins_input_flowraw_set_defaults(mconfig *ext_conf) { config_input *conf = ext_conf->plugin_conf; 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; } } #ifdef HAVE_FLOWTOOLS if (ftio_init(&(conf->ftio), fileno(conf->inputfile), FT_IO_FLAG_READ) < 0) fterr_errx(1, "ftio_init(): failed"); #endif return 0; } int mplugins_init(mplugin *func) { func->dlinit = mplugins_input_flowraw_dlinit; func->dlclose = mplugins_input_flowraw_dlclose; func->parse_config = mplugins_input_flowraw_parse_config; func->set_defaults = mplugins_input_flowraw_set_defaults; func->get_next_record = mplugins_input_flowraw_get_next_record; func->insert_record = NULL; func->gen_report = NULL; func->gen_history = NULL; return 0; }