Mercurial > pidgin
changeset 29055:73e4c14921e4
jabber: Move those functions to jutil.[ch]
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 15 Feb 2010 05:35:56 +0000 |
parents | f2949cd7db0a |
children | af4bb8ccc7f5 |
files | libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/buddy.h libpurple/protocols/jabber/jutil.c libpurple/protocols/jabber/jutil.h |
diffstat | 4 files changed, 100 insertions(+), 98 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c Mon Feb 15 05:31:34 2010 +0000 +++ b/libpurple/protocols/jabber/buddy.c Mon Feb 15 05:35:56 2010 +0000 @@ -1908,82 +1908,6 @@ } } -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) {
--- a/libpurple/protocols/jabber/buddy.h Mon Feb 15 05:31:34 2010 +0000 +++ b/libpurple/protocols/jabber/buddy.h Mon Feb 15 05:35:56 2010 +0000 @@ -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_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 *);
--- a/libpurple/protocols/jabber/jutil.c Mon Feb 15 05:31:34 2010 +0000 +++ b/libpurple/protocols/jabber/jutil.c Mon Feb 15 05:35:56 2010 +0000 @@ -651,6 +651,83 @@ 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)
--- a/libpurple/protocols/jabber/jutil.h Mon Feb 15 05:31:34 2010 +0000 +++ b/libpurple/protocols/jabber/jutil.h Mon Feb 15 05:35:56 2010 +0000 @@ -30,6 +30,17 @@ 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 *); +/* 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_ */