static int mod_init(void) { void *timer; 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 = (own_timer_proc<=1)?1:own_timer_proc ; /* 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 */ if (own_timer_proc) { for ( set=0 ; set<timer_sets ; set++ ) { timer = register_timer_process( "tm-timer", timer_routine, (void*)(long)set, 1, TIMER_PROC_INIT_FLAG); if (timer==NULL) { LM_ERR("failed to register timer for set %d\n",set); return -1; } if (append_utimer_to_process( "tm-utimer", utimer_routine, (void*)(long)set, 100*1000, timer)<0) { LM_ERR("failed to register utimer for set %d\n",set); return -1; } } } else { if (register_timer( "tm-timer", timer_routine , 0, 1 )<0) { LM_ERR("failed to register timer\n"); return -1; } if (register_utimer( "tm-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(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; } 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; }
/* initialize ratelimit module */ static int mod_init(void) { int i; LM_DBG("initializing ...\n"); rl_lock = lock_alloc(); if (! rl_lock) { LM_ERR("oom in lock_alloc()\n"); return -1; } if (lock_init(rl_lock)==0) { LM_ERR("failed to init lock\n"); return -1; } /* register timer to reset counters */ if (register_timer_process(rl_timer, NULL, timer_interval, TIMER_PROC_INIT_FLAG) == NULL) { LM_ERR("could not register timer function\n"); return -1; } /* load the SIGNALLING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } network_load_value = shm_malloc(sizeof(int)); if (network_load_value==NULL) { LM_ERR("oom for network_load_value\n"); return -1; } check_network_load = shm_malloc(sizeof(int)); if (check_network_load==NULL) { LM_ERR("oom for check_network_load\n"); return -1; } load_value = shm_malloc(sizeof(double)); if (load_value==NULL) { LM_ERR("oom for load_value\n"); return -1; } load_source = shm_malloc(sizeof(int)); if (load_source==NULL) { LM_ERR("oom for load_source\n"); return -1; } pid_kp = shm_malloc(sizeof(double)); if (pid_kp==NULL) { LM_ERR("oom for pid_kp\n"); return -1; } pid_ki = shm_malloc(sizeof(double)); if (pid_ki==NULL) { LM_ERR("oom for pid_ki\n"); return -1; } pid_kd = shm_malloc(sizeof(double)); if (pid_kd==NULL) { LM_ERR("oom for pid_kd\n"); return -1; } pid_setpoint = shm_malloc(sizeof(double)); if (pid_setpoint==NULL) { LM_ERR("oom for pid_setpoint\n"); return -1; } drop_rate = shm_malloc(sizeof(int)); if (drop_rate==NULL) { LM_ERR("oom for drop_rate\n"); return -1; } nqueues = shm_malloc(sizeof(int)); if (nqueues==NULL) { LM_ERR("oom for nqueues\n"); return -1; } rl_dbg_str = shm_malloc(sizeof(str)); if (rl_dbg_str==NULL) { LM_ERR("oom for rl_dbg_str\n"); return -1; } *network_load_value = 0; *check_network_load = 0; *load_value = 0.0; *load_source = load_source_mp; *pid_kp = 0.0; *pid_ki = -25.0; *pid_kd = 0.0; *pid_setpoint = 0.01 * (double)cfg_setpoint; *drop_rate = 0; *nqueues = nqueues_mp; rl_dbg_str->s = NULL; rl_dbg_str->len = 0; for (i=0; i<MAX_PIPES; i++) { pipes[i].algo = shm_malloc(sizeof(int)); if (pipes[i].algo==NULL) { LM_ERR("oom for pipes[%d].algo\n", i); return -1; } pipes[i].limit = shm_malloc(sizeof(int)); if (pipes[i].limit==NULL) { LM_ERR("oom for pipes[%d].limit\n", i); return -1; } pipes[i].load = shm_malloc(sizeof(int)); if (pipes[i].load==NULL) { LM_ERR("oom for pipes[%d].load\n", i); return -1; } pipes[i].counter = shm_malloc(sizeof(int)); if (pipes[i].counter==NULL) { LM_ERR("oom for pipes[%d].counter\n", i); return -1; } pipes[i].last_counter = shm_malloc(sizeof(int)); if (pipes[i].last_counter==NULL) { LM_ERR("oom for pipes[%d].last_counter\n", i); return -1; } *pipes[i].algo = pipes[i].algo_mp; *pipes[i].limit = pipes[i].limit_mp; *pipes[i].load = 0; *pipes[i].counter = 0; *pipes[i].last_counter = 0; } for (i=0; i<*nqueues; i++) { queues[i].pipe = shm_malloc(sizeof(int)); if (queues[i].pipe==NULL) { LM_ERR("oom for queues[%d].pipe\n", i); return -1; } queues[i].method = shm_malloc(sizeof(str)); if (queues[i].method==NULL) { LM_ERR("oom for queues[%d].method\n", i); return -1; } *queues[i].pipe = queues[i].pipe_mp; if (queues[i].method_mp.s == NULL) { LM_ERR("unexpected NULL method for queues[%d].method_mp\n", i); return -1; } if(str_cpy(queues[i].method, &queues[i].method_mp)) { LM_ERR("oom str_cpy(queues[%d].method\n", i); return -1; } pkg_free(queues[i].method_mp.s); queues[i].method_mp.s = NULL; queues[i].method_mp.len = 0; } set_check_network_load(); rl_drop_reason.len = strlen(rl_drop_reason.s); return 0; }