pidgin: e9f99205: Add two helper functions useful for matc...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sat May 23 14:25:37 EDT 2009


-----------------------------------------------------------------
Revision: e9f99205e2aa5bfe910cae91f59b23d9e7d77095
Ancestor: 0ef5f961fe7993b5d80b2c8b067e18fa20bf0126
Author: darkrain42 at pidgin.im
Date: 2009-05-23T17:42:34
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/e9f99205e2aa5bfe910cae91f59b23d9e7d77095

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

ChangeLog: 

Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jutil.c	409fce0ef0ea2655a392592cf6f0803eaa58dc51
+++ libpurple/protocols/jabber/jutil.c	62eb7393041207741c117918064751c3dc1e256a
@@ -223,6 +223,50 @@ const char *jabber_normalize(const Purpl
 	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)
 {
============================================================
--- libpurple/protocols/jabber/jutil.h	32198fa56730eb5a903824d28023404ac9e249de
+++ libpurple/protocols/jabber/jutil.h	3d0bf17240ef675b2db03f57235c2beb0b016159
@@ -36,6 +36,12 @@ const char *jabber_normalize(const Purpl
 
 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 *);


More information about the Commits mailing list