1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,267 +0,0 @@ |
1 |
-/* |
|
2 |
- * $Id$ |
|
3 |
- * |
|
4 |
- * statistics module - script interface to internal statistics manager |
|
5 |
- * |
|
6 |
- * Copyright (C) 2006 Voice Sistem S.R.L. |
|
7 |
- * |
|
8 |
- * This file is part of Kamailio, a free SIP server. |
|
9 |
- * |
|
10 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
11 |
- * it under the terms of the GNU General Public License as published by |
|
12 |
- * the Free Software Foundation; either version 2 of the License, or |
|
13 |
- * (at your option) any later version |
|
14 |
- * |
|
15 |
- * Kamailio 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 |
- * History: |
|
25 |
- * -------- |
|
26 |
- * 2006-03-14 initial version (bogdan) |
|
27 |
- */ |
|
28 |
- |
|
29 |
- |
|
30 |
-#include <stdio.h> |
|
31 |
-#include <string.h> |
|
32 |
-#include <stdlib.h> |
|
33 |
- |
|
34 |
-#include "../../sr_module.h" |
|
35 |
-#include "../../dprint.h" |
|
36 |
-#include "../../ut.h" |
|
37 |
-#include "../../mod_fix.h" |
|
38 |
-#include "../../lib/kcore/statistics.h" |
|
39 |
-#include "../../mem/mem.h" |
|
40 |
-#include "stats_funcs.h" |
|
41 |
- |
|
42 |
-MODULE_VERSION |
|
43 |
- |
|
44 |
-static int reg_param_stat( modparam_t type, void* val); |
|
45 |
-static int mod_init(void); |
|
46 |
-static int w_update_stat(struct sip_msg* msg, char* stat, char* n); |
|
47 |
-static int w_reset_stat(struct sip_msg* msg, char* stat, char* foo); |
|
48 |
-static int fixup_stat(void** param, int param_no); |
|
49 |
- |
|
50 |
-struct stat_or_pv { |
|
51 |
- stat_var *stat; |
|
52 |
- pv_spec_t *pv; |
|
53 |
-}; |
|
54 |
- |
|
55 |
-struct long_or_pv { |
|
56 |
- long val; |
|
57 |
- pv_spec_t *pv; |
|
58 |
-}; |
|
59 |
- |
|
60 |
- |
|
61 |
- |
|
62 |
-static cmd_export_t cmds[]={ |
|
63 |
- {"update_stat", (cmd_function)w_update_stat, 2, fixup_stat, 0, |
|
64 |
- ANY_ROUTE}, |
|
65 |
- {"reset_stat", (cmd_function)w_reset_stat, 1, fixup_stat, 0, |
|
66 |
- REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, |
|
67 |
- {0,0,0,0,0,0} |
|
68 |
-}; |
|
69 |
- |
|
70 |
-static param_export_t mod_params[]={ |
|
71 |
- { "variable", STR_PARAM|USE_FUNC_PARAM, (void*)reg_param_stat }, |
|
72 |
- { 0,0,0 } |
|
73 |
-}; |
|
74 |
- |
|
75 |
- |
|
76 |
-struct module_exports exports= { |
|
77 |
- "statistics", /* module's name */ |
|
78 |
- DEFAULT_DLFLAGS, /* dlopen flags */ |
|
79 |
- cmds, /* exported functions */ |
|
80 |
- mod_params, /* param exports */ |
|
81 |
- 0, /* exported statistics */ |
|
82 |
- 0, /* exported MI functions */ |
|
83 |
- 0, /* exported pseudo-variables */ |
|
84 |
- 0, /* extra processes */ |
|
85 |
- mod_init, /* module initialization function */ |
|
86 |
- 0, /* reply processing function */ |
|
87 |
- 0, /* module destroy function */ |
|
88 |
- 0 /* per-child init function */ |
|
89 |
-}; |
|
90 |
- |
|
91 |
- |
|
92 |
- |
|
93 |
-static int reg_param_stat( modparam_t type, void* val) |
|
94 |
-{ |
|
95 |
- return reg_statistic( (char*)val); |
|
96 |
-} |
|
97 |
- |
|
98 |
- |
|
99 |
- |
|
100 |
-static int mod_init(void) |
|
101 |
-{ |
|
102 |
- if (register_all_mod_stats()!=0) { |
|
103 |
- LM_ERR("failed to register statistic variables\n"); |
|
104 |
- return E_UNSPEC; |
|
105 |
- } |
|
106 |
- return 0; |
|
107 |
-} |
|
108 |
- |
|
109 |
- |
|
110 |
- |
|
111 |
-static int fixup_stat(void** param, int param_no) |
|
112 |
-{ |
|
113 |
- struct stat_or_pv *sopv; |
|
114 |
- struct long_or_pv *lopv; |
|
115 |
- str s; |
|
116 |
- long n=0; |
|
117 |
- int err=0; |
|
118 |
- |
|
119 |
- s.s = (char*)*param; |
|
120 |
- s.len = strlen(s.s); |
|
121 |
- if (param_no==1) { |
|
122 |
- /* var name - string or pv */ |
|
123 |
- sopv = (struct stat_or_pv *)pkg_malloc(sizeof(struct stat_or_pv)); |
|
124 |
- if (sopv==NULL) { |
|
125 |
- LM_ERR("no more pkg mem\n"); |
|
126 |
- return E_OUT_OF_MEM; |
|
127 |
- } |
|
128 |
- memset( sopv, 0 , sizeof(struct stat_or_pv) ); |
|
129 |
- /* is it pv? */ |
|
130 |
- if (s.s[0]=='$') { |
|
131 |
- if (fixup_pvar_null(param, 1)!=0) { |
|
132 |
- LM_ERR("invalid pv %s as parameter\n",s.s); |
|
133 |
- return E_CFG; |
|
134 |
- } |
|
135 |
- sopv->pv = (pv_spec_t*)(*param); |
|
136 |
- } else { |
|
137 |
- /* it is string */ |
|
138 |
- sopv->stat = get_stat( &s ); |
|
139 |
- if (sopv->stat==0) { |
|
140 |
- LM_ERR("variable <%s> not defined\n", s.s); |
|
141 |
- return E_CFG; |
|
142 |
- } |
|
143 |
- } |
|
144 |
- pkg_free(s.s); |
|
145 |
- *param=(void*)sopv; |
|
146 |
- return 0; |
|
147 |
- } else if (param_no==2) { |
|
148 |
- lopv = (struct long_or_pv *) pkg_malloc(sizeof(struct long_or_pv)); |
|
149 |
- if (lopv == NULL) { |
|
150 |
- LM_ERR("no more pkg mem\n"); |
|
151 |
- return E_OUT_OF_MEM; |
|
152 |
- } |
|
153 |
- memset(lopv, 0, sizeof(struct long_or_pv)); |
|
154 |
- /* is it pv? */ |
|
155 |
- if (s.s[0] == '$') { |
|
156 |
- if (fixup_pvar_pvar(param, 2) != 0) { |
|
157 |
- LM_ERR("invalid pv %s as parameter\n",s.s); |
|
158 |
- return E_CFG; |
|
159 |
- } |
|
160 |
- lopv->pv = (pv_spec_t*) (*param); |
|
161 |
- } else { |
|
162 |
- /* it is string */ |
|
163 |
- /* update value - integer */ |
|
164 |
- if (s.s[0] == '-' || s.s[0] == '+') { |
|
165 |
- n = str2s(s.s + 1, s.len - 1, &err); |
|
166 |
- if (s.s[0] == '-') |
|
167 |
- n = -n; |
|
168 |
- } else { |
|
169 |
- n = str2s(s.s, s.len, &err); |
|
170 |
- } |
|
171 |
- lopv->val = n; |
|
172 |
- } |
|
173 |
- |
|
174 |
- if (err==0){ |
|
175 |
- if (n==0 && (s.s[0]!='$')) { //we can't check the value of the pvar so have to ignore this check if it is a pvar |
|
176 |
- LM_ERR("update with 0 has no sense\n"); |
|
177 |
- return E_CFG; |
|
178 |
- } |
|
179 |
- pkg_free(s.s); |
|
180 |
- *param=(void*)lopv; |
|
181 |
- return 0; |
|
182 |
- }else{ |
|
183 |
- LM_ERR("bad update number <%s>\n",(char*)(*param)); |
|
184 |
- return E_CFG; |
|
185 |
- } |
|
186 |
- } |
|
187 |
- return 0; |
|
188 |
-} |
|
189 |
- |
|
190 |
- |
|
191 |
-static int w_update_stat(struct sip_msg *msg, char *stat_p, char *long_p) |
|
192 |
-{ |
|
193 |
- struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; |
|
194 |
- struct long_or_pv *lopv = (struct long_or_pv *)long_p; |
|
195 |
- pv_value_t pv_val; |
|
196 |
- stat_var *stat; |
|
197 |
- long n = 0; |
|
198 |
- int err; |
|
199 |
- |
|
200 |
- if (lopv->val) { |
|
201 |
- n=lopv->val; |
|
202 |
- } else { |
|
203 |
- if (pv_get_spec_value(msg, lopv->pv, &pv_val) != 0 || (pv_val.flags & PV_VAL_STR) == 0) { |
|
204 |
- LM_ERR("failed to get pv string value\n"); |
|
205 |
- return -1; |
|
206 |
- } |
|
207 |
- str s = pv_val.rs; |
|
208 |
- /* it is string */ |
|
209 |
- /* update value - integer */ |
|
210 |
- if (s.s[0] == '-' || s.s[0] == '+') { |
|
211 |
- n = str2s(s.s + 1, s.len - 1, &err); |
|
212 |
- if (s.s[0] == '-') |
|
213 |
- n = -n; |
|
214 |
- } else { |
|
215 |
- n = str2s(s.s, s.len, &err); |
|
216 |
- } |
|
217 |
- } |
|
218 |
- |
|
219 |
- if (sopv->stat) { |
|
220 |
- update_stat( sopv->stat, (long)n); |
|
221 |
- } else { |
|
222 |
- if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 || |
|
223 |
- (pv_val.flags & PV_VAL_STR)==0 ) { |
|
224 |
- LM_ERR("failed to get pv string value\n"); |
|
225 |
- return -1; |
|
226 |
- } |
|
227 |
- stat = get_stat( &(pv_val.rs) ); |
|
228 |
- if ( stat == 0 ) { |
|
229 |
- LM_ERR("variable <%.*s> not defined\n", |
|
230 |
- pv_val.rs.len, pv_val.rs.s); |
|
231 |
- return -1; |
|
232 |
- } |
|
233 |
- update_stat( stat, (long)n); |
|
234 |
- } |
|
235 |
- |
|
236 |
- return 1; |
|
237 |
-} |
|
238 |
- |
|
239 |
- |
|
240 |
-static int w_reset_stat(struct sip_msg *msg, char* stat_p, char *foo) |
|
241 |
-{ |
|
242 |
- struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; |
|
243 |
- pv_value_t pv_val; |
|
244 |
- stat_var *stat; |
|
245 |
- |
|
246 |
- if (sopv->stat) { |
|
247 |
- reset_stat( sopv->stat ); |
|
248 |
- } else { |
|
249 |
- if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 || |
|
250 |
- (pv_val.flags & PV_VAL_STR)==0 ) { |
|
251 |
- LM_ERR("failed to get pv string value\n"); |
|
252 |
- return -1; |
|
253 |
- } |
|
254 |
- stat = get_stat( &(pv_val.rs) ); |
|
255 |
- if ( stat == 0 ) { |
|
256 |
- LM_ERR("variable <%.*s> not defined\n", |
|
257 |
- pv_val.rs.len, pv_val.rs.s); |
|
258 |
- return -1; |
|
259 |
- } |
|
260 |
- reset_stat( stat ); |
|
261 |
- } |
|
262 |
- |
|
263 |
- |
|
264 |
- return 1; |
|
265 |
-} |
|
266 |
- |
|
267 |
- |
... | ... |
@@ -172,7 +172,7 @@ static int fixup_stat(void** param, int param_no) |
172 | 172 |
} |
173 | 173 |
|
174 | 174 |
if (err==0){ |
175 |
- if (n==0) { |
|
175 |
+ if (n==0 && (s.s[0]!='$')) { //we can't check the value of the pvar so have to ignore this check if it is a pvar |
|
176 | 176 |
LM_ERR("update with 0 has no sense\n"); |
177 | 177 |
return E_CFG; |
178 | 178 |
} |
... | ... |
@@ -52,6 +52,11 @@ struct stat_or_pv { |
52 | 52 |
pv_spec_t *pv; |
53 | 53 |
}; |
54 | 54 |
|
55 |
+struct long_or_pv { |
|
56 |
+ long val; |
|
57 |
+ pv_spec_t *pv; |
|
58 |
+}; |
|
59 |
+ |
|
55 | 60 |
|
56 | 61 |
|
57 | 62 |
static cmd_export_t cmds[]={ |
... | ... |
@@ -106,9 +111,10 @@ static int mod_init(void) |
106 | 111 |
static int fixup_stat(void** param, int param_no) |
107 | 112 |
{ |
108 | 113 |
struct stat_or_pv *sopv; |
114 |
+ struct long_or_pv *lopv; |
|
109 | 115 |
str s; |
110 | 116 |
long n; |
111 |
- int err; |
|
117 |
+ int err = 0; |
|
112 | 118 |
|
113 | 119 |
s.s = (char*)*param; |
114 | 120 |
s.len = strlen(s.s); |
... | ... |
@@ -139,21 +145,39 @@ static int fixup_stat(void** param, int param_no) |
139 | 145 |
*param=(void*)sopv; |
140 | 146 |
return 0; |
141 | 147 |
} else if (param_no==2) { |
142 |
- /* update value - integer */ |
|
143 |
- if (s.s[0]=='-' || s.s[0]=='+') { |
|
144 |
- n = str2s( s.s+1, s.len-1, &err); |
|
145 |
- if (s.s[0]=='-') |
|
146 |
- n = -n; |
|
148 |
+ lopv = (struct long_or_pv *) pkg_malloc(sizeof(struct long_or_pv)); |
|
149 |
+ if (lopv == NULL) { |
|
150 |
+ LM_ERR("no more pkg mem\n"); |
|
151 |
+ return E_OUT_OF_MEM; |
|
152 |
+ } |
|
153 |
+ memset(lopv, 0, sizeof(struct long_or_pv)); |
|
154 |
+ /* is it pv? */ |
|
155 |
+ if (s.s[0] == '$') { |
|
156 |
+ if (fixup_pvar_pvar(param, 2) != 0) { |
|
157 |
+ LM_ERR("invalid pv %s as parameter\n",s.s); |
|
158 |
+ return E_CFG; |
|
159 |
+ } |
|
160 |
+ lopv->pv = (pv_spec_t*) (*param); |
|
147 | 161 |
} else { |
148 |
- n = str2s( s.s, s.len, &err); |
|
162 |
+ /* it is string */ |
|
163 |
+ /* update value - integer */ |
|
164 |
+ if (s.s[0] == '-' || s.s[0] == '+') { |
|
165 |
+ n = str2s(s.s + 1, s.len - 1, &err); |
|
166 |
+ if (s.s[0] == '-') |
|
167 |
+ n = -n; |
|
168 |
+ } else { |
|
169 |
+ n = str2s(s.s, s.len, &err); |
|
170 |
+ } |
|
171 |
+ lopv->val = n; |
|
149 | 172 |
} |
173 |
+ |
|
150 | 174 |
if (err==0){ |
151 | 175 |
if (n==0) { |
152 | 176 |
LM_ERR("update with 0 has no sense\n"); |
153 | 177 |
return E_CFG; |
154 | 178 |
} |
155 |
- pkg_free(*param); |
|
156 |
- *param=(void*)n; |
|
179 |
+ pkg_free(s.s); |
|
180 |
+ *param=(void*)lopv; |
|
157 | 181 |
return 0; |
158 | 182 |
}else{ |
159 | 183 |
LM_ERR("bad update number <%s>\n",(char*)(*param)); |
... | ... |
@@ -164,11 +188,33 @@ static int fixup_stat(void** param, int param_no) |
164 | 188 |
} |
165 | 189 |
|
166 | 190 |
|
167 |
-static int w_update_stat(struct sip_msg *msg, char *stat_p, char *n) |
|
191 |
+static int w_update_stat(struct sip_msg *msg, char *stat_p, char *long_p) |
|
168 | 192 |
{ |
169 | 193 |
struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; |
194 |
+ struct long_or_pv *lopv = (struct long_or_pv *)long_p; |
|
170 | 195 |
pv_value_t pv_val; |
171 | 196 |
stat_var *stat; |
197 |
+ long n = 0; |
|
198 |
+ int err; |
|
199 |
+ |
|
200 |
+ if (lopv->val) { |
|
201 |
+ n=lopv->val; |
|
202 |
+ } else { |
|
203 |
+ if (pv_get_spec_value(msg, lopv->pv, &pv_val) != 0 || (pv_val.flags & PV_VAL_STR) == 0) { |
|
204 |
+ LM_ERR("failed to get pv string value\n"); |
|
205 |
+ return -1; |
|
206 |
+ } |
|
207 |
+ str s = pv_val.rs; |
|
208 |
+ /* it is string */ |
|
209 |
+ /* update value - integer */ |
|
210 |
+ if (s.s[0] == '-' || s.s[0] == '+') { |
|
211 |
+ n = str2s(s.s + 1, s.len - 1, &err); |
|
212 |
+ if (s.s[0] == '-') |
|
213 |
+ n = -n; |
|
214 |
+ } else { |
|
215 |
+ n = str2s(s.s, s.len, &err); |
|
216 |
+ } |
|
217 |
+ } |
|
172 | 218 |
|
173 | 219 |
if (sopv->stat) { |
174 | 220 |
update_stat( sopv->stat, (long)n); |
... | ... |
@@ -56,7 +56,7 @@ struct stat_or_pv { |
56 | 56 |
|
57 | 57 |
static cmd_export_t cmds[]={ |
58 | 58 |
{"update_stat", (cmd_function)w_update_stat, 2, fixup_stat, 0, |
59 |
- REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, |
|
59 |
+ ANY_ROUTE}, |
|
60 | 60 |
{"reset_stat", (cmd_function)w_reset_stat, 1, fixup_stat, 0, |
61 | 61 |
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, |
62 | 62 |
{0,0,0,0,0,0} |
... | ... |
@@ -123,7 +123,7 @@ static int fixup_stat(void** param, int param_no) |
123 | 123 |
/* is it pv? */ |
124 | 124 |
if (s.s[0]=='$') { |
125 | 125 |
if (fixup_pvar_null(param, 1)!=0) { |
126 |
- LM_ERR("invalid pv %.s as parameter\n",s.s); |
|
126 |
+ LM_ERR("invalid pv %s as parameter\n",s.s); |
|
127 | 127 |
return E_CFG; |
128 | 128 |
} |
129 | 129 |
sopv->pv = (pv_spec_t*)(*param); |
- fixup_pvar() replaced by fixup_pvar_null()
... | ... |
@@ -122,7 +122,7 @@ static int fixup_stat(void** param, int param_no) |
122 | 122 |
memset( sopv, 0 , sizeof(struct stat_or_pv) ); |
123 | 123 |
/* is it pv? */ |
124 | 124 |
if (s.s[0]=='$') { |
125 |
- if (fixup_pvar(param)!=0) { |
|
125 |
+ if (fixup_pvar_null(param, 1)!=0) { |
|
126 | 126 |
LM_ERR("invalid pv %.s as parameter\n",s.s); |
127 | 127 |
return E_CFG; |
128 | 128 |
} |
This patch does two things:
* It links them modules with shared library libkcore which contains
all the statistics related stuff that was present in kamailio core and
is missing in the sip-router core.
* it fixes the path to statistics.h to point to the header in the shared
library.
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4657 689a6050-402a-0410-94f2-e92a70836424
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4518 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -5,14 +5,14 @@ |
5 | 5 |
* |
6 | 6 |
* Copyright (C) 2006 Voice Sistem S.R.L. |
7 | 7 |
* |
8 |
- * This file is part of openser, a free SIP server. |
|
8 |
+ * This file is part of Kamailio, a free SIP server. |
|
9 | 9 |
* |
10 |
- * openser is free software; you can redistribute it and/or modify |
|
10 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
11 | 11 |
* it under the terms of the GNU General Public License as published by |
12 | 12 |
* the Free Software Foundation; either version 2 of the License, or |
13 | 13 |
* (at your option) any later version |
14 | 14 |
* |
15 |
- * openser is distributed in the hope that it will be useful, |
|
15 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
16 | 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | 18 |
* GNU General Public License for more details. |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4367 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -56,9 +56,9 @@ struct stat_or_pv { |
56 | 56 |
|
57 | 57 |
static cmd_export_t cmds[]={ |
58 | 58 |
{"update_stat", (cmd_function)w_update_stat, 2, fixup_stat, 0, |
59 |
- REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
|
59 |
+ REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, |
|
60 | 60 |
{"reset_stat", (cmd_function)w_reset_stat, 1, fixup_stat, 0, |
61 |
- REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
|
61 |
+ REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, |
|
62 | 62 |
{0,0,0,0,0,0} |
63 | 63 |
}; |
64 | 64 |
|
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4316 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -34,6 +34,7 @@ |
34 | 34 |
#include "../../sr_module.h" |
35 | 35 |
#include "../../dprint.h" |
36 | 36 |
#include "../../ut.h" |
37 |
+#include "../../mod_fix.h" |
|
37 | 38 |
#include "../../statistics.h" |
38 | 39 |
#include "../../mem/mem.h" |
39 | 40 |
#include "stats_funcs.h" |
... | ... |
@@ -46,6 +47,12 @@ static int w_update_stat(struct sip_msg* msg, char* stat, char* n); |
46 | 47 |
static int w_reset_stat(struct sip_msg* msg, char* stat, char* foo); |
47 | 48 |
static int fixup_stat(void** param, int param_no); |
48 | 49 |
|
50 |
+struct stat_or_pv { |
|
51 |
+ stat_var *stat; |
|
52 |
+ pv_spec_t *pv; |
|
53 |
+}; |
|
54 |
+ |
|
55 |
+ |
|
49 | 56 |
|
50 | 57 |
static cmd_export_t cmds[]={ |
51 | 58 |
{"update_stat", (cmd_function)w_update_stat, 2, fixup_stat, 0, |
... | ... |
@@ -100,7 +107,7 @@ static int mod_init(void) |
100 | 107 |
|
101 | 108 |
static int fixup_stat(void** param, int param_no) |
102 | 109 |
{ |
103 |
- stat_var *stat; |
|
110 |
+ struct stat_or_pv *sopv; |
|
104 | 111 |
str s; |
105 | 112 |
long n; |
106 | 113 |
int err; |
... | ... |
@@ -108,15 +115,30 @@ static int fixup_stat(void** param, int param_no) |
108 | 115 |
s.s = (char*)*param; |
109 | 116 |
s.len = strlen(s.s); |
110 | 117 |
if (param_no==1) { |
111 |
- /* var name - string */ |
|
112 |
- stat = get_stat( &s ); |
|
113 |
- if (stat==0) { |
|
114 |
- LM_ERR("fixup_stat: variable <%s> not " |
|
115 |
- "defined\n", s.s); |
|
116 |
- return E_CFG; |
|
118 |
+ /* var name - string or pv */ |
|
119 |
+ sopv = (struct stat_or_pv *)pkg_malloc(sizeof(struct stat_or_pv)); |
|
120 |
+ if (sopv==NULL) { |
|
121 |
+ LM_ERR("no more pkg mem\n"); |
|
122 |
+ return E_OUT_OF_MEM; |
|
123 |
+ } |
|
124 |
+ memset( sopv, 0 , sizeof(struct stat_or_pv) ); |
|
125 |
+ /* is it pv? */ |
|
126 |
+ if (s.s[0]=='$') { |
|
127 |
+ if (fixup_pvar(param)!=0) { |
|
128 |
+ LM_ERR("invalid pv %.s as parameter\n",s.s); |
|
129 |
+ return E_CFG; |
|
130 |
+ } |
|
131 |
+ sopv->pv = (pv_spec_t*)(*param); |
|
132 |
+ } else { |
|
133 |
+ /* it is string */ |
|
134 |
+ sopv->stat = get_stat( &s ); |
|
135 |
+ if (sopv->stat==0) { |
|
136 |
+ LM_ERR("variable <%s> not defined\n", s.s); |
|
137 |
+ return E_CFG; |
|
138 |
+ } |
|
117 | 139 |
} |
118 |
- pkg_free(*param); |
|
119 |
- *param=(void*)stat; |
|
140 |
+ pkg_free(s.s); |
|
141 |
+ *param=(void*)sopv; |
|
120 | 142 |
return 0; |
121 | 143 |
} else if (param_no==2) { |
122 | 144 |
/* update value - integer */ |
... | ... |
@@ -144,16 +166,57 @@ static int fixup_stat(void** param, int param_no) |
144 | 166 |
} |
145 | 167 |
|
146 | 168 |
|
147 |
-static int w_update_stat(struct sip_msg *msg, char *stat, char *n) |
|
169 |
+static int w_update_stat(struct sip_msg *msg, char *stat_p, char *n) |
|
148 | 170 |
{ |
149 |
- update_stat( (stat_var*)stat, (long)n); |
|
171 |
+ struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; |
|
172 |
+ pv_value_t pv_val; |
|
173 |
+ stat_var *stat; |
|
174 |
+ |
|
175 |
+ if (sopv->stat) { |
|
176 |
+ update_stat( sopv->stat, (long)n); |
|
177 |
+ } else { |
|
178 |
+ if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 || |
|
179 |
+ (pv_val.flags & PV_VAL_STR)==0 ) { |
|
180 |
+ LM_ERR("failed to get pv string value\n"); |
|
181 |
+ return -1; |
|
182 |
+ } |
|
183 |
+ stat = get_stat( &(pv_val.rs) ); |
|
184 |
+ if ( stat == 0 ) { |
|
185 |
+ LM_ERR("variable <%.*s> not defined\n", |
|
186 |
+ pv_val.rs.len, pv_val.rs.s); |
|
187 |
+ return -1; |
|
188 |
+ } |
|
189 |
+ update_stat( stat, (long)n); |
|
190 |
+ } |
|
191 |
+ |
|
150 | 192 |
return 1; |
151 | 193 |
} |
152 | 194 |
|
153 | 195 |
|
154 |
-static int w_reset_stat(struct sip_msg *msg, char* stat, char *foo) |
|
196 |
+static int w_reset_stat(struct sip_msg *msg, char* stat_p, char *foo) |
|
155 | 197 |
{ |
156 |
- reset_stat( (stat_var*)stat ); |
|
198 |
+ struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; |
|
199 |
+ pv_value_t pv_val; |
|
200 |
+ stat_var *stat; |
|
201 |
+ |
|
202 |
+ if (sopv->stat) { |
|
203 |
+ reset_stat( sopv->stat ); |
|
204 |
+ } else { |
|
205 |
+ if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 || |
|
206 |
+ (pv_val.flags & PV_VAL_STR)==0 ) { |
|
207 |
+ LM_ERR("failed to get pv string value\n"); |
|
208 |
+ return -1; |
|
209 |
+ } |
|
210 |
+ stat = get_stat( &(pv_val.rs) ); |
|
211 |
+ if ( stat == 0 ) { |
|
212 |
+ LM_ERR("variable <%.*s> not defined\n", |
|
213 |
+ pv_val.rs.len, pv_val.rs.s); |
|
214 |
+ return -1; |
|
215 |
+ } |
|
216 |
+ reset_stat( stat ); |
|
217 |
+ } |
|
218 |
+ |
|
219 |
+ |
|
157 | 220 |
return 1; |
158 | 221 |
} |
159 | 222 |
|
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3441 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -48,9 +48,9 @@ static int fixup_stat(void** param, int param_no); |
48 | 48 |
|
49 | 49 |
|
50 | 50 |
static cmd_export_t cmds[]={ |
51 |
- {"update_stat", w_update_stat, 2, fixup_stat, 0, |
|
51 |
+ {"update_stat", (cmd_function)w_update_stat, 2, fixup_stat, 0, |
|
52 | 52 |
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
53 |
- {"reset_stat", w_reset_stat, 1, fixup_stat, 0, |
|
53 |
+ {"reset_stat", (cmd_function)w_reset_stat, 1, fixup_stat, 0, |
|
54 | 54 |
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
55 | 55 |
{0,0,0,0,0,0} |
56 | 56 |
}; |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2943 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -87,11 +87,10 @@ static int reg_param_stat( modparam_t type, void* val) |
87 | 87 |
|
88 | 88 |
static int mod_init(void) |
89 | 89 |
{ |
90 |
- LOG(L_INFO,"Statistics module - initializing\n"); |
|
90 |
+ LM_INFO("initializing\n"); |
|
91 | 91 |
|
92 | 92 |
if (register_all_mod_stats()!=0) { |
93 |
- LOG(L_ERR,"ERROR:statistics:mod_init: failed to register statistic " |
|
94 |
- "variables\n"); |
|
93 |
+ LM_ERR("failed to register statistic variables\n"); |
|
95 | 94 |
return E_UNSPEC; |
96 | 95 |
} |
97 | 96 |
return 0; |
... | ... |
@@ -112,7 +111,7 @@ static int fixup_stat(void** param, int param_no) |
112 | 111 |
/* var name - string */ |
113 | 112 |
stat = get_stat( &s ); |
114 | 113 |
if (stat==0) { |
115 |
- LOG(L_ERR,"ERROR:statistics:fixup_stat: variable <%s> not " |
|
114 |
+ LM_ERR("fixup_stat: variable <%s> not " |
|
116 | 115 |
"defined\n", s.s); |
117 | 116 |
return E_CFG; |
118 | 117 |
} |
... | ... |
@@ -130,16 +129,14 @@ static int fixup_stat(void** param, int param_no) |
130 | 129 |
} |
131 | 130 |
if (err==0){ |
132 | 131 |
if (n==0) { |
133 |
- LOG(L_ERR,"ERROR:statistics:fixup_stat: update with 0 has " |
|
134 |
- "no sense\n"); |
|
132 |
+ LM_ERR("update with 0 has no sense\n"); |
|
135 | 133 |
return E_CFG; |
136 | 134 |
} |
137 | 135 |
pkg_free(*param); |
138 | 136 |
*param=(void*)n; |
139 | 137 |
return 0; |
140 | 138 |
}else{ |
141 |
- LOG(L_ERR, "ERROR:statistics:fixup_stat: bad update number <%s>\n", |
|
142 |
- (char*)(*param)); |
|
139 |
+ LM_ERR("bad update number <%s>\n",(char*)(*param)); |
|
143 | 140 |
return E_CFG; |
144 | 141 |
} |
145 | 142 |
} |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2845 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -48,11 +48,11 @@ static int fixup_stat(void** param, int param_no); |
48 | 48 |
|
49 | 49 |
|
50 | 50 |
static cmd_export_t cmds[]={ |
51 |
- {"update_stat", w_update_stat, 2, fixup_stat, |
|
51 |
+ {"update_stat", w_update_stat, 2, fixup_stat, 0, |
|
52 | 52 |
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
53 |
- {"reset_stat", w_reset_stat, 1, fixup_stat, |
|
53 |
+ {"reset_stat", w_reset_stat, 1, fixup_stat, 0, |
|
54 | 54 |
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
55 |
- {0,0,0,0,0} |
|
55 |
+ {0,0,0,0,0,0} |
|
56 | 56 |
}; |
57 | 57 |
|
58 | 58 |
static param_export_t mod_params[]={ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2657 689a6050-402a-0410-94f2-e92a70836424
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2554 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -69,6 +69,7 @@ struct module_exports exports= { |
69 | 69 |
0, /* exported statistics */ |
70 | 70 |
0, /* exported MI functions */ |
71 | 71 |
0, /* exported pseudo-variables */ |
72 |
+ 0, /* extra processes */ |
|
72 | 73 |
mod_init, /* module initialization function */ |
73 | 74 |
0, /* reply processing function */ |
74 | 75 |
0, /* module destroy function */ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1282 689a6050-402a-0410-94f2-e92a70836424
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1266 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -67,6 +67,7 @@ struct module_exports exports= { |
67 | 67 |
mod_params, /* param exports */ |
68 | 68 |
0, /* exported statistics */ |
69 | 69 |
0, /* exported MI functions */ |
70 |
+ 0, /* exported pseudo-variables */ |
|
70 | 71 |
mod_init, /* module initialization function */ |
71 | 72 |
0, /* reply processing function */ |
72 | 73 |
0, /* module destroy function */ |
- all module migrated to the changes in the module_export
- some syncronizations fixes in the MI functions in imc module
- new module ported to the new MI - flatstore and pdt
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1165 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -66,6 +66,7 @@ struct module_exports exports= { |
66 | 66 |
cmds, /* exported functions */ |
67 | 67 |
mod_params, /* param exports */ |
68 | 68 |
0, /* exported statistics */ |
69 |
+ 0, /* exported MI functions */ |
|
69 | 70 |
mod_init, /* module initialization function */ |
70 | 71 |
0, /* reply processing function */ |
71 | 72 |
0, /* module destroy function */ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@743 689a6050-402a-0410-94f2-e92a70836424
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,159 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * statistics module - script interface to internal statistics manager |
|
5 |
+ * |
|
6 |
+ * Copyright (C) 2006 Voice Sistem S.R.L. |
|
7 |
+ * |
|
8 |
+ * This file is part of openser, a free SIP server. |
|
9 |
+ * |
|
10 |
+ * openser is free software; you can redistribute it and/or modify |
|
11 |
+ * it under the terms of the GNU General Public License as published by |
|
12 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
13 |
+ * (at your option) any later version |
|
14 |
+ * |
|
15 |
+ * openser 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 |
+ * History: |
|
25 |
+ * -------- |
|
26 |
+ * 2006-03-14 initial version (bogdan) |
|
27 |
+ */ |
|
28 |
+ |
|
29 |
+ |
|
30 |
+#include <stdio.h> |
|
31 |
+#include <string.h> |
|
32 |
+#include <stdlib.h> |
|
33 |
+ |
|
34 |
+#include "../../sr_module.h" |
|
35 |
+#include "../../dprint.h" |
|
36 |
+#include "../../ut.h" |
|
37 |
+#include "../../statistics.h" |
|
38 |
+#include "../../mem/mem.h" |
|
39 |
+#include "stats_funcs.h" |
|
40 |
+ |
|
41 |
+MODULE_VERSION |
|
42 |
+ |
|
43 |
+static int reg_param_stat( modparam_t type, void* val); |
|
44 |
+static int mod_init(void); |
|
45 |
+static int w_update_stat(struct sip_msg* msg, char* stat, char* n); |
|
46 |
+static int w_reset_stat(struct sip_msg* msg, char* stat, char* foo); |
|
47 |
+static int fixup_stat(void** param, int param_no); |
|
48 |
+ |
|
49 |
+ |
|
50 |
+static cmd_export_t cmds[]={ |
|
51 |
+ {"update_stat", w_update_stat, 2, fixup_stat, |
|
52 |
+ REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
|
53 |
+ {"reset_stat", w_reset_stat, 1, fixup_stat, |
|
54 |
+ REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, |
|
55 |
+ {0,0,0,0,0} |
|
56 |
+}; |
|
57 |
+ |
|
58 |
+static param_export_t mod_params[]={ |
|
59 |
+ { "variable", STR_PARAM|USE_FUNC_PARAM, (void*)reg_param_stat }, |
|
60 |
+ { 0,0,0 } |
|
61 |
+}; |
|
62 |
+ |
|
63 |
+ |
|
64 |
+struct module_exports exports= { |
|
65 |
+ "statistics", /* module's name */ |
|
66 |
+ cmds, /* exported functions */ |
|
67 |
+ mod_params, /* param exports */ |
|
68 |
+ 0, /* exported statistics */ |
|
69 |
+ mod_init, /* module initialization function */ |
|
70 |
+ 0, /* reply processing function */ |
|
71 |
+ 0, /* module destroy function */ |
|
72 |
+ 0 /* per-child init function */ |
|
73 |
+}; |
|
74 |
+ |
|
75 |
+ |
|
76 |
+ |
|
77 |
+static int reg_param_stat( modparam_t type, void* val) |
|
78 |
+{ |
|
79 |
+ return reg_statistic( (char*)val); |
|
80 |
+} |
|
81 |
+ |
|
82 |
+ |
|
83 |
+ |
|
84 |
+static int mod_init() |
|
85 |
+{ |
|
86 |
+ LOG(L_INFO,"Statistics module - initializing\n"); |
|
87 |
+ |
|
88 |
+ if (register_all_mod_stats()!=0) { |
|
89 |
+ LOG(L_ERR,"ERROR:statistics:mod_init: failed to register statistic " |
|
90 |
+ "variables\n"); |
|
91 |
+ return E_UNSPEC; |
|
92 |
+ } |
|
93 |
+ return 0; |
|
94 |
+} |
|
95 |
+ |
|
96 |
+ |
|
97 |
+ |
|
98 |
+static int fixup_stat(void** param, int param_no) |
|
99 |
+{ |
|
100 |
+ stat_var *stat; |
|
101 |
+ str s; |
|
102 |
+ long n; |
|
103 |
+ int err; |
|
104 |
+ |
|
105 |
+ s.s = (char*)*param; |
|
106 |
+ s.len = strlen(s.s); |
|
107 |
+ if (param_no==1) { |
|
108 |
+ /* var name - string */ |
|
109 |
+ stat = get_stat( &s ); |
|
110 |
+ if (stat==0) { |
|
111 |
+ LOG(L_ERR,"ERROR:statistics:fixup_stat: variable <%s> not " |
|
112 |
+ "defined\n", s.s); |
|
113 |
+ return E_CFG; |
|
114 |
+ } |
|
115 |
+ pkg_free(*param); |
|
116 |
+ *param=(void*)stat; |
|
117 |
+ return 0; |
|
118 |
+ } else if (param_no==2) { |
|
119 |
+ /* update value - integer */ |
|
120 |
+ if (s.s[0]=='-' || s.s[0]=='+') { |
|
121 |
+ n = str2s( s.s+1, s.len-1, &err); |
|
122 |
+ if (s.s[0]=='-') |
|
123 |
+ n = -n; |
|
124 |
+ } else { |
|
125 |
+ n = str2s( s.s, s.len, &err); |
|
126 |
+ } |
|
127 |
+ if (err==0){ |
|
128 |
+ if (n==0) { |
|
129 |
+ LOG(L_ERR,"ERROR:statistics:fixup_stat: update with 0 has " |
|
130 |
+ "no sense\n"); |
|
131 |
+ return E_CFG; |
|
132 |
+ } |
|
133 |
+ pkg_free(*param); |
|
134 |
+ *param=(void*)n; |
|
135 |
+ return 0; |
|
136 |
+ }else{ |
|
137 |
+ LOG(L_ERR, "ERROR:statistics:fixup_stat: bad update number <%s>\n", |
|
138 |
+ (char*)(*param)); |
|
139 |
+ return E_CFG; |
|
140 |
+ } |
|
141 |
+ } |
|
142 |
+ return 0; |
|
143 |
+} |
|
144 |
+ |
|
145 |
+ |
|
146 |
+static int w_update_stat(struct sip_msg *msg, char *stat, char *n) |
|
147 |
+{ |
|
148 |
+ update_stat( (stat_var*)stat, (long)n); |
|
149 |
+ return 1; |
|
150 |
+} |
|
151 |
+ |
|
152 |
+ |
|
153 |
+static int w_reset_stat(struct sip_msg *msg, char* stat, char *foo) |
|
154 |
+{ |
|
155 |
+ reset_stat( (stat_var*)stat ); |
|
156 |
+ return 1; |
|
157 |
+} |
|
158 |
+ |
|
159 |
+ |