コード例 #1
0
ファイル: mod.c プロジェクト: 2pac/kamailio
/**
 * Module initialization function - called once at startup.
 * \note Other modules might not be loaded at this moment.
 * If this returns failure, wharf will exit
 * 
 * @param config - abstract configuration string
 * @return 1 on success or 0 on failure
 */
int cdp_avp_init()
{
	LOG(L_DBG," Initializing module cdp_avp\n");
	load_cdp_f load_cdp;
	/* 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;
	}
	cdp = pkg_malloc(sizeof(struct cdp_binds));
	if (!cdp) return 0;
	/* Load CDP module bindings*/
	if (load_cdp(cdp) == -1)
		goto error;
	
	cdp_avp_bind.cdp = cdp;
	
	return 0;
error:
	return -1;
}
コード例 #2
0
ファイル: mod.c プロジェクト: Gaoithe/openimscore_ims
/**
 * Initializes the module.
 */
static int mod_init(void)
{
	load_tm_f load_tm;
	load_cdp_f load_cdp;
	bind_dlg_mod_f load_dlg;
	str algo;
	
	callback_singleton=shm_malloc(sizeof(int));
	*callback_singleton=0;
	shutdown_singleton=shm_malloc(sizeof(int));
	*shutdown_singleton=0;
	
		
	LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n");
	/* fix the parameters */
	scscf_name_str.s = scscf_name;
	scscf_name_str.len = strlen(scscf_name);
	if (!build_record_service_route()) goto error;
	scscf_forced_hss_peer_str.s = scscf_forced_hss_peer;
	scscf_forced_hss_peer_str.len = strlen(scscf_forced_hss_peer);
	
	algo.s = registration_default_algorithm;
	algo.len = strlen(registration_default_algorithm);
	registration_default_algorithm_type = get_algorithm_type(algo);	
	

	#ifdef WITH_IMS_PM
		ims_pm_init(scscf_name_str,ims_pm_node_type, ims_pm_logfile);
		ims_pm_init_scscf();
	#endif /* WITH_IMS_PM */
			
	/* 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 db module */
	if(scscf_persistency_mode==WITH_DATABASE_BULK || scscf_persistency_mode==WITH_DATABASE_CACHE){
		if (!scscf_db_url) {
			LOG(L_ERR, "ERR:"M_NAME":mod_init: no db_url specified but DB has to be used "
				"(scscf_persistency_mode=%d\n", scscf_persistency_mode);
			return -1;
		}
		
		if (!scscf_db_init(scscf_db_url)<0){
			LOG(L_ERR, "ERR:"M_NAME": mod_init: Error while connecting database\n");
			return -1;
		}
		
		/* db lock */
		db_lock = (gen_lock_t*)lock_alloc();
		if(!db_lock){
	    	LOG(L_ERR, "ERR:"M_NAME": mod_init: No memory left\n");
			return -1;
		}
		lock_init(db_lock);
	
		/* snapshot and step versions */
	
		auth_snapshot_version=(int*)shm_malloc(sizeof(int));
		if(!auth_snapshot_version){
			LOG(L_ERR, "ERR:"M_NAME":mod_init: auth_snapshot_version, no memory left\n");
			return -1;
		}
		*auth_snapshot_version=0;
	
		auth_step_version=(int*)shm_malloc(sizeof(int));
		if(!auth_step_version){
			LOG(L_ERR, "ERR:"M_NAME":mod_init: auth_step_version, no memory left\n");
			return -1;
		}
		*auth_step_version=0;
	
		dialogs_snapshot_version=(int*)shm_malloc(sizeof(int));
		if(!dialogs_snapshot_version){
			LOG(L_ERR, "ERR:"M_NAME":mod_init: dialogs_snapshot_version, no memory left\n");
			return -1;
		}
		*dialogs_snapshot_version=0;
	
		dialogs_step_version=(int*)shm_malloc(sizeof(int));
		if(!dialogs_step_version){
			LOG(L_ERR, "ERR:"M_NAME":mod_init: dialogs_step_version, no memory left\n");
			return -1;
		}
		*dialogs_step_version=0;
	
		registrar_snapshot_version=(int*)shm_malloc(sizeof(int));
		if(!registrar_snapshot_version){
			LOG(L_ERR, "ERR:"M_NAME":mod_init: registrar_snapshot_version, no memory left\n");
			return -1;
		}
		*registrar_snapshot_version=0;
	
		registrar_step_version=(int*)shm_malloc(sizeof(int));
		if(!registrar_step_version){
			LOG(L_ERR, "ERR:"M_NAME":mod_init: registrar_step_version, no memory left\n");
			return -1;
		}
		*registrar_step_version=0;
		
	}
	
	/* 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;

	/* bind to the dialog module */
	load_dlg = (bind_dlg_mod_f)find_export("bind_dlg_mod", -1, 0);
	if (!load_dlg) {
		LOG(L_ERR, "ERR"M_NAME":mod_init:  Can not import bind_dlg_mod. This module requires dialog module\n");
		return -1;
	}
	if (load_dlg(&dialogb) != 0) {
		return -1;
	}
	
	
	/* Init the authorization data storage */
	if (!auth_data_init(auth_data_hash_size)) goto error;	
	if (scscf_persistency_mode!=NO_PERSISTENCY){
		load_snapshot_authdata();
		if (register_timer(persistency_timer_authdata,0,scscf_persistency_timer_authdata)<0) goto error;
	}
	

	/* register the authentication vectors timer */
	if (register_timer(reg_await_timer,auth_data,10)<0) goto error;
	
	/* init the registrar storage */
	if (!r_storage_init(registrar_hash_size)) goto error;
	if (scscf_persistency_mode!=NO_PERSISTENCY){
		load_snapshot_registrar();
		if (register_timer(persistency_timer_registrar,0,scscf_persistency_timer_registrar)<0) goto error;
	}

	/* register the registrar timer */
	if (register_timer(registrar_timer,registrar,10)<0) goto error;

	/* init the registrar notifications */
	if (!r_notify_init()) goto error;

	/* register the registrar notifications timer */
	if (register_timer(notification_timer,notification_list,5)<0) goto error;

	/* init the dialog storage */
	if (!s_dialogs_init(scscf_dialogs_hash_size)){
		LOG(L_ERR, "ERR"M_NAME":mod_init: Error initializing the Hash Table for stored dialogs\n");
		goto error;
	}		
	scscf_dialog_count = shm_malloc(sizeof(int));
	*scscf_dialog_count = 0;
	scscf_dialog_count_lock = lock_alloc();
	scscf_dialog_count_lock = lock_init(scscf_dialog_count_lock);

	if (scscf_persistency_mode!=NO_PERSISTENCY){
		load_snapshot_dialogs();
		if (register_timer(persistency_timer_dialogs,0,scscf_persistency_timer_dialogs)<0) goto error;
	}

	/* register the dialog timer */
	if (register_timer(dialog_timer,s_dialogs,60)<0) goto error;


	/* don't register response callback as we always set callback per transactions 
	 *  and we're not interested in other responses */
	/*AAAAddResponseHandler(&CxAnswerHandler,0);*/

	
	return 0;
error:
	return -1;
}
コード例 #3
0
ファイル: mod.c プロジェクト: Gaoithe/openimscore_ims
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;
}