Esempio n. 1
0
File: db.c Progetto: asyn/openvims
/**
 * Simply check if the database connection was initialized and connect if not.
 * @param db_hdl - database handle to test
 * @returns 1 if connected, 0 if not
 */
static inline int icscf_db_check_init(db_con_t *db_hdl)
{
	if (db_hdl) return 1;
	return (icscf_db_init( icscf_db_url,
		icscf_db_nds_table,
		icscf_db_scscf_table,
		icscf_db_capabilities_table)==0);		
}
Esempio n. 2
0
static int icscf_mod_init(void)
{
	load_tm_f load_tm;
	load_cdp_f load_cdp;
	LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n");
	/* fix the parameters */
	if (!fix_parameters()) goto error;

	#ifdef WITH_IMS_PM
		ims_pm_init(icscf_name_str,ims_pm_node_type, ims_pm_logfile);
		ims_pm_init_icscf();
	#endif /* WITH_IMS_PM */
	
	cscf_icid_value_count = shm_malloc(sizeof(unsigned int));
	*cscf_icid_value_count = 0;
	cscf_icid_value_count_lock = lock_alloc();
	cscf_icid_value_count_lock = lock_init(cscf_icid_value_count_lock);
		
	/* load the send_reply function from sl module */
    sl_reply = find_export("sl_send_reply", 2, 0);
	if (!sl_reply) {
		LOG(L_ERR, "ERR"M_NAME":mod_init: This module requires sl module\n");
		goto error;
	}
		
	/* bind to the tm module */
	if (!(load_tm = (load_tm_f)find_export("load_tm",NO_SCRIPT,0))) {
		LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_tm. This module requires tm module\n");
		goto error;
	}
	if (load_tm(&tmb) == -1)
		goto error;

	/* bind to the cdp module */
	if (!(load_cdp = (load_cdp_f)find_export("load_cdp",NO_SCRIPT,0))) {
		LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_cdp. This module requires cdp module\n");
		goto error;
	}
	if (load_cdp(&cdpb) == -1)
		goto error;

	/* cache the trusted domain names and capabilities */
	/* bind to the db module */
	if ( icscf_db_bind( icscf_db_url ) < 0 ) goto error;
	
	icscf_db_init( icscf_db_url, 
		icscf_db_nds_table,
		icscf_db_scscf_table,
		icscf_db_capabilities_table);
	
	I_NDS_get_trusted_domains();	
	I_get_capabilities();
	
	icscf_db_close();
	
	if (!i_hash_table_init(icscf_hash_size)){
		LOG(L_ERR, "ERR"M_NAME":mod_init: Error initializing the Hash Table for stored S-CSCF lists\n");
		goto error;
	}	
//	//TODO - only for S-CSCF - I-CSCF does not respond to request
////	AAAAddRequestHandler(&CxRequestHandler,0);
//	/* don't register response callback as we always set callback per transactions 
//	 *  and we're not interested in other responses */
//	/*AAAAddResponseHandler(&CxAnswerHandler,0);*/
//
	/** initialize twofish variables and tables (THIG)**/
	srand((unsigned) time(NULL));
	thig_key_and_cipher_init(&ki,&ci);
	LOG(L_INFO,"Twofish encryption ready\n");
	
	int route_no;
	/* try to fix the icscf_route_on_term_user_unknown route */
	if (icscf_route_on_term_user_unknown){
		route_no=route_get(&main_rt, icscf_route_on_term_user_unknown);
		if (route_no==-1){
			LOG(L_ERR, "ERR"M_NAME":mod_init: failed to fix route \"%s\": route_get() failed\n",
					icscf_route_on_term_user_unknown);
			return -1;
		}
		if (main_rt.rlist[route_no]==0){
			LOG(L_ERR, "ERR"M_NAME":mod_init: icscf_route_on_term_user_unknown \"%s\" is empty / doesn't exist\n",
					icscf_route_on_term_user_unknown);
		}
		route_on_term_user_unknown_n=route_no;
	}	
	
	return 0;
error:
	return -1;
}