-
Notifications
You must be signed in to change notification settings - Fork 909
/
h350_mod.c
284 lines (245 loc) · 6.9 KB
/
h350_mod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
* Kamailio H.350 Module
*
* Copyright (C) 2007 University of North Carolina
*
* Original author: Christian Schlatter, cs@unc.edu
*
*
* 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 "../../core/ut.h"
#include "../../core/sr_module.h"
#include "h350_mod.h"
#include "h350_exp_fn.h"
MODULE_VERSION
/*
* Module management function prototypes
*/
static int mod_init(void);
static int child_init(int rank);
/*
* fixup functions
*/
static int one_str_pv_elem_fixup(void **param, int param_no);
static int h350_auth_lookup_fixup(void **param, int param_no);
/*
* exported functions
*/
static int w_h350_sipuri_lookup(struct sip_msg *msg, char *sip_uri, char *s2);
static int w_h350_auth_lookup(
struct sip_msg *msg, char *digest_username, char *avp_specs);
static int w_h350_call_preferences(
struct sip_msg *msg, char *avp_name_prefix, char *s2);
static int w_h350_service_level(
struct sip_msg *msg, char *avp_name_prefix, char *s2);
/*
* Module parameter variables
*/
char *h350_ldap_session = H350_LDAP_SESSION;
char *h350_base_dn = H350_BASE_DN;
char *h350_search_scope = H350_SEARCH_SCOPE;
int h350_search_scope_int = -1;
/*
* LDAP API
*/
ldap_api_t ldap_api;
/*
* Exported functions
*/
static cmd_export_t cmds[] = {
{"h350_sipuri_lookup", (cmd_function)w_h350_sipuri_lookup, 1,
one_str_pv_elem_fixup, 0,
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE
| LOCAL_ROUTE},
{"h350_auth_lookup", (cmd_function)w_h350_auth_lookup, 2,
h350_auth_lookup_fixup, 0,
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE
| LOCAL_ROUTE},
{"h350_result_call_preferences", (cmd_function)w_h350_call_preferences,
1, one_str_pv_elem_fixup, 0,
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE
| LOCAL_ROUTE},
{"h350_result_service_level", (cmd_function)w_h350_service_level, 1,
one_str_pv_elem_fixup, 0,
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE
| LOCAL_ROUTE},
{0, 0, 0, 0, 0, 0}};
/*
* Exported parameters
*/
static param_export_t params[] = {
{"ldap_session", PARAM_STRING, &h350_ldap_session},
{"base_dn", PARAM_STRING, &h350_base_dn},
{"search_scope", PARAM_STRING, &h350_search_scope}, {0, 0, 0}};
/*
* Module interface
*/
struct module_exports exports = {
"h350", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* cmd (cfg function) exports */
params, /* Exported parameters */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response function */
mod_init, /* module initialization function */
child_init, /* child initialization function */
0 /* destroy function */
};
static int child_init(int rank)
{
/* don't do anything for non-worker process */
if(rank < 1) {
return 0;
}
h350_search_scope_int = ldap_api.ldap_str2scope(h350_search_scope);
/*
* initialize h350_exp_fn
*/
if(h350_exp_fn_init() != 0) {
LM_ERR("h350_exp_fn_init failed\n");
return -1;
}
return 0;
}
static int mod_init(void)
{
/*
* load the LDAP API
*/
if(load_ldap_api(&ldap_api) != 0) {
LM_ERR("Unable to load LDAP API - this module requires ldap module\n");
return -1;
}
return 0;
}
/*
* EXPORTED functions
*/
static int w_h350_sipuri_lookup(struct sip_msg *msg, char *sip_uri, char *s2)
{
return h350_sipuri_lookup(msg, (pv_elem_t *)sip_uri);
}
static int w_h350_auth_lookup(
struct sip_msg *msg, char *digest_username, char *avp_specs)
{
return h350_auth_lookup(msg, (pv_elem_t *)digest_username,
(struct h350_auth_lookup_avp_params *)avp_specs);
}
static int w_h350_call_preferences(
struct sip_msg *msg, char *avp_name_prefix, char *s2)
{
return h350_call_preferences(msg, (pv_elem_t *)avp_name_prefix);
}
static int w_h350_service_level(
struct sip_msg *msg, char *avp_name_prefix, char *s2)
{
return h350_service_level(msg, (pv_elem_t *)avp_name_prefix);
}
/*
* FIXUP functions
*/
static int one_str_pv_elem_fixup(void **param, int param_no)
{
pv_elem_t *model;
str s;
if(param_no == 1) {
s.s = (char *)*param;
if(s.s == 0 || s.s[0] == 0) {
model = 0;
} else {
s.len = strlen(s.s);
if(pv_parse_format(&s, &model) < 0) {
LM_ERR("pv_parse_format failed\n");
return E_OUT_OF_MEM;
}
}
*param = (void *)model;
}
return 0;
}
static int h350_auth_lookup_fixup(void **param, int param_no)
{
pv_elem_t *model;
char *p, *username_avp_spec_str, *pwd_avp_spec_str;
str s;
struct h350_auth_lookup_avp_params *params;
if(param_no == 1) {
s.s = (char *)*param;
if(s.s == 0 || s.s[0] == 0) {
model = 0;
} else {
s.len = strlen(s.s);
if(pv_parse_format(&s, &model) < 0) {
LM_ERR("pv_parse_format failed\n");
return E_OUT_OF_MEM;
}
}
*param = (void *)model;
} else if(param_no == 2) {
/*
* parse *param into username_avp_spec_str and pwd_avp_spec_str
*/
username_avp_spec_str = (char *)*param;
if((pwd_avp_spec_str = strchr(username_avp_spec_str, '/')) == 0) {
/* no '/' found in username_avp_spec_str */
LM_ERR("invalid second argument [%s]\n", username_avp_spec_str);
return E_UNSPEC;
}
*(pwd_avp_spec_str++) = 0;
/*
* parse avp specs into pv_spec_t and store in params
*/
params = (struct h350_auth_lookup_avp_params *)pkg_malloc(
sizeof(struct h350_auth_lookup_avp_params));
if(params == NULL) {
LM_ERR("no memory\n");
return E_OUT_OF_MEM;
}
memset(params, 0, sizeof(struct h350_auth_lookup_avp_params));
s.s = username_avp_spec_str;
s.len = strlen(s.s);
p = pv_parse_spec(&s, ¶ms->username_avp_spec);
if(p == 0) {
pkg_free(params);
LM_ERR("parse error for [%s]\n", username_avp_spec_str);
return E_UNSPEC;
}
if(params->username_avp_spec.type != PVT_AVP) {
pkg_free(params);
LM_ERR("invalid AVP specification [%s]\n", username_avp_spec_str);
return E_UNSPEC;
}
s.s = pwd_avp_spec_str;
s.len = strlen(s.s);
p = pv_parse_spec(&s, ¶ms->password_avp_spec);
if(p == 0) {
pkg_free(params);
LM_ERR("parse error for [%s]\n", pwd_avp_spec_str);
return E_UNSPEC;
}
if(params->password_avp_spec.type != PVT_AVP) {
pkg_free(params);
LM_ERR("invalid AVP specification [%s]\n", pwd_avp_spec_str);
return E_UNSPEC;
}
*param = (void *)params;
}
return 0;
}