int rl_repl_init(void) { int index; if (rl_buffer_th > (BUF_SIZE * 0.9)) { LM_WARN("Buffer size too big %d - pipe information might get lost", rl_buffer_th); return -1; } if (rl_dests_nr && bin_register_cb("ratelimit", rl_rcv_bin) < 0) { LM_ERR("Cannot register binary packet callback!\n"); return -1; } /* alocate the last_message counter in shared memory */ for (index = 0; index < rl_dests_nr; index++) { rl_dests[index].last_msg = shm_malloc(sizeof(time_t)); if (!rl_dests[index].last_msg) { LM_ERR("OOM shm\n"); return -1; } } return 0; }
int rl_repl_init(void) { if (rl_buffer_th > (BUF_SIZE * 0.9)) { LM_WARN("Buffer size too big %d - pipe information might get lost", rl_buffer_th); return -1; } if (accept_repl_pipes && bin_register_cb("ratelimit", rl_rcv_bin) < 0) { LM_ERR("Cannot register binary packet callback!\n"); return -1; } return 0; }
static int cl_register_module(char *mod_name, int proto, void (*cb)(int, struct receive_info *, int), int timeout, int auth_check, int accept_cluster_id) { struct module_list *new_module; LM_DBG("register module %s\n", mod_name); if (auth_check && !accept_cluster_id) { LM_ERR("provided bad cluster_id\n"); return -1; } new_module = shm_malloc(sizeof *new_module); if (!new_module) { LM_ERR("insufficient shm memory\n"); return -1; } new_module->mod_name.len = strlen(mod_name); new_module->mod_name.s = mod_name; new_module->proto = proto; new_module->cb = cb; new_module->timeout = timeout; new_module->auth_check = auth_check; new_module->accept_cluster_id = accept_cluster_id; new_module->duration = 2 * timeout; new_module->next = NULL; switch (proto) { case PROTO_BIN: bin_register_cb(mod_name, bin_receive_packets, new_module); break; default: LM_ERR("unidentified protocol\n"); shm_free(new_module); return -1; } new_module->values = NULL; new_module->next = clusterer_modules; clusterer_modules = new_module; 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; }
/*! \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; }
static int mod_init(void) { int heartbeats_timer_interval; cluster_info_t *cl; LM_INFO("Clusterer module - initializing\n"); db_table.len = strlen(db_table.s); id_col.len = strlen(id_col.s); cluster_id_col.len = strlen(cluster_id_col.s); node_id_col.len = strlen(node_id_col.s); url_col.len = strlen(url_col.s); state_col.len = strlen(state_col.s); no_ping_retries_col.len = strlen(no_ping_retries_col.s); priority_col.len = strlen(priority_col.s); sip_addr_col.len = strlen(sip_addr_col.s); flags_col.len = strlen(flags_col.s); description_col.len = strlen(description_col.s); /* only allow the DB URL to be skipped in "P2P discovery" mode */ init_db_url(clusterer_db_url, db_mode == 0); if (current_id < 1) { LM_CRIT("Invalid 'my_node_id' parameter\n"); return -1; } if (ping_interval <= 0) { LM_WARN("Invalid ping_interval parameter, using default value\n"); ping_interval = DEFAULT_PING_INTERVAL; } if (node_timeout < 0) { LM_WARN("Invalid node_timeout parameter, using default value\n"); node_timeout = DEFAULT_NODE_TIMEOUT; } if (ping_timeout <= 0) { LM_WARN("Invalid ping_timeout parameter, using default value\n"); ping_timeout = DEFAULT_PING_TIMEOUT; } /* create & init lock */ if ((cl_list_lock = lock_init_rw()) == NULL) { LM_CRIT("Failed to init lock\n"); return -1; } /* data pointer in shm */ if (cluster_list == NULL) { cluster_list = shm_malloc(sizeof *cluster_list); if (!cluster_list) { LM_CRIT("No more shm memory\n"); goto error; } *cluster_list = NULL; } else { /* sanity check of my_node_id if node_id also set in a my_node_info param */ for (cl = *cluster_list; cl; cl = cl->next) if (cl->current_node->node_id != current_id) { LM_ERR("Bad 'my_node_id' parameter, value: %d different than" " the node_id property in the 'my_node_info' parameter\n", current_id); goto error; } } if (db_mode) { /* bind to the mysql module */ if (db_bind_mod(&clusterer_db_url, &dr_dbf)) { LM_CRIT("Cannot bind to database module! " "Did you forget to load a database module ?\n"); goto error; } if (!DB_CAPABILITY(dr_dbf, DB_CAP_QUERY)) { LM_CRIT("Given SQL DB does not provide query types needed by this module!\n"); goto error; } /* init DB connection */ if ((db_hdl = dr_dbf.init(&clusterer_db_url)) == 0) { LM_ERR("cannot initialize database connection\n"); goto error; } if (load_db_info(&dr_dbf, db_hdl, &db_table, cluster_list) < 0) { LM_ERR("Failed to load info from DB\n"); goto error; } } /* register timer */ heartbeats_timer_interval = gcd(ping_interval*1000, ping_timeout); heartbeats_timer_interval = gcd(heartbeats_timer_interval, node_timeout*1000); if (heartbeats_timer_interval % 1000 == 0) { if (register_timer("clstr-heartbeats-timer", heartbeats_timer_handler, NULL, heartbeats_timer_interval/1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_CRIT("Unable to register clusterer heartbeats timer\n"); goto error; } } else { if (register_utimer("clstr-heartbeats-utimer", heartbeats_utimer_handler, NULL, heartbeats_timer_interval*1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_CRIT("Unable to register clusterer heartbeats timer\n"); goto error; } } if (bin_register_cb(&cl_internal_cap, bin_rcv_cl_packets, NULL) < 0) { LM_CRIT("Cannot register clusterer binary packet callback!\n"); goto error; } if (bin_register_cb(&cl_extra_cap, bin_rcv_cl_extra_packets, NULL) < 0) { LM_CRIT("Cannot register extra clusterer binary packet callback!\n"); goto error; } /* create generic message receiving events */ if (gen_rcv_evs_init() < 0) { LM_ERR("cannot create cluster message received event\n"); return -1; } return 0; error: lock_destroy_rw(cl_list_lock); cl_list_lock = NULL; if (cluster_list) { shm_free(cluster_list); cluster_list = 0; } return -1; }