stats_funcs.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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