コード例 #1
0
ファイル: db.c プロジェクト: asyn/openvims
/**
 *  Init the database connection 
 * @param db_url - URL of the database
 * @param db_table_nds - name of the NDS table
 * @param db_table_scscf - name of the S-CSCF table
 * @param db_table_capabilities - name of the S-CSCF capabilities table
 * @returns 0 on success, -1 on error
 */
int icscf_db_init(char* db_url,
	char* db_table_nds,
	char* db_table_scscf,
	char* db_table_capabilities)
{
	if (dbf.init==0){
		LOG(L_CRIT, "BUG:"M_NAME":icscf_db_init: unbound database module\n");
		return -1;
	}
	/* NDS */
	hdl_nds=dbf.init(db_url);
	if (hdl_nds==0){
		LOG(L_CRIT,"ERR:"M_NAME":icscf_db_init: cannot initialize database "
			"connection\n");
		goto error;
	}	
	if (dbf.use_table(hdl_nds, db_table_nds)<0) {
		LOG(L_CRIT,"ERR:"M_NAME":icscf_db_init: cannot select table \"%s\"\n",db_table_nds);
		goto error;
	}
	/* S_CSCF */
	hdl_scscf=dbf.init(db_url);
	if (hdl_scscf==0){
		LOG(L_CRIT,"ERR:"M_NAME":icscf_db_init: cannot initialize database "
			"connection\n");
		goto error;
	}	
	if (dbf.use_table(hdl_scscf, db_table_scscf)<0) {
		LOG(L_CRIT,"ERR:"M_NAME":icscf_db_init: cannot select table \"%s\"\n",db_table_scscf);
		goto error;
	}
	/* Capabilities */
	hdl_capabilities=dbf.init(db_url);
	if (hdl_capabilities==0){
		LOG(L_CRIT,"ERR:"M_NAME":icscf_db_init: cannot initialize database "
			"connection\n");
		goto error;
	}	
	if (dbf.use_table(hdl_capabilities, db_table_capabilities)<0) {
		LOG(L_CRIT,"ERR:"M_NAME":icscf_db_init: cannot select table \"%s\"\n",db_table_capabilities);
		goto error;
	}

	return 0;

error:
	if (hdl_nds){
		dbf.close(hdl_nds);
		hdl_nds=0;
	}
	if (hdl_scscf){
		dbf.close(hdl_scscf);
		hdl_nds=0;
	}
	if (hdl_capabilities){
		dbf.close(hdl_capabilities);
		hdl_nds=0;
	}
	return -1;
}
コード例 #2
0
ファイル: trusted.c プロジェクト: AndreiPlesa/kamailio
/*
 * Open database connections if necessary
 */
int init_child_trusted(int rank)
{
	if (db_mode == ENABLE_CACHE)
		return 0;

	if ((rank <= 0) && (rank != PROC_RPC) && (rank != PROC_UNIXSOCK))
		return 0;

	if (!db_url.s) {
		return 0;
	}

	db_handle = perm_dbf.init(&db_url);
	if (!db_handle) {
		LM_ERR("unable to connect database\n");
		return -1;
	}

	if (db_check_table_version(&perm_dbf, db_handle, &trusted_table,
				   TABLE_VERSION) < 0) {
		LM_ERR("error during table version check.\n");
		perm_dbf.close(db_handle);
		return -1;
	}

	return 0;
}
コード例 #3
0
ファイル: pua.c プロジェクト: kiryu/kamailio
static int mi_child_init(void)
{
	if (pua_dbf.init==0)
	{
		LM_CRIT("database not bound\n");
		return -1;
	}
	/* In DB only mode do not pool the connections where possible. */
	if (dbmode == PUA_DB_ONLY && pua_dbf.init2)
		pua_db = pua_dbf.init2(&db_url, DB_POOLING_NONE);
	else
		pua_db = pua_dbf.init(&db_url);
	if (!pua_db)
	{
		LM_ERR("connecting to database failed\n");
		return -1;
	}

	if (pua_dbf.use_table(pua_db, &db_table) < 0)
	{
		LM_ERR("Error in use_table pua\n");
		return -1;
	}

	LM_DBG("Database connection opened successfully\n");

	return 0;
}
コード例 #4
0
ファイル: presence.c プロジェクト: AlessioCasco/kamailio
/*
 * destroy function
 */
static void destroy(void)
{
	if(subs_htable && subs_dbmode == WRITE_BACK) {
		/* open database connection */
		pa_db = pa_dbf.init(&db_url);
		if (!pa_db) {
			LM_ERR("mod_destroy: unsuccessful connecting to database\n");
		} else
			timer_db_update(0, 0);
	}

	if(subs_htable)
		destroy_shtable(subs_htable, shtable_size);
	
	if(pres_htable)
		destroy_phtable();

	if(pa_db && pa_dbf.close)
		pa_dbf.close(pa_db);

	if (pres_notifier_id != NULL)
		shm_free(pres_notifier_id);

	destroy_evlist();
}
コード例 #5
0
ファイル: presence_xml.c プロジェクト: Distrotech/opensips
static int verify_db(void)
{
	/* binding to mysql module  */
	if (db_bind_mod(&db_url, &pxml_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}

	if (!DB_CAPABILITY(pxml_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions"
				" needed by the module\n");
		return -1;
	}

	pxml_db = pxml_dbf.init(&db_url);
	if (!pxml_db)
	{
		LM_ERR("while connecting to database\n");
		return -1;
	}

	/* pxml_db is free'd by caller later, not sure if safe to do now */
	return 0;
}
コード例 #6
0
ファイル: presence_xml.c プロジェクト: AlessioCasco/kamailio
static int child_init(int rank)
{
	LM_DBG("[%d]  pid [%d]\n", rank, getpid());
	
	if(passive_mode==1)
		return 0;

	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
		return 0; /* do nothing for the main process */

	if(force_active== 0)
	{
		if(pxml_db)
			return 0;
		pxml_db = pxml_dbf.init(&db_url);
		if (pxml_db== NULL)
		{
			LM_ERR("while connecting database\n");
			return -1;
		}
		if (pxml_dbf.use_table(pxml_db, &xcap_table) < 0)
		{
			LM_ERR("in use_table SQL operation\n");
			return -1;
		}
	}

	LM_DBG("child %d: Database connection opened successfully\n",rank);

	return 0;
}
コード例 #7
0
ファイル: auth_db_mod.c プロジェクト: lbalaceanu/kamailio
/*
 * Convert the char* parameters
 */
static int auth_fixup(void** param, int param_no)
{
	db1_con_t* dbh = NULL;
	str name;

	if(strlen((char*)*param)<=0) {
		LM_ERR("empty parameter %d not allowed\n", param_no);
		return -1;
	}

	if (param_no == 1 || param_no == 3) {
		return fixup_var_str_12(param, 1);
	} else if (param_no == 2) {
		name.s = (char*)*param;
		name.len = strlen(name.s);

		dbh = auth_dbf.init(&db_url);
		if (!dbh) {
			LM_ERR("unable to open database connection\n");
			return -1;
		}
		if(version_table_check!=0
				&& db_check_table_version(&auth_dbf, dbh, &name,
					TABLE_VERSION) < 0) {
			LM_ERR("error during table version check.\n");
			auth_dbf.close(dbh);
			return -1;
		}
		auth_dbf.close(dbh);
	}
	return 0;
}
コード例 #8
0
ファイル: rls.c プロジェクト: Drooids/openser-xmlrpc
/**
 * Initialize children
 */
static int child_init(int rank)
{
	LM_DBG("child [%d]  pid [%d]\n", rank, getpid());
	if (rls_dbf.init==0)
	{
		LM_CRIT("database not bound\n");
		return -1;
	}
	rls_db = rls_dbf.init(db_url.s);
	if (!rls_db)
	{
		LM_ERR("child %d: Error while connecting database\n",
				rank);
		return -1;
	}
	else
	{
		if (rls_dbf.use_table(rls_db, rlsubs_table) < 0)  
		{
			LM_ERR("child %d: Error in use_table rlsubs_table\n", rank);
			return -1;
		}
		if (rls_dbf.use_table(rls_db, rlpres_table) < 0)  
		{
			LM_ERR("child %d: Error in use_table rlpres_table\n", rank);
			return -1;
		}

		LM_DBG("child %d: Database connection opened successfully\n", rank);
	}

	pid= my_pid();
	return 0;
}
コード例 #9
0
ファイル: acc.c プロジェクト: iamroger/voip
/* binds to the corresponding database module
 * returns 0 on success, -1 on error */
int acc_db_init(const str* db_url)
{
	if (db_bind_mod(db_url, &acc_dbf)<0){
		LM_ERR("bind_db failed\n");
		return -1;
	}

	/* Check database capabilities */
	if (!DB_CAPABILITY(acc_dbf, DB_CAP_INSERT)) {
		LM_ERR("database module does not implement insert function\n");
		return -1;
	}

	db_handle=acc_dbf.init(db_url);

	if (db_handle==0){
		LM_ERR("unable to connect to the database\n");
		return -1;
	}

	if (db_check_table_version(&acc_dbf, db_handle, &db_table_acc,
				TABLE_VERSION) < 0) {
		LM_ERR("error during table version check\n");
		return -1;
	}

	acc_db_close();

	acc_db_init_keys();

	return 0;
}
コード例 #10
0
ファイル: authdb_mod.c プロジェクト: AndreiPlesa/opensips
/*
 * Convert the char* parameters
 */
static int auth_fixup(void** param, int param_no)
{
	db_con_t* dbh = NULL;
	str name;

	if (param_no == 1) {
		return fixup_spve_null(param, 1);
	} else if (param_no == 2) {
		name.s = (char*)*param;
		name.len = strlen(name.s);

		dbh = auth_dbf.init(&db_url);
		if (!dbh) {
			LM_ERR("unable to open database connection\n");
			return -1;
		}
		if(skip_version_check == 0 &&
			db_check_table_version(&auth_dbf, dbh, &name, TABLE_VERSION) < 0) {
			LM_ERR("error during table version check.\n");
			auth_dbf.close(dbh);
			return -1;
		}
	}
	auth_dbf.close(dbh);
	return 0;
}
コード例 #11
0
ファイル: clusterer.c プロジェクト: Danfx/opensips
/* initialize child */
static int child_init(int rank)
{
	LM_DBG("initializing child %d\n", rank);

	if (rank == PROC_TCP_MAIN || rank == PROC_BIN)
		return 0;

	/* init DB connection */
	if ((db_hdl = dr_dbf.init(&clusterer_db_url)) == 0) {
		LM_CRIT("cannot initialize database connection\n");
		return -1;
	}

	/* child 1 load the routing info */
	if ((rank == 1) && reload_data() != 0) {
		LM_CRIT("failed to load routing data\n");
		return -1;
	}

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

	return 0;
}
コード例 #12
0
ファイル: pua.c プロジェクト: kiryu/kamailio
static int child_init(int rank)
{
	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
		return 0; /* do nothing for the main process */

	if (pua_dbf.init==0)
	{
		LM_CRIT("database not bound\n");
		return -1;
	}
	/* In DB only mode do not pool the connections where possible. */
	if (dbmode == PUA_DB_ONLY && pua_dbf.init2)
		pua_db = pua_dbf.init2(&db_url, DB_POOLING_NONE);
	else
		pua_db = pua_dbf.init(&db_url);
	if (!pua_db)
	{
		LM_ERR("Child %d: connecting to database failed\n", rank);
		return -1;
	}

	if (pua_dbf.use_table(pua_db, &db_table) < 0)
	{
		LM_ERR("child %d: Error in use_table pua\n", rank);
		return -1;
	}

	LM_DBG("child %d: Database connection opened successfully\n", rank);

	return 0;
}
コード例 #13
0
/*!
 * Initialises the DB API, check the table version and closes the connection.
 * This should be called from the mod_init function.
 *
 * \return 0 means ok, -1 means an error occured.
 */
int carrierroute_db_init(void) {
	if (!carrierroute_db_url.s || !carrierroute_db_url.len) {
		LM_ERR("you have to set the db_url module parameter.\n");
		return -1;
	}
	if (db_bind_mod(&carrierroute_db_url, &carrierroute_dbf) < 0) {
		LM_ERR("can't bind database module.\n");
		return -1;
	}
	if ((carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url)) == NULL) {
		LM_ERR("can't connect to database.\n");
		return -1;
	}
	if (
	(db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrierroute_table, carrierroute_version) < 0) ||
	(db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrierfailureroute_table, carrierfailureroute_version) < 0) ||
	(db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrier_name_table, carrier_name_version) < 0) ||
	(db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &domain_name_table, domain_name_version) < 0)
	) {
		LM_ERR("during table version check.\n");
		carrierroute_db_close();
		return -1;
	}
	carrierroute_db_close();
	return 0;
}
コード例 #14
0
ファイル: presence_xml.c プロジェクト: AlessioCasco/kamailio
static int mi_child_init(void)
{
	if(passive_mode==1)
		return 0;

	if(force_active== 0)
	{
		if(pxml_db)
			return 0;
		pxml_db = pxml_dbf.init(&db_url);
		if (pxml_db== NULL)
		{
			LM_ERR("while connecting database\n");
			return -1;
		}
		if (pxml_dbf.use_table(pxml_db, &xcap_table) < 0)
		{
			LM_ERR("in use_table SQL operation\n");
			return -1;
		}
	}

	LM_DBG("Database connection opened successfully\n");

	return 0;
}
コード例 #15
0
ファイル: imc.c プロジェクト: lbalaceanu/kamailio
/**
 * child init
 */
static int child_init(int rank)
{
	if (rank==PROC_INIT || rank==PROC_TCP_MAIN)
		return 0; /* do nothing for the main process */

	if (imc_dbf.init==0)
	{
		LM_ERR("database not bound\n");
		return -1;
	}
	imc_db = imc_dbf.init(&db_url);
	if (!imc_db)
	{
		LM_ERR("child %d: Error while connecting database\n", rank);
		return -1;
	}
	else
	{
		if (imc_dbf.use_table(imc_db, &rooms_table) < 0)
		{
			LM_ERR("child %d: Error in use_table '%.*s'\n", rank, rooms_table.len, rooms_table.s);
			return -1;
		}
		if (imc_dbf.use_table(imc_db, &members_table) < 0)
		{
			LM_ERR("child %d: Error in use_table '%.*s'\n", rank, members_table.len, members_table.s);
			return -1;
		}

		LM_DBG("child %d: Database connection opened successfully\n", rank);
	}

	return 0;
}
コード例 #16
0
ファイル: acc.c プロジェクト: Jared-Prime/kamailio
/* initialize the database connection
 * returns 0 on success, -1 on error */
int acc_db_init_child(const str *db_url)
{
	db_handle=acc_dbf.init(db_url);
	if (db_handle==0){
		LM_ERR("unable to connect to the database\n");
		return -1;
	}
	return 0;
}
コード例 #17
0
ファイル: closeddial.c プロジェクト: zhangzheyuk/opensips
static int child_init(int rank)
{
	db_connection = db_functions.init(&db_url);
	if (db_connection == NULL) {
		LM_ERR("Failed to connect database\n");
		return -1;
	}
	return 0;
}
コード例 #18
0
ファイル: trusted.c プロジェクト: AndreiPlesa/kamailio
/*
 * Open database connection if necessary
 */
int mi_init_trusted(void)
{
    if (!db_url.s) return 0;
    db_handle = perm_dbf.init(&db_url);
    if (!db_handle) {
	LM_ERR("unable to connect database\n");
	return -1;
    }
    return 0;
}
コード例 #19
0
int dlg_connect_db(const str *db_url)
{
	if (dialog_db_handle) {
		LM_CRIT("BUG - db connection found already open\n");
		return -1;
	}
	if ((dialog_db_handle = dialog_dbf.init(db_url)) == 0)
		return -1;
	return 0;
}
コード例 #20
0
/*!
 * Initialize the DB connection without checking the table version and DB URL.
 * This should be called from child_init. An already existing database
 * connection will be closed, and a new one created.
 *
 * \return 0 means ok, -1 means an error occured.
 */
int carrierroute_db_open(void) {
	if (carrierroute_dbh) {
		carrierroute_dbf.close(carrierroute_dbh);
	}
	if ((carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url)) == NULL) {
		LM_ERR("can't connect to database.\n");
		return -1;
	}
	return 0;
}
コード例 #21
0
ファイル: route_db.c プロジェクト: Enigmedia/opensips
int db_child_init(void) {
	if(dbh){
		dbf.close(dbh);
	}
	if((dbh = dbf.init(&db_url)) == NULL){
		LM_ERR("Can't connect to database.\n");
		return -1;
	}
	return 0;
}
コード例 #22
0
ファイル: db_matrix.c プロジェクト: AlessioCasco/kamailio
/*!
 * Initialize the DB connection without checking the table version and DB URL.
 * This should be called from child_init. An already existing database
 * connection will be closed, and a new one created.
 *
 * \return 0 means ok, -1 means an error occured.
 */
int matrix_db_open(void) {
	if (matrix_dbh) {
		matrix_dbf.close(matrix_dbh);
	}
	if ((matrix_dbh = matrix_dbf.init(&matrix_db_url)) == NULL) {
		LM_ERR("can't connect to database.\n");
		return -1;
	}
	return 0;
}
コード例 #23
0
/*!
 * Initialize the DB connection without checking the table version and DB URL.
 * This should be called from child_init. An already existing database
 * connection will be closed, and a new one created.
 *
 * \return 0 means ok, -1 means an error occured.
 */
int userblacklist_db_open(void) {
	if (userblacklist_dbh) {
		userblacklist_dbf.close(userblacklist_dbh);
	}
	if ((userblacklist_dbh = userblacklist_dbf.init(&userblacklist_db_url)) == NULL) {
		LM_ERR("can't connect to database.\n");
		return -1;
	}
	return 0;
}
コード例 #24
0
static int child_init(int rank)
{
	auth_db_handle = auth_dbf.init(db_url);
	if (auth_db_handle == 0){
		LOG(L_ERR, "auth_db:child_init: unable to connect to the database\n");
		return -1;
	}

	return 0;
}
コード例 #25
0
ファイル: sca_db_handler.c プロジェクト: AndreiPlesa/opensips
int connect_sca_db(const str *db_url)
{
	if (sca_db_handle) {
		LM_CRIT("BUG - db connection found already open\n");
		return -1;
	}
	if ((sca_db_handle = sca_dbf.init(db_url)) == NULL)
		return -1;
	return 0;
}
コード例 #26
0
ファイル: authdb_mod.c プロジェクト: AndreiPlesa/opensips
static int child_init(int rank)
{
	auth_db_handle = auth_dbf.init(&db_url);
	if (auth_db_handle == 0){
		LM_ERR("unable to connect to the database\n");
		return -1;
	}

	return 0;
}
コード例 #27
0
ファイル: xcap_client.c プロジェクト: alias-neo/opensips
/**
 * init module function
 */
static int mod_init(void)
{
	bind_xcap_t bind_xcap;
	xcap_api_t xcap_api;

        /* load XCAP API */
        bind_xcap = (bind_xcap_t)find_export("bind_xcap", 1, 0);
        if (!bind_xcap)
        {
                LM_ERR("Can't bind xcap\n");
                return -1;
        }

        if (bind_xcap(&xcap_api) < 0)
        {
                LM_ERR("Can't bind xcap\n");
                return -1;
        }
        xcap_db_url = xcap_api.db_url;
        xcap_db_table = xcap_api.xcap_table;

	/* binding to mysql module  */
	if (db_bind_mod(&xcap_db_url, &xcap_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}

	if (!DB_CAPABILITY(xcap_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions"
				" needed by the module\n");
		return -1;
	}

	xcap_db = xcap_dbf.init(&xcap_db_url);
	if (!xcap_db)
	{
		LM_ERR("while connecting to database\n");
		return -1;
	}

	curl_global_init(CURL_GLOBAL_ALL);

	if(periodical_query)
	{
		register_timer("xcapc-update", query_xcap_update, 0,
			query_period, TIMER_FLAG_DELAY_ON_DELAY);
	}

	if(xcap_db)
		xcap_dbf.close(xcap_db);
	xcap_db = NULL;

	return 0;
}
コード例 #28
0
ファイル: clusterer_mod.c プロジェクト: OpenSIPS/opensips
/* initialize child */
static int child_init(int rank)
{
	if (db_mode) {
		/* init DB connection */
		if ((db_hdl = dr_dbf.init(&clusterer_db_url)) == 0) {
			LM_ERR("cannot initialize database connection\n");
			return -1;
		}
	}
	return 0;
}
コード例 #29
0
ファイル: siptrace.c プロジェクト: Drooids/openser-xmlrpc
static int child_init(int rank)
{
	db_con = db_funcs.init(db_url);
	if (!db_con)
	{
		LM_ERR("unable to connect database\n");
		return -1;
	}

	return 0;
}
コード例 #30
0
ファイル: mtree_mod.c プロジェクト: TheGrandWazoo/kamailio
static int mt_child_init(void)
{
	db_con = mt_dbf.init(&db_url);
	if(db_con==NULL)
	{
		LM_ERR("failed to connect to database\n");
		return -1;
	}

	return 0;
}