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; }
/*! \brief * Module initialization function */ static int mod_init(void) { int i; load_dlg_f load_dlg; if (usrloc_debug){ LM_INFO("Logging usrloc records to %.*s\n", usrloc_debug_file.len, usrloc_debug_file.s); debug_file = fopen(usrloc_debug_file.s, "a"); fprintf(debug_file, "starting\n"); fflush(debug_file); } if (rpc_register_array(ul_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } if (ul_hash_size <= 1) ul_hash_size = 512; else ul_hash_size = 1 << ul_hash_size; ul_locks_no = ul_hash_size; if (subs_hash_size <= 1) subs_hash_size = 512; else subs_hash_size = 1 << subs_hash_size; subs_locks_no = subs_hash_size; if (contacts_hash_size <= 1) contacts_hash_size = 512; else contacts_hash_size = 1 << contacts_hash_size; contacts_locks_no = contacts_hash_size; /* check matching mode */ switch (matching_mode) { case CONTACT_ONLY: case CONTACT_CALLID: case CONTACT_PATH: case CONTACT_PORT_IP_ONLY: break; default: LM_ERR("invalid matching mode %d\n", matching_mode); } if (ul_init_locks() != 0) { LM_ERR("locks array initialization failed\n"); return -1; } /* create hash table for storing registered contacts */ if (init_contacts_locks() !=0) { LM_ERR("failed to initialise locks array for contacts\n"); return -1; } contact_list = (struct contact_list*)shm_malloc(sizeof(struct contact_list)); if (!contact_list) { LM_ERR("no more memory to create contact list structure\n"); return -1; } contact_list->slot = (struct contact_hslot*) shm_malloc(sizeof(struct contact_hslot) * contacts_hash_size); if (!contact_list->slot) { LM_ERR("no more memory to create contact list structure\n"); return -1; } for (i=0; i<contacts_hash_size;i++) { init_contact_slot(&contact_list->slot[i], i); } contact_list->size = contacts_hash_size; if (subs_init_locks() != 0) { LM_ERR("IMS Subscription locks array initialization failed\n"); return -1; } ims_subscription_list = (struct ims_subscription_list*) shm_malloc(sizeof(struct ims_subscription_list)); if (!ims_subscription_list) { LM_ERR("no more shm memory to create ims subscription list\n"); return -1; } ims_subscription_list->slot = (struct hslot_sp*) shm_malloc(sizeof(struct hslot_sp) * subs_hash_size); if (!ims_subscription_list->slot) { LM_ERR("no more memory to create subscription list structure\n"); return -1; } for (i=0; i<subs_hash_size;i++) { subs_init_slot(&ims_subscription_list->slot[i], i); } ims_subscription_list->size = subs_hash_size; /* presence binding for subscribe processing*/ presence_api_t pres; bind_presence_t bind_presence; bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); if (!bind_presence) { LM_ERR("can't bind presence\n"); return -1; } if (bind_presence(&pres) < 0) { LM_ERR("can't bind pua\n"); return -1; } pres_extract_sdialog_info= pres.extract_sdialog_info; pres_new_shtable = pres.new_shtable; pres_destroy_shtable = pres.destroy_shtable; pres_insert_shtable = pres.insert_shtable; pres_delete_shtable = pres.delete_shtable; pres_update_shtable = pres.update_shtable; pres_search_shtable = pres.search_shtable; if(!pres_new_shtable || !pres_destroy_shtable || !pres_insert_shtable || !pres_delete_shtable || !pres_update_shtable || !pres_search_shtable || !pres_extract_sdialog_info) { LM_ERR("could not import add_event\n"); return -1; } /* subscriber dialog hash table */ if(sub_dialog_hash_size<=1) { sub_dialog_hash_size= 512; } else { sub_dialog_hash_size = 1<<sub_dialog_hash_size; } sub_dialog_table= pres_new_shtable(sub_dialog_hash_size); if(sub_dialog_table== NULL) { LM_ERR("while creating new hash table\n"); return -1; } /* Shall we use database ? */ if (db_mode != NO_DB) { /* Yes */ if (db_bind_mod(&db_url, &ul_dbf) < 0) { /* Find database module */ LM_ERR("failed to bind database module\n"); return -1; } if (!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) { LM_ERR("database module does not implement all functions" " needed by the module\n"); return -1; } if (ul_fetch_rows <= 0) { LM_ERR("invalid fetch_rows number '%d'\n", ul_fetch_rows); return -1; } } 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) { return -1; } if (load_dlg_api(&dlgb) != 0) { /* load the dialog API */ LM_ERR("can't load Dialog API\n"); return -1; } /* Register counters */ if (ul_scscf_init_counters() != 0) { LM_ERR("Failed to register counters\n"); return -1; } /* Register cache timer */ register_timer(timer, 0, timer_interval); /* init the callbacks list */ if (init_ulcb_list() < 0) { LM_ERR("usrloc/callbacks initialization failed\n"); return -1; } if (nat_bflag == (unsigned int) -1) { nat_bflag = 0; } else if (nat_bflag >= 8 * sizeof(nat_bflag)) { LM_ERR("bflag index (%d) too big!\n", nat_bflag); return -1; } else { nat_bflag = 1 << nat_bflag; } init_flag = 1; /* From contact_dlg_handlers.c * * V1.1*/ if (dlgb.register_dlgcb(0x00, DLGCB_CREATED, contact_dlg_create_handler, 0x00, 0x00) ) { LM_ERR("Unable to setup DLGCB_CREATED"); return -1; } else { LM_DBG(" DLGCB_CREATED created successfully"); } 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; }