1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* $Id: stats_funcs.c,v 1.1 2006/03/14 16:36:38 bogdan_iancu Exp $
*
* statistics module - script interface to internal statistics manager
*
* Copyright (C) 2006 Voice Sistem S.R.L.
*
* This file is part of openser, a free SIP server.
*
* openser 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
*
* openser 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
*
* History:
* --------
* 2006-03-14 initial version (bogdan)
*/
#include <string.h>
#include "../../dprint.h"
#include "../../statistics.h"
#include "../../mem/mem.h"
#include "stats_funcs.h"
#define NORESET_FLAG_STR "no_reset"
#define MODULE_STATS "script"
typedef struct stat_mod_elem_
{
char *name;
int flags;
struct stat_mod_elem_ *next;
} stat_elem;
static stat_elem *stat_list = 0;
int reg_statistic( char* name)
{
stat_elem *se;
char *flag_str;
int flags;
if (name==0 || *name==0) {
LOG(L_ERR,"ERROR:statistics:reg_statistics: empty parameter\n");
goto error;
}
flags = 0;
flag_str = strchr( name, '/');
if (flag_str) {
*flag_str = 0;
flag_str++;
if (strcasecmp( flag_str, NORESET_FLAG_STR)==0) {
flags |= STAT_NO_RESET;
} else {
LOG(L_ERR,"ERROR:statistics:reg_statistics: unsuported flag "
"<%s>\n",flag_str);
goto error;
}
}
se = (stat_elem*)pkg_malloc( sizeof(stat_elem) );
if (se==0) {
LOG(L_ERR,"ERROR:statistics:reg_statistics: no more pkh mem\n");
goto error;
}
se->name = name;
se->flags = flags;
se->next = stat_list;
stat_list = se;
return 0;
error:
return -1;
}
int register_all_mod_stats()
{
stat_var *stat;
stat_elem *se;
stat_elem *se_tmp;
se = stat_list;
while( se ) {
se_tmp = se;
se = se->next;
/* register the new variable */
if (register_stat(MODULE_STATS, se_tmp->name, &stat, se_tmp->flags)!=0){
LOG(L_ERR,"ERROR:statistics:register_all_mod_stats: failed to "
"register var. <%s> flags %d\n",se_tmp->name,se_tmp->flags);
return -1;
}
pkg_free(se_tmp);
}
return 0;
}
|