changeset 23111:718a9c287839

Use up the last padding for PurplePluginProtocolInfo in a way that allows adding newer functions without causing any major version bump. This is based on the changes from the .vv branch. I changed the PURPLE_PROTOCOL_PLUGIN_HAS_FUNC macro a little so it can be used for the old as well as the new functions. Someone should confirm this looks OK.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 05 May 2008 06:19:46 +0000
parents 53bf3c21b79d
children bb41bdce8981
files libpurple/protocols/bonjour/bonjour.c libpurple/protocols/gg/gg.c libpurple/protocols/irc/irc.c libpurple/protocols/jabber/libxmpp.c libpurple/protocols/msn/msn.c libpurple/protocols/msnp9/msn.c libpurple/protocols/myspace/myspace.c libpurple/protocols/novell/novell.c libpurple/protocols/oscar/libaim.c libpurple/protocols/oscar/libicq.c libpurple/protocols/qq/qq.c libpurple/protocols/silc/silc.c libpurple/protocols/silc10/silc.c libpurple/protocols/simple/simple.c libpurple/protocols/yahoo/yahoo.c libpurple/protocols/zephyr/zephyr.c libpurple/prpl.h
diffstat 17 files changed, 44 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/bonjour.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/bonjour/bonjour.c	Mon May 05 06:19:46 2008 +0000
@@ -487,7 +487,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/gg/gg.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/gg/gg.c	Mon May 05 06:19:46 2008 +0000
@@ -2152,7 +2152,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 /* }}} */
 
--- a/libpurple/protocols/irc/irc.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/irc/irc.c	Mon May 05 06:19:46 2008 +0000
@@ -905,7 +905,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static gboolean load_plugin (PurplePlugin *plugin) {
--- a/libpurple/protocols/jabber/libxmpp.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Mon May 05 06:19:46 2008 +0000
@@ -116,8 +116,7 @@
 	jabber_send_attention,			/* send_attention */
 	jabber_attention_types,			/* attention_types */
 
-	/* padding */
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static gboolean load_plugin(PurplePlugin *plugin)
--- a/libpurple/protocols/msn/msn.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/msn/msn.c	Mon May 05 06:19:46 2008 +0000
@@ -132,7 +132,6 @@
 	return list;
 }
 
-
 static PurpleCmdRet
 msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
 {
@@ -2307,8 +2306,7 @@
 	msn_send_attention,                     /* send_attention */
 	msn_attention_types,                    /* attention_types */
 
-	/* padding */
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/msnp9/msn.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/msnp9/msn.c	Mon May 05 06:19:46 2008 +0000
@@ -133,7 +133,6 @@
 	return list;
 }
 
-
 static PurpleCmdRet
 msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
 {
@@ -2148,8 +2147,7 @@
 	msn_send_attention,                     /* send_attention */
 	msn_attention_types,                    /* attention_types */
 
-	/* padding */
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/myspace/myspace.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Mon May 05 06:19:46 2008 +0000
@@ -3131,14 +3131,15 @@
 	NULL,                  /* unregister_user */
 	msim_send_attention,   /* send_attention */
 	msim_attention_types,  /* attention_types */
-	NULL                /* _purple_reserved4 */
+
+	sizeof(PurplePluginProtocolInfo),  /* struct_size */
 };
 
 
 
 /** Based on MSN's plugin info comments. */
 static PurplePluginInfo info = {
-	PURPLE_PLUGIN_MAGIC,                                
+	PURPLE_PLUGIN_MAGIC,
 	PURPLE_MAJOR_VERSION,
 	PURPLE_MINOR_VERSION,
 	PURPLE_PLUGIN_PROTOCOL,                           /**< type           */
--- a/libpurple/protocols/novell/novell.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/novell/novell.c	Mon May 05 06:19:46 2008 +0000
@@ -3517,7 +3517,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/protocols/oscar/libaim.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/oscar/libaim.c	Mon May 05 06:19:46 2008 +0000
@@ -96,8 +96,7 @@
 	NULL,					/* send_attention */
 	NULL,					/* get_attention_types */
 
-	/* padding */
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/oscar/libicq.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/oscar/libicq.c	Mon May 05 06:19:46 2008 +0000
@@ -96,8 +96,7 @@
 	NULL,					/* send_attention */
 	NULL,					/* get_attention_types */
 
-	/* padding */
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/qq/qq.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/qq/qq.c	Mon May 05 06:19:46 2008 +0000
@@ -706,7 +706,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/protocols/silc/silc.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/silc/silc.c	Mon May 05 06:19:46 2008 +0000
@@ -2071,7 +2071,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/silc10/silc.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/silc10/silc.c	Mon May 05 06:19:46 2008 +0000
@@ -1800,11 +1800,10 @@
 	NULL,                       /* send_raw */
 	NULL,                       /* roomlist_room_serialize */
 
-	/* padding */
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/simple/simple.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/simple/simple.c	Mon May 05 06:19:46 2008 +0000
@@ -2052,7 +2052,7 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 
--- a/libpurple/protocols/yahoo/yahoo.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Mon May 05 06:19:46 2008 +0000
@@ -4379,8 +4379,7 @@
 	yahoo_send_attention,
 	yahoo_attention_types,
 
-	/* padding */
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/zephyr/zephyr.c	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Mon May 05 06:19:46 2008 +0000
@@ -2907,11 +2907,10 @@
 	NULL,					/* send_raw */
 	NULL,					/* roomlist_room_serialize */
 
-	/* padding */
 	NULL,
 	NULL,
 	NULL,
-	NULL
+	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/prpl.h	Wed Apr 30 21:09:59 2008 +0000
+++ b/libpurple/prpl.h	Mon May 05 06:19:46 2008 +0000
@@ -398,9 +398,34 @@
 	gboolean (*send_attention)(PurpleConnection *gc, const char *username, guint type);
 	GList *(*get_attention_types)(PurpleAccount *acct);
 
-	void (*_purple_reserved4)(void);
+	/**
+	 * The size of the PurplePluginProtocolInfo. This should always be sizeof(PurplePluginProtocolInfo).
+	 * This allows adding more functions to this struct without requiring a major version bump.
+	 */
+	unsigned long struct_size;
+
+	/* NOTE:
+	 * If more functions are added, they should accessed using the following syntax:
+	 *
+	 *		if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl, new_function))
+	 *			prpl->new_function(...);
+	 *
+	 * instead of
+	 *
+	 *		if (prpl->new_function != NULL)
+	 *			prpl->new_function(...);
+	 *
+	 * The PURPLE_PROTOCOL_PLUGIN_HAS_FUNC macro can be used for the older member
+	 * functions (e.g. login, send_im etc.) too.
+	 */
 };
 
+#define PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl, member) \
+	(((G_STRUCT_OFFSET(PurplePluginProtocolInfo, member) < G_STRUCT_OFFSET(PurplePluginProtocolInfo, struct_size)) \
+	  || (G_STRUCT_OFFSET(PurplePluginProtocolInfo, member) < prpl->struct_size)) && \
+	 prpl->member != NULL)
+
+
 #define PURPLE_IS_PROTOCOL_PLUGIN(plugin) \
 	((plugin)->info->type == PURPLE_PLUGIN_PROTOCOL)