# HG changeset patch # User Paul Aurich # Date 1243100554 0 # Node ID e8795ced8c9b643e1fdfa4fe0ef7711446832847 # Parent e40a30c883cc0cf907853af4c622eaefc40df847 Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account. diff -r e40a30c883cc -r e8795ced8c9b libpurple/protocols/jabber/jutil.c --- a/libpurple/protocols/jabber/jutil.c Sat May 23 07:08:00 2009 +0000 +++ b/libpurple/protocols/jabber/jutil.c Sat May 23 17:42:34 2009 +0000 @@ -223,6 +223,50 @@ return buf; } +gboolean +jabber_is_own_server(JabberStream *js, const char *str) +{ + JabberID *jid; + gboolean equal; + + if (str == NULL) + return FALSE; + + g_return_val_if_fail(*str != '\0', FALSE); + + jid = jabber_id_new(str); + if (!jid) + return FALSE; + + equal = (jid->node == NULL && + g_str_equal(jid->domain, js->user->domain) && + jid->resource == NULL); + jabber_id_free(jid); + return equal; +} + +gboolean +jabber_is_own_account(JabberStream *js, const char *str) +{ + JabberID *jid; + gboolean equal; + + if (str == NULL) + return TRUE; + + g_return_val_if_fail(*str != '\0', FALSE); + + jid = jabber_id_new(str); + if (!jid) + return FALSE; + + equal = (g_str_equal(jid->node, js->user->node) && + g_str_equal(jid->domain, js->user->domain) && + jid->resource == NULL); + jabber_id_free(jid); + return equal; +} + PurpleConversation * jabber_find_unnormalized_conv(const char *name, PurpleAccount *account) { diff -r e40a30c883cc -r e8795ced8c9b libpurple/protocols/jabber/jutil.h --- a/libpurple/protocols/jabber/jutil.h Sat May 23 07:08:00 2009 +0000 +++ b/libpurple/protocols/jabber/jutil.h Sat May 23 17:42:34 2009 +0000 @@ -36,6 +36,12 @@ const char *jabber_normalize(const PurpleAccount *account, const char *in); +/* Returns true if JID is the bare JID of our server. */ +gboolean jabber_is_own_server(JabberStream *js, const char *jid); + +/* Returns true if JID is the bare JID of our account. */ +gboolean jabber_is_own_account(JabberStream *js, const char *jid); + gboolean jabber_nodeprep_validate(const char *); gboolean jabber_nameprep_validate(const char *); gboolean jabber_resourceprep_validate(const char *);