2 * Kamailio H.350 Module
4 * Copyright (C) 2007 University of North Carolina
6 * Original author: Christian Schlatter, cs@unc.edu
9 * This file is part of Kamailio, a free SIP server.
11 * Kamailio is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version
16 * Kamailio is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "../../core/ut.h"
28 #include "../../core/sr_module.h"
30 #include "h350_exp_fn.h"
36 * Module management function prototypes
38 static int mod_init(void);
39 static int child_init(int rank);
44 static int one_str_pv_elem_fixup(void** param, int param_no);
45 static int h350_auth_lookup_fixup(void** param, int param_no);
51 static int w_h350_sipuri_lookup(struct sip_msg* msg, char* sip_uri, char* s2);
52 static int w_h350_auth_lookup(struct sip_msg* msg, char* digest_username, char* avp_specs);
53 static int w_h350_call_preferences(struct sip_msg* msg, char* avp_name_prefix, char* s2);
54 static int w_h350_service_level(struct sip_msg* msg, char* avp_name_prefix, char* s2);
57 * Module parameter variables
59 char* h350_ldap_session = H350_LDAP_SESSION;
60 char* h350_base_dn = H350_BASE_DN;
61 char* h350_search_scope = H350_SEARCH_SCOPE;
62 int h350_search_scope_int = -1;
73 static cmd_export_t cmds[] = {
74 {"h350_sipuri_lookup", (cmd_function)w_h350_sipuri_lookup, 1,
75 one_str_pv_elem_fixup, 0,
76 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
77 {"h350_auth_lookup", (cmd_function)w_h350_auth_lookup, 2,
78 h350_auth_lookup_fixup, 0,
79 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
80 {"h350_result_call_preferences", (cmd_function)w_h350_call_preferences, 1,
81 one_str_pv_elem_fixup, 0,
82 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
83 {"h350_result_service_level", (cmd_function)w_h350_service_level, 1,
84 one_str_pv_elem_fixup, 0,
85 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
93 static param_export_t params[] = {
94 {"ldap_session", PARAM_STRING, &h350_ldap_session},
95 {"base_dn", PARAM_STRING, &h350_base_dn},
96 {"search_scope", PARAM_STRING, &h350_search_scope},
104 struct module_exports exports = {
106 DEFAULT_DLFLAGS, /* dlopen flags */
107 cmds, /* Exported functions */
108 params, /* Exported parameters */
109 0, /* exported statistics */
110 0, /* exported MI functions */
111 0, /* exported pseudo-variables */
112 0, /* extra processes */
113 mod_init, /* module initialization function */
114 0, /* response function */
115 0, /* destroy function */
116 child_init /* child initialization function */
119 static int child_init(int rank)
122 /* don't do anything for non-worker process */
127 h350_search_scope_int = ldap_api.ldap_str2scope(h350_search_scope);
130 * initialize h350_exp_fn
132 if(h350_exp_fn_init() != 0) {
133 LM_ERR("h350_exp_fn_init failed\n");
142 static int mod_init(void)
147 if(load_ldap_api(&ldap_api) != 0) {
148 LM_ERR("Unable to load LDAP API - this module requires ldap module\n");
159 static int w_h350_sipuri_lookup(struct sip_msg *msg, char *sip_uri, char *s2)
161 return h350_sipuri_lookup(msg, (pv_elem_t *)sip_uri);
164 static int w_h350_auth_lookup(
165 struct sip_msg *msg, char *digest_username, char *avp_specs)
167 return h350_auth_lookup(msg, (pv_elem_t *)digest_username,
168 (struct h350_auth_lookup_avp_params *)avp_specs);
171 static int w_h350_call_preferences(
172 struct sip_msg *msg, char *avp_name_prefix, char *s2)
174 return h350_call_preferences(msg, (pv_elem_t *)avp_name_prefix);
177 static int w_h350_service_level(
178 struct sip_msg *msg, char *avp_name_prefix, char *s2)
180 return h350_service_level(msg, (pv_elem_t *)avp_name_prefix);
187 static int one_str_pv_elem_fixup(void **param, int param_no)
193 s.s = (char *)*param;
194 if(s.s == 0 || s.s[0] == 0) {
198 if(pv_parse_format(&s, &model) < 0) {
199 LM_ERR("pv_parse_format failed\n");
203 *param = (void *)model;
209 static int h350_auth_lookup_fixup(void **param, int param_no)
212 char *p, *username_avp_spec_str, *pwd_avp_spec_str;
214 struct h350_auth_lookup_avp_params *params;
217 s.s = (char *)*param;
218 if(s.s == 0 || s.s[0] == 0) {
222 if(pv_parse_format(&s, &model) < 0) {
223 LM_ERR("pv_parse_format failed\n");
227 *param = (void *)model;
228 } else if(param_no == 2) {
230 * parse *param into username_avp_spec_str and pwd_avp_spec_str
233 username_avp_spec_str = (char *)*param;
234 if((pwd_avp_spec_str = strchr(username_avp_spec_str, '/')) == 0) {
235 /* no '/' found in username_avp_spec_str */
236 LM_ERR("invalid second argument [%s]\n", username_avp_spec_str);
239 *(pwd_avp_spec_str++) = 0;
242 * parse avp specs into pv_spec_t and store in params
244 params = (struct h350_auth_lookup_avp_params *)pkg_malloc(
245 sizeof(struct h350_auth_lookup_avp_params));
247 LM_ERR("no memory\n");
250 memset(params, 0, sizeof(struct h350_auth_lookup_avp_params));
251 s.s = username_avp_spec_str;
253 p = pv_parse_spec(&s, ¶ms->username_avp_spec);
256 LM_ERR("parse error for [%s]\n", username_avp_spec_str);
259 if(params->username_avp_spec.type != PVT_AVP) {
261 LM_ERR("invalid AVP specification [%s]\n", username_avp_spec_str);
264 s.s = pwd_avp_spec_str;
266 p = pv_parse_spec(&s, ¶ms->password_avp_spec);
269 LM_ERR("parse error for [%s]\n", pwd_avp_spec_str);
272 if(params->password_avp_spec.type != PVT_AVP) {
274 LM_ERR("invalid AVP specification [%s]\n", pwd_avp_spec_str);
278 *param = (void *)params;