soc.2009.transport: 91c623ab: Use vips table to get VIP users. Also Ad...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Wed Jul 22 01:05:59 EDT 2009


-----------------------------------------------------------------
Revision: 91c623aba64a2dc3d7b6a1dd403559c3b0d4f194
Ancestor: a8262c95640bc1cbafc4593be3b8dd19a26af9ce
Author: hanzz at soc.pidgin.im
Date: 2009-07-22T05:02:40
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/91c623aba64a2dc3d7b6a1dd403559c3b0d4f194

Modified files:
        main.cpp main.h schemas/mysql_schema.sql sql.cpp

ChangeLog: 

Use vips table to get VIP users. Also Added vip_mode config variable to enable/disable VIP.

-------------- next part --------------
============================================================
--- main.cpp	4c30b5fccbaa9c3a0484da346818baafe2c34020
+++ main.cpp	3365f8f89c2896fee5064f921c3670ecf5f33a49
@@ -840,6 +840,11 @@ void GlooxMessageHandler::loadConfigFile
 	else
 		m_configuration.onlyForVIP=false;
 
+	if(g_key_file_has_key(keyfile,"service","vip_mode",NULL))
+		m_configuration.VIPEnabled=g_key_file_get_boolean(keyfile, "service","vip_mode", NULL);
+	else
+		m_configuration.VIPEnabled=false;
+
 	if(g_key_file_has_key(keyfile,"service","use_proxy",NULL))
 		m_configuration.useProxy=g_key_file_get_boolean(keyfile, "service","use_proxy", NULL);
 	else
============================================================
--- main.h	50465752b8ae8b9454d383834ab5e0bef2b6f90c
+++ main.h	100bd4453c1ca8f05a2e120d50b5660eb437c38b
@@ -134,6 +134,7 @@ struct Configuration {
 	int port;				// server port
 	
 	bool onlyForVIP;		// true if transport is only for users in VIP users database
+	bool VIPEnabled;
 	bool useProxy;
 	std::list <std::string> allowedServers;
 	std::map<int,std::string> bindIPs;	// IP address to which libpurple should bind connections
============================================================
--- schemas/mysql_schema.sql	a01a7f6c0b7276441842983943514f3607c8c251
+++ schemas/mysql_schema.sql	54cb29164a71f2d8aa6d1d482bc252187eb2710b
@@ -31,6 +31,11 @@ CREATE TABLE `settings` (
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 
+CREATE TABLE `vips` (
+  `jid` VARCHAR(255) NOT NULL,
+  PRIMARY KEY (`jid`)
+) ENGINE=MYISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
 CREATE TABLE IF NOT EXISTS `vcards` (
   `username` varchar(250) NOT NULL,
   `vcard` text NOT NULL,
============================================================
--- sql.cpp	485c97641ac1c2a1e5f6eec39a27c51027101e25
+++ sql.cpp	00c8f54d7218a91f1d6d55612a7b62f5868ef514
@@ -28,21 +28,29 @@ SQLClass::SQLClass(GlooxMessageHandler *
 		std::cout << "SQL CONNECTION FAILED\n";
 	vipSQL = new mysqlpp::Connection(false);
 	if (!vipSQL->connect("platby",p->configuration().sqlHost.c_str(),p->configuration().sqlUser.c_str(),p->configuration().sqlPassword.c_str()))
-		std::cout << "SQL CONNECTION to VIP database FAILED\n";
+		std::cout << "Can't connect to SQL-VIP database, using built-in.\n";
 }
 
 bool SQLClass::isVIP(const std::string &jid){
-	if (!vipSQL->connected())
+	if (!p->configuration().VIPEnabled)
 		return true;
-	mysqlpp::Query query = vipSQL->query();
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	mysqlpp::Result res;
 #else
 	mysqlpp::StoreQueryResult res;
 #endif
 	mysqlpp::Row myrow;
-	query << "SELECT COUNT(jid) as is_vip FROM `users` WHERE jid='"<< jid <<"' and expire>NOW();";
-	res = query.store();
+	if (vipSQL->connected()) {
+		mysqlpp::Query query = vipSQL->query();
+		
+		query << "SELECT COUNT(jid) as is_vip FROM `users` WHERE jid='"<< jid <<"' and expire>NOW();";
+		res = query.store();
+	}
+	else {
+		mysqlpp::Query query = sql->query();
+		query << "SELECT COUNT(jid) as is_vip FROM `vips` WHERE jid='"<< jid <<"'";
+		res = query.store();
+	}
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	myrow = res.fetch_row();
 	if (int(myrow.at(0))==0)


More information about the Commits mailing list