Просмотр исходного кода

Merge branch 'master' of ssh://[email protected]/sip-router

* 'master' of ssh://[email protected]/sip-router:
  parser: added METHOD_PUBLISH
  registrar: included missing lib/kcore/km_ut.h
  textops: added implementation of free_/fixup_regexp_none()
  core: commented prototype of free_/fixup_regexp_none()
  kex: added module documentation
  kex: set dependency on kmi and kcore libs
  kex: new module - kamailio extensions
  libkmi: moved mi core commands to kex module
  mi_fifo: start FIFO listener process using SR interface
Juha Heinanen 16 лет назад
Родитель
Сommit
2058f9802c

+ 1 - 1
mod_fix.h

@@ -85,9 +85,9 @@ int fixup_uint_uint(void** param, int param_no);
 
 int fixup_regexp_null(void** param, int param_no);
 int fixup_free_regexp_null(void** param, int param_no);
+#if 0
 int fixup_regexp_none(void** param, int param_no);
 int fixup_free_regexp_none(void** param, int param_no);
-#if 0
 /* not implemened yet */
 int fixup_regexpNL_null(void** param, int param_no);
 int fixup_regexpNL_none(void** param, int param_no);

+ 18 - 0
modules_k/kex/Makefile

@@ -0,0 +1,18 @@
+# $Id$
+#
+# example module makefile
+#
+# 
+# WARNING: do not run this directly, it should be run by the master Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=kex.so
+LIBS=
+
+DEFS+=-DOPENSER_MOD_INTERFACE
+
+SERLIBPATH=../../lib
+SER_LIBS+=$(SERLIBPATH)/kmi/kmi
+SER_LIBS+=$(SERLIBPATH)/kcore/kcore
+include ../../Makefile.modules

+ 130 - 0
modules_k/kex/README

@@ -0,0 +1,130 @@
+KEx Module
+
+Daniel-Constantin Mierla
+
+   asipto.com
+   <[email protected]>
+
+Edited by
+
+Daniel-Constantin Mierla
+
+   <[email protected]>
+
+   Copyright © 2009 Daniel-Constantin Mierla
+     __________________________________________________________
+
+   Table of Contents
+
+   1. Admin Guide
+
+        1.1. Overview
+        1.2. Dependencies
+
+              1.2.1. Kamailio Modules
+              1.2.2. External Libraries or Applications
+
+        1.3. Exported MI Functions
+
+              1.3.1. arg
+              1.3.2. kill
+              1.3.3. pwd
+              1.3.4. uptime
+              1.3.5. version
+              1.3.6. which
+
+Chapter 1. Admin Guide
+
+1.1. Overview
+
+   This module collects extensions from Kamailio core.
+
+   Kamailio Core CookBook is available at:
+   http://kamailio.org/dokuwiki/
+
+1.2. Dependencies
+
+1.2.1. Kamailio Modules
+
+   The following modules must be loaded before this module:
+     * No dependencies on other Kamailio modules.
+
+1.2.2. External Libraries or Applications
+
+   The following libraries or applications must be installed
+   before running Kamailio with this module loaded:
+     * None.
+
+1.3. Exported MI Functions
+
+1.3.1.  arg
+
+   Print command line arguments.
+
+   Name: arg
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :arg:_reply_fifo_file_
+                _empty_line_
+
+1.3.2.  kill
+
+   Kill the application.
+
+   Name: kill
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :kill:_reply_fifo_file_
+                _empty_line_
+
+1.3.3.  pwd
+
+   Print working directory.
+
+   Name: pwd
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :pwd:_reply_fifo_file_
+                _empty_line_
+
+1.3.4.  uptime
+
+   Print uptime.
+
+   Name: uptime
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :uptime:_reply_fifo_file_
+                _empty_line_
+
+1.3.5.  version
+
+   Print version information.
+
+   Name: version
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :version:_reply_fifo_file_
+                _empty_line_
+
+1.3.6.  which
+
+   Print list of available MI commands.
+
+   Name: which
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :which:_reply_fifo_file_
+                _empty_line_

+ 47 - 0
modules_k/kex/doc/kex.xml

@@ -0,0 +1,47 @@
+<?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" [
+
+
+<!ENTITY admin SYSTEM "kex_admin.xml">
+<!ENTITY faq SYSTEM "../../../doc/module_faq.xml">
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../doc/entities.xml">
+%docentities;
+
+]>
+
+<book>
+    <bookinfo>
+	<title>KEx Module</title>
+	<productname class="trade">&kamailioname;</productname>
+	<authorgroup>
+	    <author>
+		<firstname>Daniel-Constantin</firstname>
+		<surname>Mierla</surname>
+		<affiliation><orgname>asipto.com</orgname></affiliation>
+		<email>[email protected]</email>
+		<address>
+		<otheraddr>
+		<ulink url="http://www.asipto.com">http://www.asipto.com</ulink>
+		</otheraddr>
+		</address>
+	    </author>
+	    <editor>
+		<firstname>Daniel-Constantin</firstname>
+		<surname>Mierla</surname>
+		<email>[email protected]</email>
+	    </editor>
+	</authorgroup>
+	<copyright>
+	    <year>2009</year>
+	    <holder>Daniel-Constantin Mierla</holder>
+	</copyright>
+    </bookinfo>
+    <toc></toc>
+    
+    &admin;
+    &faq;
+    
+</book>

+ 169 - 0
modules_k/kex/doc/kex_admin.xml

@@ -0,0 +1,169 @@
+<!-- Module User's Guide -->
+
+<chapter>
+	
+	<title>&adminguide;</title>
+	
+	<section>
+	<title>Overview</title>
+	<para>
+	This module collects extensions from Kamailio core.
+	</para>
+	<para>
+	Kamailio Core CookBook is available at:
+	<ulink url="http://kamailio.org/dokuwiki/">
+	http://kamailio.org/dokuwiki/</ulink>
+	</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>No dependencies on other &kamailio; modules</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>
+
+	<section>
+	<title>Exported MI Functions</title>
+	<section>
+		<title>
+		<function moreinfo="none">arg</function>
+		</title>
+		<para>
+		Print command line arguments.
+		</para>
+		<para>
+		Name: <emphasis>arg</emphasis>
+		</para>
+		<para>Parameters: <emphasis>none</emphasis>.</para>
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:arg:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
+	<section>
+		<title>
+		<function moreinfo="none">kill</function>
+		</title>
+		<para>
+		Kill the application.
+		</para>
+		<para>
+		Name: <emphasis>kill</emphasis>
+		</para>
+		<para>Parameters: <emphasis>none</emphasis>.</para>
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:kill:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
+	<section>
+		<title>
+		<function moreinfo="none">pwd</function>
+		</title>
+		<para>
+		Print working directory.
+		</para>
+		<para>
+		Name: <emphasis>pwd</emphasis>
+		</para>
+		<para>Parameters: <emphasis>none</emphasis>.</para>
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:pwd:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
+	<section>
+		<title>
+		<function moreinfo="none">uptime</function>
+		</title>
+		<para>
+		Print uptime.
+		</para>
+		<para>
+		Name: <emphasis>uptime</emphasis>
+		</para>
+		<para>Parameters: <emphasis>none</emphasis>.</para>
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:uptime:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
+	<section>
+		<title>
+		<function moreinfo="none">version</function>
+		</title>
+		<para>
+		Print version information.
+		</para>
+		<para>
+		Name: <emphasis>version</emphasis>
+		</para>
+		<para>Parameters: <emphasis>none</emphasis>.</para>
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:version:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
+	<section>
+		<title>
+		<function moreinfo="none">which</function>
+		</title>
+		<para>
+		Print list of available MI commands.
+		</para>
+		<para>
+		Name: <emphasis>which</emphasis>
+		</para>
+		<para>Parameters: <emphasis>none</emphasis>.</para>
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:which:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
+    </section>
+
+</chapter>
+

+ 85 - 0
modules_k/kex/kex_mod.c

@@ -0,0 +1,85 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2009
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "../../sr_module.h"
+#include "../../dprint.h"
+
+#include "mi_core.h"
+
+
+MODULE_VERSION
+
+
+/** parameters */
+
+/** module functions */
+static int mod_init(void);
+
+void destroy(void);
+
+static cmd_export_t cmds[]={
+	{0,0,0,0,0,0}
+};
+
+static param_export_t params[]={
+	{0,0,0}
+};
+
+
+/** module exports */
+struct module_exports exports= {
+	"kex",
+	DEFAULT_DLFLAGS, /* dlopen flags */
+	cmds,
+	params,
+	0,          /* exported statistics */
+	0,          /* exported MI functions */
+	0,          /* exported pseudo-variables */
+	0,          /* extra processes */
+	mod_init,   /* module initialization function */
+	0,
+	(destroy_function) destroy,
+	0           /* per-child init function */
+};
+
+/**
+ * init module function
+ */
+static int mod_init(void)
+{
+	if(init_mi_core()<0)
+		return -1;
+	return 0;
+}
+
+/**
+ * destroy function
+ */
+void destroy(void)
+{
+	return;
+}
+

+ 1 - 1
lib/kmi/mi_core.c → modules_k/kex/mi_core.c

@@ -46,7 +46,7 @@
 #include "../../ut.h"
 #include "../../pt.h"
 #include "../../mem/mem.h"
-#include "mi.h"
+#include "../../lib/kmi/mi.h"
 #include "../../version.h"
 
 #define BUILD_STR __FILE__ " compiled on "__TIME__ " " __DATE__ " with " COMPILER "\n"

+ 1 - 1
lib/kmi/mi_core.h → modules_k/kex/mi_core.h

@@ -36,6 +36,6 @@
 #ifndef _MI_MI_CORE_H_
 #define _MI_MI_CORE_H_
 
-// int init_mi_core(void);
+int init_mi_core(void);
 
 #endif

+ 16 - 0
modules_k/mi_fifo/mi_fifo.c

@@ -43,6 +43,7 @@
 #include "../../sr_module.h"
 #include "../../dprint.h"
 #include "../../ut.h"
+#include "../../pt.h"
 #include "../../mem/mem.h"
 #include "../../mem/shm_mem.h"
 #include "../../lib/kmi/mi.h"
@@ -170,6 +171,9 @@ static int mi_mod_init(void)
 		}
 	}
 
+	/* add space for one extra process */
+	register_procs(1);
+
 	return 0;
 }
 
@@ -177,6 +181,8 @@ static int mi_mod_init(void)
 /*! \brief Initialize module for child processes */
 static int mi_child_init(int rank)
 {
+	int pid;
+
 	if (rank==PROC_TIMER || rank>0 ) {
 		if ( mi_writer_init(read_buf_size, mi_reply_indent)!=0 ) {
 			LM_CRIT("failed to init the reply writer\n");
@@ -184,6 +190,16 @@ static int mi_child_init(int rank)
 		}
 	}
 
+	if (rank==PROC_MAIN) {
+		pid=fork_process(100, "MI FIFO", 1);
+		if (pid<0)
+			return -1; /* error */
+		if(pid==0){
+			/* child */
+			fifo_process(1);
+		}
+	}
+
 	return 0;
 }
 

+ 1 - 0
modules_k/registrar/reg_mod.c

@@ -64,6 +64,7 @@
 #include "../../error.h"
 #include "../../socket_info.h"
 #include "../../pvar.h"
+#include "../../lib/kcore/km_ut.h"
 #include "../usrloc/ul_mod.h"
 #include "../sl/sl_api.h"
 #include "../../mod_fix.h"

+ 36 - 0
modules_k/textops/textops.c

@@ -1811,3 +1811,39 @@ int fixup_regexpNL_none(void** param, int param_no)
 	*param=re;
 	return 0;
 }
+
+/*! \brief
+ * fixup for functions that get two parameters
+ * - first parameter is converted to regular expression structure
+ * - second parameter is not converted
+ */
+int fixup_regexp_none(void** param, int param_no)
+{
+	if (param_no != 1 && param_no != 2 )
+	{
+		LM_ERR("invalid parameter number %d\n", param_no);
+		return E_UNSPEC;
+	}
+	if (param_no == 1)
+		return fixup_regexp_null(param, 1);
+	return 0;
+}
+
+/**
+ * fixup free for functions that get two parameters
+ * - first parameter was converted to regular expression
+ * - second parameter was notconverted
+ */
+int fixup_free_regexp_none(void** param, int param_no)
+{
+	if (param_no != 1 && param_no != 2 )
+	{
+		LM_ERR("invalid parameter number %d\n", param_no);
+		return E_UNSPEC;
+	}
+	if (param_no == 1)
+		return fixup_free_regexp_null(param, 1);
+	return 0;
+}
+
+

+ 2 - 1
modules_k/textops/textops.h

@@ -31,5 +31,6 @@ int search_append_f(struct sip_msg*, char*, char*);
 int remove_hf_f(struct sip_msg* msg, char* str_hf, char* foo);
 int add_hf_helper(struct sip_msg* msg, str *str1, str *str2, gparam_p hfval, int mode, gparam_p hfanc);
 
-
+int fixup_regexp_none(void** param, int param_no);
+int fixup_free_regexp_none(void** param, int param_no);
 #endif /*TEXTOPS_H_*/

+ 18 - 4
parser/msg_parser.h

@@ -76,10 +76,24 @@
 #define SIP_MSG_START(m)	((m)->first_line.u.request.method.s)
 
 /* number methods as power of two to allow bitmap matching */
-enum request_method { METHOD_UNDEF=0, METHOD_INVITE=1, METHOD_CANCEL=2, METHOD_ACK=4,
-	METHOD_BYE=8, METHOD_INFO=16, METHOD_REGISTER=32, METHOD_SUBSCRIBE=64,
-	METHOD_NOTIFY=128, METHOD_MESSAGE=256, METHOD_OPTIONS=512,
-	METHOD_PRACK=1024, METHOD_UPDATE=2048, METHOD_REFER = 4096, METHOD_OTHER=8192 };
+enum request_method {
+	METHOD_UNDEF=0,           /* 0 - --- */
+	METHOD_INVITE=1,          /* 1 - 2^0 */
+	METHOD_CANCEL=2,          /* 2 - 2^1 */
+	METHOD_ACK=4,             /* 3 - 2^2 */
+	METHOD_BYE=8,             /* 4 - 2^3 */
+	METHOD_INFO=16,           /* 5 - 2^4 */
+	METHOD_REGISTER=32,       /* 6 - 2^5 */
+	METHOD_SUBSCRIBE=64,      /* 7 - 2^6 */
+	METHOD_NOTIFY=128,        /* 8 - 2^7 */
+	METHOD_MESSAGE=256,       /* 9 - 2^8 */
+	METHOD_OPTIONS=512,       /* 10 - 2^9 */
+	METHOD_PRACK=1024,        /* 11 - 2^10 */
+	METHOD_UPDATE=2048,       /* 12 - 2^11 */
+	METHOD_REFER=4096,        /* 13 - 2^12 */
+	METHOD_PUBLISH=8192,      /* 14 - 2^13 */
+	METHOD_OTHER=16384        /* 15 - 2^14 */
+};
 
 #define FL_FORCE_RPORT  (1 << 0)  /* force rport */
 #define FL_FORCE_ACTIVE (1 << 1)  /* force active SDP */

+ 14 - 10
parser/parse_methods.c

@@ -155,9 +155,14 @@ int parse_method(str* _next, enum request_method* _method)
  			_next->len -= 5;
  			_next->s += 5;
  			return 1;
- 		} else {
- 			goto unknown;
  		}
+ 		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ublish", 6)) {
+ 			*_method = METHOD_PUBLISH;
+ 			_next->len -= 7;
+ 			_next->s += 7;
+ 			return 1;
+ 		}
+ 		goto unknown;
 
  	case 'R':
  	case 'r':
@@ -221,7 +226,7 @@ int parse_method(str* _next, enum request_method* _method)
  
  /* 
   * Parse comma separated list of methods pointed by _body and assign their
-  * enum bits to _methods.  Returns 1 on success and 0 on failure.
+  * enum bits to _methods.  Returns 0 on success and -1 on failure.
   */
  int parse_methods(str* _body, unsigned int* _methods)
  {
@@ -232,7 +237,7 @@ int parse_method(str* _next, enum request_method* _method)
  
 	if (!_body || !_methods) {
 		LOG(L_ERR, "parse_methods: Invalid parameter value\n");
-		return 0;
+		return -1;
 	}
 
 	next.len = _body->len;
@@ -240,19 +245,18 @@ int parse_method(str* _next, enum request_method* _method)
  
  	trim_leading(&next);
  
+  	*_methods = 0;
+ 
  	if (next.len == 0) {
- 		LOG(L_ERR, "ERROR: parse_methods: Empty body\n");
  		return 0;
  	}
 
-  	*_methods = 0;
- 
  	while (1) {
  		if (parse_method(&next, &method)) {
  			*_methods |= method;
  		} else {
  			LOG(L_ERR, "ERROR: parse_methods: Invalid method\n");
- 			return 0;
+ 			return -1;
  		}
 		
  		trim_leading(&next);
@@ -267,12 +271,12 @@ int parse_method(str* _next, enum request_method* _method)
  				}
  			} else {
  				LOG(L_ERR, "ERROR: parse_methods: Comma expected\n");
- 				return 0;
+ 				return -1;
  			}
  		} else {
  			break;
  		}
  	}
 
- 	return 1;
+ 	return 0;
  }