Browse code

phonenum: proper access to the str type param resid

Daniel-Constantin Mierla authored on 03/09/2019 18:03:05
Showing 1 changed files
... ...
@@ -112,8 +112,7 @@ static int phonenum_resid_param(modparam_t type, void* val)
112 112
 {
113 113
 	str rname;
114 114
 
115
-	rname.s = (char*)val;
116
-	rname.len = strlen(rname.s);
115
+	rname = *((str*)val);
117 116
 	if(sr_phonenum_add_resid(&rname) < 0) {
118 117
 		LM_ERR("failed to register result container with id: %.*s\n",
119 118
 				rname.len, rname.s);
Browse code

phonenum: new param resid to register result container ids

- allow use in KEMI scripting by pre-registering container result id via
modparam

Daniel-Constantin Mierla authored on 02/09/2019 11:41:03
Showing 1 changed files
... ...
@@ -47,6 +47,8 @@ static int w_phonenum_match_cn(struct sip_msg *msg, char *str1, char *str2,
47 47
 		char *str3);
48 48
 static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass);
49 49
 
50
+static int phonenum_resid_param(modparam_t type, void* val);
51
+
50 52
 /* clang-format off */
51 53
 static pv_export_t mod_pvs[] = {
52 54
 	{ {"phn", sizeof("phn")-1}, PVT_OTHER, pv_get_phonenum, 0,
... ...
@@ -64,6 +66,7 @@ static cmd_export_t cmds[]={
64 66
 
65 67
 static param_export_t params[]={
66 68
 	{"smode", PARAM_INT, &phonenum_smode},
69
+	{"resid", PARAM_STR|PARAM_USE_FUNC, &phonenum_resid_param},
67 70
 	{0, 0, 0}
68 71
 };
69 72
 
... ...
@@ -102,6 +105,22 @@ static void mod_destroy(void)
102 105
 	phonenum_destroy_pv();
103 106
 }
104 107
 
108
+/**
109
+ *
110
+ */
111
+static int phonenum_resid_param(modparam_t type, void* val)
112
+{
113
+	str rname;
114
+
115
+	rname.s = (char*)val;
116
+	rname.len = strlen(rname.s);
117
+	if(sr_phonenum_add_resid(&rname) < 0) {
118
+		LM_ERR("failed to register result container with id: %.*s\n",
119
+				rname.len, rname.s);
120
+		return -1;
121
+	}
122
+	return 0;
123
+}
105 124
 
106 125
 static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass)
107 126
 {
Browse code

phonenum: updated to the new mod interface

Victor Seva authored on 28/09/2018 08:51:17
Showing 1 changed files
... ...
@@ -68,18 +68,16 @@ static param_export_t params[]={
68 68
 };
69 69
 
70 70
 struct module_exports exports = {
71
-	"phonenum",
71
+	"phonenum",      /* module name */
72 72
 	DEFAULT_DLFLAGS, /* dlopen flags */
73
-	cmds,            /* exported config functions */
74
-	params,          /* exported config parameters */
75
-	0,
76
-	0,              /* exported MI functions */
77
-	mod_pvs,        /* exported pseudo-variables */
78
-	0,              /* extra processes */
79
-	mod_init,       /* module initialization function */
80
-	0,              /* response function */
81
-	mod_destroy,    /* destroy function */
82
-	0               /* per child init function */
73
+	cmds,            /* cmd (cfg function) exports */
74
+	params,          /* param exports */
75
+	0,               /* RPC method exports */
76
+	mod_pvs,         /* pseudo-variables exports */
77
+	0,               /* response handling function */
78
+	mod_init,        /* module init function */
79
+	0,               /* per-child init function */
80
+	mod_destroy      /* module destroy function */
83 81
 };
84 82
 /* clang-format on */
85 83
 
Browse code

phonenum: set the order of params for phonenum_match_cn()

Daniel-Constantin Mierla authored on 28/03/2018 06:26:02
Showing 1 changed files
... ...
@@ -109,7 +109,7 @@ static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass)
109 109
 {
110 110
 	phonenum_pv_reset(pvclass);
111 111
 
112
-	return phonenum_update_pv(tomatch, pvclass, NULL);
112
+	return phonenum_update_pv(tomatch, NULL, pvclass);
113 113
 }
114 114
 
115 115
 static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
... ...
@@ -134,15 +134,15 @@ static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
134 134
 	return phonenum_match(msg, &tomatch, &pvclass);
135 135
 }
136 136
 
137
-static int phonenum_match_cn(sip_msg_t *msg, str *tomatch, str *pvclass, str *cc)
137
+static int phonenum_match_cn(sip_msg_t *msg, str *tomatch, str *cnc, str *pvclass)
138 138
 {
139 139
 	phonenum_pv_reset(pvclass);
140 140
 
141
-	return phonenum_update_pv(tomatch, pvclass, cc);
141
+	return phonenum_update_pv(tomatch, cnc, pvclass);
142 142
 }
143 143
 
144
-static int w_phonenum_match_cn(sip_msg_t *msg, char *target, char *pvname,
145
-		char *cncstr)
144
+static int w_phonenum_match_cn(sip_msg_t *msg, char *target, char *cncstr,
145
+		char *pvname)
146 146
 {
147 147
 	str tomatch = STR_NULL;
148 148
 	str pvclass = STR_NULL;
... ...
@@ -157,16 +157,16 @@ static int w_phonenum_match_cn(sip_msg_t *msg, char *target, char *pvname,
157 157
 		LM_ERR("cannot get the address\n");
158 158
 		return -1;
159 159
 	}
160
-	if(fixup_get_svalue(msg, (gparam_t *)pvname, &pvclass) < 0) {
161
-		LM_ERR("cannot get the pv class\n");
162
-		return -1;
163
-	}
164 160
 	if(fixup_get_svalue(msg, (gparam_t *)cncstr, &cncval) < 0) {
165 161
 		LM_ERR("cannot get the country code\n");
166 162
 		return -1;
167 163
 	}
164
+	if(fixup_get_svalue(msg, (gparam_t *)pvname, &pvclass) < 0) {
165
+		LM_ERR("cannot get the pv class\n");
166
+		return -1;
167
+	}
168 168
 
169
-	return phonenum_match_cn(msg, &tomatch, &pvclass, &cncval);
169
+	return phonenum_match_cn(msg, &tomatch, &cncval, &pvclass);
170 170
 }
171 171
 
172 172
 /**
Browse code

phonenum: new function phonenum_match_cn(...)

- match a phone number within a specific country provided by country
code two letter

Daniel-Constantin Mierla authored on 27/03/2018 19:59:24
Showing 1 changed files
... ...
@@ -43,6 +43,8 @@ static int mod_init(void);
43 43
 static void mod_destroy(void);
44 44
 
45 45
 static int w_phonenum_match(struct sip_msg *msg, char *str1, char *str2);
46
+static int w_phonenum_match_cn(struct sip_msg *msg, char *str1, char *str2,
47
+		char *str3);
46 48
 static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass);
47 49
 
48 50
 /* clang-format off */
... ...
@@ -55,6 +57,8 @@ static pv_export_t mod_pvs[] = {
55 57
 static cmd_export_t cmds[]={
56 58
 	{"phonenum_match", (cmd_function)w_phonenum_match, 2, fixup_spve_spve,
57 59
 		0, ANY_ROUTE},
60
+	{"phonenum_match_cn", (cmd_function)w_phonenum_match_cn, 3, fixup_spve_all,
61
+		0, ANY_ROUTE},
58 62
 	{0, 0, 0, 0, 0, 0}
59 63
 };
60 64
 
... ...
@@ -105,7 +109,7 @@ static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass)
105 109
 {
106 110
 	phonenum_pv_reset(pvclass);
107 111
 
108
-	return phonenum_update_pv(tomatch, pvclass);
112
+	return phonenum_update_pv(tomatch, pvclass, NULL);
109 113
 }
110 114
 
111 115
 static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
... ...
@@ -130,6 +134,41 @@ static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
130 134
 	return phonenum_match(msg, &tomatch, &pvclass);
131 135
 }
132 136
 
137
+static int phonenum_match_cn(sip_msg_t *msg, str *tomatch, str *pvclass, str *cc)
138
+{
139
+	phonenum_pv_reset(pvclass);
140
+
141
+	return phonenum_update_pv(tomatch, pvclass, cc);
142
+}
143
+
144
+static int w_phonenum_match_cn(sip_msg_t *msg, char *target, char *pvname,
145
+		char *cncstr)
146
+{
147
+	str tomatch = STR_NULL;
148
+	str pvclass = STR_NULL;
149
+	str cncval = STR_NULL;
150
+
151
+	if(msg == NULL) {
152
+		LM_ERR("received null msg\n");
153
+		return -1;
154
+	}
155
+
156
+	if(fixup_get_svalue(msg, (gparam_t *)target, &tomatch) < 0) {
157
+		LM_ERR("cannot get the address\n");
158
+		return -1;
159
+	}
160
+	if(fixup_get_svalue(msg, (gparam_t *)pvname, &pvclass) < 0) {
161
+		LM_ERR("cannot get the pv class\n");
162
+		return -1;
163
+	}
164
+	if(fixup_get_svalue(msg, (gparam_t *)cncstr, &cncval) < 0) {
165
+		LM_ERR("cannot get the country code\n");
166
+		return -1;
167
+	}
168
+
169
+	return phonenum_match_cn(msg, &tomatch, &pvclass, &cncval);
170
+}
171
+
133 172
 /**
134 173
  *
135 174
  */
Browse code

phonenum: set record after phone number lookup and return pv attributes

Daniel-Constantin Mierla authored on 08/11/2017 10:59:31
Showing 1 changed files
... ...
@@ -39,19 +39,19 @@ MODULE_VERSION
39 39
 
40 40
 static int phonenum_smode = 0;
41 41
 
42
-static int  mod_init(void);
42
+static int mod_init(void);
43 43
 static void mod_destroy(void);
44 44
 
45
-static int w_phonenum_match(struct sip_msg* msg, char* str1, char* str2);
45
+static int w_phonenum_match(struct sip_msg *msg, char *str1, char *str2);
46 46
 static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass);
47 47
 
48
+/* clang-format off */
48 49
 static pv_export_t mod_pvs[] = {
49 50
 	{ {"phn", sizeof("phn")-1}, PVT_OTHER, pv_get_phonenum, 0,
50 51
 		pv_parse_phonenum_name, 0, 0, 0 },
51 52
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
52 53
 };
53 54
 
54
-
55 55
 static cmd_export_t cmds[]={
56 56
 	{"phonenum_match", (cmd_function)w_phonenum_match, 2, fixup_spve_spve,
57 57
 		0, ANY_ROUTE},
... ...
@@ -66,8 +66,8 @@ static param_export_t params[]={
66 66
 struct module_exports exports = {
67 67
 	"phonenum",
68 68
 	DEFAULT_DLFLAGS, /* dlopen flags */
69
-	cmds,
70
-	params,
69
+	cmds,            /* exported config functions */
70
+	params,          /* exported config parameters */
71 71
 	0,
72 72
 	0,              /* exported MI functions */
73 73
 	mod_pvs,        /* exported pseudo-variables */
... ...
@@ -77,7 +77,7 @@ struct module_exports exports = {
77 77
 	mod_destroy,    /* destroy function */
78 78
 	0               /* per child init function */
79 79
 };
80
-
80
+/* clang-format on */
81 81
 
82 82
 /**
83 83
  * init module function
... ...
@@ -85,8 +85,7 @@ struct module_exports exports = {
85 85
 static int mod_init(void)
86 86
 {
87 87
 
88
-	if(phonenum_init_pv(phonenum_smode)!=0)
89
-	{
88
+	if(phonenum_init_pv(phonenum_smode) != 0) {
90 89
 		LM_ERR("cannot do init\n");
91 90
 		return -1;
92 91
 	}
... ...
@@ -109,21 +108,21 @@ static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass)
109 108
 	return phonenum_update_pv(tomatch, pvclass);
110 109
 }
111 110
 
112
-static int w_phonenum_match(sip_msg_t* msg, char* target, char* pvname)
111
+static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
113 112
 {
114 113
 	str tomatch = STR_NULL;
115 114
 	str pvclass = STR_NULL;
116 115
 
117
-	if(msg==NULL) {
116
+	if(msg == NULL) {
118 117
 		LM_ERR("received null msg\n");
119 118
 		return -1;
120 119
 	}
121 120
 
122
-	if(fixup_get_svalue(msg, (gparam_t*)target, &tomatch)<0) {
121
+	if(fixup_get_svalue(msg, (gparam_t *)target, &tomatch) < 0) {
123 122
 		LM_ERR("cannot get the address\n");
124 123
 		return -1;
125 124
 	}
126
-	if(fixup_get_svalue(msg, (gparam_t*)pvname, &pvclass)<0) {
125
+	if(fixup_get_svalue(msg, (gparam_t *)pvname, &pvclass) < 0) {
127 126
 		LM_ERR("cannot get the pv class\n");
128 127
 		return -1;
129 128
 	}
... ...
@@ -134,17 +133,20 @@ static int w_phonenum_match(sip_msg_t* msg, char* target, char* pvname)
134 133
 /**
135 134
  *
136 135
  */
136
+/* clang-format off */
137 137
 static sr_kemi_t sr_kemi_phonenum_exports[] = {
138
-    { str_init("phonenum"), str_init("match"),
139
-        SR_KEMIP_INT, phonenum_match,
140
-        { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
141
-            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
142
-    },
138
+	{ str_init("phonenum"), str_init("match"),
139
+		SR_KEMIP_INT, phonenum_match,
140
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
141
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
142
+	},
143 143
 
144
-    { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
144
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
145 145
 };
146
+/* clang-format on */
146 147
 
147
-int mod_register(char *path, int *dlflags, void *p1, void *p2) {
148
-    sr_kemi_modules_add(sr_kemi_phonenum_exports);
149
-    return 0;
148
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
149
+{
150
+	sr_kemi_modules_add(sr_kemi_phonenum_exports);
151
+	return 0;
150 152
 }
Browse code

phonenum: new module to do lookup on phone numbers

- relies on libphonenumber to get the attributes associated with the
phone number

Daniel-Constantin Mierla authored on 16/10/2017 08:54:44
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,150 @@
1
+/**
2
+ *
3
+ * Copyright (C) 2017 Daniel-Constantin Mierla (asipto.com)
4
+ *
5
+ * This file is part of Kamailio, a free SIP server.
6
+ *
7
+ * This file is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version
11
+ *
12
+ *
13
+ * This file is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
+ *
22
+ */
23
+
24
+#include <stdio.h>
25
+#include <unistd.h>
26
+#include <stdlib.h>
27
+#include <string.h>
28
+
29
+#include "../../core/sr_module.h"
30
+#include "../../core/dprint.h"
31
+#include "../../core/ut.h"
32
+#include "../../core/pvar.h"
33
+#include "../../core/kemi.h"
34
+#include "../../core/mod_fix.h"
35
+
36
+#include "phonenum_pv.h"
37
+
38
+MODULE_VERSION
39
+
40
+static int phonenum_smode = 0;
41
+
42
+static int  mod_init(void);
43
+static void mod_destroy(void);
44
+
45
+static int w_phonenum_match(struct sip_msg* msg, char* str1, char* str2);
46
+static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass);
47
+
48
+static pv_export_t mod_pvs[] = {
49
+	{ {"phn", sizeof("phn")-1}, PVT_OTHER, pv_get_phonenum, 0,
50
+		pv_parse_phonenum_name, 0, 0, 0 },
51
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
52
+};
53
+
54
+
55
+static cmd_export_t cmds[]={
56
+	{"phonenum_match", (cmd_function)w_phonenum_match, 2, fixup_spve_spve,
57
+		0, ANY_ROUTE},
58
+	{0, 0, 0, 0, 0, 0}
59
+};
60
+
61
+static param_export_t params[]={
62
+	{"smode", PARAM_INT, &phonenum_smode},
63
+	{0, 0, 0}
64
+};
65
+
66
+struct module_exports exports = {
67
+	"phonenum",
68
+	DEFAULT_DLFLAGS, /* dlopen flags */
69
+	cmds,
70
+	params,
71
+	0,
72
+	0,              /* exported MI functions */
73
+	mod_pvs,        /* exported pseudo-variables */
74
+	0,              /* extra processes */
75
+	mod_init,       /* module initialization function */
76
+	0,              /* response function */
77
+	mod_destroy,    /* destroy function */
78
+	0               /* per child init function */
79
+};
80
+
81
+
82
+/**
83
+ * init module function
84
+ */
85
+static int mod_init(void)
86
+{
87
+
88
+	if(phonenum_init_pv(phonenum_smode)!=0)
89
+	{
90
+		LM_ERR("cannot do init\n");
91
+		return -1;
92
+	}
93
+	return 0;
94
+}
95
+
96
+/**
97
+ * destroy module function
98
+ */
99
+static void mod_destroy(void)
100
+{
101
+	phonenum_destroy_pv();
102
+}
103
+
104
+
105
+static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass)
106
+{
107
+	phonenum_pv_reset(pvclass);
108
+
109
+	return phonenum_update_pv(tomatch, pvclass);
110
+}
111
+
112
+static int w_phonenum_match(sip_msg_t* msg, char* target, char* pvname)
113
+{
114
+	str tomatch = STR_NULL;
115
+	str pvclass = STR_NULL;
116
+
117
+	if(msg==NULL) {
118
+		LM_ERR("received null msg\n");
119
+		return -1;
120
+	}
121
+
122
+	if(fixup_get_svalue(msg, (gparam_t*)target, &tomatch)<0) {
123
+		LM_ERR("cannot get the address\n");
124
+		return -1;
125
+	}
126
+	if(fixup_get_svalue(msg, (gparam_t*)pvname, &pvclass)<0) {
127
+		LM_ERR("cannot get the pv class\n");
128
+		return -1;
129
+	}
130
+
131
+	return phonenum_match(msg, &tomatch, &pvclass);
132
+}
133
+
134
+/**
135
+ *
136
+ */
137
+static sr_kemi_t sr_kemi_phonenum_exports[] = {
138
+    { str_init("phonenum"), str_init("match"),
139
+        SR_KEMIP_INT, phonenum_match,
140
+        { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
141
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
142
+    },
143
+
144
+    { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
145
+};
146
+
147
+int mod_register(char *path, int *dlflags, void *p1, void *p2) {
148
+    sr_kemi_modules_add(sr_kemi_phonenum_exports);
149
+    return 0;
150
+}