Ejemplo n.º 1
0
static int mod_init(void)
{
	LM_INFO("Call Center module - initializing\n");

	init_db_url( db_url , 0 /*cannot be null*/);
	init_db_url( acc_db_url , 0 /*cannot be null*/);
	b2b_scenario.len = strlen(b2b_scenario.s);

	/* Load B2BUA API */
	if (load_b2b_logic_api( &b2b_api) != 0) {
		LM_ERR("Can't load B2B-UA hooks, missing 'b2b_logic' module ?\n");
		return -1;
	}

	if (register_timer( "cc_agents", cc_timer_agents, NULL, 1)<0) {
		LM_ERR("failed to register agents timer function\n");
		return -1;
	}

	if (register_timer( "cc_cleanup", cc_timer_cleanup, NULL, 5)<0) {
		LM_ERR("failed to register cleaup timer function\n");
		return -1;
	}

	/* main CC data */
	data = init_cc_data();
	if (data==0) {
		LM_CRIT("failed to get shm mem for data\n");
		return -1;
	}

	/* init and open DB connection */
	if (init_cc_db( &db_url )!=0) {
		LM_ERR("failed to initialize the DB support\n");
		return -1;
	}
	if (init_cc_acc_db( &acc_db_url )!=0) {
		LM_ERR("failed to initialize the acc DB support\n");
		return -1;
	}

	/* load data */
	if ( cc_load_db_data( data )!=0 ) {
		LM_CRIT("failed to load callcenter data\n");
		return -1;
	}
	clean_cc_old_data(data);

	/* restore calls */
	if ( cc_db_restore_calls( data )!=0 ) {
		LM_CRIT("failed to load callcenter data\n");
		return -1;
	}

	/* close DB connection */
	cc_close_db();

	return 0;
}
Ejemplo n.º 2
0
/** 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;
}