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; }
/** * 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; }
int init_stats_collector(void) { /* init the collector */ collector = (stats_collector*)shm_malloc(sizeof(stats_collector)); if (collector==0) { LM_ERR("no more shm mem\n"); goto error; } memset( collector, 0 , sizeof(stats_collector)); #ifdef NO_ATOMIC_OPS /* init BIG (really BIG) lock */ stat_lock = lock_alloc(); if (stat_lock==0 || lock_init( stat_lock )==0 ) { LM_ERR("failed to init the really BIG lock\n"); goto error; } #endif /* register MI commands */ if (register_mi_mod( "statistics", mi_stat_cmds)<0) { LM_ERR("unable to register MI cmds\n"); goto error; } /* register core statistics */ if (register_module_stats( "core", core_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); goto error; } /* register sh_mem statistics */ if (register_module_stats( "shmem", shm_stats)!=0 ) { LM_ERR("failed to register sh_mem statistics\n"); goto error; } /* register sh_mem statistics */ if (register_module_stats( "net", net_stats)!=0 ) { LM_ERR("failed to register network statistics\n"); goto error; } LM_DBG("statistics manager successfully initialized\n"); return 0; error: return -1; }
int sl_register_kstats(void) { #ifdef STATISTICS /* register statistics */ if (register_module_stats("sl", mod_stats)!=0 ) { LM_ERR("failed to register statistics\n"); return -1; } #endif 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 /* 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; }
static int init_mod( struct sr_module* m ) { if (m) { /* iterate through the list; if error occurs, propagate it up the stack */ if (init_mod(m->next)!=0) return -1; if (m->exports==0) return 0; if (m->exports->init_f) { LM_DBG("initializing module %s\n", m->exports->name); if (m->exports->init_f()!=0) { LM_ERR("failed to initialize" " module %s\n", m->exports->name); return -1; } } /* no init function -- proceed further */ #ifdef STATISTICS if (m->exports->stats) { LM_DBG("registering stats for %s\n", m->exports->name); if (register_module_stats(m->exports->name,m->exports->stats)!=0) { LM_ERR("failed to registering " "statistics for module %s\n", m->exports->name); return -1; } } #endif /* register MI functions */ if (m->exports->mi_cmds) { LM_DBG("register MI for %s\n", m->exports->name); if (register_mi_mod(m->exports->name,m->exports->mi_cmds)!=0) { LM_ERR("failed to register MI functions for module %s\n", m->exports->name); } } /* proceed with success */ return 0; } else { /* end of list */ 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; }
/*! \brief * Initialize parent */ static int mod_init(void) { pv_spec_t avp_spec; str s; bind_usrloc_t bind_usrloc; qvalue_t dq; if(sruid_init(&_reg_sruid, '-', "uloc", 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 /* bind the SL API */ if (sl_load_api(&slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } if(cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg, cfg_sizeof(registrar), ®istrar_cfg)){ LM_ERR("Fail to declare the configuration\n"); return -1; } if (rcv_avp_param && *rcv_avp_param) { s.s = rcv_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", rcv_avp_param); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &rcv_avp_name, &rcv_avp_type)!=0) { LM_ERR("[%s]- invalid AVP definition\n", rcv_avp_param); return -1; } } else { rcv_avp_name.n = 0; rcv_avp_type = 0; } if (reg_callid_avp_param && *reg_callid_avp_param) { s.s = reg_callid_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", reg_callid_avp_param); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, ®_callid_avp_name, ®_callid_avp_type)!=0) { LM_ERR("[%s]- invalid AVP definition\n", reg_callid_avp_param); return -1; } } else { reg_callid_avp_name.n = 0; reg_callid_avp_type = 0; } bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } /* Normalize default_q parameter */ dq = cfg_get(registrar, registrar_cfg, default_q); if ( dq!= Q_UNSPECIFIED) { if (dq > MAX_Q) { LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q); dq = MAX_Q; } else if (dq < MIN_Q) { LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q); dq = MIN_Q; } } cfg_get(registrar, registrar_cfg, default_q) = dq; if (bind_usrloc(&ul) < 0) { return -1; } if(ul.register_ulcb != NULL) { reg_expire_event_rt = route_lookup(&event_rt, "usrloc:contact-expired"); if (reg_expire_event_rt>=0 && event_rt.rlist[reg_expire_event_rt]==0) reg_expire_event_rt=-1; /* disable */ if (reg_expire_event_rt>=0) { set_child_rpc_sip_mode(); if(ul.register_ulcb(UL_CONTACT_EXPIRE, reg_ul_expired_contact, 0)< 0) { LM_ERR("can not register callback for expired contacts\n"); return -1; } } } /* * Import use_domain parameter from usrloc */ reg_use_domain = ul.use_domain; if (sock_hdr_name.s) { if (sock_hdr_name.len==0 || sock_flag==-1) { LM_WARN("empty sock_hdr_name or sock_flag no set -> reseting\n"); sock_hdr_name.len = 0; sock_flag = -1; } } else if (sock_flag!=-1) { LM_WARN("sock_flag defined but no sock_hdr_name -> reseting flag\n"); sock_flag = -1; } if (reg_outbound_mode < 0 || reg_outbound_mode > 2) { LM_ERR("outbound_mode modparam must be 0 (not supported), 1 (supported), or 2 (supported and required)\n"); return -1; } if (reg_regid_mode < 0 || reg_regid_mode > 1) { LM_ERR("regid_mode modparam must be 0 (use with outbound), 1 (use always)\n"); return -1; } if (reg_flow_timer < 0 || reg_flow_timer > REG_FLOW_TIMER_MAX || (reg_flow_timer > 0 && reg_outbound_mode == REG_OUTBOUND_NONE)) { LM_ERR("bad value for flow_timer\n"); return -1; } /* fix the flags */ sock_flag = (sock_flag!=-1)?(1<<sock_flag):0; tcp_persistent_flag = (tcp_persistent_flag!=-1)?(1<<tcp_persistent_flag):0; return 0; }
static int mod_init(void) { registration_default_algorithm_type = get_algorithm_type(registration_default_algorithm); #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } if (!register_stats()){ LM_ERR("Unable to register statistics\n"); return -1; } #endif /* check the max_nonce_reuse param */ if (auth_used_vector_timeout < 0) { LM_WARN("bad value for auth_used_vector_timeout parameter (=%d), must be positive. Fixed to 3600\n", auth_used_vector_timeout); auth_used_vector_timeout = 3600; } /* check the max_nonce_reuse param */ if (max_nonce_reuse < 0) { LM_WARN("bad value for max_nonce_reuse parameter (=%d), must be positive. Fixed to 0\n", max_nonce_reuse); max_nonce_reuse = 0; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); return -1; } /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } /* Init the authorization data storage */ if (!auth_data_init(auth_data_hash_size)) { LM_ERR("Unable to init auth data\n"); return -1; } /* set default qop */ if (registration_qop.s && registration_qop.len > 0) { registration_qop_str.len = s_qop_s.len + registration_qop.len + s_qop_e.len; registration_qop_str.s = pkg_malloc(registration_qop_str.len); if (!registration_qop_str.s) { LM_ERR("Error allocating %d bytes\n", registration_qop_str.len); registration_qop_str.len = 0; return 0; } registration_qop_str.len = 0; STR_APPEND(registration_qop_str, s_qop_s); memcpy(registration_qop_str.s + registration_qop_str.len, registration_qop.s, registration_qop.len); registration_qop_str.len += registration_qop.len; STR_APPEND(registration_qop_str, s_qop_e); } else { registration_qop_str.len = 0; registration_qop_str.s = 0; } /* Register the auth vector timer */ if (register_timer(reg_await_timer, auth_data, 10) < 0) { LM_ERR("Unable to register auth vector timer\n"); return -1; } return 0; }
/** * The initialization function, called when the module is loaded by * the script. This function is called only once. * * Bind to the dialog module and setup the callbacks. Also initialize * the shared memory to store our interninal information in. * * @return 0 to continue to load the Kamailio, -1 to stop the loading * and abort Kamailio. */ static int mod_init(void) { str s; /* if statistics are disabled, prevent their registration to core. */ if (sst_enable_stats==0) { exports.stats = 0; } #ifdef STATISTICS /* register statistics */ if (sst_enable_stats!=0) { if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } } #endif if (sst_flag == -1) { LM_ERR("no sst flag set!!\n"); return -1; } else if (sst_flag > MAX_FLAG) { LM_ERR("invalid sst flag %d!!\n", sst_flag); return -1; } if (timeout_spec != NULL) { LM_DBG("Dialog AVP is %s", timeout_spec); s.s = timeout_spec; s.len = strlen(s.s); if (pv_parse_spec(&s, &timeout_avp)==0 && (timeout_avp.type != PVT_AVP)){ LM_ERR("malformed or non AVP timeout AVP definition in '%s'\n", timeout_spec); return -1; } } /* bind the SL API */ if (sl_load_api(&slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* Init the handlers */ sst_handler_init((timeout_spec?&timeout_avp:0), sst_minSE, sst_flag, sst_reject); /* Register the main (static) dialog call back. */ if (load_dlg_api(&dialog_st) != 0) { LM_ERR("failed to load dialog hooks"); return(-1); } /* Load dialog hooks */ dialog_st.register_dlgcb(NULL, DLGCB_CREATED, sst_dialog_created_CB, NULL, NULL); return 0; }
static int mod_init(void) { #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, imc_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif if(imc_rpc_init()<0) { LM_ERR("failed to register RPC commands\n"); return -1; } if(imc_hash_size <= 0) { LM_ERR("invalid hash size\n"); return -1; } imc_hash_size = 1 << imc_hash_size; if(imc_htable_init() < 0) { LM_ERR("initializing hash table\n"); return -1; } if (extra_hdrs.s) { if (extra_hdrs.len + imc_hdr_ctype.len > 1024) { LM_ERR("extra_hdrs too long\n"); return -1; } all_hdrs.s = &(hdr_buf[0]); memcpy(all_hdrs.s, imc_hdr_ctype.s, imc_hdr_ctype.len); memcpy(all_hdrs.s + imc_hdr_ctype.len, extra_hdrs.s, extra_hdrs.len); all_hdrs.len = extra_hdrs.len + imc_hdr_ctype.len; } else { all_hdrs = imc_hdr_ctype; } /* binding to mysql module */ LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s); if (db_bind_mod(&db_url, &imc_dbf)) { LM_DBG("database module not found\n"); return -1; } imc_db = imc_dbf.init(&db_url); if (!imc_db) { LM_ERR("failed to connect to the database\n"); return -1; } /* read the informations stored in db */ if(add_from_db() <0) { LM_ERR("failed to get information from db\n"); return -1; } /* load TM API */ if (load_tm_api(&tmb)!=0) { LM_ERR("unable to load tm api\n"); return -1; } imc_cmd_start_char = imc_cmd_start_str.s[0]; if(imc_db) imc_dbf.close(imc_db); imc_db = NULL; return 0; }
static int init_mod( struct sr_module* m, int skip_others) { struct sr_module_dep *dep; if (m) { /* iterate through the list; if error occurs, propagate it up the stack */ if (!skip_others && init_mod(m->next, 0) != 0) return -1; /* our module might have been already init'ed through dependencies! */ if (m->init_done) return 0; if (!m->exports) return 0; /* make sure certain modules get loaded before this one */ for (dep = m->sr_deps; dep; dep = dep->next) { if (!dep->mod->init_done) if (init_mod(dep->mod, 1) != 0) return -1; } if (m->exports->init_f) { LM_DBG("initializing module %s\n", m->exports->name); if (m->exports->init_f()!=0) { LM_ERR("failed to initialize module %s\n", m->exports->name); return -1; } } m->init_done = 1; /* no init function -- proceed further */ #ifdef STATISTICS if (m->exports->stats) { LM_DBG("registering stats for %s\n", m->exports->name); if (register_module_stats(m->exports->name,m->exports->stats)!=0) { LM_ERR("failed to registering " "statistics for module %s\n", m->exports->name); return -1; } } #endif /* register MI functions */ if (m->exports->mi_cmds) { LM_DBG("register MI for %s\n", m->exports->name); if (register_mi_mod(m->exports->name,m->exports->mi_cmds)!=0) { LM_ERR("failed to register MI functions for module %s\n", m->exports->name); } } /* proceed with success */ return 0; } else { /* end of list */ return 0; } }
static int mod_init(void) { int n; load_dlg_f load_dlg; load_tm_f load_tm; bind_usrloc_t bind_usrloc; if (!fix_parameters()) { LM_ERR("unable to set Ro configuration parameters correctly\n"); goto error; } /* bind to the tm module */ if (!(load_tm = (load_tm_f) find_export("load_tm", NO_SCRIPT, 0))) { LM_ERR("Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; if (!(load_dlg = (load_dlg_f) find_export("load_dlg", 0, 0))) { /* bind to dialog module */ LM_ERR("can not import load_dlg. This module requires Kamailio dialog module.\n"); } if (load_dlg(&dlgb) == -1) { goto error; } if (load_cdp_api(&cdpb) != 0) { /* load the CDP API */ LM_ERR("can't load CDP API\n"); goto error; } if (load_dlg_api(&dlgb) != 0) { /* load the dialog API */ LM_ERR("can't load Dialog API\n"); goto error; } cdp_avp = load_cdp_avp(); /* load CDP_AVP API */ if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); goto error; } /* init timer lists*/ if (init_ro_timer(ro_session_ontimeout) != 0) { LM_ERR("cannot init timer list\n"); return -1; } /* initialized the hash table */ for (n = 0; n < (8 * sizeof(n)); n++) { if (ro_session_hash_size == (1 << n)) break; if (ro_session_hash_size < (1 << n)) { LM_WARN("hash_size is not a power of 2 as it should be -> rounding from %d to %d\n", ro_session_hash_size, 1 << (n - 1)); ro_session_hash_size = 1 << (n - 1); } } if (init_ro_session_table(ro_session_hash_size) < 0) { LM_ERR("failed to create ro session hash table\n"); return -1; } /* register global timer */ if (register_timer(ro_timer_routine, 0/*(void*)ro_session_list*/, 1) < 0) { LM_ERR("failed to register timer \n"); return -1; } bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } if (bind_usrloc(&ul) < 0) { return -1; } /*Register for callback of URECORD being deleted - so we can send a SAR*/ if (ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } /* register statistics */ if (register_module_stats(exports.name, charging_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } /*if (register_stat(MOD_NAME, "ccr_responses_time", &ccr_responses_time, 0)) { LM_ERR("failed to register core statistics\n"); return -1; }*/ /* if a database should be used to store the dialogs' information */ ro_db_mode = ro_db_mode_param; if (ro_db_mode == DB_MODE_NONE) { db_url.s = 0; db_url.len = 0; } else { if (ro_db_mode != DB_MODE_REALTIME && ro_db_mode != DB_MODE_SHUTDOWN) { LM_ERR("unsupported db_mode %d\n", ro_db_mode); return -1; } if (!db_url.s || db_url.len == 0) { LM_ERR("db_url not configured for db_mode %d\n", ro_db_mode); return -1; } if (init_ro_db(&db_url, ro_session_hash_size, db_update_period, db_fetch_rows) != 0) { LM_ERR("failed to initialize the DB support\n"); return -1; } // run_load_callbacks(); } return 0; error: LM_ERR("Failed to initialise ims_qos module\n"); return RO_RETURN_FALSE; }
/** * init module function */ static int mod_init(void) { /* fix the parameters */ if (!fix_parameters()) goto error; #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register core statistics\n"); goto error; } if (!register_stats()) { LM_ERR("Unable to register statistics\n"); goto error; } #endif callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; /*register space for event processor*/ register_procs(1); cdp_avp = 0; /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); goto error; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); goto error; } /* load the dialog API */ if (load_dlg_api(&dlgb) != 0) { LM_ERR("can't load Dialog API\n"); goto error; } cdp_avp = load_cdp_avp(); if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); goto error; } /* load the usrloc API */ bind_usrloc = (bind_usrloc_t) find_export("ul_bind_ims_usrloc_pcscf", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc_pcscf\n"); return CSCF_RETURN_FALSE; } if (bind_usrloc(&ul) < 0) { LM_ERR("can't bind to usrloc pcscf\n"); return CSCF_RETURN_FALSE; } LM_DBG("Successfully bound to PCSCF Usrloc module\n"); LM_DBG("Diameter RX interface successfully bound to TM, Dialog, Usrloc and CDP modules\n"); /*init cdb cb event list*/ if (!init_cdp_cb_event_list()) { LM_ERR("unable to initialise cdp callback event list\n"); return -1; } return 0; error: LM_ERR("Failed to initialise ims_qos module\n"); return CSCF_RETURN_FALSE; }
static int mod_init(void) { pv_spec_t avp_spec; str s; bind_usrloc_t bind_usrloc; qvalue_t dq; callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; /*build the required strings */ scscf_serviceroute_uri_str.s = (char*) pkg_malloc(orig_prefix.len + scscf_name_str.len); if (!scscf_serviceroute_uri_str.s) { LM_ERR("Unable to allocate memory for service route uri\n"); return -1; } if (contact_expires_buffer_percentage < 0 || contact_expires_buffer_percentage > 90) { LM_ERR("contact expires percentage not valid, must be >0 and <=90"); return -1; } memcpy(scscf_serviceroute_uri_str.s, orig_prefix.s, orig_prefix.len); scscf_serviceroute_uri_str.len = orig_prefix.len; if (scscf_name_str.len > 4 && strncasecmp(scscf_name_str.s, "sip:", 4) == 0) { memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len, scscf_name_str.s + 4, scscf_name_str.len - 4); scscf_serviceroute_uri_str.len += scscf_name_str.len - 4; } else { memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len, scscf_name_str.s, scscf_name_str.len); scscf_serviceroute_uri_str.len += scscf_name_str.len; } pv_tmx_data_init(); /* </build required strings> */ #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } if (!register_stats()) { LM_ERR("Unable to register statistics\n"); return -1; } #endif /*register space for notification processors*/ register_procs(notification_processes); cfg_register_child(notification_processes); /* bind the SL API */ if (sl_load_api(&slb) != 0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); return -1; } cdp_avp = load_cdp_avp(); if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); return -1; } if (cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg, cfg_sizeof(registrar), ®istrar_cfg)) { LM_ERR("Fail to declare the configuration\n"); return -1; } if (rcv_avp_param && *rcv_avp_param) { s.s = rcv_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", rcv_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, &rcv_avp_name, &rcv_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", rcv_avp_param); return -1; } } else { rcv_avp_name.n = 0; rcv_avp_type = 0; } if (aor_avp_param && *aor_avp_param) { s.s = aor_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", aor_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, &aor_avp_name, &aor_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", aor_avp_param); return -1; } } else { aor_avp_name.n = 0; aor_avp_type = 0; } if (reg_callid_avp_param && *reg_callid_avp_param) { s.s = reg_callid_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", reg_callid_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, ®_callid_avp_name, ®_callid_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", reg_callid_avp_param); return -1; } } else { reg_callid_avp_name.n = 0; reg_callid_avp_type = 0; } bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } /* Normalize default_q parameter */ dq = cfg_get(registrar, registrar_cfg, default_q); if (dq != Q_UNSPECIFIED) { if (dq > MAX_Q) { LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q); dq = MAX_Q; } else if (dq < MIN_Q) { LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q); dq = MIN_Q; } } cfg_get(registrar, registrar_cfg, default_q) = dq; if (bind_usrloc(&ul) < 0) { return -1; } /*Register for callback of URECORD being deleted - so we can send a SAR*/ if (ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } if (ul.register_ulcb(0, 0, UL_IMPU_INSERT, ul_impu_inserted, 0) < 0) { LM_ERR("can not register callback for insert\n"); return -1; } if (sock_hdr_name.s) { if (sock_hdr_name.len == 0 || sock_flag == -1) { LM_WARN("empty sock_hdr_name or sock_flag no set -> reseting\n"); sock_hdr_name.len = 0; sock_flag = -1; } } else if (sock_flag != -1) { LM_WARN("sock_flag defined but no sock_hdr_name -> reseting flag\n"); sock_flag = -1; } /* fix the flags */ sock_flag = (sock_flag != -1) ? (1 << sock_flag) : 0; tcp_persistent_flag = (tcp_persistent_flag != -1) ? (1 << tcp_persistent_flag) : 0; /* init the registrar notifications */ if (!notify_init()) return -1; /* register the registrar notifications timer */ //Currently we do not use this - we send notifies immediately //if (register_timer(notification_timer, notification_list, 5) < 0) return -1; return 0; }
/*! \brief Initialize sipcapture module */ static int mod_init(void) { struct ip_addr *ip = NULL; #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, sipcapture_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(sipcapture_init_rpc()!=0) { LM_ERR("failed to register RPC commands\n"); return -1; } db_url.len = strlen(db_url.s); table_name.len = strlen(table_name.s); hash_source.len = strlen (hash_source.s); mt_mode.len = strlen(mt_mode.s); date_column.len = strlen(date_column.s); micro_ts_column.len = strlen(micro_ts_column.s); method_column.len = strlen(method_column.s); reply_reason_column.len = strlen(reply_reason_column.s); ruri_column.len = strlen(ruri_column.s); ruri_user_column.len = strlen(ruri_user_column.s); from_user_column.len = strlen(from_user_column.s); from_tag_column.len = strlen(from_tag_column.s); to_user_column.len = strlen(to_user_column.s); pid_user_column.len = strlen(pid_user_column.s); contact_user_column.len = strlen(contact_user_column.s); auth_user_column.len = strlen(auth_user_column.s); callid_column.len = strlen(callid_column.s); via_1_column.len = strlen(via_1_column.s); via_1_branch_column.len = strlen(via_1_branch_column.s); cseq_column.len = strlen(cseq_column.s); diversion_column.len = strlen(diversion_column.s); reason_column.len = strlen(reason_column.s); content_type_column.len = strlen(content_type_column.s); authorization_column.len = strlen(authorization_column.s); user_agent_column.len = strlen(user_agent_column.s); source_ip_column.len = strlen(source_ip_column.s); source_port_column.len = strlen(source_port_column.s); dest_ip_column.len = strlen(dest_ip_column.s); dest_port_column.len = strlen(dest_port_column.s); contact_ip_column.len = strlen(contact_ip_column.s); contact_port_column.len = strlen(contact_port_column.s); orig_ip_column.len = strlen(orig_ip_column.s); orig_port_column.len = strlen(orig_port_column.s); proto_column.len = strlen(proto_column.s); family_column.len = strlen(family_column.s); type_column.len = strlen(type_column.s); rtp_stat_column.len = strlen(rtp_stat_column.s); node_column.len = strlen(node_column.s); msg_column.len = strlen(msg_column.s); capture_node.len = strlen(capture_node.s); if(raw_socket_listen.s) raw_socket_listen.len = strlen(raw_socket_listen.s); if(raw_interface.s) raw_interface.len = strlen(raw_interface.s); /* Find a database module */ if (db_bind_mod(&db_url, &db_funcs)) { LM_ERR("unable to bind database module\n"); return -1; } if (!DB_CAPABILITY(db_funcs, DB_CAP_INSERT)) { LM_ERR("database modules does not provide all functions needed" " by module\n"); return -1; } /*Check the table name*/ if(!table_name.len) { LM_ERR("ERROR: sipcapture: mod_init: table_name is not defined or empty\n"); return -1; } if (mt_init () <0) { return -1; } if(db_insert_mode) { LM_INFO("INFO: sipcapture: mod_init: you have enabled INSERT DELAYED \ Make sure your DB can support it\n"); } capture_on_flag = (int*)shm_malloc(sizeof(int)); if(capture_on_flag==NULL) { LM_ERR("no more shm memory left\n"); return -1; } *capture_on_flag = capture_on; /* register DGRAM event */ if(sr_event_register_cb(SREV_NET_DGRAM_IN, hep_msg_received) < 0) { LM_ERR("failed to register SREV_NET_DGRAM_IN event\n"); return -1; } if(ipip_capture_on && moni_capture_on) { LM_ERR("only one RAW mode is supported. Please disable ipip_capture_on or moni_capture_on\n"); return -1; } /* raw processes for IPIP encapsulation */ if (ipip_capture_on || moni_capture_on) { register_procs(raw_sock_children); if(extract_host_port() && (((ip=str2ip(&raw_socket_listen)) == NULL) #ifdef USE_IPV6 && ((ip=str2ip6(&raw_socket_listen)) == NULL) #endif )) { LM_ERR("sipcapture mod_init: bad RAW IP: %.*s\n", raw_socket_listen.len, raw_socket_listen.s); return -1; } if(moni_capture_on && !moni_port_start) { LM_ERR("ERROR:sipcapture:mod_init: Please define port/portrange in 'raw_socket_listen', before \ activate monitoring capture\n"); return -1; }
/*! \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) { 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; }
/** * init module function */ static int mod_init(void) { unsigned int n; LM_INFO("Initializing Http Async module\n"); #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif /* sanitize hash_size */ if (hash_size < 1){ LM_WARN("hash_size is smaller " "than 1 -> rounding from %d to 1\n", hash_size); hash_size = 1; } /* check that the hash table size is a power of 2 */ for( n=0 ; n<(8*sizeof(n)) ; n++) { if (hash_size==(1<<n)) break; if (n && hash_size<(1<<n)) { LM_WARN("hash_size is not a power " "of 2 as it should be -> rounding from %d to %d (n=%d)\n", hash_size, 1<<(n-1), n); hash_size = 1<<(n-1); break; } } /* check 'workers' param */ if (num_workers < 1) { LM_ERR("the 'workers' parameter must be >= 1\n"); return -1; } tls_verify_host = tls_verify_host?1:0; tls_verify_peer = tls_verify_peer?1:0; /* init http parameters list */ init_query_params(&ah_params); if (strncmp("shm", memory_manager, 3) == 0) { curl_memory_manager = 0; } else if (strncmp("sys", memory_manager, 3) == 0) { curl_memory_manager = 1; } else { LM_ERR("invalid memory_manager parameter: '%s'\n", memory_manager); return -1; } if (strncmp("shm", memory_manager, 3) == 0) { curl_memory_manager = 0; } else if (strncmp("sys", memory_manager, 3) == 0) { curl_memory_manager = 1; } else { LM_ERR("invalid memory_manager parameter: '%s'\n", memory_manager); return -1; } /* init faked sip msg */ if(faked_msg_init()<0) { LM_ERR("failed to init faked sip msg\n"); return -1; } if(load_tm_api( &tmb ) < 0) { LM_INFO("cannot load the TM-functions - async relay disabled\n"); memset(&tmb, 0, sizeof(tm_api_t)); } /* allocate workers array */ workers = shm_malloc(num_workers * sizeof(*workers)); if(workers == NULL) { LM_ERR("error in shm_malloc\n"); return -1; } memset(workers, 0, num_workers * sizeof(*workers)); register_procs(num_workers); /* add child to update local config framework structures */ cfg_register_child(num_workers); return 0; }
static int mod_init(void) { if (sl_load_api(&ws_slb) != 0) { LM_ERR("binding to SL\n"); goto error; } if (sr_event_register_cb(SREV_TCP_WS_FRAME_IN, ws_frame_receive) != 0) { LM_ERR("registering WebSocket receive call-back\n"); goto error; } if (sr_event_register_cb(SREV_TCP_WS_FRAME_OUT, ws_frame_transmit) != 0) { LM_ERR("registering WebSocket transmit call-back\n"); goto error; } if (register_module_stats(exports.name, stats) != 0) { LM_ERR("registering core statistics\n"); goto error; } if (register_mi_mod(exports.name, mi_cmds) != 0) { LM_ERR("registering MI commands\n"); goto error; } if (wsconn_init() < 0) { LM_ERR("initialising WebSocket connections table\n"); goto error; } if (ws_ping_application_data.len < 1 || ws_ping_application_data.len > 125) { ws_ping_application_data.s = DEFAULT_PING_APPLICATION_DATA + 8; ws_ping_application_data.len = DEFAULT_PING_APPLICATION_DATA_LEN - 8; } if (ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE) { if (ws_keepalive_timeout < 1 || ws_keepalive_timeout > 3600) ws_keepalive_timeout = DEFAULT_KEEPALIVE_TIMEOUT; switch(ws_keepalive_mechanism) { case KEEPALIVE_MECHANISM_PING: case KEEPALIVE_MECHANISM_PONG: break; default: ws_keepalive_mechanism = DEFAULT_KEEPALIVE_MECHANISM; break; } if (ws_keepalive_interval < 1 || ws_keepalive_interval > 60) ws_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; if (ws_keepalive_processes < 1 || ws_keepalive_processes > 16) ws_keepalive_processes = DEFAULT_KEEPALIVE_PROCESSES; /* Add extra process/timer for the keepalive process */ register_sync_timers(ws_keepalive_processes); } if (ws_sub_protocols & SUB_PROTOCOL_MSRP && !sr_event_enabled(SREV_TCP_MSRP_FRAME)) ws_sub_protocols &= ~SUB_PROTOCOL_MSRP; if ((ws_sub_protocols & SUB_PROTOCOL_ALL) == 0) { LM_ERR("no sub-protocols enabled\n"); goto error; } if ((ws_sub_protocols | SUB_PROTOCOL_ALL) != SUB_PROTOCOL_ALL) { LM_ERR("unrecognised sub-protocols enabled\n"); goto error; } if (ws_cors_mode < 0 || ws_cors_mode > 2) { LM_ERR("bad value for cors_mode\n"); goto error; } if (cfg_declare("websocket", ws_cfg_def, &default_ws_cfg, cfg_sizeof(websocket), &ws_cfg)) { LM_ERR("declaring configuration\n"); return -1; } cfg_get(websocket, ws_cfg, keepalive_timeout) = ws_keepalive_timeout; if (!module_loaded("xhttp")) { LM_ERR("\"xhttp\" must be loaded to use WebSocket.\n"); return -1; } if (((ws_sub_protocols & SUB_PROTOCOL_SIP) == SUB_PROTOCOL_SIP) && !module_loaded("nathelper") && !module_loaded("outbound")) { LM_WARN("neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n"); } return 0; error: wsconn_destroy(); return -1; }
/*! \brief Initialize siptrace module */ static int mod_init(void) { pv_spec_t avp_spec; sl_cbelem_t slcb; #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, siptrace_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(siptrace_init_rpc() != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } if (trace_flag<0 || trace_flag>(int)MAX_FLAG) { LM_ERR("invalid trace flag %d\n", trace_flag); return -1; } trace_flag = 1<<trace_flag; trace_to_database_flag = (int*)shm_malloc(sizeof(int)); if(trace_to_database_flag==NULL) { LM_ERR("no more shm memory left\n"); return -1; } *trace_to_database_flag = trace_to_database; if(hep_version != 1 && hep_version != 2) { LM_ERR("unsupported version of HEP"); return -1; } /* Find a database module if needed */ if(trace_to_database_flag!=NULL && *trace_to_database_flag!=0) { if (db_bind_mod(&db_url, &db_funcs)) { LM_ERR("unable to bind database module\n"); return -1; } if (trace_to_database_flag && !DB_CAPABILITY(db_funcs, DB_CAP_INSERT)) { LM_ERR("database modules does not provide all functions needed" " by module\n"); return -1; } } if(hep_version != 1 && hep_version != 2) { LM_ERR("unsupported version of HEP"); return -1; } trace_on_flag = (int*)shm_malloc(sizeof(int)); if(trace_on_flag==NULL) { LM_ERR("no more shm memory left\n"); return -1; } *trace_on_flag = trace_on; xheaders_write_flag = (int*)shm_malloc(sizeof(int)); xheaders_read_flag = (int*)shm_malloc(sizeof(int)); if (!(xheaders_write_flag && xheaders_read_flag)) { LM_ERR("no more shm memory left\n"); return -1; } *xheaders_write_flag = xheaders_write; *xheaders_read_flag = xheaders_read; /* register callbacks to TM */ if (load_tm_api(&tmb)!=0) { LM_WARN("can't load tm api. Will not install tm callbacks.\n"); } else if(tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, trace_onreq_in, 0, 0) <=0) { LM_ERR("can't register trace_onreq_in\n"); return -1; } /* bind the SL API */ if (sl_load_api(&slb)!=0) { LM_WARN("cannot bind to SL API. Will not install sl callbacks.\n"); } else { /* register sl callbacks */ memset(&slcb, 0, sizeof(sl_cbelem_t)); slcb.type = SLCB_REPLY_READY; slcb.cbf = trace_sl_onreply_out; if (slb.register_cb(&slcb) != 0) { LM_ERR("can't register for SLCB_REPLY_READY\n"); return -1; } if(trace_sl_acks) { slcb.type = SLCB_ACK_FILTERED; slcb.cbf = trace_sl_ack_in; if (slb.register_cb(&slcb) != 0) { LM_ERR("can't register for SLCB_ACK_FILTERED\n"); return -1; } } } if(dup_uri_str.s!=0) { dup_uri = (struct sip_uri *)pkg_malloc(sizeof(struct sip_uri)); if(dup_uri==0) { LM_ERR("no more pkg memory left\n"); return -1; } memset(dup_uri, 0, sizeof(struct sip_uri)); if(parse_uri(dup_uri_str.s, dup_uri_str.len, dup_uri)<0) { LM_ERR("bad dup uri\n"); return -1; } } if(force_send_sock_str.s!=0) { force_send_sock_str.len = strlen(force_send_sock_str.s); force_send_sock_uri = (struct sip_uri *)pkg_malloc(sizeof(struct sip_uri)); if(force_send_sock_uri==0) { LM_ERR("no more pkg memory left\n"); return -1; } memset(force_send_sock_uri, 0, sizeof(struct sip_uri)); if(parse_uri(force_send_sock_str.s, force_send_sock_str.len, force_send_sock_uri)<0) { LM_ERR("bad dup uri\n"); return -1; } } if(traced_user_avp_str.s && traced_user_avp_str.len > 0) { if (pv_parse_spec(&traced_user_avp_str, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", traced_user_avp_str.len, traced_user_avp_str.s); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &traced_user_avp, &traced_user_avp_type)!=0) { LM_ERR("[%.*s] - invalid AVP definition\n", traced_user_avp_str.len, traced_user_avp_str.s); return -1; } } else { traced_user_avp.n = 0; traced_user_avp_type = 0; } if(trace_table_avp_str.s && trace_table_avp_str.len > 0) { if (pv_parse_spec(&trace_table_avp_str, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", trace_table_avp_str.len, trace_table_avp_str.s); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &trace_table_avp, &trace_table_avp_type)!=0) { LM_ERR("[%.*s] - invalid AVP definition\n", trace_table_avp_str.len, trace_table_avp_str.s); return -1; } } else { trace_table_avp.n = 0; trace_table_avp_type = 0; } return 0; }