1 /* 2 ** Modular Logfile Analyzer 3 ** Copyright 2000 Jan Kneschke <jan@kneschke.de> 4 ** 5 ** Homepage: http://www.modlogan.org 6 ** 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version, and provided that the above 12 copyright and permission notice is included with all distributed 13 copies of this or derived software. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 23 24 ** 25 ** $Id: process.c,v 1.13 2004/08/27 20:06:18 ostborn Exp $ 26 */ 27 28 #include <libintl.h> 29 #include <locale.h> 30 #include <stdlib.h> 31 #include <stdio.h> 32 #include <time.h> 33 #include <string.h> 34 #include <ctype.h> 35 #include <errno.h> 36 #include <math.h> 37 38 #include "config.h" 39 #include "mrecord.h" 40 #include "mlocale.h" 41 #include "mconfig.h" 42 #include "mplugins.h" 43 #include "mstate.h" 44 #include "mdatatypes.h" 45 #include "datatypes/count/datatype.h" 46 #include "datatypes/state/datatype.h" 47 #include "misc.h" 48 #include "plugin_config.h" 49 50 int mplugins_processor_insert_record(mconfig *ext_conf, mlist *state_list, mlogrec *record) { 51 mlogrec_telecom *rectel = NULL; 52 config_processor *conf = ext_conf->plugin_conf; 53 mstate_telecom *statel = NULL; 54 struct tm *tm; 55 /* State */ 56 mdata *data = state_list->data; 57 mstate *state = NULL; 58 59 if (!data) { 60 const char *key = splaytree_insert(ext_conf->strings, ""); 61 data = mdata_State_create(key,NULL,NULL); 62 mlist_insert(state_list, data); 63 } 64 65 if (record->ext_type != M_RECORD_TYPE_TELECOM) return -1; 66 67 if (record->ext == NULL) return -1; 68 69 rectel = record->ext; 70 71 state = data->data.state.state; 72 73 if (ext_conf->debug_level > 2) { 74 if (rectel->direction == M_RECORD_TELECOM_DIRECTION_IN) { 75 printf("%-3s <- %-30s (%lds)\n", rectel->called_number, rectel->calling_number, rectel->duration); 76 } else { 77 printf("%-3s -> %-30s (%lds)\n", rectel->calling_number, rectel->called_number, rectel->duration); 78 } 79 } 80 81 /* if we have a subprocessor, call it */ 82 if (conf->sub_processor) { 83 conf->sub_processor->insert_record(ext_conf, state_list, record); 84 } 85 86 if (state->ext) { 87 switch(state->ext_type) { 88 case M_STATE_TYPE_TELECOM: 89 statel = state->ext; break; 90 default: 91 fprintf(stderr, "%s.%d: unsupport state subtype\n", __FILE__, __LINE__); 92 return -1; 93 } 94 } else { 95 state->ext = mstate_init_telecom(); 96 state->ext_type = M_STATE_TYPE_TELECOM; 97 98 statel = state->ext; 99 } 100 101 /* hourly/daily stats */ 102 if ((tm = localtime(&(record->timestamp)))) { 103 if (rectel->direction == M_RECORD_TELECOM_DIRECTION_IN) { 104 statel->hours[tm->tm_hour].incoming_calls++; 105 statel->days[tm->tm_mday-1].incoming_calls++; 106 } else { 107 statel->hours[tm->tm_hour].outgoing_calls++; 108 statel->days[tm->tm_mday-1].outgoing_calls++; 109 } 110 } 111 112 if (rectel->called_number) { 113 const char *key = splaytree_insert(ext_conf->strings, rectel->called_number); 114 data = mdata_Count_create(key, 1, M_DATA_STATE_PLAIN); 115 mhash_insert_sorted(statel->called_numbers, data); 116 } 117 118 if (rectel->calling_number) { 119 const char *key = splaytree_insert(ext_conf->strings, rectel->calling_number); 120 data = mdata_Count_create(key, 1, M_DATA_STATE_PLAIN); 121 mhash_insert_sorted(statel->calling_numbers, data); 122 } 123 124 return 0; 125 } 126 127 128 129