Browse code

core: ability to run alternative request_route and reply_route handlers

- they can be offered by the embedded interpreters
- at this moment app_lua can execute functions from the script loaded
with param 'load':
- instead of request_route it executes ksr_request_route()
- instead of reply_route it executes ksr_reply_route()

Daniel-Constantin Mierla authored on 12/04/2016 12:14:15
Showing 1 changed files
... ...
@@ -54,6 +54,7 @@
54 54
 #include "tcp_options.h" /* for access to tcp_accept_aliases*/
55 55
 #include "cfg/cfg.h"
56 56
 #include "core_stats.h"
57
+#include "kemi.h"
57 58
 
58 59
 #ifdef DEBUG_DMALLOC
59 60
 #include <mem/dmalloc.h>
... ...
@@ -125,6 +126,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
125 126
 #endif
126 127
 	str inb;
127 128
 	sr_net_info_t netinfo;
129
+	sr_kemi_eng_t *keng = NULL;
128 130
 
129 131
 	if(sr_event_enabled(SREV_NET_DATA_RECV)) {
130 132
 		if(sip_check_fline(buf, len)==0) {
... ...
@@ -237,9 +239,20 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
237 239
 
238 240
 		set_route_type(REQUEST_ROUTE);
239 241
 		/* exec the routing script */
240
-		if (run_top_route(main_rt.rlist[DEFAULT_RT], msg, 0)<0){
241
-			LM_WARN("error while trying script\n");
242
-			goto error_req;
242
+		if(unlikely(main_rt.rlist[DEFAULT_RT]==NULL)) {
243
+			keng = sr_kemi_eng_get();
244
+			if(keng==NULL) {
245
+				LM_ERR("no config routing engine registered\n");
246
+				goto error_req;
247
+			}
248
+			if(keng->froute(msg, REQUEST_ROUTE, NULL)<0) {
249
+				LM_NOTICE("negative return code from engine function\n");
250
+			}
251
+		} else {
252
+			if (run_top_route(main_rt.rlist[DEFAULT_RT], msg, 0)<0){
253
+				LM_WARN("error while trying script\n");
254
+				goto error_req;
255
+			}
243 256
 		}
244 257
 
245 258
 #ifdef STATS
... ...
@@ -283,7 +296,15 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
283 296
 		/* exec the onreply routing script */
284 297
 		if (onreply_rt.rlist[DEFAULT_RT]){
285 298
 			set_route_type(CORE_ONREPLY_ROUTE);
286
-			ret=run_top_route(onreply_rt.rlist[DEFAULT_RT], msg, &ctx);
299
+			ret = 1;
300
+			if(unlikely(main_rt.rlist[DEFAULT_RT]==NULL)) {
301
+				keng = sr_kemi_eng_get();
302
+				if(keng!=NULL) {
303
+					ret = keng->froute(msg, REQUEST_ROUTE, NULL);
304
+				}
305
+			} else {
306
+				ret=run_top_route(onreply_rt.rlist[DEFAULT_RT], msg, &ctx);
307
+			}
287 308
 #ifndef NO_ONREPLY_ROUTE_ERROR
288 309
 			if (unlikely(ret<0)){
289 310
 				LM_WARN("error while trying onreply script\n");