int register_core_stats(void) { /* register core statistics */ if (register_module_stats( "core", core_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } /* register sh_mem statistics */ if (register_module_stats( "shmem", shm_stats)!=0 ) { LM_ERR("failed to register sh_mem statistics\n"); return -1; } if (register_script_cb(km_cb_req_stats, PRE_SCRIPT_CB|REQUEST_CB, 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if (register_script_cb(km_cb_rpl_stats, PRE_SCRIPT_CB|ONREPLY_CB, 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if (stats_proc_stats_init_rpc()<0) return -1; sr_event_register_cb(SREV_CORE_STATS, sts_update_core_stats); return 0; }
/* Module initialization function */ static int mod_init(void) { if (init_shmlock() != 0) { LM_CRIT("cannot initialize shmlock.\n"); return -1; } if (conf_init(mp_max_id) < 0) { LM_CRIT("cannot initialize configuration.\n"); return -1; } /* read module parameters and update configuration structure */ if (conf_parse_proxy(mp_proxy) < 0) { LM_CRIT("cannot parse proxy module parameter.\n"); return -1; } if (conf_parse_filter(mp_filter) < 0) { LM_CRIT("cannot parse filter module parameter.\n"); return -1; } if (conf_parse_switch(mp_switch) < 0) { LM_CRIT("cannot parse switch module parameter.\n"); return -1; } if (forward_active == 1) { /* register callback for id 0 */ if (register_script_cb(pre_script_filter, PRE_SCRIPT_CB|ONREPLY_CB, 0) < 0) { LM_CRIT("cannot register script callback for requests.\n"); return -1; } if (register_script_cb(pre_script_filter, PRE_SCRIPT_CB|ONREPLY_CB, 0) < 0) { LM_CRIT("cannot register script callback for replies.\n"); return -1; } } else { LM_INFO("forward functionality disabled"); } /* presence database */ LM_DBG("pres_db_url=%s/%d/%p\n", ZSW(pres_db_url.s), pres_db_url.len, pres_db_url.s); if(pres_db_init() < 0) { return -1; } return 0; }
static int mod_init(void) { LM_INFO("Initializing StateLess engine\n"); /* if statistics are disabled, prevent their registration to core */ if (sl_enable_stats==0) #ifdef STATIC_SL sl_exports.stats = 0; #else exports.stats = 0; #endif /* filter all ACKs before script */ if (register_script_cb(sl_filter_ACK, PRE_SCRIPT_CB|REQ_TYPE_CB, 0 )!=0) { LM_ERR("register_script_cb failed\n"); return -1; } /* init internal SL stuff */ if (sl_startup()!=0) { LM_ERR("sl_startup failed\n"); return -1; } return 0; }
static int mod_init(void) { if(default_siputils_cfg.ring_timeout > 0) { ring_init_hashtable(); ring_lock = lock_alloc(); assert(ring_lock); if (lock_init(ring_lock) == 0) { LM_CRIT("cannot initialize lock.\n"); return -1; } if (register_script_cb(ring_filter, PRE_SCRIPT_CB|ONREPLY_CB, 0) != 0) { LM_ERR("could not insert callback"); return -1; } } /* bind the SL API */ if (sl_load_api(&opt_slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } if ( init_rpid_avp(rpid_avp_param)<0 ) { LM_ERR("failed to init rpid AVP name\n"); return -1; } if(cfg_declare("siputils", siputils_cfg_def, &default_siputils_cfg, cfg_sizeof(siputils), &siputils_cfg)){ LM_ERR("Fail to declare the configuration\n"); return -1; } return 0; }
/** * init module function */ static int mod_init(void) { /* load the TM API */ if (load_tm_api(&_tmx_tmb)!=0) { LM_ERR("can't load TM API\n"); return -1; } if(register_mi_mod(exports.name, mi_cmds)!=0) { LM_ERR("failed to register MI commands\n"); return -1; } #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register statistics\n"); return -1; } #endif pv_tmx_data_init(); if (register_script_cb(tmx_cfg_callback, POST_SCRIPT_CB|REQUEST_CB,0)<0) { LM_ERR("cannot register post-script callback\n"); return -1; } return 0; }
/** * init module function */ static int mod_init(void) { int fl; if (_dbg_cfgtrace_facility_str!=NULL) { fl = str2facility(_dbg_cfgtrace_facility_str); if (fl != -1) { _dbg_cfgtrace_facility = fl; } else { LM_ERR("invalid log facility configured"); return -1; } } if(dbg_init_rpc()!=0) { LM_ERR("failed to register RPC commands\n"); return -1; } if(cfg_declare("dbg", dbg_cfg_def, &default_dbg_cfg, cfg_sizeof(dbg), &dbg_cfg)) { LM_ERR("Fail to declare the configuration\n"); return -1; } LM_DBG("cfg level_mode:%d hash_size:%d\n", cfg_get(dbg, dbg_cfg, mod_level_mode), cfg_get(dbg, dbg_cfg, mod_hash_size)); if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0) { LM_ERR("failed to init per module log level\n"); return -1; } if(_dbg_log_assign>0) { if(dbg_init_pvcache()!=0) { LM_ERR("failed to create pvcache\n"); return -1; } } if(_dbg_reset_msgid==1) { unsigned int ALL = REQUEST_CB+FAILURE_CB+ONREPLY_CB +BRANCH_CB+ONSEND_CB+ERROR_CB+LOCAL_CB+EVENT_CB+BRANCH_FAILURE_CB; if (register_script_cb(dbg_msgid_filter, PRE_SCRIPT_CB|ALL, 0) != 0) { LM_ERR("could not insert callback"); return -1; } } return dbg_init_bp_list(); }
static int mod_init(void) { fprintf(stderr, "stateless - initializing\n"); if (init_sl_stats()<0) { LOG(L_ERR, "ERROR: init_sl_stats failed\n"); return -1; } /* if SL loaded, filter ACKs on beginning */ register_script_cb( sl_filter_ACK, PRE_SCRIPT_CB, 0 ); sl_startup(); return 0; }
static int mod_init(void) { struct dbops_action* p; xlbuf = pkg_malloc((xlbuf_size+1)*sizeof(char)); if (!xlbuf) { ERR(MODULE_NAME": out of memory, cannot create xlbuf\n"); return E_OUT_OF_MEM; } for (p=dbops_actions; p; p=p->next) { int res; res = init_action(p); if (res < 0) { pkg_free(xlbuf); xlbuf = NULL; return res; } } if(register_script_cb(dbops_pre_script_cb, REQUEST_CB | ONREPLY_CB | PRE_SCRIPT_CB, 0)<0) { LM_ERR("failed to register pre script callback\n"); pkg_free(xlbuf); xlbuf = NULL; return -1; } if(register_script_cb(dbops_post_script_cb, REQUEST_CB | ONREPLY_CB | POST_SCRIPT_CB, 0)<0) { LM_ERR("failed to register post script callback\n"); pkg_free(xlbuf); xlbuf = NULL; return -1; } register_select_table(sel_declaration); return 0; }
static int mod_init(void) { if (init_sl_stats() < 0) { ERR("init_sl_stats failed\n"); return -1; } /* if SL loaded, filter ACKs on beginning */ if (register_script_cb( sl_filter_ACK, PRE_SCRIPT_CB|REQ_TYPE_CB, 0 )<0) { ERR("Failed to install SCRIPT callback\n"); return -1; } sl_startup(); return 0; }
static int mod_init(void) { fprintf(stderr, "stateless - initializing\n"); if (init_sl_stats()<0) { LOG(L_ERR, "ERROR: init_sl_stats failed\n"); return -1; } /* filter all ACKs before script */ if (register_script_cb(sl_filter_ACK, PRE_SCRIPT_CB|REQ_TYPE_CB, 0 )!=0) { LOG(L_ERR,"ERROR:sl:mod_init: register_script_cb failed\n"); return -1; } /* init internal SL stuff */ if (sl_startup()!=0) { LOG(L_ERR,"ERROR:sl:mod_init: sl_startup failed\n"); return -1; } return 0; }
static int mod_init(void) { if (init_sl_stats() < 0) { ERR("init_sl_stats failed\n"); return -1; } if (sl_register_kstats()<0) { ERR("init k stats failed\n"); return -1; } /* if SL loaded, filter ACKs on beginning */ if (register_script_cb( sl_filter_ACK, PRE_SCRIPT_CB|REQUEST_CB, 0 )<0) { ERR("Failed to install SCRIPT callback\n"); return -1; } if(sl_startup()<0) { ERR("Failed to do startup tasks\n"); return -1; } if(sl_bind_tm!=0) { if(load_tm_api(&tmb)==-1) { LM_INFO("could not bind tm module - only stateless mode" " available\n"); sl_bind_tm=0; } } _sl_filtered_ack_route=route_lookup(&event_rt, "sl:filtered-ack"); if (_sl_filtered_ack_route>=0 && event_rt.rlist[_sl_filtered_ack_route]==0) _sl_filtered_ack_route=-1; /* disable */ return 0; }
static int mod_init(void) { if (init_sl_stats() < 0) { ERR("init_sl_stats failed\n"); return -1; } if (sl_register_kstats()<0) { ERR("init k stats failed\n"); return -1; } /* if SL loaded, filter ACKs on beginning */ if (register_script_cb( sl_filter_ACK, PRE_SCRIPT_CB|REQUEST_CB, 0 )<0) { ERR("Failed to install SCRIPT callback\n"); return -1; } if(sl_startup()<0) { ERR("Failed to do startup tasks\n"); return -1; } memset(&tmb, 0, sizeof(struct tm_binds)); if(sl_bind_tm!=0) { if(load_tm_api(&tmb)==-1) { LM_INFO("could not bind tm module - only stateless mode" " available during modules initialization\n"); } } sl_lookup_event_routes(); return 0; }
/** * init module function */ static int mod_init(void) { bind_usrloc_t bind_usrloc; bind_pua_t bind_pua; LM_DBG("initializing module ...\n"); if(default_domain.s == NULL ) { LM_ERR("default domain parameter not set\n"); return -1; } default_domain.len= strlen(default_domain.s); if(pres_prefix.s == NULL ) { LM_DBG("No pres_prefix configured\n"); } else pres_prefix.len= strlen(pres_prefix.s); if(presence_server.s) { presence_server.len= strlen(presence_server.s); } 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) { LM_ERR("Can't bind usrloc\n"); return -1; } if(ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_INSERT, ul_publish, 0)< 0) { LM_ERR("can not register callback for" " insert\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_EXPIRE, ul_publish, 0)< 0) { LM_ERR("can not register callback for" " expire\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_UPDATE, ul_publish, 0)< 0) { LM_ERR("can not register callback for update\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_DELETE, ul_publish, 0)< 0) { LM_ERR("can not register callback for delete\n"); return -1; } bind_pua= (bind_pua_t)find_export("bind_pua", 1,0); if (!bind_pua) { LM_ERR("Can't bind pua\n"); return -1; } if (bind_pua(&pua) < 0) { LM_ERR("Can't bind pua\n"); return -1; } if(pua.send_publish == NULL) { LM_ERR("Could not import send_publish\n"); return -1; } pua_send_publish= pua.send_publish; if(pua.send_subscribe == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } pua_send_subscribe= pua.send_subscribe; /* register post-script pua_unset_publish unset function */ if(register_script_cb(pua_unset_publish, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0) { LM_ERR("failed to register POST request callback\n"); return -1; } return 0; }
static int mod_init(void) { LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LM_ERR("timer init failed\n"); return -1; } /* register the timer functions */ if (register_timer( timer_routine , 0, 1 )<0) { LM_ERR("failed to register timer\n"); return -1; } if (register_utimer( utimer_routine , 0, 100*1000 )<0) { LM_ERR("failed to register utimer\n"); return -1; } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if ( init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LM_ERR("ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } return 0; }
static int pike_init(void) { int rt; LM_INFO("initializing...\n"); /* alloc the timer lock */ timer_lock=lock_alloc(); if (timer_lock==0) { LM_ERR(" alloc locks failed!\n"); goto error1; } /* init the lock */ if (lock_init(timer_lock)==0){ LM_ERR(" init lock failed\n"); goto error1; } /* init the IP tree */ if ( init_ip_tree(max_reqs)!=0 ) { LM_ERR(" ip_tree creation failed!\n"); goto error2; } /* init timer list */ timer = (struct list_link*)shm_malloc(sizeof(struct list_link)); if (timer==0) { LM_ERR(" cannot alloc shm mem for timer!\n"); goto error3; } timer->next = timer->prev = timer; /* registering timing functions */ register_timer( "pike-clean", clean_routine , 0, 1 ); register_timer( "pike-swap", swap_routine , 0, time_unit ); if (pike_route_s && *pike_route_s) { rt = get_script_route_ID_by_name( pike_route_s, rlist, RT_NO); if (rt<1) { LM_ERR("route <%s> does not exist\n",pike_route_s); return -1; } /* register the script callback to get all requests and replies */ if (register_script_cb( run_pike_route , PARSE_ERR_CB|REQ_TYPE_CB|RPL_TYPE_CB|PRE_SCRIPT_CB, (void*)(long)rt )!=0 ) { LM_ERR("failed to register script callbacks\n"); goto error3; } } if((pike_event_id = evi_publish_event(pike_block_event)) == EVI_ERROR) LM_ERR("cannot register pike flood start event\n"); return 0; error3: destroy_ip_tree(); error2: lock_destroy(timer_lock); error1: if (timer_lock) lock_dealloc(timer_lock); timer_lock = 0; return -1; }
static int mod_init(void) { unsigned int timer_sets,set; unsigned int roundto_init; LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } fix_flag_name(minor_branch_flag_str, minor_branch_flag); minor_branch_flag = get_flag_id_by_name(FLAG_TYPE_BRANCH, minor_branch_flag_str); if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* how many timer sets do we need to create? */ timer_sets = (timer_partitions<=1)?1:timer_partitions ; /* try first allocating all the structures needed for syncing */ if (lock_initialize( timer_sets )==-1) return -1; /* building the hash table*/ if (!init_hash_table( timer_sets )) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers( timer_sets ) ) { LM_ERR("timer init failed\n"); return -1; } /* the ROUNDTO macro taken from the locking interface */ #ifdef ROUNDTO roundto_init = ROUNDTO; #else roundto_init = sizeof(void *); #endif while (roundto_init != 1) { tm_timer_shift++; roundto_init >>= 1; } LM_DBG("timer set shift is %d\n", tm_timer_shift); /* register the timer functions */ for ( set=0 ; set<timer_sets ; set++ ) { if (register_timer( "tm-timer", timer_routine, (void*)(long)set, 1, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) { LM_ERR("failed to register timer for set %d\n",set); return -1; } if (register_utimer( "tm-utimer", utimer_routine, (void*)(long)set, 100*1000, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register utimer for set %d\n",set); return -1; } } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if ( parse_avp_spec( &uac_ctx_avp, &uac_ctx_avp_id)<0 ) { LM_ERR("failed to register AVP name <%s>\n",uac_ctx_avp.s); return -1; } if ( register_async_script_handlers( t_handle_async, t_resume_async )<0 ) { LM_ERR("failed to register async handler to core \n"); return -1; } return 0; }
/*! \brief * init module function */ static int mod_init(void) { bind_usrloc_t bind_usrloc; bind_pua_t bind_pua; if(!default_domain.s || default_domain.len<=0) { LM_ERR("default domain parameter not set\n"); return -1; } if(!pres_prefix.s || pres_prefix.len<=0) LM_DBG("No pres_prefix configured\n"); 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) { LM_ERR("Can't bind usrloc\n"); return -1; } if(ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_INSERT, ul_publish, 0)< 0) { LM_ERR("can not register callback for" " insert\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_EXPIRE, ul_publish, 0)< 0) { LM_ERR("can not register callback for" " expire\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_UPDATE, ul_publish, 0)< 0) { LM_ERR("can not register callback for update\n"); return -1; } if(ul.register_ulcb(UL_CONTACT_DELETE, ul_publish, 0)< 0) { LM_ERR("can not register callback for delete\n"); return -1; } bind_pua= (bind_pua_t)find_export("bind_pua", 1,0); if (!bind_pua) { LM_ERR("Can't bind pua\n"); return -1; } if (bind_pua(&_pu_pua) < 0) { LM_ERR("Can't bind pua\n"); return -1; } if(_pu_pua.send_publish == NULL) { LM_ERR("Could not import send_publish\n"); return -1; } if(_pu_pua.send_subscribe == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } /* register post-script pua_unset_publish unset function */ if(register_script_cb(pua_unset_publish, POST_SCRIPT_CB|REQUEST_CB, 0)<0) { LM_ERR("failed to register POST request callback\n"); return -1; } if(pua_ul_bflag!=-1) pua_ul_bmask = 1 << pua_ul_bflag; return 0; }
/* Module initialization function */ static int mod_init(void) { if(register_mi_mod(exports.name, mi_cmds)!=0) { LM_ERR("failed to register MI commands\n"); return -1; } /* Initialize curl */ if (curl_global_init(CURL_GLOBAL_ALL)) { LM_ERR("curl_global_init failed\n"); return -1; } if (init_shmlock() != 0) { LM_CRIT("cannot initialize shmlock.\n"); return -1; } if (conf_init(mp_max_id) < 0) { LM_CRIT("cannot initialize configuration.\n"); return -1; } /* read module parameters and update configuration structure */ if (conf_parse_proxy(mp_proxy) < 0) { LM_CRIT("cannot parse proxy module parameter.\n"); return -1; } if (conf_parse_filter(mp_filter) < 0) { LM_CRIT("cannot parse filter module parameter.\n"); return -1; } if (conf_parse_switch(mp_switch) < 0) { LM_CRIT("cannot parse switch module parameter.\n"); return -1; } if (forward_active == 1) { /* register callback for id 0 */ if (register_script_cb(pre_script_filter, PRE_SCRIPT_CB|ONREPLY_CB, 0) < 0) { LM_CRIT("cannot register script callback for requests.\n"); return -1; } if (register_script_cb(pre_script_filter, PRE_SCRIPT_CB|ONREPLY_CB, 0) < 0) { LM_CRIT("cannot register script callback for replies.\n"); return -1; } } else { LM_INFO("forward functionality disabled"); } /* presence database */ pres_db_url.len = pres_db_url.s ? strlen(pres_db_url.s) : 0; LM_DBG("pres_db_url=%s/%d/%p\n", ZSW(pres_db_url.s), pres_db_url.len, pres_db_url.s); xcap_table.len = xcap_table.s ? strlen(xcap_table.s) : 0; if(pres_db_init() < 0) { return -1; } return 0; }
static int mod_init(void) { DBG( "TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializin Call-ID generator\n"); return -1; } if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac\n"); return -1; } if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { LOG(L_CRIT, "cannot register hash\n"); return -1; } if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* register the timer function */ register_timer( timer_routine , 0 /* empty attr */, 1 ); /* init_tm_stats calls process_count, which should * NOT be called from mod_init, because one does not * now, if a timer is used and thus how many processes * will be started; however we started already our * timers, so we know and process_count should not * change any more */ if (init_tm_stats()<0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } /* building the hash table*/ if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } /* register post-script clean-up function */ register_script_cb( w_t_unref, POST_SCRIPT_CB, 0 /* empty param */ ); register_script_cb( script_init, PRE_SCRIPT_CB , 0 /* empty param */ ); tm_init_tags(); return 0; }
/** Module initialize function */ static int mod_init(void) { /* inspect the parameters */ if(server_hsize< 1 || server_hsize> 20 || client_hsize< 1 || client_hsize> 20) { LM_ERR("Wrong hash size. Needs to be greater than 1" " and smaller than 20. Be aware that you should set the log 2" " value of the real size\n"); return -1; } server_hsize = 1<<server_hsize; client_hsize = 1<<client_hsize; if(b2b_key_prefix.s) { b2b_key_prefix.len = strlen(b2b_key_prefix.s); if(b2b_key_prefix.len > B2B_MAX_PREFIX_LEN) { LM_ERR("b2b_key_prefix [%s] too long. Maximum size %d\n", b2b_key_prefix.s, B2B_MAX_PREFIX_LEN); return -1; } } /* load all TM stuff */ if(load_tm_api(&tmb)==-1) { LM_ERR("can't load tm functions\n"); return -1; } /* load the UAC_AUTH API - FIXME it should be loaded only * if authentication is required */ if(load_uac_auth_api(&uac_auth_api)<0) { LM_INFO("authentication functionality disabled:" " load uac_auth first to enable it\n"); uac_auth_loaded = 0; } else { uac_auth_loaded = 1; } /* initialize the hash tables; they will be allocated in shared memory * to be accesible by all processes */ if(init_b2b_htables()< 0) { LM_ERR("Failed to initialize b2b table\n"); return -1; } memset(&b2be_dbf, 0, sizeof(db_func_t)); if(b2be_db_mode && db_url.s) { db_url.len = strlen(db_url.s); b2be_dbtable.len = strlen(b2be_dbtable.s); /* binding to database module */ if (db_bind_mod(&db_url, &b2be_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(b2be_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by b2b_entities module\n"); return -1; } b2be_db = b2be_dbf.init(&db_url); if(!b2be_db) { LM_ERR("connecting to database failed\n"); return -1; } /*verify table versions */ if(db_check_table_version(&b2be_dbf, b2be_db, &b2be_dbtable, TABLE_VERSION) < 0) { LM_ERR("error during table version check\n"); return -1; } b2be_initialize(); /* reload data */ if(b2b_entities_restore() < 0) { LM_ERR("Failed to restore data from database\n"); return -1; } if(b2be_db) b2be_dbf.close(b2be_db); b2be_db = NULL; } else b2be_db_mode = 0; if(register_script_cb( b2b_prescript_f, PRE_SCRIPT_CB|REQ_TYPE_CB, 0 ) < 0) { LM_ERR("Failed to register prescript function\n"); return -1; } if (script_req_route) { req_routeid = get_script_route_ID_by_name( script_req_route, rlist, RT_NO); if (req_routeid < 1) { LM_ERR("route <%s> does not exist\n",script_req_route); return -1; } } if (script_reply_route) { reply_routeid = get_script_route_ID_by_name( script_reply_route, rlist, RT_NO); if (reply_routeid < 1) { LM_ERR("route <%s> does not exist\n",script_reply_route); return -1; } } if(b2b_update_period < 0) { LM_ERR("Wrong parameter - b2b_update_period [%d]\n", b2b_update_period); return -1; } if(b2be_db_mode == WRITE_BACK) register_timer("b2be-dbupdate", b2be_db_timer_update, 0, b2b_update_period); //register_timer("b2b2-clean", b2be_clean, 0, b2b_update_period); return 0; }
/** * init module function */ static int mod_init(void) { int fl; bind_cfgt_t bind_cfgt; if (register_mi_mod(exports.name, mi_cmds) != 0) { LM_ERR("failed to register MI commands\n"); return -1; } if (_dbg_cfgtrace_facility_str!=NULL) { fl = str2facility(_dbg_cfgtrace_facility_str); if (fl != -1) { _dbg_cfgtrace_facility = fl; } else { LM_ERR("invalid log facility configured"); return -1; } } if(dbg_init_rpc()!=0) { LM_ERR("failed to register RPC commands\n"); return -1; } if(cfg_declare("dbg", dbg_cfg_def, &default_dbg_cfg, cfg_sizeof(dbg), &dbg_cfg)) { LM_ERR("Fail to declare the configuration\n"); return -1; } /* anyhow, should fail before */ if (!dbg_cfg) { return -1; } LM_DBG("cfg level_mode:%d facility_mode:%d hash_size:%d\n", cfg_get(dbg, dbg_cfg, mod_level_mode), cfg_get(dbg, dbg_cfg, mod_facility_mode), cfg_get(dbg, dbg_cfg, mod_hash_size)); if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0) { LM_ERR("failed to init per module log level\n"); return -1; } if(_dbg_log_assign>0) { if(dbg_init_pvcache()!=0) { LM_ERR("failed to create pvcache\n"); return -1; } } if(_dbg_reset_msgid==1) { unsigned int ALL = REQUEST_CB+FAILURE_CB+ONREPLY_CB +BRANCH_CB+ONSEND_CB+ERROR_CB+LOCAL_CB+EVENT_CB+BRANCH_FAILURE_CB; if (register_script_cb(dbg_msgid_filter, PRE_SCRIPT_CB|ALL, 0) != 0) { LM_ERR("could not insert callback"); return -1; } } if(_dbg_cfgtest==1) { bind_cfgt = (bind_cfgt_t)find_export("cfgt_bind_cfgt", 1, 0); if (!bind_cfgt) { LM_ERR("can't find cfgt module\n"); return -1; } if (bind_cfgt(&_dbg_cfgt) < 0) { return -1; } LM_INFO("bind to cfgt module\n"); } return dbg_init_bp_list(); }
void ims_pm_init_icscf() { register_script_cb(ims_pm_pre_script,PRE_SCRIPT_CB|REQ_TYPE_CB|RPL_TYPE_CB,0); register_script_cb(ims_pm_post_script,POST_SCRIPT_CB|REQ_TYPE_CB|RPL_TYPE_CB,0); }
static int mod_init(void) { DBG( "TM - (sizeof cell=%ld, sip_msg=%ld) initializing...\n", (long)sizeof(struct cell), (long)sizeof(struct sip_msg)); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializing Call-ID generator\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (tm_init_selects()==-1) { LOG(L_ERR, "ERROR: mod_init: select init failed\n"); return -1; } if (tm_init_timers()==-1) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* First tm_stat initialization function only allocates the top level stat * structure in shared memory, the initialization will complete in child * init with init_tm_stats_child when the final value of estimated_process_count is * known */ if (init_tm_stats() < 0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LOG(L_CRIT, "ERROR:tm:mod_init: failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LOG(L_ERR, "ERROR:tm:mod_init: Unable to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; } if (init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } tm_init = 1; return 0; }
static int mod_init(void) { DBG( "TM - (size of cell=%ld, sip_msg=%ld) initializing...\n", (long)sizeof(struct cell), (long)sizeof(struct sip_msg)); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializing Call-ID generator\n"); return -1; } if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac\n"); return -1; } if (register_fifo_cmd(fifo_uac_cancel, "t_uac_cancel", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac_cancel\n"); return -1; } if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { LOG(L_CRIT, "cannot register hash\n"); return -1; } if (register_fifo_cmd(fifo_t_reply, "t_reply", 0)<0) { LOG(L_CRIT, "cannot register t_reply\n"); return -1; } if (unixsock_register_cmd("t_uac_dlg", unixsock_uac) < 0) { LOG(L_CRIT, "cannot register t_uac with the unix server\n"); return -1; } if (unixsock_register_cmd("t_uac_cancel", unixsock_uac_cancel) < 0) { LOG(L_CRIT, "cannot register t_uac_cancel with the unix server\n"); return -1; } if (unixsock_register_cmd("t_hash", unixsock_hash) < 0) { LOG(L_CRIT, "cannot register t_hash with the unix server\n"); return -1; } if (unixsock_register_cmd("t_reply", unixsock_t_reply) < 0) { LOG(L_CRIT, "cannot register t_reply with the unix server\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* register the timer function */ register_timer( timer_routine , 0 /* empty attr */, 1 ); /* init_tm_stats calls process_count, which should * NOT be called from mod_init, because one does not * now, if a timer is used and thus how many processes * will be started; however we started already our * timers, so we know and process_count should not * change any more */ if (init_tm_stats()<0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LOG(L_CRIT, "ERROR:tm:mod_init: failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LOG(L_ERR, "ERROR:tm:mod_init: Unable to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; } if ( init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } if ( init_gf_mask( bf_mask_param )<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to process " "\"branch_flag_mask\" param\n"); return -1; } return 0; }
static int mod_init(void) { unsigned int n; if(dlg_ka_interval!=0 && dlg_ka_interval<30) { LM_ERR("ka interval too low (%d), has to be at least 30\n", dlg_ka_interval); return -1; } dlg_event_rt[DLG_EVENTRT_START] = route_lookup(&event_rt, "dialog:start"); dlg_event_rt[DLG_EVENTRT_END] = route_lookup(&event_rt, "dialog:end"); dlg_event_rt[DLG_EVENTRT_FAILED] = route_lookup(&event_rt, "dialog:failed"); #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register %s statistics\n", exports.name); 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(rpc_methods)!=0) { LM_ERR("failed to register RPC commands\n"); return -1; } if(faked_msg_init()<0) return -1; if(dlg_bridge_init_hdrs()<0) return -1; /* param checkings */ if (dlg_flag==-1) { LM_ERR("no dlg flag set!!\n"); return -1; } else if (dlg_flag>MAX_FLAG) { LM_ERR("invalid dlg flag %d!!\n",dlg_flag); return -1; } if (rr_param==0 || rr_param[0]==0) { LM_ERR("empty rr_param!!\n"); return -1; } else if (strlen(rr_param)>MAX_DLG_RR_PARAM_NAME) { LM_ERR("rr_param too long (max=%d)!!\n", MAX_DLG_RR_PARAM_NAME); return -1; } if (timeout_spec.s) { if ( pv_parse_spec(&timeout_spec, &timeout_avp)==0 && (timeout_avp.type!=PVT_AVP)){ LM_ERR("malformed or non AVP timeout " "AVP definition in '%.*s'\n", timeout_spec.len,timeout_spec.s); return -1; } } if (default_timeout<=0) { LM_ERR("0 default_timeout not accepted!!\n"); return -1; } if (ruri_pvar_param.s==NULL || ruri_pvar_param.len<=0) { LM_ERR("invalid r-uri PV string\n"); return -1; } if(pv_parse_format(&ruri_pvar_param, &ruri_param_model) < 0 || ruri_param_model==NULL) { LM_ERR("malformed r-uri PV string: %s\n", ruri_pvar_param.s); return -1; } if (initial_cbs_inscript != 0 && initial_cbs_inscript != 1) { LM_ERR("invalid parameter for running initial callbacks in-script" " (must be either 0 or 1)\n"); return -1; } if (seq_match_mode!=SEQ_MATCH_NO_ID && seq_match_mode!=SEQ_MATCH_FALLBACK && seq_match_mode!=SEQ_MATCH_STRICT_ID ) { LM_ERR("invalid value %d for seq_match_mode param!!\n",seq_match_mode); return -1; } if (detect_spirals != 0 && detect_spirals != 1) { LM_ERR("invalid value %d for detect_spirals param!!\n",detect_spirals); return -1; } if (dlg_timeout_noreset != 0 && dlg_timeout_noreset != 1) { LM_ERR("invalid value %d for timeout_noreset param!!\n", dlg_timeout_noreset); return -1; } /* if statistics are disabled, prevent their registration to core */ if (dlg_enable_stats==0) exports.stats = 0; /* create profile hashes */ if (add_profile_definitions( profiles_nv_s, 0)!=0 ) { LM_ERR("failed to add profiles without value\n"); return -1; } if (add_profile_definitions( profiles_wv_s, 1)!=0 ) { LM_ERR("failed to add profiles with value\n"); return -1; } /* load the TM API */ if (load_tm_api(&d_tmb)!=0) { LM_ERR("can't load TM API\n"); return -1; } /* load RR API also */ if (load_rr_api(&d_rrb)!=0) { LM_ERR("can't load RR API\n"); return -1; } /* register callbacks*/ /* listen for all incoming requests */ if ( d_tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, dlg_onreq, 0, 0 ) <=0 ) { LM_ERR("cannot register TMCB_REQUEST_IN callback\n"); return -1; } /* listen for all routed requests */ if ( d_rrb.register_rrcb( dlg_onroute, 0 ) <0 ) { LM_ERR("cannot register RR callback\n"); return -1; } if (register_script_cb( profile_cleanup, POST_SCRIPT_CB|REQUEST_CB,0)<0) { LM_ERR("cannot register script callback"); return -1; } if (register_script_cb(dlg_cfg_cb, PRE_SCRIPT_CB|REQUEST_CB,0)<0) { LM_ERR("cannot register pre-script ctx callback\n"); return -1; } if (register_script_cb(dlg_cfg_cb, POST_SCRIPT_CB|REQUEST_CB,0)<0) { LM_ERR("cannot register post-script ctx callback\n"); return -1; } if (register_script_cb( spiral_detect_reset, POST_SCRIPT_CB|REQUEST_CB,0)<0) { LM_ERR("cannot register req pre-script spiral detection reset callback\n"); return -1; } if(dlg_timer_procs<=0) { if ( register_timer( dlg_timer_routine, 0, 1)<0 ) { LM_ERR("failed to register timer \n"); return -1; } } else { register_sync_timers(1); } /* init handlers */ init_dlg_handlers( rr_param, dlg_flag, timeout_spec.s?&timeout_avp:0, default_timeout, seq_match_mode); /* init timer */ if (init_dlg_timer(dlg_ontimeout)!=0) { LM_ERR("cannot init timer list\n"); return -1; } /* sanitize dlg_hash_zie */ if (dlg_hash_size < 1){ LM_WARN("hash_size is smaller " "then 1 -> rounding from %d to 1\n", dlg_hash_size); dlg_hash_size = 1; } /* initialized the hash table */ for( n=0 ; n<(8*sizeof(n)) ; n++) { if (dlg_hash_size==(1<<n)) break; if (n && dlg_hash_size<(1<<n)) { LM_WARN("hash_size is not a power " "of 2 as it should be -> rounding from %d to %d\n", dlg_hash_size, 1<<(n-1)); dlg_hash_size = 1<<(n-1); } } if ( init_dlg_table(dlg_hash_size)<0 ) { LM_ERR("failed to create hash table\n"); return -1; } /* if a database should be used to store the dialogs' information */ dlg_db_mode = dlg_db_mode_param; if (dlg_db_mode==DB_MODE_NONE) { db_url.s = 0; db_url.len = 0; } else { if (dlg_db_mode!=DB_MODE_REALTIME && dlg_db_mode!=DB_MODE_DELAYED && dlg_db_mode!=DB_MODE_SHUTDOWN ) { LM_ERR("unsupported db_mode %d\n", dlg_db_mode); return -1; } if ( !db_url.s || db_url.len==0 ) { LM_ERR("db_url not configured for db_mode %d\n", dlg_db_mode); return -1; } if (init_dlg_db(&db_url, dlg_hash_size, db_update_period,db_fetch_rows)!=0) { LM_ERR("failed to initialize the DB support\n"); return -1; } run_load_callbacks(); } destroy_dlg_callbacks( DLGCB_LOADED ); /* timer process to send keep alive requests */ if(dlg_ka_timer>0 && dlg_ka_interval>0) register_sync_timers(1); /* timer process to clean old unconfirmed dialogs */ register_sync_timers(1); return 0; }
static int mod_init(void) { pv_spec_t avp_spec; int *param; modparam_t type; // initialize the canonical_uri_avp structure if (canonical_uri_avp.spec.s==NULL || canonical_uri_avp.spec.len<=0) { LOG(L_ERR, "missing/empty canonical_uri_avp parameter. using default.\n"); canonical_uri_avp.spec.s = CANONICAL_URI_AVP_SPEC; } if (pv_parse_spec(&(canonical_uri_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LOG(L_CRIT, "invalid AVP specification for canonical_uri_avp: `%s'\n", canonical_uri_avp.spec.s); return -1; } if (pv_get_avp_name(0, &(avp_spec.pvp), &(canonical_uri_avp.name), &(canonical_uri_avp.type))!=0) { LOG(L_CRIT, "invalid AVP specification for canonical_uri_avp: `%s'\n", canonical_uri_avp.spec.s); return -1; } // initialize the signaling_ip_avp structure if (signaling_ip_avp.spec.s==NULL || signaling_ip_avp.spec.len<=0) { LOG(L_ERR, "missing/empty signaling_ip_avp parameter. using default.\n"); signaling_ip_avp.spec.s = SIGNALING_IP_AVP_SPEC; } if (pv_parse_spec(&(signaling_ip_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LOG(L_CRIT, "invalid AVP specification for signaling_ip_avp: `%s'\n", signaling_ip_avp.spec.s); return -1; } if (pv_get_avp_name(0, &(avp_spec.pvp), &(signaling_ip_avp.name), &(signaling_ip_avp.type))!=0) { LOG(L_CRIT, "invalid AVP specification for signaling_ip_avp: `%s'\n", signaling_ip_avp.spec.s); return -1; } // initialize the sip_application_avp structure if (sip_application_avp.spec.s==NULL || sip_application_avp.spec.len<=0) { LOG(L_ERR, "missing/empty sip_application_avp parameter. using default.\n"); sip_application_avp.spec.s = SIP_APPLICATION_AVP_SPEC; } if (pv_parse_spec(&(sip_application_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LOG(L_CRIT, "invalid AVP specification for sip_application_avp: `%s'\n", sip_application_avp.spec.s); return -1; } if (pv_get_avp_name(0, &(avp_spec.pvp), &(sip_application_avp.name), &(sip_application_avp.type))!=0) { LOG(L_CRIT, "invalid AVP specification for sip_application_avp: `%s'\n", sip_application_avp.spec.s); return -1; } // bind to the dialog API if (load_dlg_api(&dlg_api)!=0) { LOG(L_CRIT, "cannot load the dialog module API\n"); return -1; } // load dlg_flag and default_timeout parameters from the dialog module param = find_param_export(find_module_by_name("dialog"), "dlg_flag", INT_PARAM, &type); if (!param) { LOG(L_CRIT, "cannot find dlg_flag parameter in the dialog module\n"); return -1; } if (type != INT_PARAM) { LOG(L_CRIT, "dlg_flag parameter found but with wrong type: %d\n", type); return -1; } dialog_flag = *param; // register dialog creation callback if (dlg_api.register_dlgcb(NULL, DLGCB_CREATED, __dialog_created, NULL, NULL) != 0) { LOG(L_CRIT, "cannot register callback for dialog creation\n"); return -1; } // register dialog loading callback if (dlg_api.register_dlgcb(NULL, DLGCB_LOADED, __dialog_loaded, NULL, NULL) != 0) { LOG(L_ERR, "cannot register callback for dialogs loaded from the database\n"); } // register a pre-script callback to automatically enable dialog tracing if (register_script_cb(postprocess_request, POST_SCRIPT_CB|REQUEST_CB, 0) != 0) { LOG(L_CRIT, "ERROR:call_control:mod_init: could not register request postprocessing callback\n"); return -1; } return 0; }
static int mod_init(void) { unsigned int n; LM_INFO("Dialog module - initializing\n"); if (timeout_spec.s) timeout_spec.len = strlen(timeout_spec.s); init_db_url( db_url , 1 /*can be null*/); dlg_id_column.len = strlen(dlg_id_column.s); call_id_column.len = strlen(call_id_column.s); from_uri_column.len = strlen(from_uri_column.s); from_tag_column.len = strlen(from_tag_column.s); to_uri_column.len = strlen(to_uri_column.s); to_tag_column.len = strlen(to_tag_column.s); state_column.len = strlen(state_column.s); start_time_column.len = strlen(start_time_column.s); timeout_column.len = strlen(timeout_column.s); to_cseq_column.len = strlen(to_cseq_column.s); from_cseq_column.len = strlen(from_cseq_column.s); to_route_column.len = strlen(to_route_column.s); from_route_column.len = strlen(from_route_column.s); to_contact_column.len = strlen(to_contact_column.s); from_contact_column.len = strlen(from_contact_column.s); to_sock_column.len = strlen(to_sock_column.s); from_sock_column.len = strlen(from_sock_column.s); profiles_column.len = strlen(profiles_column.s); vars_column.len = strlen(vars_column.s); sflags_column.len = strlen(sflags_column.s); dialog_table_name.len = strlen(dialog_table_name.s); /* param checkings */ if( log_profile_hash_size <= 0) { LM_ERR("invalid value for log_profile_hash_size:%d!!\n", log_profile_hash_size); return -1; } if (rr_param.s==0 || rr_param.s[0]==0) { LM_ERR("empty rr_param!!\n"); return -1; } rr_param.len = strlen(rr_param.s); if (rr_param.len>MAX_DLG_RR_PARAM_NAME) { LM_ERR("rr_param too long (max=%d)!!\n", MAX_DLG_RR_PARAM_NAME); return -1; } if (timeout_spec.s) { if ( pv_parse_spec(&timeout_spec, &timeout_avp)==0 && (timeout_avp.type!=PVT_AVP)){ LM_ERR("malformed or non AVP timeout " "AVP definition in '%.*s'\n", timeout_spec.len,timeout_spec.s); return -1; } } if (default_timeout<=0) { LM_ERR("0 default_timeout not accepted!!\n"); return -1; } if (ping_interval<=0) { LM_ERR("Non-positive ping interval not accepted!!\n"); return -1; } /* update the len of the extra headers */ if (dlg_extra_hdrs.s) dlg_extra_hdrs.len = strlen(dlg_extra_hdrs.s); if (seq_match_mode!=SEQ_MATCH_NO_ID && seq_match_mode!=SEQ_MATCH_FALLBACK && seq_match_mode!=SEQ_MATCH_STRICT_ID ) { LM_ERR("invalid value %d for seq_match_mode param!!\n",seq_match_mode); return -1; } /* if statistics are disabled, prevent their registration to core */ if (dlg_enable_stats==0) exports.stats = 0; /* we are only interested in these parameters if the cachedb url was defined */ if (cdb_url.s) { cdb_url.len = strlen(cdb_url.s); if (init_cachedb_utils() <0) { LM_ERR("cannot init cachedb utils\n"); return -1; } cdb_val_prefix.len = strlen(cdb_val_prefix.s); cdb_noval_prefix.len = strlen(cdb_noval_prefix.s); cdb_size_prefix.len = strlen(cdb_size_prefix.s); } /* create profile hashes */ if (add_profile_definitions( profiles_nv_s, 0)!=0 ) { LM_ERR("failed to add profiles without value\n"); return -1; } if (add_profile_definitions( profiles_wv_s, 1)!=0 ) { LM_ERR("failed to add profiles with value\n"); return -1; } /* load the TM API */ if (load_tm_api(&d_tmb)!=0) { LM_ERR("can't load TM API\n"); return -1; } /* load RR API also */ if (load_rr_api(&d_rrb)!=0) { LM_ERR("can't load RR API\n"); return -1; } /* register callbacks*/ /* listen for all incoming requests */ if ( d_tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, dlg_onreq, 0, 0 ) <=0 ) { LM_ERR("cannot register TMCB_REQUEST_IN callback\n"); return -1; } /* listen for all routed requests */ if ( d_rrb.register_rrcb( dlg_onroute, 0, 1 ) <0 ) { LM_ERR("cannot register RR callback\n"); return -1; } if (register_script_cb( dialog_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB,0)<0) { LM_ERR("cannot regsiter script callback"); return -1; } if (accept_replicated_dlg && bin_register_cb("dialog", receive_binary_packet) < 0) { LM_ERR("Cannot register binary packet callback!\n"); return -1; } if (dlg_have_own_timer_proc) { LM_INFO("Running with dedicated dialog timer process\n"); dlg_own_timer_proc = register_timer_process( "dlg-timer", dlg_timer_routine, NULL,1,TIMER_PROC_INIT_FLAG ); if (dlg_own_timer_proc == NULL) { LM_ERR("Failed to init dialog own timer proc\n"); return -1; } if (append_timer_to_process("dlg-pinger", dlg_ping_routine, NULL, ping_interval,dlg_own_timer_proc) < 0) { LM_ERR("Failed to append ping timer \n"); return -1; } } else { if ( register_timer( "dlg-timer", dlg_timer_routine, NULL, 1)<0 ) { LM_ERR("failed to register timer \n"); return -1; } if ( register_timer( "dlg-pinger", dlg_ping_routine, NULL, ping_interval)<0) { LM_ERR("failed to register timer 2 \n"); return -1; } } /* init handlers */ init_dlg_handlers(timeout_spec.s?&timeout_avp:0, default_timeout); /* init timer */ if (init_dlg_timer(dlg_ontimeout)!=0) { LM_ERR("cannot init timer list\n"); return -1; } if (init_dlg_ping_timer()!=0) { LM_ERR("cannot init ping timer\n"); return -1; } /* initialized the hash table */ for( n=0 ; n<(8*sizeof(n)) ; n++) { if (dlg_hash_size==(1<<n)) break; if (dlg_hash_size<(1<<n)) { LM_WARN("hash_size is not a power " "of 2 as it should be -> rounding from %d to %d\n", dlg_hash_size, 1<<(n-1)); dlg_hash_size = 1<<(n-1); break; } } if ( init_dlg_table(dlg_hash_size)<0 ) { LM_ERR("failed to create hash table\n"); return -1; } /* if a database should be used to store the dialogs' information */ if (dlg_db_mode==DB_MODE_NONE) { db_url.s = 0; db_url.len = 0; } else { if (dlg_db_mode!=DB_MODE_REALTIME && dlg_db_mode!=DB_MODE_DELAYED && dlg_db_mode!=DB_MODE_SHUTDOWN ) { LM_ERR("unsupported db_mode %d\n", dlg_db_mode); return -1; } if ( !db_url.s || db_url.len==0 ) { LM_ERR("db_url not configured for db_mode %d\n", dlg_db_mode); return -1; } if (init_dlg_db(&db_url, dlg_hash_size, db_update_period)!=0) { LM_ERR("failed to initialize the DB support\n"); return -1; } run_load_callbacks(); } /* if profiles should be kept in cachedb's */ destroy_dlg_callbacks( DLGCB_LOADED ); destroy_cachedb(0); return 0; }
static int mod_init(void) { unsigned int n; if (register_mi_mod(exports.name, mi_cmds) != 0) { LM_ERR("failed to register MI commands\n"); return -1; } if (rpc_register_array(rpc_methods) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } if (dialog_ng_stats_init() != 0) { LM_ERR("Failed to register dialog_ng counters\n"); return -1; } if (faked_msg_init() < 0) return -1; if (timeout_spec.s) timeout_spec.len = strlen(timeout_spec.s); dlg_bridge_controller.len = strlen(dlg_bridge_controller.s); /* param checkings */ if (dlg_flag == -1) { LM_ERR("no dlg flag set!!\n"); return -1; } else if (dlg_flag > MAX_FLAG) { LM_ERR("invalid dlg flag %d!!\n", dlg_flag); return -1; } if (rr_param == 0 || rr_param[0] == 0) { LM_ERR("empty rr_param!!\n"); return -1; } else if (strlen(rr_param) > MAX_DLG_RR_PARAM_NAME) { LM_ERR("rr_param too long (max=%d)!!\n", MAX_DLG_RR_PARAM_NAME); return -1; } if (timeout_spec.s) { if (pv_parse_spec(&timeout_spec, &timeout_avp) == 0 && (timeout_avp.type != PVT_AVP)) { LM_ERR("malformed or non AVP timeout " "AVP definition in '%.*s'\n", timeout_spec.len, timeout_spec.s); return -1; } } if (default_timeout <= 0) { LM_ERR("0 default_timeout not accepted!!\n"); return -1; } if (ruri_pvar_param.s == NULL || *ruri_pvar_param.s == '\0') { LM_ERR("invalid r-uri PV string\n"); return -1; } ruri_pvar_param.len = strlen(ruri_pvar_param.s); if (pv_parse_format(&ruri_pvar_param, &ruri_param_model) < 0 || ruri_param_model == NULL) { LM_ERR("malformed r-uri PV string: %s\n", ruri_pvar_param.s); return -1; } /* update the len of the extra headers */ if (dlg_extra_hdrs.s) dlg_extra_hdrs.len = strlen(dlg_extra_hdrs.s); if (seq_match_mode != SEQ_MATCH_NO_ID && seq_match_mode != SEQ_MATCH_FALLBACK && seq_match_mode != SEQ_MATCH_STRICT_ID) { LM_ERR("invalid value %d for seq_match_mode param!!\n", seq_match_mode); return -1; } if (detect_spirals != 0 && detect_spirals != 1) { LM_ERR("invalid value %d for detect_spirals param!!\n", detect_spirals); return -1; } /* create profile hashes */ if (add_profile_definitions(profiles_nv_s, 0) != 0) { LM_ERR("failed to add profiles without value\n"); return -1; } if (add_profile_definitions(profiles_wv_s, 1) != 0) { LM_ERR("failed to add profiles with value\n"); return -1; } /* load the TM API */ if (load_tm_api(&d_tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } /* load RR API also */ if (load_rr_api(&d_rrb) != 0) { LM_ERR("can't load RR API\n"); return -1; } /* register callbacks*/ /* listen for all incoming requests */ if (d_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, dlg_onreq, 0, 0) <= 0) { LM_ERR("cannot register TMCB_REQUEST_IN callback\n"); return -1; } /* listen for all routed requests */ if (d_rrb.register_rrcb(dlg_onroute, 0) < 0) { LM_ERR("cannot register RR callback\n"); return -1; } if (register_script_cb(profile_cleanup, POST_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("cannot regsiter script callback"); return -1; } if (register_script_cb(dlg_cfg_cb, PRE_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("cannot regsiter pre-script ctx callback\n"); return -1; } if (register_script_cb(dlg_cfg_cb, POST_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("cannot regsiter post-script ctx callback\n"); return -1; } if (register_script_cb(spiral_detect_reset, POST_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("cannot register req pre-script spiral detection reset callback\n"); return -1; } if (register_timer(dlg_timer_routine, 0, 1) < 0) { LM_ERR("failed to register timer \n"); return -1; } /*for testing only!!!! setup timer to call print all dlg every 10 seconds!*/ if (register_timer(print_all_dlgs, 0, 10) < 0) { LM_ERR("failed to register timer \n"); return -1; } /* init handlers */ init_dlg_handlers(rr_param, dlg_flag, timeout_spec.s ? &timeout_avp : 0, default_timeout, seq_match_mode); /* init timer */ if (init_dlg_timer(dlg_ontimeout) != 0) { LM_ERR("cannot init timer list\n"); return -1; } /* sanitize dlg_hash_zie */ if (dlg_hash_size < 1) { LM_WARN("hash_size is smaller " "then 1 -> rounding from %d to 1\n", dlg_hash_size); dlg_hash_size = 1; } /* initialized the hash table */ for (n = 0; n < (8 * sizeof (n)); n++) { if (dlg_hash_size == (1 << n)) break; if (n && dlg_hash_size < (1 << n)) { LM_WARN("hash_size is not a power " "of 2 as it should be -> rounding from %d to %d\n", dlg_hash_size, 1 << (n - 1)); dlg_hash_size = 1 << (n - 1); } } if (init_dlg_table(dlg_hash_size) < 0) { LM_ERR("failed to create hash table\n"); return -1; } /* if a database should be used to store the dialogs' information */ dlg_db_mode = dlg_db_mode_param; if (dlg_db_mode==DB_MODE_NONE) { db_url.s = 0; db_url.len = 0; } else { if (dlg_db_mode!=DB_MODE_REALTIME && dlg_db_mode!=DB_MODE_DELAYED && dlg_db_mode!=DB_MODE_SHUTDOWN ) { LM_ERR("unsupported db_mode %d\n", dlg_db_mode); return -1; } if ( !db_url.s || db_url.len==0 ) { LM_ERR("db_url not configured for db_mode %d\n", dlg_db_mode); return -1; } if (init_dlg_db(&db_url, dlg_hash_size, db_update_period, db_fetch_rows)!=0) { LM_ERR("failed to initialize the DB support\n"); return -1; } run_load_callbacks(); } destroy_dlg_callbacks(DLGCB_LOADED); return 0; }