Mercurial > pidgin
changeset 26732:d1a0c36cc4ea
Provide alternative find_by_jid that doesn't use g_hash_table_find
g_hash_table_find was added in 2.4.0
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 27 Apr 2009 23:07:01 +0000 |
parents | 0e67e1b7581e |
children | 6543ecbb0717 |
files | libpurple/protocols/jabber/jingle/session.c |
diffstat | 1 files changed, 49 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jingle/session.c Mon Apr 27 17:01:11 2009 +0000 +++ b/libpurple/protocols/jabber/jingle/session.c Mon Apr 27 23:07:01 2009 +0000 @@ -363,17 +363,18 @@ g_hash_table_lookup(js->sessions, sid) : NULL; } +#if GLIB_CHECK_VERSION(2,4,0) static gboolean find_by_jid_ghr(gpointer key, gpointer value, gpointer user_data) { JingleSession *session = (JingleSession *)value; const gchar *jid = user_data; - gboolean use_bare = strchr(jid, '/') == NULL; + gboolean use_bare = g_utf8_strchr(jid, -1, '/') == NULL; gchar *remote_jid = jingle_session_get_remote_jid(session); gchar *cmp_jid = use_bare ? jabber_get_bare_jid(remote_jid) : g_strdup(remote_jid); g_free(remote_jid); - if (!strcmp(jid, cmp_jid)) { + if (g_str_equal(jid, cmp_jid)) { g_free(cmp_jid); return TRUE; } @@ -382,12 +383,58 @@ return FALSE; } +#else /* GLIB_CHECK_VERSION 2.4.0 */ + +/* Ugly code; g_hash_table_find version above is much nicer */ +struct session_find_jid +{ + const gchar *jid; + JingleSession *ret; + gboolean use_bare; +}; + +static void find_by_jid_ghr(gpointer key, gpointer value, gpointer user_data) +{ + JingleSession *session = (JingleSession *)value; + struct session_find_jid *data = user_data; + gchar *remote_jid; + gchar *cmp_jid; + + if (data->ret != NULL) + return; + + remote_jid = jingle_session_get_remote_jid(session); + cmp_jid = data->use_bare ? jabber_get_bare_jid(remote_jid) + : g_strdup(remote_jid); + g_free(remote_jid); + + if (g_str_equal(data->jid, cmp_jid)) + data->ret = session; + + g_free(cmp_jid); +} +#endif /* GLIB_CHECK_VERSION 2.4.0 */ + JingleSession * jingle_session_find_by_jid(JabberStream *js, const gchar *jid) { +#if GLIB_CHECK_VERSION(2,4,0) return js->sessions != NULL ? g_hash_table_find(js->sessions, find_by_jid_ghr, (gpointer)jid) : NULL; +#else + struct session_find_jid data; + + if (js->sessions == NULL) + return NULL; + + data.jid = jid; + data.ret = NULL; + data.use_bare = g_utf8_strchr(jid, -1, '/') == NULL; + + g_hash_table_foreach(js->sessions, find_by_jid_ghr, &data); + return data.ret; +#endif } static xmlnode *