app_python: for now return none for array and map kemi results
[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_kemi_apy_return_xval(sr_kemi_t *ket, sr_kemi_xval_t *rx)
170 {
171         switch(rx->vtype) {
172                 case SR_KEMIP_NONE:
173                         return sr_apy_kemi_return_none();
174                 case SR_KEMIP_INT:
175                         return sr_kemi_apy_return_int(ket, rx->v.n);
176                 case SR_KEMIP_STR:
177                         return sr_apy_kemi_return_str(ket, rx->v.s.s, rx->v.s.len);
178                 case SR_KEMIP_BOOL:
179                         if(rx->v.n!=SR_KEMI_FALSE) {
180                                 return sr_kemi_apy_return_true();
181                         } else {
182                                 return sr_kemi_apy_return_false();
183                         }
184                 case SR_KEMIP_ARRAY:
185                         LM_ERR("unsupported return type: array\n");
186                         sr_kemi_xval_free(rx);
187                         return sr_apy_kemi_return_none();
188                 case SR_KEMIP_DICT:
189                         LM_ERR("unsupported return type: map\n");
190                 case SR_KEMIP_XVAL:
191                         /* unknown content - return false */
192                         return sr_kemi_apy_return_false();
193                 case SR_KEMIP_NULL:
194                         return sr_apy_kemi_return_none();
195                 default:
196                         /* unknown type - return false */
197                         return sr_kemi_apy_return_false();
198         }
199 }
200
201 /**
202  *
203  */
204 PyObject *sr_apy_kemi_exec_func_ex(sr_kemi_t *ket, PyObject *self,
205                         PyObject *args, int idx)
206 {
207         str fname;
208         int i;
209         int ret;
210         sr_kemi_val_t vps[SR_KEMI_PARAMS_MAX];
211         sr_apy_env_t *env_P;
212         sip_msg_t *lmsg = NULL;
213         sr_kemi_xval_t *xret;
214
215         env_P = sr_apy_env_get();
216
217         if(env_P==NULL) {
218                 LM_ERR("invalid Python environment attributes\n");
219                 return sr_kemi_apy_return_false();
220         }
221         if(env_P->msg==NULL) {
222                 lmsg = faked_msg_next();
223         } else {
224                 lmsg = env_P->msg;
225         }
226
227         if(ket->mname.len>0) {
228                 LM_DBG("execution of method: %.*s\n", ket->fname.len, ket->fname.s);
229         } else {
230                 LM_DBG("execution of method: %.*s.%.*s\n",
231                                 ket->mname.len, ket->mname.s,
232                                 ket->fname.len, ket->fname.s);
233         }
234         fname = ket->fname;
235
236         if(ket->ptypes[0]==SR_KEMIP_NONE) {
237                 if(ket->rtype==SR_KEMIP_XVAL) {
238                         xret = ((sr_kemi_xfm_f)(ket->func))(lmsg);
239                         return sr_kemi_apy_return_xval(ket, xret);
240                 } else {
241                         ret = ((sr_kemi_fm_f)(ket->func))(lmsg);
242                         return sr_kemi_apy_return_int(ket, ret);
243                 }
244         }
245
246         memset(vps, 0, SR_KEMI_PARAMS_MAX*sizeof(sr_kemi_val_t));
247         if(ket->ptypes[1]==SR_KEMIP_NONE) {
248                 i = 1;
249                 if(ket->ptypes[0]==SR_KEMIP_INT) {
250                         if(!PyArg_ParseTuple(args, "i:kemi-param-n", &vps[0].n)) {
251                                 LM_ERR("unable to retrieve int param %d\n", 0);
252                                 return sr_kemi_apy_return_false();
253                         }
254                         LM_DBG("param[%d] for: %.*s is int: %d\n", i,
255                                 fname.len, fname.s, vps[0].n);
256                 } else {
257                         if(!PyArg_ParseTuple(args, "s:kemi-param-s", &vps[0].s.s)) {
258                                 LM_ERR("unable to retrieve str param %d\n", 0);
259                                 return sr_kemi_apy_return_false();
260                         }
261                         vps[0].s.len = strlen(vps[0].s.s);
262                         LM_DBG("param[%d] for: %.*s is str: %.*s\n", i,
263                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s);
264                 }
265         } else if(ket->ptypes[2]==SR_KEMIP_NONE) {
266                 i = 2;
267                 if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_INT) {
268                         if(!PyArg_ParseTuple(args, "ii:kemi-param-nn", &vps[0].n, &vps[1].n)) {
269                                 LM_ERR("unable to retrieve int-int params %d\n", i);
270                                 return sr_kemi_apy_return_false();
271                         }
272                         LM_DBG("params[%d] for: %.*s are int-int: [%d] [%d]\n", i,
273                                 fname.len, fname.s, vps[0].n, vps[1].n);
274                 } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_STR) {
275                         if(!PyArg_ParseTuple(args, "is:kemi-param-ns", &vps[0].n, &vps[1].s.s)) {
276                                 LM_ERR("unable to retrieve int-str params %d\n", i);
277                                 return sr_kemi_apy_return_false();
278                         }
279                         vps[1].s.len = strlen(vps[1].s.s);
280                         LM_DBG("params[%d] for: %.*s are int-str: [%d] [%.*s]\n", i,
281                                 fname.len, fname.s, vps[0].n, vps[1].s.len, vps[1].s.s);
282                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_INT) {
283                         if(!PyArg_ParseTuple(args, "si:kemi-param-sn", &vps[0].s.s, &vps[1].n)) {
284                                 LM_ERR("unable to retrieve str-int params %d\n", i);
285                                 return sr_kemi_apy_return_false();
286                         }
287                         vps[0].s.len = strlen(vps[0].s.s);
288                         LM_DBG("params[%d] for: %.*s are str-int: [%.*s] [%d]\n", i,
289                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s, vps[1].n);
290                 } else {
291                         if(!PyArg_ParseTuple(args, "ss:kemi-param-ss", &vps[0].s.s, &vps[1].s.s)) {
292                                 LM_ERR("unable to retrieve str-str param %d\n", i);
293                                 return sr_kemi_apy_return_false();
294                         }
295                         vps[0].s.len = strlen(vps[0].s.s);
296                         vps[1].s.len = strlen(vps[1].s.s);
297                         LM_DBG("params[%d] for: %.*s are str: [%.*s] [%.*s]\n", i,
298                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s,
299                                 vps[1].s.len, vps[1].s.s);
300                 }
301
302         } else if(ket->ptypes[3]==SR_KEMIP_NONE) {
303                 i = 3;
304                 if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_INT
305                                 && ket->ptypes[2]==SR_KEMIP_INT) {
306                         if(!PyArg_ParseTuple(args, "iii:kemi-param-nnn", &vps[0].n,
307                                                 &vps[1].n, &vps[2].n)) {
308                                 LM_ERR("unable to retrieve int-int-int params %d\n", i);
309                                 return sr_kemi_apy_return_false();
310                         }
311                         LM_DBG("params[%d] for: %.*s are int-int-int: [%d] [%d] [%d]\n",
312                                         i, fname.len, fname.s, vps[0].n, vps[1].n, vps[2].n);
313                 } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_INT
314                                         && ket->ptypes[2]==SR_KEMIP_STR) {
315                         if(!PyArg_ParseTuple(args, "iis:kemi-param-nns", &vps[0].n,
316                                                 &vps[1].n, &vps[2].s.s)) {
317                                 LM_ERR("unable to retrieve int-int-str params %d\n", i);
318                                 return sr_kemi_apy_return_false();
319                         }
320                         vps[2].s.len = strlen(vps[2].s.s);
321                         LM_DBG("params[%d] for: %.*s are int-int-str: [%d] [%d] [%.*s]\n", i,
322                                         fname.len, fname.s, vps[0].n, vps[1].n, vps[2].s.len, vps[2].s.s);
323                 } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_STR
324                                 && ket->ptypes[2]==SR_KEMIP_INT) {
325                         if(!PyArg_ParseTuple(args, "isi:kemi-param-nsn", &vps[0].n,
326                                                 &vps[1].s.s, &vps[2].n)) {
327                                 LM_ERR("unable to retrieve int-str-int params %d\n", i);
328                                 return sr_kemi_apy_return_false();
329                         }
330                         vps[1].s.len = strlen(vps[1].s.s);
331                         LM_DBG("params[%d] for: %.*s are int-str-int: [%d] [%.*s] [%d]\n", i,
332                                 fname.len, fname.s, vps[0].n, vps[1].s.len, vps[1].s.s, vps[2].n);
333                 } else if(ket->ptypes[0]==SR_KEMIP_INT && ket->ptypes[1]==SR_KEMIP_STR
334                                 && ket->ptypes[2]==SR_KEMIP_STR) {
335                         if(!PyArg_ParseTuple(args, "iss:kemi-param-nss", &vps[0].n,
336                                                 &vps[1].s.s, &vps[2].s.s)) {
337                                 LM_ERR("unable to retrieve int-str-str param %d\n", i);
338                                 return sr_kemi_apy_return_false();
339                         }
340                         vps[1].s.len = strlen(vps[1].s.s);
341                         vps[2].s.len = strlen(vps[2].s.s);
342                         LM_DBG("params[%d] for: %.*s are int-str-str: [%d] [%.*s]"
343                                         " [%.*s]\n", i, fname.len, fname.s,
344                                         vps[0].n, vps[1].s.len, vps[1].s.s, vps[2].s.len, vps[2].s.s);
345                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_INT
346                                 && ket->ptypes[2]==SR_KEMIP_INT) {
347                         if(!PyArg_ParseTuple(args, "sii:kemi-param-snn", &vps[0].s.s,
348                                                 &vps[1].n, &vps[2].n)) {
349                                 LM_ERR("unable to retrieve str-int-int params %d\n", i);
350                                 return sr_kemi_apy_return_false();
351                         }
352                         vps[0].s.len = strlen(vps[0].s.s);
353                         LM_DBG("params[%d] for: %.*s are str-int: [%.*s] [%d] [%d]\n", i,
354                                         fname.len, fname.s, vps[0].s.len, vps[0].s.s, vps[1].n,
355                                         vps[2].n);
356                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_INT
357                                 && ket->ptypes[2]==SR_KEMIP_STR) {
358                         if(!PyArg_ParseTuple(args, "sis:kemi-param-ssn", &vps[0].s.s,
359                                                 &vps[1].n, &vps[2].s.s)) {
360                                 LM_ERR("unable to retrieve str-int-str param %d\n", i);
361                                 return sr_kemi_apy_return_false();
362                         }
363                         vps[0].s.len = strlen(vps[0].s.s);
364                         vps[2].s.len = strlen(vps[2].s.s);
365                         LM_DBG("params[%d] for: %.*s are str-str-int: [%.*s] [%d] [%.*s]\n",
366                                         i, fname.len, fname.s,
367                                         vps[0].s.len, vps[0].s.s,
368                                         vps[1].n, vps[2].s.len, vps[2].s.s);
369                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_STR
370                                 && ket->ptypes[2]==SR_KEMIP_INT) {
371                         if(!PyArg_ParseTuple(args, "ssi:kemi-param-ssn", &vps[0].s.s,
372                                                 &vps[1].s.s, &vps[2].n)) {
373                                 LM_ERR("unable to retrieve str-str-int param %d\n", i);
374                                 return sr_kemi_apy_return_false();
375                         }
376                         vps[0].s.len = strlen(vps[0].s.s);
377                         vps[1].s.len = strlen(vps[1].s.s);
378                         LM_DBG("params[%d] for: %.*s are str-str-int: [%.*s] [%.*s]"
379                                         " [%d]\n", i, fname.len, fname.s,
380                                         vps[0].s.len, vps[0].s.s,
381                                         vps[1].s.len, vps[1].s.s, vps[2].n);
382                 } else if(ket->ptypes[0]==SR_KEMIP_STR && ket->ptypes[1]==SR_KEMIP_STR
383                                 && ket->ptypes[2]==SR_KEMIP_STR) {
384                         if(!PyArg_ParseTuple(args, "sss:kemi-param-sss", &vps[0].s.s,
385                                                 &vps[1].s.s, &vps[2].s.s)) {
386                                 LM_ERR("unable to retrieve str-str-str param %d\n", i);
387                                 return sr_kemi_apy_return_false();
388                         }
389                         vps[0].s.len = strlen(vps[0].s.s);
390                         vps[1].s.len = strlen(vps[1].s.s);
391                         vps[2].s.len = strlen(vps[2].s.s);
392                         LM_DBG("params[%d] for: %.*s are str-str-str: [%.*s] [%.*s]"
393                                         " [%.*s]\n", i, fname.len, fname.s,
394                                         vps[0].s.len, vps[0].s.s,
395                                         vps[1].s.len, vps[1].s.s, vps[2].s.len, vps[2].s.s);
396                 } else {
397                         LM_ERR("not implemented yet\n");
398                         return sr_kemi_apy_return_false();
399                 }
400         } else if(ket->ptypes[4]==SR_KEMIP_NONE) {
401                 i = 4;
402                 if(ket->ptypes[0]==SR_KEMIP_STR
403                                 && ket->ptypes[1]==SR_KEMIP_STR
404                                 && ket->ptypes[2]==SR_KEMIP_STR
405                                 && ket->ptypes[3]==SR_KEMIP_STR) {
406                         if(!PyArg_ParseTuple(args, "ssss:kemi-param-ssss",
407                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s)) {
408                                 LM_ERR("unable to retrieve ssss params %d\n", i);
409                                 return sr_kemi_apy_return_false();
410                         }
411                         vps[0].s.len = strlen(vps[0].s.s);
412                         vps[1].s.len = strlen(vps[1].s.s);
413                         vps[2].s.len = strlen(vps[2].s.s);
414                         vps[3].s.len = strlen(vps[3].s.s);
415
416                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%s]\n",
417                                         i, fname.len, fname.s,
418                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].s.s);
419                 } else if(ket->ptypes[0]==SR_KEMIP_STR
420                                 && ket->ptypes[1]==SR_KEMIP_STR
421                                 && ket->ptypes[2]==SR_KEMIP_STR
422                                 && ket->ptypes[3]==SR_KEMIP_INT) {
423                         if(!PyArg_ParseTuple(args, "sssn:kemi-param-sssn",
424                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].n)) {
425                                 LM_ERR("unable to retrieve sssn params %d\n", i);
426                                 return sr_kemi_apy_return_false();
427                         }
428                         vps[0].s.len = strlen(vps[0].s.s);
429                         vps[1].s.len = strlen(vps[1].s.s);
430                         vps[2].s.len = strlen(vps[2].s.s);
431
432                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%d]\n",
433                                         i, fname.len, fname.s,
434                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].n);
435                 } else if(ket->ptypes[0]==SR_KEMIP_STR
436                                 && ket->ptypes[1]==SR_KEMIP_STR
437                                 && ket->ptypes[2]==SR_KEMIP_INT
438                                 && ket->ptypes[3]==SR_KEMIP_STR) {
439                         if(!PyArg_ParseTuple(args, "ssns:kemi-param-ssns",
440                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].s.s)) {
441                                 LM_ERR("unable to retrieve ssns params %d\n", i);
442                                 return sr_kemi_apy_return_false();
443                         }
444                         vps[0].s.len = strlen(vps[0].s.s);
445                         vps[1].s.len = strlen(vps[1].s.s);
446                         vps[3].s.len = strlen(vps[3].s.s);
447
448                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%s]\n",
449                                         i, fname.len, fname.s,
450                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].s.s);
451                 } else if(ket->ptypes[0]==SR_KEMIP_STR
452                                 && ket->ptypes[1]==SR_KEMIP_STR
453                                 && ket->ptypes[2]==SR_KEMIP_INT
454                                 && ket->ptypes[3]==SR_KEMIP_INT) {
455                         if(!PyArg_ParseTuple(args, "ssnn:kemi-param-ssnn",
456                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].n)) {
457                                 LM_ERR("unable to retrieve ssnn params %d\n", i);
458                                 return sr_kemi_apy_return_false();
459                         }
460                         vps[0].s.len = strlen(vps[0].s.s);
461                         vps[1].s.len = strlen(vps[1].s.s);
462
463                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%d]\n",
464                                         i, fname.len, fname.s,
465                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].n);
466                 } else if(ket->ptypes[0]==SR_KEMIP_STR
467                                 && ket->ptypes[1]==SR_KEMIP_INT
468                                 && ket->ptypes[2]==SR_KEMIP_STR
469                                 && ket->ptypes[3]==SR_KEMIP_STR) {
470                         if(!PyArg_ParseTuple(args, "snss:kemi-param-snss",
471                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].s.s)) {
472                                 LM_ERR("unable to retrieve snss params %d\n", i);
473                                 return sr_kemi_apy_return_false();
474                         }
475                         vps[0].s.len = strlen(vps[0].s.s);
476                         vps[2].s.len = strlen(vps[2].s.s);
477                         vps[3].s.len = strlen(vps[3].s.s);
478
479                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%s]\n",
480                                         i, fname.len, fname.s,
481                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].s.s);
482                 } else if(ket->ptypes[0]==SR_KEMIP_STR
483                                 && ket->ptypes[1]==SR_KEMIP_INT
484                                 && ket->ptypes[2]==SR_KEMIP_STR
485                                 && ket->ptypes[3]==SR_KEMIP_INT) {
486                         if(!PyArg_ParseTuple(args, "snsn:kemi-param-snsn",
487                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].n)) {
488                                 LM_ERR("unable to retrieve snsn params %d\n", i);
489                                 return sr_kemi_apy_return_false();
490                         }
491                         vps[0].s.len = strlen(vps[0].s.s);
492                         vps[2].s.len = strlen(vps[2].s.s);
493
494                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%d]\n",
495                                         i, fname.len, fname.s,
496                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].n);
497                 } else if(ket->ptypes[0]==SR_KEMIP_STR
498                                 && ket->ptypes[1]==SR_KEMIP_INT
499                                 && ket->ptypes[2]==SR_KEMIP_INT
500                                 && ket->ptypes[3]==SR_KEMIP_STR) {
501                         if(!PyArg_ParseTuple(args, "snns:kemi-param-snns",
502                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].s.s)) {
503                                 LM_ERR("unable to retrieve snns params %d\n", i);
504                                 return sr_kemi_apy_return_false();
505                         }
506                         vps[0].s.len = strlen(vps[0].s.s);
507                         vps[3].s.len = strlen(vps[3].s.s);
508
509                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%s]\n",
510                                         i, fname.len, fname.s,
511                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].s.s);
512                 } else if(ket->ptypes[0]==SR_KEMIP_STR
513                                 && ket->ptypes[1]==SR_KEMIP_INT
514                                 && ket->ptypes[2]==SR_KEMIP_INT
515                                 && ket->ptypes[3]==SR_KEMIP_INT) {
516                         if(!PyArg_ParseTuple(args, "snnn:kemi-param-snnn",
517                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].n)) {
518                                 LM_ERR("unable to retrieve snnn params %d\n", i);
519                                 return sr_kemi_apy_return_false();
520                         }
521                         vps[0].s.len = strlen(vps[0].s.s);
522
523                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%d]\n",
524                                         i, fname.len, fname.s,
525                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].n);
526                 } else if(ket->ptypes[0]==SR_KEMIP_INT
527                                 && ket->ptypes[1]==SR_KEMIP_STR
528                                 && ket->ptypes[2]==SR_KEMIP_STR
529                                 && ket->ptypes[3]==SR_KEMIP_STR) {
530                         if(!PyArg_ParseTuple(args, "nsss:kemi-param-nsss",
531                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s)) {
532                                 LM_ERR("unable to retrieve nsss params %d\n", i);
533                                 return sr_kemi_apy_return_false();
534                         }
535                         vps[1].s.len = strlen(vps[1].s.s);
536                         vps[2].s.len = strlen(vps[2].s.s);
537                         vps[3].s.len = strlen(vps[3].s.s);
538
539                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%s]\n",
540                                         i, fname.len, fname.s,
541                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].s.s);
542                 } else if(ket->ptypes[0]==SR_KEMIP_INT
543                                 && ket->ptypes[1]==SR_KEMIP_STR
544                                 && ket->ptypes[2]==SR_KEMIP_STR
545                                 && ket->ptypes[3]==SR_KEMIP_INT) {
546                         if(!PyArg_ParseTuple(args, "nssn:kemi-param-nssn",
547                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].n)) {
548                                 LM_ERR("unable to retrieve nssn params %d\n", i);
549                                 return sr_kemi_apy_return_false();
550                         }
551                         vps[1].s.len = strlen(vps[1].s.s);
552                         vps[2].s.len = strlen(vps[2].s.s);
553
554                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%d]\n",
555                                         i, fname.len, fname.s,
556                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].n);
557                 } else if(ket->ptypes[0]==SR_KEMIP_INT
558                                 && ket->ptypes[1]==SR_KEMIP_STR
559                                 && ket->ptypes[2]==SR_KEMIP_INT
560                                 && ket->ptypes[3]==SR_KEMIP_STR) {
561                         if(!PyArg_ParseTuple(args, "nsns:kemi-param-nsns",
562                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].s.s)) {
563                                 LM_ERR("unable to retrieve nsns params %d\n", i);
564                                 return sr_kemi_apy_return_false();
565                         }
566                         vps[1].s.len = strlen(vps[1].s.s);
567                         vps[3].s.len = strlen(vps[3].s.s);
568
569                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%s]\n",
570                                         i, fname.len, fname.s,
571                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].s.s);
572                 } else if(ket->ptypes[0]==SR_KEMIP_INT
573                                 && ket->ptypes[1]==SR_KEMIP_STR
574                                 && ket->ptypes[2]==SR_KEMIP_INT
575                                 && ket->ptypes[3]==SR_KEMIP_INT) {
576                         if(!PyArg_ParseTuple(args, "nsnn:kemi-param-nsnn",
577                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].n)) {
578                                 LM_ERR("unable to retrieve nsnn params %d\n", i);
579                                 return sr_kemi_apy_return_false();
580                         }
581                         vps[1].s.len = strlen(vps[1].s.s);
582
583                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%d]\n",
584                                         i, fname.len, fname.s,
585                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].n);
586                 } else if(ket->ptypes[0]==SR_KEMIP_INT
587                                 && ket->ptypes[1]==SR_KEMIP_INT
588                                 && ket->ptypes[2]==SR_KEMIP_STR
589                                 && ket->ptypes[3]==SR_KEMIP_STR) {
590                         if(!PyArg_ParseTuple(args, "nnss:kemi-param-nnss",
591                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].s.s)) {
592                                 LM_ERR("unable to retrieve nnss params %d\n", i);
593                                 return sr_kemi_apy_return_false();
594                         }
595                         vps[2].s.len = strlen(vps[2].s.s);
596                         vps[3].s.len = strlen(vps[3].s.s);
597
598                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%s]\n",
599                                         i, fname.len, fname.s,
600                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].s.s);
601                 } else if(ket->ptypes[0]==SR_KEMIP_INT
602                                 && ket->ptypes[1]==SR_KEMIP_INT
603                                 && ket->ptypes[2]==SR_KEMIP_STR
604                                 && ket->ptypes[3]==SR_KEMIP_INT) {
605                         if(!PyArg_ParseTuple(args, "nnsn:kemi-param-nnsn",
606                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].n)) {
607                                 LM_ERR("unable to retrieve nnsn params %d\n", i);
608                                 return sr_kemi_apy_return_false();
609                         }
610                         vps[2].s.len = strlen(vps[2].s.s);
611
612                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%d]\n",
613                                         i, fname.len, fname.s,
614                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].n);
615                 } else if(ket->ptypes[0]==SR_KEMIP_INT
616                                 && ket->ptypes[1]==SR_KEMIP_INT
617                                 && ket->ptypes[2]==SR_KEMIP_INT
618                                 && ket->ptypes[3]==SR_KEMIP_STR) {
619                         if(!PyArg_ParseTuple(args, "nnns:kemi-param-nnns",
620                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].s.s)) {
621                                 LM_ERR("unable to retrieve nnns params %d\n", i);
622                                 return sr_kemi_apy_return_false();
623                         }
624                         vps[3].s.len = strlen(vps[3].s.s);
625
626                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%s]\n",
627                                         i, fname.len, fname.s,
628                                         vps[0].n, vps[1].n, vps[2].n, vps[3].s.s);
629                 } else if(ket->ptypes[0]==SR_KEMIP_INT
630                                 && ket->ptypes[1]==SR_KEMIP_INT
631                                 && ket->ptypes[2]==SR_KEMIP_INT
632                                 && ket->ptypes[3]==SR_KEMIP_INT) {
633                         if(!PyArg_ParseTuple(args, "nnnn:kemi-param-nnnn",
634                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].n)) {
635                                 LM_ERR("unable to retrieve nnnn params %d\n", i);
636                                 return sr_kemi_apy_return_false();
637                         }
638
639                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%d]\n",
640                                         i, fname.len, fname.s,
641                                         vps[0].n, vps[1].n, vps[2].n, vps[3].n);
642                 } else {
643                         LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
644                         return sr_kemi_apy_return_false();
645                 }
646         } else if(ket->ptypes[5]==SR_KEMIP_NONE) {
647                 i = 5;
648                 if(ket->ptypes[0]==SR_KEMIP_STR
649                                 && ket->ptypes[1]==SR_KEMIP_STR
650                                 && ket->ptypes[2]==SR_KEMIP_STR
651                                 && ket->ptypes[3]==SR_KEMIP_STR
652                                 && ket->ptypes[4]==SR_KEMIP_STR) {
653                         if(!PyArg_ParseTuple(args, "sssss:kemi-param-sssss",
654                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
655                                 LM_ERR("unable to retrieve sssss params %d\n", i);
656                                 return sr_kemi_apy_return_false();
657                         }
658                         vps[0].s.len = strlen(vps[0].s.s);
659                         vps[1].s.len = strlen(vps[1].s.s);
660                         vps[2].s.len = strlen(vps[2].s.s);
661                         vps[3].s.len = strlen(vps[3].s.s);
662                         vps[4].s.len = strlen(vps[4].s.s);
663
664                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%s] [%s]\n",
665                                         i, fname.len, fname.s,
666                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].s.s);
667                 } else if(ket->ptypes[0]==SR_KEMIP_STR
668                                 && ket->ptypes[1]==SR_KEMIP_STR
669                                 && ket->ptypes[2]==SR_KEMIP_STR
670                                 && ket->ptypes[3]==SR_KEMIP_STR
671                                 && ket->ptypes[4]==SR_KEMIP_INT) {
672                         if(!PyArg_ParseTuple(args, "ssssn:kemi-param-ssssn",
673                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
674                                 LM_ERR("unable to retrieve ssssn params %d\n", i);
675                                 return sr_kemi_apy_return_false();
676                         }
677                         vps[0].s.len = strlen(vps[0].s.s);
678                         vps[1].s.len = strlen(vps[1].s.s);
679                         vps[2].s.len = strlen(vps[2].s.s);
680                         vps[3].s.len = strlen(vps[3].s.s);
681
682                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%s] [%d]\n",
683                                         i, fname.len, fname.s,
684                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].n);
685                 } else if(ket->ptypes[0]==SR_KEMIP_STR
686                                 && ket->ptypes[1]==SR_KEMIP_STR
687                                 && ket->ptypes[2]==SR_KEMIP_STR
688                                 && ket->ptypes[3]==SR_KEMIP_INT
689                                 && ket->ptypes[4]==SR_KEMIP_STR) {
690                         if(!PyArg_ParseTuple(args, "sssns:kemi-param-sssns",
691                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
692                                 LM_ERR("unable to retrieve sssns params %d\n", i);
693                                 return sr_kemi_apy_return_false();
694                         }
695                         vps[0].s.len = strlen(vps[0].s.s);
696                         vps[1].s.len = strlen(vps[1].s.s);
697                         vps[2].s.len = strlen(vps[2].s.s);
698                         vps[4].s.len = strlen(vps[4].s.s);
699
700                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%d] [%s]\n",
701                                         i, fname.len, fname.s,
702                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].s.s);
703                 } else if(ket->ptypes[0]==SR_KEMIP_STR
704                                 && ket->ptypes[1]==SR_KEMIP_STR
705                                 && ket->ptypes[2]==SR_KEMIP_STR
706                                 && ket->ptypes[3]==SR_KEMIP_INT
707                                 && ket->ptypes[4]==SR_KEMIP_INT) {
708                         if(!PyArg_ParseTuple(args, "sssnn:kemi-param-sssnn",
709                                         &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
710                                 LM_ERR("unable to retrieve sssnn params %d\n", i);
711                                 return sr_kemi_apy_return_false();
712                         }
713                         vps[0].s.len = strlen(vps[0].s.s);
714                         vps[1].s.len = strlen(vps[1].s.s);
715                         vps[2].s.len = strlen(vps[2].s.s);
716
717                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%s] [%d] [%d]\n",
718                                         i, fname.len, fname.s,
719                                         vps[0].s.s, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].n);
720                 } else if(ket->ptypes[0]==SR_KEMIP_STR
721                                 && ket->ptypes[1]==SR_KEMIP_STR
722                                 && ket->ptypes[2]==SR_KEMIP_INT
723                                 && ket->ptypes[3]==SR_KEMIP_STR
724                                 && ket->ptypes[4]==SR_KEMIP_STR) {
725                         if(!PyArg_ParseTuple(args, "ssnss:kemi-param-ssnss",
726                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
727                                 LM_ERR("unable to retrieve ssnss params %d\n", i);
728                                 return sr_kemi_apy_return_false();
729                         }
730                         vps[0].s.len = strlen(vps[0].s.s);
731                         vps[1].s.len = strlen(vps[1].s.s);
732                         vps[3].s.len = strlen(vps[3].s.s);
733                         vps[4].s.len = strlen(vps[4].s.s);
734
735                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%s] [%s]\n",
736                                         i, fname.len, fname.s,
737                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].s.s);
738                 } else if(ket->ptypes[0]==SR_KEMIP_STR
739                                 && ket->ptypes[1]==SR_KEMIP_STR
740                                 && ket->ptypes[2]==SR_KEMIP_INT
741                                 && ket->ptypes[3]==SR_KEMIP_STR
742                                 && ket->ptypes[4]==SR_KEMIP_INT) {
743                         if(!PyArg_ParseTuple(args, "ssnsn:kemi-param-ssnsn",
744                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
745                                 LM_ERR("unable to retrieve ssnsn params %d\n", i);
746                                 return sr_kemi_apy_return_false();
747                         }
748                         vps[0].s.len = strlen(vps[0].s.s);
749                         vps[1].s.len = strlen(vps[1].s.s);
750                         vps[3].s.len = strlen(vps[3].s.s);
751
752                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%s] [%d]\n",
753                                         i, fname.len, fname.s,
754                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].n);
755                 } else if(ket->ptypes[0]==SR_KEMIP_STR
756                                 && ket->ptypes[1]==SR_KEMIP_STR
757                                 && ket->ptypes[2]==SR_KEMIP_INT
758                                 && ket->ptypes[3]==SR_KEMIP_INT
759                                 && ket->ptypes[4]==SR_KEMIP_STR) {
760                         if(!PyArg_ParseTuple(args, "ssnns:kemi-param-ssnns",
761                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
762                                 LM_ERR("unable to retrieve ssnns params %d\n", i);
763                                 return sr_kemi_apy_return_false();
764                         }
765                         vps[0].s.len = strlen(vps[0].s.s);
766                         vps[1].s.len = strlen(vps[1].s.s);
767                         vps[4].s.len = strlen(vps[4].s.s);
768
769                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%d] [%s]\n",
770                                         i, fname.len, fname.s,
771                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].n, vps[4].s.s);
772                 } else if(ket->ptypes[0]==SR_KEMIP_STR
773                                 && ket->ptypes[1]==SR_KEMIP_STR
774                                 && ket->ptypes[2]==SR_KEMIP_INT
775                                 && ket->ptypes[3]==SR_KEMIP_INT
776                                 && ket->ptypes[4]==SR_KEMIP_INT) {
777                         if(!PyArg_ParseTuple(args, "ssnnn:kemi-param-ssnnn",
778                                         &vps[0].s.s, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].n)) {
779                                 LM_ERR("unable to retrieve ssnnn params %d\n", i);
780                                 return sr_kemi_apy_return_false();
781                         }
782                         vps[0].s.len = strlen(vps[0].s.s);
783                         vps[1].s.len = strlen(vps[1].s.s);
784
785                         LM_DBG("params[%d] for: %.*s are: [%s] [%s] [%d] [%d] [%d]\n",
786                                         i, fname.len, fname.s,
787                                         vps[0].s.s, vps[1].s.s, vps[2].n, vps[3].n, vps[4].n);
788                 } else if(ket->ptypes[0]==SR_KEMIP_STR
789                                 && ket->ptypes[1]==SR_KEMIP_INT
790                                 && ket->ptypes[2]==SR_KEMIP_STR
791                                 && ket->ptypes[3]==SR_KEMIP_STR
792                                 && ket->ptypes[4]==SR_KEMIP_STR) {
793                         if(!PyArg_ParseTuple(args, "snsss:kemi-param-snsss",
794                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
795                                 LM_ERR("unable to retrieve snsss params %d\n", i);
796                                 return sr_kemi_apy_return_false();
797                         }
798                         vps[0].s.len = strlen(vps[0].s.s);
799                         vps[2].s.len = strlen(vps[2].s.s);
800                         vps[3].s.len = strlen(vps[3].s.s);
801                         vps[4].s.len = strlen(vps[4].s.s);
802
803                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%s] [%s]\n",
804                                         i, fname.len, fname.s,
805                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].s.s);
806                 } else if(ket->ptypes[0]==SR_KEMIP_STR
807                                 && ket->ptypes[1]==SR_KEMIP_INT
808                                 && ket->ptypes[2]==SR_KEMIP_STR
809                                 && ket->ptypes[3]==SR_KEMIP_STR
810                                 && ket->ptypes[4]==SR_KEMIP_INT) {
811                         if(!PyArg_ParseTuple(args, "snssn:kemi-param-snssn",
812                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
813                                 LM_ERR("unable to retrieve snssn params %d\n", i);
814                                 return sr_kemi_apy_return_false();
815                         }
816                         vps[0].s.len = strlen(vps[0].s.s);
817                         vps[2].s.len = strlen(vps[2].s.s);
818                         vps[3].s.len = strlen(vps[3].s.s);
819
820                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%s] [%d]\n",
821                                         i, fname.len, fname.s,
822                                         vps[0].s.s, vps[1].n, vps[2].s.s, 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_STR
826                                 && ket->ptypes[3]==SR_KEMIP_INT
827                                 && ket->ptypes[4]==SR_KEMIP_STR) {
828                         if(!PyArg_ParseTuple(args, "snsns:kemi-param-snsns",
829                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
830                                 LM_ERR("unable to retrieve snsns params %d\n", i);
831                                 return sr_kemi_apy_return_false();
832                         }
833                         vps[0].s.len = strlen(vps[0].s.s);
834                         vps[2].s.len = strlen(vps[2].s.s);
835                         vps[4].s.len = strlen(vps[4].s.s);
836
837                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%d] [%s]\n",
838                                         i, fname.len, fname.s,
839                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].n, vps[4].s.s);
840                 } else if(ket->ptypes[0]==SR_KEMIP_STR
841                                 && ket->ptypes[1]==SR_KEMIP_INT
842                                 && ket->ptypes[2]==SR_KEMIP_STR
843                                 && ket->ptypes[3]==SR_KEMIP_INT
844                                 && ket->ptypes[4]==SR_KEMIP_INT) {
845                         if(!PyArg_ParseTuple(args, "snsnn:kemi-param-snsnn",
846                                         &vps[0].s.s, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
847                                 LM_ERR("unable to retrieve snsnn params %d\n", i);
848                                 return sr_kemi_apy_return_false();
849                         }
850                         vps[0].s.len = strlen(vps[0].s.s);
851                         vps[2].s.len = strlen(vps[2].s.s);
852
853                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%s] [%d] [%d]\n",
854                                         i, fname.len, fname.s,
855                                         vps[0].s.s, vps[1].n, vps[2].s.s, vps[3].n, vps[4].n);
856                 } else if(ket->ptypes[0]==SR_KEMIP_STR
857                                 && ket->ptypes[1]==SR_KEMIP_INT
858                                 && ket->ptypes[2]==SR_KEMIP_INT
859                                 && ket->ptypes[3]==SR_KEMIP_STR
860                                 && ket->ptypes[4]==SR_KEMIP_STR) {
861                         if(!PyArg_ParseTuple(args, "snnss:kemi-param-snnss",
862                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
863                                 LM_ERR("unable to retrieve snnss params %d\n", i);
864                                 return sr_kemi_apy_return_false();
865                         }
866                         vps[0].s.len = strlen(vps[0].s.s);
867                         vps[3].s.len = strlen(vps[3].s.s);
868                         vps[4].s.len = strlen(vps[4].s.s);
869
870                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%s] [%s]\n",
871                                         i, fname.len, fname.s,
872                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].s.s, vps[4].s.s);
873                 } else if(ket->ptypes[0]==SR_KEMIP_STR
874                                 && ket->ptypes[1]==SR_KEMIP_INT
875                                 && ket->ptypes[2]==SR_KEMIP_INT
876                                 && ket->ptypes[3]==SR_KEMIP_STR
877                                 && ket->ptypes[4]==SR_KEMIP_INT) {
878                         if(!PyArg_ParseTuple(args, "snnsn:kemi-param-snnsn",
879                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
880                                 LM_ERR("unable to retrieve snnsn params %d\n", i);
881                                 return sr_kemi_apy_return_false();
882                         }
883                         vps[0].s.len = strlen(vps[0].s.s);
884                         vps[3].s.len = strlen(vps[3].s.s);
885
886                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%s] [%d]\n",
887                                         i, fname.len, fname.s,
888                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].s.s, vps[4].n);
889                 } else if(ket->ptypes[0]==SR_KEMIP_STR
890                                 && ket->ptypes[1]==SR_KEMIP_INT
891                                 && ket->ptypes[2]==SR_KEMIP_INT
892                                 && ket->ptypes[3]==SR_KEMIP_INT
893                                 && ket->ptypes[4]==SR_KEMIP_STR) {
894                         if(!PyArg_ParseTuple(args, "snnns:kemi-param-snnns",
895                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
896                                 LM_ERR("unable to retrieve snnns params %d\n", i);
897                                 return sr_kemi_apy_return_false();
898                         }
899                         vps[0].s.len = strlen(vps[0].s.s);
900                         vps[4].s.len = strlen(vps[4].s.s);
901
902                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%d] [%s]\n",
903                                         i, fname.len, fname.s,
904                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].n, vps[4].s.s);
905                 } else if(ket->ptypes[0]==SR_KEMIP_STR
906                                 && ket->ptypes[1]==SR_KEMIP_INT
907                                 && ket->ptypes[2]==SR_KEMIP_INT
908                                 && ket->ptypes[3]==SR_KEMIP_INT
909                                 && ket->ptypes[4]==SR_KEMIP_INT) {
910                         if(!PyArg_ParseTuple(args, "snnnn:kemi-param-snnnn",
911                                         &vps[0].s.s, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].n)) {
912                                 LM_ERR("unable to retrieve snnnn params %d\n", i);
913                                 return sr_kemi_apy_return_false();
914                         }
915                         vps[0].s.len = strlen(vps[0].s.s);
916
917                         LM_DBG("params[%d] for: %.*s are: [%s] [%d] [%d] [%d] [%d]\n",
918                                         i, fname.len, fname.s,
919                                         vps[0].s.s, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
920                 } else if(ket->ptypes[0]==SR_KEMIP_INT
921                                 && ket->ptypes[1]==SR_KEMIP_STR
922                                 && ket->ptypes[2]==SR_KEMIP_STR
923                                 && ket->ptypes[3]==SR_KEMIP_STR
924                                 && ket->ptypes[4]==SR_KEMIP_STR) {
925                         if(!PyArg_ParseTuple(args, "nssss:kemi-param-nssss",
926                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
927                                 LM_ERR("unable to retrieve nssss params %d\n", i);
928                                 return sr_kemi_apy_return_false();
929                         }
930                         vps[1].s.len = strlen(vps[1].s.s);
931                         vps[2].s.len = strlen(vps[2].s.s);
932                         vps[3].s.len = strlen(vps[3].s.s);
933                         vps[4].s.len = strlen(vps[4].s.s);
934
935                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%s] [%s]\n",
936                                         i, fname.len, fname.s,
937                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].s.s, vps[4].s.s);
938                 } else if(ket->ptypes[0]==SR_KEMIP_INT
939                                 && ket->ptypes[1]==SR_KEMIP_STR
940                                 && ket->ptypes[2]==SR_KEMIP_STR
941                                 && ket->ptypes[3]==SR_KEMIP_STR
942                                 && ket->ptypes[4]==SR_KEMIP_INT) {
943                         if(!PyArg_ParseTuple(args, "nsssn:kemi-param-nsssn",
944                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
945                                 LM_ERR("unable to retrieve nsssn params %d\n", i);
946                                 return sr_kemi_apy_return_false();
947                         }
948                         vps[1].s.len = strlen(vps[1].s.s);
949                         vps[2].s.len = strlen(vps[2].s.s);
950                         vps[3].s.len = strlen(vps[3].s.s);
951
952                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%s] [%d]\n",
953                                         i, fname.len, fname.s,
954                                         vps[0].n, vps[1].s.s, vps[2].s.s, 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_STR
958                                 && ket->ptypes[3]==SR_KEMIP_INT
959                                 && ket->ptypes[4]==SR_KEMIP_STR) {
960                         if(!PyArg_ParseTuple(args, "nssns:kemi-param-nssns",
961                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
962                                 LM_ERR("unable to retrieve nssns params %d\n", i);
963                                 return sr_kemi_apy_return_false();
964                         }
965                         vps[1].s.len = strlen(vps[1].s.s);
966                         vps[2].s.len = strlen(vps[2].s.s);
967                         vps[4].s.len = strlen(vps[4].s.s);
968
969                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%d] [%s]\n",
970                                         i, fname.len, fname.s,
971                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].s.s);
972                 } else if(ket->ptypes[0]==SR_KEMIP_INT
973                                 && ket->ptypes[1]==SR_KEMIP_STR
974                                 && ket->ptypes[2]==SR_KEMIP_STR
975                                 && ket->ptypes[3]==SR_KEMIP_INT
976                                 && ket->ptypes[4]==SR_KEMIP_INT) {
977                         if(!PyArg_ParseTuple(args, "nssnn:kemi-param-nssnn",
978                                         &vps[0].n, &vps[1].s.s, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
979                                 LM_ERR("unable to retrieve nssnn params %d\n", i);
980                                 return sr_kemi_apy_return_false();
981                         }
982                         vps[1].s.len = strlen(vps[1].s.s);
983                         vps[2].s.len = strlen(vps[2].s.s);
984
985                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%s] [%d] [%d]\n",
986                                         i, fname.len, fname.s,
987                                         vps[0].n, vps[1].s.s, vps[2].s.s, vps[3].n, vps[4].n);
988                 } else if(ket->ptypes[0]==SR_KEMIP_INT
989                                 && ket->ptypes[1]==SR_KEMIP_STR
990                                 && ket->ptypes[2]==SR_KEMIP_INT
991                                 && ket->ptypes[3]==SR_KEMIP_STR
992                                 && ket->ptypes[4]==SR_KEMIP_STR) {
993                         if(!PyArg_ParseTuple(args, "nsnss:kemi-param-nsnss",
994                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
995                                 LM_ERR("unable to retrieve nsnss params %d\n", i);
996                                 return sr_kemi_apy_return_false();
997                         }
998                         vps[1].s.len = strlen(vps[1].s.s);
999                         vps[3].s.len = strlen(vps[3].s.s);
1000                         vps[4].s.len = strlen(vps[4].s.s);
1001
1002                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%s] [%s]\n",
1003                                         i, fname.len, fname.s,
1004                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].s.s);
1005                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1006                                 && ket->ptypes[1]==SR_KEMIP_STR
1007                                 && ket->ptypes[2]==SR_KEMIP_INT
1008                                 && ket->ptypes[3]==SR_KEMIP_STR
1009                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1010                         if(!PyArg_ParseTuple(args, "nsnsn:kemi-param-nsnsn",
1011                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
1012                                 LM_ERR("unable to retrieve nsnsn params %d\n", i);
1013                                 return sr_kemi_apy_return_false();
1014                         }
1015                         vps[1].s.len = strlen(vps[1].s.s);
1016                         vps[3].s.len = strlen(vps[3].s.s);
1017
1018                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%s] [%d]\n",
1019                                         i, fname.len, fname.s,
1020                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].s.s, vps[4].n);
1021                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1022                                 && ket->ptypes[1]==SR_KEMIP_STR
1023                                 && ket->ptypes[2]==SR_KEMIP_INT
1024                                 && ket->ptypes[3]==SR_KEMIP_INT
1025                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1026                         if(!PyArg_ParseTuple(args, "nsnns:kemi-param-nsnns",
1027                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
1028                                 LM_ERR("unable to retrieve nsnns params %d\n", i);
1029                                 return sr_kemi_apy_return_false();
1030                         }
1031                         vps[1].s.len = strlen(vps[1].s.s);
1032                         vps[4].s.len = strlen(vps[4].s.s);
1033
1034                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%d] [%s]\n",
1035                                         i, fname.len, fname.s,
1036                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].n, vps[4].s.s);
1037                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1038                                 && ket->ptypes[1]==SR_KEMIP_STR
1039                                 && ket->ptypes[2]==SR_KEMIP_INT
1040                                 && ket->ptypes[3]==SR_KEMIP_INT
1041                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1042                         if(!PyArg_ParseTuple(args, "nsnnn:kemi-param-nsnnn",
1043                                         &vps[0].n, &vps[1].s.s, &vps[2].n, &vps[3].n, &vps[4].n)) {
1044                                 LM_ERR("unable to retrieve nsnnn params %d\n", i);
1045                                 return sr_kemi_apy_return_false();
1046                         }
1047                         vps[1].s.len = strlen(vps[1].s.s);
1048
1049                         LM_DBG("params[%d] for: %.*s are: [%d] [%s] [%d] [%d] [%d]\n",
1050                                         i, fname.len, fname.s,
1051                                         vps[0].n, vps[1].s.s, vps[2].n, vps[3].n, vps[4].n);
1052                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1053                                 && ket->ptypes[1]==SR_KEMIP_INT
1054                                 && ket->ptypes[2]==SR_KEMIP_STR
1055                                 && ket->ptypes[3]==SR_KEMIP_STR
1056                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1057                         if(!PyArg_ParseTuple(args, "nnsss:kemi-param-nnsss",
1058                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].s.s)) {
1059                                 LM_ERR("unable to retrieve nnsss params %d\n", i);
1060                                 return sr_kemi_apy_return_false();
1061                         }
1062                         vps[2].s.len = strlen(vps[2].s.s);
1063                         vps[3].s.len = strlen(vps[3].s.s);
1064                         vps[4].s.len = strlen(vps[4].s.s);
1065
1066                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%s] [%s]\n",
1067                                         i, fname.len, fname.s,
1068                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].s.s);
1069                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1070                                 && ket->ptypes[1]==SR_KEMIP_INT
1071                                 && ket->ptypes[2]==SR_KEMIP_STR
1072                                 && ket->ptypes[3]==SR_KEMIP_STR
1073                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1074                         if(!PyArg_ParseTuple(args, "nnssn:kemi-param-nnssn",
1075                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].s.s, &vps[4].n)) {
1076                                 LM_ERR("unable to retrieve nnssn params %d\n", i);
1077                                 return sr_kemi_apy_return_false();
1078                         }
1079                         vps[2].s.len = strlen(vps[2].s.s);
1080                         vps[3].s.len = strlen(vps[3].s.s);
1081
1082                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%s] [%d]\n",
1083                                         i, fname.len, fname.s,
1084                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].s.s, vps[4].n);
1085                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1086                                 && ket->ptypes[1]==SR_KEMIP_INT
1087                                 && ket->ptypes[2]==SR_KEMIP_STR
1088                                 && ket->ptypes[3]==SR_KEMIP_INT
1089                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1090                         if(!PyArg_ParseTuple(args, "nnsns:kemi-param-nnsns",
1091                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].s.s)) {
1092                                 LM_ERR("unable to retrieve nnsns params %d\n", i);
1093                                 return sr_kemi_apy_return_false();
1094                         }
1095                         vps[2].s.len = strlen(vps[2].s.s);
1096                         vps[4].s.len = strlen(vps[4].s.s);
1097
1098                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%d] [%s]\n",
1099                                         i, fname.len, fname.s,
1100                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].n, vps[4].s.s);
1101                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1102                                 && ket->ptypes[1]==SR_KEMIP_INT
1103                                 && ket->ptypes[2]==SR_KEMIP_STR
1104                                 && ket->ptypes[3]==SR_KEMIP_INT
1105                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1106                         if(!PyArg_ParseTuple(args, "nnsnn:kemi-param-nnsnn",
1107                                         &vps[0].n, &vps[1].n, &vps[2].s.s, &vps[3].n, &vps[4].n)) {
1108                                 LM_ERR("unable to retrieve nnsnn params %d\n", i);
1109                                 return sr_kemi_apy_return_false();
1110                         }
1111                         vps[2].s.len = strlen(vps[2].s.s);
1112
1113                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%s] [%d] [%d]\n",
1114                                         i, fname.len, fname.s,
1115                                         vps[0].n, vps[1].n, vps[2].s.s, vps[3].n, vps[4].n);
1116                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1117                                 && ket->ptypes[1]==SR_KEMIP_INT
1118                                 && ket->ptypes[2]==SR_KEMIP_INT
1119                                 && ket->ptypes[3]==SR_KEMIP_STR
1120                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1121                         if(!PyArg_ParseTuple(args, "nnnss:kemi-param-nnnss",
1122                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].s.s)) {
1123                                 LM_ERR("unable to retrieve nnnss params %d\n", i);
1124                                 return sr_kemi_apy_return_false();
1125                         }
1126                         vps[3].s.len = strlen(vps[3].s.s);
1127                         vps[4].s.len = strlen(vps[4].s.s);
1128
1129                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%s] [%s]\n",
1130                                         i, fname.len, fname.s,
1131                                         vps[0].n, vps[1].n, vps[2].n, vps[3].s.s, vps[4].s.s);
1132                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1133                                 && ket->ptypes[1]==SR_KEMIP_INT
1134                                 && ket->ptypes[2]==SR_KEMIP_INT
1135                                 && ket->ptypes[3]==SR_KEMIP_STR
1136                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1137                         if(!PyArg_ParseTuple(args, "nnnsn:kemi-param-nnnsn",
1138                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].s.s, &vps[4].n)) {
1139                                 LM_ERR("unable to retrieve nnnsn params %d\n", i);
1140                                 return sr_kemi_apy_return_false();
1141                         }
1142                         vps[3].s.len = strlen(vps[3].s.s);
1143
1144                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%s] [%d]\n",
1145                                         i, fname.len, fname.s,
1146                                         vps[0].n, vps[1].n, vps[2].n, vps[3].s.s, vps[4].n);
1147                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1148                                 && ket->ptypes[1]==SR_KEMIP_INT
1149                                 && ket->ptypes[2]==SR_KEMIP_INT
1150                                 && ket->ptypes[3]==SR_KEMIP_INT
1151                                 && ket->ptypes[4]==SR_KEMIP_STR) {
1152                         if(!PyArg_ParseTuple(args, "nnnns:kemi-param-nnnns",
1153                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].s.s)) {
1154                                 LM_ERR("unable to retrieve nnnns params %d\n", i);
1155                                 return sr_kemi_apy_return_false();
1156                         }
1157                         vps[4].s.len = strlen(vps[4].s.s);
1158
1159                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%d] [%s]\n",
1160                                         i, fname.len, fname.s,
1161                                         vps[0].n, vps[1].n, vps[2].n, vps[3].n, vps[4].s.s);
1162                 } else if(ket->ptypes[0]==SR_KEMIP_INT
1163                                 && ket->ptypes[1]==SR_KEMIP_INT
1164                                 && ket->ptypes[2]==SR_KEMIP_INT
1165                                 && ket->ptypes[3]==SR_KEMIP_INT
1166                                 && ket->ptypes[4]==SR_KEMIP_INT) {
1167                         if(!PyArg_ParseTuple(args, "nnnnn:kemi-param-nnnnn",
1168                                         &vps[0].n, &vps[1].n, &vps[2].n, &vps[3].n, &vps[4].n)) {
1169                                 LM_ERR("unable to retrieve nnnnn params %d\n", i);
1170                                 return sr_kemi_apy_return_false();
1171                         }
1172
1173                         LM_DBG("params[%d] for: %.*s are: [%d] [%d] [%d] [%d] [%d]\n",
1174                                         i, fname.len, fname.s,
1175                                         vps[0].n, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
1176                 } else {
1177                         LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
1178                         return sr_kemi_apy_return_false();
1179                 }
1180         } else {
1181                 i = 6;
1182                 if(ket->ptypes[0]==SR_KEMIP_STR
1183                                 && ket->ptypes[1]==SR_KEMIP_STR
1184                                 && ket->ptypes[2]==SR_KEMIP_STR
1185                                 && ket->ptypes[3]==SR_KEMIP_STR
1186                                 && ket->ptypes[4]==SR_KEMIP_STR
1187                                 && ket->ptypes[5]==SR_KEMIP_STR) {
1188                         if(!PyArg_ParseTuple(args, "ssssss:kemi-param-ssssss",
1189                                                 &vps[0].s.s, &vps[1].s.s, &vps[2].s.s, &vps[3].s.s,
1190                                                 &vps[4].s.s, &vps[5].s.s)) {
1191                                 LM_ERR("unable to retrieve str-str-str-str params %d\n", i);
1192                                 return sr_kemi_apy_return_false();
1193                         }
1194                         vps[0].s.len = strlen(vps[0].s.s);
1195                         vps[1].s.len = strlen(vps[1].s.s);
1196                         vps[2].s.len = strlen(vps[2].s.s);
1197                         vps[3].s.len = strlen(vps[3].s.s);
1198                         vps[4].s.len = strlen(vps[4].s.s);
1199                         vps[5].s.len = strlen(vps[5].s.s);
1200                         LM_DBG("params[%d] for: %.*s are str: [%.*s] [%.*s]"
1201                                         " [%.*s] [%.*s] [%.*s] [%.*s]\n", i,
1202                                 fname.len, fname.s, vps[0].s.len, vps[0].s.s,
1203                                 vps[1].s.len, vps[1].s.s, vps[2].s.len, vps[2].s.s,
1204                                 vps[3].s.len, vps[3].s.s, vps[4].s.len, vps[4].s.s,
1205                                 vps[5].s.len, vps[5].s.s);
1206                 } else {
1207                         LM_ERR("not implemented yet\n");
1208                         return sr_kemi_apy_return_false();
1209                 }
1210         }
1211
1212         switch(i) {
1213                 case 1:
1214                         if(ket->ptypes[0]==SR_KEMIP_INT) {
1215                                 if(ket->rtype==SR_KEMIP_XVAL) {
1216                                         xret = ((sr_kemi_xfmn_f)(ket->func))(lmsg, vps[0].n);
1217                                         return sr_kemi_apy_return_xval(ket, xret);
1218                                 } else {
1219                                         ret = ((sr_kemi_fmn_f)(ket->func))(lmsg, vps[0].n);
1220                                         return sr_kemi_apy_return_int(ket, ret);
1221                                 }
1222                         } else if(ket->ptypes[0]==SR_KEMIP_STR) {
1223                                 if(ket->rtype==SR_KEMIP_XVAL) {
1224                                         xret = ((sr_kemi_xfms_f)(ket->func))(lmsg, &vps[0].s);
1225                                         return sr_kemi_apy_return_xval(ket, xret);
1226                                 } else {
1227                                         ret = ((sr_kemi_fms_f)(ket->func))(lmsg, &vps[0].s);
1228                                         return sr_kemi_apy_return_int(ket, ret);
1229                                 }
1230                         } else {
1231                                 LM_ERR("invalid parameters for: %.*s\n",
1232                                                 fname.len, fname.s);
1233                                 return sr_kemi_apy_return_false();
1234                         }
1235                 break;
1236                 case 2:
1237                         if(ket->ptypes[0]==SR_KEMIP_INT) {
1238                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1239                                         if(ket->rtype==SR_KEMIP_XVAL) {
1240                                                 xret = ((sr_kemi_xfmnn_f)(ket->func))(lmsg, vps[0].n, vps[1].n);
1241                                                 return sr_kemi_apy_return_xval(ket, xret);
1242                                         } else {
1243                                                 ret = ((sr_kemi_fmnn_f)(ket->func))(lmsg, vps[0].n, vps[1].n);
1244                                                 return sr_kemi_apy_return_int(ket, ret);
1245                                         }
1246                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1247                                         if(ket->rtype==SR_KEMIP_XVAL) {
1248                                                 xret = ((sr_kemi_xfmns_f)(ket->func))(lmsg, vps[0].n, &vps[1].s);
1249                                                 return sr_kemi_apy_return_xval(ket, xret);
1250                                         } else {
1251                                                 ret = ((sr_kemi_fmns_f)(ket->func))(lmsg, vps[0].n, &vps[1].s);
1252                                                 return sr_kemi_apy_return_int(ket, ret);
1253                                         }
1254                                 } else {
1255                                         LM_ERR("invalid parameters for: %.*s\n",
1256                                                         fname.len, fname.s);
1257                                         return sr_kemi_apy_return_false();
1258                                 }
1259                         } else if(ket->ptypes[0]==SR_KEMIP_STR) {
1260                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1261                                         if(ket->rtype==SR_KEMIP_XVAL) {
1262                                                 xret = ((sr_kemi_xfmsn_f)(ket->func))(lmsg, &vps[0].s, vps[1].n);
1263                                                 return sr_kemi_apy_return_xval(ket, xret);
1264                                         } else {
1265                                                 ret = ((sr_kemi_fmsn_f)(ket->func))(lmsg, &vps[0].s, vps[1].n);
1266                                                 return sr_kemi_apy_return_int(ket, ret);
1267                                         }
1268                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1269                                         if(ket->rtype==SR_KEMIP_XVAL) {
1270                                                 xret = ((sr_kemi_xfmss_f)(ket->func))(lmsg, &vps[0].s, &vps[1].s);
1271                                                 return sr_kemi_apy_return_xval(ket, xret);
1272                                         } else {
1273                                                 ret = ((sr_kemi_fmss_f)(ket->func))(lmsg, &vps[0].s, &vps[1].s);
1274                                                 return sr_kemi_apy_return_int(ket, ret);
1275                                         }
1276                                 } else {
1277                                         LM_ERR("invalid parameters for: %.*s\n",
1278                                                         fname.len, fname.s);
1279                                         return sr_kemi_apy_return_false();
1280                                 }
1281                         } else {
1282                                 LM_ERR("invalid parameters for: %.*s\n",
1283                                                 fname.len, fname.s);
1284                                 return sr_kemi_apy_return_false();
1285                         }
1286                 break;
1287                 case 3:
1288                         if(ket->ptypes[0]==SR_KEMIP_INT) {
1289                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1290                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1291                                                 /* nnn */
1292                                                 ret = ((sr_kemi_fmnnn_f)(ket->func))(lmsg,
1293                                                                 vps[0].n, vps[1].n, vps[2].n);
1294                                                 return sr_kemi_apy_return_int(ket, ret);
1295                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1296                                                 /* nns */
1297                                                 ret = ((sr_kemi_fmnns_f)(ket->func))(lmsg,
1298                                                                 vps[0].n, vps[1].n, &vps[2].s);
1299                                                 return sr_kemi_apy_return_int(ket, ret);
1300                                         } else {
1301                                                 LM_ERR("invalid parameters for: %.*s\n",
1302                                                                 fname.len, fname.s);
1303                                                 return sr_kemi_apy_return_false();
1304                                         }
1305                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1306                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1307                                                 /* nsn */
1308                                                 ret = ((sr_kemi_fmnsn_f)(ket->func))(lmsg,
1309                                                                 vps[0].n, &vps[1].s, vps[2].n);
1310                                                 return sr_kemi_apy_return_int(ket, ret);
1311                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1312                                                 /* nss */
1313                                                 ret = ((sr_kemi_fmnss_f)(ket->func))(lmsg,
1314                                                                 vps[0].n, &vps[1].s, &vps[2].s);
1315                                                 return sr_kemi_apy_return_int(ket, ret);
1316                                         } else {
1317                                                 LM_ERR("invalid parameters for: %.*s\n",
1318                                                                 fname.len, fname.s);
1319                                                 return sr_kemi_apy_return_false();
1320                                         }
1321                                 } else {
1322                                         LM_ERR("invalid parameters for: %.*s\n",
1323                                                         fname.len, fname.s);
1324                                         return sr_kemi_apy_return_false();
1325                                 }
1326                         } else if(ket->ptypes[0]==SR_KEMIP_STR) {
1327                                 if(ket->ptypes[1]==SR_KEMIP_INT) {
1328                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1329                                                 /* snn */
1330                                                 ret = ((sr_kemi_fmsnn_f)(ket->func))(lmsg,
1331                                                                 &vps[0].s, vps[1].n, vps[2].n);
1332                                                 return sr_kemi_apy_return_int(ket, ret);
1333                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1334                                                 /* sns */
1335                                                 ret = ((sr_kemi_fmsns_f)(ket->func))(lmsg,
1336                                                                 &vps[0].s, vps[1].n, &vps[2].s);
1337                                                 return sr_kemi_apy_return_int(ket, ret);
1338                                         } else {
1339                                                 LM_ERR("invalid parameters for: %.*s\n",
1340                                                                 fname.len, fname.s);
1341                                                 return sr_kemi_apy_return_false();
1342                                         }
1343                                 } else if(ket->ptypes[1]==SR_KEMIP_STR) {
1344                                         if(ket->ptypes[2]==SR_KEMIP_INT) {
1345                                                 /* ssn */
1346                                                 ret = ((sr_kemi_fmssn_f)(ket->func))(lmsg,
1347                                                                 &vps[0].s, &vps[1].s, vps[2].n);
1348                                                 return sr_kemi_apy_return_int(ket, ret);
1349                                         } else if(ket->ptypes[2]==SR_KEMIP_STR) {
1350                                                 /* sss */
1351                                                 ret = ((sr_kemi_fmsss_f)(ket->func))(lmsg,
1352                                                                 &vps[0].s, &vps[1].s, &vps[2].s);
1353                                                 return sr_kemi_apy_return_int(ket, ret);
1354                                         } else {
1355                                                 LM_ERR("invalid parameters for: %.*s\n",
1356                                                                 fname.len, fname.s);
1357                                                 return sr_kemi_apy_return_false();
1358                                         }
1359                                 } else {
1360                                         LM_ERR("invalid parameters for: %.*s\n",
1361                                                         fname.len, fname.s);
1362                                         return sr_kemi_apy_return_false();
1363                                 }
1364                         } else {
1365                                 LM_ERR("invalid parameters for: %.*s\n",
1366                                                 fname.len, fname.s);
1367                                 return sr_kemi_apy_return_false();
1368                         }
1369                 break;
1370                 case 4:
1371                         if(ket->ptypes[0]==SR_KEMIP_STR
1372                                         && ket->ptypes[1]==SR_KEMIP_STR
1373                                         && ket->ptypes[2]==SR_KEMIP_STR
1374                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1375                                 ret = ((sr_kemi_fmssss_f)(ket->func))(lmsg,
1376                                                 &vps[0].s, &vps[1].s, &vps[2].s, &vps[3].s);
1377                                 return sr_kemi_apy_return_int(ket, ret);
1378                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1379                                         && ket->ptypes[1]==SR_KEMIP_STR
1380                                         && ket->ptypes[2]==SR_KEMIP_STR
1381                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1382                                 ret = ((sr_kemi_fmsssn_f)(ket->func))(lmsg,
1383                                                 &vps[0].s, &vps[1].s, &vps[2].s, vps[3].n);
1384                                 return sr_kemi_apy_return_int(ket, ret);
1385                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1386                                         && ket->ptypes[1]==SR_KEMIP_STR
1387                                         && ket->ptypes[2]==SR_KEMIP_INT
1388                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1389                                 ret = ((sr_kemi_fmssns_f)(ket->func))(lmsg,
1390                                                 &vps[0].s, &vps[1].s, vps[2].n, &vps[3].s);
1391                                 return sr_kemi_apy_return_int(ket, ret);
1392                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1393                                         && ket->ptypes[1]==SR_KEMIP_STR
1394                                         && ket->ptypes[2]==SR_KEMIP_INT
1395                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1396                                 ret = ((sr_kemi_fmssnn_f)(ket->func))(lmsg,
1397                                                 &vps[0].s, &vps[1].s, vps[2].n, vps[3].n);
1398                                 return sr_kemi_apy_return_int(ket, ret);
1399                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1400                                         && ket->ptypes[1]==SR_KEMIP_INT
1401                                         && ket->ptypes[2]==SR_KEMIP_STR
1402                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1403                                 ret = ((sr_kemi_fmsnss_f)(ket->func))(lmsg,
1404                                                 &vps[0].s, vps[1].n, &vps[2].s, &vps[3].s);
1405                                 return sr_kemi_apy_return_int(ket, ret);
1406                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1407                                         && ket->ptypes[1]==SR_KEMIP_INT
1408                                         && ket->ptypes[2]==SR_KEMIP_STR
1409                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1410                                 ret = ((sr_kemi_fmsnsn_f)(ket->func))(lmsg,
1411                                                 &vps[0].s, vps[1].n, &vps[2].s, vps[3].n);
1412                                 return sr_kemi_apy_return_int(ket, ret);
1413                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1414                                         && ket->ptypes[1]==SR_KEMIP_INT
1415                                         && ket->ptypes[2]==SR_KEMIP_INT
1416                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1417                                 ret = ((sr_kemi_fmsnns_f)(ket->func))(lmsg,
1418                                                 &vps[0].s, vps[1].n, vps[2].n, &vps[3].s);
1419                                 return sr_kemi_apy_return_int(ket, ret);
1420                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1421                                         && ket->ptypes[1]==SR_KEMIP_INT
1422                                         && ket->ptypes[2]==SR_KEMIP_INT
1423                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1424                                 ret = ((sr_kemi_fmsnnn_f)(ket->func))(lmsg,
1425                                                 &vps[0].s, vps[1].n, vps[2].n, vps[3].n);
1426                                 return sr_kemi_apy_return_int(ket, ret);
1427                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1428                                         && ket->ptypes[1]==SR_KEMIP_STR
1429                                         && ket->ptypes[2]==SR_KEMIP_STR
1430                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1431                                 ret = ((sr_kemi_fmnsss_f)(ket->func))(lmsg,
1432                                                 vps[0].n, &vps[1].s, &vps[2].s, &vps[3].s);
1433                                 return sr_kemi_apy_return_int(ket, ret);
1434                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1435                                         && ket->ptypes[1]==SR_KEMIP_STR
1436                                         && ket->ptypes[2]==SR_KEMIP_STR
1437                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1438                                 ret = ((sr_kemi_fmnssn_f)(ket->func))(lmsg,
1439                                                 vps[0].n, &vps[1].s, &vps[2].s, vps[3].n);
1440                                 return sr_kemi_apy_return_int(ket, ret);
1441                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1442                                         && ket->ptypes[1]==SR_KEMIP_STR
1443                                         && ket->ptypes[2]==SR_KEMIP_INT
1444                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1445                                 ret = ((sr_kemi_fmnsns_f)(ket->func))(lmsg,
1446                                                 vps[0].n, &vps[1].s, vps[2].n, &vps[3].s);
1447                                 return sr_kemi_apy_return_int(ket, ret);
1448                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1449                                         && ket->ptypes[1]==SR_KEMIP_STR
1450                                         && ket->ptypes[2]==SR_KEMIP_INT
1451                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1452                                 ret = ((sr_kemi_fmnsnn_f)(ket->func))(lmsg,
1453                                                 vps[0].n, &vps[1].s, vps[2].n, vps[3].n);
1454                                 return sr_kemi_apy_return_int(ket, ret);
1455                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1456                                         && ket->ptypes[1]==SR_KEMIP_INT
1457                                         && ket->ptypes[2]==SR_KEMIP_STR
1458                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1459                                 ret = ((sr_kemi_fmnnss_f)(ket->func))(lmsg,
1460                                                 vps[0].n, vps[1].n, &vps[2].s, &vps[3].s);
1461                                 return sr_kemi_apy_return_int(ket, ret);
1462                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1463                                         && ket->ptypes[1]==SR_KEMIP_INT
1464                                         && ket->ptypes[2]==SR_KEMIP_STR
1465                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1466                                 ret = ((sr_kemi_fmnnsn_f)(ket->func))(lmsg,
1467                                                 vps[0].n, vps[1].n, &vps[2].s, vps[3].n);
1468                                 return sr_kemi_apy_return_int(ket, ret);
1469                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1470                                         && ket->ptypes[1]==SR_KEMIP_INT
1471                                         && ket->ptypes[2]==SR_KEMIP_INT
1472                                         && ket->ptypes[3]==SR_KEMIP_STR) {
1473                                 ret = ((sr_kemi_fmnnns_f)(ket->func))(lmsg,
1474                                                 vps[0].n, vps[1].n, vps[2].n, &vps[3].s);
1475                                 return sr_kemi_apy_return_int(ket, ret);
1476                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1477                                         && ket->ptypes[1]==SR_KEMIP_INT
1478                                         && ket->ptypes[2]==SR_KEMIP_INT
1479                                         && ket->ptypes[3]==SR_KEMIP_INT) {
1480                                 ret = ((sr_kemi_fmnnnn_f)(ket->func))(lmsg,
1481                                                 vps[0].n, vps[1].n, vps[2].n, vps[3].n);
1482                                 return sr_kemi_apy_return_int(ket, ret);
1483                         } else {
1484                                 LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
1485                                 return sr_kemi_apy_return_false();
1486                         }
1487                 break;
1488                 case 5:
1489                         if(ket->ptypes[0]==SR_KEMIP_STR
1490                                         && ket->ptypes[1]==SR_KEMIP_STR
1491                                         && ket->ptypes[2]==SR_KEMIP_STR
1492                                         && ket->ptypes[3]==SR_KEMIP_STR
1493                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1494                                 ret = ((sr_kemi_fmsssss_f)(ket->func))(lmsg,
1495                                                 &vps[0].s, &vps[1].s, &vps[2].s, &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_STR
1499                                         && ket->ptypes[2]==SR_KEMIP_STR
1500                                         && ket->ptypes[3]==SR_KEMIP_STR
1501                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1502                                 ret = ((sr_kemi_fmssssn_f)(ket->func))(lmsg,
1503                                                 &vps[0].s, &vps[1].s, &vps[2].s, &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_STR
1507                                         && ket->ptypes[2]==SR_KEMIP_STR
1508                                         && ket->ptypes[3]==SR_KEMIP_INT
1509                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1510                                 ret = ((sr_kemi_fmsssns_f)(ket->func))(lmsg,
1511                                                 &vps[0].s, &vps[1].s, &vps[2].s, 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_STR
1515                                         && ket->ptypes[2]==SR_KEMIP_STR
1516                                         && ket->ptypes[3]==SR_KEMIP_INT
1517                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1518                                 ret = ((sr_kemi_fmsssnn_f)(ket->func))(lmsg,
1519                                                 &vps[0].s, &vps[1].s, &vps[2].s, vps[3].n, vps[4].n);
1520                                 return sr_kemi_apy_return_int(ket, ret);
1521                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1522                                         && ket->ptypes[1]==SR_KEMIP_STR
1523                                         && ket->ptypes[2]==SR_KEMIP_INT
1524                                         && ket->ptypes[3]==SR_KEMIP_STR
1525                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1526                                 ret = ((sr_kemi_fmssnss_f)(ket->func))(lmsg,
1527                                                 &vps[0].s, &vps[1].s, vps[2].n, &vps[3].s, &vps[4].s);
1528                                 return sr_kemi_apy_return_int(ket, ret);
1529                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1530                                         && ket->ptypes[1]==SR_KEMIP_STR
1531                                         && ket->ptypes[2]==SR_KEMIP_INT
1532                                         && ket->ptypes[3]==SR_KEMIP_STR
1533                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1534                                 ret = ((sr_kemi_fmssnsn_f)(ket->func))(lmsg,
1535                                                 &vps[0].s, &vps[1].s, vps[2].n, &vps[3].s, vps[4].n);
1536                                 return sr_kemi_apy_return_int(ket, ret);
1537                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1538                                         && ket->ptypes[1]==SR_KEMIP_STR
1539                                         && ket->ptypes[2]==SR_KEMIP_INT
1540                                         && ket->ptypes[3]==SR_KEMIP_INT
1541                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1542                                 ret = ((sr_kemi_fmssnns_f)(ket->func))(lmsg,
1543                                                 &vps[0].s, &vps[1].s, vps[2].n, vps[3].n, &vps[4].s);
1544                                 return sr_kemi_apy_return_int(ket, ret);
1545                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1546                                         && ket->ptypes[1]==SR_KEMIP_STR
1547                                         && ket->ptypes[2]==SR_KEMIP_INT
1548                                         && ket->ptypes[3]==SR_KEMIP_INT
1549                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1550                                 ret = ((sr_kemi_fmssnnn_f)(ket->func))(lmsg,
1551                                                 &vps[0].s, &vps[1].s, vps[2].n, vps[3].n, vps[4].n);
1552                                 return sr_kemi_apy_return_int(ket, ret);
1553                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1554                                         && ket->ptypes[1]==SR_KEMIP_INT
1555                                         && ket->ptypes[2]==SR_KEMIP_STR
1556                                         && ket->ptypes[3]==SR_KEMIP_STR
1557                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1558                                 ret = ((sr_kemi_fmsnsss_f)(ket->func))(lmsg,
1559                                                 &vps[0].s, vps[1].n, &vps[2].s, &vps[3].s, &vps[4].s);
1560                                 return sr_kemi_apy_return_int(ket, ret);
1561                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1562                                         && ket->ptypes[1]==SR_KEMIP_INT
1563                                         && ket->ptypes[2]==SR_KEMIP_STR
1564                                         && ket->ptypes[3]==SR_KEMIP_STR
1565                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1566                                 ret = ((sr_kemi_fmsnssn_f)(ket->func))(lmsg,
1567                                                 &vps[0].s, vps[1].n, &vps[2].s, &vps[3].s, vps[4].n);
1568                                 return sr_kemi_apy_return_int(ket, ret);
1569                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1570                                         && ket->ptypes[1]==SR_KEMIP_INT
1571                                         && ket->ptypes[2]==SR_KEMIP_STR
1572                                         && ket->ptypes[3]==SR_KEMIP_INT
1573                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1574                                 ret = ((sr_kemi_fmsnsns_f)(ket->func))(lmsg,
1575                                                 &vps[0].s, vps[1].n, &vps[2].s, vps[3].n, &vps[4].s);
1576                                 return sr_kemi_apy_return_int(ket, ret);
1577                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1578                                         && ket->ptypes[1]==SR_KEMIP_INT
1579                                         && ket->ptypes[2]==SR_KEMIP_STR
1580                                         && ket->ptypes[3]==SR_KEMIP_INT
1581                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1582                                 ret = ((sr_kemi_fmsnsnn_f)(ket->func))(lmsg,
1583                                                 &vps[0].s, vps[1].n, &vps[2].s, vps[3].n, vps[4].n);
1584                                 return sr_kemi_apy_return_int(ket, ret);
1585                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1586                                         && ket->ptypes[1]==SR_KEMIP_INT
1587                                         && ket->ptypes[2]==SR_KEMIP_INT
1588                                         && ket->ptypes[3]==SR_KEMIP_STR
1589                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1590                                 ret = ((sr_kemi_fmsnnss_f)(ket->func))(lmsg,
1591                                                 &vps[0].s, vps[1].n, vps[2].n, &vps[3].s, &vps[4].s);
1592                                 return sr_kemi_apy_return_int(ket, ret);
1593                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1594                                         && ket->ptypes[1]==SR_KEMIP_INT
1595                                         && ket->ptypes[2]==SR_KEMIP_INT
1596                                         && ket->ptypes[3]==SR_KEMIP_STR
1597                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1598                                 ret = ((sr_kemi_fmsnnsn_f)(ket->func))(lmsg,
1599                                                 &vps[0].s, vps[1].n, vps[2].n, &vps[3].s, vps[4].n);
1600                                 return sr_kemi_apy_return_int(ket, ret);
1601                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1602                                         && ket->ptypes[1]==SR_KEMIP_INT
1603                                         && ket->ptypes[2]==SR_KEMIP_INT
1604                                         && ket->ptypes[3]==SR_KEMIP_INT
1605                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1606                                 ret = ((sr_kemi_fmsnnns_f)(ket->func))(lmsg,
1607                                                 &vps[0].s, vps[1].n, vps[2].n, vps[3].n, &vps[4].s);
1608                                 return sr_kemi_apy_return_int(ket, ret);
1609                         } else if(ket->ptypes[0]==SR_KEMIP_STR
1610                                         && ket->ptypes[1]==SR_KEMIP_INT
1611                                         && ket->ptypes[2]==SR_KEMIP_INT
1612                                         && ket->ptypes[3]==SR_KEMIP_INT
1613                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1614                                 ret = ((sr_kemi_fmsnnnn_f)(ket->func))(lmsg,
1615                                                 &vps[0].s, vps[1].n, vps[2].n, 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_STR
1619                                         && ket->ptypes[2]==SR_KEMIP_STR
1620                                         && ket->ptypes[3]==SR_KEMIP_STR
1621                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1622                                 ret = ((sr_kemi_fmnssss_f)(ket->func))(lmsg,
1623                                                 vps[0].n, &vps[1].s, &vps[2].s, &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_STR
1627                                         && ket->ptypes[2]==SR_KEMIP_STR
1628                                         && ket->ptypes[3]==SR_KEMIP_STR
1629                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1630                                 ret = ((sr_kemi_fmnsssn_f)(ket->func))(lmsg,
1631                                                 vps[0].n, &vps[1].s, &vps[2].s, &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_STR
1635                                         && ket->ptypes[2]==SR_KEMIP_STR
1636                                         && ket->ptypes[3]==SR_KEMIP_INT
1637                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1638                                 ret = ((sr_kemi_fmnssns_f)(ket->func))(lmsg,
1639                                                 vps[0].n, &vps[1].s, &vps[2].s, 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_STR
1643                                         && ket->ptypes[2]==SR_KEMIP_STR
1644                                         && ket->ptypes[3]==SR_KEMIP_INT
1645                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1646                                 ret = ((sr_kemi_fmnssnn_f)(ket->func))(lmsg,
1647                                                 vps[0].n, &vps[1].s, &vps[2].s, vps[3].n, vps[4].n);
1648                                 return sr_kemi_apy_return_int(ket, ret);
1649                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1650                                         && ket->ptypes[1]==SR_KEMIP_STR
1651                                         && ket->ptypes[2]==SR_KEMIP_INT
1652                                         && ket->ptypes[3]==SR_KEMIP_STR
1653                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1654                                 ret = ((sr_kemi_fmnsnss_f)(ket->func))(lmsg,
1655                                                 vps[0].n, &vps[1].s, vps[2].n, &vps[3].s, &vps[4].s);
1656                                 return sr_kemi_apy_return_int(ket, ret);
1657                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1658                                         && ket->ptypes[1]==SR_KEMIP_STR
1659                                         && ket->ptypes[2]==SR_KEMIP_INT
1660                                         && ket->ptypes[3]==SR_KEMIP_STR
1661                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1662                                 ret = ((sr_kemi_fmnsnsn_f)(ket->func))(lmsg,
1663                                                 vps[0].n, &vps[1].s, vps[2].n, &vps[3].s, vps[4].n);
1664                                 return sr_kemi_apy_return_int(ket, ret);
1665                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1666                                         && ket->ptypes[1]==SR_KEMIP_STR
1667                                         && ket->ptypes[2]==SR_KEMIP_INT
1668                                         && ket->ptypes[3]==SR_KEMIP_INT
1669                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1670                                 ret = ((sr_kemi_fmnsnns_f)(ket->func))(lmsg,
1671                                                 vps[0].n, &vps[1].s, vps[2].n, vps[3].n, &vps[4].s);
1672                                 return sr_kemi_apy_return_int(ket, ret);
1673                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1674                                         && ket->ptypes[1]==SR_KEMIP_STR
1675                                         && ket->ptypes[2]==SR_KEMIP_INT
1676                                         && ket->ptypes[3]==SR_KEMIP_INT
1677                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1678                                 ret = ((sr_kemi_fmnsnnn_f)(ket->func))(lmsg,
1679                                                 vps[0].n, &vps[1].s, vps[2].n, vps[3].n, vps[4].n);
1680                                 return sr_kemi_apy_return_int(ket, ret);
1681                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1682                                         && ket->ptypes[1]==SR_KEMIP_INT
1683                                         && ket->ptypes[2]==SR_KEMIP_STR
1684                                         && ket->ptypes[3]==SR_KEMIP_STR
1685                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1686                                 ret = ((sr_kemi_fmnnsss_f)(ket->func))(lmsg,
1687                                                 vps[0].n, vps[1].n, &vps[2].s, &vps[3].s, &vps[4].s);
1688                                 return sr_kemi_apy_return_int(ket, ret);
1689                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1690                                         && ket->ptypes[1]==SR_KEMIP_INT
1691                                         && ket->ptypes[2]==SR_KEMIP_STR
1692                                         && ket->ptypes[3]==SR_KEMIP_STR
1693                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1694                                 ret = ((sr_kemi_fmnnssn_f)(ket->func))(lmsg,
1695                                                 vps[0].n, vps[1].n, &vps[2].s, &vps[3].s, vps[4].n);
1696                                 return sr_kemi_apy_return_int(ket, ret);
1697                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1698                                         && ket->ptypes[1]==SR_KEMIP_INT
1699                                         && ket->ptypes[2]==SR_KEMIP_STR
1700                                         && ket->ptypes[3]==SR_KEMIP_INT
1701                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1702                                 ret = ((sr_kemi_fmnnsns_f)(ket->func))(lmsg,
1703                                                 vps[0].n, vps[1].n, &vps[2].s, vps[3].n, &vps[4].s);
1704                                 return sr_kemi_apy_return_int(ket, ret);
1705                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1706                                         && ket->ptypes[1]==SR_KEMIP_INT
1707                                         && ket->ptypes[2]==SR_KEMIP_STR
1708                                         && ket->ptypes[3]==SR_KEMIP_INT
1709                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1710                                 ret = ((sr_kemi_fmnnsnn_f)(ket->func))(lmsg,
1711                                                 vps[0].n, vps[1].n, &vps[2].s, vps[3].n, vps[4].n);
1712                                 return sr_kemi_apy_return_int(ket, ret);
1713                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1714                                         && ket->ptypes[1]==SR_KEMIP_INT
1715                                         && ket->ptypes[2]==SR_KEMIP_INT
1716                                         && ket->ptypes[3]==SR_KEMIP_STR
1717                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1718                                 ret = ((sr_kemi_fmnnnss_f)(ket->func))(lmsg,
1719                                                 vps[0].n, vps[1].n, vps[2].n, &vps[3].s, &vps[4].s);
1720                                 return sr_kemi_apy_return_int(ket, ret);
1721                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1722                                         && ket->ptypes[1]==SR_KEMIP_INT
1723                                         && ket->ptypes[2]==SR_KEMIP_INT
1724                                         && ket->ptypes[3]==SR_KEMIP_STR
1725                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1726                                 ret = ((sr_kemi_fmnnnsn_f)(ket->func))(lmsg,
1727                                                 vps[0].n, vps[1].n, vps[2].n, &vps[3].s, vps[4].n);
1728                                 return sr_kemi_apy_return_int(ket, ret);
1729                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1730                                         && ket->ptypes[1]==SR_KEMIP_INT
1731                                         && ket->ptypes[2]==SR_KEMIP_INT
1732                                         && ket->ptypes[3]==SR_KEMIP_INT
1733                                         && ket->ptypes[4]==SR_KEMIP_STR) {
1734                                 ret = ((sr_kemi_fmnnnns_f)(ket->func))(lmsg,
1735                                                 vps[0].n, vps[1].n, vps[2].n, vps[3].n, &vps[4].s);
1736                                 return sr_kemi_apy_return_int(ket, ret);
1737                         } else if(ket->ptypes[0]==SR_KEMIP_INT
1738                                         && ket->ptypes[1]==SR_KEMIP_INT
1739                                         && ket->ptypes[2]==SR_KEMIP_INT
1740                                         && ket->ptypes[3]==SR_KEMIP_INT
1741                                         && ket->ptypes[4]==SR_KEMIP_INT) {
1742                                 ret = ((sr_kemi_fmnnnnn_f)(ket->func))(lmsg,
1743                                                 vps[0].n, vps[1].n, vps[2].n, vps[3].n, vps[4].n);
1744                                 return sr_kemi_apy_return_int(ket, ret);
1745                         } else {
1746                                 LM_ERR("invalid parameters for: %.*s\n", fname.len, fname.s);
1747                                 return sr_kemi_apy_return_false();
1748                         }
1749                 break;
1750                 case 6:
1751                         if(ket->ptypes[0]==SR_KEMIP_STR
1752                                         && ket->ptypes[1]==SR_KEMIP_STR
1753                                         && ket->ptypes[2]==SR_KEMIP_STR
1754                                         && ket->ptypes[3]==SR_KEMIP_STR
1755                                         && ket->ptypes[4]==SR_KEMIP_STR
1756                                         && ket->ptypes[5]==SR_KEMIP_STR) {
1757                                 /* ssssss */
1758                                 ret = ((sr_kemi_fmssssss_f)(ket->func))(lmsg,
1759                                                 &vps[0].s, &vps[1].s, &vps[2].s, &vps[3].s,
1760                                                 &vps[4].s, &vps[5].s);
1761                                 return sr_kemi_apy_return_int(ket, ret);
1762                         } else {
1763                                 LM_ERR("invalid parameters for: %.*s\n",
1764                                                 fname.len, fname.s);
1765                                 return sr_kemi_apy_return_false();
1766                         }
1767                 break;
1768                 default:
1769                         LM_ERR("invalid parameters for: %.*s\n",
1770                                         fname.len, fname.s);
1771                         return sr_kemi_apy_return_false();
1772         }
1773 }
1774
1775 /**
1776  *
1777  */
1778 PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
1779 {
1780         sr_kemi_t *ket = NULL;
1781         PyObject *ret = NULL;
1782         PyThreadState *pstate = NULL;
1783         PyFrameObject *pframe = NULL;
1784         struct timeval tvb, tve;
1785         struct timezone tz;
1786         unsigned int tdiff;
1787
1788         ket = sr_apy_kemi_export_get(idx);
1789         if(ket==NULL) {
1790                 return sr_kemi_apy_return_false();
1791         }
1792         if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
1793                         && is_printable(cfg_get(core, core_cfg, latency_log))) {
1794                 gettimeofday(&tvb, &tz);
1795         }
1796
1797         ret = sr_apy_kemi_exec_func_ex(ket, self, args, idx);
1798
1799         if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
1800                         && is_printable(cfg_get(core, core_cfg, latency_log))) {
1801                 gettimeofday(&tve, &tz);
1802                 tdiff = (tve.tv_sec - tvb.tv_sec) * 1000000
1803                                    + (tve.tv_usec - tvb.tv_usec);
1804                 if(tdiff >= cfg_get(core, core_cfg, latency_limit_action)) {
1805                         pstate = PyThreadState_GET();
1806                         if (pstate != NULL && pstate->frame != NULL) {
1807                                 pframe = pstate->frame;
1808                         }
1809
1810                         LOG(cfg_get(core, core_cfg, latency_log),
1811                                         "alert - action KSR.%s%s%s(...)"
1812                                         " took too long [%u us] (file:%s func:%s line:%d)\n",
1813                                         (ket->mname.len>0)?ket->mname.s:"",
1814                                         (ket->mname.len>0)?".":"", ket->fname.s, tdiff,
1815                                         (pframe)?PyString_AsString(pframe->f_code->co_filename):"",
1816                                         (pframe)?PyString_AsString(pframe->f_code->co_name):"",
1817                                         (pframe)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0);
1818                 }
1819         }
1820
1821         return ret;
1822 }
1823
1824 /**
1825  *
1826  */
1827 PyObject *_sr_apy_ksr_module = NULL;
1828 PyObject *_sr_apy_ksr_module_dict = NULL;
1829 PyObject **_sr_apy_ksr_modules_list = NULL;
1830
1831 PyMethodDef *_sr_KSRMethods = NULL;
1832 #define SR_APY_KSR_MODULES_SIZE 256
1833 #define SR_APY_KSR_METHODS_SIZE (SR_APY_KEMI_EXPORT_SIZE + SR_APY_KSR_MODULES_SIZE)
1834
1835 /**
1836  *
1837  */
1838 static int sr_apy_kemi_f_ktest(sip_msg_t *msg, str *txt)
1839 {
1840         if(txt!=NULL && txt->s!=NULL)
1841                 LM_DBG("%.*s", txt->len, txt->s);
1842         return 0;
1843 }
1844
1845 /**
1846  *
1847  */
1848 /* clang-format off */
1849 static sr_kemi_t _sr_apy_kemi_test[] = {
1850         { str_init(""), str_init("ktest"),
1851                 SR_KEMIP_NONE, sr_apy_kemi_f_ktest,
1852                 { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1853                         SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1854         },
1855
1856         { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1857 };
1858 /* clang-format on */
1859
1860 /**
1861  *
1862  */
1863 static PyMethodDef _sr_apy_kemi_x_Methods[] = {
1864         {"modf", (PyCFunction)msg_call_function, METH_VARARGS,
1865                 "Invoke function exported by the other module."},
1866         {NULL, NULL, 0, NULL} /* sentinel */
1867 };
1868
1869 /**
1870  *
1871  */
1872 int sr_apy_init_ksr(void)
1873 {
1874         PyMethodDef *_sr_crt_KSRMethods = NULL;
1875         sr_kemi_module_t *emods = NULL;
1876         int emods_size = 0;
1877         int i;
1878         int k;
1879         int m;
1880         int n;
1881         char mname[128];
1882
1883         /* init faked sip msg */
1884         if(faked_msg_init()<0)
1885         {
1886                 LM_ERR("failed to init local faked sip msg\n");
1887                 return -1;
1888         }
1889
1890         _sr_KSRMethods = malloc(SR_APY_KSR_METHODS_SIZE * sizeof(PyMethodDef));
1891         if(_sr_KSRMethods==NULL) {
1892                 LM_ERR("no more pkg memory\n");
1893                 return -1;
1894         }
1895         _sr_apy_ksr_modules_list = malloc(SR_APY_KSR_MODULES_SIZE * sizeof(PyObject*));
1896         if(_sr_apy_ksr_modules_list==NULL) {
1897                 LM_ERR("no more pkg memory\n");
1898                 return -1;
1899         }
1900         memset(_sr_KSRMethods, 0, SR_APY_KSR_METHODS_SIZE * sizeof(PyMethodDef));
1901         memset(_sr_apy_ksr_modules_list, 0, SR_APY_KSR_MODULES_SIZE * sizeof(PyObject*));
1902
1903         emods_size = sr_kemi_modules_size_get();
1904         emods = sr_kemi_modules_get();
1905
1906         n = 0;
1907         _sr_crt_KSRMethods = _sr_KSRMethods;
1908         if(emods_size==0 || emods[0].kexp==NULL) {
1909                 LM_DBG("exporting KSR.%s(...)\n", _sr_apy_kemi_test[0].fname.s);
1910                 _sr_crt_KSRMethods[0].ml_name = _sr_apy_kemi_test[0].fname.s;
1911                 _sr_crt_KSRMethods[0].ml_meth = sr_apy_kemi_export_associate(&_sr_apy_kemi_test[0]);
1912                 _sr_crt_KSRMethods[0].ml_flags = METH_VARARGS;
1913                 _sr_crt_KSRMethods[0].ml_doc = NAME " exported function";
1914         } else {
1915                 for(i=0; emods[0].kexp[i].func!=NULL; i++) {
1916                         LM_DBG("exporting KSR.%s(...)\n", emods[0].kexp[i].fname.s);
1917                         _sr_crt_KSRMethods[i].ml_name = emods[0].kexp[i].fname.s;
1918                         _sr_crt_KSRMethods[i].ml_meth =
1919                                 sr_apy_kemi_export_associate(&emods[0].kexp[i]);
1920                         if(_sr_crt_KSRMethods[i].ml_meth == NULL) {
1921                                 LM_ERR("failed to associate kemi function with python export\n");
1922                                 free(_sr_KSRMethods);
1923                                 _sr_KSRMethods = NULL;
1924                                 return -1;
1925                         }
1926                         _sr_crt_KSRMethods[i].ml_flags = METH_VARARGS;
1927                         _sr_crt_KSRMethods[i].ml_doc = NAME " exported function";
1928                         n++;
1929                 }
1930         }
1931
1932         _sr_apy_ksr_module = Py_InitModule("KSR", _sr_crt_KSRMethods);
1933         _sr_apy_ksr_module_dict = PyModule_GetDict(_sr_apy_ksr_module);
1934
1935         Py_INCREF(_sr_apy_ksr_module);
1936
1937         m = 0;
1938
1939         /* special sub-modules - x.modf() can have variable number of params */
1940         _sr_apy_ksr_modules_list[m] = Py_InitModule("KSR.x",
1941                         _sr_apy_kemi_x_Methods);
1942         PyDict_SetItemString(_sr_apy_ksr_module_dict,
1943                         "x", _sr_apy_ksr_modules_list[m]);
1944         Py_INCREF(_sr_apy_ksr_modules_list[m]);
1945         m++;
1946
1947         if(emods_size>1) {
1948                 for(k=1; k<emods_size; k++) {
1949                         n++;
1950                         _sr_crt_KSRMethods = _sr_KSRMethods + n;
1951                         snprintf(mname, 128, "KSR.%s", emods[k].kexp[0].mname.s);
1952                         for(i=0; emods[k].kexp[i].func!=NULL; i++) {
1953                                 LM_DBG("exporting %s.%s(...)\n", mname,
1954                                                 emods[k].kexp[i].fname.s);
1955                                 _sr_crt_KSRMethods[i].ml_name = emods[k].kexp[i].fname.s;
1956                                 _sr_crt_KSRMethods[i].ml_meth =
1957                                         sr_apy_kemi_export_associate(&emods[k].kexp[i]);
1958                                 if(_sr_crt_KSRMethods[i].ml_meth == NULL) {
1959                                         LM_ERR("failed to associate kemi function with python export\n");
1960                                         free(_sr_KSRMethods);
1961                                         _sr_KSRMethods = NULL;
1962                                         return -1;
1963                                 }
1964                                 _sr_crt_KSRMethods[i].ml_flags = METH_VARARGS;
1965                                 _sr_crt_KSRMethods[i].ml_doc = NAME " exported function";
1966                                 n++;
1967                         }
1968                         LM_DBG("initializing kemi sub-module: %s (%s)\n", mname,
1969                                         emods[k].kexp[0].mname.s);
1970                         _sr_apy_ksr_modules_list[m] = Py_InitModule(mname, _sr_crt_KSRMethods);
1971                         PyDict_SetItemString(_sr_apy_ksr_module_dict,
1972                                         emods[k].kexp[0].mname.s, _sr_apy_ksr_modules_list[m]);
1973                         Py_INCREF(_sr_apy_ksr_modules_list[m]);
1974                         m++;
1975                 }
1976         }
1977         LM_DBG("module 'KSR' has been initialized\n");
1978         return 0;
1979 }
1980
1981 /**
1982  *
1983  */
1984 void sr_apy_destroy_ksr(void)
1985 {
1986         if(_sr_apy_ksr_module!=NULL) {
1987                 Py_XDECREF(_sr_apy_ksr_module);
1988                 _sr_apy_ksr_module = NULL;
1989         }
1990         if(_sr_apy_ksr_module_dict!=NULL) {
1991                 Py_XDECREF(_sr_apy_ksr_module_dict);
1992                 _sr_apy_ksr_module_dict = NULL;
1993         }
1994         if(_sr_KSRMethods!=NULL) {
1995                 free(_sr_KSRMethods);
1996                 _sr_KSRMethods = NULL;
1997         }
1998
1999         LM_DBG("module 'KSR' has been destroyed\n");
2000 }
2001
2002 /**
2003  *
2004  */
2005 int apy_sr_init_mod(void)
2006 {
2007         if(_sr_python_reload_version == NULL) {
2008                 _sr_python_reload_version = (int*)shm_malloc(sizeof(int));
2009                 if(_sr_python_reload_version == NULL) {
2010                         SHM_MEM_ERROR;
2011                         return -1;
2012                 }
2013                 *_sr_python_reload_version = 0;
2014         }
2015
2016         return 0;
2017 }
2018
2019 static const char* app_python_rpc_reload_doc[2] = {
2020         "Reload python file",
2021         0
2022 };
2023
2024
2025 static void app_python_rpc_reload(rpc_t* rpc, void* ctx)
2026 {
2027         void *vh;
2028
2029         if(_sr_python_load_file.s == NULL && _sr_python_load_file.len<=0) {
2030                 LM_WARN("script file path not provided\n");
2031                 rpc->fault(ctx, 500, "No script file");
2032                 return;
2033         }
2034         if(_sr_python_reload_version == NULL) {
2035                 LM_WARN("reload not enabled\n");
2036                 rpc->fault(ctx, 500, "Reload not enabled");
2037                 return;
2038         }
2039
2040         *_sr_python_reload_version += 1;
2041         LM_INFO("marking for reload Python script file: %.*s (%d)\n",
2042                                 _sr_python_load_file.len, _sr_python_load_file.s,
2043                                 *_sr_python_reload_version);
2044
2045         if (rpc->add(ctx, "{", &vh) < 0) {
2046                 rpc->fault(ctx, 500, "Server error");
2047                 return;
2048         }
2049         rpc->struct_add(vh, "dd",
2050                         "old", *_sr_python_reload_version-1,
2051                         "new", *_sr_python_reload_version);
2052
2053         return;
2054 }
2055
2056 static const char* app_python_rpc_api_list_doc[2] = {
2057         "List kemi exports to javascript",
2058         0
2059 };
2060
2061 static void app_python_rpc_api_list(rpc_t* rpc, void* ctx)
2062 {
2063         int i;
2064         int n;
2065         sr_kemi_t *ket;
2066         void* th;
2067         void* sh;
2068         void* ih;
2069
2070         if (rpc->add(ctx, "{", &th) < 0) {
2071                 rpc->fault(ctx, 500, "Internal error root reply");
2072                 return;
2073         }
2074         n = 0;
2075         for(i=0; i<SR_APY_KSR_METHODS_SIZE ; i++) {
2076                 ket = sr_apy_kemi_export_get(i);
2077                 if(ket==NULL) continue;
2078                 n++;
2079         }
2080
2081         if(rpc->struct_add(th, "d[",
2082                                 "msize", n,
2083                                 "methods",  &ih)<0)
2084         {
2085                 rpc->fault(ctx, 500, "Internal error array structure");
2086                 return;
2087         }
2088         for(i=0; i<SR_APY_KSR_METHODS_SIZE; i++) {
2089                 ket = sr_apy_kemi_export_get(i);
2090                 if(ket==NULL) continue;
2091                 if(rpc->struct_add(ih, "{", "func", &sh)<0) {
2092                         rpc->fault(ctx, 500, "Internal error internal structure");
2093                         return;
2094                 }
2095                 if(rpc->struct_add(sh, "SSSS",
2096                                 "ret", sr_kemi_param_map_get_name(ket->rtype),
2097                                 "module", &ket->mname,
2098                                 "name", &ket->fname,
2099                                 "params", sr_kemi_param_map_get_params(ket->ptypes))<0) {
2100                         LM_ERR("failed to add the structure with attributes (%d)\n", i);
2101                         rpc->fault(ctx, 500, "Internal error creating dest struct");
2102                         return;
2103                 }
2104         }
2105 }
2106
2107 rpc_export_t app_python_rpc_cmds[] = {
2108         {"app_python.reload", app_python_rpc_reload,
2109                 app_python_rpc_reload_doc, 0},
2110         {"app_python.api_list", app_python_rpc_api_list,
2111                 app_python_rpc_api_list_doc, 0},
2112         {0, 0, 0, 0}
2113 };
2114
2115 /**
2116  * register RPC commands
2117  */
2118 int app_python_init_rpc(void)
2119 {
2120         if (rpc_register_array(app_python_rpc_cmds)!=0)
2121         {
2122                 LM_ERR("failed to register RPC commands\n");
2123                 return -1;
2124         }
2125         return 0;
2126 }