Esempio n. 1
0
File: mod.c Progetto: gbour/kamailio
/**
 * init module function
 */
static int mod_init(void) {

    bind_usrloc_t bind_usrloc;
    /* fix the parameters */
    if (!fix_parameters())
        goto error;

    /* load the TM API */
    if (load_tm_api(&isc_tmb) != 0) {
        LM_ERR("can't load TM API\n");
        goto error;
    }

    bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0);
    if (!bind_usrloc) {
        LM_ERR("can't bind usrloc\n");
        return -1;
    }

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

    /* Init the isc_my_uri parameter */
    if (!isc_my_uri_c) {
        LM_CRIT("mandatory parameter \"isc_my_uri\" found empty\n");
        goto error;
    }

    isc_my_uri.s = isc_my_uri_c;
    isc_my_uri.len = strlen(isc_my_uri_c);
    isc_my_uri_sip.len = 4 + isc_my_uri.len;
    isc_my_uri_sip.s = shm_malloc(isc_my_uri_sip.len + 1);
    memcpy(isc_my_uri_sip.s, "sip:", 4);
    memcpy(isc_my_uri_sip.s + 4, isc_my_uri.s, isc_my_uri.len);
    isc_my_uri_sip.s[isc_my_uri_sip.len] = 0;

    LM_DBG("ISC module successfully initialised\n");

    return 0;
error:
    LM_ERR("Failed to initialise ISC module\n");
    return -1;
}
Esempio n. 2
0
/*! \brief
 * Initialize parent
 */
static int mod_init(void) {
	bind_usrloc_t bind_usrloc;
	bind_pua_t bind_pua;

	/*register space for event processor*/
	register_procs(1);
	
	if (!fix_parameters()) goto error;

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

	/* load the TM API */
	if (load_tm_api(&tmb) != 0) {
		LM_ERR("can't load TM API\n");
		return -1;
	}
	LM_DBG("Successfully bound to TM module\n");

	bind_usrloc = (bind_usrloc_t) find_export("ul_bind_ims_usrloc_pcscf", 1, 0);
	if (!bind_usrloc) {
		LM_ERR("can't bind ims_usrloc_pcscf\n");
		return -1;
	}

	if (bind_usrloc(&ul) < 0) {
		return -1;
	}
	LM_DBG("Successfully bound to PCSCF Usrloc module\n");

       if(subscribe_to_reginfo == 1){
               /* Bind to PUA: */
               bind_pua = (bind_pua_t) find_export("bind_pua", 1, 0);
               if (!bind_pua) {
                       LM_ERR("Can't bind pua\n");
                       return -1;
               }
               if (bind_pua(&pua) < 0) {
                       LM_ERR("Can't bind pua\n");
                       return -1;
               }
               /* Check for Publish/Subscribe methods */
               if (pua.send_publish == NULL) {
                       LM_ERR("Could not import send_publish\n");
                       return -1;
               }
               if (pua.send_subscribe == NULL) {
                       LM_ERR("Could not import send_subscribe\n");
                       return -1;
               }
	       if (pua.get_subs_list == NULL) {
                       LM_ERR("Could not import get_subs_list\n");
                       return -1;
               }
	       LM_DBG("Successfully bound to PUA module\n");
	       
	       /*init cdb cb event list*/
		if (!init_reginfo_event_list()) {
		    LM_ERR("unable to initialise reginfo_event_list\n");
		    return -1;
		}
	       LM_DBG("Successfully initialised reginfo_event_list\n");
       }

	return 0;

error:
	return -1;
}
Esempio n. 3
0
/**
 * Initializes the module.
 */
static int mod_init(void)
{
	load_tm_f load_tm;
	load_cdp_f load_cdp;
	cdp_avp_get_bind_f load_cdp_avp;
			
	LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n");
	shutdown_singleton=shm_malloc(sizeof(int));
	*shutdown_singleton=0;
	
	
	/* fix the parameters */
	if (!fix_parameters()) goto error;

	/* 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;

	if (!(load_cdp = (load_cdp_f)find_export("load_cdp",NO_SCRIPT,0))) {
		LOG(L_ERR, "DBG:"M_NAME":mod_init: Can not import load_cdp. This module requires cdp module.\n");
		goto error;
	}

	if (!(load_cdp_avp = (cdp_avp_get_bind_f)find_export("cdp_avp_get_bind",NO_SCRIPT,0))) {
		LOG(L_ERR, "DBG:"M_NAME":mod_init: loading cdp_avp module unsuccessful. exiting\n");			
		goto error;
	}	
	cavpb = load_cdp_avp();
	if (!cavpb)
		goto error;

	if (!init_acct_records()){
		LOG(L_ERR, "DBG:"M_NAME":mod_init: failed to initiate local accounting records\n");			
		goto error;
	}

	if(!init_an_charg_info()){
		LOG(L_ERR, "DBG:"M_NAME":mod_init: failed to initiate local user charging info\n");			
		goto error;
	}

	if(!init_ims_charg_info()){
		LOG(L_ERR, "DBG:"M_NAME":mod_init: failed to initiate local user charging info\n");			
		goto error;
	}
	
	return 0;
error:
	return -1;
}
Esempio n. 4
0
static int mod_init(void) {
	int n;
	load_dlg_f load_dlg;
	load_tm_f load_tm;
	bind_usrloc_t bind_usrloc;

	if (!fix_parameters()) {
		LM_ERR("unable to set Ro configuration parameters correctly\n");
		goto error;
	}

	/* bind to the tm module */
	if (!(load_tm = (load_tm_f) find_export("load_tm", NO_SCRIPT, 0))) {
		LM_ERR("Can not import load_tm. This module requires tm module\n");
		goto error;
	}
	if (load_tm(&tmb) == -1)
		goto error;

	if (!(load_dlg = (load_dlg_f) find_export("load_dlg", 0, 0))) { /* bind to dialog module */
		LM_ERR("can not import load_dlg. This module requires Kamailio dialog module.\n");
	}
	if (load_dlg(&dlgb) == -1) {
		goto error;
	}

	if (load_cdp_api(&cdpb) != 0) { /* load the CDP API */
		LM_ERR("can't load CDP API\n");
		goto error;
	}

	if (load_dlg_api(&dlgb) != 0) { /* load the dialog API */
		LM_ERR("can't load Dialog API\n");
		goto error;
	}

	cdp_avp = load_cdp_avp(); /* load CDP_AVP API */
	if (!cdp_avp) {
		LM_ERR("can't load CDP_AVP API\n");
		goto error;
	}

	/* init timer lists*/
	if (init_ro_timer(ro_session_ontimeout) != 0) {
		LM_ERR("cannot init timer list\n");
		return -1;
	}

	/* initialized the hash table */
	for (n = 0; n < (8 * sizeof(n)); n++) {
		if (ro_session_hash_size == (1 << n))
			break;
		if (ro_session_hash_size < (1 << n)) {
			LM_WARN("hash_size is not a power of 2 as it should be -> rounding from %d to %d\n", ro_session_hash_size, 1 << (n - 1));
			ro_session_hash_size = 1 << (n - 1);
		}
	}

	if (init_ro_session_table(ro_session_hash_size) < 0) {
		LM_ERR("failed to create ro session hash table\n");
		return -1;
	}

	/* register global timer */
	if (register_timer(ro_timer_routine, 0/*(void*)ro_session_list*/, 1) < 0) {
		LM_ERR("failed to register timer \n");
		return -1;
	}

	bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0);
	if (!bind_usrloc) {
	    LM_ERR("can't bind usrloc\n");
	    return -1;
	}
	
	if (bind_usrloc(&ul) < 0) {
	    return -1;
	}

	/*Register for callback of URECORD being deleted - so we can send a SAR*/

	if (ul.register_ulcb == NULL) {
	    LM_ERR("Could not import ul_register_ulcb\n");
	    return -1;
	}
	
	 /* register statistics */
	if (register_module_stats(exports.name, charging_stats) != 0) {
		LM_ERR("failed to register core statistics\n");
		return -1;
	}

	/*if (register_stat(MOD_NAME, "ccr_responses_time", &ccr_responses_time, 0)) {
		LM_ERR("failed to register core statistics\n");
		return -1;
	}*/
	
	/* if a database should be used to store the dialogs' information */
	ro_db_mode = ro_db_mode_param;
	if (ro_db_mode == DB_MODE_NONE) {
	    db_url.s = 0;
	    db_url.len = 0;
	} else {
	    if (ro_db_mode != DB_MODE_REALTIME && ro_db_mode != DB_MODE_SHUTDOWN) {
		LM_ERR("unsupported db_mode %d\n", ro_db_mode);
		return -1;
	    }
	    if (!db_url.s || db_url.len == 0) {
		LM_ERR("db_url not configured for db_mode %d\n", ro_db_mode);
		return -1;
	    }
	    if (init_ro_db(&db_url, ro_session_hash_size, db_update_period, db_fetch_rows) != 0) {
		LM_ERR("failed to initialize the DB support\n");
		return -1;
	    }
//	    run_load_callbacks();
	}

	return 0;

error:
	LM_ERR("Failed to initialise ims_qos module\n");
	return RO_RETURN_FALSE;

}
Esempio n. 5
0
/**
 * init module function
 */
static int mod_init(void) {

    /* fix the parameters */
    if (!fix_parameters())
        goto error;

#ifdef STATISTICS
    /* register statistics */
    if (register_module_stats(exports.name, mod_stats) != 0) {
        LM_ERR("failed to register core statistics\n");
        goto error;
    }

    if (!register_stats()) {
        LM_ERR("Unable to register statistics\n");
        goto error;
    }
#endif

    callback_singleton = shm_malloc(sizeof (int));
    *callback_singleton = 0;

    /*register space for event processor*/
    register_procs(1);

    cdp_avp = 0;
    /* load the TM API */
    if (load_tm_api(&tmb) != 0) {
        LM_ERR("can't load TM API\n");
        goto error;
    }

    /* load the CDP API */
    if (load_cdp_api(&cdpb) != 0) {
        LM_ERR("can't load CDP API\n");
        goto error;
    }

    /* load the dialog API */
    if (load_dlg_api(&dlgb) != 0) {
        LM_ERR("can't load Dialog API\n");
        goto error;
    }

    cdp_avp = load_cdp_avp();
    if (!cdp_avp) {
        LM_ERR("can't load CDP_AVP API\n");
        goto error;
    }

    /* load the usrloc API */
    bind_usrloc = (bind_usrloc_t) find_export("ul_bind_ims_usrloc_pcscf", 1, 0);
    if (!bind_usrloc) {
        LM_ERR("can't bind usrloc_pcscf\n");
        return CSCF_RETURN_FALSE;
    }

    if (bind_usrloc(&ul) < 0) {
        LM_ERR("can't bind to usrloc pcscf\n");
        return CSCF_RETURN_FALSE;
    }
    LM_DBG("Successfully bound to PCSCF Usrloc module\n");

    LM_DBG("Diameter RX interface successfully bound to TM, Dialog, Usrloc and CDP modules\n");

    /*init cdb cb event list*/
    if (!init_cdp_cb_event_list()) {
        LM_ERR("unable to initialise cdp callback event list\n");
        return -1;
    }

    return 0;
error:
    LM_ERR("Failed to initialise ims_qos module\n");
    return CSCF_RETURN_FALSE;
}
Esempio n. 6
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;
}