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
00033
00034
00035 #include <osp/osp.h>
00036 #include "../rr/api.h"
00037 #include "../auth/api.h"
00038 #include "osp_mod.h"
00039 #include "orig_transaction.h"
00040 #include "term_transaction.h"
00041 #include "usage.h"
00042 #include "tm.h"
00043 #include "provider.h"
00044
00045 MODULE_VERSION
00046
00047 extern unsigned int _osp_sp_number;
00048 extern char* _osp_sp_uris[];
00049 extern unsigned long _osp_sp_weights[];
00050 extern char* _osp_device_ip;
00051 extern char* _osp_device_port;
00052 extern unsigned char* _osp_private_key;
00053 extern unsigned char* _osp_local_certificate;
00054 extern unsigned char* _osp_ca_certificate;
00055 extern int _osp_crypto_hw;
00056 extern int _osp_validate_callid;
00057 extern int _osp_token_format;
00058 extern int _osp_ssl_lifetime;
00059 extern int _osp_persistence;
00060 extern int _osp_retry_delay;
00061 extern int _osp_retry_limit;
00062 extern int _osp_timeout;
00063 extern int _osp_max_dests;
00064 extern int _osp_use_rpid;
00065 extern int _osp_redir_uri;
00066 extern char _osp_PRIVATE_KEY[];
00067 extern char _osp_LOCAL_CERTIFICATE[];
00068 extern char _osp_CA_CERTIFICATE[];
00069 extern char* _osp_snid_avp;
00070 extern int_str _osp_snid_avpname;
00071 extern unsigned short _osp_snid_avptype;
00072 extern OSPTPROVHANDLE _osp_provider;
00073
00074 struct rr_binds osp_rr;
00075 auth_api_t osp_auth;
00076 int osp_index[OSP_DEF_SPS];
00077
00078 static int ospInitMod(void);
00079 static void ospDestMod(void);
00080 static int ospInitChild(int);
00081 static int ospVerifyParameters(void);
00082 static void ospDumpParameters(void);
00083
00084 static cmd_export_t cmds[]={
00085 {"checkospheader", (cmd_function)ospCheckHeader, 0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
00086 {"validateospheader", (cmd_function)ospValidateHeader, 0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
00087 {"requestosprouting", (cmd_function)ospRequestRouting, 0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
00088 {"checkosproute", (cmd_function)ospCheckRoute, 0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
00089 {"prepareosproute", (cmd_function)ospPrepareRoute, 0, 0, 0, BRANCH_ROUTE},
00090 {"prepareallosproutes", (cmd_function)ospPrepareAllRoutes, 0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
00091 {"checkcallingtranslation", (cmd_function)ospCheckTranslation, 0, 0, 0, BRANCH_ROUTE},
00092 {"reportospusage", (cmd_function)ospReportUsage, 1, 0, 0, REQUEST_ROUTE},
00093 {0, 0, 0, 0, 0, 0}
00094 };
00095
00096 static param_export_t params[]={
00097 {"sp1_uri", STR_PARAM, &_osp_sp_uris[0]},
00098 {"sp2_uri", STR_PARAM, &_osp_sp_uris[1]},
00099 {"sp3_uri", STR_PARAM, &_osp_sp_uris[2]},
00100 {"sp4_uri", STR_PARAM, &_osp_sp_uris[3]},
00101 {"sp5_uri", STR_PARAM, &_osp_sp_uris[4]},
00102 {"sp6_uri", STR_PARAM, &_osp_sp_uris[5]},
00103 {"sp7_uri", STR_PARAM, &_osp_sp_uris[6]},
00104 {"sp8_uri", STR_PARAM, &_osp_sp_uris[7]},
00105 {"sp9_uri", STR_PARAM, &_osp_sp_uris[8]},
00106 {"sp10_uri", STR_PARAM, &_osp_sp_uris[9]},
00107 {"sp11_uri", STR_PARAM, &_osp_sp_uris[10]},
00108 {"sp12_uri", STR_PARAM, &_osp_sp_uris[11]},
00109 {"sp13_uri", STR_PARAM, &_osp_sp_uris[12]},
00110 {"sp14_uri", STR_PARAM, &_osp_sp_uris[13]},
00111 {"sp15_uri", STR_PARAM, &_osp_sp_uris[14]},
00112 {"sp16_uri", STR_PARAM, &_osp_sp_uris[15]},
00113 {"sp1_weight", INT_PARAM, &(_osp_sp_weights[0])},
00114 {"sp2_weight", INT_PARAM, &(_osp_sp_weights[1])},
00115 {"sp3_weight", INT_PARAM, &(_osp_sp_weights[2])},
00116 {"sp4_weight", INT_PARAM, &(_osp_sp_weights[3])},
00117 {"sp5_weight", INT_PARAM, &(_osp_sp_weights[4])},
00118 {"sp6_weight", INT_PARAM, &(_osp_sp_weights[5])},
00119 {"sp7_weight", INT_PARAM, &(_osp_sp_weights[6])},
00120 {"sp8_weight", INT_PARAM, &(_osp_sp_weights[7])},
00121 {"sp9_weight", INT_PARAM, &(_osp_sp_weights[8])},
00122 {"sp10_weight", INT_PARAM, &(_osp_sp_weights[9])},
00123 {"sp11_weight", INT_PARAM, &(_osp_sp_weights[10])},
00124 {"sp12_weight", INT_PARAM, &(_osp_sp_weights[11])},
00125 {"sp13_weight", INT_PARAM, &(_osp_sp_weights[12])},
00126 {"sp14_weight", INT_PARAM, &(_osp_sp_weights[13])},
00127 {"sp15_weight", INT_PARAM, &(_osp_sp_weights[14])},
00128 {"sp16_weight", INT_PARAM, &(_osp_sp_weights[15])},
00129 {"device_ip", STR_PARAM, &_osp_device_ip},
00130 {"device_port", STR_PARAM, &_osp_device_port},
00131 {"private_key", STR_PARAM, &_osp_private_key},
00132 {"local_certificate", STR_PARAM, &_osp_local_certificate},
00133 {"ca_certificates", STR_PARAM, &_osp_ca_certificate},
00134 {"enable_crypto_hardware_support", INT_PARAM, &_osp_crypto_hw},
00135 {"validate_callid", INT_PARAM, &(_osp_validate_callid)},
00136 {"token_format", INT_PARAM, &_osp_token_format},
00137 {"ssl_lifetime", INT_PARAM, &_osp_ssl_lifetime},
00138 {"persistence", INT_PARAM, &_osp_persistence},
00139 {"retry_delay", INT_PARAM, &_osp_retry_delay},
00140 {"retry_limit", INT_PARAM, &_osp_retry_limit},
00141 {"timeout", INT_PARAM, &_osp_timeout},
00142 {"max_destinations", INT_PARAM, &_osp_max_dests},
00143 {"use_rpid_for_calling_number", INT_PARAM, &_osp_use_rpid},
00144 {"redirection_uri_format", INT_PARAM, &_osp_redir_uri},
00145 {"source_networkid_avp", STR_PARAM, &_osp_snid_avp},
00146 {0,0,0}
00147 };
00148
00149 struct module_exports exports = {
00150 "osp",
00151 DEFAULT_DLFLAGS,
00152 cmds,
00153 params,
00154 0,
00155 0,
00156 0,
00157 0,
00158 ospInitMod,
00159 0,
00160 ospDestMod,
00161 ospInitChild,
00162 };
00163
00164
00165
00166
00167
00168 static int ospInitMod(void)
00169 {
00170 bind_auth_t bind_auth;
00171
00172 if (ospVerifyParameters() != 0) {
00173
00174 return -1;
00175 }
00176
00177
00178 if (load_rr_api(&osp_rr) != 0) {
00179 LM_WARN("failed to load the RR API. Check if you load the rr module\n");
00180 LM_WARN("add_rr_param is required for reporting duration for OSP transactions\n");
00181 memset(&osp_rr, 0, sizeof(osp_rr));
00182 }
00183
00184
00185 bind_auth = (bind_auth_t)find_export("bind_auth", 0, 0);
00186 if ((bind_auth == NULL) || (bind_auth(&osp_auth) != 0)) {
00187 LM_WARN("failed to load the AUTH API. Check if you load the auth module.\n");
00188 LM_WARN("rpid_avp & rpid_avp_type is required for calling number translation\n");
00189 memset(&osp_auth, 0, sizeof(osp_auth));
00190 }
00191
00192 if (ospInitTm() < 0) {
00193 return -1;
00194 }
00195
00196
00197 return 0;
00198 }
00199
00200
00201
00202
00203 static void ospDestMod(void)
00204 {
00205 }
00206
00207
00208
00209
00210
00211
00212 static int ospInitChild(
00213 int rank)
00214 {
00215 int code = -1;
00216
00217 code = ospSetupProvider();
00218
00219 LM_DBG("provider '%d' (%d)\n", _osp_provider, code);
00220
00221 return 0;
00222 }
00223
00224
00225
00226
00227
00228 static int ospVerifyParameters(void)
00229 {
00230 int i;
00231 pv_spec_t avp_spec;
00232 str avp_str;
00233 int result = 0;
00234
00235
00236 if (_osp_private_key == NULL) {
00237 sprintf(_osp_PRIVATE_KEY, "%spkey.pem", CFG_DIR);
00238 _osp_private_key = (unsigned char*)_osp_PRIVATE_KEY;
00239 }
00240
00241 if (_osp_local_certificate == NULL) {
00242 sprintf(_osp_LOCAL_CERTIFICATE, "%slocalcert.pem", CFG_DIR);
00243 _osp_local_certificate = (unsigned char*)_osp_LOCAL_CERTIFICATE;
00244 }
00245
00246 if (_osp_ca_certificate == NULL) {
00247 sprintf(_osp_CA_CERTIFICATE, "%scacert_0.pem", CFG_DIR);
00248 _osp_ca_certificate = (unsigned char*)_osp_CA_CERTIFICATE;
00249 }
00250
00251 if (_osp_device_ip == NULL) {
00252 _osp_device_ip = "";
00253 }
00254
00255 if (_osp_device_port == NULL) {
00256 _osp_device_port = "";
00257 }
00258
00259 if (_osp_max_dests > OSP_DEF_DESTS || _osp_max_dests < 1) {
00260 _osp_max_dests = OSP_DEF_DESTS;
00261 LM_WARN("max_destinations is out of range, reset to %d\n", OSP_DEF_DESTS);
00262 }
00263
00264 if (_osp_token_format < 0 || _osp_token_format > 2) {
00265 _osp_token_format = OSP_DEF_TOKEN;
00266 LM_WARN("token_format is out of range, reset to %d\n", OSP_DEF_TOKEN);
00267 }
00268
00269 _osp_sp_number = 0;
00270 for (i = 0; i < OSP_DEF_SPS; i++) {
00271 if (_osp_sp_uris[i] != NULL) {
00272 if (_osp_sp_number != i) {
00273 _osp_sp_uris[_osp_sp_number] = _osp_sp_uris[i];
00274 _osp_sp_weights[_osp_sp_number] = _osp_sp_weights[i];
00275 _osp_sp_uris[i] = NULL;
00276 _osp_sp_weights[i] = OSP_DEF_WEIGHT;
00277 }
00278 osp_index[_osp_sp_number] = i + 1;
00279 _osp_sp_number++;
00280 }
00281 }
00282
00283 if (_osp_sp_number == 0) {
00284 LM_ERR("at least one service point uri must be configured\n");
00285 result = -1;
00286 }
00287
00288 if (_osp_snid_avp && *_osp_snid_avp) {
00289 avp_str.s = _osp_snid_avp;
00290 avp_str.len = strlen(_osp_snid_avp);
00291 if (pv_parse_spec(&avp_str, &avp_spec) == NULL ||
00292 avp_spec.type != PVT_AVP ||
00293 pv_get_avp_name(0, &(avp_spec.pvp), &_osp_snid_avpname, &_osp_snid_avptype) != 0)
00294 {
00295 LM_WARN("'%s' invalid AVP definition\n", _osp_snid_avp);
00296 _osp_snid_avpname.n = 0;
00297 _osp_snid_avptype = 0;
00298 }
00299 } else {
00300 _osp_snid_avpname.n = 0;
00301 _osp_snid_avptype = 0;
00302 }
00303
00304 ospDumpParameters();
00305
00306 return result;
00307 }
00308
00309
00310
00311
00312 static void ospDumpParameters(void)
00313 {
00314 int i;
00315
00316 LM_INFO("module configuration: ");
00317 LM_INFO(" number of service points '%d'", _osp_sp_number);
00318 for (i = 0; i < _osp_sp_number; i++) {
00319 LM_INFO(" sp%d_uri '%s' sp%d_weight '%ld' ",
00320 osp_index[i], _osp_sp_uris[i], osp_index[i], _osp_sp_weights[i]);
00321 }
00322 LM_INFO(" device_ip '%s' device_port '%s' ", _osp_device_ip, _osp_device_port);
00323 LM_INFO(" private_key '%s' ", _osp_private_key);
00324 LM_INFO(" local_certificate '%s' ", _osp_local_certificate);
00325 LM_INFO(" ca_certificates '%s' ", _osp_ca_certificate);
00326 LM_INFO(" enable_crypto_hardware_support '%d' ", _osp_crypto_hw);
00327 LM_INFO(" token_format '%d' ", _osp_token_format);
00328 LM_INFO(" ssl_lifetime '%d' ", _osp_ssl_lifetime);
00329 LM_INFO(" persistence '%d' ", _osp_persistence);
00330 LM_INFO(" retry_delay '%d' ", _osp_retry_delay);
00331 LM_INFO(" retry_limit '%d' ", _osp_retry_limit);
00332 LM_INFO(" timeout '%d' ", _osp_timeout);
00333 LM_INFO(" validate_call_id '%d' ", _osp_validate_callid);
00334 LM_INFO(" use_rpid_for_calling_number '%d' ", _osp_use_rpid);
00335 LM_INFO(" redirection_uri_format '%d' ", _osp_redir_uri);
00336 LM_INFO(" max_destinations '%d'\n", _osp_max_dests);
00337 if (_osp_snid_avpname.n == 0) {
00338 LM_INFO(" source network ID disabled\n");
00339 } else if (_osp_snid_avptype & AVP_NAME_STR) {
00340 LM_INFO(" source network ID AVP name '%.*s'\n", _osp_snid_avpname.s.len, _osp_snid_avpname.s.s);
00341 } else {
00342 LM_INFO(" source network ID AVP ID '%d'\n", _osp_snid_avpname.n);
00343 }
00344 }
00345