]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
doh
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 Mar 2007 17:31:47 +0000 (17:31 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 Mar 2007 17:31:47 +0000 (17:31 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4812 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/libdingaling/src/libdingaling.c
libs/libdingaling/src/libdingaling.h

index 55e76a4263bad859d0b585297692fe3a06a01652..c26df29807b1818b56d171fa84855a9542f42fcf 100644 (file)
@@ -761,6 +761,11 @@ static void do_presence(ldl_handle_t *handle, char *from, char *to, char *type,
                from = buf;
        }
 
+       if (ldl_test_flag(handle, LDL_FLAG_COMPONENT) && ldl_jid_domcmp(from, to)) {
+               globals.logger(DL_LOG_ERR, "Refusal to send presence from and to the same domain in component mode [%s][%s]\n", from, to);
+               return;
+       }
+
        if ((pres = iks_new("presence"))) {
                iks_insert_attrib(pres, "xmlns", "jabber:client");
                if (from) {
index 47dc8b989d58ee6361484e2899a63282632dc574..dd1b3b43a1b7501063369264e00454671899ac92 100644 (file)
@@ -179,6 +179,55 @@ typedef void (*ldl_logger_t)(char *file, const char *func, int line, int level,
 
 #define ldl_yield(ms) apr_sleep(ms * 10); apr_thread_yield();
 
+/*!
+  \brief Test for a common domain in 2 jid
+  \param id_a the first id
+  \param id_b the second id
+  \return 1 if the domains match 0 if they dont or -1 if either id is invalid
+  \note the id may or may not contain a user and/or resource
+*/
+static inline int ldl_jid_domcmp(char *id_a, char *id_b)
+{
+    char *id_a_host, *id_b_host, *id_a_r, *id_b_r;
+
+       if ((id_a_host = strchr(id_a, '@'))) {
+               id_a_host++;
+       } else {
+               id_a_host = id_a;
+       }
+
+       if ((id_b_host = strchr(id_b, '@'))) {
+               id_b_host++;
+       } else {
+               id_b_host = id_b;
+       }
+
+    if (id_a_host && id_b_host) {
+        int id_a_len = 0, id_b_len = 0, len = 0;
+
+        if ((id_a_r = strchr(id_a_host, '/'))) {
+            id_a_len = id_a_r - id_a_host;
+        } else {
+            id_a_len = strlen(id_a_host);
+        }
+
+        if ((id_b_r = strchr(id_b_host, '/'))) {
+            id_b_len = id_b_r - id_b_host;
+        } else {
+            id_b_len = strlen(id_b_host);
+        }
+
+        if (id_a_len > id_b_len) {
+            len = id_b_len;
+        } else {
+            len = id_a_len;
+        }
+               printf("[%s][%s][%d]\n", id_a_host, id_b_host, len);
+        return strncasecmp(id_a_host, id_b_host, len) ? 0 : 1;
+    }
+    return -1;
+}
+
 /*!
   \brief Test for the existance of a flag on an arbitary object
   \param obj the object to test