stats_funcs.c

Go to the documentation of this file.
00001 /*
00002  * $Id: stats_funcs.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * statistics module - script interface to internal statistics manager
00005  *
00006  * Copyright (C) 2006 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2006-03-14  initial version (bogdan)
00027  */
00028 
00029 
00030 #include <string.h>
00031 
00032 #include "../../dprint.h"
00033 #include "../../statistics.h"
00034 #include "../../mem/mem.h"
00035 #include "stats_funcs.h"
00036 
00037 
00038 #define NORESET_FLAG_STR "no_reset"
00039 #define MODULE_STATS     "script"
00040 
00041 
00042 typedef struct stat_mod_elem_
00043 {
00044    char *name;
00045    int flags;
00046    struct stat_mod_elem_ *next;
00047 } stat_elem;
00048 
00049 static stat_elem *stat_list = 0;
00050 
00051 
00052 int reg_statistic( char* name)
00053 {
00054    stat_elem *se;
00055    char *flag_str;
00056    int flags;
00057 
00058    if (name==0 || *name==0) {
00059       LM_ERR("empty parameter\n");
00060       goto error;
00061    }
00062 
00063    flags = 0;
00064    flag_str = strchr( name, '/');
00065    if (flag_str) {
00066       *flag_str = 0;
00067       flag_str++;
00068       if (strcasecmp( flag_str, NORESET_FLAG_STR)==0) {
00069          flags |= STAT_NO_RESET;
00070       } else {
00071          LM_ERR("unsuported flag <%s>\n",flag_str);
00072          goto error;
00073       }
00074    }
00075 
00076    se = (stat_elem*)pkg_malloc( sizeof(stat_elem) );
00077    if (se==0) {
00078       LM_ERR("no more pkg mem\n");
00079       goto error;
00080    }
00081 
00082    se->name = name;
00083    se->flags = flags;
00084    se->next = stat_list;
00085    stat_list = se;
00086 
00087    return 0;
00088 error:
00089    return -1;
00090 }
00091 
00092 
00093 
00094 int register_all_mod_stats(void)
00095 {
00096    stat_var  *stat;
00097    stat_elem *se;
00098    stat_elem *se_tmp;
00099 
00100    se = stat_list;
00101    stat = NULL;
00102    while( se ) {
00103       se_tmp = se;
00104       se = se->next;
00105 
00106       /* register the new variable */
00107       if (register_stat(MODULE_STATS, se_tmp->name, &stat, se_tmp->flags)!=0){
00108          LM_ERR("failed to register var. <%s> flags %d\n",
00109                se_tmp->name,se_tmp->flags);
00110          return -1;
00111       }
00112       pkg_free(se_tmp);
00113    }
00114 
00115    return 0;
00116 }
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 

Generated on Thu May 24 14:00:31 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6