Browse code

app_lua: implemented alternative config file interpreting engine

- can be used to execute routing logic for SIP requests and responses by
using next statement in kamailio.cfg:

cfgengine="lua"

Daniel-Constantin Mierla authored on 12/04/2016 12:16:44
Showing 1 changed files
... ...
@@ -29,6 +29,7 @@
29 29
 #include "../../mod_fix.h"
30 30
 #include "../../rpc.h"
31 31
 #include "../../rpc_lookup.h"
32
+#include "../../kemi.h"
32 33
 
33 34
 #include "app_lua_api.h"
34 35
 
... ...
@@ -103,9 +104,49 @@ struct module_exports exports = {
103 104
 	child_init      /* per child init function */
104 105
 };
105 106
 
107
+/**
108
+ *
109
+ */
110
+int sr_kemi_config_engine_lua(sip_msg_t *msg, int rtype, str *rname)
111
+{
112
+	int ret;
113
+
114
+	if(rtype==REQUEST_ROUTE) {
115
+		ret = app_lua_run(msg, "ksr_request_route", NULL, NULL, NULL);
116
+	} else if(rtype==CORE_ONREPLY_ROUTE) {
117
+		ret = app_lua_run(msg, "ksr_reply_route", NULL, NULL, NULL);
118
+	} else {
119
+		if(rname!=NULL) {
120
+			LM_ERR("route type %d with name [%.*s] not implemented\n",
121
+				rtype, rname->len, rname->s);
122
+		} else {
123
+			LM_ERR("route type %d with no name not implemented\n",
124
+				rtype);
125
+		}
126
+	}
127
+
128
+	if(rname!=NULL) {
129
+		LM_DBG("execution of route type %d with name [%.*s] returned %d\n",
130
+				rtype, rname->len, rname->s, ret);
131
+	} else {
132
+		LM_DBG("execution of route type %d with no name returned %d\n",
133
+			rtype, ret);
134
+	}
135
+
136
+	return 1;
137
+}
138
+
139
+/**
140
+ *
141
+ */
106 142
 int mod_register(char *path, int *dlflags, void *p1, void *p2)
107 143
 {
144
+	str ename = str_init("lua");
145
+
108 146
 	*dlflags = RTLD_NOW | RTLD_GLOBAL;
147
+
148
+	sr_kemi_eng_register(&ename, sr_kemi_config_engine_lua);
149
+
109 150
 	return 0;
110 151
 }
111 152