Do not link the guest account with any configured XMPP client (in
authorPhilippe Sultan <philippe.sultan@gmail.com>
Mon, 2 Jun 2008 14:35:24 +0000 (14:35 +0000)
committerPhilippe Sultan <philippe.sultan@gmail.com>
Mon, 2 Jun 2008 14:35:24 +0000 (14:35 +0000)
jabber.conf). The actual connection is made when a call comes in
Asterisk.

Apply this fix to Jingle too.

Fix the ast_aji_get_client function that was not able to retrieve an
XMPP client from its JID.

(closes issue #12085)
Reported by: junky
Tested by: phsultan

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@119741 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_gtalk.c
channels/chan_jingle.c
res/res_jabber.c

index 90b2cde..f8b038b 100644 (file)
@@ -251,17 +251,12 @@ static struct gtalk *find_gtalk(char *name, char *connection)
        if (!gtalk && strchr(name, '@'))
                gtalk = ASTOBJ_CONTAINER_FIND_FULL(&gtalk_list, name, user,,, strcasecmp);
 
-       if (!gtalk) {                           /* guest call */
+       if (!gtalk) {                           
+               /* guest call */
                ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
                        ASTOBJ_RDLOCK(iterator);
                        if (!strcasecmp(iterator->name, "guest")) {
-                               if (!strcasecmp(iterator->connection->jid->partial, connection)) {
-                                       gtalk = iterator;
-                               } else if (!strcasecmp(iterator->connection->name, connection)) {
-                                       gtalk = iterator;
-                               } else if (iterator->connection->component && !strcasecmp(iterator->connection->user,domain)) {
-                                       gtalk = iterator;
-                               }
+                               gtalk = iterator;
                        }
                        ASTOBJ_UNLOCK(iterator);
 
@@ -1142,6 +1137,16 @@ static int gtalk_newcall(struct gtalk *client, ikspak *pak)
                tmp = tmp->next;
        }
 
+       if (!strcasecmp(client->name, "guest")){
+               /* the guest account is not tied to any configured XMPP client,
+                  let's set it now */
+               client->connection = ast_aji_get_client(from);
+               if (!client->connection) {
+                       ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", from);
+                       return -1;
+               }
+       }
+
        p = gtalk_alloc(client, from, pak->from->full, iks_find_attrib(pak->query, "id"));
        if (!p) {
                ast_log(LOG_WARNING, "Unable to allocate gtalk structure!\n");
@@ -1602,11 +1607,22 @@ static struct ast_channel *gtalk_request(const char *type, int format, void *dat
                        }
                }
        }
+
        client = find_gtalk(to, sender);
        if (!client) {
                ast_log(LOG_WARNING, "Could not find recipient.\n");
                return NULL;
        }
+       if (!strcasecmp(client->name, "guest")){
+               /* the guest account is not tied to any configured XMPP client,
+                  let's set it now */
+               client->connection = ast_aji_get_client(sender);
+               if (!client->connection) {
+                       ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", sender);
+                       return NULL;
+               }
+       }
+       
        ASTOBJ_WRLOCK(client);
        p = gtalk_alloc(client, strchr(sender, '@') ? sender : client->connection->jid->full, strchr(to, '@') ? to : client->user, NULL);
        if (p)
@@ -1937,13 +1953,13 @@ static int gtalk_load_config(void)
                                        ASTOBJ_CONTAINER_TRAVERSE(clients, 1, {
                                                ASTOBJ_WRLOCK(iterator);
                                                ASTOBJ_WRLOCK(member);
-                                               member->connection = iterator;
+                                               member->connection = NULL;
                                                iks_filter_add_rule(iterator->f, gtalk_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
                                                iks_filter_add_rule(iterator->f, gtalk_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, "http://jabber.org/protocol/gtalk", IKS_RULE_DONE);
                                                ASTOBJ_UNLOCK(member);
-                                               ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
                                                ASTOBJ_UNLOCK(iterator);
                                        });
+                                       ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
                                } else {
                                        ASTOBJ_UNLOCK(member);
                                        ASTOBJ_UNREF(member, gtalk_member_destroy);
index 372ebe3..107db08 100644 (file)
@@ -248,15 +248,12 @@ static struct jingle *find_jingle(char *name, char *connection)
        if (!jingle && strchr(name, '@'))
                jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingle_list, name, user,,, strcasecmp);
 
-       if (!jingle) {                          /* guest call */
+       if (!jingle) {                          
+               /* guest call */
                ASTOBJ_CONTAINER_TRAVERSE(&jingle_list, 1, {
                        ASTOBJ_RDLOCK(iterator);
                        if (!strcasecmp(iterator->name, "guest")) {
-                               if (!strcasecmp(iterator->connection->jid->partial, connection)) {
-                                       jingle = iterator;
-                               } else if (!strcasecmp(iterator->connection->name, connection)) {
-                                       jingle = iterator;
-                               }
+                               jingle = iterator;
                        }
                        ASTOBJ_UNLOCK(iterator);
 
@@ -959,8 +956,13 @@ static int jingle_newcall(struct jingle *client, ikspak *pak)
        struct ast_channel *chan;
        int res;
        iks *codec, *content, *description;
+       char *from = NULL;
 
        /* Make sure our new call doesn't exist yet */
+       from = iks_find_attrib(pak->x,"to");
+       if(!from)
+               from = client->connection->jid->full;
+
        while (tmp) {
                if (iks_find_with_attrib(pak->x, JINGLE_NODE, JINGLE_SID, tmp->sid)) {
                        ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
@@ -970,6 +972,16 @@ static int jingle_newcall(struct jingle *client, ikspak *pak)
                tmp = tmp->next;
        }
 
+       if (!strcasecmp(client->name, "guest")){
+               /* the guest account is not tied to any configured XMPP client,
+                  let's set it now */
+               client->connection = ast_aji_get_client(from);
+               if (!client->connection) {
+                       ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", from);
+                       return -1;
+               }
+       }
+
        p = jingle_alloc(client, pak->from->partial, iks_find_attrib(pak->query, JINGLE_SID));
        if (!p) {
                ast_log(LOG_WARNING, "Unable to allocate jingle structure!\n");
@@ -1471,11 +1483,22 @@ static struct ast_channel *jingle_request(const char *type, int format, void *da
                        }
                }
        }
+
        client = find_jingle(to, sender);
        if (!client) {
                ast_log(LOG_WARNING, "Could not find recipient.\n");
                return NULL;
        }
+       if (!strcasecmp(client->name, "guest")){
+               /* the guest account is not tied to any configured XMPP client,
+                  let's set it now */
+               client->connection = ast_aji_get_client(sender);
+               if (!client->connection) {
+                       ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", sender);
+                       return NULL;
+               }
+       }
+       
        ASTOBJ_WRLOCK(client);
        p = jingle_alloc(client, to, NULL);
        if (p)
@@ -1797,13 +1820,13 @@ static int jingle_load_config(void)
                                        ASTOBJ_CONTAINER_TRAVERSE(clients, 1, {
                                                ASTOBJ_WRLOCK(iterator);
                                                ASTOBJ_WRLOCK(member);
-                                               member->connection = iterator;
+                                               member->connection = NULL;
                                                iks_filter_add_rule(iterator->f, jingle_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, JINGLE_NS, IKS_RULE_DONE);
                                                iks_filter_add_rule(iterator->f, jingle_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, JINGLE_DTMF_NS, IKS_RULE_DONE);
                                                ASTOBJ_UNLOCK(member);
-                                               ASTOBJ_CONTAINER_LINK(&jingle_list, member);
                                                ASTOBJ_UNLOCK(iterator);
                                        });
+                                       ASTOBJ_CONTAINER_LINK(&jingle_list, member);
                                } else {
                                        ASTOBJ_UNLOCK(member);
                                        ASTOBJ_UNREF(member, jingle_member_destroy);
index 653537d..20189c7 100644 (file)
@@ -2884,17 +2884,30 @@ static int aji_load_config(int reload)
 }
 
 /*!
- * \brief grab a aji_client structure by label name.
- * \param name label name 
+ * \brief grab a aji_client structure by label name or JID 
+ * (without the resource string)
+ * \param name label or JID 
  * \return aji_client.
  */
 struct aji_client *ast_aji_get_client(const char *name)
 {
        struct aji_client *client = NULL;
+       char *aux = NULL;
 
        client = ASTOBJ_CONTAINER_FIND(&clients, name);
-       if (!client && !strchr(name, '@'))
-               client = ASTOBJ_CONTAINER_FIND_FULL(&clients, name, user,,, strcasecmp);
+       if (!client && strchr(name, '@')) {
+               ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
+                       aux = ast_strdupa(iterator->user);
+                       if (strchr(aux, '/')) {
+                               /* strip resource for comparison */
+                               aux = strsep(&aux, "/");
+                       }
+                       if (!strcasecmp(aux, name)) {
+                               client = iterator;
+                       }                               
+               });
+       }
+
        return client;
 }