include "logger.h" and errno.h from asterisk.h - usage shows that they
[asterisk/asterisk.git] / channels / chan_gtalk.c
index a67df2c..e28684e 100644 (file)
 /*** MODULEINFO
        <depend>iksemel</depend>
        <depend>res_jabber</depend>
-       <use>gnutls</use>
+       <use>openssl</use>
  ***/
 
 #include "asterisk.h"
 
 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>
@@ -50,19 +44,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include <iksemel.h>
 #include <pthread.h>
 
-#ifdef HAVE_GNUTLS
-#include <gcrypt.h>
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
-#endif /* HAVE_GNUTLS */
-
 #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"
@@ -191,8 +178,8 @@ static int gtalk_indicate(struct ast_channel *ast, int condition, const void *da
 static int gtalk_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 static int gtalk_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
 static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid);
-static int gtalk_do_reload(int fd, int argc, char **argv);
-static int gtalk_show_channels(int fd, int argc, char **argv);
+static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 /*----- RTP interface functions */
 static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
                                                           struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
@@ -203,7 +190,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,
@@ -226,7 +213,6 @@ static struct sched_context *sched; /*!< The scheduling context */
 static struct io_context *io;  /*!< The IO context */
 static struct in_addr __ourip;
 
-
 /*! \brief RTP driver interface */
 static struct ast_rtp_protocol gtalk_rtp = {
        type: "Gtalk",
@@ -235,21 +221,10 @@ static struct ast_rtp_protocol gtalk_rtp = {
        get_codec: gtalk_get_codec,
 };
 
-static const char debug_usage[] = 
-"Usage: gtalk show channels\n" 
-"       Shows current state of the Gtalk channels.\n";
-
-static const char reload_usage[] = 
-"Usage: gtalk reload\n" 
-"       Reload gtalk channel driver.\n";
-
-
 static struct ast_cli_entry gtalk_cli[] = {
-       {{ "gtalk", "reload", NULL}, gtalk_do_reload, "Enable Jabber debugging", reload_usage },
-       {{ "gtalk", "show", "channels", NULL}, gtalk_show_channels, "Show GoogleTalk Channels", debug_usage },
- };
-
-
+       AST_CLI_DEFINE(gtalk_do_reload, "Reload GoogleTalk configuration"),
+       AST_CLI_DEFINE(gtalk_show_channels, "Show GoogleTalk channels"),
+};
 
 static char externip[16];
 
@@ -265,7 +240,7 @@ static struct gtalk *find_gtalk(char *name, char *connection)
        struct gtalk *gtalk = NULL;
        char *domain = NULL , *s = NULL;
 
-       if(strchr(connection, '@')) {
+       if (strchr(connection, '@')) {
                s = ast_strdupa(connection);
                domain = strsep(&s, "@");
                ast_verbose("OOOOH domain = %s\n", domain);
@@ -453,7 +428,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);
@@ -490,7 +465,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);
@@ -587,7 +562,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)
@@ -847,7 +822,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;
 
@@ -1053,7 +1028,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;
                }
@@ -1227,9 +1202,6 @@ static int gtalk_add_candidate(struct gtalk *client, ikspak *pak)
        if(!from)
                from = c->jid->full;
 
-       newcandidate = ast_calloc(1, sizeof(*newcandidate));
-       if (!newcandidate)
-               return 0;
        for (tmp = client->p; tmp; tmp = tmp->next) {
                if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
                        p = tmp;
@@ -1294,7 +1266,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;
@@ -1467,7 +1439,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);
@@ -1581,7 +1553,7 @@ static struct ast_channel *gtalk_request(const char *type, int format, void *dat
 }
 
 /*! \brief CLI command "gtalk show channels" */
-static int gtalk_show_channels(int fd, int argc, char **argv)
+static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 #define FORMAT  "%-30.30s  %-30.30s  %-15.15s  %-5.5s %-5.5s \n"
        struct gtalk_pvt *p;
@@ -1591,11 +1563,22 @@ static int gtalk_show_channels(int fd, int argc, char **argv)
        char *jid = NULL;
        char *resource = NULL;
 
-       if (argc != 3)
-               return RESULT_SHOWUSAGE;
+       switch (cmd) {
+       case CLI_INIT:
+               e->command = "gtalk show channels";
+               e->usage =
+                       "Usage: gtalk show channels\n"
+                       "       Shows current state of the Gtalk channels.\n";
+               return NULL;
+       case CLI_GENERATE:
+               return NULL;
+       }
+
+       if (a->argc != 3)
+               return CLI_SHOWUSAGE;
 
        ast_mutex_lock(&gtalklock);
-       ast_cli(fd, FORMAT, "Channel", "Jabber ID", "Resource", "Read", "Write");
+       ast_cli(a->fd, FORMAT, "Channel", "Jabber ID", "Resource", "Read", "Write");
        ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
                ASTOBJ_WRLOCK(iterator);
                p = iterator->p;
@@ -1611,7 +1594,7 @@ static int gtalk_show_channels(int fd, int argc, char **argv)
                                resource ++;
                        }
                        if (chan)
-                               ast_cli(fd, FORMAT, 
+                               ast_cli(a->fd, FORMAT, 
                                        chan->name,
                                        jid,
                                        resource,
@@ -1628,16 +1611,27 @@ static int gtalk_show_channels(int fd, int argc, char **argv)
 
        ast_mutex_unlock(&gtalklock);
 
-       ast_cli(fd, "%d active gtalk channel%s\n", numchans, (numchans != 1) ? "s" : "");
-       return RESULT_SUCCESS;
+       ast_cli(a->fd, "%d active gtalk channel%s\n", numchans, (numchans != 1) ? "s" : "");
+       return CLI_SUCCESS;
 #undef FORMAT
 }
 
-/*! \brief CLI command "gtalk show channels" */
-static int gtalk_do_reload(int fd, int argc, char **argv)
+/*! \brief CLI command "gtalk reload" */
+static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+       switch (cmd) {
+       case CLI_INIT:
+               e->command = "gtalk reload";
+               e->usage =
+                       "Usage: gtalk reload\n"
+                       "       Reload gtalk channel driver.\n";
+               return NULL;
+       case CLI_GENERATE:
+               return NULL;
+       }       
+       
        ast_verbose("IT DOES WORK!\n");
-       return RESULT_SUCCESS;
+       return CLI_SUCCESS;
 }
 
 static int gtalk_parser(void *data, ikspak *pak)
@@ -1894,10 +1888,6 @@ static int gtalk_load_config(void)
 /*! \brief Load module into PBX, register channel */
 static int load_module(void)
 {
-#ifdef HAVE_GNUTLS     
-        gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
-#endif /* HAVE_GNUTLS */
-
        ASTOBJ_CONTAINER_INIT(&gtalk_list);
        if (!gtalk_load_config()) {
                ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", GOOGLE_CONFIG);