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