e6bb316e6a687eeee6b49baf363150cebbf5a5ef
[sip-router] / src / modules / app_python / apy_kemi.c
1 /**
2  * Copyright (C) 2016 Daniel-Constantin Mierla (asipto.com)
3  *
4  * This file is part of Kamailio, a free SIP server.
5  *
6  * Kamailio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version
10  *
11  * Kamailio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <stdlib.h>
24
25 #include <Python.h>
26 #include <frameobject.h>
27
28 #include "../../core/dprint.h"
29 #include "../../core/route.h"
30 #include "../../core/fmsg.h"
31 #include "../../core/kemi.h"
32 #include "../../core/pvar.h"
33 #include "../../core/timer.h"
34 #include "../../core/mem/pkg.h"
35 #include "../../core/mem/shm.h"
36 #include "../../core/rpc.h"
37 #include "../../core/rpc_lookup.h"
38
39 #include "msgobj_struct.h"
40 #include "python_exec.h"
41 #include "apy_kemi_export.h"
42 #include "apy_kemi.h"
43
44 int *_sr_python_reload_version = NULL;
45 int _sr_python_local_version = 0;
46 extern str _sr_python_load_file;
47 extern int _apy_process_rank;
48
49 /**
50  *
51  */
52 int sr_kemi_config_engine_python(sip_msg_t *msg, int rtype, str *rname,
53                 str *rparam)
54 {
55         int ret;
56
57         ret = -1;
58         if(rtype==REQUEST_ROUTE) {
59                 if(rname!=NULL && rname->s!=NULL) {
60                         ret = apy_exec(msg, rname->s,
61                                         (rparam && rparam->s)?rparam->s:NULL, 0);
62                 } else {
63                         ret = apy_exec(msg, "ksr_request_route", NULL, 1);
64                 }
65         } else if(rtype==CORE_ONREPLY_ROUTE) {
66                 if(kemi_reply_route_callback.len>0) {
67                         ret = apy_exec(msg, kemi_reply_route_callback.s, NULL, 0);
68                 }
69         } else if(rtype==BRANCH_ROUTE) {
70                 if(rname!=NULL && rname->s!=NULL) {
71                         ret = apy_exec(msg, rname->s, NULL, 0);
72                 }
73         } else if(rtype==FAILURE_ROUTE) {
74                 if(rname!=NULL && rname->s!=NULL) {
75                         ret = apy_exec(msg, rname->s, NULL, 0);
76                 }
77         } else if(rtype==BRANCH_FAILURE_ROUTE) {
78                 if(rname!=NULL && rname->s!=NULL) {
79                         ret = apy_exec(msg, rname->s, NULL, 0);
80                 }
81         } else if(rtype==TM_ONREPLY_ROUTE) {
82                 if(rname!=NULL && rname->s!=NULL) {
83                         ret = apy_exec(msg, rname->s, NULL, 0);
84                 }
85         } else if(rtype==ONSEND_ROUTE) {
86                 if(kemi_onsend_route_callback.len>0) {
87                         ret = apy_exec(msg, kemi_onsend_route_callback.s, NULL, 0);
88                 }
89                 return 1;
90         } else if(rtype==EVENT_ROUTE) {
91                 if(rname!=NULL && rname->s!=NULL) {
92                         ret = apy_exec(msg, rname->s,
93                                         (rparam && rparam->s)?rparam->s:NULL, 0);
94                 }
95         } else {
96                 if(rname!=NULL) {
97                         LM_ERR("route type %d with name [%.*s] not implemented\n",
98                                 rtype, rname->len, rname->s);
99                 } else {
100                         LM_ERR("route type %d with no name not implemented\n",
101                                 rtype);
102                 }
103         }
104
105         if(rname!=NULL) {
106                 LM_DBG("execution of route type %d with name [%.*s] returned %d\n",
107                                 rtype, rname->len, rname->s, ret);
108         } else {
109                 LM_DBG("execution of route type %d with no name returned %d\n",
110                         rtype, ret);
111         }
112
113         return 1;
114 }
115
116 /**
117  *
118  */
119 PyObject *sr_kemi_apy_return_true(void)
120 {
121         Py_INCREF(Py_True);
122         return Py_True;
123 }
124
125 /**
126  *
127  */
128 PyObject *sr_kemi_apy_return_false(void)
129 {
130         Py_INCREF(Py_False);
131         return Py_False;
132 }
133
134 /**
135  *
136  */
137 PyObject *sr_apy_kemi_return_none(void)
138 {
139         Py_INCREF(Py_None);
140         return Py_None;
141 }
142
143 /**
144  *
145  */
146 PyObject *sr_kemi_apy_return_int(sr_kemi_t *ket, int rval)
147 {
148         if(ket!=NULL && ket->rtype==SR_KEMIP_BOOL) {
149                 if(rval==SR_KEMI_TRUE) {
150                         return sr_kemi_apy_return_true();
151                 } else {
152                         return sr_kemi_apy_return_false();
153                 }
154         }
155         return PyInt_FromLong((long)rval);
156 }
157
158 /**
159  *
160  */
161 PyObject *sr_apy_kemi_return_str(sr_kemi_t *ket, char *sval, int slen)
162 {
163         return PyString_FromStringAndSize(sval, slen);
164 }
165
166 /**
167  *
168  */
169 PyObject *sr_apy_kemi_exec_func_ex(sr_kemi_t *ket, PyObject *self,
170                         PyObject *args, int idx)
171 {
172         str fname;
173         int i;
174         int ret;
175         sr_kemi_val_t vps[SR_KEMI_PARAMS_MAX];
176         sr_apy_env_t *env_P;
177         sip_msg_t *lmsg = NULL;
178
179         env_P = sr_apy_env_get();
180
181         if(env_P==NULL) {
182                 LM_ERR("invalid Python environment attributes\n");
183                 return sr_kemi_apy_return_false();
184         }
185         if(env_P->msg==NULL) {
186                 lmsg = faked_msg_next();
187         } else {
188                 lmsg = env_P->msg;
189         }
190
191         if(ket->mname.len>0) {
192                 LM_DBG("execution of method: %.*s\n", ket->fname.len, ket->fname.s);
193         } else {
194                 LM_DBG("execution of method: %.*s.%.*s\n",
195                                 ket->mname.len, ket->mname.s,
196                                 ket->fname.len, ket->fname.s);
197         }
198         fname = ket->fname;
199
200         if(ket->ptypes[0]==SR_KEMIP_NONE) {
201                 ret = ((sr_kemi_fm_f)(ket->func))(lmsg);
202                 return sr_kemi_apy_return_int(ket, ret);
203         }
204
205         memset(vps, 0, SR_KEMI_PARAMS_MAX*sizeof(sr_kemi_val_t));
206         if(ket->ptypes[1]==SR_KEMIP_NONE) {
207                 i = 1;
208                 if(ket->ptypes[0]==SR_KEMIP_INT) {
209                         if(!PyArg_ParseTuple(args, "i:kemi-param-n", &vps[0].n)) {
210                                 LM_ERR("unable to retrieve int param %d\n", 0);
211                                 return sr_kemi_apy_return_false();
212                         }
213                         LM_DBG("param[%d] for: %.*s is int: %d\n", i,
214                                 fname.len, fname.s, vps[0].n);
215                 } else {
216                         if(!PyArg_ParseTuple(args, "s:kemi-param-s", &vps[0].s.s)) {
217                                 LM_ERR("unable to retrieve str param %d\n", 0);
218                                 return sr_kemi_apy_return_false();
219                         }
220                         vps[0].s.len = strlen(vps[0].s.s);
221                         LM_DBG("param[%d] for: %.*s is str: %.*s\n", i,
222                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s);
223                 }
224         } else if(ket->ptypes[2]==SR_KEMIP_NONE) {
225                 i = 2;
226                 if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_INT) {
227                         if(!PyArg_ParseTuple(args, "ii:kemi-param-nn", &vps[0].n, &vps[1].n)) {
228                                 LM_ERR("unable to retrieve int-int params %d\n", i);
229                                 return sr_kemi_apy_return_false();
230                         }
231                         LM_DBG("params[%d] for: %.*s are int-int: [%d] [%d]\n", i,
232                                 fname.len, fname.s, vps[0].n, vps[1].n);
233                 } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_STR) {
234                         if(!PyArg_ParseTuple(args, "is:kemi-param-ns", &vps[0].n, &vps[1].s.s)) {
235                                 LM_ERR("unable to retrieve int-str params %d\n", i);
236                                 return sr_kemi_apy_return_false();
237                         }
238                         vps[1].s.len = strlen(vps[1].s.s);
239                         LM_DBG("params[%d] for: %.*s are int-str: [%d] [%.*s]\n", i,
240                                 fname.len, fname.s, vps[0].n, vps[1].s.len, vps[1].s.s);
241                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_INT) {
242                         if(!PyArg_ParseTuple(args, "si:kemi-param-sn", &vps[0].s.s, &vps[1].n)) {
243                                 LM_ERR("unable to retrieve str-int params %d\n", i);
244                                 return sr_kemi_apy_return_false();
245                         }
246                         vps[0].s.len = strlen(vps[0].s.s);
247                         LM_DBG("params[%d] for: %.*s are str-int: [%.*s] [%d]\n", i,
248                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s, vps[1].n);
249                 } else {
250                         if(!PyArg_ParseTuple(args, "ss:kemi-param-ss", &vps[0].s.s, &vps[1].s.s)) {
251                                 LM_ERR("unable to retrieve str-str param %d\n", i);
252                                 return sr_kemi_apy_return_false();
253                         }
254                         vps[0].s.len = strlen(vps[0].s.s);
255                         vps[1].s.len = strlen(vps[1].s.s);
256                         LM_DBG("params[%d] for: %.*s are str: [%.*s] [%.*s]\n", i,
257                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s,
258                                 vps[1].s.len, vps[1].s.s);
259                 }
260
261         } else if(ket->ptypes[3]==SR_KEMIP_NONE) {
262                 i = 3;
263                 if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_INT
264                                 && ket->ptypes[2]==SR_KEMIP_INT) {
265                         if(!PyArg_ParseTuple(args, "iii:kemi-param-nnn", &vps[0].n,
266                                                 &vps[1].n, &vps[2].n)) {
267                                 LM_ERR("unable to retrieve int-int-int params %d\n", i);
268                                 return sr_kemi_apy_return_false();
269                         }
270                         LM_DBG("params[%d] for: %.*s are int-int-int: [%d] [%d] [%d]\n",
271                                         i, fname.len, fname.s, vps[0].n, vps[1].n, vps[2].n);
272                } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_INT
273                                && ket->ptypes[2]==SR_KEMIP_STR) {
274                        if(!PyArg_ParseTuple(args, "iis:kemi-param-nns", &vps[0].n,
275                                             &vps[1].n, &vps[2].s.s)) {
276                                LM_ERR("unable to retrieve int-int-str params %d\n", i);
277                                return sr_kemi_apy_return_false();
278                        }
279                        vps[2].s.len = strlen(vps[2].s.s);
280                        LM_DBG("params[%d] for: %.*s are int-int-str: [%d] [%d] [%.*s]\n", i,
281                                fname.len, fname.s, vps[0].n, vps[1].n, vps[2].s.len, vps[2].s.s);
282                 } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_STR
283                                 && ket->ptypes[2]==SR_KEMIP_INT) {
284                         if(!PyArg_ParseTuple(args, "isi:kemi-param-nsn", &vps[0].n,
285                                                 &vps[1].s.s, &vps[2].n)) {
286                                 LM_ERR("unable to retrieve int-str-int params %d\n", i);
287                                 return sr_kemi_apy_return_false();
288                         }
289                         vps[1].s.len = strlen(vps[1].s.s);
290                         LM_DBG("params[%d] for: %.*s are int-str-int: [%d] [%.*s] [%d]\n", i,
291                                 fname.len, fname.s, vps[0].n, vps[1].s.len, vps[1].s.s, vps[2].n);
292                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_INT
293                                 && ket->ptypes[2]==SR_KEMIP_INT) {
294                         if(!PyArg_ParseTuple(args, "sii:kemi-param-snn", &vps[0].s.s,
295                                                 &vps[1].n, &vps[2].n)) {
296                                 LM_ERR("unable to retrieve str-int-int params %d\n", i);
297                                 return sr_kemi_apy_return_false();
298                         }
299                         vps[0].s.len = strlen(vps[0].s.s);
300                         LM_DBG("params[%d] for: %.*s are str-int: [%.*s] [%d] [%d]\n", i,
301                                         fname.len, fname.s, vps[0].s.len, vps[0].s.s, vps[1].n,
302                                         vps[2].n);
303                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_STR
304                                 && ket->ptypes[2]==SR_KEMIP_INT) {
305                         if(!PyArg_ParseTuple(args, "ssi:kemi-param-ssn", &vps[0].s.s,
306                                                 &vps[1].s.s, &vps[2].n)) {
307                                 LM_ERR("unable to retrieve str-str-int param %d\n", i);
308                                 return sr_kemi_apy_return_false();
309                         }
310                         vps[0].s.len = strlen(vps[0].s.s);
311                         vps[1].s.len = strlen(vps[1].s.s);
312                         LM_DBG("params[%d] for: %.*s are str-str-int: [%.*s] [%.*s]"
313                                         " [%d]\n", i, fname.len, fname.s,
314                                         vps[0].s.len, vps[0].s.s,
315                                         vps[1].s.len, vps[1].s.s, vps[2].n);
316                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_STR
317                                 && ket->ptypes[2]==SR_KEMIP_STR) {
318                         if(!PyArg_ParseTuple(args, "sss:kemi-param-sss", &vps[0].s.s,
319                                                 &vps[1].s.s, &vps[2].s.s)) {
320                                 LM_ERR("unable to retrieve str-str-str param %d\n", i);
321                                 return sr_kemi_apy_return_false();
322                         }
323                         vps[0].s.len = strlen(vps[0].s.s);
324                         vps[1].s.len = strlen(vps[1].s.s);
325                         vps[2].s.len = strlen(vps[2].s.s);
326                         LM_DBG("params[%d] for: %.*s are str-str-int: [%.*s] [%.*s]"
327                                         " [%.*s]\n", i, fname.len, fname.s,
328                                         vps[0].s.len, vps[0].s.s,
329                                         vps[1].s.len, vps[1].s.s, vps[2].s.len, vps[2].s.s);
330                 } else {
331                         LM_ERR("not implemented yet\n");
332                         return sr_kemi_apy_return_false();
333                 }
334         } else if(ket->ptypes[4]==SR_KEMIP_NONE) {
335                 i = 4;
336                 if(ket->ptypes[0]==SR_KEMIP_STR
337                                 && ket->ptypes[1]==SR_KEMIP_STR
338                                 && ket->ptypes[2]==SR_KEMIP_STR
339                                 && ket->ptypes[3]==SR_KEMIP_STR) {
340                         if(!PyArg_ParseTuple(args, "ssss:kemi-param-ssss",
341                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s)) {
342                                 LM_ERR("unable to retrieve ssss params %d\n", i);
343                                 return sr_kemi_apy_return_false();
344                         }
345                         vps[0].s.len = strlen(vps[0].s.s);
346                         vps[1].s.len = strlen(vps[1].s.s);
347                         vps[2].s.len = strlen(vps[2].s.s);
348                         vps[3].s.len = strlen(vps[3].s.s);
349
350                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%s]\n",
351                                         i, fname.len, fname.s,
352                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].s.s);
353                 } else if(ket->ptypes[0]==SR_KEMIP_STR
354                                 && ket->ptypes[1]==SR_KEMIP_STR
355                                 && ket->ptypes[2]==SR_KEMIP_STR
356                                 && ket->ptypes[3]==SR_KEMIP_INT) {
357                         if(!PyArg_ParseTuple(args, "sssn:kemi-param-sssn",
358                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].n)) {
359                                 LM_ERR("unable to retrieve sssn params %d\n", i);
360                                 return sr_kemi_apy_return_false();
361                         }
362                         vps[0].s.len = strlen(vps[0].s.s);
363                         vps[1].s.len = strlen(vps[1].s.s);
364                         vps[2].s.len = strlen(vps[2].s.s);
365
366                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%d]\n",
367                                         i, fname.len, fname.s,
368                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].n);
369                 } else if(ket->ptypes[0]==SR_KEMIP_STR
370                                 && ket->ptypes[1]==SR_KEMIP_STR
371                                 && ket->ptypes[2]==SR_KEMIP_INT
372                                 && ket->ptypes[3]==SR_KEMIP_STR) {
373                         if(!PyArg_ParseTuple(args, "ssns:kemi-param-ssns",
374                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].s.s)) {
375                                 LM_ERR("unable to retrieve ssns params %d\n", i);
376                                 return sr_kemi_apy_return_false();
377                         }
378                         vps[0].s.len = strlen(vps[0].s.s);
379                         vps[1].s.len = strlen(vps[1].s.s);
380                         vps[3].s.len = strlen(vps[3].s.s);
381
382                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%s]\n",
383                                         i, fname.len, fname.s,
384                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].s.s);
385                 } else if(ket->ptypes[0]==SR_KEMIP_STR
386                                 && ket->ptypes[1]==SR_KEMIP_STR
387                                 && ket->ptypes[2]==SR_KEMIP_INT
388                                 && ket->ptypes[3]==SR_KEMIP_INT) {
389                         if(!PyArg_ParseTuple(args, "ssnn:kemi-param-ssnn",
390                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].n)) {
391                                 LM_ERR("unable to retrieve ssnn params %d\n", i);
392                                 return sr_kemi_apy_return_false();
393                         }
394                         vps[0].s.len = strlen(vps[0].s.s);
395                         vps[1].s.len = strlen(vps[1].s.s);
396
397                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%d]\n",
398                                         i, fname.len, fname.s,
399                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].n);
400                 } else if(ket->ptypes[0]==SR_KEMIP_STR
401                                 && ket->ptypes[1]==SR_KEMIP_INT
402                                 && ket->ptypes[2]==SR_KEMIP_STR
403                                 && ket->ptypes[3]==SR_KEMIP_STR) {
404                         if(!PyArg_ParseTuple(args, "snss:kemi-param-snss",
405                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].s.s)) {
406                                 LM_ERR("unable to retrieve snss params %d\n", i);
407                                 return sr_kemi_apy_return_false();
408                         }
409                         vps[0].s.len = strlen(vps[0].s.s);
410                         vps[2].s.len = strlen(vps[2].s.s);
411                         vps[3].s.len = strlen(vps[3].s.s);
412
413                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%s]\n",
414                                         i, fname.len, fname.s,
415                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].s.s);
416                 } else if(ket->ptypes[0]==SR_KEMIP_STR
417                                 && ket->ptypes[1]==SR_KEMIP_INT
418                                 && ket->ptypes[2]==SR_KEMIP_STR
419                                 && ket->ptypes[3]==SR_KEMIP_INT) {
420                         if(!PyArg_ParseTuple(args, "snsn:kemi-param-snsn",
421                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].n)) {
422                                 LM_ERR("unable to retrieve snsn params %d\n", i);
423                                 return sr_kemi_apy_return_false();
424                         }
425                         vps[0].s.len = strlen(vps[0].s.s);
426                         vps[2].s.len = strlen(vps[2].s.s);
427
428                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%d]\n",
429                                         i, fname.len, fname.s,
430                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].n);
431                 } else if(ket->ptypes[0]==SR_KEMIP_STR
432                                 && ket->ptypes[1]==SR_KEMIP_INT
433                                 && ket->ptypes[2]==SR_KEMIP_INT
434                                 && ket->ptypes[3]==SR_KEMIP_STR) {
435                         if(!PyArg_ParseTuple(args, "snns:kemi-param-snns",
436                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].s.s)) {
437                                 LM_ERR("unable to retrieve snns params %d\n", i);
438                                 return sr_kemi_apy_return_false();
439                         }
440                         vps[0].s.len = strlen(vps[0].s.s);
441                         vps[3].s.len = strlen(vps[3].s.s);
442
443                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%s]\n",
444                                         i, fname.len, fname.s,
445                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].s.s);
446                 } else if(ket->ptypes[0]==SR_KEMIP_STR
447                                 && ket->ptypes[1]==SR_KEMIP_INT
448                                 && ket->ptypes[2]==SR_KEMIP_INT
449                                 && ket->ptypes[3]==SR_KEMIP_INT) {
450                         if(!PyArg_ParseTuple(args, "snnn:kemi-param-snnn",
451                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].n)) {
452                                 LM_ERR("unable to retrieve snnn params %d\n", i);
453                                 return sr_kemi_apy_return_false();
454                         }
455                         vps[0].s.len = strlen(vps[0].s.s);
456
457                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%d]\n",
458                                         i, fname.len, fname.s,
459                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].n);
460                 } else if(ket->ptypes[0]==SR_KEMIP_INT
461                                 && ket->ptypes[1]==SR_KEMIP_STR
462                                 && ket->ptypes[2]==SR_KEMIP_STR
463                                 && ket->ptypes[3]==SR_KEMIP_STR) {
464                         if(!PyArg_ParseTuple(args, "nsss:kemi-param-nsss",
465                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s)) {
466                                 LM_ERR("unable to retrieve nsss params %d\n", i);
467                                 return sr_kemi_apy_return_false();
468                         }
469                         vps[1].s.len = strlen(vps[1].s.s);
470                         vps[2].s.len = strlen(vps[2].s.s);
471                         vps[3].s.len = strlen(vps[3].s.s);
472
473                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%s]\n",
474                                         i, fname.len, fname.s,
475                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].s.s);
476                 } else if(ket->ptypes[0]==SR_KEMIP_INT
477                                 && ket->ptypes[1]==SR_KEMIP_STR
478                                 && ket->ptypes[2]==SR_KEMIP_STR
479                                 && ket->ptypes[3]==SR_KEMIP_INT) {
480                         if(!PyArg_ParseTuple(args, "nssn:kemi-param-nssn",
481                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].n)) {
482                                 LM_ERR("unable to retrieve nssn params %d\n", i);
483                                 return sr_kemi_apy_return_false();
484                         }
485                         vps[1].s.len = strlen(vps[1].s.s);
486                         vps[2].s.len = strlen(vps[2].s.s);
487
488                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%d]\n",
489                                         i, fname.len, fname.s,
490                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].n);
491                 } else if(ket->ptypes[0]==SR_KEMIP_INT
492                                 && ket->ptypes[1]==SR_KEMIP_STR
493                                 && ket->ptypes[2]==SR_KEMIP_INT
494                                 && ket->ptypes[3]==SR_KEMIP_STR) {
495                         if(!PyArg_ParseTuple(args, "nsns:kemi-param-nsns",
496                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].s.s)) {
497                                 LM_ERR("unable to retrieve nsns params %d\n", i);
498                                 return sr_kemi_apy_return_false();
499                         }
500                         vps[1].s.len = strlen(vps[1].s.s);
501                         vps[3].s.len = strlen(vps[3].s.s);
502
503                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%s]\n",
504                                         i, fname.len, fname.s,
505                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].s.s);
506                 } else if(ket->ptypes[0]==SR_KEMIP_INT
507                                 && ket->ptypes[1]==SR_KEMIP_STR
508                                 && ket->ptypes[2]==SR_KEMIP_INT
509                                 && ket->ptypes[3]==SR_KEMIP_INT) {
510                         if(!PyArg_ParseTuple(args, "nsnn:kemi-param-nsnn",
511                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].n)) {
512                                 LM_ERR("unable to retrieve nsnn params %d\n", i);
513                                 return sr_kemi_apy_return_false();
514                         }
515                         vps[1].s.len = strlen(vps[1].s.s);
516
517                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%d]\n",
518                                         i, fname.len, fname.s,
519                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].n);
520                 } else if(ket->ptypes[0]==SR_KEMIP_INT
521                                 && ket->ptypes[1]==SR_KEMIP_INT
522                                 && ket->ptypes[2]==SR_KEMIP_STR
523                                 && ket->ptypes[3]==SR_KEMIP_STR) {
524                         if(!PyArg_ParseTuple(args, "nnss:kemi-param-nnss",
525                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].s.s)) {
526                                 LM_ERR("unable to retrieve nnss params %d\n", i);
527                                 return sr_kemi_apy_return_false();
528                         }
529                         vps[2].s.len = strlen(vps[2].s.s);
530                         vps[3].s.len = strlen(vps[3].s.s);
531
532                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%s]\n",
533                                         i, fname.len, fname.s,
534                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].s.s);
535                 } else if(ket->ptypes[0]==SR_KEMIP_INT
536                                 && ket->ptypes[1]==SR_KEMIP_INT
537                                 && ket->ptypes[2]==SR_KEMIP_STR
538                                 && ket->ptypes[3]==SR_KEMIP_INT) {
539                         if(!PyArg_ParseTuple(args, "nnsn:kemi-param-nnsn",
540                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].n)) {
541                                 LM_ERR("unable to retrieve nnsn params %d\n", i);
542                                 return sr_kemi_apy_return_false();
543                         }
544                         vps[2].s.len = strlen(vps[2].s.s);
545
546                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%d]\n",
547                                         i, fname.len, fname.s,
548                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].n);
549                 } else if(ket->ptypes[0]==SR_KEMIP_INT
550                                 && ket->ptypes[1]==SR_KEMIP_INT
551                                 && ket->ptypes[2]==SR_KEMIP_INT
552                                 && ket->ptypes[3]==SR_KEMIP_STR) {
553                         if(!PyArg_ParseTuple(args, "nnns:kemi-param-nnns",
554                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].s.s)) {
555                                 LM_ERR("unable to retrieve nnns params %d\n", i);
556                                 return sr_kemi_apy_return_false();
557                         }
558                         vps[3].s.len = strlen(vps[3].s.s);
559
560                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%s]\n",
561                                         i, fname.len, fname.s,
562                                         vps[0].n, vps[1].n, vps[2].n, vps[3].s.s);
563                 } else if(ket->ptypes[0]==SR_KEMIP_INT
564                                 && ket->ptypes[1]==SR_KEMIP_INT
565                                 && ket->ptypes[2]==SR_KEMIP_INT
566                                 && ket->ptypes[3]==SR_KEMIP_INT) {
567                         if(!PyArg_ParseTuple(args, "nnnn:kemi-param-nnnn",
568                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].n)) {
569                                 LM_ERR("unable to retrieve nnnn params %d\n", i);
570                                 return sr_kemi_apy_return_false();
571                         }
572
573                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%d]\n",
574                                         i, fname.len, fname.s,
575                                         vps[0].n, vps[1].n, vps[2].n, vps[3].n);
576                 } else {
577                         LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
578                         return sr_kemi_apy_return_false();
579                 }
580         } else if(ket->ptypes[5]==SR_KEMIP_NONE) {
581                 i = 5;
582                 if(ket->ptypes[0]==SR_KEMIP_STR
583                                 && ket->ptypes[1]==SR_KEMIP_STR
584                                 && ket->ptypes[2]==SR_KEMIP_STR
585                                 && ket->ptypes[3]==SR_KEMIP_STR
586                                 && ket->ptypes[4]==SR_KEMIP_STR) {
587                         if(!PyArg_ParseTuple(args, "sssss:kemi-param-sssss",
588                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
589                                 LM_ERR("unable to retrieve sssss params %d\n", i);
590                                 return sr_kemi_apy_return_false();
591                         }
592                         vps[0].s.len = strlen(vps[0].s.s);
593                         vps[1].s.len = strlen(vps[1].s.s);
594                         vps[2].s.len = strlen(vps[2].s.s);
595                         vps[3].s.len = strlen(vps[3].s.s);
596                         vps[4].s.len = strlen(vps[4].s.s);
597
598                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%s] [%s]\n",
599                                         i, fname.len, fname.s,
600                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].s.s);
601                 } else if(ket->ptypes[0]==SR_KEMIP_STR
602                                 && ket->ptypes[1]==SR_KEMIP_STR
603                                 && ket->ptypes[2]==SR_KEMIP_STR
604                                 && ket->ptypes[3]==SR_KEMIP_STR
605                                 && ket->ptypes[4]==SR_KEMIP_INT) {
606                         if(!PyArg_ParseTuple(args, "ssssn:kemi-param-ssssn",
607                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
608                                 LM_ERR("unable to retrieve ssssn params %d\n", i);
609                                 return sr_kemi_apy_return_false();
610                         }
611                         vps[0].s.len = strlen(vps[0].s.s);
612                         vps[1].s.len = strlen(vps[1].s.s);
613                         vps[2].s.len = strlen(vps[2].s.s);
614                         vps[3].s.len = strlen(vps[3].s.s);
615
616                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%s] [%d]\n",
617                                         i, fname.len, fname.s,
618                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].n);
619                 } else if(ket->ptypes[0]==SR_KEMIP_STR
620                                 && ket->ptypes[1]==SR_KEMIP_STR
621                                 && ket->ptypes[2]==SR_KEMIP_STR
622                                 && ket->ptypes[3]==SR_KEMIP_INT
623                                 && ket->ptypes[4]==SR_KEMIP_STR) {
624                         if(!PyArg_ParseTuple(args, "sssns:kemi-param-sssns",
625                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
626                                 LM_ERR("unable to retrieve sssns params %d\n", i);
627                                 return sr_kemi_apy_return_false();
628                         }
629                         vps[0].s.len = strlen(vps[0].s.s);
630                         vps[1].s.len = strlen(vps[1].s.s);
631                         vps[2].s.len = strlen(vps[2].s.s);
632                         vps[4].s.len = strlen(vps[4].s.s);
633
634                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%d] [%s]\n",
635                                         i, fname.len, fname.s,
636                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].s.s);
637                 } else if(ket->ptypes[0]==SR_KEMIP_STR
638                                 && ket->ptypes[1]==SR_KEMIP_STR
639                                 && ket->ptypes[2]==SR_KEMIP_STR
640                                 && ket->ptypes[3]==SR_KEMIP_INT
641                                 && ket->ptypes[4]==SR_KEMIP_INT) {
642                         if(!PyArg_ParseTuple(args, "sssnn:kemi-param-sssnn",
643                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
644                                 LM_ERR("unable to retrieve sssnn params %d\n", i);
645                                 return sr_kemi_apy_return_false();
646                         }
647                         vps[0].s.len = strlen(vps[0].s.s);
648                         vps[1].s.len = strlen(vps[1].s.s);
649                         vps[2].s.len = strlen(vps[2].s.s);
650
651                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%d] [%d]\n",
652                                         i, fname.len, fname.s,
653                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].n);
654                 } else if(ket->ptypes[0]==SR_KEMIP_STR
655                                 && ket->ptypes[1]==SR_KEMIP_STR
656                                 && ket->ptypes[2]==SR_KEMIP_INT
657                                 && ket->ptypes[3]==SR_KEMIP_STR
658                                 && ket->ptypes[4]==SR_KEMIP_STR) {
659                         if(!PyArg_ParseTuple(args, "ssnss:kemi-param-ssnss",
660                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
661                                 LM_ERR("unable to retrieve ssnss params %d\n", i);
662                                 return sr_kemi_apy_return_false();
663                         }
664                         vps[0].s.len = strlen(vps[0].s.s);
665                         vps[1].s.len = strlen(vps[1].s.s);
666                         vps[3].s.len = strlen(vps[3].s.s);
667                         vps[4].s.len = strlen(vps[4].s.s);
668
669                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%s] [%s]\n",
670                                         i, fname.len, fname.s,
671                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].s.s);
672                 } else if(ket->ptypes[0]==SR_KEMIP_STR
673                                 && ket->ptypes[1]==SR_KEMIP_STR
674                                 && ket->ptypes[2]==SR_KEMIP_INT
675                                 && ket->ptypes[3]==SR_KEMIP_STR
676                                 && ket->ptypes[4]==SR_KEMIP_INT) {
677                         if(!PyArg_ParseTuple(args, "ssnsn:kemi-param-ssnsn",
678                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
679                                 LM_ERR("unable to retrieve ssnsn params %d\n", i);
680                                 return sr_kemi_apy_return_false();
681                         }
682                         vps[0].s.len = strlen(vps[0].s.s);
683                         vps[1].s.len = strlen(vps[1].s.s);
684                         vps[3].s.len = strlen(vps[3].s.s);
685
686                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%s] [%d]\n",
687                                         i, fname.len, fname.s,
688                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].n);
689                 } else if(ket->ptypes[0]==SR_KEMIP_STR
690                                 && ket->ptypes[1]==SR_KEMIP_STR
691                                 && ket->ptypes[2]==SR_KEMIP_INT
692                                 && ket->ptypes[3]==SR_KEMIP_INT
693                                 && ket->ptypes[4]==SR_KEMIP_STR) {
694                         if(!PyArg_ParseTuple(args, "ssnns:kemi-param-ssnns",
695                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
696                                 LM_ERR("unable to retrieve ssnns params %d\n", i);
697                                 return sr_kemi_apy_return_false();
698                         }
699                         vps[0].s.len = strlen(vps[0].s.s);
700                         vps[1].s.len = strlen(vps[1].s.s);
701                         vps[4].s.len = strlen(vps[4].s.s);
702
703                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%d] [%s]\n",
704                                         i, fname.len, fname.s,
705                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].n, vps[4].s.s);
706                 } else if(ket->ptypes[0]==SR_KEMIP_STR
707                                 && ket->ptypes[1]==SR_KEMIP_STR
708                                 && ket->ptypes[2]==SR_KEMIP_INT
709                                 && ket->ptypes[3]==SR_KEMIP_INT
710                                 && ket->ptypes[4]==SR_KEMIP_INT) {
711                         if(!PyArg_ParseTuple(args, "ssnnn:kemi-param-ssnnn",
712                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].n)) {
713                                 LM_ERR("unable to retrieve ssnnn params %d\n", i);
714                                 return sr_kemi_apy_return_false();
715                         }
716                         vps[0].s.len = strlen(vps[0].s.s);
717                         vps[1].s.len = strlen(vps[1].s.s);
718
719                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%d] [%d]\n",
720                                         i, fname.len, fname.s,
721                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].n, vps[4].n);
722                 } else if(ket->ptypes[0]==SR_KEMIP_STR
723                                 && ket->ptypes[1]==SR_KEMIP_INT
724                                 && ket->ptypes[2]==SR_KEMIP_STR
725                                 && ket->ptypes[3]==SR_KEMIP_STR
726                                 && ket->ptypes[4]==SR_KEMIP_STR) {
727                         if(!PyArg_ParseTuple(args, "snsss:kemi-param-snsss",
728                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
729                                 LM_ERR("unable to retrieve snsss params %d\n", i);
730                                 return sr_kemi_apy_return_false();
731                         }
732                         vps[0].s.len = strlen(vps[0].s.s);
733                         vps[2].s.len = strlen(vps[2].s.s);
734                         vps[3].s.len = strlen(vps[3].s.s);
735                         vps[4].s.len = strlen(vps[4].s.s);
736
737                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%s] [%s]\n",
738                                         i, fname.len, fname.s,
739                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].s.s);
740                 } else if(ket->ptypes[0]==SR_KEMIP_STR
741                                 && ket->ptypes[1]==SR_KEMIP_INT
742                                 && ket->ptypes[2]==SR_KEMIP_STR
743                                 && ket->ptypes[3]==SR_KEMIP_STR
744                                 && ket->ptypes[4]==SR_KEMIP_INT) {
745                         if(!PyArg_ParseTuple(args, "snssn:kemi-param-snssn",
746                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
747                                 LM_ERR("unable to retrieve snssn params %d\n", i);
748                                 return sr_kemi_apy_return_false();
749                         }
750                         vps[0].s.len = strlen(vps[0].s.s);
751                         vps[2].s.len = strlen(vps[2].s.s);
752                         vps[3].s.len = strlen(vps[3].s.s);
753
754                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%s] [%d]\n",
755                                         i, fname.len, fname.s,
756                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].n);
757                 } else if(ket->ptypes[0]==SR_KEMIP_STR
758                                 && ket->ptypes[1]==SR_KEMIP_INT
759                                 && ket->ptypes[2]==SR_KEMIP_STR
760                                 && ket->ptypes[3]==SR_KEMIP_INT
761                                 && ket->ptypes[4]==SR_KEMIP_STR) {
762                         if(!PyArg_ParseTuple(args, "snsns:kemi-param-snsns",
763                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
764                                 LM_ERR("unable to retrieve snsns params %d\n", i);
765                                 return sr_kemi_apy_return_false();
766                         }
767                         vps[0].s.len = strlen(vps[0].s.s);
768                         vps[2].s.len = strlen(vps[2].s.s);
769                         vps[4].s.len = strlen(vps[4].s.s);
770
771                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%d] [%s]\n",
772                                         i, fname.len, fname.s,
773                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].n, vps[4].s.s);
774                 } else if(ket->ptypes[0]==SR_KEMIP_STR
775                                 && ket->ptypes[1]==SR_KEMIP_INT
776                                 && ket->ptypes[2]==SR_KEMIP_STR
777                                 && ket->ptypes[3]==SR_KEMIP_INT
778                                 && ket->ptypes[4]==SR_KEMIP_INT) {
779                         if(!PyArg_ParseTuple(args, "snsnn:kemi-param-snsnn",
780                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
781                                 LM_ERR("unable to retrieve snsnn params %d\n", i);
782                                 return sr_kemi_apy_return_false();
783                         }
784                         vps[0].s.len = strlen(vps[0].s.s);
785                         vps[2].s.len = strlen(vps[2].s.s);
786
787                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%d] [%d]\n",
788                                         i, fname.len, fname.s,
789                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].n, vps[4].n);
790                 } else if(ket->ptypes[0]==SR_KEMIP_STR
791                                 && ket->ptypes[1]==SR_KEMIP_INT
792                                 && ket->ptypes[2]==SR_KEMIP_INT
793                                 && ket->ptypes[3]==SR_KEMIP_STR
794                                 && ket->ptypes[4]==SR_KEMIP_STR) {
795                         if(!PyArg_ParseTuple(args, "snnss:kemi-param-snnss",
796                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
797                                 LM_ERR("unable to retrieve snnss params %d\n", i);
798                                 return sr_kemi_apy_return_false();
799                         }
800                         vps[0].s.len = strlen(vps[0].s.s);
801                         vps[3].s.len = strlen(vps[3].s.s);
802                         vps[4].s.len = strlen(vps[4].s.s);
803
804                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%s] [%s]\n",
805                                         i, fname.len, fname.s,
806                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].s.s, vps[4].s.s);
807                 } else if(ket->ptypes[0]==SR_KEMIP_STR
808                                 && ket->ptypes[1]==SR_KEMIP_INT
809                                 && ket->ptypes[2]==SR_KEMIP_INT
810                                 && ket->ptypes[3]==SR_KEMIP_STR
811                                 && ket->ptypes[4]==SR_KEMIP_INT) {
812                         if(!PyArg_ParseTuple(args, "snnsn:kemi-param-snnsn",
813                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
814                                 LM_ERR("unable to retrieve snnsn params %d\n", i);
815                                 return sr_kemi_apy_return_false();
816                         }
817                         vps[0].s.len = strlen(vps[0].s.s);
818                         vps[3].s.len = strlen(vps[3].s.s);
819
820                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%s] [%d]\n",
821                                         i, fname.len, fname.s,
822                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].s.s, vps[4].n);
823                 } else if(ket->ptypes[0]==SR_KEMIP_STR
824                                 && ket->ptypes[1]==SR_KEMIP_INT
825                                 && ket->ptypes[2]==SR_KEMIP_INT
826                                 && ket->ptypes[3]==SR_KEMIP_INT
827                                 && ket->ptypes[4]==SR_KEMIP_STR) {
828                         if(!PyArg_ParseTuple(args, "snnns:kemi-param-snnns",
829                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
830                                 LM_ERR("unable to retrieve snnns params %d\n", i);
831                                 return sr_kemi_apy_return_false();
832                         }
833                         vps[0].s.len = strlen(vps[0].s.s);
834                         vps[4].s.len = strlen(vps[4].s.s);
835
836                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%d] [%s]\n",
837                                         i, fname.len, fname.s,
838                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].n, vps[4].s.s);
839                 } else if(ket->ptypes[0]==SR_KEMIP_STR
840                                 && ket->ptypes[1]==SR_KEMIP_INT
841                                 && ket->ptypes[2]==SR_KEMIP_INT
842                                 && ket->ptypes[3]==SR_KEMIP_INT
843                                 && ket->ptypes[4]==SR_KEMIP_INT) {
844                         if(!PyArg_ParseTuple(args, "snnnn:kemi-param-snnnn",
845                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].n)) {
846                                 LM_ERR("unable to retrieve snnnn params %d\n", i);
847                                 return sr_kemi_apy_return_false();
848                         }
849                         vps[0].s.len = strlen(vps[0].s.s);
850
851                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%d] [%d]\n",
852                                         i, fname.len, fname.s,
853                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
854                 } else if(ket->ptypes[0]==SR_KEMIP_INT
855                                 && ket->ptypes[1]==SR_KEMIP_STR
856                                 && ket->ptypes[2]==SR_KEMIP_STR
857                                 && ket->ptypes[3]==SR_KEMIP_STR
858                                 && ket->ptypes[4]==SR_KEMIP_STR) {
859                         if(!PyArg_ParseTuple(args, "nssss:kemi-param-nssss",
860                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
861                                 LM_ERR("unable to retrieve nssss params %d\n", i);
862                                 return sr_kemi_apy_return_false();
863                         }
864                         vps[1].s.len = strlen(vps[1].s.s);
865                         vps[2].s.len = strlen(vps[2].s.s);
866                         vps[3].s.len = strlen(vps[3].s.s);
867                         vps[4].s.len = strlen(vps[4].s.s);
868
869                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%s] [%s]\n",
870                                         i, fname.len, fname.s,
871                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].s.s);
872                 } else if(ket->ptypes[0]==SR_KEMIP_INT
873                                 && ket->ptypes[1]==SR_KEMIP_STR
874                                 && ket->ptypes[2]==SR_KEMIP_STR
875                                 && ket->ptypes[3]==SR_KEMIP_STR
876                                 && ket->ptypes[4]==SR_KEMIP_INT) {
877                         if(!PyArg_ParseTuple(args, "nsssn:kemi-param-nsssn",
878                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
879                                 LM_ERR("unable to retrieve nsssn params %d\n", i);
880                                 return sr_kemi_apy_return_false();
881                         }
882                         vps[1].s.len = strlen(vps[1].s.s);
883                         vps[2].s.len = strlen(vps[2].s.s);
884                         vps[3].s.len = strlen(vps[3].s.s);
885
886                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%s] [%d]\n",
887                                         i, fname.len, fname.s,
888                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].n);
889                 } else if(ket->ptypes[0]==SR_KEMIP_INT
890                                 && ket->ptypes[1]==SR_KEMIP_STR
891                                 && ket->ptypes[2]==SR_KEMIP_STR
892                                 && ket->ptypes[3]==SR_KEMIP_INT
893                                 && ket->ptypes[4]==SR_KEMIP_STR) {
894                         if(!PyArg_ParseTuple(args, "nssns:kemi-param-nssns",
895                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
896                                 LM_ERR("unable to retrieve nssns params %d\n", i);
897                                 return sr_kemi_apy_return_false();
898                         }
899                         vps[1].s.len = strlen(vps[1].s.s);
900                         vps[2].s.len = strlen(vps[2].s.s);
901                         vps[4].s.len = strlen(vps[4].s.s);
902
903                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%d] [%s]\n",
904                                         i, fname.len, fname.s,
905                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].s.s);
906                 } else if(ket->ptypes[0]==SR_KEMIP_INT
907                                 && ket->ptypes[1]==SR_KEMIP_STR
908                                 && ket->ptypes[2]==SR_KEMIP_STR
909                                 && ket->ptypes[3]==SR_KEMIP_INT
910                                 && ket->ptypes[4]==SR_KEMIP_INT) {
911                         if(!PyArg_ParseTuple(args, "nssnn:kemi-param-nssnn",
912                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
913                                 LM_ERR("unable to retrieve nssnn params %d\n", i);
914                                 return sr_kemi_apy_return_false();
915                         }
916                         vps[1].s.len = strlen(vps[1].s.s);
917                         vps[2].s.len = strlen(vps[2].s.s);
918
919                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%d] [%d]\n",
920                                         i, fname.len, fname.s,
921                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].n);
922                 } else if(ket->ptypes[0]==SR_KEMIP_INT
923                                 && ket->ptypes[1]==SR_KEMIP_STR
924                                 && ket->ptypes[2]==SR_KEMIP_INT
925                                 && ket->ptypes[3]==SR_KEMIP_STR
926                                 && ket->ptypes[4]==SR_KEMIP_STR) {
927                         if(!PyArg_ParseTuple(args, "nsnss:kemi-param-nsnss",
928                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
929                                 LM_ERR("unable to retrieve nsnss params %d\n", i);
930                                 return sr_kemi_apy_return_false();
931                         }
932                         vps[1].s.len = strlen(vps[1].s.s);
933                         vps[3].s.len = strlen(vps[3].s.s);
934                         vps[4].s.len = strlen(vps[4].s.s);
935
936                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%s] [%s]\n",
937                                         i, fname.len, fname.s,
938                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].s.s);
939                 } else if(ket->ptypes[0]==SR_KEMIP_INT
940                                 && ket->ptypes[1]==SR_KEMIP_STR
941                                 && ket->ptypes[2]==SR_KEMIP_INT
942                                 && ket->ptypes[3]==SR_KEMIP_STR
943                                 && ket->ptypes[4]==SR_KEMIP_INT) {
944                         if(!PyArg_ParseTuple(args, "nsnsn:kemi-param-nsnsn",
945                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
946                                 LM_ERR("unable to retrieve nsnsn params %d\n", i);
947                                 return sr_kemi_apy_return_false();
948                         }
949                         vps[1].s.len = strlen(vps[1].s.s);
950                         vps[3].s.len = strlen(vps[3].s.s);
951
952                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%s] [%d]\n",
953                                         i, fname.len, fname.s,
954                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].n);
955                 } else if(ket->ptypes[0]==SR_KEMIP_INT
956                                 && ket->ptypes[1]==SR_KEMIP_STR
957                                 && ket->ptypes[2]==SR_KEMIP_INT
958                                 && ket->ptypes[3]==SR_KEMIP_INT
959                                 && ket->ptypes[4]==SR_KEMIP_STR) {
960                         if(!PyArg_ParseTuple(args, "nsnns:kemi-param-nsnns",
961                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
962                                 LM_ERR("unable to retrieve nsnns params %d\n", i);
963                                 return sr_kemi_apy_return_false();
964                         }
965                         vps[1].s.len = strlen(vps[1].s.s);
966                         vps[4].s.len = strlen(vps[4].s.s);
967
968                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%d] [%s]\n",
969                                         i, fname.len, fname.s,
970                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].n, vps[4].s.s);
971                 } else if(ket->ptypes[0]==SR_KEMIP_INT
972                                 && ket->ptypes[1]==SR_KEMIP_STR
973                                 && ket->ptypes[2]==SR_KEMIP_INT
974                                 && ket->ptypes[3]==SR_KEMIP_INT
975                                 && ket->ptypes[4]==SR_KEMIP_INT) {
976                         if(!PyArg_ParseTuple(args, "nsnnn:kemi-param-nsnnn",
977                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].n)) {
978                                 LM_ERR("unable to retrieve nsnnn params %d\n", i);
979                                 return sr_kemi_apy_return_false();
980                         }
981                         vps[1].s.len = strlen(vps[1].s.s);
982
983                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%d] [%d]\n",
984                                         i, fname.len, fname.s,
985                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].n, vps[4].n);
986                 } else if(ket->ptypes[0]==SR_KEMIP_INT
987                                 && ket->ptypes[1]==SR_KEMIP_INT
988                                 && ket->ptypes[2]==SR_KEMIP_STR
989                                 && ket->ptypes[3]==SR_KEMIP_STR
990                                 && ket->ptypes[4]==SR_KEMIP_STR) {
991                         if(!PyArg_ParseTuple(args, "nnsss:kemi-param-nnsss",
992                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
993                                 LM_ERR("unable to retrieve nnsss params %d\n", i);
994                                 return sr_kemi_apy_return_false();
995                         }
996                         vps[2].s.len = strlen(vps[2].s.s);
997                         vps[3].s.len = strlen(vps[3].s.s);
998                         vps[4].s.len = strlen(vps[4].s.s);
999
1000                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%s] [%s]\n",
1001                                         i, fname.len, fname.s,
1002                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].s.s);
1003                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1004                                 && ket->ptypes[1]==SR_KEMIP_INT
1005                                 && ket->ptypes[2]==SR_KEMIP_STR
1006                                 && ket->ptypes[3]==SR_KEMIP_STR
1007                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1008                         if(!PyArg_ParseTuple(args, "nnssn:kemi-param-nnssn",
1009                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
1010                                 LM_ERR("unable to retrieve nnssn params %d\n", i);
1011                                 return sr_kemi_apy_return_false();
1012                         }
1013                         vps[2].s.len = strlen(vps[2].s.s);
1014                         vps[3].s.len = strlen(vps[3].s.s);
1015
1016                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%s] [%d]\n",
1017                                         i, fname.len, fname.s,
1018                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].n);
1019                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1020                                 && ket->ptypes[1]==SR_KEMIP_INT
1021                                 && ket->ptypes[2]==SR_KEMIP_STR
1022                                 && ket->ptypes[3]==SR_KEMIP_INT
1023                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1024                         if(!PyArg_ParseTuple(args, "nnsns:kemi-param-nnsns",
1025                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
1026                                 LM_ERR("unable to retrieve nnsns params %d\n", i);
1027                                 return sr_kemi_apy_return_false();
1028                         }
1029                         vps[2].s.len = strlen(vps[2].s.s);
1030                         vps[4].s.len = strlen(vps[4].s.s);
1031
1032                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%d] [%s]\n",
1033                                         i, fname.len, fname.s,
1034                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].n, vps[4].s.s);
1035                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1036                                 && ket->ptypes[1]==SR_KEMIP_INT
1037                                 && ket->ptypes[2]==SR_KEMIP_STR
1038                                 && ket->ptypes[3]==SR_KEMIP_INT
1039                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1040                         if(!PyArg_ParseTuple(args, "nnsnn:kemi-param-nnsnn",
1041                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
1042                                 LM_ERR("unable to retrieve nnsnn params %d\n", i);
1043                                 return sr_kemi_apy_return_false();
1044                         }
1045                         vps[2].s.len = strlen(vps[2].s.s);
1046
1047                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%d] [%d]\n",
1048                                         i, fname.len, fname.s,
1049                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].n, vps[4].n);
1050                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1051                                 && ket->ptypes[1]==SR_KEMIP_INT
1052                                 && ket->ptypes[2]==SR_KEMIP_INT
1053                                 && ket->ptypes[3]==SR_KEMIP_STR
1054                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1055                         if(!PyArg_ParseTuple(args, "nnnss:kemi-param-nnnss",
1056                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
1057                                 LM_ERR("unable to retrieve nnnss params %d\n", i);
1058                                 return sr_kemi_apy_return_false();
1059                         }
1060                         vps[3].s.len = strlen(vps[3].s.s);
1061                         vps[4].s.len = strlen(vps[4].s.s);
1062
1063                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%s] [%s]\n",
1064                                         i, fname.len, fname.s,
1065                                         vps[0].n, vps[1].n, vps[2].n, vps[3].s.s, vps[4].s.s);
1066                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1067                                 && ket->ptypes[1]==SR_KEMIP_INT
1068                                 && ket->ptypes[2]==SR_KEMIP_INT
1069                                 && ket->ptypes[3]==SR_KEMIP_STR
1070                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1071                         if(!PyArg_ParseTuple(args, "nnnsn:kemi-param-nnnsn",
1072                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
1073                                 LM_ERR("unable to retrieve nnnsn params %d\n", i);
1074                                 return sr_kemi_apy_return_false();
1075                         }
1076                         vps[3].s.len = strlen(vps[3].s.s);
1077
1078                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%s] [%d]\n",
1079                                         i, fname.len, fname.s,
1080                                         vps[0].n, vps[1].n, vps[2].n, vps[3].s.s, vps[4].n);
1081                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1082                                 && ket->ptypes[1]==SR_KEMIP_INT
1083                                 && ket->ptypes[2]==SR_KEMIP_INT
1084                                 && ket->ptypes[3]==SR_KEMIP_INT
1085                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1086                         if(!PyArg_ParseTuple(args, "nnnns:kemi-param-nnnns",
1087                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
1088                                 LM_ERR("unable to retrieve nnnns params %d\n", i);
1089                                 return sr_kemi_apy_return_false();
1090                         }
1091                         vps[4].s.len = strlen(vps[4].s.s);
1092
1093                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%d] [%s]\n",
1094                                         i, fname.len, fname.s,
1095                                         vps[0].n, vps[1].n, vps[2].n, vps[3].n, vps[4].s.s);
1096                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1097                                 && ket->ptypes[1]==SR_KEMIP_INT
1098                                 && ket->ptypes[2]==SR_KEMIP_INT
1099                                 && ket->ptypes[3]==SR_KEMIP_INT
1100                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1101                         if(!PyArg_ParseTuple(args, "nnnnn:kemi-param-nnnnn",
1102                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].n)) {
1103                                 LM_ERR("unable to retrieve nnnnn params %d\n", i);
1104                                 return sr_kemi_apy_return_false();
1105                         }
1106
1107                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%d] [%d]\n",
1108                                         i, fname.len, fname.s,
1109                                         vps[0].n, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
1110                 } else {
1111                         LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
1112                         return sr_kemi_apy_return_false();
1113                 }
1114         } else {
1115                 i = 6;
1116                 if(ket->ptypes[0]==SR_KEMIP_STR
1117                                 && ket->ptypes[1]==SR_KEMIP_STR
1118                                 && ket->ptypes[2]==SR_KEMIP_STR
1119                                 && ket->ptypes[3]==SR_KEMIP_STR
1120                                 && ket->ptypes[4]==SR_KEMIP_STR
1121                                 && ket->ptypes[5]==SR_KEMIP_STR) {
1122                         if(!PyArg_ParseTuple(args, "ssssss:kemi-param-ssssss",
1123                                                 &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s,
1124                                                 &vps[4].s.s, &vps[5].s.s)) {
1125                                 LM_ERR("unable to retrieve str-str-str-str params %d\n", i);
1126                                 return sr_kemi_apy_return_false();
1127                         }
1128                         vps[0].s.len = strlen(vps[0].s.s);
1129                         vps[1].s.len = strlen(vps[1].s.s);
1130                         vps[2].s.len = strlen(vps[2].s.s);
1131                         vps[3].s.len = strlen(vps[3].s.s);
1132                         vps[4].s.len = strlen(vps[4].s.s);
1133                         vps[5].s.len = strlen(vps[5].s.s);
1134                         LM_DBG("params[%d] for: %.*s are str: [%.*s] [%.*s]"
1135                                         " [%.*s] [%.*s] [%.*s] [%.*s]\n", i,
1136                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s,
1137                                 vps[1].s.len, vps[1].s.s, vps[2].s.len, vps[2].s.s,
1138                                 vps[3].s.len, vps[3].s.s, vps[4].s.len, vps[4].s.s,
1139                                 vps[5].s.len, vps[5].s.s);
1140                 } else {
1141                         LM_ERR("not implemented yet\n");
1142                         return sr_kemi_apy_return_false();
1143                 }
1144         }
1145
1146         switch(i) {
1147                 case 1:
1148                         if(ket->ptypes[0]==SR_KEMIP_INT) {
1149                                 ret = ((sr_kemi_fmn_f)(ket->func))(lmsg, vps[0].n);
1150                                 return sr_kemi_apy_return_int(ket, ret);
1151                         } else if(ket->ptypes[0]==SR_KEMIP_STR) {
1152                                 ret = ((sr_kemi_fms_f)(ket->func))(lmsg, &vps[0].s);
1153                                 return sr_kemi_apy_return_int(ket, ret);
1154                         } else {
1155                                 LM_ERR("invalid parameters for: %.*s\n",
1156                                                 fname.len, fname.s);
1157                                 return sr_kemi_apy_return_false();
1158                         }
1159                 break;
1160                 case 2:
1161                         if(ket->ptypes[0]==SR_KEMIP_INT) {
1162                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1163                                         ret = ((sr_kemi_fmnn_f)(ket->func))(lmsg, vps[0].n, vps[1].n);
1164                                         return sr_kemi_apy_return_int(ket, ret);
1165                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1166                                         ret = ((sr_kemi_fmns_f)(ket->func))(lmsg, vps[0].n, &vps[1].s);
1167                                         return sr_kemi_apy_return_int(ket, ret);
1168                                 } else {
1169                                         LM_ERR("invalid parameters for: %.*s\n",
1170                                                         fname.len, fname.s);
1171                                         return sr_kemi_apy_return_false();
1172                                 }
1173                         } else if(ket->ptypes[0]==SR_KEMIP_STR) {
1174                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1175                                         ret = ((sr_kemi_fmsn_f)(ket->func))(lmsg, &vps[0].s, vps[1].n);
1176                                         return sr_kemi_apy_return_int(ket, ret);
1177                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1178                                         ret = ((sr_kemi_fmss_f)(ket->func))(lmsg, &vps[0].s, &vps[1].s);
1179                                         return sr_kemi_apy_return_int(ket, ret);
1180                                 } else {
1181                                         LM_ERR("invalid parameters for: %.*s\n",
1182                                                         fname.len, fname.s);
1183                                         return sr_kemi_apy_return_false();
1184                                 }
1185                         } else {
1186                                 LM_ERR("invalid parameters for: %.*s\n",
1187                                                 fname.len, fname.s);
1188                                 return sr_kemi_apy_return_false();
1189                         }
1190                 break;
1191                 case 3:
1192                         if(ket->ptypes[0]==SR_KEMIP_INT) {
1193                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1194                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1195                                                 /* nnn */
1196                                                 ret = ((sr_kemi_fmnnn_f)(ket->func))(lmsg,
1197                                                                 vps[0].n, vps[1].n, vps[2].n);
1198                                                 return sr_kemi_apy_return_int(ket, ret);
1199                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1200                                                 /* nns */
1201                                                 ret = ((sr_kemi_fmnns_f)(ket->func))(lmsg,
1202                                                                 vps[0].n, vps[1].n, &vps[2].s);
1203                                                 return sr_kemi_apy_return_int(ket, ret);
1204                                         } else {
1205                                                 LM_ERR("invalid parameters for: %.*s\n",
1206                                                                 fname.len, fname.s);
1207                                                 return sr_kemi_apy_return_false();
1208                                         }
1209                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1210                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1211                                                 /* nsn */
1212                                                 ret = ((sr_kemi_fmnsn_f)(ket->func))(lmsg,
1213                                                                 vps[0].n, &vps[1].s, vps[2].n);
1214                                                 return sr_kemi_apy_return_int(ket, ret);
1215                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1216                                                 /* nss */
1217                                                 ret = ((sr_kemi_fmnss_f)(ket->func))(lmsg,
1218                                                                 vps[0].n, &vps[1].s, &vps[2].s);
1219                                                 return sr_kemi_apy_return_int(ket, ret);
1220                                         } else {
1221                                                 LM_ERR("invalid parameters for: %.*s\n",
1222                                                                 fname.len, fname.s);
1223                                                 return sr_kemi_apy_return_false();
1224                                         }
1225                                 } else {
1226                                         LM_ERR("invalid parameters for: %.*s\n",
1227                                                         fname.len, fname.s);
1228                                         return sr_kemi_apy_return_false();
1229                                 }
1230                         } else if(ket->ptypes[0]==SR_KEMIP_STR) {
1231                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1232                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1233                                                 /* snn */
1234                                                 ret = ((sr_kemi_fmsnn_f)(ket->func))(lmsg,
1235                                                                 &vps[0].s, vps[1].n, vps[2].n);
1236                                                 return sr_kemi_apy_return_int(ket, ret);
1237                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1238                                                 /* sns */
1239                                                 ret = ((sr_kemi_fmsns_f)(ket->func))(lmsg,
1240                                                                 &vps[0].s, vps[1].n, &vps[2].s);
1241                                                 return sr_kemi_apy_return_int(ket, ret);
1242                                         } else {
1243                                                 LM_ERR("invalid parameters for: %.*s\n",
1244                                                                 fname.len, fname.s);
1245                                                 return sr_kemi_apy_return_false();
1246                                         }
1247                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1248                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1249                                                 /* ssn */
1250                                                 ret = ((sr_kemi_fmssn_f)(ket->func))(lmsg,
1251                                                                 &vps[0].s, &vps[1].s, vps[2].n);
1252                                                 return sr_kemi_apy_return_int(ket, ret);
1253                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1254                                                 /* sss */
1255                                                 ret = ((sr_kemi_fmsss_f)(ket->func))(lmsg,
1256                                                                 &vps[0].s, &vps[1].s, &vps[2].s);
1257                                                 return sr_kemi_apy_return_int(ket, ret);
1258                                         } else {
1259                                                 LM_ERR("invalid parameters for: %.*s\n",
1260                                                                 fname.len, fname.s);
1261                                                 return sr_kemi_apy_return_false();
1262                                         }
1263                                 } else {
1264                                         LM_ERR("invalid parameters for: %.*s\n",
1265                                                         fname.len, fname.s);
1266                                         return sr_kemi_apy_return_false();
1267                                 }
1268                         } else {
1269                                 LM_ERR("invalid parameters for: %.*s\n",
1270                                                 fname.len, fname.s);
1271                                 return sr_kemi_apy_return_false();
1272                         }
1273                 break;
1274                 case 4:
1275                         if(ket->ptypes[0]==SR_KEMIP_STR
1276                                         && ket->ptypes[1]==SR_KEMIP_STR
1277                                         && ket->ptypes[2]==SR_KEMIP_STR
1278                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1279                                 ret = ((sr_kemi_fmssss_f)(ket->func))(lmsg,
1280                                                 &vps[0].s, &vps[1].s, &vps[2].s, &vps[3].s);
1281                                 return sr_kemi_apy_return_int(ket, ret);
1282                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1283                                         && ket->ptypes[1]==SR_KEMIP_STR
1284                                         && ket->ptypes[2]==SR_KEMIP_STR
1285                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1286                                 ret = ((sr_kemi_fmsssn_f)(ket->func))(lmsg,
1287                                                 &vps[0].s, &vps[1].s, &vps[2].s, vps[3].n);
1288                                 return sr_kemi_apy_return_int(ket, ret);
1289                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1290                                         && ket->ptypes[1]==SR_KEMIP_STR
1291                                         && ket->ptypes[2]==SR_KEMIP_INT
1292                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1293                                 ret = ((sr_kemi_fmssns_f)(ket->func))(lmsg,
1294                                                 &vps[0].s, &vps[1].s, vps[2].n, &vps[3].s);
1295                                 return sr_kemi_apy_return_int(ket, ret);
1296                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1297                                         && ket->ptypes[1]==SR_KEMIP_STR
1298                                         && ket->ptypes[2]==SR_KEMIP_INT
1299                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1300                                 ret = ((sr_kemi_fmssnn_f)(ket->func))(lmsg,
1301                                                 &vps[0].s, &vps[1].s, vps[2].n, vps[3].n);
1302                                 return sr_kemi_apy_return_int(ket, ret);
1303                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1304                                         && ket->ptypes[1]==SR_KEMIP_INT
1305                                         && ket->ptypes[2]==SR_KEMIP_STR
1306                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1307                                 ret = ((sr_kemi_fmsnss_f)(ket->func))(lmsg,
1308                                                 &vps[0].s, vps[1].n, &vps[2].s, &vps[3].s);
1309                                 return sr_kemi_apy_return_int(ket, ret);
1310                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1311                                         && ket->ptypes[1]==SR_KEMIP_INT
1312                                         && ket->ptypes[2]==SR_KEMIP_STR
1313                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1314                                 ret = ((sr_kemi_fmsnsn_f)(ket->func))(lmsg,
1315                                                 &vps[0].s, vps[1].n, &vps[2].s, vps[3].n);
1316                                 return sr_kemi_apy_return_int(ket, ret);
1317                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1318                                         && ket->ptypes[1]==SR_KEMIP_INT
1319                                         && ket->ptypes[2]==SR_KEMIP_INT
1320                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1321                                 ret = ((sr_kemi_fmsnns_f)(ket->func))(lmsg,
1322                                                 &vps[0].s, vps[1].n, vps[2].n, &vps[3].s);
1323                                 return sr_kemi_apy_return_int(ket, ret);
1324                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1325                                         && ket->ptypes[1]==SR_KEMIP_INT
1326                                         && ket->ptypes[2]==SR_KEMIP_INT
1327                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1328                                 ret = ((sr_kemi_fmsnnn_f)(ket->func))(lmsg,
1329                                                 &vps[0].s, vps[1].n, vps[2].n, vps[3].n);
1330                                 return sr_kemi_apy_return_int(ket, ret);
1331                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1332                                         && ket->ptypes[1]==SR_KEMIP_STR
1333                                         && ket->ptypes[2]==SR_KEMIP_STR
1334                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1335                                 ret = ((sr_kemi_fmnsss_f)(ket->func))(lmsg,
1336                                                 vps[0].n, &vps[1].s, &vps[2].s, &vps[3].s);
1337                                 return sr_kemi_apy_return_int(ket, ret);
1338                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1339                                         && ket->ptypes[1]==SR_KEMIP_STR
1340                                         && ket->ptypes[2]==SR_KEMIP_STR
1341                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1342                                 ret = ((sr_kemi_fmnssn_f)(ket->func))(lmsg,
1343                                                 vps[0].n, &vps[1].s, &vps[2].s, vps[3].n);
1344                                 return sr_kemi_apy_return_int(ket, ret);
1345                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1346                                         && ket->ptypes[1]==SR_KEMIP_STR
1347                                         && ket->ptypes[2]==SR_KEMIP_INT
1348                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1349                                 ret = ((sr_kemi_fmnsns_f)(ket->func))(lmsg,
1350                                                 vps[0].n, &vps[1].s, vps[2].n, &vps[3].s);
1351                                 return sr_kemi_apy_return_int(ket, ret);
1352                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1353                                         && ket->ptypes[1]==SR_KEMIP_STR
1354                                         && ket->ptypes[2]==SR_KEMIP_INT
1355                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1356                                 ret = ((sr_kemi_fmnsnn_f)(ket->func))(lmsg,
1357                                                 vps[0].n, &vps[1].s, vps[2].n, vps[3].n);
1358                                 return sr_kemi_apy_return_int(ket, ret);
1359                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1360                                         && ket->ptypes[1]==SR_KEMIP_INT
1361                                         && ket->ptypes[2]==SR_KEMIP_STR
1362                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1363                                 ret = ((sr_kemi_fmnnss_f)(ket->func))(lmsg,
1364                                                 vps[0].n, vps[1].n, &vps[2].s, &vps[3].s);
1365                                 return sr_kemi_apy_return_int(ket, ret);
1366                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1367                                         && ket->ptypes[1]==SR_KEMIP_INT
1368                                         && ket->ptypes[2]==SR_KEMIP_STR
1369                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1370                                 ret = ((sr_kemi_fmnnsn_f)(ket->func))(lmsg,
1371                                                 vps[0].n, vps[1].n, &vps[2].s, vps[3].n);
1372                                 return sr_kemi_apy_return_int(ket, ret);
1373                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1374                                         && ket->ptypes[1]==SR_KEMIP_INT
1375                                         && ket->ptypes[2]==SR_KEMIP_INT
1376                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1377                                 ret = ((sr_kemi_fmnnns_f)(ket->func))(lmsg,
1378                                                 vps[0].n, vps[1].n, vps[2].n, &vps[3].s);
1379                                 return sr_kemi_apy_return_int(ket, ret);
1380                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1381                                         && ket->ptypes[1]==SR_KEMIP_INT
1382                                         && ket->ptypes[2]==SR_KEMIP_INT
1383                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1384                                 ret = ((sr_kemi_fmnnnn_f)(ket->func))(lmsg,
1385                                                 vps[0].n, vps[1].n, vps[2].n, vps[3].n);
1386                                 return sr_kemi_apy_return_int(ket, ret);
1387                         } else {
1388                                 LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
1389                                 return sr_kemi_apy_return_false();
1390                         }
1391                 break;
1392                 case 5:
1393                         if(ket->ptypes[0]==SR_KEMIP_STR
1394                                         && ket->ptypes[1]==SR_KEMIP_STR
1395                                         && ket->ptypes[2]==SR_KEMIP_STR
1396                                         && ket->ptypes[3]==SR_KEMIP_STR
1397                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1398                                 ret = ((sr_kemi_fmsssss_f)(ket->func))(lmsg,
1399                                                 &vps[0].s, &vps[1].s, &vps[2].s, &vps[3].s, &vps[4].s);
1400                                 return sr_kemi_apy_return_int(ket, ret);
1401                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1402                                         && ket->ptypes[1]==SR_KEMIP_STR
1403                                         && ket->ptypes[2]==SR_KEMIP_STR
1404                                         && ket->ptypes[3]==SR_KEMIP_STR
1405                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1406                                 ret = ((sr_kemi_fmssssn_f)(ket->func))(lmsg,
1407                                                 &vps[0].s, &vps[1].s, &vps[2].s, &vps[3].s, vps[4].n);
1408                                 return sr_kemi_apy_return_int(ket, ret);
1409                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1410                                         && ket->ptypes[1]==SR_KEMIP_STR
1411                                         && ket->ptypes[2]==SR_KEMIP_STR
1412                                         && ket->ptypes[3]==SR_KEMIP_INT
1413                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1414                                 ret = ((sr_kemi_fmsssns_f)(ket->func))(lmsg,
1415                                                 &vps[0].s, &vps[1].s, &vps[2].s, vps[3].n, &vps[4].s);
1416                                 return sr_kemi_apy_return_int(ket, ret);
1417                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1418                                         && ket->ptypes[1]==SR_KEMIP_STR
1419                                         && ket->ptypes[2]==SR_KEMIP_STR
1420                                         && ket->ptypes[3]==SR_KEMIP_INT
1421                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1422                                 ret = ((sr_kemi_fmsssnn_f)(ket->func))(lmsg,
1423                                                 &vps[0].s, &vps[1].s, &vps[2].s, vps[3].n, vps[4].n);
1424                                 return sr_kemi_apy_return_int(ket, ret);
1425                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1426                                         && ket->ptypes[1]==SR_KEMIP_STR
1427                                         && ket->ptypes[2]==SR_KEMIP_INT
1428                                         && ket->ptypes[3]==SR_KEMIP_STR
1429                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1430                                 ret = ((sr_kemi_fmssnss_f)(ket->func))(lmsg,
1431                                                 &vps[0].s, &vps[1].s, vps[2].n, &vps[3].s, &vps[4].s);
1432                                 return sr_kemi_apy_return_int(ket, ret);
1433                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1434                                         && ket->ptypes[1]==SR_KEMIP_STR
1435                                         && ket->ptypes[2]==SR_KEMIP_INT
1436                                         && ket->ptypes[3]==SR_KEMIP_STR
1437                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1438                                 ret = ((sr_kemi_fmssnsn_f)(ket->func))(lmsg,
1439                                                 &vps[0].s, &vps[1].s, vps[2].n, &vps[3].s, vps[4].n);
1440                                 return sr_kemi_apy_return_int(ket, ret);
1441                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1442                                         && ket->ptypes[1]==SR_KEMIP_STR
1443                                         && ket->ptypes[2]==SR_KEMIP_INT
1444                                         && ket->ptypes[3]==SR_KEMIP_INT
1445                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1446                                 ret = ((sr_kemi_fmssnns_f)(ket->func))(lmsg,
1447                                                 &vps[0].s, &vps[1].s, vps[2].n, vps[3].n, &vps[4].s);
1448                                 return sr_kemi_apy_return_int(ket, ret);
1449                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1450                                         && ket->ptypes[1]==SR_KEMIP_STR
1451                                         && ket->ptypes[2]==SR_KEMIP_INT
1452                                         && ket->ptypes[3]==SR_KEMIP_INT
1453                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1454                                 ret = ((sr_kemi_fmssnnn_f)(ket->func))(lmsg,
1455                                                 &vps[0].s, &vps[1].s, vps[2].n, vps[3].n, vps[4].n);
1456                                 return sr_kemi_apy_return_int(ket, ret);
1457                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1458                                         && ket->ptypes[1]==SR_KEMIP_INT
1459                                         && ket->ptypes[2]==SR_KEMIP_STR
1460                                         && ket->ptypes[3]==SR_KEMIP_STR
1461                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1462                                 ret = ((sr_kemi_fmsnsss_f)(ket->func))(lmsg,
1463                                                 &vps[0].s, vps[1].n, &vps[2].s, &vps[3].s, &vps[4].s);
1464                                 return sr_kemi_apy_return_int(ket, ret);
1465                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1466                                         && ket->ptypes[1]==SR_KEMIP_INT
1467                                         && ket->ptypes[2]==SR_KEMIP_STR
1468                                         && ket->ptypes[3]==SR_KEMIP_STR
1469                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1470                                 ret = ((sr_kemi_fmsnssn_f)(ket->func))(lmsg,
1471                                                 &vps[0].s, vps[1].n, &vps[2].s, &vps[3].s, vps[4].n);
1472                                 return sr_kemi_apy_return_int(ket, ret);
1473                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1474                                         && ket->ptypes[1]==SR_KEMIP_INT
1475                                         && ket->ptypes[2]==SR_KEMIP_STR
1476                                         && ket->ptypes[3]==SR_KEMIP_INT
1477                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1478                                 ret = ((sr_kemi_fmsnsns_f)(ket->func))(lmsg,
1479                                                 &vps[0].s, vps[1].n, &vps[2].s, vps[3].n, &vps[4].s);
1480                                 return sr_kemi_apy_return_int(ket, ret);
1481                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1482                                         && ket->ptypes[1]==SR_KEMIP_INT
1483                                         && ket->ptypes[2]==SR_KEMIP_STR
1484                                         && ket->ptypes[3]==SR_KEMIP_INT
1485                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1486                                 ret = ((sr_kemi_fmsnsnn_f)(ket->func))(lmsg,
1487                                                 &vps[0].s, vps[1].n, &vps[2].s, vps[3].n, vps[4].n);
1488                                 return sr_kemi_apy_return_int(ket, ret);
1489                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1490                                         && ket->ptypes[1]==SR_KEMIP_INT
1491                                         && ket->ptypes[2]==SR_KEMIP_INT
1492                                         && ket->ptypes[3]==SR_KEMIP_STR
1493                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1494                                 ret = ((sr_kemi_fmsnnss_f)(ket->func))(lmsg,
1495                                                 &vps[0].s, vps[1].n, vps[2].n, &vps[3].s, &vps[4].s);
1496                                 return sr_kemi_apy_return_int(ket, ret);
1497                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1498                                         && ket->ptypes[1]==SR_KEMIP_INT
1499                                         && ket->ptypes[2]==SR_KEMIP_INT
1500                                         && ket->ptypes[3]==SR_KEMIP_STR
1501                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1502                                 ret = ((sr_kemi_fmsnnsn_f)(ket->func))(lmsg,
1503                                                 &vps[0].s, vps[1].n, vps[2].n, &vps[3].s, vps[4].n);
1504                                 return sr_kemi_apy_return_int(ket, ret);
1505                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1506                                         && ket->ptypes[1]==SR_KEMIP_INT
1507                                         && ket->ptypes[2]==SR_KEMIP_INT
1508                                         && ket->ptypes[3]==SR_KEMIP_INT
1509                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1510                                 ret = ((sr_kemi_fmsnnns_f)(ket->func))(lmsg,
1511                                                 &vps[0].s, vps[1].n, vps[2].n, vps[3].n, &vps[4].s);
1512                                 return sr_kemi_apy_return_int(ket, ret);
1513                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1514                                         && ket->ptypes[1]==SR_KEMIP_INT
1515                                         && ket->ptypes[2]==SR_KEMIP_INT
1516                                         && ket->ptypes[3]==SR_KEMIP_INT
1517                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1518                                 ret = ((sr_kemi_fmsnnnn_f)(ket->func))(lmsg,
1519                                                 &vps[0].s, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
1520                                 return sr_kemi_apy_return_int(ket, ret);
1521                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1522                                         && ket->ptypes[1]==SR_KEMIP_STR
1523                                         && ket->ptypes[2]==SR_KEMIP_STR
1524                                         && ket->ptypes[3]==SR_KEMIP_STR
1525                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1526                                 ret = ((sr_kemi_fmnssss_f)(ket->func))(lmsg,
1527                                                 vps[0].n, &vps[1].s, &vps[2].s, &vps[3].s, &vps[4].s);
1528                                 return sr_kemi_apy_return_int(ket, ret);
1529                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1530                                         && ket->ptypes[1]==SR_KEMIP_STR
1531                                         && ket->ptypes[2]==SR_KEMIP_STR
1532                                         && ket->ptypes[3]==SR_KEMIP_STR
1533                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1534                                 ret = ((sr_kemi_fmnsssn_f)(ket->func))(lmsg,
1535                                                 vps[0].n, &vps[1].s, &vps[2].s, &vps[3].s, vps[4].n);
1536                                 return sr_kemi_apy_return_int(ket, ret);
1537                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1538                                         && ket->ptypes[1]==SR_KEMIP_STR
1539                                         && ket->ptypes[2]==SR_KEMIP_STR
1540                                         && ket->ptypes[3]==SR_KEMIP_INT
1541                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1542                                 ret = ((sr_kemi_fmnssns_f)(ket->func))(lmsg,
1543                                                 vps[0].n, &vps[1].s, &vps[2].s, vps[3].n, &vps[4].s);
1544                                 return sr_kemi_apy_return_int(ket, ret);
1545                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1546                                         && ket->ptypes[1]==SR_KEMIP_STR
1547                                         && ket->ptypes[2]==SR_KEMIP_STR
1548                                         && ket->ptypes[3]==SR_KEMIP_INT
1549                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1550                                 ret = ((sr_kemi_fmnssnn_f)(ket->func))(lmsg,
1551                                                 vps[0].n, &vps[1].s, &vps[2].s, vps[3].n, vps[4].n);
1552                                 return sr_kemi_apy_return_int(ket, ret);
1553                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1554                                         && ket->ptypes[1]==SR_KEMIP_STR
1555                                         && ket->ptypes[2]==SR_KEMIP_INT
1556                                         && ket->ptypes[3]==SR_KEMIP_STR
1557                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1558                                 ret = ((sr_kemi_fmnsnss_f)(ket->func))(lmsg,
1559                                                 vps[0].n, &vps[1].s, vps[2].n, &vps[3].s, &vps[4].s);
1560                                 return sr_kemi_apy_return_int(ket, ret);
1561                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1562                                         && ket->ptypes[1]==SR_KEMIP_STR
1563                                         && ket->ptypes[2]==SR_KEMIP_INT
1564                                         && ket->ptypes[3]==SR_KEMIP_STR
1565                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1566                                 ret = ((sr_kemi_fmnsnsn_f)(ket->func))(lmsg,
1567                                                 vps[0].n, &vps[1].s, vps[2].n, &vps[3].s, vps[4].n);
1568                                 return sr_kemi_apy_return_int(ket, ret);
1569                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1570                                         && ket->ptypes[1]==SR_KEMIP_STR
1571                                         && ket->ptypes[2]==SR_KEMIP_INT
1572                                         && ket->ptypes[3]==SR_KEMIP_INT
1573                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1574                                 ret = ((sr_kemi_fmnsnns_f)(ket->func))(lmsg,
1575                                                 vps[0].n, &vps[1].s, vps[2].n, vps[3].n, &vps[4].s);
1576                                 return sr_kemi_apy_return_int(ket, ret);
1577                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1578                                         && ket->ptypes[1]==SR_KEMIP_STR
1579                                         && ket->ptypes[2]==SR_KEMIP_INT
1580                                         && ket->ptypes[3]==SR_KEMIP_INT
1581                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1582                                 ret = ((sr_kemi_fmnsnnn_f)(ket->func))(lmsg,
1583                                                 vps[0].n, &vps[1].s, vps[2].n, vps[3].n, vps[4].n);
1584                                 return sr_kemi_apy_return_int(ket, ret);
1585                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1586                                         && ket->ptypes[1]==SR_KEMIP_INT
1587                                         && ket->ptypes[2]==SR_KEMIP_STR
1588                                         && ket->ptypes[3]==SR_KEMIP_STR
1589                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1590                                 ret = ((sr_kemi_fmnnsss_f)(ket->func))(lmsg,
1591                                                 vps[0].n, vps[1].n, &vps[2].s, &vps[3].s, &vps[4].s);
1592                                 return sr_kemi_apy_return_int(ket, ret);
1593                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1594                                         && ket->ptypes[1]==SR_KEMIP_INT
1595                                         && ket->ptypes[2]==SR_KEMIP_STR
1596                                         && ket->ptypes[3]==SR_KEMIP_STR
1597                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1598                                 ret = ((sr_kemi_fmnnssn_f)(ket->func))(lmsg,
1599                                                 vps[0].n, vps[1].n, &vps[2].s, &vps[3].s, vps[4].n);
1600                                 return sr_kemi_apy_return_int(ket, ret);
1601                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1602                                         && ket->ptypes[1]==SR_KEMIP_INT
1603                                         && ket->ptypes[2]==SR_KEMIP_STR
1604                                         && ket->ptypes[3]==SR_KEMIP_INT
1605                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1606                                 ret = ((sr_kemi_fmnnsns_f)(ket->func))(lmsg,
1607                                                 vps[0].n, vps[1].n, &vps[2].s, vps[3].n, &vps[4].s);
1608                                 return sr_kemi_apy_return_int(ket, ret);
1609                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1610                                         && ket->ptypes[1]==SR_KEMIP_INT
1611                                         && ket->ptypes[2]==SR_KEMIP_STR
1612                                         && ket->ptypes[3]==SR_KEMIP_INT
1613                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1614                                 ret = ((sr_kemi_fmnnsnn_f)(ket->func))(lmsg,
1615                                                 vps[0].n, vps[1].n, &vps[2].s, vps[3].n, vps[4].n);
1616                                 return sr_kemi_apy_return_int(ket, ret);
1617                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1618                                         && ket->ptypes[1]==SR_KEMIP_INT
1619                                         && ket->ptypes[2]==SR_KEMIP_INT
1620                                         && ket->ptypes[3]==SR_KEMIP_STR
1621                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1622                                 ret = ((sr_kemi_fmnnnss_f)(ket->func))(lmsg,
1623                                                 vps[0].n, vps[1].n, vps[2].n, &vps[3].s, &vps[4].s);
1624                                 return sr_kemi_apy_return_int(ket, ret);
1625                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1626                                         && ket->ptypes[1]==SR_KEMIP_INT
1627                                         && ket->ptypes[2]==SR_KEMIP_INT
1628                                         && ket->ptypes[3]==SR_KEMIP_STR
1629                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1630                                 ret = ((sr_kemi_fmnnnsn_f)(ket->func))(lmsg,
1631                                                 vps[0].n, vps[1].n, vps[2].n, &vps[3].s, vps[4].n);
1632                                 return sr_kemi_apy_return_int(ket, ret);
1633                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1634                                         && ket->ptypes[1]==SR_KEMIP_INT
1635                                         && ket->ptypes[2]==SR_KEMIP_INT
1636                                         && ket->ptypes[3]==SR_KEMIP_INT
1637                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1638                                 ret = ((sr_kemi_fmnnnns_f)(ket->func))(lmsg,
1639                                                 vps[0].n, vps[1].n, vps[2].n, vps[3].n, &vps[4].s);
1640                                 return sr_kemi_apy_return_int(ket, ret);
1641                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1642                                         && ket->ptypes[1]==SR_KEMIP_INT
1643                                         && ket->ptypes[2]==SR_KEMIP_INT
1644                                         && ket->ptypes[3]==SR_KEMIP_INT
1645                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1646                                 ret = ((sr_kemi_fmnnnnn_f)(ket->func))(lmsg,
1647                                                 vps[0].n, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
1648                                 return sr_kemi_apy_return_int(ket, ret);
1649                         } else {
1650                                 LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
1651                                 return sr_kemi_apy_return_false();
1652                         }
1653                 break;
1654                 case 6:
1655                         if(ket->ptypes[0]==SR_KEMIP_STR
1656                                         && ket->ptypes[1]==SR_KEMIP_STR
1657                                         && ket->ptypes[2]==SR_KEMIP_STR
1658                                         && ket->ptypes[3]==SR_KEMIP_STR
1659                                         && ket->ptypes[4]==SR_KEMIP_STR
1660                                         && ket->ptypes[5]==SR_KEMIP_STR) {
1661                                 /* ssssss */
1662                                 ret = ((sr_kemi_fmssssss_f)(ket->func))(lmsg,
1663                                                 &vps[0].s, &vps[1].s, &vps[2].s, &vps[3].s,
1664                                                 &vps[4].s, &vps[5].s);
1665                                 return sr_kemi_apy_return_int(ket, ret);
1666                         } else {
1667                                 LM_ERR("invalid parameters for: %.*s\n",
1668                                                 fname.len, fname.s);
1669                                 return sr_kemi_apy_return_false();
1670                         }
1671                 break;
1672                 default:
1673                         LM_ERR("invalid parameters for: %.*s\n",
1674                                         fname.len, fname.s);
1675                         return sr_kemi_apy_return_false();
1676         }
1677 }
1678
1679 /**
1680  *
1681  */
1682 PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
1683 {
1684         sr_kemi_t *ket = NULL;
1685         PyObject *ret = NULL;
1686         PyThreadState *pstate = NULL;
1687         PyFrameObject *pframe = NULL;
1688         struct timeval tvb, tve;
1689         struct timezone tz;
1690         unsigned int tdiff;
1691
1692         ket = sr_apy_kemi_export_get(idx);
1693         if(ket==NULL) {
1694                 return sr_kemi_apy_return_false();
1695         }
1696         if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
1697                         && is_printable(cfg_get(core, core_cfg, latency_log))) {
1698                 gettimeofday(&tvb, &tz);
1699         }
1700
1701         ret = sr_apy_kemi_exec_func_ex(ket, self, args, idx);
1702
1703         if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
1704                         && is_printable(cfg_get(core, core_cfg, latency_log))) {
1705                 gettimeofday(&tve, &tz);
1706                 tdiff = (tve.tv_sec - tvb.tv_sec) * 1000000
1707                                    + (tve.tv_usec - tvb.tv_usec);
1708                 if(tdiff >= cfg_get(core, core_cfg, latency_limit_action)) {
1709                         pstate = PyThreadState_GET();
1710                         if (pstate != NULL && pstate->frame != NULL) {
1711                                 pframe = pstate->frame;
1712                         }
1713
1714                         LOG(cfg_get(core, core_cfg, latency_log),
1715                                         "alert - action KSR.%s%s%s(...)"
1716                                         " took too long [%u us] (file:%s func:%s line:%d)\n",
1717                                         (ket->mname.len>0)?ket->mname.s:"",
1718                                         (ket->mname.len>0)?".":"", ket->fname.s, tdiff,
1719                                         (pframe)?PyString_AsString(pframe->f_code->co_filename):"",
1720                                         (pframe)?PyString_AsString(pframe->f_code->co_name):"",
1721                                         (pframe)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0);
1722                 }
1723         }
1724
1725         return ret;
1726 }
1727
1728 /**
1729  *
1730  */
1731 PyObject *_sr_apy_ksr_module = NULL;
1732 PyObject *_sr_apy_ksr_module_dict = NULL;
1733 PyObject **_sr_apy_ksr_modules_list = NULL;
1734
1735 PyMethodDef *_sr_KSRMethods = NULL;
1736 #define SR_APY_KSR_MODULES_SIZE 256
1737 #define SR_APY_KSR_METHODS_SIZE (SR_APY_KEMI_EXPORT_SIZE + SR_APY_KSR_MODULES_SIZE)
1738
1739 /**
1740  *
1741  */
1742 static int sr_apy_kemi_f_ktest(sip_msg_t *msg, str *txt)
1743 {
1744         if(txt!=NULL && txt->s!=NULL)
1745                 LM_DBG("%.*s", txt->len, txt->s);
1746         return 0;
1747 }
1748
1749 /**
1750  *
1751  */
1752 static sr_kemi_t _sr_apy_kemi_test[] = {
1753         { str_init(""), str_init("ktest"),
1754                 SR_KEMIP_NONE, sr_apy_kemi_f_ktest,
1755                 { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1756                         SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1757         },
1758
1759         { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1760 };
1761
1762 /**
1763  *
1764  */
1765 PyObject *sr_apy_kemi_return_none_mode(int rmode)
1766 {
1767         if(rmode==1) {
1768                 return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
1769         } else if(rmode==2) {
1770                 return sr_apy_kemi_return_str(NULL, "", 0);
1771         } else {
1772                 return sr_apy_kemi_return_none();
1773         }
1774 }
1775
1776 /**
1777  *
1778  */
1779 static PyObject *sr_apy_kemi_f_pv_get_mode(PyObject *self, PyObject *args,
1780                 char *pfmt, int rmode)
1781 {
1782         str pvn;
1783         pv_spec_t *pvs;
1784         pv_value_t val;
1785         int pl;
1786         sr_apy_env_t *env_P;
1787         sip_msg_t *lmsg = NULL;
1788
1789         env_P = sr_apy_env_get();
1790
1791         if(env_P==NULL) {
1792                 LM_ERR("invalid Python environment attributes\n");
1793                 return sr_apy_kemi_return_none_mode(rmode);
1794         }
1795         if(env_P->msg==NULL) {
1796                 lmsg = faked_msg_next();
1797         } else {
1798                 lmsg = env_P->msg;
1799         }
1800
1801         if(!PyArg_ParseTuple(args, pfmt, &pvn.s)) {
1802                 LM_ERR("unable to retrieve str param\n");
1803                 return sr_apy_kemi_return_none_mode(rmode);
1804         }
1805
1806         if(pvn.s==NULL || lmsg==NULL) {
1807                 LM_ERR("invalid context attributes\n");
1808                 return sr_apy_kemi_return_none_mode(rmode);
1809         }
1810
1811         pvn.len = strlen(pvn.s);
1812         LM_DBG("pv get: %s\n", pvn.s);
1813         pl = pv_locate_name(&pvn);
1814         if(pl != pvn.len) {
1815                 LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
1816                 return sr_apy_kemi_return_none_mode(rmode);
1817         }
1818         pvs = pv_cache_get(&pvn);
1819         if(pvs==NULL) {
1820                 LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
1821                 return sr_apy_kemi_return_none_mode(rmode);
1822         }
1823         memset(&val, 0, sizeof(pv_value_t));
1824         if(pv_get_spec_value(lmsg, pvs, &val) != 0)
1825         {
1826                 LM_ERR("unable to get pv value for [%s]\n", pvn.s);
1827                 return sr_apy_kemi_return_none_mode(rmode);
1828         }
1829         if(val.flags&PV_VAL_NULL) {
1830                 return sr_apy_kemi_return_none_mode(rmode);
1831         }
1832         if(val.flags&PV_TYPE_INT) {
1833                 return sr_kemi_apy_return_int(NULL, val.ri);
1834         }
1835         return sr_apy_kemi_return_str(NULL, val.rs.s, val.rs.len);
1836 }
1837
1838 /**
1839  *
1840  */
1841 static PyObject *sr_apy_kemi_f_pv_get(PyObject *self, PyObject *args)
1842 {
1843         return sr_apy_kemi_f_pv_get_mode(self, args, "s:pv.get", 0);
1844 }
1845
1846 /**
1847  *
1848  */
1849 static PyObject *sr_apy_kemi_f_pv_getw(PyObject *self, PyObject *args)
1850 {
1851         return sr_apy_kemi_f_pv_get_mode(self, args, "s:pv.getw", 1);
1852 }
1853
1854 /**
1855  *
1856  */
1857 static PyObject *sr_apy_kemi_f_pv_gete(PyObject *self, PyObject *args)
1858 {
1859         return sr_apy_kemi_f_pv_get_mode(self, args, "s:pv.gete", 2);
1860 }
1861
1862 /**
1863  *
1864  */
1865 static PyObject *sr_apy_kemi_pv_push_valx(int rmode, int xival, str *xsval)
1866 {
1867         if(rmode==1) {
1868                 return sr_kemi_apy_return_int(NULL, xival);
1869         } else {
1870                 return sr_apy_kemi_return_str(NULL, xsval->s, xsval->len);
1871         }
1872 }
1873
1874 /**
1875  *
1876  */
1877 static PyObject *sr_apy_kemi_f_pv_get_valx(PyObject *self, PyObject *args,
1878         int rmode)
1879 {
1880         str pvn;
1881         pv_spec_t *pvs;
1882         pv_value_t val;
1883         int pl;
1884         sr_apy_env_t *env_P;
1885         sip_msg_t *lmsg = NULL;
1886         int xival = 0;
1887         str xsval = str_init("");
1888
1889         env_P = sr_apy_env_get();
1890
1891         if(env_P==NULL) {
1892                 LM_ERR("invalid Python environment attributes\n");
1893                 return sr_apy_kemi_return_none_mode(rmode);
1894         }
1895         if(env_P->msg==NULL) {
1896                 lmsg = faked_msg_next();
1897         } else {
1898                 lmsg = env_P->msg;
1899         }
1900
1901         memset(&val, 0, sizeof(pv_value_t));
1902         if(rmode==1) {
1903                 if(!PyArg_ParseTuple(args, "si:pv.getvn", &pvn.s, &xival)) {
1904                         LM_ERR("unable to retrieve str-int params\n");
1905                         return sr_apy_kemi_return_none_mode(rmode);
1906                 }
1907         } else {
1908                 if(!PyArg_ParseTuple(args, "ss:pv.getvs", &pvn.s, &xival)) {
1909                         LM_ERR("unable to retrieve str-int params\n");
1910                         return sr_apy_kemi_return_none_mode(rmode);
1911                 }
1912         }
1913
1914         if(pvn.s==NULL || lmsg==NULL) {
1915                 LM_ERR("invalid context attributes\n");
1916                 return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
1917         }
1918         val.flags |= PV_TYPE_INT|PV_VAL_INT;
1919         pvn.len = strlen(pvn.s);
1920
1921         LM_DBG("pv set: %s\n", pvn.s);
1922         pl = pv_locate_name(&pvn);
1923         if(pl != pvn.len) {
1924                 LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
1925                 return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
1926         }
1927         pvs = pv_cache_get(&pvn);
1928         if(pvs==NULL) {
1929                 LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
1930                 return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
1931         }
1932         memset(&val, 0, sizeof(pv_value_t));
1933         if(pv_get_spec_value(lmsg, pvs, &val) != 0) {
1934                 LM_ERR("unable to get pv value for [%s]\n", pvn.s);
1935                 return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
1936         }
1937         if(val.flags&PV_VAL_NULL) {
1938                 return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
1939         }
1940         if(val.flags&PV_TYPE_INT) {
1941                 return sr_kemi_apy_return_int(NULL, val.ri);
1942         }
1943         return sr_apy_kemi_return_str(NULL, val.rs.s, val.rs.len);
1944 }
1945
1946 /**
1947  *
1948  */
1949 static PyObject *sr_apy_kemi_f_pv_getvs(PyObject *self, PyObject *args)
1950 {
1951         return sr_apy_kemi_f_pv_get_valx(self, args, 0);
1952 }
1953
1954 /**
1955  *
1956  */
1957 static PyObject *sr_apy_kemi_f_pv_getvn(PyObject *self, PyObject *args)
1958 {
1959         return sr_apy_kemi_f_pv_get_valx(self, args, 1);
1960 }
1961
1962 /**
1963  *
1964  */
1965 static PyObject *sr_apy_kemi_f_pv_seti(PyObject *self, PyObject *args)
1966 {
1967         str pvn;
1968         pv_spec_t *pvs;
1969         pv_value_t val;
1970         int pl;
1971         sr_apy_env_t *env_P;
1972         sip_msg_t *lmsg = NULL;
1973
1974         env_P = sr_apy_env_get();
1975
1976         if(env_P==NULL) {
1977                 LM_ERR("invalid Python environment attributes\n");
1978                 return sr_kemi_apy_return_false();
1979         }
1980         if(env_P->msg==NULL) {
1981                 lmsg = faked_msg_next();
1982         } else {
1983                 lmsg = env_P->msg;
1984         }
1985
1986         memset(&val, 0, sizeof(pv_value_t));
1987         if(!PyArg_ParseTuple(args, "si:pv.seti", &pvn.s, &val.ri)) {
1988                 LM_ERR("unable to retrieve str-int params\n");
1989                 return sr_kemi_apy_return_false();
1990         }
1991
1992         if(pvn.s==NULL || lmsg==NULL) {
1993                 LM_ERR("invalid context attributes\n");
1994                 return sr_kemi_apy_return_false();
1995         }
1996         val.flags |= PV_TYPE_INT|PV_VAL_INT;
1997         pvn.len = strlen(pvn.s);
1998
1999         LM_DBG("pv set: %s\n", pvn.s);
2000         pl = pv_locate_name(&pvn);
2001         if(pl != pvn.len) {
2002                 LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
2003                 return sr_kemi_apy_return_false();
2004         }
2005         pvs = pv_cache_get(&pvn);
2006         if(pvs==NULL) {
2007                 LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
2008                 return sr_kemi_apy_return_false();
2009         }
2010         if(pv_set_spec_value(lmsg, pvs, 0, &val)<0)
2011         {
2012                 LM_ERR("unable to set pv [%s]\n", pvn.s);
2013                 return sr_kemi_apy_return_false();
2014         }
2015         return sr_kemi_apy_return_true();
2016 }
2017
2018 /**
2019  *
2020  */
2021 static PyObject *sr_apy_kemi_f_pv_sets(PyObject *self, PyObject *args)
2022 {
2023         str pvn;
2024         pv_spec_t *pvs;
2025         pv_value_t val;
2026         int pl;
2027         sr_apy_env_t *env_P;
2028         sip_msg_t *lmsg = NULL;
2029
2030         env_P = sr_apy_env_get();
2031
2032         if(env_P==NULL) {
2033                 LM_ERR("invalid Python environment attributes\n");
2034                 return sr_kemi_apy_return_false();
2035         }
2036         if(env_P->msg==NULL) {
2037                 lmsg = faked_msg_next();
2038         } else {
2039                 lmsg = env_P->msg;
2040         }
2041
2042         memset(&val, 0, sizeof(pv_value_t));
2043         if(!PyArg_ParseTuple(args, "ss:pv.sets", &pvn.s, &val.rs.s)) {
2044                 LM_ERR("unable to retrieve str-int params\n");
2045                 return sr_kemi_apy_return_false();
2046         }
2047
2048         if(pvn.s==NULL || val.rs.s==NULL || lmsg==NULL) {
2049                 LM_ERR("invalid context attributes\n");
2050                 return sr_kemi_apy_return_false();
2051         }
2052
2053         val.rs.len = strlen(val.rs.s);
2054         val.flags |= PV_VAL_STR;
2055
2056         pvn.len = strlen(pvn.s);
2057         LM_DBG("pv set: %s\n", pvn.s);
2058         pl = pv_locate_name(&pvn);
2059         if(pl != pvn.len) {
2060                 LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
2061                 return sr_kemi_apy_return_false();
2062         }
2063         pvs = pv_cache_get(&pvn);
2064         if(pvs==NULL) {
2065                 LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
2066                 return sr_kemi_apy_return_false();
2067         }
2068         if(pv_set_spec_value(lmsg, pvs, 0, &val)<0) {
2069                 LM_ERR("unable to set pv [%s]\n", pvn.s);
2070                 return sr_kemi_apy_return_false();
2071         }
2072
2073         return sr_kemi_apy_return_true();
2074 }
2075
2076 /**
2077  *
2078  */
2079 static PyObject *sr_apy_kemi_f_pv_unset(PyObject *self, PyObject *args)
2080 {
2081         str pvn;
2082         pv_spec_t *pvs;
2083         pv_value_t val;
2084         int pl;
2085         sr_apy_env_t *env_P;
2086         sip_msg_t *lmsg = NULL;
2087
2088         env_P = sr_apy_env_get();
2089
2090         if(env_P==NULL) {
2091                 LM_ERR("invalid Python environment attributes\n");
2092                 return sr_kemi_apy_return_false();
2093         }
2094         if(env_P->msg==NULL) {
2095                 lmsg = faked_msg_next();
2096         } else {
2097                 lmsg = env_P->msg;
2098         }
2099
2100         if(!PyArg_ParseTuple(args, "s:pv.unset", &pvn.s)) {
2101                 LM_ERR("unable to retrieve str param\n");
2102                 return sr_kemi_apy_return_false();
2103         }
2104
2105         if(pvn.s==NULL || lmsg==NULL) {
2106                 LM_ERR("invalid context attributes\n");
2107                 return sr_kemi_apy_return_false();
2108         }
2109
2110         pvn.len = strlen(pvn.s);
2111         LM_DBG("pv unset: %s\n", pvn.s);
2112         pl = pv_locate_name(&pvn);
2113         if(pl != pvn.len) {
2114                 LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
2115                 return sr_kemi_apy_return_false();
2116         }
2117         pvs = pv_cache_get(&pvn);
2118         if(pvs==NULL) {
2119                 LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
2120                 return sr_kemi_apy_return_false();
2121         }
2122         memset(&val, 0, sizeof(pv_value_t));
2123         val.flags |= PV_VAL_NULL;
2124         if(pv_set_spec_value(lmsg, pvs, 0, &val)<0) {
2125                 LM_ERR("unable to unset pv [%s]\n", pvn.s);
2126                 return sr_kemi_apy_return_false();
2127         }
2128
2129         return sr_kemi_apy_return_true();
2130 }
2131
2132 /**
2133  *
2134  */
2135 static PyObject *sr_apy_kemi_f_pv_is_null(PyObject *self, PyObject *args)
2136 {
2137         str pvn;
2138         pv_spec_t *pvs;
2139         pv_value_t val;
2140         int pl;
2141         sr_apy_env_t *env_P;
2142         sip_msg_t *lmsg = NULL;
2143
2144         env_P = sr_apy_env_get();
2145
2146         if(env_P==NULL) {
2147                 LM_ERR("invalid Python environment attributes\n");
2148                 return sr_kemi_apy_return_false();
2149         }
2150         if(env_P->msg==NULL) {
2151                 lmsg = faked_msg_next();
2152         } else {
2153                 lmsg = env_P->msg;
2154         }
2155
2156         if(!PyArg_ParseTuple(args, "s:pv.unset", &pvn.s)) {
2157                 LM_ERR("unable to retrieve str param\n");
2158                 return sr_kemi_apy_return_false();
2159         }
2160
2161         if(pvn.s==NULL || lmsg==NULL) {
2162                 LM_ERR("invalid context attributes\n");
2163                 return sr_kemi_apy_return_false();
2164         }
2165
2166         pvn.len = strlen(pvn.s);
2167         LM_DBG("pv is null test: %s\n", pvn.s);
2168         pl = pv_locate_name(&pvn);
2169         if(pl != pvn.len) {
2170                 LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
2171                 return sr_kemi_apy_return_false();
2172         }
2173         pvs = pv_cache_get(&pvn);
2174         if(pvs==NULL) {
2175                 LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
2176                 return sr_kemi_apy_return_true();
2177         }
2178         memset(&val, 0, sizeof(pv_value_t));
2179         if(pv_get_spec_value(lmsg, pvs, &val) != 0) {
2180                 LM_NOTICE("unable to get pv value for [%s]\n", pvn.s);
2181                 return sr_kemi_apy_return_true();
2182         }
2183         if(val.flags&PV_VAL_NULL) {
2184                 return sr_kemi_apy_return_true();
2185         } else {
2186                 return sr_kemi_apy_return_false();
2187         }
2188 }
2189
2190 static PyMethodDef _sr_apy_kemi_pv_Methods[] = {
2191         {"get",         sr_apy_kemi_f_pv_get,           METH_VARARGS,
2192                 NAME " - pv get value"},
2193         {"getw",        sr_apy_kemi_f_pv_getw,          METH_VARARGS,
2194                 NAME " - pv get value or <<null>>"},
2195         {"getvs",       sr_apy_kemi_f_pv_getvs,         METH_VARARGS,
2196                 NAME " - pv get value of pv or str val param"},
2197         {"getvn",       sr_apy_kemi_f_pv_getvn,         METH_VARARGS,
2198                 NAME " - pv get value of pv or int val param"},
2199         {"gete",        sr_apy_kemi_f_pv_gete,          METH_VARARGS,
2200                 NAME " - pv get value or empty string"},
2201         {"seti",        sr_apy_kemi_f_pv_seti,          METH_VARARGS,
2202                 NAME " - pv set int value"},
2203         {"sets",        sr_apy_kemi_f_pv_sets,          METH_VARARGS,
2204                 NAME " - pv set str value"},
2205         {"unset",       sr_apy_kemi_f_pv_unset,         METH_VARARGS,
2206                 NAME " - pv uset value (assign $null)"},
2207         {"is_null",     sr_apy_kemi_f_pv_is_null,       METH_VARARGS,
2208                 NAME " - pv test if it is $null"},
2209
2210         {NULL,          NULL,                   0,              NULL}
2211 };
2212
2213 /**
2214  *
2215  */
2216 static PyMethodDef _sr_apy_kemi_x_Methods[] = {
2217         {"modf", (PyCFunction)msg_call_function, METH_VARARGS,
2218                 "Invoke function exported by the other module."},
2219         {NULL, NULL, 0, NULL} /* sentinel */
2220 };
2221
2222 /**
2223  *
2224  */
2225 int sr_apy_init_ksr(void)
2226 {
2227         PyMethodDef *_sr_crt_KSRMethods = NULL;
2228         sr_kemi_module_t *emods = NULL;
2229         int emods_size = 0;
2230         int i;
2231         int k;
2232         int m;
2233         int n;
2234         char mname[128];
2235
2236         /* init faked sip msg */
2237         if(faked_msg_init()<0)
2238         {
2239                 LM_ERR("failed to init local faked sip msg\n");
2240                 return -1;
2241         }
2242
2243         _sr_KSRMethods = malloc(SR_APY_KSR_METHODS_SIZE * sizeof(PyMethodDef));
2244         if(_sr_KSRMethods==NULL) {
2245                 LM_ERR("no more pkg memory\n");
2246                 return -1;
2247         }
2248         _sr_apy_ksr_modules_list = malloc(SR_APY_KSR_MODULES_SIZE * sizeof(PyObject*));
2249         if(_sr_apy_ksr_modules_list==NULL) {
2250                 LM_ERR("no more pkg memory\n");
2251                 return -1;
2252         }
2253         memset(_sr_KSRMethods, 0, SR_APY_KSR_METHODS_SIZE * sizeof(PyMethodDef));
2254         memset(_sr_apy_ksr_modules_list, 0, SR_APY_KSR_MODULES_SIZE * sizeof(PyObject*));
2255
2256         emods_size = sr_kemi_modules_size_get();
2257         emods = sr_kemi_modules_get();
2258
2259         n = 0;
2260         _sr_crt_KSRMethods = _sr_KSRMethods;
2261         if(emods_size==0 || emods[0].kexp==NULL) {
2262                 LM_DBG("exporting KSR.%s(...)\n", _sr_apy_kemi_test[0].fname.s);
2263                 _sr_crt_KSRMethods[0].ml_name = _sr_apy_kemi_test[0].fname.s;
2264                 _sr_crt_KSRMethods[0].ml_meth = sr_apy_kemi_export_associate(&_sr_apy_kemi_test[0]);
2265                 _sr_crt_KSRMethods[0].ml_flags = METH_VARARGS;
2266                 _sr_crt_KSRMethods[0].ml_doc = NAME " exported function";
2267         } else {
2268                 for(i=0; emods[0].kexp[i].func!=NULL; i++) {
2269                         LM_DBG("exporting KSR.%s(...)\n", emods[0].kexp[i].fname.s);
2270                         _sr_crt_KSRMethods[i].ml_name = emods[0].kexp[i].fname.s;
2271                         _sr_crt_KSRMethods[i].ml_meth =
2272                                 sr_apy_kemi_export_associate(&emods[0].kexp[i]);
2273                         if(_sr_crt_KSRMethods[i].ml_meth == NULL) {
2274                                 LM_ERR("failed to associate kemi function with python export\n");
2275                                 free(_sr_KSRMethods);
2276                                 _sr_KSRMethods = NULL;
2277                                 return -1;
2278                         }
2279                         _sr_crt_KSRMethods[i].ml_flags = METH_VARARGS;
2280                         _sr_crt_KSRMethods[i].ml_doc = NAME " exported function";
2281                         n++;
2282                 }
2283         }
2284
2285         _sr_apy_ksr_module = Py_InitModule("KSR", _sr_crt_KSRMethods);
2286         _sr_apy_ksr_module_dict = PyModule_GetDict(_sr_apy_ksr_module);
2287
2288         Py_INCREF(_sr_apy_ksr_module);
2289
2290         m = 0;
2291
2292         /* special sub-modules - pv.get() can return int or string */
2293         _sr_apy_ksr_modules_list[m] = Py_InitModule("KSR.pv",
2294                         _sr_apy_kemi_pv_Methods);
2295         PyDict_SetItemString(_sr_apy_ksr_module_dict,
2296                         "pv", _sr_apy_ksr_modules_list[m]);
2297         Py_INCREF(_sr_apy_ksr_modules_list[m]);
2298         m++;
2299         /* special sub-modules - x.modf() can have variable number of params */
2300         _sr_apy_ksr_modules_list[m] = Py_InitModule("KSR.x",
2301                         _sr_apy_kemi_x_Methods);
2302         PyDict_SetItemString(_sr_apy_ksr_module_dict,
2303                         "x", _sr_apy_ksr_modules_list[m]);
2304         Py_INCREF(_sr_apy_ksr_modules_list[m]);
2305         m++;
2306
2307         if(emods_size>1) {
2308                 for(k=1; k<emods_size; k++) {
2309                         if(emods[k].kexp == sr_kemi_exports_get_pv()) {
2310                                 LM_DBG("skip registering the core KSR.pv module\n");
2311                                 continue;
2312                         }
2313                         n++;
2314                         _sr_crt_KSRMethods = _sr_KSRMethods + n;
2315                         snprintf(mname, 128, "KSR.%s", emods[k].kexp[0].mname.s);
2316                         for(i=0; emods[k].kexp[i].func!=NULL; i++) {
2317                                 LM_DBG("exporting %s.%s(...)\n", mname,
2318                                                 emods[k].kexp[i].fname.s);
2319                                 _sr_crt_KSRMethods[i].ml_name = emods[k].kexp[i].fname.s;
2320                                 _sr_crt_KSRMethods[i].ml_meth =
2321                                         sr_apy_kemi_export_associate(&emods[k].kexp[i]);
2322                                 if(_sr_crt_KSRMethods[i].ml_meth == NULL) {
2323                                         LM_ERR("failed to associate kemi function with python export\n");
2324                                         free(_sr_KSRMethods);
2325                                         _sr_KSRMethods = NULL;
2326                                         return -1;
2327                                 }
2328                                 _sr_crt_KSRMethods[i].ml_flags = METH_VARARGS;
2329                                 _sr_crt_KSRMethods[i].ml_doc = NAME " exported function";
2330                                 n++;
2331                         }
2332                         LM_DBG("initializing kemi sub-module: %s (%s)\n", mname,
2333                                         emods[k].kexp[0].mname.s);
2334                         _sr_apy_ksr_modules_list[m] = Py_InitModule(mname, _sr_crt_KSRMethods);
2335                         PyDict_SetItemString(_sr_apy_ksr_module_dict,
2336                                         emods[k].kexp[0].mname.s, _sr_apy_ksr_modules_list[m]);
2337                         Py_INCREF(_sr_apy_ksr_modules_list[m]);
2338                         m++;
2339                 }
2340         }
2341         LM_DBG("module 'KSR' has been initialized\n");
2342         return 0;
2343 }
2344
2345 /**
2346  *
2347  */
2348 void sr_apy_destroy_ksr(void)
2349 {
2350         if(_sr_apy_ksr_module!=NULL) {
2351                 Py_XDECREF(_sr_apy_ksr_module);
2352                 _sr_apy_ksr_module = NULL;
2353         }
2354         if(_sr_apy_ksr_module_dict!=NULL) {
2355                 Py_XDECREF(_sr_apy_ksr_module_dict);
2356                 _sr_apy_ksr_module_dict = NULL;
2357         }
2358         if(_sr_KSRMethods!=NULL) {
2359                 free(_sr_KSRMethods);
2360                 _sr_KSRMethods = NULL;
2361         }
2362
2363         LM_DBG("module 'KSR' has been destroyed\n");
2364 }
2365
2366 /**
2367  *
2368  */
2369 int apy_sr_init_mod(void)
2370 {
2371         if(_sr_python_reload_version == NULL) {
2372                 _sr_python_reload_version = (int*)shm_malloc(sizeof(int));
2373                 if(_sr_python_reload_version == NULL) {
2374                         SHM_MEM_ERROR;
2375                         return -1;
2376                 }
2377                 *_sr_python_reload_version = 0;
2378         }
2379
2380         return 0;
2381 }
2382
2383 static const char* app_python_rpc_reload_doc[2] = {
2384         "Reload python file",
2385         0
2386 };
2387
2388
2389 static void app_python_rpc_reload(rpc_t* rpc, void* ctx)
2390 {
2391         void *vh;
2392
2393         if(_sr_python_load_file.s == NULL && _sr_python_load_file.len<=0) {
2394                 LM_WARN("script file path not provided\n");
2395                 rpc->fault(ctx, 500, "No script file");
2396                 return;
2397         }
2398         if(_sr_python_reload_version == NULL) {
2399                 LM_WARN("reload not enabled\n");
2400                 rpc->fault(ctx, 500, "Reload not enabled");
2401                 return;
2402         }
2403
2404         *_sr_python_reload_version += 1;
2405         LM_INFO("marking for reload Python script file: %.*s (%d)\n",
2406                                 _sr_python_load_file.len, _sr_python_load_file.s,
2407                                 *_sr_python_reload_version);
2408
2409         if (rpc->add(ctx, "{", &vh) < 0) {
2410                 rpc->fault(ctx, 500, "Server error");
2411                 return;
2412         }
2413         rpc->struct_add(vh, "dd",
2414                         "old", *_sr_python_reload_version-1,
2415                         "new", *_sr_python_reload_version);
2416
2417         return;
2418 }
2419
2420 static const char* app_python_rpc_api_list_doc[2] = {
2421         "List kemi exports to javascript",
2422         0
2423 };
2424
2425 static void app_python_rpc_api_list(rpc_t* rpc, void* ctx)
2426 {
2427         int i;
2428         int n;
2429         sr_kemi_t *ket;
2430         void* th;
2431         void* sh;
2432         void* ih;
2433
2434         if (rpc->add(ctx, "{", &th) < 0) {
2435                 rpc->fault(ctx, 500, "Internal error root reply");
2436                 return;
2437         }
2438         n = 0;
2439         for(i=0; i<SR_APY_KSR_METHODS_SIZE ; i++) {
2440                 ket = sr_apy_kemi_export_get(i);
2441                 if(ket==NULL) continue;
2442                 n++;
2443         }
2444
2445         if(rpc->struct_add(th, "d[",
2446                                 "msize", n,
2447                                 "methods",  &ih)<0)
2448         {
2449                 rpc->fault(ctx, 500, "Internal error array structure");
2450                 return;
2451         }
2452         for(i=0; i<SR_APY_KSR_METHODS_SIZE; i++) {
2453                 ket = sr_apy_kemi_export_get(i);
2454                 if(ket==NULL) continue;
2455                 if(rpc->struct_add(ih, "{", "func", &sh)<0) {
2456                         rpc->fault(ctx, 500, "Internal error internal structure");
2457                         return;
2458                 }
2459                 if(rpc->struct_add(sh, "SSSS",
2460                                 "ret", sr_kemi_param_map_get_name(ket->rtype),
2461                                 "module", &ket->mname,
2462                                 "name", &ket->fname,
2463                                 "params", sr_kemi_param_map_get_params(ket->ptypes))<0) {
2464                         LM_ERR("failed to add the structure with attributes (%d)\n", i);
2465                         rpc->fault(ctx, 500, "Internal error creating dest struct");
2466                         return;
2467                 }
2468         }
2469 }
2470
2471 rpc_export_t app_python_rpc_cmds[] = {
2472         {"app_python.reload", app_python_rpc_reload,
2473                 app_python_rpc_reload_doc, 0},
2474         {"app_python.api_list", app_python_rpc_api_list,
2475                 app_python_rpc_api_list_doc, 0},
2476         {0, 0, 0, 0}
2477 };
2478
2479 /**
2480  * register RPC commands
2481  */
2482 int app_python_init_rpc(void)
2483 {
2484         if (rpc_register_array(app_python_rpc_cmds)!=0)
2485         {
2486                 LM_ERR("failed to register RPC commands\n");
2487                 return -1;
2488         }
2489         return 0;
2490 }