Exemple #1
0
int domain_db_ver(str* name)
{
	int ver;

	if (db_handle==0){
		LOG(L_CRIT, "BUG:domain_db_ver: null database handler\n");
		return -1;
	}
	ver=table_version(&domain_dbf, db_handle, name);
	return ver;
}
Exemple #2
0
int domain_db_ver(str* name)
{
	int ver;

	if (db_handle==0){
		LM_ERR("Null database handler\n");
		return -1;
	}
	ver=table_version(&domain_dbf, db_handle, name);
	return ver;
}
/*
 * Check version of domain and domain_attrs tables
 */
static int check_version(void)
{
    int ver;
    
	 /* Check table version */
    ver = table_version(&db, con, &domain_table);
    if (ver < 0) {
	ERR("Error while querying table version\n");
	return -1;
    } else if (ver < DOMAIN_TABLE_VERSION) {
	ERR("Invalid table version, update your database schema\n");
	return -1;
    }
    
    ver = table_version(&db, con, &domattr_table);
    if (ver < 0) {
	ERR("Error while querying table version\n");
	return -1;
    } else if (ver < DOMATTR_TABLE_VERSION) {
	ERR("Invalid table version, update your database schema\n");
	return -1;
    }
    return 0;
}
Exemple #4
0
/**
 * init module function
 */
static int mod_init(void)
{
	str _s;
	int ver;

	xcap_db_url.len = xcap_db_url.s ? strlen(xcap_db_url.s) : 0;
	
	/* binding to mysql module  */
	if (bind_dbmod(xcap_db_url.s, &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.s);
	if (!xcap_db)
	{
		LM_ERR("while connecting to database\n");
		return -1;
	}

	_s.s = xcap_db_table;
	_s.len = strlen(xcap_db_table);
	 ver =  table_version(&xcap_dbf, xcap_db, &_s);
	if(ver!=XCAP_TABLE_VERSION)
	{
		LM_ERR("Wrong version v%d for table <%s>, need v%d\n",
				 ver, _s.s, XCAP_TABLE_VERSION);
		return -1;
	}

	curl_global_init(CURL_GLOBAL_ALL);

	if(periodical_query)
	{
		register_timer(query_xcap_update, 0, query_period);
	}
	return 0;
}
int domainpolicy_db_ver(char* db_url, str* name)
{
	int ver;
	db_con_t* dbh;

	if (domainpolicy_dbf.init==0){
		LM_CRIT("unbound database\n");
		return -1;
	}
	dbh=domainpolicy_dbf.init(db_url);
	if (dbh==0){
		LM_CRIT("null database handler\n");
		return -1;
	}
	ver=table_version(&domainpolicy_dbf, dbh, name);
	domainpolicy_dbf.close(dbh);
	return ver;
}
Exemple #6
0
int group_db_ver(char* db_url, str* name)
{
	db_con_t* dbh;
	int ver;

	if (group_dbf.init==0){
		LOG(L_CRIT, "BUG: group_db_ver: unbound database\n");
		return -1;
	}
	dbh=group_dbf.init(db_url);
	if (dbh==0){
		LOG(L_ERR, "ERROR: group_db_ver: unable to open database "
				"connection\n");
		return -1;
	}
	ver=table_version(&group_dbf, dbh, name);
	group_dbf.close(dbh);
	return ver;
}
Exemple #7
0
/*
 * Convert char* parameter to str* parameter
 */
static int str_fixup(void** param, int param_no)
{
	db_con_t* dbh;
	str* s;
	int ver;
	str name;

	if (param_no == 1) {
		s = (str*)pkg_malloc(sizeof(str));
		if (!s) {
			LOG(L_ERR, "str_fixup(): No memory left\n");
			return E_UNSPEC;
		}

		s->s = (char*)*param;
		s->len = strlen(s->s);
		*param = (void*)s;
	} else if (param_no == 2) {
		name.s = (char*)*param;
		name.len = strlen(name.s);

		dbh = auth_dbf.init(db_url);
		if (!dbh) {
			LOG(L_ERR, "auth_db:str_fixup: Unable to open database connection\n");
			return -1;
		}
		ver = table_version(&auth_dbf, dbh, &name);
		auth_dbf.close(dbh);
		if (ver < 0) {
			LOG(L_ERR, "auth_db:str_fixup: Error while querying table version\n");
			return -1;
		} else if (ver < TABLE_VERSION) {
			LOG(L_ERR, "auth_db:str_fixup: Invalid table version (use ser_mysql.sh reinstall)\n");
			return -1;
		}
	}

	return 0;
}
Exemple #8
0
/*
 * Function registers a new domain with usrloc
 * if the domain exists, pointer to existing structure
 * will be returned, otherwise a new domain will be
 * created
 */
int register_udomain(const char* _n, udomain_t** _d)
{
	dlist_t* d;
	str s;
	int ver;
	db_con_t* con;

	s.s = (char*)_n;
	s.len = strlen(_n);

	if (find_dlist(&s, &d) == 0) {
	        *_d = d->d;
		return 0;
	}
	
	if (new_dlist(&s, &d) < 0) {
		LOG(L_ERR, "register_udomain(): Error while creating new domain\n");
		return -1;
	} 

	     /* Preload domain with data from database if we are gonna
	      * to use database
	      */
	if (db_mode != NO_DB) {
		con = ul_dbf.init(db_url.s);
		if (!con) {
			LOG(L_ERR, "register_udomain(): Can not open database connection\n");
			goto err;
		}

		ver = table_version(&ul_dbf, con, &s);

		if (ver < 0) {
			LOG(L_ERR, "register_udomain(): Error while querying table version\n");
			goto err;
		} else if (ver < TABLE_VERSION) {
			LOG(L_ERR, "register_udomain(): Invalid table version (use ser_mysql.sh reinstall)\n");
			goto err;
		}
		
		if (preload_udomain(con, d->d) < 0) {
			LOG(L_ERR, "register_udomain(): Error while preloading domain '%.*s'\n",
			    s.len, ZSW(s.s));
			goto err;
		}

		ul_dbf.close(con);
	}

	d->next = root;
	root = d;
	
	*_d = d->d;
	return 0;

 err:
	if (con) ul_dbf.close(con);
	free_udomain(d->d);
	shm_free(d->name.s);
	shm_free(d);
	return -1;
}
Exemple #9
0
/**
 * init module function
 */
static int mod_init(void)
{
	str _s;
	int ver = 0;
	bind_presence_t bind_presence;
	presence_api_t pres;
	bind_pua_t bind_pua;
	pua_api_t pua;
	bind_libxml_t bind_libxml;
	libxml_api_t libxml_api;
	bind_xcap_t bind_xcap;
	xcap_api_t xcap_api;
	char* sep;

	LM_DBG("start\n");

	if(server_address.s== NULL)
	{
		LM_DBG("server_address parameter not set in configuration file\n");
	}	
	if(server_address.s)
		server_address.len= strlen(server_address.s);
	else
		server_address.len= 0;
	
	if(xcap_root== NULL)
	{
		LM_ERR("xcap_root parameter not set\n");
		return -1;
	}
	/* extract port if any */
	sep= strchr(xcap_root, ':');
	if(sep)
	{
		char* sep2= NULL;
		sep2= strchr(sep+ 1, ':');
		if(sep2)
			sep= sep2;
		
		str port_str;

		port_str.s= sep+ 1;
		port_str.len= strlen(xcap_root)- (port_str.s-xcap_root);

		if(str2int(&port_str, &xcap_port)< 0)
		{
			LM_ERR("converting string to int [port]= %.*s\n",port_str.len,
					port_str.s);
			return -1;
		}
		if(xcap_port< 0 || xcap_port> 65535)
		{
			LM_ERR("wrong xcap server port\n");
			return -1;
		}
		*sep= '\0';
	}

	/* load SL API */
	if(load_sl_api(&slb)==-1)
	{
		LM_ERR("can't load sl functions\n");
		return -1;
	}

	/* load all TM stuff */
	if(load_tm_api(&tmb)==-1)
	{
		LM_ERR("can't load tm functions\n");
		return -1;
	}
	bind_presence= (bind_presence_t)find_export("bind_presence", 1,0);
	if (!bind_presence)
	{
		LM_ERR("Can't bind presence\n");
		return -1;
	}
	if (bind_presence(&pres) < 0)
	{
		LM_ERR("Can't bind presence\n");
		return -1;
	}
	pres_contains_event = pres.contains_event;
	pres_search_event   = pres.search_event;
	pres_get_ev_list    = pres.get_event_list;
	pres_new_shtable    = pres.new_shtable;
	pres_destroy_shtable= pres.destroy_shtable;
	pres_insert_shtable = pres.insert_shtable;
	pres_delete_shtable = pres.delete_shtable;
	pres_update_shtable = pres.update_shtable;
	pres_search_shtable = pres.search_shtable;
	pres_copy_subs      = pres.mem_copy_subs;
	pres_update_db_subs = pres.update_db_subs;
	pres_extract_sdialog_info= pres.extract_sdialog_info;

	if(!pres_contains_event || !pres_get_ev_list || !pres_new_shtable ||
		!pres_destroy_shtable || !pres_insert_shtable || !pres_delete_shtable
		 || !pres_update_shtable || !pres_search_shtable || !pres_copy_subs
		 || !pres_extract_sdialog_info)
	{
		LM_ERR("importing functions from presence module\n");
		return -1;
	}
	db_url.len = db_url.s ? strlen(db_url.s) : 0;
	LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len,
			db_url.s);
	
	/* binding to mysql module  */
	if (bind_dbmod(db_url.s, &rls_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}
	
	if (!DB_CAPABILITY(rls_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions"
				" needed by the module\n");
		return -1;
	}

	rls_db = rls_dbf.init(db_url.s);
	if (!rls_db)
	{
		LM_ERR("while connecting database\n");
		return -1;
	}
	/* verify table version */
	_s.s = rlsubs_table;
	_s.len = strlen(rlsubs_table);
	 ver =  table_version(&rls_dbf, rls_db, &_s);
	if(ver!=W_TABLE_VERSION)
	{
		LM_ERR("Wrong version v%d for table <%s>,"
				" need v%d\n", ver, _s.s, W_TABLE_VERSION);
		return -1;
	}
	
	_s.s = rlpres_table;
	_s.len = strlen(rlpres_table);
	 ver =  table_version(&rls_dbf, rls_db, &_s);
	if(ver!=P_TABLE_VERSION)
	{
		LM_ERR("Wrong version v%d for table <%s>,"
				" need v%d\n", ver, _s.s, P_TABLE_VERSION);
		return -1;
	}
	if(hash_size<=1)
		hash_size= 512;
	else
		hash_size = 1<<hash_size;

	rls_table= pres_new_shtable(hash_size);
	if(rls_table== NULL)
	{
		LM_ERR("while creating new hash table\n");
		return -1;
	}
	if(rls_restore_db_subs()< 0)
	{
		LM_ERR("while restoring rl watchers table\n");
		return -1;
	}

	if(rls_db)
		rls_dbf.close(rls_db);
	rls_db = NULL;

	if(waitn_time<= 0)
		waitn_time= 5;
	
	if(waitn_time<= 0)
		waitn_time= 100;

	/* bind libxml wrapper functions */

	if((bind_libxml=(bind_libxml_t)find_export("bind_libxml_api", 1, 0))== NULL)
	{
		LM_ERR("can't import bind_libxml_api\n");
		return -1;
	}
	if(bind_libxml(&libxml_api)< 0)
	{
		LM_ERR("can not bind libxml api\n");
		return -1;
	}
	XMLNodeGetAttrContentByName= libxml_api.xmlNodeGetAttrContentByName;
	XMLDocGetNodeByName= libxml_api.xmlDocGetNodeByName;
	XMLNodeGetNodeByName= libxml_api.xmlNodeGetNodeByName;
    XMLNodeGetNodeContentByName= libxml_api.xmlNodeGetNodeContentByName;

	if(XMLNodeGetAttrContentByName== NULL || XMLDocGetNodeByName== NULL ||
			XMLNodeGetNodeByName== NULL || XMLNodeGetNodeContentByName== NULL)
	{
		LM_ERR("libxml wrapper functions could not be bound\n");
		return -1;
	}

	/* bind 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("mod_init Can't bind pua\n");
		return -1;
	}
	if(pua.send_subscribe == NULL)
	{
		LM_ERR("Could not import send_subscribe\n");
		return -1;
	}
	pua_send_subscribe= pua.send_subscribe;
	
	if(pua.get_record_id == NULL)
	{
		LM_ERR("Could not import send_subscribe\n");
		return -1;
	}
	pua_get_record_id= pua.get_record_id;

	if(!rls_integrated_xcap_server)
	{
		/* bind xcap */
		bind_xcap= (bind_xcap_t)find_export("bind_xcap", 1, 0);
		if (!bind_xcap)
		{
			LM_ERR("Can't bind xcap_client\n");
			return -1;
		}
	
		if (bind_xcap(&xcap_api) < 0)
		{
			LM_ERR("Can't bind xcap\n");
			return -1;
		}
		xcap_GetNewDoc= xcap_api.getNewDoc;
		if(xcap_GetNewDoc== NULL)
		{
			LM_ERR("Can't import xcap_client functions\n");
			return -1;
		}
	}
	register_timer(timer_send_notify,0, waitn_time);
	
	register_timer(rls_presentity_clean, 0, clean_period);
	
	register_timer(rlsubs_table_update, 0, clean_period);
	
	return 0;
}
Exemple #10
0
int group_db_ver(str* name)
{
	return table_version( &group_dbf, group_dbh, name);
}