soc.2009.transport: 8fb27b5d: Added transportFeatures, VIPFeatures and...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu Jul 23 04:05:38 EDT 2009


-----------------------------------------------------------------
Revision: 8fb27b5dd4bad511f0f973b110da2a6d2b5535d8
Ancestor: 91c623aba64a2dc3d7b6a1dd403559c3b0d4f194
Author: hanzz at soc.pidgin.im
Date: 2009-07-23T07:59:01
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/8fb27b5dd4bad511f0f973b110da2a6d2b5535d8

Modified files:
        main.cpp main.h registerhandler.cpp user.cpp user.h
        vcardhandler.cpp

ChangeLog: 

Added transportFeatures, VIPFeatures and language config variables.

-------------- next part --------------
============================================================
--- main.cpp	3365f8f89c2896fee5064f921c3670ecf5f33a49
+++ main.cpp	b418c9fd6b955581bf4ca788b6b85b3ced675079
@@ -833,8 +833,12 @@ void GlooxMessageHandler::loadConfigFile
 // 	features1 = (int)g_key_file_get_integer(keyfile, "category1","features", NULL);
 
 	m_configuration.userDir = (std::string)g_key_file_get_string(keyfile, "purple","userdir", NULL);
+
+	if(g_key_file_has_key(keyfile,"service","language",NULL))
+		m_configuration.language=g_key_file_get_string(keyfile, "service","language", NULL);
+	else
+		m_configuration.language = "en";
 	
-	
 	if(g_key_file_has_key(keyfile,"service","only_for_vip",NULL))
 		m_configuration.onlyForVIP=g_key_file_get_boolean(keyfile, "service","only_for_vip", NULL);
 	else
@@ -845,6 +849,34 @@ void GlooxMessageHandler::loadConfigFile
 	else
 		m_configuration.VIPEnabled=false;
 
+	if(g_key_file_has_key(keyfile,"service","transport_features",NULL)) {
+		bind = g_key_file_get_string_list (keyfile,"service","transport_features",NULL, NULL);
+		m_configuration.transportFeatures = 0;
+		for (i = 0; bind[i]; i++){
+			std::string feature(bind[i]);
+			if (feature == "avatars")
+				m_configuration.transportFeatures = m_configuration.transportFeatures | TRANSPORT_FEATURE_AVATARS;
+			else if (feature == "chatstate")
+				m_configuration.transportFeatures = m_configuration.transportFeatures | TRANSPORT_FEATURE_TYPING_NOTIFY;
+		}
+		g_strfreev (bind);
+	}
+	else m_configuration.transportFeatures = 256;
+	
+	if(g_key_file_has_key(keyfile,"service","vip_features",NULL)) {
+		bind = g_key_file_get_string_list (keyfile,"service","vip_features",NULL, NULL);
+		m_configuration.VIPFeatures = 0;
+		for (i = 0; bind[i]; i++){
+			std::string feature(bind[i]);
+			if (feature == "avatars")
+				m_configuration.VIPFeatures = m_configuration.VIPFeatures | TRANSPORT_FEATURE_AVATARS;
+			else if (feature == "chatstate")
+				m_configuration.VIPFeatures = m_configuration.VIPFeatures | TRANSPORT_FEATURE_TYPING_NOTIFY;
+		}
+		g_strfreev (bind);
+	}
+	else m_configuration.VIPFeatures = 256;
+
 	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
@@ -1208,13 +1240,10 @@ void GlooxMessageHandler::handlePresence
 				}
 				else
 					user = new User(this, stanza.from(), res.uin, res.password, stanza.from().bare());
+				user->setFeatures(isVip ? configuration().VIPFeatures : configuration().transportFeatures);
 				if (c!=NULL)
 					if(hasCaps(c->findAttribute("ver")))
 						user->setResource(stanza.from().resource(), stanza.priority(), c->findAttribute("ver"));
-// 				if (!isVip)
-// 					user->features=features0;
-// 				else
-// 					user->features=features1;
 
 				std::map<int,std::string> ::iterator iter = configuration().bindIPs.begin();
 				iter = configuration().bindIPs.find(lastIP);
============================================================
--- main.h	100bd4453c1ca8f05a2e120d50b5660eb437c38b
+++ main.h	2d88e47c116f38d22072c0489c75dc0e76a5cdf7
@@ -135,6 +135,9 @@ struct Configuration {
 	
 	bool onlyForVIP;		// true if transport is only for users in VIP users database
 	bool VIPEnabled;
+	int transportFeatures;
+	std::string language;
+	int VIPFeatures;
 	bool useProxy;
 	std::list <std::string> allowedServers;
 	std::map<int,std::string> bindIPs;	// IP address to which libpurple should bind connections
============================================================
--- registerhandler.cpp	e3786baee9c768fe48a07e836c5885911b48fe5a
+++ registerhandler.cpp	0b6747ae099ca08313771852595fb28e221244be
@@ -63,7 +63,7 @@ bool GlooxRegisterHandler::handleIq (con
 			query->addChild( new Tag("instructions", p->protocol()->text("instructions")) );
 			query->addChild( new Tag("username") );
 			query->addChild( new Tag("password") );
-			query->addChild( new Tag("language", "cs") );
+			query->addChild( new Tag("language", p->configuration().language) );
 		}
 		else {
 			std::cout << "* sending registration form; user is registered\n";
@@ -106,7 +106,7 @@ bool GlooxRegisterHandler::handleIq (con
 		if (res.id!=-1)
 			field->addChild( new Tag("value", res.language) );
 		else
-			field->addChild( new Tag("value", "cs") );
+			field->addChild( new Tag("value", p->configuration().language) );
 
 		Tag *option = new Tag("option");
 		option->addAttribute("label", "Cesky");
@@ -175,7 +175,7 @@ bool GlooxRegisterHandler::handleIq (con
 			if (languagetag)
 				language = languagetag->cdata();
 			else
-				language = "cs";
+				language = p->configuration().language;
 
 			if (usernametag==NULL || passwordtag==NULL)
 				e=true;
============================================================
--- user.cpp	f20a842759ae68d583e0a348a7ba2d0408276e28
+++ user.cpp	1ef6a03d7cd404788394ef986f637278c1c963a9
@@ -70,7 +70,7 @@ User::User(GlooxMessageHandler *parent, 
 	m_subscribeLastCount = -1;
 	m_reconnectCount = 0;
 	m_lang = NULL;
-	this->features = 6; // TODO: I can't be hardcoded
+	m_features = 0;
 	m_mucs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 	PurpleValue *value;
 	
@@ -138,7 +138,7 @@ bool User::hasTransportFeature(int featu
  * otherwise returns false.
  */
 bool User::hasTransportFeature(int feature){
-	if (this->features&feature)
+	if (m_features & feature)
 		return true;
 	return false;
 }
@@ -336,38 +336,40 @@ Tag *User::generatePresenceStanza(Purple
 	c->addAttribute("ver","Q543534fdsfsdsssT/WM94uAlu0=");
 	tag->addChild(c);
 	
-	// vcard-temp:x:update
-	char *avatarHash = NULL;
-	PurpleBuddyIcon *icon = purple_buddy_icons_find(m_account, name.c_str());
-	if (icon != NULL) {
-		avatarHash = purple_buddy_icon_get_full_path(icon);
-		Log().Get(m_jid) << "avatarHash";
-	}
+	if (hasTransportFeature(TRANSPORT_FEATURE_AVATARS)) {
+		// vcard-temp:x:update
+		char *avatarHash = NULL;
+		PurpleBuddyIcon *icon = purple_buddy_icons_find(m_account, name.c_str());
+		if (icon != NULL) {
+			avatarHash = purple_buddy_icon_get_full_path(icon);
+			Log().Get(m_jid) << "avatarHash";
+		}
 
-	if (purple_value_get_boolean(getSetting("enable_avatars"))){
-		Tag *x = new Tag("x");
-		x->addAttribute("xmlns","vcard-temp:x:update");
-		if (avatarHash != NULL) {
-			Log().Get(m_jid) << "Got avatar hash";
-			// Check if it's patched libpurple which saved icons to directories
-			char *hash = rindex(avatarHash,'/');
-			std::string h;
-			if (hash) {
-				char *dot;
-				hash++;
-				dot = strchr(hash, '.');
-				if (dot)
-					*dot = '\0';
-				x->addChild(new Tag("photo",(std::string) hash));
+		if (purple_value_get_boolean(getSetting("enable_avatars"))){
+			Tag *x = new Tag("x");
+			x->addAttribute("xmlns","vcard-temp:x:update");
+			if (avatarHash != NULL) {
+				Log().Get(m_jid) << "Got avatar hash";
+				// Check if it's patched libpurple which saves icons to directories
+				char *hash = rindex(avatarHash,'/');
+				std::string h;
+				if (hash) {
+					char *dot;
+					hash++;
+					dot = strchr(hash, '.');
+					if (dot)
+						*dot = '\0';
+					x->addChild(new Tag("photo",(std::string) hash));
+				}
+				else
+					x->addChild(new Tag("photo",(std::string) avatarHash));
 			}
-			else
-				x->addChild(new Tag("photo",(std::string) avatarHash));
+			else{
+				Log().Get(m_jid) << "no avatar hash";
+				x->addChild(new Tag("photo"));
+			}
+			tag->addChild(x);
 		}
-		else{
-			Log().Get(m_jid) << "no avatar hash";
-			x->addChild(new Tag("photo"));
-		}
-		tag->addChild(x);
 	}
 
 	// update stats...
@@ -690,7 +692,7 @@ void User::purpleBuddyTypingStopped(cons
  * Called when legacy network user stops typing.
  */
 void User::purpleBuddyTypingStopped(const std::string &uin){
-	if (!hasFeature(GLOOX_FEATURE_CHATSTATES))
+	if (!hasFeature(GLOOX_FEATURE_CHATSTATES) || !hasTransportFeature(TRANSPORT_FEATURE_TYPING_NOTIFY))
 		return;
 	if (!purple_value_get_boolean(getSetting("enable_chatstate")))
 		return;
@@ -721,7 +723,7 @@ void User::purpleBuddyTyping(const std::
  * Called when legacy network user starts typing.
  */
 void User::purpleBuddyTyping(const std::string &uin){
-	if (!hasFeature(GLOOX_FEATURE_CHATSTATES))
+	if (!hasFeature(GLOOX_FEATURE_CHATSTATES) || !hasTransportFeature(TRANSPORT_FEATURE_TYPING_NOTIFY))
 		return;
 	if (!purple_value_get_boolean(getSetting("enable_chatstate")))
 		return;
@@ -751,7 +753,7 @@ void User::receivedChatState(const std::
  * Received Chatstate notification from jabber user :).
  */
 void User::receivedChatState(const std::string &uin,const std::string &state){
-	if (!hasFeature(GLOOX_FEATURE_CHATSTATES))
+	if (!hasFeature(GLOOX_FEATURE_CHATSTATES) || !hasTransportFeature(TRANSPORT_FEATURE_TYPING_NOTIFY))
 		return;
 	Log().Get(m_jid) << "Sending " << state << " message to " << uin;
 	if (state=="composing")
============================================================
--- user.h	0e3457460a1c9c4cc14430eeff7e36dc39f2186d
+++ user.h	ab6f84621e91ec8e3d2e9b6135ab2c39c10b36a6
@@ -119,7 +119,6 @@ class User {
 
 
 		std::string actionData;
-		int features;
 
 		// Connected
 		bool isConnected() { return m_connected; }
@@ -168,6 +167,7 @@ class User {
 		void *protocolData() { return m_protocolData; }
 		GHashTable *mucs() { return m_mucs; }
 		std::map<std::string,Conversation> conversations() { return m_conversations; }
+		void setFeatures(int f) { m_features = f; }
 		
 		guint removeTimer;
 	
@@ -189,6 +189,7 @@ class User {
 		std::string m_jid;			// Jabber ID of this user
 		std::string m_resource;		// active resource
 		const char *m_lang;			// xml:lang
+		int m_features;
 		time_t m_connectionStart;	// connection start timestamp
 		GHashTable *m_mucs;			// MUCs
 		std::map<std::string,RosterRow> m_roster;	// jabber roster of this user
============================================================
--- vcardhandler.cpp	39b2519e99ab84e84a7e7e810e2217a78670bcc8
+++ vcardhandler.cpp	0be7bd3684fcefd84e8adf6c47b7c89b146c1d58
@@ -160,7 +160,7 @@ void GlooxVCardHandler::userInfoArrived(
 			vcard->addAttribute( "xmlns", "vcard-temp" );
 		}
 
-		if (purple_value_get_boolean(user->getSetting("enable_avatars"))) {
+		if (purple_value_get_boolean(user->getSetting("enable_avatars")) && user->hasTransportFeature(TRANSPORT_FEATURE_AVATARS)) {
 			Tag *photo = new Tag("PHOTO");
 
 			PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(gc), who.c_str());


More information about the Commits mailing list