/soc/2013/ankitkv/gobjectification: ff356949df25: Refactored the...

Ankit Vani a at nevitus.org
Sat Aug 31 16:59:45 EDT 2013


Changeset: ff356949df259daa174660aab0dbdd270e69c843
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-01 02:28 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/ff356949df25

Description:

Refactored the rest of libpurple to use the new protocol API

diffstat:

 libpurple/dbus-analyze-functions.py |   3 +
 libpurple/example/nullclient.c      |   8 +-
 libpurple/roomlist.c                |   6 +-
 libpurple/server.c                  |  79 ++++++++++++------------------------
 libpurple/util.c                    |   7 +-
 5 files changed, 40 insertions(+), 63 deletions(-)

diffs (truncated from 310 to 300 lines):

diff --git a/libpurple/dbus-analyze-functions.py b/libpurple/dbus-analyze-functions.py
--- a/libpurple/dbus-analyze-functions.py
+++ b/libpurple/dbus-analyze-functions.py
@@ -31,6 +31,9 @@ excluded = [\
     "purple_account_set_register_callback",
     "purple_account_unregister",
 
+    # Similar to the above:
+    "purple_protocol_iface_unregister_user",
+
     # Similar to the above, again
     "purple_menu_action_new",
     "purple_menu_action_set_callback",
diff --git a/libpurple/example/nullclient.c b/libpurple/example/nullclient.c
--- a/libpurple/example/nullclient.c
+++ b/libpurple/example/nullclient.c
@@ -266,10 +266,10 @@ int main(int argc, char *argv[])
 
 	iter = purple_protocols_get_all();
 	for (i = 0; iter; iter = iter->next) {
-		PurpleProtocol *info = iter->data;
-		if (info && info->name) {
-			printf("\t%d: %s\n", i++, info->name);
-			names = g_list_append(names, (gpointer)info->id);
+		PurpleProtocol *protocol = iter->data;
+		if (protocol && purple_protocol_get_name(protocol)) {
+			printf("\t%d: %s\n", i++, purple_protocol_get_name(protocol));
+			names = g_list_append(names, (gpointer)purple_protocol_get_id(protocol));
 		}
 	}
 	printf("Select the protocol [0-%d]: ", i-1);
diff --git a/libpurple/roomlist.c b/libpurple/roomlist.c
--- a/libpurple/roomlist.c
+++ b/libpurple/roomlist.c
@@ -214,7 +214,7 @@ PurpleRoomlist *purple_roomlist_get_list
 
 	protocol = purple_connection_get_protocol(gc);
 
-	if(protocol && protocol->roomlist_get_list)
+	if(protocol)
 		return purple_protocol_iface_roomlist_get_list(protocol, gc);
 
 	return NULL;
@@ -234,7 +234,7 @@ void purple_roomlist_cancel_get_list(Pur
 	if(gc)
 		protocol = purple_connection_get_protocol(gc);
 
-	if(protocol && protocol->roomlist_cancel)
+	if(protocol)
 		purple_protocol_iface_roomlist_cancel(protocol, list);
 }
 
@@ -253,7 +253,7 @@ void purple_roomlist_expand_category(Pur
 	if(gc)
 		protocol = purple_connection_get_protocol(gc);
 
-	if(protocol && protocol->roomlist_expand_category)
+	if(protocol)
 		purple_protocol_iface_roomlist_expand_category(protocol, list, category);
 }
 
diff --git a/libpurple/server.c b/libpurple/server.c
--- a/libpurple/server.c
+++ b/libpurple/server.c
@@ -47,9 +47,7 @@ serv_send_typing(PurpleConnection *gc, c
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->send_typing)
-			return purple_protocol_iface_send_typing(protocol, gc, name, state);
+		return purple_protocol_iface_send_typing(protocol, gc, name, state);
 	}
 
 	return 0;
@@ -135,7 +133,7 @@ int serv_send_im(PurpleConnection *gc, c
 
 	im = purple_conversations_find_im_with_account(name, account);
 
-	if (protocol->send_im)
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_im))
 		val = purple_protocol_iface_send_im(protocol, gc, name, message, flags);
 
 	/*
@@ -164,9 +162,7 @@ void serv_get_info(PurpleConnection *gc,
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->get_info)
-			purple_protocol_iface_get_info(protocol, gc, name);
+		purple_protocol_iface_get_info(protocol, gc, name);
 	}
 }
 
@@ -178,7 +174,7 @@ void serv_set_info(PurpleConnection *gc,
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
 
-		if (protocol->set_info) {
+		if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, set_info)) {
 			account = purple_connection_get_account(gc);
 
 			if (purple_signal_emit_return_1(purple_accounts_get_handle(),
@@ -210,11 +206,9 @@ void serv_alias_buddy(PurpleBuddy *b)
 
 			if (gc) {
 				protocol = purple_connection_get_protocol(gc);
-
-				if (protocol->alias_buddy)
-					purple_protocol_iface_alias_buddy(protocol, gc,
-							purple_buddy_get_name(b),
-							purple_buddy_get_local_alias(b));
+				purple_protocol_iface_alias_buddy(protocol, gc,
+						purple_buddy_get_name(b),
+						purple_buddy_get_local_alias(b));
 			}
 		}
 	}
@@ -293,18 +287,16 @@ PurpleAttentionType *purple_get_attentio
 {
 	PurpleProtocol *protocol;
 	PurpleAttentionType* attn;
-	GList *(*get_attention_types)(PurpleAccount *);
 
 	g_return_val_if_fail(account != NULL, NULL);
 
 	protocol = purple_protocols_find(purple_account_get_protocol_id(account));
 
 	/* Lookup the attention type in the protocol's attention_types list, if any. */
-	get_attention_types = protocol->get_attention_types;
-	if (get_attention_types) {
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, get_attention_types)) {
 		GList *attention_types;
 
-		attention_types = get_attention_types(account);
+		attention_types = purple_protocol_iface_get_attention_types(protocol, account);
 		attn = (PurpleAttentionType *)g_list_nth_data(attention_types, type_code);
 	} else {
 		attn = NULL;
@@ -336,11 +328,9 @@ void serv_move_buddy(PurpleBuddy *b, Pur
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->group_buddy)
-			purple_protocol_iface_group_buddy(protocol, gc, purple_buddy_get_name(b),
-					purple_group_get_name(og),
-					purple_group_get_name(ng));
+		purple_protocol_iface_group_buddy(protocol, gc, purple_buddy_get_name(b),
+				purple_group_get_name(og),
+				purple_group_get_name(ng));
 	}
 }
 
@@ -350,9 +340,7 @@ void serv_add_permit(PurpleConnection *g
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->add_permit)
-			purple_protocol_iface_add_permit(protocol, gc, name);
+		purple_protocol_iface_add_permit(protocol, gc, name);
 	}
 }
 
@@ -362,9 +350,7 @@ void serv_add_deny(PurpleConnection *gc,
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->add_deny)
-			purple_protocol_iface_add_deny(protocol, gc, name);
+		purple_protocol_iface_add_deny(protocol, gc, name);
 	}
 }
 
@@ -374,9 +360,7 @@ void serv_rem_permit(PurpleConnection *g
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->rem_permit)
-			purple_protocol_iface_rem_permit(protocol, gc, name);
+		purple_protocol_iface_rem_permit(protocol, gc, name);
 	}
 }
 
@@ -386,9 +370,7 @@ void serv_rem_deny(PurpleConnection *gc,
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->rem_deny)
-			purple_protocol_iface_rem_deny(protocol, gc, name);
+		purple_protocol_iface_rem_deny(protocol, gc, name);
 	}
 }
 
@@ -405,8 +387,7 @@ void serv_set_permit_deny(PurpleConnecti
 		 * in the prefs. In either case you should probably be resetting and
 		 * resending the permit/deny info when you get this.
 		 */
-		if (protocol->set_permit_deny)
-			purple_protocol_iface_set_permit_deny(protocol, gc);
+		purple_protocol_iface_set_permit_deny(protocol, gc);
 	}
 }
 
@@ -416,9 +397,7 @@ void serv_join_chat(PurpleConnection *gc
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->join_chat)
-			purple_protocol_iface_join_chat(protocol, gc, data);
+		purple_protocol_iface_join_chat(protocol, gc, data);
 	}
 }
 
@@ -429,9 +408,7 @@ void serv_reject_chat(PurpleConnection *
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->reject_chat)
-			purple_protocol_iface_reject_chat(protocol, gc, data);
+		purple_protocol_iface_reject_chat(protocol, gc, data);
 	}
 }
 
@@ -452,7 +429,7 @@ void serv_chat_invite(PurpleConnection *
 	purple_signal_emit(purple_conversations_get_handle(), "chat-inviting-user",
 					 chat, name, &buffy);
 
-	if (protocol && protocol->chat_invite)
+	if (protocol)
 		purple_protocol_iface_chat_invite(protocol, gc, id, buffy, name);
 
 	purple_signal_emit(purple_conversations_get_handle(), "chat-invited-user",
@@ -471,9 +448,7 @@ void serv_chat_leave(PurpleConnection *g
 	PurpleProtocol *protocol;
 
 	protocol = purple_connection_get_protocol(gc);
-
-	if (protocol->chat_leave)
-		purple_protocol_iface_chat_leave(protocol, gc, id);
+	purple_protocol_iface_chat_leave(protocol, gc, id);
 }
 
 void serv_chat_whisper(PurpleConnection *gc, int id, const char *who, const char *message)
@@ -482,9 +457,7 @@ void serv_chat_whisper(PurpleConnection 
 
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
-
-		if (protocol->chat_whisper)
-			purple_protocol_iface_chat_whisper(protocol, gc, id, who, message);
+		purple_protocol_iface_chat_whisper(protocol, gc, id, who, message);
 	}
 }
 
@@ -494,7 +467,7 @@ int serv_chat_send(PurpleConnection *gc,
 
 	protocol = purple_connection_get_protocol(gc);
 
-	if (protocol->chat_send)
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, chat_send))
 		return purple_protocol_iface_chat_send(protocol, gc, id, message, flags);
 
 	return -EINVAL;
@@ -891,9 +864,9 @@ void serv_send_file(PurpleConnection *gc
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
 
-		if (protocol->send_file &&
-				(!protocol->can_receive_file
-						|| purple_protocol_iface_can_receive_file(protocol, gc, who)))
+		if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, can_receive_file) ||
+				purple_protocol_iface_can_receive_file(protocol, gc, who))
+
 			purple_protocol_iface_send_file(protocol, gc, who, file);
 	}
 }
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -3392,7 +3392,7 @@ purple_normalize(const PurpleAccount *ac
 		PurpleProtocol *protocol =
 				purple_protocols_find(purple_account_get_protocol_id(account));
 
-		if (protocol != NULL && protocol->normalize)
+		if (protocol != NULL)
 			ret = purple_protocol_iface_normalize(protocol, account, str);
 	}
 
@@ -3443,10 +3443,11 @@ purple_validate(const PurpleProtocol *pr
 	if (str[0] == '\0')
 		return FALSE;
 



More information about the Commits mailing list