コード例 #1
0
ファイル: t_funcs.c プロジェクト: Gaoithe/openimscore_ims
/*
 * Initialize parameters containing the ID of
 * AVPs with variable timers
 */
int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param)
{
	if (fr_timer_param && *fr_timer_param) {
		fr_timer_str.s = fr_timer_param;
		fr_timer_str.len = strlen(fr_timer_str.s);
		if (parse_avp_spec( &fr_timer_str, &fr_timer_avp_type,
		&fr_timer_avp, &fr_timer_index)<0) {
			LOG(L_CRIT,"ERROR:tm:init_avp_params: invalid fr_timer "
				"AVP specs \"%s\"\n", fr_timer_param);
			return -1;
		}
	}

	if (fr_inv_timer_param && *fr_inv_timer_param) {
		fr_inv_timer_str.s = fr_inv_timer_param;
		fr_inv_timer_str.len = strlen(fr_inv_timer_str.s);
		if (parse_avp_spec( &fr_inv_timer_str, &fr_inv_timer_avp_type, 
		&fr_inv_timer_avp, &fr_inv_timer_index)<0) {
			LOG(L_CRIT,"ERROR:tm:init_avp_params: invalid fr_inv_timer "
				"AVP specs \"%s\"\n", fr_inv_timer_param);
			return -1;
		}
	}
	return 0;
}
コード例 #2
0
ファイル: usr_avp.c プロジェクト: Distrotech/opensips
int get_avp_id(str *name)
{
	int id;
	if (parse_avp_spec(name, &id)) {
		LM_ERR("unable to get id\n");
		return -1;
	}
	return id;
}
コード例 #3
0
int init_serialization(void)
{
	str alias = { SERIAL_AVP_ALIAS, sizeof(SERIAL_AVP_ALIAS)-1 };

	if (parse_avp_spec(&alias, &serial_avp)) {
		LM_ERR("cannot parse avp spec\n");
		return -1;
	}
	return 0;
}
コード例 #4
0
ファイル: destination.c プロジェクト: NormB/opensips
/*
 * Parses avps used by this module
 * return 0 success, -1 failure
 */
int ospParseAvps(void)
{
    if (parse_avp_spec(&OSP_INBOUND_NAME, &_osp_inbound_avpid)) {
        LM_ERR("cannot get INBOUND AVP id\n");
        return -1;
    }

    if (parse_avp_spec(&OSP_ORIGDEST_NAME, &_osp_origdest_avpid)) {
        LM_ERR("cannot get ORIGDEST AVP id\n");
        return -1;
    }

    if (parse_avp_spec(&OSP_TERMDEST_NAME, &_osp_termdest_avpid)) {
        LM_ERR("cannot get TERMDEST AVP id\n");
        return -1;
    }

    if (parse_avp_spec(&OSP_CALLING_NAME, &_osp_calling_avpid)) {
        LM_ERR("cannot get CALLING AVP id\n");
        return -1;
    }

    return 0;
}
コード例 #5
0
ファイル: t_fwd.c プロジェクト: rrb3942/opensips
int t_set_reason(struct sip_msg *msg, str *val)
{
	str avp_name = str_init("_reason_avp_internal");
	int_str reason;

	if (_reason_avp_id==0) {
		if (parse_avp_spec( &avp_name, &_reason_avp_id) ) {
			LM_ERR("failed to init the internal AVP\n");
			return -1;
		}
	}

	reason.s = *val;
	if (add_avp( AVP_VAL_STR, _reason_avp_id, reason)!=0) {
		LM_ERR("failed to add the internal reason AVP\n");
		return -1;
	}
	return 1;
}
コード例 #6
0
ファイル: acc_logic.c プロジェクト: ph4r05/opensips
/**
 * types: cdr, missed
 * case insesitive
 *
 */
static inline
unsigned long long do_acc_flags_parser(str* token)
{
	str_trim_spaces_lr(*token);

	if (token->len == do_acc_cdr_s.len &&
			!strncasecmp(token->s, do_acc_cdr_s.s, token->len)) {

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

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

			if (!dlg_api.get_dlg) {
				LM_WARN("error loading dialog module - cdrs cannot be generated\n");
				return 0;
			}

			if (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");

			is_cdr_enabled=1;
		}

		return DO_ACC_CDR;
	} else if (token->len == do_acc_missed_s.len &&
			!strncasecmp(token->s, do_acc_missed_s.s, token->len)) {
		/* load dialog module if these are used */
		return DO_ACC_MISSED;
	} else if (token->len == do_acc_failed_s.len &&
			!strncasecmp(token->s, do_acc_failed_s.s, token->len)) {
		return DO_ACC_FAILED;
	} else {
		return -1;
	}
}
コード例 #7
0
ファイル: ebr_data.c プロジェクト: lemenkov/opensips
static struct usr_avp *pack_evi_params_as_avp_list(evi_params_t *params)
{
	struct usr_avp *avp, *head=NULL;
	evi_param_t *e_param;
	int_str val;
	int avp_id;

	/* take all the EVI parameters and convert them into AVPs */
	for( e_param=params->first ; e_param ; e_param=e_param->next ) {

		/* get an AVP name matching the param name */
		if (parse_avp_spec( &e_param->name, &avp_id)<0) {
			LM_ERR("cannot get AVP ID for name <%.*s>, skipping..\n",
				e_param->name.len, e_param->name.s);
			continue;
		}

		/* create a new AVP */
		if (e_param->flags&EVI_STR_VAL) {
			val.s = e_param->val.s;
			avp = new_avp( AVP_VAL_STR, avp_id, val);
		} else if (e_param->flags&EVI_INT_VAL) {
			val.n = e_param->val.n;
			avp = new_avp( 0, avp_id, val);
		} else {
			LM_BUG("EVI param no STR, nor INT, ignoring...\n");
			continue;
		}

		if (avp==NULL) {
			LM_ERR("cannot get create new AVP name <%.*s>, skipping..\n",
				e_param->name.len, e_param->name.s);
			continue;
		}

		/* link the AVP */
		avp->next = head;
		head = avp;
	}

	return head;
}
コード例 #8
0
ファイル: t_funcs.c プロジェクト: AndyJRobinson/kamailio
/*
 * Initialize parameters containing the ID of
 * AVPs with various timers
 */
int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param)
{
	pv_spec_t avp_spec;
	unsigned short avp_type;

	if (fr_timer_param && *fr_timer_param) {
		fr_timer_str.s = fr_timer_param;
		fr_timer_str.len = strlen(fr_timer_str.s);
		LM_WARN("using AVP for TM fr_timer is deprecated,"
				" use t_set_fr(...) instead\n");

		if(fr_timer_str.s[0]==PV_MARKER) {
			if (pv_parse_spec(&fr_timer_str, &avp_spec)==0
			        || avp_spec.type!=PVT_AVP) {
			        LM_ERR("malformed or non AVP %s AVP definition\n",
							fr_timer_param);
				return -1;
			}

			if(pv_get_avp_name(0, &avp_spec.pvp, &fr_timer_avp, &avp_type)!=0)
			{
				LM_ERR("[%s]- invalid AVP definition\n", fr_timer_param);
				return -1;
			}
			fr_timer_avp_type = avp_type;
		} else {
			if (parse_avp_spec( &fr_timer_str, &fr_timer_avp_type,
			&fr_timer_avp, &fr_timer_index)<0) {
				LOG(L_CRIT,"ERROR:tm:init_avp_params: invalid fr_timer "
					"AVP specs \"%s\"\n", fr_timer_param);
				return -1;
			}
			/* ser flavour uses the To track of AVPs */
			fr_timer_avp_type |= AVP_TRACK_TO;
		}
	}

	if (fr_inv_timer_param && *fr_inv_timer_param) {
		fr_inv_timer_str.s = fr_inv_timer_param;
		fr_inv_timer_str.len = strlen(fr_inv_timer_str.s);
		LM_WARN("using AVP for TM fr_inv_timer is deprecated,"
				" use t_set_fr(...) instead\n");

		if(fr_inv_timer_str.s[0]==PV_MARKER) {
			if (pv_parse_spec(&fr_inv_timer_str, &avp_spec)==0
					|| avp_spec.type!=PVT_AVP) {
				LM_ERR("malformed or non AVP %s AVP definition\n",
					fr_inv_timer_param);
				return -1;
			}

			if(pv_get_avp_name(0, &avp_spec.pvp, &fr_inv_timer_avp,
								&avp_type)!=0)
			{
				LM_ERR("[%s]- invalid AVP definition\n", fr_inv_timer_param);
				return -1;
			}
			fr_inv_timer_avp_type = avp_type;
		} else {
			if (parse_avp_spec( &fr_inv_timer_str, &fr_inv_timer_avp_type, 
			&fr_inv_timer_avp, &fr_inv_timer_index)<0) {
				LOG(L_CRIT,"ERROR:tm:init_avp_params: invalid fr_inv_timer "
					"AVP specs \"%s\"\n", fr_inv_timer_param);
				return -1;
			}
			/* ser flavour uses the To track of AVPs */
			fr_inv_timer_avp_type |= AVP_TRACK_TO;
		}
	}

	return 0;
}
コード例 #9
0
ファイル: load_balancer.c プロジェクト: NormB/opensips
static int mod_init(void)
{
	LM_INFO("Load-Balancer module - initializing\n");

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

	/* Load dialog API */
	if (load_dlg_api(&lb_dlg_binds) != 0) {
		LM_ERR("Can't load dialog hooks\n");
		return -1;
	}

	if (fetch_freeswitch_stats) {
		if (load_fs_api(&fs_api) == -1) {
			LM_ERR("failed to load the FS API!\n");
			return -1;
		}
	}

	/* data pointer in shm */
	curr_data = (struct lb_data**)shm_malloc( sizeof(struct lb_data*) );
	if (curr_data==0) {
		LM_CRIT("failed to get shm mem for data ptr\n");
		return -1;
	}
	*curr_data = 0;

	/* create & init lock */
	if ((ref_lock = lock_init_rw()) == NULL) {
		LM_CRIT("failed to init lock\n");
		return -1;
	}

	if (init_lb_bls()) {
		LM_ERR("BL INIT failed\n");
		return -1;
	}

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

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

	/* close DB connection */
	lb_close_db();

	/* arm a function for probing */
	if (lb_prob_interval) {
		/* load TM API */
		if (load_tm_api(&lb_tmb)!=0) {
			LM_ERR("can't load TM API\n");
			return -1;
		}

		/* probing method */
		lb_probe_method.len = strlen(lb_probe_method.s);
		lb_probe_from.len = strlen(lb_probe_from.s);
		if (lb_probe_replies.s)
			lb_probe_replies.len = strlen(lb_probe_replies.s);

		/* register pinger function */
		if (register_timer( "lb-pinger", lb_prob_handler , NULL,
		lb_prob_interval, TIMER_FLAG_DELAY_ON_DELAY)<0) {
			LM_ERR("failed to register probing handler\n");
			return -1;
		}

		/* Register the max load recalculation timer */
		if (fetch_freeswitch_stats &&
		    register_timer("lb-update-max-load", lb_update_max_loads, NULL,
		           fs_api.stats_update_interval, TIMER_FLAG_SKIP_ON_DELAY)<0) {
			LM_ERR("failed to register timer for max load recalc!\n");
			return -1;
		}

		if (lb_probe_replies.s) {
			lb_probe_replies.len = strlen(lb_probe_replies.s);
			if(parse_reply_codes( &lb_probe_replies, &probing_reply_codes,
			&probing_codes_no )< 0) {
				LM_ERR("Bad format for options_reply_code parameter"
					" - Need a code list separated by commas\n");
				return -1;
			}
		}
	}

	/* parse avps */
	if (parse_avp_spec(&group_avp_name_s, &group_avp_name)) {
		LM_ERR("cannot parse group avp\n");
		return -1;
	}
	if (parse_avp_spec(&flags_avp_name_s, &flags_avp_name)) {
		LM_ERR("cannot parse flags avp\n");
		return -1;
	}
	if (parse_avp_spec(&mask_avp_name_s, &mask_avp_name)) {
		LM_ERR("cannot parse mask avp\n");
		return -1;
	}
	if (parse_avp_spec(&id_avp_name_s, &id_avp_name)) {
		LM_ERR("cannot parse id avp\n");
		return -1;
	}
	if (parse_avp_spec(&res_avp_name_s, &res_avp_name)) {
		LM_ERR("cannot parse resources avp\n");
		return -1;
	}

	if (lb_init_event() < 0) {
		LM_ERR("cannot init event\n");
		return -1;
	}

	if (lb_repl_cluster < 0) {
		LM_ERR("Invalid replication_cluster, must be 0 or "
			"a positive cluster id\n");
		return -1;
	}

	if (lb_repl_cluster && load_clusterer_api(&clusterer_api)!=0) {
		LM_DBG("failed to find clusterer API - is clusterer module loaded?\n");
		return -1;
	}

	/* register handler for processing load_balancer replication packets to the clusterer module */
	if (lb_repl_cluster > 0 &&
		clusterer_api.register_capability(&status_repl_cap,
		receive_lb_binary_packet, NULL, lb_repl_cluster, 0, NODE_CMP_ANY) < 0) {
		LM_ERR("cannot register binary packet callback to clusterer module!\n");
		return -1;
	}

	return 0;
}
コード例 #10
0
ファイル: load_balancer.c プロジェクト: NoamRom89/opensips
static int mod_init(void)
{
	LM_INFO("Load-Balancer module - initializing\n");

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

	/* Load dialog API */
	if (load_dlg_api(&lb_dlg_binds) != 0) {
		LM_ERR("Can't load dialog hooks");
		return -1;
	}

	/* data pointer in shm */
	curr_data = (struct lb_data**)shm_malloc( sizeof(struct lb_data*) );
	if (curr_data==0) {
		LM_CRIT("failed to get shm mem for data ptr\n");
		return -1;
	}
	*curr_data = 0;

	/* create & init lock */
	if ((ref_lock = lock_init_rw()) == NULL) {
		LM_CRIT("failed to init lock\n");
		return -1;
	}

	if (init_lb_bls()) {
		LM_ERR("BL INIT failed\n");
		return -1;
	}

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

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

	/* close DB connection */
	lb_close_db();

	/* arm a function for probing */
	if (lb_prob_interval) {
		/* load TM API */
		if (load_tm_api(&lb_tmb)!=0) {
			LM_ERR("can't load TM API\n");
			return -1;
		}

		/* probing method */
		lb_probe_method.len = strlen(lb_probe_method.s);
		lb_probe_from.len = strlen(lb_probe_from.s);
		if (lb_probe_replies.s)
			lb_probe_replies.len = strlen(lb_probe_replies.s);

		/* register pinger function */
		if (register_timer( "lb-pinger", lb_prob_handler , NULL,
		lb_prob_interval)<0) {
			LM_ERR("failed to register probing handler\n");
			return -1;
		}

		if (lb_probe_replies.s) {
			lb_probe_replies.len = strlen(lb_probe_replies.s);
			if(parse_reply_codes( &lb_probe_replies, &probing_reply_codes,
			&probing_codes_no )< 0) {
				LM_ERR("Bad format for options_reply_code parameter"
					" - Need a code list separated by commas\n");
				return -1;
			}
		}

	}

	/* parse avps */
	if (parse_avp_spec(&grp_avp_name_s, &grp_avp_name)) {
		LM_ERR("cannot parse group avp\n");
		return -1;
	}
	if (parse_avp_spec(&mask_avp_name_s, &mask_avp_name)) {
		LM_ERR("cannot parse mask avp\n");
		return -1;
	}
	if (parse_avp_spec(&id_avp_name_s, &id_avp_name)) {
		LM_ERR("cannot parse id avp\n");
		return -1;
	}

	return 0;
}
コード例 #11
0
ファイル: tm.c プロジェクト: 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;
}
コード例 #12
0
ファイル: cpl.c プロジェクト: SibghatullahSheikh/kamailio
static int cpl_init(void)
{
	bind_usrloc_t bind_usrloc;
	load_tm_f     load_tm;
	struct stat   stat_t;
	char *ptr;
	int val;
	str foo;

	LOG(L_INFO,"CPL - initializing\n");

	/* check the module params */
	if (DB_URL==0) {
		LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_db\" "
			"found empty\n");
		goto error;
	}

	if (DB_TABLE==0) {
		LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_table\" "
			"found empty\n");
		goto error;
	}

	if (cpl_env.proxy_recurse>MAX_PROXY_RECURSE) {
		LOG(L_CRIT,"ERROR:cpl_init: value of proxy_recurse param (%d) exceeds "
			"the maximum safety value (%d)\n",
			cpl_env.proxy_recurse,MAX_PROXY_RECURSE);
		goto error;
	}

	/* fix the timer_avp name */
	if (timer_avp) {
		foo.s = timer_avp;
		foo.len = strlen(foo.s);
		if (parse_avp_spec(&foo,&cpl_env.timer_avp_type,&cpl_env.timer_avp,0)<0){
			LOG(L_CRIT,"ERROR:cpl_init: invalid timer AVP specs \"%s\"\n",
				timer_avp);
			goto error;
		}
		if (cpl_env.timer_avp_type&AVP_NAME_STR && cpl_env.timer_avp.s.s==foo.s) {
			cpl_env.timer_avp.s = foo;
		}
	}

	if (dtd_file==0) {
		LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_dtd_file\" "
			"found empty\n");
		goto error;
	} else {
		/* check if the dtd file exists */
		if (stat( dtd_file, &stat_t)==-1) {
			LOG(L_ERR,"ERROR:cpl_init: checking file \"%s\" status failed;"
				" stat returned %s\n",dtd_file,strerror(errno));
			goto error;
		}
		if ( !S_ISREG( stat_t.st_mode ) ) {
			LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" is not a regular file!\n",
				dtd_file);
			goto error;
		}
		if (access( dtd_file, R_OK )==-1) {
			LOG(L_ERR,"ERROR:cpl_init: checking file \"%s\" for permissions "
				"failed; access returned %s\n",dtd_file,strerror(errno));
			goto error;
		}
	}

	if (cpl_env.log_dir==0) {
		LOG(L_INFO,"INFO:cpl_init: log_dir param found void -> logging "
			" disabled!\n");
	} else {
		if ( strlen(cpl_env.log_dir)>MAX_LOG_DIR_SIZE ) {
			LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" has a too long name :-(!\n",
				cpl_env.log_dir);
			goto error;
		}
		/* check if the dir exists */
		if (stat( cpl_env.log_dir, &stat_t)==-1) {
			LOG(L_ERR,"ERROR:cpl_init: checking dir \"%s\" status failed;"
				" stat returned %s\n",cpl_env.log_dir,strerror(errno));
			goto error;
		}
		if ( !S_ISDIR( stat_t.st_mode ) ) {
			LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" is not a directory!\n",
				cpl_env.log_dir);
			goto error;
		}
		if (access( cpl_env.log_dir, R_OK|W_OK )==-1) {
			LOG(L_ERR,"ERROR:cpl_init: checking dir \"%s\" for permissions "
				"failed; access returned %s\n",
				cpl_env.log_dir, strerror(errno));
			goto error;
		}
	}

	/* import the TM auto-loading function */
	if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) {
		LOG(L_ERR, "ERROR:cpl_c:cpl_init: cannot import load_tm\n");
		goto error;
	}
	/* let the auto-loading function load all TM stuff */
	if (load_tm( &(cpl_fct.tmb) )==-1)
		goto error;

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

	/* bind to usrloc module if requested */
	if (lookup_domain) {
		/* import all usrloc functions */
		bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
		if (!bind_usrloc) {
			LOG(L_ERR, "ERROR:cpl_c:cpl_init: Can't bind usrloc\n");
			goto error;
		}
		if (bind_usrloc( &(cpl_fct.ulb) ) < 0) {
			LOG(L_ERR, "ERROR:cpl_c:cpl_init: importing usrloc failed\n");
			goto error;
		}
		/* convert lookup_domain from char* to udomain_t* pointer */
		if (cpl_fct.ulb.register_udomain( lookup_domain, &cpl_env.lu_domain)
		< 0) {
			LOG(L_ERR, "ERROR:cpl_c:cpl_init: Error while registering domain "
				"<%s>\n",lookup_domain);
			goto error;
		}
	} else {
		LOG(L_NOTICE,"NOTICE:cpl_init: no lookup_domain given -> disable "
			" lookup node\n");
	}

	/* build a pipe for sending commands to aux process */
	if ( pipe( cpl_env.cmd_pipe )==-1 ) {
		LOG(L_CRIT,"ERROR:cpl_init: cannot create command pipe: %s!\n",
			strerror(errno) );
		goto error;
	}
	/* set the writing non blocking */
	if ( (val=fcntl(cpl_env.cmd_pipe[1], F_GETFL, 0))<0 ) {
		LOG(L_ERR,"ERROR:cpl_init: getting flags from pipe[1] failed: fcntl "
			"said %s!\n",strerror(errno));
		goto error;
	}
	if ( fcntl(cpl_env.cmd_pipe[1], F_SETFL, val|O_NONBLOCK) ) {
		LOG(L_ERR,"ERROR:cpl_init: setting flags to pipe[1] failed: fcntl "
			"said %s!\n",strerror(errno));
		goto error;
	}

	/* init the CPL parser */
	if (init_CPL_parser( dtd_file )!=1 ) {
		LOG(L_ERR,"ERROR:cpl_init: init_CPL_parser failed!\n");
		goto error;
	}

	/* make a copy of the original TZ env. variable */
	ptr = getenv("TZ");
	cpl_env.orig_tz.len = 3/*"TZ="*/ + (ptr?(strlen(ptr)+1):0);
	if ( (cpl_env.orig_tz.s=shm_malloc( cpl_env.orig_tz.len ))==0 ) {
		LOG(L_ERR,"ERROR:cpl_init: no more shm mem. for saving TZ!\n");
		goto error;
	}
	memcpy(cpl_env.orig_tz.s,"TZ=",3);
	if (ptr)
		strcpy(cpl_env.orig_tz.s+3,ptr);

	/* convert realm_prefix from string null terminated to str */
	if (cpl_env.realm_prefix.s) {
		/* convert the realm_prefix to lower cases */
		strlower( &cpl_env.realm_prefix );
	}

	/* Register a child process that will keep updating
	 * its local configuration */
	cfg_register_child(1);

	return 0;
error:
	return -1;
}
コード例 #13
0
ファイル: tls_mgm.c プロジェクト: Danfx/opensips
static int mod_init(void){
	str s;
	int n;

	LM_INFO("initializing TLS protocol\n");


	if (tls_db_enabled != 0 && tls_db_enabled != 1) {
		tls_db_enabled = 1;
	}

	if (tls_db_enabled) {

		/* create & init lock */
		if ((dom_lock = lock_init_rw()) == NULL) {
			LM_CRIT("failed to init lock\n");
			return -1;
		}

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

		tls_db_table.len = strlen(tls_db_table.s);

		if (tls_db_table.len == 0) {
			LM_ERR("db url not specified\n");
			return -1;
		}

		id_col.len = strlen(id_col.s);
		address_col.len = strlen(address_col.s);
		type_col.len = strlen(type_col.s);
		method_col.len = strlen(method_col.s);
		verify_cert_col.len = strlen(verify_cert_col.s);
		require_cert_col.len = strlen(require_cert_col.s);
		certificate_col.len = strlen(certificate_col.s);
		pk_col.len = strlen(pk_col.s);
		crl_check_col.len = strlen(crl_check_col.s);
		calist_col.len = strlen(calist_col.s);
		cadir_col.len = strlen(cadir_col.s);
		cplist_col.len = strlen(cplist_col.s);
		dhparams_col.len = strlen(dhparams_col.s);
		eccurve_col.len = strlen(eccurve_col.s);

		if (db_bind_mod(&tls_db_url, &dr_dbf)) {
			LM_CRIT("cannot bind to database module! "
				"Did you forget to load a database module ?\n");
			return -1;
		}
		/* init DB connection */
		if ((db_hdl = dr_dbf.init(&tls_db_url)) == 0) {
			LM_CRIT("cannot initialize database connection\n");
			return -1;
		}

		if (dr_dbf.use_table(db_hdl, &tls_db_table) < 0) {
			LM_ERR("cannot select table \"%.*s\"\n", tls_db_table.len, tls_db_table.s);
			return -1;
		}
	}

	if (tls_domain_avp) {
		s.s = tls_domain_avp;
		s.len = strlen(s.s);
		if (parse_avp_spec( &s, &tls_client_domain_avp)) {
			LM_ERR("cannot parse tls_client_avp");
			return -1;
		}
	}

	/*
	 * this has to be called before any function calling CRYPTO_malloc,
	 * CRYPTO_malloc will set allow_customize in openssl to 0
	 */
	if (!CRYPTO_set_mem_functions(os_malloc, os_realloc, os_free)) {
		LM_ERR("unable to set the memory allocation functions\n");
		LM_ERR("NOTE: check if you have openssl 1.0.1e-fips, as this "
			"version is know to be broken; if so, you need to upgrade or "
			"downgrade to a differen openssl version !!\n");
		return -1;
	}

#if !defined(OPENSSL_NO_COMP)
	STACK_OF(SSL_COMP)* comp_methods;
	/* disabling compression */
	LM_WARN("disabling compression due ZLIB problems\n");
	comp_methods = SSL_COMP_get_compression_methods();
	if (comp_methods==0) {
		LM_INFO("openssl compression already disabled\n");
	} else {
		sk_SSL_COMP_zero(comp_methods);
	}
#endif
	if (tls_init_multithread() < 0) {
		LM_ERR("failed to init multi-threading support\n");
		return -1;
	}

	SSL_library_init();
	SSL_load_error_strings();
	init_ssl_methods();

	n = check_for_krb();
	if (n==-1) {
		LM_ERR("kerberos check failed\n");
		return -1;
	}

	if ( ( n ^
#ifndef OPENSSL_NO_KRB5
			1
#else
			0
#endif
		 )!=0 ) {
		LM_ERR("compiled agaist an openssl with %s"
				"kerberos, but run with one with %skerberos\n",
				(n==1)?"":"no ",(n!=1)?"no ":"");
		return -1;
	}

	/*
	 * finish setting up the tls default domains
	 */
	tls_default_client_domain.type = TLS_DOMAIN_DEF|TLS_DOMAIN_CLI ;
	tls_default_client_domain.addr.af = AF_INET;

	tls_default_server_domain.type = TLS_DOMAIN_DEF|TLS_DOMAIN_SRV;
	tls_default_server_domain.addr.af = AF_INET;

	/*
	 * now initialize tls default domains
	 */
	if ( (n=init_tls_domains(&tls_default_server_domain)) ) {
		return n;
	}

	if ( (n=init_tls_domains(&tls_default_client_domain)) ) {
		return n;
	}
	/*
	 * now initialize tls virtual domains
	 */
	
	if (tls_db_enabled && load_info(&dr_dbf, db_hdl, &tls_db_table, &tls_server_domains,
			&tls_client_domains)){
		return -1;
	}

	if ( (n=init_tls_domains(tls_server_domains)) ) {
		return n;
	}

	if ( (n=init_tls_domains(tls_client_domains)) ) {
		return n;
	}
	/*
	 * we are all set
	 */
	return 0;

}
コード例 #14
0
ファイル: t_fifo.c プロジェクト: BackupTheBerlios/ser
/* tw_append syntax:
 * tw_append = name:element[;element]
 * element   = [title=]value 
 * value     = avp[avp_spec] | hdr[hdr_name] | msg[body] */
int parse_tw_append( modparam_t type, void* val)
{
	struct hdr_field hdr;
	struct hdr_avp *last;
	struct hdr_avp *ha;
	struct tw_append *app;
	int_str avp_name;
	char *s;
	char bar;
	str foo;
	int n;
	int index;
	
	if (val==0 || ((char*)val)[0]==0)
		return 0;
	s = (char*)val;

	/* start parsing - first the name */
	while( *s && isspace((int)*s) )  s++;
	if ( !*s || *s==':')
		goto parse_error;
	foo.s = s;
	while ( *s && *s!=':' && !isspace((int)*s) ) s++;
	if ( !*s || foo.s==s )
		goto parse_error;
	foo.len = s - foo.s;
	/* parse separator */
	while( *s && isspace((int)*s) )  s++;
	if ( !*s || *s!=':')
		goto parse_error;
	s++;
	while( *s && isspace((int)*s) )  s++;
	if ( !*s )
		goto parse_error;

	/* check for name duplication */
	for(app=tw_appends;app;app=app->next)
		if (app->name.len==foo.len && !strncasecmp(app->name.s,foo.s,foo.len)){
			LOG(L_ERR,"ERROR:tm:parse_tw_append: duplicated tw_append name "
				"<%.*s>\n",foo.len,foo.s);
			goto error;
		}

	/* new tw_append structure */
	app = (struct tw_append*)pkg_malloc( sizeof(struct tw_append) );
	if (app==0) {
		LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg memory\n");
		goto error;
	}
	app->name.s = (char*)pkg_malloc( foo.len+1 );
	if (app->name.s==0) {
		LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg memory\n");
		goto error;
	}
	memcpy( app->name.s, foo.s, foo.len);
	app->name.len = foo.len;
	app->name.s[app->name.len] = 0;
	last = app->elems = 0;
	app->next = tw_appends;
	tw_appends = app;

	/* parse the elements */
	while (*s) {
		/* parse element title or element type */
		foo.s = s;
		while( *s && *s!='[' && *s!='=' && *s!=';' && !isspace((int)*s) ) s++;
		if ( !*s || foo.s==s)
			goto parse_error;
		foo.len = s - foo.s;
		/* new hdr_avp structure */
		ha = (struct hdr_avp*)pkg_malloc( sizeof(struct hdr_avp) );
		if (ha==0) {
			LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg memory\n");
			goto error;
		}
		memset( ha, 0, sizeof(struct hdr_avp));
		if (*s!='[') {
			/* foo must by title or some error -> parse separator */
			while( *s && isspace((int)*s) )  s++;
			if ( !*s || *s!='=')
				goto parse_error;
			s++;
			while( *s && isspace((int)*s) )  s++;
			if ( !*s )
				goto parse_error;
			/* set the title */
			ha->title.s = (char*)pkg_malloc( foo.len+1 );
			if (ha->title.s==0) {
				LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg memory\n");
				goto error;
			}
			memcpy( ha->title.s, foo.s, foo.len);
			ha->title.len = foo.len;
			ha->title.s[ha->title.len] = 0;
			/* parse the type now */
			foo.s = s;
			while( *s && *s!='[' && *s!=']' && *s!=';' && !isspace((int)*s) )
				s++;
			if ( *s!='[' || foo.s==s)
				goto parse_error;
			foo.len = s - foo.s;
		}
		/* foo containes the elemet type */
		if ( foo.len==ELEM_TYPE_AVP_LEN &&
		!strncasecmp( foo.s, ELEM_TYPE_AVP, foo.len) ) {
			ha->type = ELEM_IS_AVP;
		} else if ( foo.len==ELEM_TYPE_HDR_LEN &&
		!strncasecmp( foo.s, ELEM_TYPE_HDR, foo.len) ) {
			ha->type = ELEM_IS_HDR;
		} else if ( foo.len==ELEM_TYPE_MSG_LEN &&
		!strncasecmp( foo.s, ELEM_TYPE_MSG, foo.len) ) {
			ha->type = ELEM_IS_MSG;
		} else {
			LOG(L_ERR,"ERROR:tm:parse_tw_append: unknown type <%.*s>\n",
				foo.len, foo.s);
			goto error;
		}
		/* parse the element name */
		s++;
		foo.s = s;
		while( *s && *s!=']' && *s!=';' && !isspace((int)*s) ) s++;
		if ( *s!=']' || foo.s==s )
			goto parse_error;
		foo.len = s - foo.s;
		s++;
		/* process and optimize the element name */
		if (ha->type==ELEM_IS_AVP) {
			/* element is AVP */
			if ( parse_avp_spec( &foo, &n, &avp_name, &index)!=0 ) {
				LOG(L_ERR,"ERROR:tm:parse_tw_append: bad alias spec "
					"<%.*s>\n",foo.len, foo.s);
				goto error;
			}
			if (n&AVP_NAME_STR) {
				/* string name */
				ha->sval.s = (char*)pkg_malloc(avp_name.s.len+1);
				if (ha->sval.s==0) {
					LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg mem\n");
					goto error;
				}
				memcpy( ha->sval.s, avp_name.s.s, avp_name.s.len);
				ha->sval.len = avp_name.s.len;
				ha->sval.s[ha->sval.len] = 0;
				if (ha->title.s==0)
					ha->title = ha->sval;
			} else {
				/* ID name - if title is missing, convert the ID to
				 * string and us it a title */
				ha->ival = avp_name.n;
				if (ha->title.s==0) {
					foo.s=int2str((unsigned long)ha->ival, &foo.len);
					ha->title.s = (char*)pkg_malloc( n+1 );
					if (ha->title.s==0) {
						LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg "
							"memory\n");
						goto error;
					}
					memcpy( ha->title.s, foo.s, foo.len);
					ha->title.len = foo.len;
					ha->title.s[ha->title.len] = 0;
				}
			}
		} else if (ha->type==ELEM_IS_HDR) {
			/* element is HDR -  try to get it's coded type if defined */
			bar = foo.s[foo.len];
			foo.s[foo.len] = ':';
			/* parse header name */
			if (parse_hname2( foo.s, foo.s+foo.len+1, &hdr)==0) {
				LOG(L_ERR,"BUG:tm_parse_tw_append: parse header failed\n");
				goto error;
			}
			foo.s[foo.len] = bar;
			ha->ival = hdr.type;
			if (hdr.type==HDR_OTHER_T || ha->title.s==0) {
				/* duplicate hdr name */
				ha->sval.s = (char*)pkg_malloc(foo.len+1);
				if (ha->sval.s==0) {
					LOG(L_ERR,"ERROR:tm:parse_tw_append: no more pkg mem\n");
					goto error;
				}
				memcpy( ha->sval.s, foo.s, foo.len);
				ha->sval.len = foo.len;
				ha->sval.s[ha->sval.len] = 0;
				if (ha->title.s==0)
					ha->title = ha->sval;
			}
		} else {
			/* element is MSG */
			if ( !(foo.len==ELEM_VAL_BODY_LEN &&
			!strncasecmp(ELEM_VAL_BODY,foo.s,foo.len)) ) {
				LOG(L_ERR,"ERROR:tm:parse_tw_append: unsupported value <%.*s>"
					" for msg type\n",foo.len,foo.s);
				goto error;
			}
			app->add_body = 1;
			pkg_free( ha );
			ha = 0;
		}

		/* parse the element separator, if present */
		while( *s && isspace((int)*s) )  s++;
		if ( *s && *s!=';')
			goto parse_error;
		if (*s==';') {
			s++;
			while( *s && isspace((int)*s) )  s++;
			if (!*s)
				goto parse_error;
		}

		/* link the element to tw_append structure */
		if (ha) {
			if (last==0) {
				last = app->elems = ha;
			} else {
				last->next = ha;
				last = ha;
			}
		}

	} /* end while */

	print_tw_append( app );
	/* free the old string */
	pkg_free(val);
	return 0;
parse_error:
	LOG(L_ERR,"ERROR:tm:parse_tw_append: parse error in <%s> around "
		"position %ld\n", (char*)val, (long)(s-(char*)val));
error:
	return -1;
}
コード例 #15
0
ファイル: t_fwd.c プロジェクト: rrb3942/opensips
static int ul_contact_event_to_msg(struct sip_msg *req)
{
	static enum ul_attrs { UL_URI, UL_RECEIVED, UL_PATH, UL_QVAL,
		UL_SOCKET, UL_BFLAGS, UL_ATTR, UL_MAX } ul_attr;
	/* keep the names of the AVPs aligned with the contact-related events
	 * from USRLOC module !!!! */
	static str ul_names[UL_MAX]= {str_init("uri"),str_init("received"),
	                              str_init("path"),str_init("qval"),
	                              str_init("socket"),str_init("bflags"),
	                              str_init("attr") };
	static int avp_ids[UL_MAX] = { -1, -1, -1, -1, -1, -1, -1};
	int_str vals[UL_MAX];
	int proto, port;
	str host;
	str path_dst;

	if (avp_ids[0]==-1) {
		/* init the avp IDs mapping us on the UL event */
		for( ul_attr=0 ; ul_attr<UL_MAX ; ul_attr++ ){
			if (parse_avp_spec( &ul_names[ul_attr], &avp_ids[ul_attr])<0) {
				LM_ERR("failed to init UL AVP %d/%s\n",
					ul_attr,ul_names[ul_attr].s);
				avp_ids[0] = -1;
				return -1;
			}
		}
	}

	/* fetch the AVP values one by one */
	for( ul_attr=0 ; ul_attr<UL_MAX ; ul_attr++ ) {
		if (search_first_avp(0, avp_ids[ul_attr], &vals[ul_attr], NULL)==NULL){
			LM_ERR("cannot find AVP(%d) for event attr %d/%s\n",
				avp_ids[ul_attr], ul_attr, ul_names[ul_attr].s);
			return -1;
		}
	}

	/* OK, we have the values, lets inject them into the SIP msg */
	LM_DBG("injecting new branch: uri=<%.*s>, received=<%.*s>,"
		"path=<%.*s>, qval=%d, socket=<%.*s>, bflags=%X, attr=<%.*s>\n",
		vals[UL_URI].s.len, vals[UL_URI].s.s,
		vals[UL_RECEIVED].s.len, vals[UL_RECEIVED].s.s,
		vals[UL_PATH].s.len, vals[UL_PATH].s.s,
		vals[UL_QVAL].n,
		vals[UL_SOCKET].s.len, vals[UL_SOCKET].s.s,
		vals[UL_BFLAGS].n,
		vals[UL_ATTR].s.len, vals[UL_ATTR].s.s);

	/* contact URI goes as RURI */
	if (set_ruri( req, &vals[UL_URI].s)<0) {
		LM_ERR("failed to set new RURI\n");
		return -1;
	}

	/* contact PATH goes as path */
	if (vals[UL_PATH].s.len) {
		if (get_path_dst_uri(&vals[UL_PATH].s, &path_dst) < 0) {
			LM_ERR("failed to get dst_uri for Path\n");
			return -1;
		}
		if (set_dst_uri( req, &path_dst) < 0) {
			LM_ERR("failed to set dst_uri of Path\n");
			return -1;
		}

		if (set_path_vector( req, &vals[UL_PATH].s)<0) {
			LM_ERR("failed to set PATH\n");
			return -1;
		}
	} else
	/* contact RECEIVED goes as DURI */
	if (vals[UL_RECEIVED].s.len) {
		if (set_dst_uri( req, &vals[UL_RECEIVED].s)<0) {
			LM_ERR("failed to set DST URI\n");
			return -1;
		}
	}

	/* contact Qval goes as RURI Qval */
	set_ruri_q( req, vals[UL_QVAL].n);

	/* contact BFLAGS goes as RURI bflags */
	setb0flags( req, vals[UL_BFLAGS].n);

	/* socket info */
	if (vals[UL_SOCKET].s.len) {
		if ( parse_phostport( vals[UL_SOCKET].s.s, vals[UL_SOCKET].s.len,
		&host.s, &host.len, &port, &proto) < 0) {
			LM_ERR("failed to parse socket from Event attr <%.*s>\n",
				vals[UL_SOCKET].s.len, vals[UL_SOCKET].s.s);
		} else {
			req->force_send_socket = grep_sock_info( &host,
				(unsigned short)port, (unsigned short)proto);
		}
	}

	return 0;
}
コード例 #16
0
ファイル: domainpolicy_mod.c プロジェクト: KISSMonX/opensips
static int mod_init(void)
{
	int ver;

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

	init_db_url( db_url , 0 /*cannot be null*/);
	domainpolicy_table.len = strlen(domainpolicy_table.s);
	domainpolicy_col_rule.len = strlen(domainpolicy_col_rule.s);
	domainpolicy_col_type.len = strlen(domainpolicy_col_type.s);
	domainpolicy_col_att.len = strlen(domainpolicy_col_att.s);
	domainpolicy_col_val.len = strlen(domainpolicy_col_val.s);

	LM_INFO("check for DB module\n");

	/* Check if database module has been loaded */
	if (domainpolicy_db_bind(&db_url)<0)  {
		LM_ERR("no database module loaded!"
			" Please make sure that a DB module is loaded first\n");
		return -1;
	}

	LM_INFO("update length of module variables\n");
	/* Update length of module variables */
	port_override_avp.len         = strlen(port_override_avp.s);
	transport_override_avp.len    = strlen(transport_override_avp.s);
	domain_prefix_avp.len         = strlen(domain_prefix_avp.s);
	domain_suffix_avp.len         = strlen(domain_suffix_avp.s);
	domain_replacement_avp.len    = strlen(domain_replacement_avp.s);
	send_socket_avp.len           = strlen(send_socket_avp.s);

	/* Check table version */
	ver = domainpolicy_db_ver(&db_url, &domainpolicy_table);
	if (ver < 0) {
		LM_ERR("failed to query table version\n");
		return -1;
	} else if (ver < DOMAINPOLICY_TABLE_VERSION) {
		LM_ERR("invalid table version of domainpolicy table\n");
		return -1;
	}

	/* Assign AVP parameter names */
	LM_INFO("AVP\n");
	if (parse_avp_spec(&port_override_avp, &port_override_name) < 0) {
		LM_ERR("invalid port_override_avp!\n");
		return -1;
	}
	if (parse_avp_spec(&transport_override_avp, &transport_override_name) < 0) {
		LM_ERR("invalid transport_override_avp!\n");
		return -1;
	}
	if (parse_avp_spec(&domain_prefix_avp, &domain_prefix_name) < 0) {
		LM_ERR("invalid domain_prefix_avp!\n");
		return -1;
	}
	if (parse_avp_spec(&domain_suffix_avp, &domain_suffix_name) < 0) {
		LM_ERR("invalid domain_suffix_avp!\n");
		return -1;
	}
	if (parse_avp_spec(&domain_replacement_avp, &domain_replacement_name) < 0) {
		LM_ERR("invalid domain_replacement_avp!\n");
		return -1;
	}
	if (parse_avp_spec(&send_socket_avp, &send_socket_name) < 0) {
		LM_ERR("invalid send_socket_avp!\n");
		return -1;
	}

	return 0;
}
コード例 #17
0
ファイル: proto_tls.c プロジェクト: GeorgeShaw/opensips
static int mod_init(void)
{
	str s;
	int n;

	LM_INFO("initializing TLS protocol\n");

	if (tls_domain_avp) {
		s.s = tls_domain_avp;
		s.len = strlen(s.s);
		if (parse_avp_spec( &s, &tls_client_domain_avp)) {
			LM_ERR("cannot parse tls_client_avp");
			return -1;
		}
	}

	/*
	* this has to be called before any function calling CRYPTO_malloc,
	* CRYPTO_malloc will set allow_customize in openssl to 0
	*/
	if (!CRYPTO_set_mem_functions(os_malloc, os_realloc, os_free)) {
		LM_ERR("unable to set the memory allocation functions\n");
		return -1;
	}

#if !defined(OPENSSL_NO_COMP)
	STACK_OF(SSL_COMP)* comp_methods;
	/* disabling compression */
	LM_WARN("disabling compression due ZLIB problems\n");
	comp_methods = SSL_COMP_get_compression_methods();
	if (comp_methods==0) {
		LM_INFO("openssl compression already disabled\n");
	} else {
		sk_SSL_COMP_zero(comp_methods);
	}
#endif

	if (tls_init_multithread() < 0) {
		LM_ERR("failed to init multi-threading support\n");
		return -1;
	}

	SSL_library_init();
	SSL_load_error_strings();
	init_ssl_methods();

	n = check_for_krb();
	if (n==-1) {
		LM_ERR("kerberos check failed\n");
		return -1;
	}

	if ( ( n ^
#ifndef OPENSSL_NO_KRB5
	1
#else
	0
#endif
	)!=0 ) {
		LM_ERR("compiled agaist an openssl with %s"
			"kerberos, but run with one with %skerberos\n",
			(n==1)?"":"no ",(n!=1)?"no ":"");
		return -1;
	}


	/*
	 * finish setting up the tls default domains
	 */
	tls_default_client_domain.type = TLS_DOMAIN_DEF|TLS_DOMAIN_CLI ;
	tls_default_client_domain.addr.af = AF_INET;

	tls_default_server_domain.type = TLS_DOMAIN_DEF|TLS_DOMAIN_SRV;
	tls_default_server_domain.addr.af = AF_INET;

	/*
	 * now initialize tls default domains
	 */
	if ( (n=init_tls_domains(&tls_default_server_domain)) ) {
		return n;
	}
	if ( (n=init_tls_domains(&tls_default_client_domain)) ) {
		return n;
	}
	/*
	 * now initialize tls virtual domains
	 */
	if ( (n=init_tls_domains(tls_server_domains)) ) {
		return n;
	}
	if ( (n=init_tls_domains(tls_client_domains)) ) {
		return n;
	}
	/*
	 * we are all set
	 */
	return 0;
}