コード例 #1
0
ファイル: proto_smpp.c プロジェクト: rrb3942/opensips
static int mod_init(void)
{
	LM_INFO("initializing SMPP protocol\n");

	db_url.len = strlen(db_url.s);
	smpp_outbound_uri.len = strlen(smpp_outbound_uri.s);

	if (smpp_db_init(&db_url) < 0)
		return -1;

	if (smpp_sessions_init() < 0)
		return -1;

	smpp_db_close();

	if (register_timer("enquire-link-timer", enquire_link, NULL, 5,
			TIMER_FLAG_DELAY_ON_DELAY)<0 )
		return -1;

	/* load the TM API */
	if (load_tm_api(&tmb)!=0) {
		LM_ERR("can't load TM API\n");
		return -1;
	}


	return 0;
}
コード例 #2
0
ファイル: tmx_mod.c プロジェクト: AndreyRybkin/kamailio
/**
 * 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;
}
コード例 #3
0
ファイル: compression.c プロジェクト: Enigmedia/opensips
static int mod_init(void)
{
	LM_INFO("Initializing module...\n");

	if (build_hdr_masks()) {
		LM_ERR("Cannot build initial mandatory headers mask\n");
		return -1;
	}

	if (mc_level > 9 || mc_level < 1) {
		LM_WARN("invalid level. using default 6\n");
		mc_level = 6;
	}

	compress_ctx_pos = context_register_ptr(CONTEXT_GLOBAL);
	LM_DBG("received compress context postion %d\n", compress_ctx_pos);

	compact_ctx_pos = context_register_ptr(CONTEXT_GLOBAL);
	LM_DBG("received compact context postion %d\n", compact_ctx_pos);

	memset(&tm_api, 0, sizeof(struct tm_binds));
	if (load_tm_api(&tm_api) != 0)
		LM_DBG("TM modules was not found\n");

	return 0;
}
コード例 #4
0
ファイル: registrant.c プロジェクト: KISSMonX/opensips
/** Module init function */
static int mod_init(void)
{
	if(load_uac_auth_api(&uac_auth_api)<0){
		LM_ERR("Failed to load uac_auth api\n");
		return -1;
	}

	/* load all TM stuff */
	if(load_tm_api(&tmb)==-1) {
		LM_ERR("can't load tm functions\n");
		return -1;
	}

	if(default_expires<15){
		LM_ERR("default_expires to short: [%d]<15\n", default_expires);
		return -1;
	}
	if(timer_interval<10){
		LM_ERR("timer_interval to short: [%d]<10\n", timer_interval);
		return -1;
	}
	if(reg_hsize<1 || reg_hsize>20) {
		LM_ERR("Wrong hash size: 20<[%d]<1\n", reg_hsize);
	}
	reg_hsize = 1<<reg_hsize;

	if(init_reg_htable()<0) {
		LM_ERR("Failed to initialize registrant hash table\n");
		return -1;
	}

	reg_table_name.len = strlen(reg_table_name.s);
	registrar_column.len = strlen(registrar_column.s);
	proxy_column.len = strlen(proxy_column.s);
	aor_column.len = strlen(aor_column.s);
	third_party_registrant_column.len =
		strlen(third_party_registrant_column.s);
	username_column.len = strlen(username_column.s);
	password_column.len = strlen(password_column.s);
	binding_URI_column.len = strlen(binding_URI_column.s);
	binding_params_column.len = strlen(binding_params_column.s);
	expiry_column.len = strlen(expiry_column.s);
	forced_socket_column.len = strlen(forced_socket_column.s);
	init_db_url(db_url , 0 /*cannot be null*/);
	if (init_reg_db(&db_url) != 0) {
		LM_ERR("failed to initialize the DB support\n");
		return -1;
	}

	register_timer("uac_reg_check", timer_check, 0,
					timer_interval/reg_hsize);

	return 0;
}
コード例 #5
0
ファイル: rtjson_routing.c プロジェクト: btriller/kamailio
int rtjson_init(void)
{
	if (load_tm_api( &tmb ) == -1) {
		LM_NOTICE("cannot load the TM API - some features are disabled\n");
		memset(&tmb, 0, sizeof(struct tm_binds));
	}
	if (load_uac_api(&uacb) < 0) {
		LM_NOTICE("cannot bind to UAC API - some features are disabled\n");
		memset(&uacb, 0, sizeof(uac_api_t));
	}
	return 0;
}
コード例 #6
0
ファイル: tm.c プロジェクト: SibghatullahSheikh/kamailio
/*
 * Load TM API
 * return 0 success, -1 failure
 */
int ospInitTm(void)
{
    if (load_tm_api(&osp_tmb) != 0) {
       LM_ERR("failed to load TM API\n");
       LM_ERR("TM is required for reporting call setup usage\n");
        return -1;
    }

    /* Register callbacks, listen for all incoming requests  */
    if (osp_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, ospOnReq, 0, 0) <= 0) {
       LM_ERR("failed to register TMCB_REQUEST_IN callback\n");
       LM_ERR("TM callbacks are required for reporting call set up usage\n");
        return -1;
    }

    return 0;
}
コード例 #7
0
ファイル: topology_hiding.c プロジェクト: alias-neo/opensips
static int mod_init(void)
{
	LM_INFO("initializing...\n");

	/* param handling */
	topo_hiding_prefix.len = strlen(topo_hiding_prefix.s);
	topo_hiding_seed.len = strlen(topo_hiding_seed.s);
	th_contact_encode_param.len = strlen(th_contact_encode_param.s);
	if (topo_hiding_ct_params.s) {
		topo_hiding_ct_params.len = strlen(topo_hiding_ct_params.s);
		topo_parse_passed_ct_params(&topo_hiding_ct_params);
	}
	if (topo_hiding_ct_hdr_params.s) {
		topo_hiding_ct_hdr_params.len = strlen(topo_hiding_ct_hdr_params.s);
		topo_parse_passed_hdr_ct_params(&topo_hiding_ct_hdr_params);
	}

	/* loading dependencies */
	if (load_tm_api(&tm_api)!=0) {
		LM_ERR("can't load TM API\n");
		goto error;
	}

	if (load_dlg_api(&dlg_api)!=0) {
		if (force_dialog) {
			LM_ERR("cannot force dialog. dialog module not loaded\n");
			goto error;
		}
	}

	if (register_pre_raw_processing_cb(topo_callid_pre_raw, 
	PRE_RAW_PROCESSING, 0/*no free*/) < 0) {
		LM_ERR("failed to initialize pre raw support\n");
		return -1;
	}

	if (register_post_raw_processing_cb(topo_callid_post_raw,
	POST_RAW_PROCESSING, 0/*no free*/) < 0) {
		LM_ERR("failed to initialize post raw support\n");
		return -1;
	}

	return 0;
error:
	return -1;
}
コード例 #8
0
ファイル: sl.c プロジェクト: 4N7HR4X/kamailio
static int child_init(int rank)
{
	if (rank == PROC_INIT) {
		if (init_sl_stats_child() < 0) {
			ERR("init_sl_stats_child failed\n");
			return -1;
		}
		if(sl_bind_tm!=0 && tmb.register_tmcb==0) {
			if(load_tm_api(&tmb)==-1) {
				LM_INFO("could not bind tm module - only stateless mode"
					" available during runtime\n");
				sl_bind_tm=0;
			}
		}

	}
	return 0;
}
コード例 #9
0
ファイル: xmpp.c プロジェクト: zhangzheyuk/opensips
/*
 * initialize module
 */
static int mod_init(void) {

	LM_DBG("initializing\n");

	if (load_tm_api(&tmb)) {
		LM_ERR("failed to load tm API\n");
		return -1;
	}

	if (strcmp(backend, "component") && strcmp(backend, "server")) {
		LM_ERR("invalid backend '%s'\n", backend);
		return -1;
	}

	if (!xmpp_port) {
		if (!strcmp(backend, "component"))
			xmpp_port = DEFAULT_COMPONENT_PORT;
		else if (!strcmp(backend, "server"))
			xmpp_port = DEFAULT_SERVER_PORT;
	}

	if(outbound_proxy.s)
		outbound_proxy.len= strlen(outbound_proxy.s);
	if(sip_domain.s)
		sip_domain.len = strlen(sip_domain.s);

	if(init_xmpp_cb_list()<0){
		LM_ERR("failed to init callback list\n");
		return -1;
	}

	if (pipe(pipe_fds) < 0) {
		LM_ERR("pipe() failed\n");
		return -1;
	}

	xmpp_pid = (int*)shm_malloc(sizeof(int));
	if(xmpp_pid == NULL) {
		LM_ERR("No more shared memory\n");
		return -1;
	}

	return 0;
}
コード例 #10
0
ファイル: mod.c プロジェクト: gbour/kamailio
/**
 * init module function
 */
static int mod_init(void) {

    bind_usrloc_t bind_usrloc;
    /* fix the parameters */
    if (!fix_parameters())
        goto error;

    /* load the TM API */
    if (load_tm_api(&isc_tmb) != 0) {
        LM_ERR("can't load TM API\n");
        goto error;
    }

    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(&isc_ulb) < 0) {
        return -1;
    }

    /* Init the isc_my_uri parameter */
    if (!isc_my_uri_c) {
        LM_CRIT("mandatory parameter \"isc_my_uri\" found empty\n");
        goto error;
    }

    isc_my_uri.s = isc_my_uri_c;
    isc_my_uri.len = strlen(isc_my_uri_c);
    isc_my_uri_sip.len = 4 + isc_my_uri.len;
    isc_my_uri_sip.s = shm_malloc(isc_my_uri_sip.len + 1);
    memcpy(isc_my_uri_sip.s, "sip:", 4);
    memcpy(isc_my_uri_sip.s + 4, isc_my_uri.s, isc_my_uri.len);
    isc_my_uri_sip.s[isc_my_uri_sip.len] = 0;

    LM_DBG("ISC module successfully initialised\n");

    return 0;
error:
    LM_ERR("Failed to initialise ISC module\n");
    return -1;
}
コード例 #11
0
ファイル: xmpp.c プロジェクト: gbour/kamailio
/*
 * initialize module
 */
static int mod_init(void) {

	if (load_tm_api(&tmb)) {
		LM_ERR("failed to load tm API\n");
		return -1;
	}
	
	if (strcmp(backend, "component") && strcmp(backend, "server")) {
		LM_ERR("invalid backend '%s'\n", backend);
		return -1;
	}

	if (!xmpp_port) {
		if (!strcmp(backend, "component"))
			xmpp_port = DEFAULT_COMPONENT_PORT;
		else if (!strcmp(backend, "server"))
			xmpp_port = DEFAULT_SERVER_PORT;
	}

	/* fix up the domain separator -- we only need 1 char */
	if (domain_sep_str && *domain_sep_str)
		domain_separator = *domain_sep_str;

	if(outbound_proxy.s)
		outbound_proxy.len= strlen(outbound_proxy.s);

	if(init_xmpp_cb_list()<0){
		LM_ERR("failed to init callback list\n");
		return -1;
	}

	if (pipe(pipe_fds) < 0) {
		LM_ERR("pipe() failed\n");
		return -1;
	}

	/* add space for one extra process */
	register_procs(1);
	/* add child to update local config framework structures */
	cfg_register_child(1);

	return 0;
}
コード例 #12
0
static int redirect_init(void)
{
	regex_t *filter;

	/* load the TM API */
	if (load_tm_api(&rd_tmb)!=0) {
		LOG(L_ERR, "ERROR:uac_redirect:init: can't load TM API\n");
		goto error;
	}

	/* init filter */
	init_filters();

	/* what's the default rule? */
	if (def_filter_s) {
		if ( !strcasecmp(def_filter_s,ACCEPT_RULE_STR) ) {
			set_default_rule( ACCEPT_RULE );
		} else if ( !strcasecmp(def_filter_s,DENY_RULE_STR) ) {
			set_default_rule( DENY_RULE );
		} else {
			LOG(L_ERR,"ERROR:uac_redirect:init: unknown default "
				"filter <%s>\n",def_filter_s);
		}
	}

	/* if accept filter specify, compile it */
	if (regexp_compile(accept_filter_s, &filter)<0) {
		LOG(L_ERR,"ERROR:uac_redirect:init: cannot init accept filter\n");
		goto error;
	}
	add_default_filter( ACCEPT_FILTER, filter);

	/* if deny filter specify, compile it */
	if (regexp_compile(deny_filter_s, &filter)<0) {
		LOG(L_ERR,"ERROR:uac_redirect:init: cannot init deny filter\n");
		goto error;
	}
	add_default_filter( DENY_FILTER, filter);

	return 0;
error:
	return -1;
}
コード例 #13
0
ファイル: async_mod.c プロジェクト: 4N7HR4X/kamailio
/**
 * init module function
 */
static int mod_init(void)
{
	if (load_tm_api( &tmb ) == -1) {
		LM_ERR("cannot load the TM-functions. Missing TM module?\n");
		return -1;
	}

	if(async_workers<=0)
		return 0;

	if(async_init_timer_list()<0) {
		LM_ERR("cannot initialize internal structure\n");
		return -1;
	}

	register_dummy_timers(async_workers);

	return 0;
}
コード例 #14
0
ファイル: mangler.c プロジェクト: NoamRom89/opensips
int prepare (void)
{

	/* using pre-compiled expressions to speed things up*/
	compile_expresions(PORT_REGEX,IP_REGEX);

#ifdef DEMO
	fprintf(stdout,"===============NEW RUN================\n");

	/* load the TM API */
	if (load_tm_api(&tmb)!=0) {
		LM_ERR("can't load TM API\n");
		return -1;
	}

	//register callbacks
	if (tmb.register_tmcb(TMCB_REQUEST_OUT,func_invite,0) <= 0) return -1;
#endif
	return 0;
}
コード例 #15
0
ファイル: siprec.c プロジェクト: OpenSIPS/opensips
/**
 * init module function
 */
static int mod_init(void)
{
	LM_DBG("initializing siprec module ...\n");

	if (srs_init() < 0) {
		LM_ERR("cannot initialize srs structures!\n");
		return -1;
	}

	if (src_init() < 0) {
		LM_ERR("cannot initialize src structures!\n");
		return -1;
	}

	if (load_dlg_api(&srec_dlg) != 0) {
		LM_ERR("dialog module not loaded! Cannot use siprec module\n");
		return -1;
	}

	if (load_tm_api(&srec_tm) != 0) {
		LM_ERR("tm module not loaded! Cannot use siprec module\n");
		return -1;
	}

	if (load_b2b_api(&srec_b2b) != 0) {
		LM_ERR("b2b_entities module not loaded! Cannot use siprec module\n");
		return -1;
	}

	if (load_rtpproxy_api(&srec_rtp) != 0) {
		LM_ERR("rtpproxy module not loaded! Cannot use siprec module\n");
		return -1;
	}

	if (srec_dlg.register_dlgcb(NULL, DLGCB_LOADED, srec_loaded_callback,
			NULL, NULL) < 0)
		LM_WARN("cannot register callback for loaded dialogs - will not be "
				"able to terminate siprec sessions after a restart!\n");

	return 0;
}
コード例 #16
0
ファイル: pcem_mod.c プロジェクト: mattvv/kamailio
static int mod_init( void )
{
	if ((pcem_qos_flag != -1) && 
		!flag_in_range(pcem_qos_flag)) {
		LM_ERR("pcem_qos_flag set to invalid value\n");
		return -1;
	}
	if ((pcem_all_flag != -1) && 
		!flag_in_range(pcem_all_flag)) {
		LM_ERR("pcem_all_flag set to invalid value\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 RR API */
	if (load_rr_api(&rrb)!=0) {
		LM_ERR("can't load RR API\n");
		return -1;
	}
	/* we need the append_fromtag on in RR */
	if (!rrb.append_fromtag) {
		LM_ERR("'append_fromtag' RR param is not enabled\n");
		return -1;
	}

	/* listen for all incoming requests  */
	if ( tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, pcem_onreq, 0, 0 ) <=0 ) {
		LM_ERR("cannot register TMCB_REQUEST_IN callback\n");
		return -1;
	}

	_pcem_module_initialized = 1;

	return 0;
}
コード例 #17
0
ファイル: uac_send.c プロジェクト: alezzandro/kamailio
void uac_req_init(void)
{
	/* load the TM API */
	if (load_tm_api(&tmb)!=0) {
		LM_DBG("can't load TM API - disable it\n");
		memset(&tmb, 0, sizeof(struct tm_binds));
		return;
	}
	memset(&_uac_req, 0, sizeof(struct _uac_send_info));
	_uac_req.s_ruri.s = _uac_req.b_ruri;
	_uac_req.s_furi.s = _uac_req.b_furi;
	_uac_req.s_turi.s = _uac_req.b_turi;
	_uac_req.s_ouri.s = _uac_req.b_ouri;
	_uac_req.s_hdrs.s = _uac_req.b_hdrs;
	_uac_req.s_body.s = _uac_req.b_body;
	_uac_req.s_method.s = _uac_req.b_method;
	_uac_req.s_auser.s  = _uac_req.b_auser;
	_uac_req.s_apasswd.s  = _uac_req.b_apasswd;
	_uac_req.s_callid.s   = _uac_req.b_callid;
	_uac_req.s_sock.s     = _uac_req.b_sock;
	return;
}
コード例 #18
0
ファイル: script_helper.c プロジェクト: ataillefer/opensips
int mod_init(void)
{
	LM_DBG("initializing module...\n");

	if (seq_route) {
		seq_route_id = get_script_route_ID_by_name(seq_route, rlist, RT_NO);
		if (seq_route_id == -1)
			LM_ERR("route \"%s\" does not exist! ignoring\n", seq_route);
	}

	if (load_tm_api(&tm_api) != 0) {
		LM_ERR("failed to load tm API\n");
		return -1;
	}

	if (use_dialog && load_dlg_api(&dlg_api) != 0) {
		LM_ERR("failed to load dialog API\n");
		return -1;
	}

	if (load_rr_api(&rr_api) != 0) {
		LM_ERR("failed to load rr API\n");
		return -1;
	}

	if (load_sl_api(&sl_api) != 0) {
		LM_ERR("failed to load sl API\n");
		return -1;
	}

	if (__register_script_cb(run_helper_logic,
	                         PRE_SCRIPT_CB|REQ_TYPE_CB, NULL, -1) != 0) {
		LM_ERR("cannot register script callback");
		return -1;
	}

	return 0;
}
コード例 #19
0
ファイル: sl.c プロジェクト: kiryu/kamailio
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;
}
コード例 #20
0
ファイル: evapi_mod.c プロジェクト: SipSeb/kamailio
/**
 * init module function
 */
static int mod_init(void)
{
	char *p;

	/* init faked sip msg */
	if(faked_msg_init()<0) {
		LM_ERR("failed to init faked sip message\n");
		return -1;
	}

	if(load_tm_api( &tmb ) < 0) {
		LM_INFO("cannot load the TM module functions - async relay disabled\n");
		memset(&tmb, 0, sizeof(tm_api_t));
	}

	if(_evapi_bind_param!=NULL) {
		p = strchr(_evapi_bind_param, ':');
		if(p!=NULL) {
			*p++ = '\0';
			_evapi_bind_port = (short)atoi(p);
			if (_evapi_bind_port <= 0) {
				LM_ERR("invalid port: %d\n", _evapi_bind_port);
				return -1;
			}
		}
		_evapi_bind_addr = _evapi_bind_param;
	}

	/* add space for one extra process */
	register_procs(1 + _evapi_workers);

	/* add child to update local config framework structures */
	cfg_register_child(1 + _evapi_workers);

	evapi_init_environment(_evapi_netstring_format_param);

	return 0;
}
コード例 #21
0
ファイル: xmpp.c プロジェクト: Drooids/openser-xmlrpc
/*
 * initialize module
 */
static int mod_init(void) {

	LM_DBG("initializing\n");

	if (load_tm_api(&tmb)) {
		LM_ERR("failed to load tm API\n");
		return -1;
	}
	
	if (strcmp(backend, "component") && strcmp(backend, "server")) {
		LM_ERR("invalid backend '%s'\n", backend);
		return -1;
	}

	if (!xmpp_port) {
		if (!strcmp(backend, "component"))
			xmpp_port = DEFAULT_COMPONENT_PORT;
		else if (!strcmp(backend, "server"))
			xmpp_port = DEFAULT_SERVER_PORT;
	}

	/* fix up the domain separator -- we only need 1 char */
	if (domain_sep_str && *domain_sep_str)
		domain_separator = *domain_sep_str;

	if(init_xmpp_cb_list()<0){
		LM_ERR("failed to init callback list\n");
		return -1;
	}

	if (pipe(pipe_fds) < 0) {
		LM_ERR("pipe() failed\n");
		return -1;
	}

	return 0;
}
コード例 #22
0
ファイル: sl.c プロジェクト: 4N7HR4X/kamailio
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;
}
コード例 #23
0
ファイル: sca.c プロジェクト: btriller/kamailio
static int sca_mod_init(void)
{
	sca = (sca_mod *) shm_malloc(sizeof(sca_mod));
	if (sca == NULL) {
		LM_ERR("Failed to shm_malloc module object\n");
		return (-1);
	}
	memset(sca, 0, sizeof(sca_mod));

	if (sca_set_config(sca) != 0) {
		LM_ERR("Failed to set configuration\n");
		goto error;
	}

	if (rpc_register_array(sca_rpc) != 0) {
		LM_ERR("Failed to register RPC commands\n");
		goto error;
	}

	if (sca_bind_srdb1(sca, &dbf) != 0) {
		LM_ERR("Failed to initialize required DB API\n");
		goto error;
	}

	if (load_tm_api(&tmb) != 0) {
		LM_ERR("Failed to initialize required tm API. Check that the \"tm\" module is loaded before this module.\n");
		goto error;
	}
	sca->tm_api = &tmb;

	if (sca_bind_sl(sca, &slb) != 0) {
		LM_ERR("Failed to initialize required sl API. Check that the \"sl\" module is loaded before this module.\n");
		goto error;
	}

	if (sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size)
			!= 0) {
		LM_ERR("Failed to create subscriptions hash table\n");
		goto error;
	}
	if (sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size)
			!= 0) {
		LM_ERR("Failed to create appearances hash table\n");
		goto error;
	}

	sca_subscriptions_restore_from_db(sca);

	register_timer(sca_subscription_purge_expired, sca,
			sca->cfg->purge_expired_interval);
	register_timer(sca_appearance_purge_stale, sca,
			sca->cfg->purge_expired_interval);

	// register separate timer process to write subscriptions to DB.
	// move to 3.3+ timer API (register_basic_timer) at some point.
	// timer process forks in sca_child_init, above.
	register_dummy_timers(1);

	LM_INFO("SCA initialized \n");

	return (0);

	error: if (sca != NULL) {
		if (sca->cfg != NULL) {
			shm_free(sca->cfg);
		}
		if (sca->subscriptions != NULL) {
			sca_hash_table_free(sca->subscriptions);
		}
		if (sca->appearances != NULL) {
			sca_hash_table_free(sca->appearances);
		}
		shm_free(sca);
		sca = NULL;
	}

	return (-1);
}
コード例 #24
0
ファイル: b2b_sca.c プロジェクト: OpenSIPS/opensips
/** Module init function */
static int mod_init(void)
{
	unsigned int i;

	LM_DBG("start\n");

	init_db_url( db_url , 0 /*cannot be null*/);

	/* load tm api */
	if(load_tm_api(&tmb)==-1)
	{
		LM_ERR("can't load tm functions\n");
		return -1;
	}

	/* load pua api */
	if(load_pua_api(&pua_api) < 0)
	{
		LM_ERR("Can't bind pua\n");
		return -1;
	}
	/* add event in pua module */
	if(pua_api.add_event(CALLINFO_EVENT, "call-info", NULL, 0) < 0) {
		LM_ERR("failed to add 'call-info' event to pua module\n");
		return -1;
	}

	/* load b2b_logic api */
	if(load_b2b_logic_api(&b2bl_api)< 0)
	{
		LM_ERR("Failed to load b2b_logic api\n");
		return -1;
	}

	if(b2b_sca_hsize<1 || b2b_sca_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;
	}
	b2b_sca_hsize = 1<<b2b_sca_hsize;

	if(presence_server.s)
		presence_server.len = strlen(presence_server.s);
	LM_DBG("fix db columns\n");
	sca_table_name.len = strlen(sca_table_name.s);
	shared_line_column.len = strlen(shared_line_column.s);
	watchers_column.len = strlen(watchers_column.s);
	for (i=0; i<MAX_APPEARANCE_INDEX; i++) {
		app_shared_entity_column[i].len = strlen(app_shared_entity_column[i].s);
		app_call_state_column[i].len = strlen(app_call_state_column[i].s);
		app_call_info_uri_column[i].len = strlen(app_call_info_uri_column[i].s);
		app_call_info_appearance_uri_column[i].len =
				strlen(app_call_info_appearance_uri_column[i].s);
		app_b2bl_key_column[i].len = strlen(app_b2bl_key_column[i].s);
	}

	LM_DBG("fix AVP spec\n");
	/* fix AVP spec */
	if(watchers_avp_spec.s)
	{
		watchers_avp_spec.len = strlen(watchers_avp_spec.s);
		if(pv_parse_spec(&watchers_avp_spec, &watchers_spec)==NULL ||
			watchers_spec.type != PVT_AVP)
		{
			LM_ERR("failed to parse watchers spec [%.*s]\n",
				watchers_avp_spec.len, watchers_avp_spec.s);
			return E_CFG;
		}
		if(pv_get_avp_name(NULL, &(watchers_spec.pvp), &(watchers_avp_name),
			&(watchers_avp_type) )!=0)
		{
			LM_ERR("[%.*s]- invalid AVP definition for watchers_avp_spec\n",
				watchers_avp_spec.len, watchers_avp_spec.s);
		}
	} else {
		watchers_avp_name = -1;
		watchers_avp_type = 0;
	}

	if(shared_line_spec_param.s)
	{
		shared_line_spec_param.len = strlen(shared_line_spec_param.s);
		if(pv_parse_spec(&shared_line_spec_param, &shared_line_spec)==NULL)
		{
			LM_ERR("failed to parse shared_line spec\n");
			return E_CFG;
		}
		switch(shared_line_spec.type) {
			case PVT_NONE:
			case PVT_EMPTY:
			case PVT_NULL:
			case PVT_MARKER:
			case PVT_COLOR:
				LM_ERR("invalid shared_line spec\n");
				return -3;
			default: ;
		}
	}

	if(appearance_name_addr_spec_param.s)
	{
		appearance_name_addr_spec_param.len = strlen(appearance_name_addr_spec_param.s);
		if(pv_parse_spec(&appearance_name_addr_spec_param, &appearance_name_addr_spec)==NULL)
		{
			LM_ERR("failed to parse appearance_name_addr spec\n");
			return E_CFG;
		}
		switch(appearance_name_addr_spec.type) {
			case PVT_NONE:
			case PVT_EMPTY:
			case PVT_NULL:
			case PVT_MARKER:
			case PVT_COLOR:
				LM_ERR("invalid appearance_name_addr spec\n");
				return -3;
			default: ;
		}
	}

	if(init_b2b_sca_htable() < 0) {
		LM_ERR("Failed to initialize b2b_sca hash table\n");
		return -1;
	}

	if (sca_db_mode==DB_MODE_NONE) {
		db_url.s = NULL; db_url.len = 0;
	} else {
		if (sca_db_mode!=DB_MODE_REALTIME) {
			LM_ERR("unsupported db_mode %d\n", sca_db_mode);
			return -1;
		}
		if ( !db_url.s || db_url.len==0 ) {
			LM_ERR("db_url not configured for db_mode %d\n", sca_db_mode);
			return -1;
		}
		if (init_sca_db(&db_url, b2b_sca_hsize)!=0) {
			LM_ERR("failed to initialize the DB support\n");
			return -1;
		}
	}
	return 0;
}
コード例 #25
0
ファイル: imc.c プロジェクト: lbalaceanu/kamailio
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;
}
コード例 #26
0
ファイル: dmq.c プロジェクト: 4N7HR4X/kamailio
/**
 * init module 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;
	}

	/* bind the SL API */
	if (sl_load_api(&slb)!=0) {
		LM_ERR("cannot bind to SL API\n");
		return -1;
	}

	/* load all TM stuff */
	if(load_tm_api(&tmb)==-1) {
		LM_ERR("can't load tm functions. TM module probably not loaded\n");
		return -1;
	}

	/* load peer list - the list containing the module callbacks for dmq */
	peer_list = init_peer_list();
	if(peer_list==NULL) {
		LM_ERR("cannot initialize peer list\n");
		return -1;
	}

	/* load the dmq node list - the list containing the dmq servers */
	node_list = init_dmq_node_list();
	if(node_list==NULL) {
		LM_ERR("cannot initialize node list\n");
		return -1;
	}

	if (rpc_register_array(rpc_methods)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* register worker processes - add one because of the ping process */
	register_procs(num_workers);
	
	/* check server_address and notification_address are not empty and correct */
	if(parse_uri(dmq_server_address.s, dmq_server_address.len, &dmq_server_uri) < 0) {
		LM_ERR("server address invalid\n");
		return -1;
	}

	if(parse_uri(dmq_notification_address.s, dmq_notification_address.len, &dmq_notification_uri) < 0) {
		LM_ERR("notification address invalid\n");
		return -1;
	}

	/* create socket string out of the server_uri */
	if(make_socket_str_from_uri(&dmq_server_uri, &dmq_server_socket) < 0) {
		LM_ERR("failed to create socket out of server_uri\n");
		return -1;
	}
	if (lookup_local_socket(&dmq_server_socket) == NULL) {
		LM_ERR("server_uri is not a socket the proxy is listening on\n");
		return -1;
	}

	/* allocate workers array */
	workers = shm_malloc(num_workers * sizeof(*workers));
	if(workers == NULL) {
		LM_ERR("error in shm_malloc\n");
		return -1;
	}

	dmq_init_callback_done = shm_malloc(sizeof(int));
	if (!dmq_init_callback_done) {
		LM_ERR("no more shm\n");
		return -1;
	}
	*dmq_init_callback_done = 0;

	/**
	 * add the dmq notification peer.
	 * the dmq is a peer itself so that it can receive node notifications
	 */
	if(add_notification_peer()<0) {
		LM_ERR("cannot add notification peer\n");
		return -1;
	}

	startup_time = (int) time(NULL);

	/**
	 * add the ping timer
	 * it pings the servers once in a while so that we know which failed
	 */
	if(ping_interval < MIN_PING_INTERVAL) {
		ping_interval = MIN_PING_INTERVAL;
	}
	if(register_timer(ping_servers, 0, ping_interval)<0) {
		LM_ERR("cannot register timer callback\n");
		return -1;
	}

	return 0;
}
コード例 #27
0
ファイル: seas.c プロジェクト: Distrotech/opensips
/** Initializes seas module. It first parses the listen_sockets parameter
 * which has the form "ip_address[:port]", creates the pipe to
 * communicate with the dispatcher.
 */
static int seas_init(void)
{
   char *p,*port;
   struct hostent *he;
   struct socket_info *si;
   int c_pipe[2],mierr,i;
   /** Populate seas_functions*/
   if (load_tm_api(&seas_f.tmb)!=0) {
      LM_ERR( "can't load TM API\n");
      return -1;
   }
   if(!(seas_f.t_check_orig_trans = find_export("t_check_trans", 0, 0))){
      LM_ERR( "Seas requires transaction module (t_check_trans not found)\n");
      return -1;
   }
   /** Populate seas_functions*/
   c_pipe[0]=c_pipe[1]=-1;
   p=seas_listen_socket;
   port=(char *)0;
   seas_listen_port=5080;
   /*if the seas_listen_socket configuration string is empty, use default values*/
   if(p==NULL || *p==0){
      si=get_first_socket();
      seas_listen_ip=&si->address;
   } else {/*if config string is not empty, then try to find host first, and maybe port..*/
      while(*p){
	 if(*p == ':'){
	    *p=0;
	    port=p+1;
	    break;
	 }
	 p++;
      }
      if(!(he=resolvehost(seas_listen_socket,0)))
	 goto error;
      if(!(seas_listen_ip=pkg_malloc(sizeof(struct ip_addr))))
	 goto error;
      hostent2ip_addr(seas_listen_ip, he, 0);
      if(port!=(char *)0 && (seas_listen_port=str2s(port,strlen(port),&mierr))==0){
	 LM_ERR("invalid port %s \n",port);
	 goto error;
      }
   }
   memset(unc_as_t,0,2*MAX_UNC_AS_NR*sizeof(struct unc_as));//useless because unc_as_t is in bss?
   if (pipe(c_pipe)==-1) {
      LM_ERR("cannot create pipe!\n");
      goto error;
   }
   read_pipe=c_pipe[0];
   write_pipe=c_pipe[1];
   seas_init_tags();
   if(0>start_stats_server(seas_stats_socket))
      goto error;
   if(0>prepare_ha())
      goto error;
   if(0>parse_cluster_cfg())
      goto error;
   return 0;
error:
   for(i=0;i<2;i++)
      if(c_pipe[i]!=-1)
	 close(c_pipe[i]);
   if(seas_listen_ip!=0)
      pkg_free(seas_listen_ip);
   if(use_stats)
      stop_stats_server();
   return -1;
}
コード例 #28
0
ファイル: dialog.c プロジェクト: MayamaTakeshi/opensips
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;
}
コード例 #29
0
ファイル: acc_mod.c プロジェクト: NoamRom89/opensips
static int mod_init( void )
{
	pv_spec_t avp_spec;

	LM_INFO("initializing...\n");

	if (db_url.s)
		db_url.len = strlen(db_url.s);
	db_table_acc.len = strlen(db_table_acc.s);
	db_table_mc.len = strlen(db_table_mc.s);
	acc_method_col.len = strlen(acc_method_col.s);
	acc_fromtag_col.len = strlen(acc_fromtag_col.s);
	acc_totag_col.len = strlen(acc_totag_col.s);
	acc_callid_col.len = strlen(acc_callid_col.s);
	acc_sipcode_col.len = strlen(acc_sipcode_col.s);
	acc_sipreason_col.len = strlen(acc_sipreason_col.s);
	acc_time_col.len = strlen(acc_time_col.s);

	if (log_facility_str) {
		int tmp = str2facility(log_facility_str);
		if (tmp != -1)
			acc_log_facility = tmp;
		else {
			LM_ERR("invalid log facility configured");
			return -1;
		}
	}

	/* ----------- GENERIC INIT SECTION  ----------- */

	fix_flag_name(failed_transaction_string, failed_transaction_flag);

	failed_transaction_flag =
	    get_flag_id_by_name(FLAG_TYPE_MSG, failed_transaction_string);

	if (flag_idx2mask(&failed_transaction_flag)<0)
		return -1;
	fix_flag_name(cdr_string, cdr_flag);

	cdr_flag = get_flag_id_by_name(FLAG_TYPE_MSG, cdr_string);

	if (flag_idx2mask(&cdr_flag)<0)
		return -1;

	/* load the TM API */
	if (load_tm_api(&tmb)!=0) {
		LM_ERR("can't load TM API\n");
		return -1;
	}

	if (load_dlg_api(&dlg_api)!=0)
		LM_DBG("failed to find dialog API - is dialog module loaded?\n");

	if (cdr_flag && !dlg_api.get_dlg) {
		LM_WARN("error loading dialog module - cdrs cannot be generated\n");
		cdr_flag = 0;
	}
	/* if detect_direction is enabled, load rr also */
	if (detect_direction) {
		if (load_rr_api(&rrb)!=0) {
			LM_ERR("can't load RR API\n");
			return -1;
		}
		/* we need the append_fromtag on in RR */
		if (!rrb.append_fromtag) {
			LM_ERR("'append_fromtag' RR param is not enabled!"
				" - required by 'detect_direction'\n");
			return -1;
		}
	}

	/* listen for all incoming requests  */
	if ( tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, acc_onreq, 0, 0 ) <=0 ) {
		LM_ERR("cannot register TMCB_REQUEST_IN callback\n");
		return -1;
	}

	/* init the extra engine */
	init_acc_extra();

	/* configure multi-leg accounting */
	if (leg_info_str && (leg_info=parse_acc_leg(leg_info_str))==0 ) {
		LM_ERR("failed to parse multi_leg_info param\n");
		return -1;
	}
	if (leg_bye_info_str && (leg_bye_info=parse_acc_leg(leg_bye_info_str))==0 ) {
		LM_ERR("failed to parse multi_leg_bye_info param\n");
		return -1;
	}

	/* ----------- SYSLOG INIT SECTION ----------- */

	/* parse the extra string, if any */
	if (log_extra_str && (log_extra=parse_acc_extra(log_extra_str, 1))==0 ) {
		LM_ERR("failed to parse log_extra param\n");
		return -1;
	}
	if (log_extra_bye_str &&
			(log_extra_bye=parse_acc_extra(log_extra_bye_str, 0))==0 ) {
		LM_ERR("failed to parse log_extra_bye param\n");
		return -1;
	}

	fix_flag_name(log_string, log_flag);

	log_flag = get_flag_id_by_name(FLAG_TYPE_MSG, log_string);

	if (flag_idx2mask(&log_flag)<0)
		return -1;

	fix_flag_name(log_missed_string, log_missed_flag);

	log_missed_flag = get_flag_id_by_name(FLAG_TYPE_MSG, log_missed_string);

	if (flag_idx2mask(&log_missed_flag)<0)
		return -1;

	acc_log_init();

	/* ------------ SQL INIT SECTION ----------- */

	if (db_url.s && db_url.len > 0) {
		/* parse the extra string, if any */
		if (db_extra_str && (db_extra=parse_acc_extra(db_extra_str, 1))==0 ) {
			LM_ERR("failed to parse db_extra param\n");
			return -1;
		}
		if (db_extra_bye_str &&
				(db_extra_bye=parse_acc_extra(db_extra_bye_str, 0))==0 ) {
			LM_ERR("failed to parse db_extra_bye param\n");
			return -1;
		}
		if (acc_db_init(&db_url)<0){
			LM_ERR("failed...did you load a database module?\n");
			return -1;
		}
		/* fix the flags */
		fix_flag_name(db_string, db_flag);

		db_flag = get_flag_id_by_name(FLAG_TYPE_MSG, db_string);

		if (flag_idx2mask(&db_flag)<0)
			return -1;

		fix_flag_name(db_missed_string, db_missed_flag);

		db_missed_flag = get_flag_id_by_name(FLAG_TYPE_MSG, db_missed_string);

		if (flag_idx2mask(&db_missed_flag)<0)
			return -1;
		if (db_table_avp.s) {
			db_table_avp.len = strlen(db_table_avp.s);
			if (pv_parse_spec(&db_table_avp, &avp_spec) == 0 ||
					avp_spec.type != PVT_AVP) {
				LM_ERR("malformed or non AVP %s\n", db_table_avp.s);
				return -1;
			}
			if (pv_get_avp_name(0, &avp_spec.pvp, &db_table_name,
						&db_table_name_type)) {
				LM_ERR("invalid definition of AVP %s\n", db_table_avp.s);
				return -1;
			}
		}
	} else {
		db_flag = 0;
		db_missed_flag = 0;
	}

	/* ------------ AAA PROTOCOL INIT SECTION ----------- */

	if (aaa_proto_url && aaa_proto_url[0]) {
		/* parse the extra string, if any */
		if (aaa_extra_str && (aaa_extra = parse_acc_extra(aaa_extra_str, 1))==0) {
			LM_ERR("failed to parse aaa_extra param\n");
			return -1;
		}
		if (aaa_extra_bye_str &&
				(aaa_extra_bye = parse_acc_extra(aaa_extra_bye_str, 0))==0) {
			LM_ERR("failed to parse aaa_extra_bye param\n");
			return -1;
		}

		/* fix the flags */
		fix_flag_name(aaa_string, aaa_flag);

		aaa_flag = get_flag_id_by_name(FLAG_TYPE_MSG, aaa_string);

		if (flag_idx2mask(&aaa_flag)<0)
			return -1;

		fix_flag_name(aaa_missed_string, aaa_missed_flag);

		aaa_missed_flag = get_flag_id_by_name(FLAG_TYPE_MSG, aaa_missed_string);

		if (flag_idx2mask(&aaa_missed_flag)<0)
			return -1;

		if (init_acc_aaa(aaa_proto_url, service_type)!=0 ) {
			LM_ERR("failed to init radius\n");
			return -1;
		}
	} else {
		aaa_proto_url = NULL;
		aaa_flag = 0;
		aaa_missed_flag = 0;
	}

	/* ------------ DIAMETER INIT SECTION ----------- */

#ifdef DIAM_ACC
	/* fix the flags */
	fix_flag_name(diameter_string, diameter_flag);

	diameter_flag = get_flag_id_by_name(FLAG_TYPE_MSG, diameter_string);

	if (flag_idx2mask(&diameter_flag)<0)
		return -1;

	fix_flag_name(diameter_missed_string, diameter_missed_flag);

	diameter_missed_flag=get_flag_id_by_name(FLAG_TYPE_MSG, diameter_missed_string);

	if (flag_idx2mask(&diameter_missed_flag)<0)
		return -1;

	/* parse the extra string, if any */
	if (dia_extra_str && (dia_extra=parse_acc_extra(dia_extra_str))==0 ) {
		LM_ERR("failed to parse dia_extra param\n");
		return -1;
	}

	if (acc_diam_init()!=0) {
		LM_ERR("failed to init diameter engine\n");
		return -1;
	}

#endif

	/* ------------ EVENTS INIT SECTION ----------- */

	if (evi_extra_str && (evi_extra = parse_acc_extra(evi_extra_str, 1))==0) {
		LM_ERR("failed to parse evi_extra param\n");
		return -1;
	}
	if (evi_extra_bye_str &&
			(evi_extra_bye = parse_acc_extra(evi_extra_bye_str, 0))==0) {
		LM_ERR("failed to parse evi_extra_bye param\n");
		return -1;
	}

	/* fix the flags */
	fix_flag_name(evi_string, evi_flag);

	evi_flag = get_flag_id_by_name(FLAG_TYPE_MSG, evi_string);

	if (flag_idx2mask(&evi_flag)<0)
		return -1;

	fix_flag_name(evi_missed_string, evi_missed_flag);

	evi_missed_flag = get_flag_id_by_name(FLAG_TYPE_MSG, evi_missed_string);

	if (flag_idx2mask(&evi_missed_flag)<0)
		return -1;

	if (init_acc_evi() < 0) {
		LM_ERR("cannot init acc events\n");
		return -1;
	}

	/* load callbacks */
	if (cdr_flag && dlg_api.get_dlg && dlg_api.register_dlgcb(NULL,
				DLGCB_LOADED,acc_loaded_callback, NULL, NULL) < 0)
			LM_ERR("cannot register callback for dialog loaded - accounting "
					"for ongoing calls will be lost after restart\n");


	return 0;
}
コード例 #30
0
ファイル: pua.c プロジェクト: kiryu/kamailio
/**
 * init module function
 */
static int mod_init(void)
{
	LM_DBG("...\n");

	if (register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}

	if(min_expires< 0)
		min_expires= 0;

	if(default_expires< 600)
		default_expires= 3600;

	/* load TM API */
	if(load_tm_api(&tmb)==-1)
	{
		LM_ERR("can't load tm functions\n");
		return -1;
	}

	db_url.len = db_url.s ? strlen(db_url.s) : 0;
	LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s);
	db_table.len = db_table.s ? strlen(db_table.s) : 0;

	/* binding to database module  */
	if (db_bind_mod(&db_url, &pua_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}
	if (!DB_CAPABILITY(pua_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions needed"
				" by the module\n");
		return -1;
	}

	pua_db = pua_dbf.init(&db_url);
	if (!pua_db)
	{
		LM_ERR("while connecting database\n");
		return -1;
	}
	/* verify table version  */
	if(db_check_table_version(&pua_dbf, pua_db, &db_table, PUA_TABLE_VERSION) < 0) {
		LM_ERR("error during table version check.\n");
		return -1;
	}

	if (dbmode != PUA_DB_ONLY)
	{ 
		if(HASH_SIZE<=1)
			HASH_SIZE= 512;
		else
			HASH_SIZE = 1<<HASH_SIZE;

		HashT= new_htable();
		if(HashT== NULL)
		{
			LM_ERR("while creating new hash table\n");
			return -1;
		}
		if(db_restore()< 0)
		{
			LM_ERR("while restoring hash_table\n");
			return -1;
		}
	} 

	if (dbmode != PUA_DB_DEFAULT && dbmode != PUA_DB_ONLY)
	{
		dbmode = PUA_DB_DEFAULT;
		LM_ERR( "Invalid dbmode-using default mode\n" );
	}

	if(update_period<0)
	{
		LM_ERR("wrong clean_period\n");
		return -1;
	}
	if ( init_puacb_list() < 0)
	{
		LM_ERR("callbacks initialization failed\n");
		return -1;
	}
	pua_evlist= init_pua_evlist();
	if(pua_evlist==0)
	{
		LM_ERR("when initializing pua_evlist\n");
		return -1;
	}
	if(pua_add_events()< 0)
	{
		LM_ERR("while adding events\n");
		return -1;
	}

	if(check_remote_contact<0 || check_remote_contact>1)
	{
		LM_ERR("bad value for check_remote_contact\n");
		return -1;
	}

	startup_time = (int) time(NULL);

	if (update_period > 0) /* probably should check > 5 here!! -croc */
		register_timer(hashT_clean, 0, update_period- 5);

	if (dbmode != PUA_DB_ONLY) 
	{        
		if (update_period > 0) 
			register_timer(db_update, 0, update_period);
	}

	if(pua_db)
		pua_dbf.close(pua_db);
	pua_db = NULL;

	outbound_proxy.len = outbound_proxy.s ? strlen(outbound_proxy.s) : 0;

	return 0;
}