/*! \brief * Module initialization function */ static int mod_init(void) { 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); } #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif /* Compute the lengths of string parameters */ usrloc_debug_file.len = strlen(usrloc_debug_file.s); if (ul_hash_size <= 1) ul_hash_size = 512; else ul_hash_size = 1 << ul_hash_size; ul_locks_no = ul_hash_size; if (ul_init_locks() != 0) { LM_ERR("locks array initialization failed\n"); return -1; } /* Regsiter RPC */ if (rpc_register_array(ul_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } /* Register cache timer */ LM_DBG("Registering 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; } init_flag = 1; return 0; }
/*! \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; }
/*! \brief * Module initialization function */ static int mod_init(void) { 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); } #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif if (ul_hash_size <= 1) ul_hash_size = 512; else ul_hash_size = 1 << ul_hash_size; ul_locks_no = ul_hash_size; if (ul_init_locks() != 0) { LM_ERR("locks array initialization failed\n"); return -1; } /* Regsiter RPC */ if (rpc_register_array(ul_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } /* Register cache timer */ LM_DBG("Registering 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; } /* Shall we use database ? */ if (db_mode != NO_DB) { /* Yes */ if(ul_fetch_rows<=0) { LM_ERR("invalid fetch_rows number '%d'\n", ul_fetch_rows); return -1; } if (init_db(&db_url, timer_interval, ul_fetch_rows) != 0) { LM_ERR("Error initializing db connection\n"); return -1; } LM_DBG("Running in DB mode %i\n", db_mode); } init_flag = 1; return 0; }
/*! \brief * Module initialization function */ static int mod_init(void) { LM_DBG("initializing\n"); /* Compute the lengths of string parameters */ init_db_url( db_url , 1 /*can be null*/); user_col.len = strlen(user_col.s); domain_col.len = strlen(domain_col.s); contact_col.len = strlen(contact_col.s); expires_col.len = strlen(expires_col.s); q_col.len = strlen(q_col.s); callid_col.len = strlen(callid_col.s); cseq_col.len = strlen(cseq_col.s); flags_col.len = strlen(flags_col.s); cflags_col.len = strlen(cflags_col.s); user_agent_col.len = strlen(user_agent_col.s); received_col.len = strlen(received_col.s); path_col.len = strlen(path_col.s); sock_col.len = strlen(sock_col.s); methods_col.len = strlen(methods_col.s); sip_instance_col.len = strlen(sip_instance_col.s); attr_col.len = strlen(attr_col.s); last_mod_col.len = strlen(last_mod_col.s); if(ul_hash_size<=1) ul_hash_size = 512; else ul_hash_size = 1<<ul_hash_size; ul_locks_no = ul_hash_size; /* check matching mode */ switch (matching_mode) { case CONTACT_ONLY: case CONTACT_CALLID: 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; } /* Register cache timer */ register_timer( "ul-timer", timer, 0, timer_interval, TIMER_FLAG_DELAY_ON_DELAY); /* init the callbacks list */ if ( init_ulcb_list() < 0) { LM_ERR("usrloc/callbacks initialization failed\n"); return -1; } /* Shall we use database ? */ if (db_mode != NO_DB) { /* Yes */ if (db_url.s==NULL || db_url.len==0) { LM_ERR("selected db_mode requires a db connection -> db_url \n"); return -1; } 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 (db_mode != DB_ONLY && (sync_lock = lock_init_rw()) == NULL) { LM_ERR("cannot init rw lock\n"); return -1; } } fix_flag_name(nat_bflag_str, nat_bflag); nat_bflag = get_flag_id_by_name(FLAG_TYPE_BRANCH, nat_bflag_str); 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; } if (ul_event_init() < 0) { LM_ERR("cannot initialize USRLOC events\n"); return -1; } /* register handler for processing usrloc packets from the bin interface */ if (accept_replicated_udata && bin_register_cb(repl_module_name.s, receive_binary_packet) < 0) { LM_ERR("cannot register binary packet callback!\n"); return -1; } if(ul_replicate_cluster > 0 && load_clusterer_api(&clusterer_api)!=0){ LM_DBG("failed to find clusterer API - is clusterer module loaded?\n"); return -1; } if(ul_replicate_cluster < 0){ ul_replicate_cluster = 0; } init_flag = 1; return 0; }
/*! \brief * Module initialization function */ static int mod_init(void) { int i; udomain_t* d; if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0) return -1; #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif if(register_mi_mod(exports.name, mi_cmds)!=0) { LM_ERR("failed to register MI commands\n"); return -1; } if (rpc_register_array(ul_rpc)!=0) { LM_ERR("failed to register RPC commands\n"); return -1; } /* Compute the lengths of string parameters */ ruid_col.len = strlen(ruid_col.s); user_col.len = strlen(user_col.s); domain_col.len = strlen(domain_col.s); contact_col.len = strlen(contact_col.s); expires_col.len = strlen(expires_col.s); q_col.len = strlen(q_col.s); callid_col.len = strlen(callid_col.s); cseq_col.len = strlen(cseq_col.s); flags_col.len = strlen(flags_col.s); cflags_col.len = strlen(cflags_col.s); user_agent_col.len = strlen(user_agent_col.s); received_col.len = strlen(received_col.s); path_col.len = strlen(path_col.s); sock_col.len = strlen(sock_col.s); methods_col.len = strlen(methods_col.s); instance_col.len = strlen(instance_col.s); reg_id_col.len = strlen(reg_id_col.s); last_mod_col.len = strlen(last_mod_col.s); db_url.len = strlen(db_url.s); if(ul_xavp_contact_name.s!=NULL) ul_xavp_contact_name.len = strlen(ul_xavp_contact_name.s); if(ul_hash_size<=1) ul_hash_size = 512; else ul_hash_size = 1<<ul_hash_size; ul_locks_no = ul_hash_size; /* check matching mode */ switch (matching_mode) { case CONTACT_ONLY: case CONTACT_CALLID: case CONTACT_PATH: 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; } /* Register cache timer */ if(ul_timer_procs<=0) { if (timer_interval > 0) register_timer(ul_core_timer, 0, timer_interval); } else register_sync_timers(ul_timer_procs); /* init the callbacks list */ if ( init_ulcb_list() < 0) { LM_ERR("usrloc/callbacks initialization failed\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 (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; } for(i=0; i<ul_preload_index; i++) { if(register_udomain((const char*)ul_preload_list[i], &d)<0) { LM_ERR("cannot register preloaded table %s\n", ul_preload_list[i]); return -1; } } if (handle_lost_tcp && db_mode == DB_ONLY) LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n"); init_flag = 1; return 0; }
/*! \brief * Module initialization function */ static int mod_init(void) { LM_DBG("initializing\n"); /* Compute the lengths of string parameters */ init_db_url( db_url , 1 /*can be null*/); user_col.len = strlen(user_col.s); domain_col.len = strlen(domain_col.s); contact_col.len = strlen(contact_col.s); expires_col.len = strlen(expires_col.s); q_col.len = strlen(q_col.s); callid_col.len = strlen(callid_col.s); cseq_col.len = strlen(cseq_col.s); flags_col.len = strlen(flags_col.s); cflags_col.len = strlen(cflags_col.s); user_agent_col.len = strlen(user_agent_col.s); received_col.len = strlen(received_col.s); path_col.len = strlen(path_col.s); sock_col.len = strlen(sock_col.s); methods_col.len = strlen(methods_col.s); last_mod_col.len = strlen(last_mod_col.s); if(ul_hash_size<=1) ul_hash_size = 512; else ul_hash_size = 1<<ul_hash_size; ul_locks_no = ul_hash_size; /* check matching mode */ switch (matching_mode) { case CONTACT_ONLY: case CONTACT_CALLID: 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; } /* 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; } /* Shall we use database ? */ if (db_mode != NO_DB) { /* Yes */ if (db_url.s==NULL || db_url.len==0) { LM_ERR("selected db_mode requires a db connection -> db_url \n"); return -1; } 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 (db_mode != DB_ONLY && (sync_lock = lock_init_rw()) == NULL) { LM_ERR("cannot init rw lock\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; return 0; }