kemix: new module to collect KEMI specific collections
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 24 May 2019 10:44:16 +0000 (12:44 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 24 May 2019 10:44:16 +0000 (12:44 +0200)
- avoid pushing code in core for alternatives to core keywords,
conditions, a.s.o.

src/modules/kemix/Makefile [new file with mode: 0644]
src/modules/kemix/README [new file with mode: 0644]
src/modules/kemix/doc/Makefile [new file with mode: 0644]
src/modules/kemix/doc/kemix.xml [new file with mode: 0644]
src/modules/kemix/doc/kemix_admin.xml [new file with mode: 0644]
src/modules/kemix/kemix_mod.c [new file with mode: 0644]

diff --git a/src/modules/kemix/Makefile b/src/modules/kemix/Makefile
new file mode 100644 (file)
index 0000000..8997328
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# WARNING: do not run this directly, it should be run by the master Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=kemix.so
+LIBS=
+
+include ../../Makefile.modules
diff --git a/src/modules/kemix/README b/src/modules/kemix/README
new file mode 100644 (file)
index 0000000..1fa5a94
--- /dev/null
@@ -0,0 +1,63 @@
+KEMIX Module
+
+Daniel-Constantin Mierla
+
+   <miconda@gmail.com>
+
+Edited by
+
+Daniel-Constantin Mierla
+
+   <miconda@gmail.com>
+
+   Copyright © 2019 asipto.com
+     __________________________________________________________________
+
+   Table of Contents
+
+   1. Admin Guide
+
+        1. Overview
+        2. Dependencies
+
+              2.1. Kamailio Modules
+              2.2. External Libraries or Applications
+
+Chapter 1. Admin Guide
+
+   Table of Contents
+
+   1. Overview
+   2. Dependencies
+
+        2.1. Kamailio Modules
+        2.2. External Libraries or Applications
+
+1. Overview
+
+   This module collects extensions and functions to be used with KEMI SIP
+   routing scripting. The target is to implement alternatives to specific
+   concepts designed for the native scripting language (e.g., core
+   keywords and core conditions) without pushing code in the core of the
+   application.
+
+   It does not provide functions for the native Kamailio.cfg.
+
+   To see the KEMI functions exported by this module, see:
+     * http://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/
+
+2. Dependencies
+
+   2.1. Kamailio Modules
+   2.2. External Libraries or Applications
+
+2.1. Kamailio Modules
+
+   The following modules must be loaded before this module:
+     * None.
+
+2.2. External Libraries or Applications
+
+   The following libraries or applications must be installed before
+   running Kamailio with this module loaded:
+     * None
diff --git a/src/modules/kemix/doc/Makefile b/src/modules/kemix/doc/Makefile
new file mode 100644 (file)
index 0000000..20d39be
--- /dev/null
@@ -0,0 +1,4 @@
+docs = kemix.xml
+
+docbook_dir = ../../../../doc/docbook
+include $(docbook_dir)/Makefile.module
diff --git a/src/modules/kemix/doc/kemix.xml b/src/modules/kemix/doc/kemix.xml
new file mode 100644 (file)
index 0000000..cf824eb
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
+%docentities;
+
+]>
+
+<book xmlns:xi="http://www.w3.org/2001/XInclude">
+    <bookinfo>
+       <title>KEMIX Module</title>
+       <productname class="trade">kamailio.org</productname>
+       <authorgroup>
+           <author>
+               <firstname>Daniel-Constantin</firstname>
+               <surname>Mierla</surname>
+               <email>miconda@gmail.com</email>
+           </author>
+           <editor>
+               <firstname>Daniel-Constantin</firstname>
+               <surname>Mierla</surname>
+               <email>miconda@gmail.com</email>
+           </editor>
+       </authorgroup>
+       <copyright>
+           <year>2019</year>
+           <holder>asipto.com</holder>
+       </copyright>
+    </bookinfo>
+    <toc></toc>
+
+    <xi:include href="kemix_admin.xml"/>
+
+</book>
diff --git a/src/modules/kemix/doc/kemix_admin.xml b/src/modules/kemix/doc/kemix_admin.xml
new file mode 100644 (file)
index 0000000..0743d77
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
+%docentities;
+
+]>
+<!-- Module User's Guide -->
+
+<chapter>
+
+       <title>&adminguide;</title>
+
+       <section>
+       <title>Overview</title>
+       <para>
+               This module collects extensions and functions to be used with KEMI
+               SIP routing scripting. The target is to implement alternatives to
+               specific concepts designed for the native scripting language (e.g.,
+               core keywords and core conditions) without pushing code in the core
+               of the application.
+       </para>
+       <para>
+               It does not provide functions for the native &kamailio;.cfg.
+       </para>
+       <para>
+               To see the KEMI functions exported by this module, see:
+               <itemizedlist>
+                       <listitem>
+                       <para>
+                               <ulink url="http://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/">
+                                       http://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/</ulink>
+                       </para>
+                       </listitem>
+               </itemizedlist>
+       </para>
+       </section>
+
+       <section>
+       <title>Dependencies</title>
+       <section>
+               <title>&kamailio; Modules</title>
+               <para>
+               The following modules must be loaded before this module:
+                       <itemizedlist>
+                       <listitem>
+                       <para>
+                               <emphasis>None</emphasis>.
+                       </para>
+                       </listitem>
+                       </itemizedlist>
+               </para>
+       </section>
+       <section>
+               <title>External Libraries or Applications</title>
+               <para>
+               The following libraries or applications must be installed before running
+               &kamailio; with this module loaded:
+                       <itemizedlist>
+                       <listitem>
+                       <para>
+                               <emphasis>None</emphasis>
+                       </para>
+                       </listitem>
+                       </itemizedlist>
+               </para>
+       </section>
+       </section>
+</chapter>
+
diff --git a/src/modules/kemix/kemix_mod.c b/src/modules/kemix/kemix_mod.c
new file mode 100644 (file)
index 0000000..f342ef6
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * Copyright (C) 2019 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../core/sr_module.h"
+#include "../../core/dprint.h"
+#include "../../core/kemi.h"
+#include "../../core/parser/parse_uri.h"
+
+MODULE_VERSION
+
+struct module_exports exports = {
+       "kemix",         /* module name */
+       DEFAULT_DLFLAGS, /* dlopen flags */
+       0,               /* cmd (cfg function) exports */
+       0,               /* param exports */
+       0,               /* RPC method exports */
+       0,               /* pseudo-variables exports */
+       0,               /* response handling function */
+       0,               /* module init function */
+       0,               /* per-child init function */
+       0                /* module destroy function */
+};
+
+
+/**
+ *
+ */
+static sr_kemi_xval_t _sr_kemi_kx_xval = {0};
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_get_ruri(sip_msg_t *msg)
+{
+       memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
+
+       if(msg==NULL) {
+               sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
+               return &_sr_kemi_kx_xval;
+       }
+
+       if(msg->first_line.type == SIP_REPLY) {
+               /* REPLY doesnt have a ruri */
+               sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
+               return &_sr_kemi_kx_xval;
+       }
+
+       if(msg->parsed_uri_ok==0 /* R-URI not parsed*/ && parse_sip_msg_uri(msg)<0) {
+               LM_ERR("failed to parse the R-URI\n");
+               sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
+               return &_sr_kemi_kx_xval;
+       }
+
+       _sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
+       if (msg->new_uri.s!=NULL) {
+               _sr_kemi_kx_xval.v.s = msg->new_uri;
+       } else {
+               _sr_kemi_kx_xval.v.s = msg->first_line.u.request.uri;
+       }
+       return &_sr_kemi_kx_xval;
+}
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_kx_exports[] = {
+       { str_init("kx"), str_init("get_ruri"),
+               SR_KEMIP_XVAL, ki_kx_get_ruri,
+               { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
+
+       { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+       sr_kemi_modules_add(sr_kemi_kx_exports);
+       return 0;
+}