Example #1
0
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;
}
Example #2
0
/*! \brief
 * Module initialization function
 */
static int mod_init(void)
{
	LM_DBG("initializing\n");

	/* Compute the lengths of string parameters */
	init_db_url( db_url , 1 /*can be null*/);
	user_col.len = strlen(user_col.s);
	domain_col.len = strlen(domain_col.s);
	contact_col.len = strlen(contact_col.s);
	expires_col.len = strlen(expires_col.s);
	q_col.len = strlen(q_col.s);
	callid_col.len = strlen(callid_col.s);
	cseq_col.len = strlen(cseq_col.s);
	flags_col.len = strlen(flags_col.s);
	cflags_col.len = strlen(cflags_col.s);
	user_agent_col.len = strlen(user_agent_col.s);
	received_col.len = strlen(received_col.s);
	path_col.len = strlen(path_col.s);
	sock_col.len = strlen(sock_col.s);
	methods_col.len = strlen(methods_col.s);
	sip_instance_col.len = strlen(sip_instance_col.s);
	attr_col.len = strlen(attr_col.s);
	last_mod_col.len = strlen(last_mod_col.s);

	if(ul_hash_size<=1)
		ul_hash_size = 512;
	else
		ul_hash_size = 1<<ul_hash_size;
	ul_locks_no = ul_hash_size;

	/* check matching mode */
	switch (matching_mode) {
		case CONTACT_ONLY:
		case CONTACT_CALLID:
			break;
		default:
			LM_ERR("invalid matching mode %d\n", matching_mode);
	}

	if(ul_init_locks()!=0)
	{
		LM_ERR("locks array initialization failed\n");
		return -1;
	}

	/* Register cache timer */
	register_timer( "ul-timer", timer, 0, timer_interval,
		TIMER_FLAG_DELAY_ON_DELAY);

	/* init the callbacks list */
	if ( init_ulcb_list() < 0) {
		LM_ERR("usrloc/callbacks initialization failed\n");
		return -1;
	}

	/* Shall we use database ? */
	if (db_mode != NO_DB) { /* Yes */
		if (db_url.s==NULL || db_url.len==0) {
			LM_ERR("selected db_mode requires a db connection -> db_url \n");
			return -1;
		}
		if (db_bind_mod(&db_url, &ul_dbf) < 0) { /* Find database module */
			LM_ERR("failed to bind database module\n");
			return -1;
		}
		if (!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) {
			LM_ERR("database module does not implement all functions"
					" needed by the module\n");
			return -1;
		}
		if (db_mode != DB_ONLY && (sync_lock = lock_init_rw()) == NULL) {
			LM_ERR("cannot init rw lock\n");
			return -1;
		}
	}

	fix_flag_name(nat_bflag_str, nat_bflag);

	nat_bflag = get_flag_id_by_name(FLAG_TYPE_BRANCH, nat_bflag_str);

	if (nat_bflag==(unsigned int)-1) {
		nat_bflag = 0;
	} else if ( nat_bflag>=8*sizeof(nat_bflag) ) {
		LM_ERR("bflag index (%d) too big!\n", nat_bflag);
		return -1;
	} else {
		nat_bflag = 1<<nat_bflag;
	}

	if (ul_event_init() < 0) {
		LM_ERR("cannot initialize USRLOC events\n");
		return -1;
	}

	/* register handler for processing usrloc packets from the bin interface */
	if (accept_replicated_udata &&
		bin_register_cb(repl_module_name.s, receive_binary_packet) < 0) {
		LM_ERR("cannot register binary packet callback!\n");
		return -1;
	}
	
	if(ul_replicate_cluster > 0 && load_clusterer_api(&clusterer_api)!=0){
		LM_DBG("failed to find clusterer API - is clusterer module loaded?\n");
		return -1;	
	}
	
	if(ul_replicate_cluster < 0){
		ul_replicate_cluster = 0;
	}
	
	init_flag = 1;

	return 0;
}
Example #3
0
static int mod_init(void)
{
	pv_spec_t avp_spec;
	int i;

	init_db_url( db_url , 0 /*cannot be null*/);
	siptrace_table.len = strlen(siptrace_table.s);
	date_column.len = strlen(date_column.s);
	callid_column.len = strlen(callid_column.s);
	traced_user_column.len = strlen(traced_user_column.s);
	msg_column.len = strlen(msg_column.s);
	method_column.len = strlen(method_column.s);
	status_column.len = strlen(status_column.s);
	fromproto_column.len = strlen(fromproto_column.s);
	fromip_column.len = strlen(fromip_column.s);
	fromport_column.len = strlen(fromport_column.s);
	toproto_column.len = strlen(toproto_column.s);
	toip_column.len = strlen(toip_column.s);
	toport_column.len = strlen(toport_column.s);
	fromtag_column.len = strlen(fromtag_column.s);
	direction_column.len = strlen(direction_column.s);
	if (traced_user_avp_str.s)
		traced_user_avp_str.len = strlen(traced_user_avp_str.s);
	if (trace_table_avp_str.s)
		trace_table_avp_str.len = strlen(trace_table_avp_str.s);
	if (dup_uri_str.s)
		dup_uri_str.len = strlen(dup_uri_str.s);

	if (trace_local_ip.s)
		parse_trace_local_ip();

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

	fix_flag_name(trace_flag_str, trace_flag);

	trace_flag = get_flag_id_by_name(FLAG_TYPE_MSG, trace_flag_str);

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

	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(trace_to_database_flag!=NULL && *trace_to_database_flag!=0) {
		/* Find a database module */
		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 ((db_con = db_funcs.init(&db_url)) == 0) {
			LM_CRIT("Cannot connect to DB\n");
			return -1;
		}

		if(db_check_table_version(&db_funcs, db_con,
				&siptrace_table, SIPTRACE_TABLE_VERSION) < 0) {
			LM_ERR("error during table version check.\n");
			return -1;
		}

		db_funcs.close(db_con);
		db_con = 0;
	}

	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;



	/* register callbacks to TM */
	if (load_tm_api(&tmb)!=0)
	{
		LM_ERR("can't load tm api\n");
		return -1;
	}

	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;
	}

	/* register sl callback */
	register_slcb_f = (register_slcb_t)find_export("register_slcb", 0, 0);
	if(register_slcb_f==NULL)
	{
		LM_ERR("can't load sl api\n");
		return -1;
	}
	if(register_slcb_f(SLCB_REPLY_OUT,trace_sl_onreply_out, NULL)!=0)
	{
		LM_ERR("can't register trace_sl_onreply_out\n");
		return -1;
	}
	if(register_fwdcb(trace_msg_out_w)!=0)
	{
		LM_ERR("can't register trace_sl_ack_out\n");
		return -1;
	}
	if(enable_ack_trace&&register_slcb_f(SLCB_ACK_IN,trace_sl_ack_in,NULL)!=0)
	{
		LM_ERR("can't register trace_sl_ack_in\n");
		return -1;
	}

	if(dup_uri_str.s!=0) {
		dup_uri_str.len = strlen(dup_uri_str.s);
		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(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 = -1;
		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 = -1;
		trace_table_avp_type = 0;
	}

	if (duplicate_with_hep) {
		load_hep = (load_hep_f)find_export("load_hep", 1, 0);
		if (!load_hep) {
			LM_ERR("Can't bind proto hep!\n");
			return -1;
		}

		if (load_hep(&hep_api)) {
			LM_ERR("can't bind proto hep\n");
			return -1;
		}
	}



	/* init the DB keys for future queries */
	db_keys[0] = &msg_column;
	db_keys[1] = &callid_column;
	db_keys[2] = &method_column;
	db_keys[3] = &status_column;
	db_keys[4] = &fromproto_column;
	db_keys[5] = &fromip_column;
	db_keys[6] = &fromport_column;
	db_keys[7] = &toproto_column;
	db_keys[8] = &toip_column;
	db_keys[9] = &toport_column;
	db_keys[10] = &date_column;
	db_keys[11] = &direction_column;
	db_keys[12] = &fromtag_column;
	db_keys[13] = &traced_user_column;

	/* init DB values info which is constant ( type, null ) */
	db_vals[0].type = DB_BLOB;
	db_vals[1].type = DB_STR;
	db_vals[2].type = DB_STR;
	db_vals[3].type = DB_STR;
	db_vals[4].type = DB_STR;
	db_vals[5].type = DB_STR;
	db_vals[6].type = DB_INT;
	db_vals[7].type = DB_STR;
	db_vals[8].type = DB_STR;
	db_vals[9].type = DB_INT;
	db_vals[10].type = DB_DATETIME;
	db_vals[11].type = DB_STRING;
	db_vals[12].type = DB_STR;
	db_vals[13].type = DB_STR;
	/* no field can be null */
	for (i=0;i<NR_KEYS;i++)
		db_vals[i].nul = 0;

	return 0;
}
Example #4
0
/*! \brief
 * Initialize parent
 */
static int mod_init(void)
{
	pv_spec_t avp_spec;
	str s;
	bind_usrloc_t bind_usrloc;

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

	/* load SIGNALING API */
	if(load_sig_api(&sigb)< 0) {
		LM_ERR("can't load signaling functions\n");
		return -1;
	}

	/* load TM API */
	memset(&tmb, 0, sizeof(struct tm_binds));
	load_tm_api(&tmb);

	realm_prefix.s = realm_pref;
	realm_prefix.len = strlen(realm_pref);

	rcv_param.len = strlen(rcv_param.s);

	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 = -1;
		rcv_avp_type = 0;
	}

	if (mct_avp_param && *mct_avp_param) {
		s.s = mct_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", mct_avp_param);
			return -1;
		}

		if(pv_get_avp_name(0, &avp_spec.pvp, &mct_avp_name, &mct_avp_type)!=0)
		{
			LM_ERR("[%s]- invalid AVP definition\n", mct_avp_param);
			return -1;
		}
	} else {
		mct_avp_name = -1;
		mct_avp_type = 0;
	}

	if (attr_avp_param && *attr_avp_param) {
		s.s = attr_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", attr_avp_param);
			return -1;
		}

		if(pv_get_avp_name(0, &avp_spec.pvp, &attr_avp_name, &attr_avp_type)!=0)
		{
			LM_ERR("[%s]- invalid AVP definition\n", attr_avp_param);
			return -1;
		}
	} else {
		attr_avp_name = -1;
		attr_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 */
	if (default_q != Q_UNSPECIFIED) {
		if (default_q > MAX_Q) {
			LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", default_q, MAX_Q);
			default_q = MAX_Q;
		} else if (default_q < MIN_Q) {
			LM_DBG("default_q = %d, raising to MIN_Q: %d\n", default_q, MIN_Q);
			default_q = MIN_Q;
		}
	}


	if (bind_usrloc(&ul) < 0) {
		return -1;
	}

	/*
	 * Import use_domain parameter from usrloc
	 */
	reg_use_domain = ul.use_domain;

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

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

	/* fix the flags */
	fix_flag_name(tcp_persistent_flag_s, tcp_persistent_flag);
	tcp_persistent_flag = get_flag_id_by_name(FLAG_TYPE_MSG, tcp_persistent_flag_s);
	tcp_persistent_flag = (tcp_persistent_flag!=-1)?(1<<tcp_persistent_flag):0;

	return 0;
}
Example #5
0
File: tm.c Project: Deni90/opensips
static int mod_init(void)
{
	unsigned int timer_sets,set;
	unsigned int roundto_init;

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

	/* checking if we have sufficient bitmap capacity for given
	   maximum number of  branches */
	if (MAX_BRANCHES+1>31) {
		LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n",
			MAX_BRANCHES );
		return -1;
	}

	fix_flag_name(minor_branch_flag_str, minor_branch_flag);

	minor_branch_flag =
		get_flag_id_by_name(FLAG_TYPE_BRANCH, minor_branch_flag_str);

	if (minor_branch_flag!=-1) {
		if (minor_branch_flag > (8*sizeof(int)-1)) {
			LM_CRIT("invalid minor branch flag\n");
			return -1;
		}
		minor_branch_flag = 1<<minor_branch_flag;
	} else {
		minor_branch_flag = 0;
	}

	/* if statistics are disabled, prevent their registration to core */
	if (tm_enable_stats==0)
#ifdef STATIC_TM
		tm_exports.stats = 0;
#else
		exports.stats = 0;
#endif

	if (init_callid() < 0) {
		LM_CRIT("Error while initializing Call-ID generator\n");
		return -1;
	}

	/* how many timer sets do we need to create? */
	timer_sets = (timer_partitions<=1)?1:timer_partitions ;

	/* try first allocating all the structures needed for syncing */
	if (lock_initialize( timer_sets )==-1)
		return -1;

	/* building the hash table*/
	if (!init_hash_table( timer_sets )) {
		LM_ERR("initializing hash_table failed\n");
		return -1;
	}

	/* init static hidden values */
	init_t();

	if (!tm_init_timers( timer_sets ) ) {
		LM_ERR("timer init failed\n");
		return -1;
	}

	/* the ROUNDTO macro taken from the locking interface */
#ifdef ROUNDTO
	roundto_init = ROUNDTO;
#else
	roundto_init = sizeof(void *);
#endif
	while (roundto_init != 1) {
		tm_timer_shift++;
		roundto_init >>= 1;
	}

	LM_DBG("timer set shift is %d\n", tm_timer_shift);


	/* register the timer functions */
	for ( set=0 ; set<timer_sets ; set++ ) {
		if (register_timer( "tm-timer", timer_routine,
		(void*)(long)set, 1, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) {
			LM_ERR("failed to register timer for set %d\n",set);
			return -1;
		}
		if (register_utimer( "tm-utimer", utimer_routine,
		(void*)(long)set, 100*1000, TIMER_FLAG_DELAY_ON_DELAY)<0) {
			LM_ERR("failed to register utimer for set %d\n",set);
			return -1;
		}
	}

	if (uac_init()==-1) {
		LM_ERR("uac_init failed\n");
		return -1;
	}

	if (init_tmcb_lists()!=1) {
		LM_CRIT("failed to init tmcb lists\n");
		return -1;
	}

	tm_init_tags();
	init_twrite_lines();
	if (init_twrite_sock() < 0) {
		LM_ERR("failed to create socket\n");
		return -1;
	}

	/* register post-script clean-up function */
	if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) {
		LM_ERR("failed to register POST request callback\n");
		return -1;
	}
	if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) {
		LM_ERR("failed to register PRE request callback\n");
		return -1;
	}

	if(register_pv_context("request", tm_pv_context_request)< 0) {
		LM_ERR("Failed to register pv contexts\n");
		return -1;
	}

	if(register_pv_context("reply", tm_pv_context_reply)< 0) {
		LM_ERR("Failed to register pv contexts\n");
		return -1;
	}

	if ( parse_avp_spec( &uac_ctx_avp, &uac_ctx_avp_id)<0 ) {
		LM_ERR("failed to register AVP name <%s>\n",uac_ctx_avp.s);
		return -1;
	}

	if ( register_async_script_handlers( t_handle_async, t_resume_async )<0 ) {
		LM_ERR("failed to register async handler to core \n");
		return -1;
	}

	return 0;
}
Example #6
0
/*
 * Module initialization function
 */
static int mod_init(void)
{
	bind_auth_t bind_auth;
	str proto_url;

	aaa_map map;

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

	memset(attrs, 0, sizeof(attrs));
	memset(vals, 0, sizeof(vals));
	attrs[A_SERVICE_TYPE].name			= "Service-Type";
	attrs[A_SIP_URI_USER].name			= "Sip-URI-User";
	attrs[A_DIGEST_RESPONSE].name		= "Digest-Response";
	attrs[A_DIGEST_ALGORITHM].name		= "Digest-Algorithm";
	attrs[A_DIGEST_BODY_DIGEST].name	= "Digest-Body-Digest";
	attrs[A_DIGEST_CNONCE].name			= "Digest-CNonce";
	attrs[A_DIGEST_NONCE_COUNT].name	= "Digest-Nonce-Count";
	attrs[A_DIGEST_QOP].name			= "Digest-QOP";
	attrs[A_DIGEST_METHOD].name			= "Digest-Method";
	attrs[A_DIGEST_URI].name			= "Digest-URI";
	attrs[A_DIGEST_NONCE].name			= "Digest-Nonce";
	attrs[A_DIGEST_REALM].name			= "Digest-Realm";
	attrs[A_DIGEST_USER_NAME].name		= "Digest-User-Name";
	attrs[A_USER_NAME].name				= "User-Name";
	attrs[A_CISCO_AVPAIR].name			= "Cisco-AVPair";
	attrs[A_SIP_AVP].name				= "SIP-AVP";
	attrs[A_ACCT_SESSION_ID].name		= "Acct-Session-Id";
	vals[V_SIP_SESSION].name			= "Sip-Session";

	fix_flag_name(&use_ruri_flag_str, use_ruri_flag);
	use_ruri_flag = get_flag_id_by_name(FLAG_TYPE_MSG, use_ruri_flag_str);

	if (!aaa_proto_url) {
		LM_ERR("aaa_url is empty\n");
		return -1;
	}

	proto_url.s = aaa_proto_url;
	proto_url.len = strlen(aaa_proto_url);

	if(aaa_prot_bind(&proto_url, &proto)) {
		LM_ERR("aaa protocol bind failure\n");
		return -1;
	}

	if (!(conn = proto.init_prot(&proto_url))) {
		LM_ERR("aaa init protocol failure\n");
		return -2;
	}

	map.name = "Cisco";
	if (proto.dictionary_find(conn, &map, AAA_DICT_FIND_VEND)) {
		LM_DBG("no `Cisco' vendor in AAA protocol dictionary\n");
		attrs[A_CISCO_AVPAIR].name = NULL;
	}

	bind_auth = (bind_auth_t)find_export("bind_auth", 0, 0);
	if (!bind_auth) {
		LM_ERR("unable to find bind_auth function. Check if you load the auth module.\n");
		return -1;
	}

	if (bind_auth(&auth_api) < 0) {
		LM_ERR("cannot bind to auth module\n");
		return -4;
	}

	INIT_AV(proto, conn, attrs, A_MAX, vals, V_MAX, "auth_aaa", -5, -6);

	if (service_type != -1) {
		vals[V_SIP_SESSION].value = service_type;
	}

	return 0;
}
Example #7
0
static int
mod_init(void)
{
    pv_spec_t avp_spec;

    // initialize the canonical_uri_avp structure
    if (canonical_uri_avp.spec.s==NULL || *(canonical_uri_avp.spec.s)==0) {
        LM_ERR("missing/empty canonical_uri_avp parameter. using default.\n");
        canonical_uri_avp.spec.s = CANONICAL_URI_AVP_SPEC;
    }
    canonical_uri_avp.spec.len = strlen(canonical_uri_avp.spec.s);
    if (pv_parse_spec(&(canonical_uri_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) {
        LM_CRIT("invalid AVP specification for canonical_uri_avp: `%s'\n", canonical_uri_avp.spec.s);
        return -1;
    }
    if (pv_get_avp_name(0, &(avp_spec.pvp), &(canonical_uri_avp.name), &(canonical_uri_avp.type))!=0) {
        LM_CRIT("invalid AVP specification for canonical_uri_avp: `%s'\n", canonical_uri_avp.spec.s);
        return -1;
    }

    // initialize the signaling_ip_avp structure
    if (signaling_ip_avp.spec.s==NULL || *(signaling_ip_avp.spec.s)==0) {
        LM_ERR("missing/empty signaling_ip_avp parameter. using default.\n");
        signaling_ip_avp.spec.s = SIGNALING_IP_AVP_SPEC;
    }
    signaling_ip_avp.spec.len = strlen(signaling_ip_avp.spec.s);
    if (pv_parse_spec(&(signaling_ip_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) {
        LM_CRIT("invalid AVP specification for signaling_ip_avp: `%s'\n", signaling_ip_avp.spec.s);
        return -1;
    }
    if (pv_get_avp_name(0, &(avp_spec.pvp), &(signaling_ip_avp.name), &(signaling_ip_avp.type))!=0) {
        LM_CRIT("invalid AVP specification for signaling_ip_avp: `%s'\n", signaling_ip_avp.spec.s);
        return -1;
    }

    // initialize the call_limit_avp structure
    if (call_limit_avp.spec.s==NULL || *(call_limit_avp.spec.s)==0) {
        LM_ERR("missing/empty call_limit_avp parameter. using default.\n");
        call_limit_avp.spec.s = CALL_LIMIT_AVP_SPEC;
    }
    call_limit_avp.spec.len = strlen(call_limit_avp.spec.s);
    if (pv_parse_spec(&(call_limit_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) {
        LM_CRIT("invalid AVP specification for call_limit_avp: `%s'\n", call_limit_avp.spec.s);
        return -1;
    }
    if (pv_get_avp_name(0, &(avp_spec.pvp), &(call_limit_avp.name), &(call_limit_avp.type))!=0) {
        LM_CRIT("invalid AVP specification for call_limit_avp: `%s'\n", call_limit_avp.spec.s);
        return -1;
    }

    // initialize the call_token_avp structure
    if (call_token_avp.spec.s==NULL || *(call_token_avp.spec.s)==0) {
        LM_ERR("missing/empty call_token_avp parameter. using default.\n");
        call_token_avp.spec.s = CALL_TOKEN_AVP_SPEC;
    }
    call_token_avp.spec.len = strlen(call_token_avp.spec.s);
    if (pv_parse_spec(&(call_token_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) {
        LM_CRIT("invalid AVP specification for call_token_avp: `%s'\n", call_token_avp.spec.s);
        return -1;
    }
    if (pv_get_avp_name(0, &(avp_spec.pvp), &(call_token_avp.name), &(call_token_avp.type))!=0) {
        LM_CRIT("invalid AVP specification for call_token_avp: `%s'\n", call_token_avp.spec.s);
        return -1;
    }

    // initialize the diverter_avp structure
    if (diverter_avp.spec.s==NULL || *(diverter_avp.spec.s)==0) {
        LM_ERR("missing/empty diverter_avp parameter. using default.\n");
        diverter_avp.spec.s = DIVERTER_AVP_SPEC;
    }
    diverter_avp.spec.len = strlen(diverter_avp.spec.s);
    if (pv_parse_spec(&(diverter_avp.spec), &avp_spec)==0 || avp_spec.type!=PVT_AVP) {
        LM_CRIT("invalid AVP specification for diverter_avp: `%s'\n", diverter_avp.spec.s);
        return -1;
    }
    if (pv_get_avp_name(0, &(avp_spec.pvp), &(diverter_avp.name), &(diverter_avp.type))!=0) {
        LM_CRIT("invalid AVP specification for diverter_avp: `%s'\n", diverter_avp.spec.s);
        return -1;
    }

    // bind to the dialog API
    if (load_dlg_api(&dlg_api)!=0) {
        LM_CRIT("cannot load the dialog module API\n");
        return -1;
    }

    // register dialog loading callback
    if (dlg_api.register_dlgcb(NULL, DLGCB_LOADED, __dialog_loaded, NULL, NULL) != 0) {
        LM_CRIT("cannot register callback for dialogs loaded from the database\n");
    }

    fix_flag_name(prepaid_account_str, prepaid_account_flag);

    prepaid_account_flag = get_flag_id_by_name(FLAG_TYPE_MSG, prepaid_account_str);

    return 0;
}