Browse code

kemix: new module to collect KEMI specific collections

- avoid pushing code in core for alternatives to core keywords,
conditions, a.s.o.

Daniel-Constantin Mierla authored on 24/05/2019 10:44:16
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,9 @@
1
+#
2
+# WARNING: do not run this directly, it should be run by the master Makefile
3
+
4
+include ../../Makefile.defs
5
+auto_gen=
6
+NAME=kemix.so
7
+LIBS=
8
+
9
+include ../../Makefile.modules
0 10
new file mode 100644
... ...
@@ -0,0 +1,63 @@
1
+KEMIX Module
2
+
3
+Daniel-Constantin Mierla
4
+
5
+   <miconda@gmail.com>
6
+
7
+Edited by
8
+
9
+Daniel-Constantin Mierla
10
+
11
+   <miconda@gmail.com>
12
+
13
+   Copyright � 2019 asipto.com
14
+     __________________________________________________________________
15
+
16
+   Table of Contents
17
+
18
+   1. Admin Guide
19
+
20
+        1. Overview
21
+        2. Dependencies
22
+
23
+              2.1. Kamailio Modules
24
+              2.2. External Libraries or Applications
25
+
26
+Chapter 1. Admin Guide
27
+
28
+   Table of Contents
29
+
30
+   1. Overview
31
+   2. Dependencies
32
+
33
+        2.1. Kamailio Modules
34
+        2.2. External Libraries or Applications
35
+
36
+1. Overview
37
+
38
+   This module collects extensions and functions to be used with KEMI SIP
39
+   routing scripting. The target is to implement alternatives to specific
40
+   concepts designed for the native scripting language (e.g., core
41
+   keywords and core conditions) without pushing code in the core of the
42
+   application.
43
+
44
+   It does not provide functions for the native Kamailio.cfg.
45
+
46
+   To see the KEMI functions exported by this module, see:
47
+     * http://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/
48
+
49
+2. Dependencies
50
+
51
+   2.1. Kamailio Modules
52
+   2.2. External Libraries or Applications
53
+
54
+2.1. Kamailio Modules
55
+
56
+   The following modules must be loaded before this module:
57
+     * None.
58
+
59
+2.2. External Libraries or Applications
60
+
61
+   The following libraries or applications must be installed before
62
+   running Kamailio with this module loaded:
63
+     * None
0 64
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+docs = kemix.xml
2
+
3
+docbook_dir = ../../../../doc/docbook
4
+include $(docbook_dir)/Makefile.module
0 5
new file mode 100644
... ...
@@ -0,0 +1,36 @@
1
+<?xml version="1.0" encoding='ISO-8859-1'?>
2
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4
+
5
+<!-- Include general documentation entities -->
6
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
7
+%docentities;
8
+
9
+]>
10
+
11
+<book xmlns:xi="http://www.w3.org/2001/XInclude">
12
+    <bookinfo>
13
+	<title>KEMIX Module</title>
14
+	<productname class="trade">kamailio.org</productname>
15
+	<authorgroup>
16
+	    <author>
17
+		<firstname>Daniel-Constantin</firstname>
18
+		<surname>Mierla</surname>
19
+		<email>miconda@gmail.com</email>
20
+	    </author>
21
+	    <editor>
22
+		<firstname>Daniel-Constantin</firstname>
23
+		<surname>Mierla</surname>
24
+		<email>miconda@gmail.com</email>
25
+	    </editor>
26
+	</authorgroup>
27
+	<copyright>
28
+	    <year>2019</year>
29
+	    <holder>asipto.com</holder>
30
+	</copyright>
31
+    </bookinfo>
32
+    <toc></toc>
33
+
34
+    <xi:include href="kemix_admin.xml"/>
35
+
36
+</book>
0 37
new file mode 100644
... ...
@@ -0,0 +1,72 @@
1
+<?xml version="1.0" encoding='ISO-8859-1'?>
2
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4
+
5
+<!-- Include general documentation entities -->
6
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
7
+%docentities;
8
+
9
+]>
10
+<!-- Module User's Guide -->
11
+
12
+<chapter>
13
+
14
+	<title>&adminguide;</title>
15
+
16
+	<section>
17
+	<title>Overview</title>
18
+	<para>
19
+		This module collects extensions and functions to be used with KEMI
20
+		SIP routing scripting. The target is to implement alternatives to
21
+		specific concepts designed for the native scripting language (e.g.,
22
+		core keywords and core conditions) without pushing code in the core
23
+		of the application.
24
+	</para>
25
+	<para>
26
+		It does not provide functions for the native &kamailio;.cfg.
27
+	</para>
28
+	<para>
29
+		To see the KEMI functions exported by this module, see:
30
+		<itemizedlist>
31
+			<listitem>
32
+			<para>
33
+				<ulink url="http://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/">
34
+					http://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/</ulink>
35
+			</para>
36
+			</listitem>
37
+		</itemizedlist>
38
+	</para>
39
+	</section>
40
+
41
+	<section>
42
+	<title>Dependencies</title>
43
+	<section>
44
+		<title>&kamailio; Modules</title>
45
+		<para>
46
+		The following modules must be loaded before this module:
47
+			<itemizedlist>
48
+			<listitem>
49
+			<para>
50
+				<emphasis>None</emphasis>.
51
+			</para>
52
+			</listitem>
53
+			</itemizedlist>
54
+		</para>
55
+	</section>
56
+	<section>
57
+		<title>External Libraries or Applications</title>
58
+		<para>
59
+		The following libraries or applications must be installed before running
60
+		&kamailio; with this module loaded:
61
+			<itemizedlist>
62
+			<listitem>
63
+			<para>
64
+				<emphasis>None</emphasis>
65
+			</para>
66
+			</listitem>
67
+			</itemizedlist>
68
+		</para>
69
+	</section>
70
+	</section>
71
+</chapter>
72
+
0 73
new file mode 100644
... ...
@@ -0,0 +1,107 @@
1
+/**
2
+ * Copyright (C) 2019 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 <string.h>
26
+
27
+#include "../../core/sr_module.h"
28
+#include "../../core/dprint.h"
29
+#include "../../core/kemi.h"
30
+#include "../../core/parser/parse_uri.h"
31
+
32
+MODULE_VERSION
33
+
34
+struct module_exports exports = {
35
+	"kemix",         /* module name */
36
+	DEFAULT_DLFLAGS, /* dlopen flags */
37
+	0,               /* cmd (cfg function) exports */
38
+	0,               /* param exports */
39
+	0,               /* RPC method exports */
40
+	0,               /* pseudo-variables exports */
41
+	0,               /* response handling function */
42
+	0,               /* module init function */
43
+	0,               /* per-child init function */
44
+	0                /* module destroy function */
45
+};
46
+
47
+
48
+/**
49
+ *
50
+ */
51
+static sr_kemi_xval_t _sr_kemi_kx_xval = {0};
52
+
53
+/**
54
+ *
55
+ */
56
+static sr_kemi_xval_t* ki_kx_get_ruri(sip_msg_t *msg)
57
+{
58
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
59
+
60
+	if(msg==NULL) {
61
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
62
+		return &_sr_kemi_kx_xval;
63
+	}
64
+
65
+	if(msg->first_line.type == SIP_REPLY) {
66
+		/* REPLY doesnt have a ruri */
67
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
68
+		return &_sr_kemi_kx_xval;
69
+	}
70
+
71
+	if(msg->parsed_uri_ok==0 /* R-URI not parsed*/ && parse_sip_msg_uri(msg)<0) {
72
+		LM_ERR("failed to parse the R-URI\n");
73
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
74
+		return &_sr_kemi_kx_xval;
75
+	}
76
+
77
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
78
+	if (msg->new_uri.s!=NULL) {
79
+		_sr_kemi_kx_xval.v.s = msg->new_uri;
80
+	} else {
81
+		_sr_kemi_kx_xval.v.s = msg->first_line.u.request.uri;
82
+	}
83
+	return &_sr_kemi_kx_xval;
84
+}
85
+
86
+/**
87
+ *
88
+ */
89
+/* clang-format off */
90
+static sr_kemi_t sr_kemi_kx_exports[] = {
91
+	{ str_init("kx"), str_init("get_ruri"),
92
+		SR_KEMIP_XVAL, ki_kx_get_ruri,
93
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
94
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
95
+	},
96
+
97
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
98
+};
99
+
100
+/**
101
+ *
102
+ */
103
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
104
+{
105
+	sr_kemi_modules_add(sr_kemi_kx_exports);
106
+	return 0;
107
+}