pidgin: a84f322a: jabber: Move those functions to jutil.[c...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Feb 16 10:24:01 EST 2010


-----------------------------------------------------------------
Revision: a84f322aacd39e703e258f6fb74cca0908c4c055
Ancestor: 541b94db5d2e13039101b0d8be4aaefe65c4fb59
Author: darkrain42 at pidgin.im
Date: 2010-02-15T05:35:56
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a84f322aacd39e703e258f6fb74cca0908c4c055

Modified files:
        libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/buddy.h
        libpurple/protocols/jabber/jutil.c
        libpurple/protocols/jabber/jutil.h

ChangeLog: 

jabber: Move those functions to jutil.[ch]

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	b78468f6c93c1b99b83cc9b102d77f51da1f3ae4
+++ libpurple/protocols/jabber/buddy.c	f8990d24deb8fd91391eb6010eb432e88e528ca1
@@ -1908,83 +1908,7 @@ jabber_blist_node_menu(PurpleBlistNode *
 	}
 }
 
-static const struct {
-		const char *status_id; /* link to core */
-		const char *show; /* The show child's cdata in a presence stanza */
-		const char *readable; /* readable representation */
-		JabberBuddyState state;
-} jabber_statuses[] = {
-	{ "offline",       NULL,   N_("Offline"),        JABBER_BUDDY_STATE_UNAVAILABLE },
-	{ "available",     NULL,   N_("Available"),      JABBER_BUDDY_STATE_ONLINE},
-	{ "freeforchat",   "chat", N_("Chatty"),         JABBER_BUDDY_STATE_CHAT },
-	{ "away",          "away", N_("Away"),           JABBER_BUDDY_STATE_AWAY },
-	{ "extended_away", "xa",   N_("Extended Away"),  JABBER_BUDDY_STATE_XA },
-	{ "dnd",           "dnd",  N_("Do Not Disturb"), JABBER_BUDDY_STATE_DND },
-	{ "error",         NULL,   N_("Error"),          JABBER_BUDDY_STATE_ERROR }
-};
 
-const char *
-jabber_buddy_state_get_name(const JabberBuddyState state)
-{
-	int i;
-	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
-		if (jabber_statuses[i].state == state)
-			return _(jabber_statuses[i].readable);
-
-	return _("Unknown");
-}
-
-JabberBuddyState
-jabber_buddy_status_id_get_state(const char *id)
-{
-	int i;
-	if (!id)
-		return JABBER_BUDDY_STATE_UNKNOWN;
-
-	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
-		if (g_str_equal(id, jabber_statuses[i].status_id))
-			return jabber_statuses[i].state;
-
-	return JABBER_BUDDY_STATE_UNKNOWN;
-}
-
-JabberBuddyState jabber_buddy_show_get_state(const char *id)
-{
-	int i;
-
-	g_return_val_if_fail(id != NULL, JABBER_BUDDY_STATE_UNKNOWN);
-
-	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
-		if (g_str_equal(id, jabber_statuses[i].show))
-			return jabber_statuses[i].state;
-
-	purple_debug_warning("jabber", "Invalid value of presence <show/> "
-	                     "attribute: %s\n", id);
-	return JABBER_BUDDY_STATE_UNKNOWN;
-}
-
-const char *
-jabber_buddy_state_get_show(JabberBuddyState state)
-{
-	int i;
-	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
-		if (state == jabber_statuses[i].state)
-			return jabber_statuses[i].show;
-
-	return NULL;
-}
-
-const char *
-jabber_buddy_state_get_status_id(JabberBuddyState state)
-{
-	int i;
-	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
-		if (state == jabber_statuses[i].state)
-			return jabber_statuses[i].status_id;
-
-	return NULL;
-}
-
 static void user_search_result_add_buddy_cb(PurpleConnection *gc, GList *row, void *user_data)
 {
 	/* XXX find out the jid */
============================================================
--- libpurple/protocols/jabber/buddy.h	80cdc15f3167fa1573fd2e5b1d233bd15655ec40
+++ libpurple/protocols/jabber/buddy.h	d719dd25eabaa7c09429c0c3a73403768742ebd2
@@ -24,21 +24,11 @@
 #ifndef PURPLE_JABBER_BUDDY_H_
 #define PURPLE_JABBER_BUDDY_H_
 
-typedef enum {
-	JABBER_BUDDY_STATE_UNKNOWN = -2,
-	JABBER_BUDDY_STATE_ERROR = -1,
-	JABBER_BUDDY_STATE_UNAVAILABLE = 0,
-	JABBER_BUDDY_STATE_ONLINE,
-	JABBER_BUDDY_STATE_CHAT,
-	JABBER_BUDDY_STATE_AWAY,
-	JABBER_BUDDY_STATE_XA,
-	JABBER_BUDDY_STATE_DND
-} JabberBuddyState;
-
 typedef struct _JabberBuddy JabberBuddy;
 
 #include "jabber.h"
 #include "caps.h"
+#include "jutil.h"
 
 struct _JabberBuddy {
 	GList *resources;
@@ -110,17 +100,6 @@ void jabber_set_buddy_icon(PurpleConnect
 void jabber_setup_set_info(PurplePluginAction *action);
 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img);
 
-/* state -> readable name */
-const char *jabber_buddy_state_get_name(JabberBuddyState state);
-/* state -> core id */
-const char *jabber_buddy_state_get_status_id(JabberBuddyState state);
-/* state -> show attr (for presence stanza) */
-const char *jabber_buddy_state_get_show(JabberBuddyState state);
-/* core id -> state */
-JabberBuddyState jabber_buddy_status_id_get_state(const char *id);
-/* show attr (presence stanza) -> state */
-JabberBuddyState jabber_buddy_show_get_state(const char *id);
-
 void jabber_user_search(JabberStream *js, const char *directory);
 void jabber_user_search_begin(PurplePluginAction *);
 
============================================================
--- libpurple/protocols/jabber/jutil.c	d0ecf1856c5cde6e1deb28492fcdbf624805d7f3
+++ libpurple/protocols/jabber/jutil.c	2a409146fa1c89efcf647438ba1d40a6c6bd0be2
@@ -651,6 +651,83 @@ jabber_is_own_account(JabberStream *js, 
 	return equal;
 }
 
+static const struct {
+		const char *status_id; /* link to core */
+		const char *show; /* The show child's cdata in a presence stanza */
+		const char *readable; /* readable representation */
+		JabberBuddyState state;
+} jabber_statuses[] = {
+	{ "offline",       NULL,   N_("Offline"),        JABBER_BUDDY_STATE_UNAVAILABLE },
+	{ "available",     NULL,   N_("Available"),      JABBER_BUDDY_STATE_ONLINE},
+	{ "freeforchat",   "chat", N_("Chatty"),         JABBER_BUDDY_STATE_CHAT },
+	{ "away",          "away", N_("Away"),           JABBER_BUDDY_STATE_AWAY },
+	{ "extended_away", "xa",   N_("Extended Away"),  JABBER_BUDDY_STATE_XA },
+	{ "dnd",           "dnd",  N_("Do Not Disturb"), JABBER_BUDDY_STATE_DND },
+	{ "error",         NULL,   N_("Error"),          JABBER_BUDDY_STATE_ERROR }
+};
+
+const char *
+jabber_buddy_state_get_name(const JabberBuddyState state)
+{
+	int i;
+	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
+		if (jabber_statuses[i].state == state)
+			return _(jabber_statuses[i].readable);
+
+	return _("Unknown");
+}
+
+JabberBuddyState
+jabber_buddy_status_id_get_state(const char *id)
+{
+	int i;
+	if (!id)
+		return JABBER_BUDDY_STATE_UNKNOWN;
+
+	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
+		if (g_str_equal(id, jabber_statuses[i].status_id))
+			return jabber_statuses[i].state;
+
+	return JABBER_BUDDY_STATE_UNKNOWN;
+}
+
+JabberBuddyState jabber_buddy_show_get_state(const char *id)
+{
+	int i;
+
+	g_return_val_if_fail(id != NULL, JABBER_BUDDY_STATE_UNKNOWN);
+
+	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
+		if (g_str_equal(id, jabber_statuses[i].show))
+			return jabber_statuses[i].state;
+
+	purple_debug_warning("jabber", "Invalid value of presence <show/> "
+	                     "attribute: %s\n", id);
+	return JABBER_BUDDY_STATE_UNKNOWN;
+}
+
+const char *
+jabber_buddy_state_get_show(JabberBuddyState state)
+{
+	int i;
+	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
+		if (state == jabber_statuses[i].state)
+			return jabber_statuses[i].show;
+
+	return NULL;
+}
+
+const char *
+jabber_buddy_state_get_status_id(JabberBuddyState state)
+{
+	int i;
+	for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
+		if (state == jabber_statuses[i].state)
+			return jabber_statuses[i].status_id;
+
+	return NULL;
+}
+
 /* The same as purple_util_get_image_checksum, but guaranteed to remain SHA1 */
 char *
 jabber_calculate_data_sha1sum(gconstpointer data, size_t len)
============================================================
--- libpurple/protocols/jabber/jutil.h	e18a94f6754ab41d5272d85925d8115f29fcfba0
+++ libpurple/protocols/jabber/jutil.h	8278b5db84fa1fc0f8f72544722efbb7cea51537
@@ -30,6 +30,17 @@ typedef struct _JabberID {
 	char *resource;
 } JabberID;
 
+typedef enum {
+	JABBER_BUDDY_STATE_UNKNOWN = -2,
+	JABBER_BUDDY_STATE_ERROR = -1,
+	JABBER_BUDDY_STATE_UNAVAILABLE = 0,
+	JABBER_BUDDY_STATE_ONLINE,
+	JABBER_BUDDY_STATE_CHAT,
+	JABBER_BUDDY_STATE_AWAY,
+	JABBER_BUDDY_STATE_XA,
+	JABBER_BUDDY_STATE_DND
+} JabberBuddyState;
+
 #include "jabber.h"
 
 JabberID* jabber_id_new(const char *str);
@@ -63,5 +74,16 @@ char *jabber_saslprep(const char *);
  */
 char *jabber_saslprep(const char *);
 
+/* state -> readable name */
+const char *jabber_buddy_state_get_name(JabberBuddyState state);
+/* state -> core id */
+const char *jabber_buddy_state_get_status_id(JabberBuddyState state);
+/* state -> show attr (for presence stanza) */
+const char *jabber_buddy_state_get_show(JabberBuddyState state);
+/* core id -> state */
+JabberBuddyState jabber_buddy_status_id_get_state(const char *id);
+/* show attr (presence stanza) -> state */
+JabberBuddyState jabber_buddy_show_get_state(const char *id);
+
 char *jabber_calculate_data_sha1sum(gconstpointer data, size_t len);
 #endif /* PURPLE_JABBER_JUTIL_H_ */


More information about the Commits mailing list