00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "../../ut.h"
00033 #include "../../sr_module.h"
00034 #include "h350_mod.h"
00035 #include "h350_exp_fn.h"
00036
00037
00038 MODULE_VERSION
00039
00040
00041
00042
00043 static int mod_init(void);
00044 static int child_init(int rank);
00045
00046
00047
00048
00049 static int one_str_pv_elem_fixup(void** param, int param_no);
00050 static int h350_auth_lookup_fixup(void** param, int param_no);
00051
00052
00053
00054
00055
00056 static int w_h350_sipuri_lookup(struct sip_msg* msg, char* sip_uri, char* s2);
00057 static int w_h350_auth_lookup(struct sip_msg* msg, char* digest_username, char* avp_specs);
00058 static int w_h350_call_preferences(struct sip_msg* msg, char* avp_name_prefix, char* s2);
00059 static int w_h350_service_level(struct sip_msg* msg, char* avp_name_prefix, char* s2);
00060
00061
00062
00063
00064 str h350_ldap_session = str_init(H350_LDAP_SESSION);
00065 str h350_base_dn = str_init(H350_BASE_DN);
00066 str h350_search_scope = str_init(H350_SEARCH_SCOPE);
00067 int h350_search_scope_int = -1;
00068
00069
00070
00071
00072
00073 ldap_api_t ldap_api;
00074
00075
00076
00077
00078 static cmd_export_t cmds[] = {
00079 {"h350_sipuri_lookup", (cmd_function)w_h350_sipuri_lookup, 1,
00080 one_str_pv_elem_fixup, 0,
00081 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00082 {"h350_auth_lookup", (cmd_function)w_h350_auth_lookup, 2,
00083 h350_auth_lookup_fixup, 0,
00084 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00085 {"h350_result_call_preferences", (cmd_function)w_h350_call_preferences, 1,
00086 one_str_pv_elem_fixup, 0,
00087 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00088 {"h350_result_service_level", (cmd_function)w_h350_service_level, 1,
00089 one_str_pv_elem_fixup, 0,
00090 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
00091 {0, 0, 0, 0, 0, 0}
00092 };
00093
00094
00095
00096
00097
00098 static param_export_t params[] = {
00099 {"ldap_session", STR_PARAM, &h350_ldap_session.s},
00100 {"base_dn", STR_PARAM, &h350_base_dn.s},
00101 {"search_scope", STR_PARAM, &h350_search_scope.s},
00102 {0, 0, 0}
00103 };
00104
00105
00106
00107
00108
00109 struct module_exports exports = {
00110 "h350",
00111 DEFAULT_DLFLAGS,
00112 cmds,
00113 params,
00114 0,
00115 0,
00116 0,
00117 0,
00118 mod_init,
00119 0,
00120 0,
00121 child_init
00122 };
00123
00124 static int child_init(int rank)
00125 {
00126
00127
00128 if (rank < 1) {
00129 return 0;
00130 }
00131
00132 h350_search_scope_int = ldap_api.ldap_str2scope(h350_search_scope.s);
00133
00134
00135
00136
00137 if (h350_exp_fn_init() != 0)
00138 {
00139 LM_ERR("h350_exp_fn_init failed\n");
00140 return -1;
00141 }
00142
00143
00144 return 0;
00145 }
00146
00147
00148 static int mod_init(void)
00149 {
00150
00151
00152
00153 if (load_ldap_api(&ldap_api) != 0)
00154 {
00155 LM_ERR("Unable to load LDAP API - this module requires ldap module\n");
00156 return -1;
00157 }
00158
00159 return 0;
00160
00161
00162
00163
00164 if (ldap_api.ldap_str2scope(h350_search_scope.s) == -1)
00165 {
00166 LM_ERR("Invalid search_scope [%s]\n", h350_search_scope.s);
00167 return -1;
00168 }
00169
00170 }
00171
00172
00173
00174
00175
00176 static int w_h350_sipuri_lookup(struct sip_msg* msg, char* sip_uri, char* s2)
00177 {
00178 return h350_sipuri_lookup(msg, (pv_elem_t*)sip_uri);
00179 }
00180
00181 static int w_h350_auth_lookup(struct sip_msg* msg, char* digest_username, char* avp_specs)
00182 {
00183 return h350_auth_lookup(
00184 msg,
00185 (pv_elem_t*)digest_username,
00186 (struct h350_auth_lookup_avp_params*)avp_specs);
00187 }
00188
00189 static int w_h350_call_preferences(struct sip_msg* msg, char* avp_name_prefix, char* s2)
00190 {
00191 return h350_call_preferences(msg, (pv_elem_t*)avp_name_prefix);
00192 }
00193
00194 static int w_h350_service_level(struct sip_msg* msg, char* avp_name_prefix, char* s2)
00195 {
00196 return h350_service_level(msg, (pv_elem_t*)avp_name_prefix);
00197 }
00198
00199
00200
00201
00202
00203 static int one_str_pv_elem_fixup(void** param, int param_no)
00204 {
00205 pv_elem_t *model;
00206 str s;
00207
00208 if (param_no == 1) {
00209 s.s = (char*)*param;
00210 if (s.s==0 || s.s[0]==0) {
00211 model = 0;
00212 } else {
00213 s.len = strlen(s.s);
00214 if (pv_parse_format(&s,&model)<0) {
00215 LM_ERR("pv_parse_format failed\n");
00216 return E_OUT_OF_MEM;
00217 }
00218 }
00219 *param = (void*)model;
00220 }
00221
00222 return 0;
00223 }
00224
00225 static int h350_auth_lookup_fixup(void** param, int param_no)
00226 {
00227 pv_elem_t *model;
00228 char *p, *username_avp_spec_str, *pwd_avp_spec_str;
00229 str s;
00230 struct h350_auth_lookup_avp_params *params;
00231
00232 if (param_no == 1)
00233 {
00234 s.s = (char*)*param;
00235 if (s.s==0 || s.s[0]==0) {
00236 model = 0;
00237 } else {
00238 if (pv_parse_format(&s,&model)<0) {
00239 LM_ERR("pv_parse_format failed\n");
00240 return E_OUT_OF_MEM;
00241 }
00242 }
00243 *param = (void*)model;
00244 } else if (param_no == 2) {
00245
00246
00247
00248
00249 username_avp_spec_str = (char*)*param;
00250 if ((pwd_avp_spec_str = strchr(username_avp_spec_str, '/')) == 0)
00251 {
00252
00253 LM_ERR("invalid second argument [%s]\n", username_avp_spec_str);
00254 return E_UNSPEC;
00255 }
00256 *(pwd_avp_spec_str++) = 0;
00257
00258
00259
00260
00261 params = (struct h350_auth_lookup_avp_params*)pkg_malloc
00262 (sizeof(struct h350_auth_lookup_avp_params));
00263 if (params == NULL)
00264 {
00265 LM_ERR("no memory\n");
00266 return E_OUT_OF_MEM;
00267 }
00268 memset(params, 0, sizeof(struct h350_auth_lookup_avp_params));
00269 s.s = username_avp_spec_str; s.len = strlen(s.s);
00270 p = pv_parse_spec(&s, ¶ms->username_avp_spec);
00271 if (p == 0)
00272 {
00273 pkg_free(params);
00274 LM_ERR("parse error for [%s]\n", username_avp_spec_str);
00275 return E_UNSPEC;
00276 }
00277 if (params->username_avp_spec.type != PVT_AVP)
00278 {
00279 pkg_free(params);
00280 LM_ERR("invalid AVP specification [%s]\n", username_avp_spec_str);
00281 return E_UNSPEC;
00282 }
00283 s.s = pwd_avp_spec_str; s.len = strlen(s.s);
00284 p = pv_parse_spec(&s, ¶ms->password_avp_spec);
00285 if (p == 0)
00286 {
00287 pkg_free(params);
00288 LM_ERR("parse error for [%s]\n", pwd_avp_spec_str);
00289 return E_UNSPEC;
00290 }
00291 if (params->password_avp_spec.type != PVT_AVP)
00292 {
00293 pkg_free(params);
00294 LM_ERR("invalid AVP specification [%s]\n", pwd_avp_spec_str);
00295 return E_UNSPEC;
00296 }
00297
00298 *param = (void*)params;
00299 }
00300
00301 return 0;
00302 }