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; }
/** * Initializes the module. */ static int mod_init(void) { load_tm_f load_tm; load_cdp_f load_cdp; bind_dlg_mod_f load_dlg; str algo; callback_singleton=shm_malloc(sizeof(int)); *callback_singleton=0; shutdown_singleton=shm_malloc(sizeof(int)); *shutdown_singleton=0; LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n"); /* fix the parameters */ scscf_name_str.s = scscf_name; scscf_name_str.len = strlen(scscf_name); if (!build_record_service_route()) goto error; scscf_forced_hss_peer_str.s = scscf_forced_hss_peer; scscf_forced_hss_peer_str.len = strlen(scscf_forced_hss_peer); algo.s = registration_default_algorithm; algo.len = strlen(registration_default_algorithm); registration_default_algorithm_type = get_algorithm_type(algo); #ifdef WITH_IMS_PM ims_pm_init(scscf_name_str,ims_pm_node_type, ims_pm_logfile); ims_pm_init_scscf(); #endif /* WITH_IMS_PM */ /* load the send_reply function from sl module */ sl_reply = find_export("sl_send_reply", 2, 0); if (!sl_reply) { LOG(L_ERR, "ERR"M_NAME":mod_init: This module requires sl module\n"); goto error; } /* bind to the db module */ if(scscf_persistency_mode==WITH_DATABASE_BULK || scscf_persistency_mode==WITH_DATABASE_CACHE){ if (!scscf_db_url) { LOG(L_ERR, "ERR:"M_NAME":mod_init: no db_url specified but DB has to be used " "(scscf_persistency_mode=%d\n", scscf_persistency_mode); return -1; } if (!scscf_db_init(scscf_db_url)<0){ LOG(L_ERR, "ERR:"M_NAME": mod_init: Error while connecting database\n"); return -1; } /* db lock */ db_lock = (gen_lock_t*)lock_alloc(); if(!db_lock){ LOG(L_ERR, "ERR:"M_NAME": mod_init: No memory left\n"); return -1; } lock_init(db_lock); /* snapshot and step versions */ auth_snapshot_version=(int*)shm_malloc(sizeof(int)); if(!auth_snapshot_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: auth_snapshot_version, no memory left\n"); return -1; } *auth_snapshot_version=0; auth_step_version=(int*)shm_malloc(sizeof(int)); if(!auth_step_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: auth_step_version, no memory left\n"); return -1; } *auth_step_version=0; dialogs_snapshot_version=(int*)shm_malloc(sizeof(int)); if(!dialogs_snapshot_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: dialogs_snapshot_version, no memory left\n"); return -1; } *dialogs_snapshot_version=0; dialogs_step_version=(int*)shm_malloc(sizeof(int)); if(!dialogs_step_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: dialogs_step_version, no memory left\n"); return -1; } *dialogs_step_version=0; registrar_snapshot_version=(int*)shm_malloc(sizeof(int)); if(!registrar_snapshot_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: registrar_snapshot_version, no memory left\n"); return -1; } *registrar_snapshot_version=0; registrar_step_version=(int*)shm_malloc(sizeof(int)); if(!registrar_step_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: registrar_step_version, no memory left\n"); return -1; } *registrar_step_version=0; } /* bind to the tm module */ if (!(load_tm = (load_tm_f)find_export("load_tm",NO_SCRIPT,0))) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; /* bind to the cdp module */ if (!(load_cdp = (load_cdp_f)find_export("load_cdp",NO_SCRIPT,0))) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_cdp. This module requires cdp module\n"); goto error; } if (load_cdp(&cdpb) == -1) goto error; /* bind to the dialog module */ load_dlg = (bind_dlg_mod_f)find_export("bind_dlg_mod", -1, 0); if (!load_dlg) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import bind_dlg_mod. This module requires dialog module\n"); return -1; } if (load_dlg(&dialogb) != 0) { return -1; } /* Init the authorization data storage */ if (!auth_data_init(auth_data_hash_size)) goto error; if (scscf_persistency_mode!=NO_PERSISTENCY){ load_snapshot_authdata(); if (register_timer(persistency_timer_authdata,0,scscf_persistency_timer_authdata)<0) goto error; } /* register the authentication vectors timer */ if (register_timer(reg_await_timer,auth_data,10)<0) goto error; /* init the registrar storage */ if (!r_storage_init(registrar_hash_size)) goto error; if (scscf_persistency_mode!=NO_PERSISTENCY){ load_snapshot_registrar(); if (register_timer(persistency_timer_registrar,0,scscf_persistency_timer_registrar)<0) goto error; } /* register the registrar timer */ if (register_timer(registrar_timer,registrar,10)<0) goto error; /* init the registrar notifications */ if (!r_notify_init()) goto error; /* register the registrar notifications timer */ if (register_timer(notification_timer,notification_list,5)<0) goto error; /* init the dialog storage */ if (!s_dialogs_init(scscf_dialogs_hash_size)){ LOG(L_ERR, "ERR"M_NAME":mod_init: Error initializing the Hash Table for stored dialogs\n"); goto error; } scscf_dialog_count = shm_malloc(sizeof(int)); *scscf_dialog_count = 0; scscf_dialog_count_lock = lock_alloc(); scscf_dialog_count_lock = lock_init(scscf_dialog_count_lock); if (scscf_persistency_mode!=NO_PERSISTENCY){ load_snapshot_dialogs(); if (register_timer(persistency_timer_dialogs,0,scscf_persistency_timer_dialogs)<0) goto error; } /* register the dialog timer */ if (register_timer(dialog_timer,s_dialogs,60)<0) goto error; /* don't register response callback as we always set callback per transactions * and we're not interested in other responses */ /*AAAAddResponseHandler(&CxAnswerHandler,0);*/ return 0; error: return -1; }