Browse code

modules/mtree: added mt_match API function

Juha Heinanen authored on 15/05/2017 13:40:28
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,57 @@
1
+/*
2
+ * Mtree module API specification
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
+#ifndef _MTREE_API_H_
23
+#define _MTREE_API_H_
24
+
25
+#include "../../core/parser/msg_parser.h"
26
+
27
+typedef int (*mt_match_f)(sip_msg_t *msg, str *tname, str *tomatch, int mval);
28
+
29
+typedef struct mtree_api {
30
+	mt_match_f mt_match;
31
+	mt_match_f mt_match_value;
32
+	mt_match_f mt_match_values;
33
+} mtree_api_t;
34
+
35
+typedef int (*bind_mtree_f)(mtree_api_t* api);
36
+
37
+/**
38
+ * @brief Load Mtree API
39
+ */
40
+static inline int mtree_load_api(mtree_api_t *api)
41
+{
42
+	bind_mtree_f bind_mtree;
43
+
44
+	bind_mtree = (bind_mtree_f)find_export("bind_mtree", 0, 0);
45
+	if (bind_mtree == 0) {
46
+		LM_ERR("cannot find bind_mtree\n");
47
+		return -1;
48
+	}
49
+	if (bind_mtree(api) <0) {
50
+		LM_ERR("cannot bind mtree api\n");
51
+		return -1;
52
+	}
53
+	return 0;
54
+}
55
+
56
+
57
+#endif /* _MTREE_API_H_ */
... ...
@@ -46,5 +46,6 @@
46 46
     <toc></toc>
47 47
     
48 48
 	<xi:include href="mtree_admin.xml"/>
49
+	<xi:include href="mtree_devel.xml"/>
49 50
     
50 51
 </book>
51 52
new file mode 100644
... ...
@@ -0,0 +1,65 @@
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 Developer's Guide -->
11
+
12
+<chapter>
13
+	
14
+	<title>&develguide;</title>
15
+	<section>
16
+	<title>Available Functions</title>
17
+	<section>
18
+		<title>
19
+		<function moreinfo="none">mt_load_api(api)
20
+			</function>
21
+		</title>
22
+		<para>
23
+		The function imports all API functions that are exported by the 
24
+		mtree module (see sections below).
25
+		</para>
26
+		<para>Meaning of the parameters is as follows:</para>
27
+		<itemizedlist>
28
+		<listitem>
29
+			<para><emphasis>mtree_api_t* api</emphasis> - mtree API
30
+			</para>
31
+		</listitem>
32
+		</itemizedlist>
33
+	</section>
34
+	<section>
35
+		<title>
36
+		<function moreinfo="none">mt_match(msg, mtree, value, mode)</function>
37
+		</title>
38
+		<para>
39
+		Match 'value' against 'mtree' using 'mode' (see mt_match
40
+        function Admin Guide documentation).
41
+		</para>
42
+		<para>Meaning of the parameters is as follows:</para>
43
+		<itemizedlist>
44
+		<listitem>
45
+			<para><emphasis>sip_msg_t *msg</emphasis> - SIP Request
46
+			</para>
47
+		</listitem>
48
+		<listitem>
49
+			<para><emphasis>str *mtree</emphasis> - Name of mtree
50
+			</para>
51
+		</listitem>
52
+		<listitem>
53
+			<para><emphasis>str *value</emphasis> - Value to match
54
+			</para>
55
+		</listitem>
56
+		<listitem>
57
+			<para><emphasis>int mode</emphasis> - Match mode
58
+			</para>
59
+		</listitem>
60
+		</itemizedlist>
61
+	</section>
62
+	</section>
63
+
64
+</chapter>
65
+
... ...
@@ -42,6 +42,7 @@
42 42
 #include "../../core/kemi.h"
43 43
 
44 44
 #include "mtree.h"
45
+#include "api.h"
45 46
 
46 47
 MODULE_VERSION
47 48
 
... ...
@@ -112,6 +113,7 @@ static int  mod_init(void);
112 113
 static void mod_destroy(void);
113 114
 static int  child_init(int rank);
114 115
 static int mtree_init_rpc(void);
116
+static int bind_mtree(mtree_api_t* api);
115 117
 
116 118
 static int mt_match(sip_msg_t *msg, str *tname, str *tomatch,
117 119
 		int mval);
... ...
@@ -122,6 +124,7 @@ static int mt_load_db_trees();
122 124
 static cmd_export_t cmds[]={
123 125
 	{"mt_match", (cmd_function)w_mt_match, 3, fixup_mt_match,
124 126
 		0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE},
127
+	{"bind_mtree", (cmd_function)bind_mtree, 0, 0, 0},
125 128
 	{0, 0, 0, 0, 0, 0}
126 129
 };
127 130
 
... ...
@@ -1191,6 +1194,22 @@ static sr_kemi_t sr_kemi_mtree_exports[] = {
1191 1194
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1192 1195
 };
1193 1196
 
1197
+
1198
+/**
1199
+ * load mtree module API
1200
+ */
1201
+static int bind_mtree(mtree_api_t* api)
1202
+{
1203
+	if (!api) {
1204
+		LM_ERR("Invalid parameter value\n");
1205
+		return -1;
1206
+	}
1207
+	api->mt_match = mt_match;
1208
+
1209
+	return 0;
1210
+}
1211
+
1212
+
1194 1213
 /**
1195 1214
  *
1196 1215
  */