Browse code

app_lua_sr: use snprintf() instead of sprintf()

Daniel-Constantin Mierla authored on 25/11/2019 11:02:01
Showing 1 changed files
... ...
@@ -655,7 +655,7 @@ static int lua_sr_tm_t_on_branch_failure(lua_State *L)
655 655
 		}
656 656
 		rt_name.len = rt_name_len;
657 657
 	}
658
-	sprintf(rt_name.s, "%s:%s", BRANCH_FAILURE_ROUTE_PREFIX, name);
658
+	snprintf(rt_name.s, rt_name_len+1, "%s:%s", BRANCH_FAILURE_ROUTE_PREFIX, name);
659 659
 
660 660
 	i = route_get(&event_rt, rt_name.s);
661 661
 	if(i < 0 || event_rt.rlist[i]==0)
Browse code

app_lua_sr: new module split from app_lua to export old Lua sr lib

Daniel-Constantin Mierla authored on 29/05/2019 11:55:26
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,3736 @@
1
+/**
2
+ * Copyright (C) 2010-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
+
22
+#include <stdio.h>
23
+#include <unistd.h>
24
+#include <stdlib.h>
25
+#include <sys/stat.h>
26
+
27
+#include "../../core/sr_module.h"
28
+#include "../../core/dprint.h"
29
+#include "../../core/route.h"
30
+#include "../../core/ut.h"
31
+
32
+#include "../../modules/sl/sl.h"
33
+#include "../../modules/tm/tm_load.h"
34
+#include "../../modules/sqlops/sql_api.h"
35
+#include "../../modules/rr/api.h"
36
+#include "../../modules/auth/api.h"
37
+#include "../../modules/auth_db/api.h"
38
+#include "../../modules/maxfwd/api.h"
39
+#include "../../modules/registrar/api.h"
40
+#include "../../modules/dispatcher/api.h"
41
+#include "../../modules/xhttp/api.h"
42
+#include "../../modules/sdpops/api.h"
43
+#include "../../modules/presence/bind_presence.h"
44
+#include "../../modules/presence_xml/api.h"
45
+#include "../../modules/textops/api.h"
46
+#include "../../modules/pua_usrloc/api.h"
47
+#include "../../modules/siputils/siputils.h"
48
+#include "../../modules/rls/api.h"
49
+#include "../../modules/alias_db/api.h"
50
+#include "../../modules/msilo/api.h"
51
+#include "../../modules/uac/api.h"
52
+#include "../../modules/sanity/api.h"
53
+#include "../../modules/cfgutils/api.h"
54
+#include "../../modules/tmx/api.h"
55
+#include "../../modules/mqueue/api.h"
56
+#include "../../modules/ndb_mongodb/api.h"
57
+
58
+#include "../../modules/app_lua/modapi.h"
59
+
60
+#include "app_lua_sr_api.h"
61
+
62
+#define SR_LUA_EXP_MOD_SL         (1<<0)
63
+#define SR_LUA_EXP_MOD_TM         (1<<1)
64
+#define SR_LUA_EXP_MOD_SQLOPS     (1<<2)
65
+#define SR_LUA_EXP_MOD_RR         (1<<3)
66
+#define SR_LUA_EXP_MOD_AUTH       (1<<4)
67
+#define SR_LUA_EXP_MOD_AUTH_DB    (1<<5)
68
+#define SR_LUA_EXP_MOD_MAXFWD     (1<<6)
69
+#define SR_LUA_EXP_MOD_REGISTRAR  (1<<7)
70
+#define SR_LUA_EXP_MOD_DISPATCHER (1<<8)
71
+#define SR_LUA_EXP_MOD_XHTTP      (1<<9)
72
+#define SR_LUA_EXP_MOD_SDPOPS     (1<<10)
73
+#define SR_LUA_EXP_MOD_PRESENCE   (1<<11)
74
+#define SR_LUA_EXP_MOD_PRESENCE_XML (1<<12)
75
+#define SR_LUA_EXP_MOD_TEXTOPS    (1<<13)
76
+#define SR_LUA_EXP_MOD_PUA_USRLOC (1<<14)
77
+#define SR_LUA_EXP_MOD_SIPUTILS   (1<<15)
78
+#define SR_LUA_EXP_MOD_RLS        (1<<16)
79
+#define SR_LUA_EXP_MOD_ALIAS_DB   (1<<17)
80
+#define SR_LUA_EXP_MOD_MSILO      (1<<18)
81
+#define SR_LUA_EXP_MOD_UAC        (1<<19)
82
+#define SR_LUA_EXP_MOD_SANITY     (1<<20)
83
+#define SR_LUA_EXP_MOD_CFGUTILS   (1<<21)
84
+#define SR_LUA_EXP_MOD_TMX        (1<<22)
85
+#define SR_LUA_EXP_MOD_MQUEUE     (1<<23)
86
+#define SR_LUA_EXP_MOD_NDB_MONGODB (1<<24)
87
+
88
+extern app_lua_api_t _app_lua_api;
89
+
90
+/**
91
+ *
92
+ */
93
+static unsigned int _sr_lua_exp_reg_mods = 0;
94
+
95
+/**
96
+ * auth
97
+ */
98
+static auth_api_s_t _lua_authb;
99
+
100
+/**
101
+ * auth_db
102
+ */
103
+static auth_db_api_t _lua_auth_dbb;
104
+
105
+/**
106
+ * dispatcher
107
+ */
108
+static dispatcher_api_t _lua_dispatcherb;
109
+
110
+/**
111
+ * maxfwd
112
+ */
113
+static maxfwd_api_t _lua_maxfwdb;
114
+
115
+/**
116
+ * registrar
117
+ */
118
+static registrar_api_t _lua_registrarb;
119
+
120
+/**
121
+ * rr
122
+ */
123
+static rr_api_t _lua_rrb;
124
+
125
+/**
126
+ * sqlops
127
+ */
128
+static sqlops_api_t _lua_sqlopsb;
129
+
130
+/**
131
+ * sl
132
+ */
133
+static sl_api_t _lua_slb;
134
+
135
+/**
136
+ * tm
137
+ */
138
+static tm_api_t  _lua_tmb;
139
+static tm_xapi_t _lua_xtmb;
140
+
141
+/**
142
+ * xhttp
143
+ */
144
+static xhttp_api_t _lua_xhttpb;
145
+
146
+/**
147
+ * sdpops
148
+ */
149
+static sdpops_api_t _lua_sdpopsb;
150
+
151
+/**
152
+ * presence
153
+ */
154
+static presence_api_t _lua_presenceb;
155
+
156
+/**
157
+ * presence_xml
158
+ */
159
+static presence_xml_api_t _lua_presence_xmlb;
160
+
161
+/**
162
+ * textops
163
+ */
164
+static textops_api_t _lua_textopsb;
165
+
166
+/**
167
+ * pua_usrloc
168
+ */
169
+static pua_usrloc_api_t _lua_pua_usrlocb;
170
+
171
+/**
172
+ * siputils
173
+ */
174
+static siputils_api_t _lua_siputilsb;
175
+
176
+/**
177
+ * rls
178
+ */
179
+static rls_api_t _lua_rlsb;
180
+
181
+/**
182
+ * alias_db
183
+ */
184
+static alias_db_api_t _lua_alias_dbb;
185
+
186
+/**
187
+ * msilo
188
+ */
189
+static msilo_api_t _lua_msilob;
190
+
191
+/**
192
+ * uac
193
+ */
194
+static uac_api_t _lua_uacb;
195
+
196
+/**
197
+ * sanity
198
+ */
199
+static sanity_api_t _lua_sanityb;
200
+
201
+/**
202
+ * cfgutils
203
+ */
204
+static cfgutils_api_t _lua_cfgutilsb;
205
+
206
+/**
207
+ * tmx
208
+ */
209
+static tmx_api_t _lua_tmxb;
210
+
211
+/**
212
+ * mqueue
213
+ */
214
+static mq_api_t _lua_mqb;
215
+
216
+/**
217
+ * mqueue
218
+ */
219
+static ndb_mongodb_api_t _lua_ndb_mongodbb;
220
+
221
+
222
+/**
223
+ *
224
+ */
225
+static int lua_sr_sl_send_reply (lua_State *L)
226
+{
227
+	str txt;
228
+	int code;
229
+	int ret;
230
+	sr_lua_env_t *env_L;
231
+
232
+	env_L = _app_lua_api.env_get_f();
233
+
234
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL))
235
+	{
236
+		LM_WARN("weird: sl function executed but module not registered\n");
237
+		return app_lua_return_error(L);
238
+	}
239
+	if(env_L->msg==NULL)
240
+	{
241
+		LM_WARN("invalid parameters from Lua env\n");
242
+		return app_lua_return_error(L);
243
+	}
244
+
245
+	code = lua_tointeger(L, -2);
246
+
247
+	if(code<100 || code>=800)
248
+		return app_lua_return_error(L);
249
+
250
+	txt.s = (char*)lua_tostring(L, -1);
251
+	if(txt.s==NULL || env_L->msg==NULL)
252
+		return app_lua_return_error(L);
253
+
254
+	txt.len = strlen(txt.s);
255
+	ret = _lua_slb.freply(env_L->msg, code, &txt);
256
+	return app_lua_return_int(L, ret);
257
+}
258
+
259
+/**
260
+ *
261
+ */
262
+static int lua_sr_sl_get_reply_totag (lua_State *L)
263
+{
264
+	str txt;
265
+	int ret;
266
+	sr_lua_env_t *env_L;
267
+
268
+	env_L = _app_lua_api.env_get_f();
269
+
270
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL))
271
+	{
272
+		LM_WARN("weird: sl function executed but module not registered\n");
273
+		return app_lua_return_false(L);
274
+	}
275
+	if(env_L->msg==NULL)
276
+	{
277
+		LM_WARN("invalid parameters from Lua env\n");
278
+		return app_lua_return_error(L);
279
+	}
280
+	ret = _lua_slb.get_reply_totag(env_L->msg, &txt);
281
+	if(ret<0)
282
+	{
283
+		LM_WARN("sl get_reply_totag returned false\n");
284
+		return app_lua_return_false(L);
285
+	}
286
+	lua_pushlstring(L, txt.s, txt.len);
287
+	return 1;
288
+}
289
+
290
+/**
291
+ *
292
+ */
293
+static const luaL_Reg _sr_sl_Map [] = {
294
+	{"send_reply",      lua_sr_sl_send_reply},
295
+	{"get_reply_totag", lua_sr_sl_get_reply_totag},
296
+	{NULL, NULL}
297
+};
298
+
299
+/**
300
+ *
301
+ */
302
+static int lua_sr_tm_t_reply(lua_State *L)
303
+{
304
+	char *txt;
305
+	int code;
306
+	int ret;
307
+	sr_lua_env_t *env_L;
308
+
309
+	env_L = _app_lua_api.env_get_f();
310
+
311
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
312
+	{
313
+		LM_WARN("weird: tm function executed but module not registered\n");
314
+		return app_lua_return_error(L);
315
+	}
316
+	if(env_L->msg==NULL)
317
+	{
318
+		LM_WARN("invalid parameters from Lua env\n");
319
+		return app_lua_return_error(L);
320
+	}
321
+
322
+	code = lua_tointeger(L, -2);
323
+
324
+	if(code<100 || code>=800)
325
+		return app_lua_return_error(L);
326
+
327
+	txt = (char*)lua_tostring(L, -1);
328
+	if(txt!=NULL && env_L->msg!=NULL)
329
+	{
330
+		ret = _lua_tmb.t_reply(env_L->msg, code, txt);
331
+		return app_lua_return_int(L, ret);
332
+	}
333
+	return app_lua_return_error(L);
334
+}
335
+
336
+/**
337
+ *
338
+ */
339
+static int lua_sr_tm_t_relay(lua_State *L)
340
+{
341
+	int ret;
342
+	sr_lua_env_t *env_L;
343
+
344
+	env_L = _app_lua_api.env_get_f();
345
+
346
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
347
+	{
348
+		LM_WARN("weird: tm function executed but module not registered\n");
349
+		return app_lua_return_error(L);
350
+	}
351
+	if(env_L->msg==NULL)
352
+	{
353
+		LM_WARN("invalid parameters from Lua env\n");
354
+		return app_lua_return_error(L);
355
+	}
356
+	ret = _lua_tmb.t_relay(env_L->msg, NULL, NULL);
357
+	return app_lua_return_int(L, ret);
358
+}
359
+
360
+/**
361
+ *
362
+ */
363
+static int lua_sr_tm_t_on_failure(lua_State *L)
364
+{
365
+	char *name;
366
+	int i;
367
+	sr_lua_env_t *env_L;
368
+
369
+	env_L = _app_lua_api.env_get_f();
370
+
371
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
372
+	{
373
+		LM_WARN("weird: tm function executed but module not registered\n");
374
+		return app_lua_return_error(L);
375
+	}
376
+
377
+	if(env_L->msg==NULL)
378
+	{
379
+		LM_WARN("invalid parameters from Lua env\n");
380
+		return app_lua_return_error(L);
381
+	}
382
+
383
+	name = (char*)lua_tostring(L, -1);
384
+	if(name==NULL)
385
+	{
386
+		LM_WARN("invalid parameters from Lua\n");
387
+		return app_lua_return_error(L);
388
+	}
389
+
390
+	i = route_get(&failure_rt, name);
391
+	if(failure_rt.rlist[i]==0)
392
+	{
393
+		LM_WARN("no actions in failure_route[%s]\n", name);
394
+		return app_lua_return_error(L);
395
+	}
396
+
397
+	_lua_xtmb.t_on_failure((unsigned int)i);
398
+	return app_lua_return_int(L, 1);
399
+}
400
+
401
+/**
402
+ *
403
+ */
404
+static int lua_sr_tm_t_on_branch(lua_State *L)
405
+{
406
+	char *name;
407
+	int i;
408
+	sr_lua_env_t *env_L;
409
+
410
+	env_L = _app_lua_api.env_get_f();
411
+
412
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
413
+	{
414
+		LM_WARN("weird: tm function executed but module not registered\n");
415
+		return app_lua_return_error(L);
416
+	}
417
+
418
+	if(env_L->msg==NULL)
419
+	{
420
+		LM_WARN("invalid parameters from Lua env\n");
421
+		return app_lua_return_error(L);
422
+	}
423
+
424
+	name = (char*)lua_tostring(L, -1);
425
+	if(name==NULL)
426
+	{
427
+		LM_WARN("invalid parameters from Lua\n");
428
+		return app_lua_return_error(L);
429
+	}
430
+
431
+	i = route_get(&branch_rt, name);
432
+	if(branch_rt.rlist[i]==0)
433
+	{
434
+		LM_WARN("no actions in branch_route[%s]\n", name);
435
+		return app_lua_return_error(L);
436
+	}
437
+
438
+	_lua_xtmb.t_on_branch((unsigned int)i);
439
+	return app_lua_return_int(L, 1);
440
+}
441
+
442
+/**
443
+ *
444
+ */
445
+static int lua_sr_tm_t_on_reply(lua_State *L)
446
+{
447
+	char *name;
448
+	int i;
449
+	sr_lua_env_t *env_L;
450
+
451
+	env_L = _app_lua_api.env_get_f();
452
+
453
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
454
+	{
455
+		LM_WARN("weird: tm function executed but module not registered\n");
456
+		return app_lua_return_error(L);
457
+	}
458
+
459
+	if(env_L->msg==NULL)
460
+	{
461
+		LM_WARN("invalid parameters from Lua env\n");
462
+		return app_lua_return_error(L);
463
+	}
464
+
465
+	name = (char*)lua_tostring(L, -1);
466
+	if(name==NULL)
467
+	{
468
+		LM_WARN("invalid parameters from Lua\n");
469
+		return app_lua_return_error(L);
470
+	}
471
+
472
+	i = route_get(&onreply_rt, name);
473
+	if(onreply_rt.rlist[i]==0)
474
+	{
475
+		LM_WARN("no actions in onreply_route[%s]\n", name);
476
+		return app_lua_return_error(L);
477
+	}
478
+
479
+	_lua_xtmb.t_on_reply((unsigned int)i);
480
+	return app_lua_return_int(L, 1);
481
+}
482
+
483
+/**
484
+ *
485
+ */
486
+static int lua_sr_tm_t_check_trans(lua_State *L)
487
+{
488
+	int ret;
489
+	sr_lua_env_t *env_L;
490
+
491
+	env_L = _app_lua_api.env_get_f();
492
+
493
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
494
+	{
495
+		LM_WARN("weird: tm function executed but module not registered\n");
496
+		return app_lua_return_error(L);
497
+	}
498
+	if(env_L->msg==NULL)
499
+	{
500
+		LM_WARN("invalid parameters from Lua env\n");
501
+		return app_lua_return_error(L);
502
+	}
503
+
504
+	ret = _lua_xtmb.t_check_trans(env_L->msg);
505
+	return app_lua_return_int(L, ret);
506
+}
507
+
508
+/**
509
+ *
510
+ */
511
+static int lua_sr_tm_t_is_canceled(lua_State *L)
512
+{
513
+	int ret;
514
+	sr_lua_env_t *env_L;
515
+
516
+	env_L = _app_lua_api.env_get_f();
517
+
518
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
519
+	{
520
+		LM_WARN("weird: tm function executed but module not registered\n");
521
+		return app_lua_return_error(L);
522
+	}
523
+	if(env_L->msg==NULL)
524
+	{
525
+		LM_WARN("invalid parameters from Lua env\n");
526
+		return app_lua_return_error(L);
527
+	}
528
+
529
+	ret = _lua_xtmb.t_is_canceled(env_L->msg);
530
+	return app_lua_return_int(L, ret);
531
+}
532
+
533
+/**
534
+ *
535
+ */
536
+static int lua_sr_tm_t_newtran(lua_State *L)
537
+{
538
+	int ret;
539
+	sr_lua_env_t *env_L;
540
+
541
+	env_L = _app_lua_api.env_get_f();
542
+
543
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
544
+	{
545
+		LM_WARN("weird: tm function executed but module not registered\n");
546
+		return app_lua_return_error(L);
547
+	}
548
+	if(env_L->msg==NULL)
549
+	{
550
+		LM_WARN("invalid parameters from Lua env\n");
551
+		return app_lua_return_error(L);
552
+	}
553
+
554
+	ret = _lua_tmb.t_newtran(env_L->msg);
555
+	return app_lua_return_int(L, ret);
556
+}
557
+
558
+/**
559
+ *
560
+ */
561
+static int lua_sr_tm_t_release(lua_State *L)
562
+{
563
+	int ret;
564
+	sr_lua_env_t *env_L;
565
+
566
+	env_L = _app_lua_api.env_get_f();
567
+
568
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
569
+	{
570
+		LM_WARN("weird: tm function executed but module not registered\n");
571
+		return app_lua_return_error(L);
572
+	}
573
+	if(env_L->msg==NULL)
574
+	{
575
+		LM_WARN("invalid parameters from Lua env\n");
576
+		return app_lua_return_error(L);
577
+	}
578
+
579
+	ret = _lua_tmb.t_release(env_L->msg);
580
+	return app_lua_return_int(L, ret);
581
+}
582
+
583
+/**
584
+ *
585
+ */
586
+static int lua_sr_tm_t_replicate(lua_State *L)
587
+{
588
+	int ret;
589
+	sr_lua_env_t *env_L;
590
+	str suri;
591
+
592
+	env_L = _app_lua_api.env_get_f();
593
+
594
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
595
+	{
596
+		LM_WARN("weird: tm function executed but module not registered\n");
597
+		return app_lua_return_error(L);
598
+	}
599
+	if(env_L->msg==NULL)
600
+	{
601
+		LM_WARN("invalid parameters from Lua env\n");
602
+		return app_lua_return_error(L);
603
+	}
604
+	suri.s = (char*)lua_tostring(L, -1);
605
+	if(suri.s == NULL)
606
+	{
607
+		LM_WARN("invalid parameters from Lua\n");
608
+		return app_lua_return_error(L);
609
+	}
610
+	suri.len = strlen(suri.s);
611
+
612
+	ret = _lua_tmb.t_replicate(env_L->msg, &suri);
613
+	return app_lua_return_int(L, ret);
614
+}
615
+
616
+/**
617
+ *
618
+ */
619
+#define BRANCH_FAILURE_ROUTE_PREFIX "tm:branch-failure"
620
+static int lua_sr_tm_t_on_branch_failure(lua_State *L)
621
+{
622
+	static str rt_name = {NULL, 0};
623
+	char *name;
624
+	int rt_name_len;
625
+	int i;
626
+	sr_lua_env_t *env_L;
627
+
628
+	env_L = _app_lua_api.env_get_f();
629
+
630
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
631
+	{
632
+		LM_WARN("weird: tm function executed but module not registered\n");
633
+		return app_lua_return_error(L);
634
+	}
635
+
636
+	if(env_L->msg==NULL)
637
+	{
638
+		LM_WARN("invalid parameters from Lua env\n");
639
+		return app_lua_return_error(L);
640
+	}
641
+
642
+	name = (char*)lua_tostring(L, -1);
643
+	if(name==NULL)
644
+	{
645
+		LM_WARN("invalid parameters from Lua\n");
646
+		return app_lua_return_error(L);
647
+	}
648
+	rt_name_len = strlen(BRANCH_FAILURE_ROUTE_PREFIX) + 1 + strlen(name);
649
+	if (rt_name_len > rt_name.len)
650
+	{
651
+		if ((rt_name.s = pkg_reallocxf(rt_name.s, rt_name_len+1)) == NULL)
652
+		{
653
+			PKG_MEM_ERROR;
654
+			return -1;
655
+		}
656
+		rt_name.len = rt_name_len;
657
+	}
658
+	sprintf(rt_name.s, "%s:%s", BRANCH_FAILURE_ROUTE_PREFIX, name);
659
+
660
+	i = route_get(&event_rt, rt_name.s);
661
+	if(i < 0 || event_rt.rlist[i]==0)
662
+	{
663
+		LM_WARN("no actions in branch_failure_route[%s]\n", name);
664
+		return app_lua_return_error(L);
665
+	}
666
+
667
+	_lua_xtmb.t_on_branch_failure((unsigned int)i);
668
+	return app_lua_return_int(L, 1);
669
+}
670
+
671
+/**
672
+ *
673
+ */
674
+static int lua_sr_tm_t_load_contacts(lua_State *L)
675
+{
676
+	int ret;
677
+	sr_lua_env_t *env_L;
678
+
679
+	env_L = _app_lua_api.env_get_f();
680
+
681
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
682
+	{
683
+		LM_WARN("weird: tm function executed but module not registered\n");
684
+		return app_lua_return_error(L);
685
+	}
686
+	if(env_L->msg==NULL)
687
+	{
688
+		LM_WARN("invalid parameters from Lua env\n");
689
+		return app_lua_return_error(L);
690
+	}
691
+
692
+	ret = _lua_tmb.t_load_contacts(env_L->msg, NULL, NULL);
693
+	return app_lua_return_int(L, ret);
694
+}
695
+
696
+/**
697
+ *
698
+ */
699
+static int lua_sr_tm_t_next_contacts(lua_State *L)
700
+{
701
+	int ret;
702
+	sr_lua_env_t *env_L;
703
+
704
+	env_L = _app_lua_api.env_get_f();
705
+
706
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
707
+	{
708
+		LM_WARN("weird: tm function executed but module not registered\n");
709
+		return app_lua_return_error(L);
710
+	}
711
+	if(env_L->msg==NULL)
712
+	{
713
+		LM_WARN("invalid parameters from Lua env\n");
714
+		return app_lua_return_error(L);
715
+	}
716
+
717
+	ret = _lua_tmb.t_next_contacts(env_L->msg, NULL, NULL);
718
+	return app_lua_return_int(L, ret);
719
+}
720
+
721
+/**
722
+ *
723
+ */
724
+static const luaL_Reg _sr_tm_Map [] = {
725
+	{"t_reply",             lua_sr_tm_t_reply},
726
+	{"t_relay",             lua_sr_tm_t_relay},
727
+	{"t_on_failure",        lua_sr_tm_t_on_failure},
728
+	{"t_on_branch",         lua_sr_tm_t_on_branch},
729
+	{"t_on_reply",          lua_sr_tm_t_on_reply},
730
+	{"t_check_trans",       lua_sr_tm_t_check_trans},
731
+	{"t_is_canceled",       lua_sr_tm_t_is_canceled},
732
+	{"t_newtran",           lua_sr_tm_t_newtran},
733
+	{"t_release",           lua_sr_tm_t_release},
734
+	{"t_replicate",         lua_sr_tm_t_replicate},
735
+	{"t_on_branch_failure", lua_sr_tm_t_on_branch_failure},
736
+	{"t_load_contacts",     lua_sr_tm_t_load_contacts},
737
+	{"t_next_contacts",     lua_sr_tm_t_next_contacts},
738
+	{NULL, NULL}
739
+};
740
+
741
+
742
+/**
743
+ *
744
+ */
745
+static int lua_sr_sqlops_query(lua_State *L)
746
+{
747
+	str scon;
748
+	str squery;
749
+	str sres;
750
+	int ret;
751
+
752
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS))
753
+	{
754
+		LM_WARN("weird: sqlops function executed but module not registered\n");
755
+		return app_lua_return_error(L);
756
+	}
757
+
758
+	scon.s = (char*)lua_tostring(L, -3);
759
+	squery.s = (char*)lua_tostring(L, -2);
760
+	sres.s = (char*)lua_tostring(L, -1);
761
+	if(scon.s == NULL || squery.s == NULL || sres.s == NULL)
762
+	{
763
+		LM_WARN("invalid parameters from Lua\n");
764
+		return app_lua_return_error(L);
765
+	}
766
+	scon.len = strlen(scon.s);
767
+	squery.len = strlen(squery.s);
768
+	sres.len = strlen(sres.s);
769
+
770
+	ret = _lua_sqlopsb.query(&scon, &squery, &sres);
771
+	return app_lua_return_int(L, ret);
772
+}
773
+
774
+/**
775
+ *
776
+ */
777
+static int lua_sr_sqlops_value(lua_State *L)
778
+{
779
+	str sres;
780
+	int col;
781
+	int row;
782
+	sql_val_t *val;
783
+
784
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS))
785
+	{
786
+		LM_WARN("weird: sqlops function executed but module not registered\n");
787
+		return app_lua_return_false(L);
788
+	}
789
+	sres.s = (char*)lua_tostring(L, -3);
790
+	row = lua_tointeger(L, -2);
791
+	col = lua_tointeger(L, -1);
792
+	if(row<0 || col<0 || sres.s==NULL)
793
+	{
794
+		LM_WARN("invalid parameters from Lua\n");
795
+		return app_lua_return_false(L);
796
+	}
797
+	sres.len = strlen(sres.s);
798
+	if(_lua_sqlopsb.value(&sres, row, col, &val)<0)
799
+		return app_lua_return_false(L);
800
+	if(val->flags&PV_VAL_NULL)
801
+	{
802
+		lua_pushinteger(L, 0);
803
+		return 1;
804
+	}
805
+
806
+	if(val->flags&PV_VAL_INT)
807
+	{
808
+		lua_pushinteger(L, val->value.n);
809
+		return 1;
810
+	}
811
+	lua_pushlstring(L, val->value.s.s, val->value.s.len);
812
+	return 1;
813
+}
814
+
815
+/**
816
+ *
817
+ */
818
+static int lua_sr_sqlops_is_null(lua_State *L)
819
+{
820
+	str sres;
821
+	int col;
822
+	int row;
823
+
824
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS))
825
+	{
826
+		LM_WARN("weird: sqlops function executed but module not registered\n");
827
+		return app_lua_return_false(L);
828
+	}
829
+	sres.s = (char*)lua_tostring(L, -3);
830
+	row = lua_tointeger(L, -2);
831
+	col = lua_tointeger(L, -1);
832
+	if(row<0 || col<0 || sres.s==NULL)
833
+	{
834
+		LM_WARN("invalid parameters from Lua\n");
835
+		return app_lua_return_false(L);
836
+	}
837
+	sres.len = strlen(sres.s);
838
+	if(_lua_sqlopsb.is_null(&sres, row, col)==1)
839
+		return app_lua_return_true(L);
840
+	return app_lua_return_false(L);
841
+}
842
+
843
+/**
844
+ *
845
+ */
846
+static int lua_sr_sqlops_column(lua_State *L)
847
+{
848
+	str sres;
849
+	int col;
850
+	str name = {0, 0};
851
+
852
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS))
853
+	{
854
+		LM_WARN("weird: sqlops function executed but module not registered\n");
855
+		return app_lua_return_false(L);
856
+	}
857
+	sres.s = (char*)lua_tostring(L, -2);
858
+	col = lua_tointeger(L, -1);
859
+	if(col<0 || sres.s==NULL)
860
+	{
861
+		LM_WARN("invalid parameters from Lua\n");
862
+		return app_lua_return_false(L);
863
+	}
864
+	sres.len = strlen(sres.s);
865
+	if(_lua_sqlopsb.column(&sres, col, &name)<0)
866
+		return app_lua_return_false(L);
867
+	lua_pushlstring(L, name.s, name.len);
868
+	return 1;
869
+}
870
+
871
+/**
872
+ *
873
+ */
874
+static int lua_sr_sqlops_nrows(lua_State *L)
875
+{
876
+	str sres;
877
+	int rows;
878
+
879
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SQLOPS))
880
+	{
881
+		LM_WARN("weird: sqlops function executed but module not registered\n");
882
+		return app_lua_return_false(L);
883
+	}
884
+	sres.s = (char*)lua_tostring(L, -1);
885
+	if(sres.s==NULL)
886
+	{
887
+		LM_WARN("invalid parameters from Lua\n");
888
+		return app_lua_return_false(L);
889
+	}
890
+	sres.len = strlen(sres.s);
891
+	rows = _lua_sqlopsb.nrows(&sres);
892
+	if(rows<0)
893
+		return app_lua_return_false(L);
894
+	lua_pushinteger(L, rows);
895
+	return 1;
896
+}
897
+
898
+/**