/** * init module function */ static int mod_init(void) { LM_DBG("Loading...\n"); event_route_ccr_orig = route_get(&event_rt, "ocs:ccr-orig"); if (event_route_ccr_orig < 0) { LM_ERR("No ocs:ccr-orig event route found\n"); goto error; } LM_DBG("Found Route ocs:ccr-orig: %i\n", event_route_ccr_orig); event_route_ccr_term = route_get(&event_rt, "ocs:ccr-term"); if (event_route_ccr_term < 0) { LM_INFO("No ocs:ccr-term event route found\n"); } LM_DBG("Found Route ocs:ccr-term: %i\n", event_route_ccr_term); callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; cdp_avp = 0; /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); goto error; } cdp_avp = load_cdp_avp(); if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); goto error; } return 0; error: LM_ERR("Failed to initialise ims_ocs module\n"); return -1; }
static int mod_init(void) { pv_spec_t avp_spec; str s; bind_usrloc_t bind_usrloc; qvalue_t dq; callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; /*build the required strings */ scscf_serviceroute_uri_str.s = (char*) pkg_malloc(orig_prefix.len + scscf_name_str.len); if (!scscf_serviceroute_uri_str.s) { LM_ERR("Unable to allocate memory for service route uri\n"); return -1; } if (contact_expires_buffer_percentage < 0 || contact_expires_buffer_percentage > 90) { LM_ERR("contact expires percentage not valid, must be >0 and <=90"); return -1; } memcpy(scscf_serviceroute_uri_str.s, orig_prefix.s, orig_prefix.len); scscf_serviceroute_uri_str.len = orig_prefix.len; if (scscf_name_str.len > 4 && strncasecmp(scscf_name_str.s, "sip:", 4) == 0) { memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len, scscf_name_str.s + 4, scscf_name_str.len - 4); scscf_serviceroute_uri_str.len += scscf_name_str.len - 4; } else { memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len, scscf_name_str.s, scscf_name_str.len); scscf_serviceroute_uri_str.len += scscf_name_str.len; } pv_tmx_data_init(); /* </build required strings> */ #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } if (!register_stats()) { LM_ERR("Unable to register statistics\n"); return -1; } #endif /*register space for notification processors*/ register_procs(notification_processes); cfg_register_child(notification_processes); /* bind the SL API */ if (sl_load_api(&slb) != 0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); return -1; } cdp_avp = load_cdp_avp(); if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); return -1; } if (cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg, cfg_sizeof(registrar), ®istrar_cfg)) { LM_ERR("Fail to declare the configuration\n"); return -1; } if (rcv_avp_param && *rcv_avp_param) { s.s = rcv_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", rcv_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, &rcv_avp_name, &rcv_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", rcv_avp_param); return -1; } } else { rcv_avp_name.n = 0; rcv_avp_type = 0; } if (aor_avp_param && *aor_avp_param) { s.s = aor_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", aor_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, &aor_avp_name, &aor_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", aor_avp_param); return -1; } } else { aor_avp_name.n = 0; aor_avp_type = 0; } if (reg_callid_avp_param && *reg_callid_avp_param) { s.s = reg_callid_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", reg_callid_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, ®_callid_avp_name, ®_callid_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", reg_callid_avp_param); return -1; } } else { reg_callid_avp_name.n = 0; reg_callid_avp_type = 0; } bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } /* Normalize default_q parameter */ dq = cfg_get(registrar, registrar_cfg, default_q); if (dq != Q_UNSPECIFIED) { if (dq > MAX_Q) { LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q); dq = MAX_Q; } else if (dq < MIN_Q) { LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q); dq = MIN_Q; } } cfg_get(registrar, registrar_cfg, default_q) = dq; if (bind_usrloc(&ul) < 0) { return -1; } /*Register for callback of URECORD being deleted - so we can send a SAR*/ if (ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } if (ul.register_ulcb(0, 0, UL_IMPU_INSERT, ul_impu_inserted, 0) < 0) { LM_ERR("can not register callback for insert\n"); return -1; } if (sock_hdr_name.s) { if (sock_hdr_name.len == 0 || sock_flag == -1) { LM_WARN("empty sock_hdr_name or sock_flag no set -> reseting\n"); sock_hdr_name.len = 0; sock_flag = -1; } } else if (sock_flag != -1) { LM_WARN("sock_flag defined but no sock_hdr_name -> reseting flag\n"); sock_flag = -1; } /* fix the flags */ sock_flag = (sock_flag != -1) ? (1 << sock_flag) : 0; tcp_persistent_flag = (tcp_persistent_flag != -1) ? (1 << tcp_persistent_flag) : 0; /* init the registrar notifications */ if (!notify_init()) return -1; /* register the registrar notifications timer */ //Currently we do not use this - we send notifies immediately //if (register_timer(notification_timer, notification_list, 5) < 0) return -1; return 0; }
static int mod_init(void) { registration_default_algorithm_type = get_algorithm_type(registration_default_algorithm); #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } if (!register_stats()){ LM_ERR("Unable to register statistics\n"); return -1; } #endif /* check the max_nonce_reuse param */ if (auth_used_vector_timeout < 0) { LM_WARN("bad value for auth_used_vector_timeout parameter (=%d), must be positive. Fixed to 3600\n", auth_used_vector_timeout); auth_used_vector_timeout = 3600; } /* check the max_nonce_reuse param */ if (max_nonce_reuse < 0) { LM_WARN("bad value for max_nonce_reuse parameter (=%d), must be positive. Fixed to 0\n", max_nonce_reuse); max_nonce_reuse = 0; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); return -1; } /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } /* Init the authorization data storage */ if (!auth_data_init(auth_data_hash_size)) { LM_ERR("Unable to init auth data\n"); return -1; } /* set default qop */ if (registration_qop.s && registration_qop.len > 0) { registration_qop_str.len = s_qop_s.len + registration_qop.len + s_qop_e.len; registration_qop_str.s = pkg_malloc(registration_qop_str.len); if (!registration_qop_str.s) { LM_ERR("Error allocating %d bytes\n", registration_qop_str.len); registration_qop_str.len = 0; return 0; } registration_qop_str.len = 0; STR_APPEND(registration_qop_str, s_qop_s); memcpy(registration_qop_str.s + registration_qop_str.len, registration_qop.s, registration_qop.len); registration_qop_str.len += registration_qop.len; STR_APPEND(registration_qop_str, s_qop_e); } else { registration_qop_str.len = 0; registration_qop_str.s = 0; } /* Register the auth vector timer */ if (register_timer(reg_await_timer, auth_data, 10) < 0) { LM_ERR("Unable to register auth vector timer\n"); return -1; } return 0; }
static int mod_init(void) { int n; load_dlg_f load_dlg; load_tm_f load_tm; bind_usrloc_t bind_usrloc; if (!fix_parameters()) { LM_ERR("unable to set Ro configuration parameters correctly\n"); goto error; } /* bind to the tm module */ if (!(load_tm = (load_tm_f) find_export("load_tm", NO_SCRIPT, 0))) { LM_ERR("Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; if (!(load_dlg = (load_dlg_f) find_export("load_dlg", 0, 0))) { /* bind to dialog module */ LM_ERR("can not import load_dlg. This module requires Kamailio dialog module.\n"); } if (load_dlg(&dlgb) == -1) { goto error; } if (load_cdp_api(&cdpb) != 0) { /* load the CDP API */ LM_ERR("can't load CDP API\n"); goto error; } if (load_dlg_api(&dlgb) != 0) { /* load the dialog API */ LM_ERR("can't load Dialog API\n"); goto error; } cdp_avp = load_cdp_avp(); /* load CDP_AVP API */ if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); goto error; } /* init timer lists*/ if (init_ro_timer(ro_session_ontimeout) != 0) { LM_ERR("cannot init timer list\n"); return -1; } /* initialized the hash table */ for (n = 0; n < (8 * sizeof(n)); n++) { if (ro_session_hash_size == (1 << n)) break; if (ro_session_hash_size < (1 << n)) { LM_WARN("hash_size is not a power of 2 as it should be -> rounding from %d to %d\n", ro_session_hash_size, 1 << (n - 1)); ro_session_hash_size = 1 << (n - 1); } } if (init_ro_session_table(ro_session_hash_size) < 0) { LM_ERR("failed to create ro session hash table\n"); return -1; } /* register global timer */ if (register_timer(ro_timer_routine, 0/*(void*)ro_session_list*/, 1) < 0) { LM_ERR("failed to register timer \n"); return -1; } bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } if (bind_usrloc(&ul) < 0) { return -1; } /*Register for callback of URECORD being deleted - so we can send a SAR*/ if (ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } /* register statistics */ if (register_module_stats(exports.name, charging_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } /*if (register_stat(MOD_NAME, "ccr_responses_time", &ccr_responses_time, 0)) { LM_ERR("failed to register core statistics\n"); return -1; }*/ /* if a database should be used to store the dialogs' information */ ro_db_mode = ro_db_mode_param; if (ro_db_mode == DB_MODE_NONE) { db_url.s = 0; db_url.len = 0; } else { if (ro_db_mode != DB_MODE_REALTIME && ro_db_mode != DB_MODE_SHUTDOWN) { LM_ERR("unsupported db_mode %d\n", ro_db_mode); return -1; } if (!db_url.s || db_url.len == 0) { LM_ERR("db_url not configured for db_mode %d\n", ro_db_mode); return -1; } if (init_ro_db(&db_url, ro_session_hash_size, db_update_period, db_fetch_rows) != 0) { LM_ERR("failed to initialize the DB support\n"); return -1; } // run_load_callbacks(); } return 0; error: LM_ERR("Failed to initialise ims_qos module\n"); return RO_RETURN_FALSE; }
/** * init module function */ static int mod_init(void) { /* fix the parameters */ if (!fix_parameters()) goto error; #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register core statistics\n"); goto error; } if (!register_stats()) { LM_ERR("Unable to register statistics\n"); goto error; } #endif callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; /*register space for event processor*/ register_procs(1); cdp_avp = 0; /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); goto error; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); goto error; } /* load the dialog API */ if (load_dlg_api(&dlgb) != 0) { LM_ERR("can't load Dialog API\n"); goto error; } cdp_avp = load_cdp_avp(); if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); goto error; } /* load the usrloc API */ bind_usrloc = (bind_usrloc_t) find_export("ul_bind_ims_usrloc_pcscf", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc_pcscf\n"); return CSCF_RETURN_FALSE; } if (bind_usrloc(&ul) < 0) { LM_ERR("can't bind to usrloc pcscf\n"); return CSCF_RETURN_FALSE; } LM_DBG("Successfully bound to PCSCF Usrloc module\n"); LM_DBG("Diameter RX interface successfully bound to TM, Dialog, Usrloc and CDP modules\n"); /*init cdb cb event list*/ if (!init_cdp_cb_event_list()) { LM_ERR("unable to initialise cdp callback event list\n"); return -1; } return 0; error: LM_ERR("Failed to initialise ims_qos module\n"); return CSCF_RETURN_FALSE; }