Merged revisions 97489 via svnmerge from
[asterisk/asterisk.git] / channels / chan_gtalk.c
index f67cd6c..05e7de7 100644 (file)
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
 #include <sys/socket.h>
-#include <errno.h>
-#include <stdlib.h>
 #include <fcntl.h>
 #include <netdb.h>
 #include <netinet/in.h>
@@ -53,11 +47,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/lock.h"
 #include "asterisk/channel.h"
 #include "asterisk/config.h"
-#include "asterisk/logger.h"
 #include "asterisk/module.h"
 #include "asterisk/pbx.h"
-#include "asterisk/options.h"
-#include "asterisk/lock.h"
 #include "asterisk/sched.h"
 #include "asterisk/io.h"
 #include "asterisk/rtp.h"
@@ -198,7 +189,7 @@ static int gtalk_get_codec(struct ast_channel *chan);
 static const struct ast_channel_tech gtalk_tech = {
        .type = "Gtalk",
        .description = "Gtalk Channel Driver",
-       .capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1),
+       .capabilities = AST_FORMAT_AUDIO_MASK,
        .requester = gtalk_request,
        .send_digit_begin = gtalk_digit_begin,
        .send_digit_end = gtalk_digit_end,
@@ -436,7 +427,7 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        iks_insert_node(gtalk, transport);
        iks_insert_node(dcodecs, payload_telephone);
 
-       iks_send(client->connection->p, iq);
+       ast_aji_send(client->connection, iq);
        iks_delete(payload_telephone);
        iks_delete(transport);
        iks_delete(dcodecs);
@@ -473,7 +464,7 @@ static int gtalk_invite_response(struct gtalk_pvt *p, char *to , char *from, cha
        iks_insert_attrib(transport, "xmlns", "http://www.google.com/transport/p2p");
        iks_insert_node(iq,session);
        iks_insert_node(session,transport);
-       iks_send(p->parent->connection->p, iq);
+       ast_aji_send(p->parent->connection, iq);
        iks_delete(transport);
        iks_delete(session);
        iks_delete(iq);
@@ -501,6 +492,8 @@ static int gtalk_answer(struct ast_channel *ast)
        ast_debug(1, "Answer!\n");
        ast_mutex_lock(&p->lock);
        gtalk_invite(p, p->them, p->us,p->sid, 0);
+       manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", "Channel: %s\r\nChanneltype: %s\r\nGtalk-SID: %s\r\n",
+               ast->name, "GTALK", p->sid);
        ast_mutex_unlock(&p->lock);
        return res;
 }
@@ -570,7 +563,7 @@ static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const c
                                iks_insert_node(response, error);
                        }
                }
-               iks_send(client->connection->p, response);
+               ast_aji_send(client->connection, response);
                if (reason)
                        iks_delete(reason);
                if (error)
@@ -830,7 +823,7 @@ static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, ch
                        iks_insert_attrib(candidate, "type", "relay");
                iks_insert_attrib(candidate, "network", "0");
                iks_insert_attrib(candidate, "generation", "0");
-               iks_send(c->p, iq);
+               ast_aji_send(c, iq);
        }
        p->laststun = 0;
 
@@ -903,6 +896,9 @@ static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const
                return NULL;
        }
 
+       /* Set CALLERID(name) to the full JID of the remote peer */
+       ast_copy_string(tmp->cid_name, tmp->them, sizeof(tmp->cid_name));
+
        if(strchr(tmp->us, '/')) {
                data = ast_strdupa(tmp->us);
                exten = strsep(&data, "/");
@@ -924,7 +920,6 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
        int fmt;
        int what;
        const char *n2;
-       char *data = NULL, *cid = NULL;
 
        if (title)
                n2 = title;
@@ -988,20 +983,7 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
        ast_module_ref(ast_module_info->self);
        ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
        ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
-       /* Don't use ast_set_callerid() here because it will
-        * generate a needless NewCallerID event */
-       if (!strcasecmp(client->name, "guest")) {
-               data = ast_strdupa(i->them);
-               if (strchr(data, '/')) {
-                       cid = strsep(&data, "/");
-               } else
-                       cid = data;
-       } else {
-               data =  ast_strdupa(client->user);
-               cid = data;
-       }
-       cid = strsep(&cid, "@");
-       tmp->cid.cid_ani = ast_strdup(cid);
+
        if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
                tmp->cid.cid_dnid = ast_strdup(i->exten);
        tmp->priority = 1;
@@ -1012,8 +994,11 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
                tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
                ast_hangup(tmp);
                tmp = NULL;
+       } else {
+               manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate",
+                       "Channel: %s\r\nChanneltype: %s\r\nGtalk-SID: %s\r\n",
+                       i->owner ? i->owner->name : "", "Gtalk", i->sid);
        }
-
        return tmp;
 }
 
@@ -1036,7 +1021,7 @@ static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *a
                        iks_insert_attrib(session, "initiator", p->initiator ? p->us : p->them);
                        iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
                        iks_insert_node(request, session);
-                       iks_send(client->connection->p, request);
+                       ast_aji_send(client->connection, request);
                        iks_delete(session);
                        res = 0;
                }
@@ -1274,7 +1259,7 @@ static int gtalk_add_candidate(struct gtalk *client, ikspak *pak)
        iks_insert_attrib(receipt, "from", from);
        iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
        iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
-       iks_send(c->p, receipt);
+       ast_aji_send(c, receipt);
        iks_delete(receipt);
 
        return 1;
@@ -1447,7 +1432,7 @@ static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duratio
        } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END || duration != 0) {
                iks_insert_attrib(dtmf, "action", "button-up");
        }
-       iks_send(client->connection->p, iq);
+       ast_aji_send(client->connection, iq);
        iks_delete(iq);
        iks_delete(gtalk);
        iks_delete(dtmf);