Sat Mar 26 11:06:57 2011

Asterisk developer's documentation


chan_gtalk.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Matt O'Gorman <mogorman@digium.com>
00007  * Philippe Sultan <philippe.sultan@gmail.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*! \file
00021  *
00022  * \author Matt O'Gorman <mogorman@digium.com>
00023  * \author Philippe Sultan <philippe.sultan@gmail.com>
00024  *
00025  * \brief Gtalk Channel Driver, until google/libjingle works with jingle spec
00026  *
00027  * \ingroup channel_drivers
00028  *
00029  * ********** General TODO:s
00030  * \todo Support config reloading.
00031  * \todo Fix native bridging.
00032  */
00033 
00034 /*** MODULEINFO
00035    <depend>iksemel</depend>
00036    <depend>res_jabber</depend>
00037    <use>openssl</use>
00038  ***/
00039 
00040 
00041 #include "asterisk.h"
00042 
00043 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 291827 $")
00044 
00045 #include <sys/socket.h>
00046 #include <fcntl.h>
00047 #include <netdb.h>
00048 #include <netinet/in.h>
00049 #include <arpa/inet.h>
00050 #include <sys/signal.h>
00051 #include <iksemel.h>
00052 #include <pthread.h>
00053 #include <ctype.h>
00054 
00055 #include "asterisk/lock.h"
00056 #include "asterisk/channel.h"
00057 #include "asterisk/config.h"
00058 #include "asterisk/module.h"
00059 #include "asterisk/pbx.h"
00060 #include "asterisk/sched.h"
00061 #include "asterisk/io.h"
00062 #include "asterisk/rtp_engine.h"
00063 #include "asterisk/stun.h"
00064 #include "asterisk/acl.h"
00065 #include "asterisk/callerid.h"
00066 #include "asterisk/file.h"
00067 #include "asterisk/cli.h"
00068 #include "asterisk/app.h"
00069 #include "asterisk/musiconhold.h"
00070 #include "asterisk/manager.h"
00071 #include "asterisk/stringfields.h"
00072 #include "asterisk/utils.h"
00073 #include "asterisk/causes.h"
00074 #include "asterisk/astobj.h"
00075 #include "asterisk/abstract_jb.h"
00076 #include "asterisk/jabber.h"
00077 #include "asterisk/jingle.h"
00078 
00079 #define GOOGLE_CONFIG "gtalk.conf"
00080 
00081 /*! Global jitterbuffer configuration - by default, jb is disabled */
00082 static struct ast_jb_conf default_jbconf =
00083 {
00084    .flags = 0,
00085    .max_size = -1,
00086    .resync_threshold = -1,
00087    .impl = "",
00088    .target_extra = -1,
00089 };
00090 static struct ast_jb_conf global_jbconf;
00091 
00092 enum gtalk_protocol {
00093    AJI_PROTOCOL_UDP = 1,
00094    AJI_PROTOCOL_SSLTCP = 2,
00095 };
00096 
00097 enum gtalk_connect_type {
00098    AJI_CONNECT_STUN = 1,
00099    AJI_CONNECT_LOCAL = 2,
00100    AJI_CONNECT_RELAY = 3,
00101 };
00102 
00103 struct gtalk_pvt {
00104    ast_mutex_t lock;                /*!< Channel private lock */
00105    time_t laststun;
00106    struct gtalk *parent;            /*!< Parent client */
00107    char sid[100];
00108    char us[AJI_MAX_JIDLEN];
00109    char them[AJI_MAX_JIDLEN];
00110    char ring[10];                   /*!< Message ID of ring */
00111    iksrule *ringrule;               /*!< Rule for matching RING request */
00112    int initiator;                   /*!< If we're the initiator */
00113    int alreadygone;
00114    int capability;
00115    struct ast_codec_pref prefs;
00116    struct gtalk_candidate *theircandidates;
00117    struct gtalk_candidate *ourcandidates;
00118    char cid_num[80];                /*!< Caller ID num */
00119    char cid_name[80];               /*!< Caller ID name */
00120    char exten[80];                  /*!< Called extension */
00121    struct ast_channel *owner;       /*!< Master Channel */
00122    struct ast_rtp_instance *rtp;             /*!< RTP audio session */
00123    struct ast_rtp_instance *vrtp;            /*!< RTP video session */
00124    format_t jointcapability;             /*!< Supported capability at both ends (codecs ) */
00125    format_t peercapability;
00126    struct gtalk_pvt *next; /* Next entity */
00127 };
00128 
00129 struct gtalk_candidate {
00130    char name[100];
00131    enum gtalk_protocol protocol;
00132    double preference;
00133    char username[100];
00134    char password[100];
00135    enum gtalk_connect_type type;
00136    char network[6];
00137    int generation;
00138    char ip[16];
00139    int port;
00140    int receipt;
00141    struct gtalk_candidate *next;
00142 };
00143 
00144 struct gtalk {
00145    ASTOBJ_COMPONENTS(struct gtalk);
00146    struct aji_client *connection;
00147    struct aji_buddy *buddy;
00148    struct gtalk_pvt *p;
00149    struct ast_codec_pref prefs;
00150    int amaflags;        /*!< AMA Flags */
00151    char user[AJI_MAX_JIDLEN];
00152    char context[AST_MAX_CONTEXT];
00153    char parkinglot[AST_MAX_CONTEXT];   /*!<  Parkinglot */
00154    char accountcode[AST_MAX_ACCOUNT_CODE];   /*!< Account code */
00155    format_t capability;
00156    ast_group_t callgroup;  /*!< Call group */
00157    ast_group_t pickupgroup;   /*!< Pickup group */
00158    int callingpres;     /*!< Calling presentation */
00159    int allowguest;
00160    char language[MAX_LANGUAGE];  /*!<  Default language for prompts */
00161    char musicclass[MAX_MUSICCLASS]; /*!<  Music on Hold class */
00162 };
00163 
00164 struct gtalk_container {
00165    ASTOBJ_CONTAINER_COMPONENTS(struct gtalk);
00166 };
00167 
00168 static const char desc[] = "Gtalk Channel";
00169 
00170 static format_t global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
00171 
00172 AST_MUTEX_DEFINE_STATIC(gtalklock); /*!< Protect the interface list (of gtalk_pvt's) */
00173 
00174 /* Forward declarations */
00175 static struct ast_channel *gtalk_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
00176 /*static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duration);*/
00177 static int gtalk_sendtext(struct ast_channel *ast, const char *text);
00178 static int gtalk_digit_begin(struct ast_channel *ast, char digit);
00179 static int gtalk_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
00180 static int gtalk_call(struct ast_channel *ast, char *dest, int timeout);
00181 static int gtalk_hangup(struct ast_channel *ast);
00182 static int gtalk_answer(struct ast_channel *ast);
00183 static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *action);
00184 static void gtalk_free_pvt(struct gtalk *client, struct gtalk_pvt *p);
00185 static int gtalk_newcall(struct gtalk *client, ikspak *pak);
00186 static struct ast_frame *gtalk_read(struct ast_channel *ast);
00187 static int gtalk_write(struct ast_channel *ast, struct ast_frame *f);
00188 static int gtalk_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
00189 static int gtalk_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
00190 static int gtalk_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
00191 static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid);
00192 static int gtalk_update_stun(struct gtalk *client, struct gtalk_pvt *p);
00193 /* static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); */
00194 static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
00195 static int gtalk_update_externip(void);
00196 
00197 /*! \brief PBX interface structure for channel registration */
00198 static const struct ast_channel_tech gtalk_tech = {
00199    .type = "Gtalk",
00200    .description = "Gtalk Channel Driver",
00201    .capabilities = AST_FORMAT_AUDIO_MASK,
00202    .requester = gtalk_request,
00203    .send_text = gtalk_sendtext,
00204    .send_digit_begin = gtalk_digit_begin,
00205    .send_digit_end = gtalk_digit_end,
00206    /* XXX TODO native bridging is causing odd problems with DTMF pass-through with
00207     * the gtalk servers. Enable native bridging once the source of this problem has
00208     * been identified.
00209    .bridge = ast_rtp_instance_bridge, */
00210    .call = gtalk_call,
00211    .hangup = gtalk_hangup,
00212    .answer = gtalk_answer,
00213    .read = gtalk_read,
00214    .write = gtalk_write,
00215    .exception = gtalk_read,
00216    .indicate = gtalk_indicate,
00217    .fixup = gtalk_fixup,
00218    .send_html = gtalk_sendhtml,
00219    .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER
00220 };
00221 
00222 static struct sockaddr_in bindaddr = { 0, }; /*!< The address we bind to */
00223 
00224 static struct sched_context *sched; /*!< The scheduling context */
00225 static struct io_context *io; /*!< The IO context */
00226 static struct in_addr __ourip;
00227 
00228 static struct ast_cli_entry gtalk_cli[] = {
00229 /* AST_CLI_DEFINE(gtalk_do_reload, "Reload GoogleTalk configuration"), XXX TODO reloads are not possible yet. */
00230    AST_CLI_DEFINE(gtalk_show_channels, "Show GoogleTalk channels"),
00231 };
00232 
00233 static char externip[16];
00234 static struct sockaddr_in stunaddr; /*!< the stun server we get the externip from */
00235 
00236 static struct gtalk_container gtalk_list;
00237 
00238 static void gtalk_member_destroy(struct gtalk *obj)
00239 {
00240    ast_free(obj);
00241 }
00242 
00243 static struct gtalk *find_gtalk(char *name, char *connection)
00244 {
00245    struct gtalk *gtalk = NULL;
00246    char *domain = NULL , *s = NULL;
00247 
00248    if (strchr(connection, '@')) {
00249       s = ast_strdupa(connection);
00250       domain = strsep(&s, "@");
00251       ast_verbose("OOOOH domain = %s\n", domain);
00252    }
00253    gtalk = ASTOBJ_CONTAINER_FIND(&gtalk_list, name);
00254    if (!gtalk && strchr(name, '@'))
00255       gtalk = ASTOBJ_CONTAINER_FIND_FULL(&gtalk_list, name, user,,, strcasecmp);
00256 
00257    if (!gtalk) {
00258       /* guest call */
00259       ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
00260          ASTOBJ_RDLOCK(iterator);
00261          if (!strcasecmp(iterator->name, "guest")) {
00262             gtalk = iterator;
00263          }
00264          ASTOBJ_UNLOCK(iterator);
00265 
00266          if (gtalk)
00267             break;
00268       });
00269 
00270    }
00271    return gtalk;
00272 }
00273 
00274 
00275 static int add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodecs)
00276 {
00277    int res = 0;
00278    char *format = ast_getformatname(codec);
00279 
00280    if (!strcasecmp("ulaw", format)) {
00281       iks *payload_eg711u, *payload_pcmu;
00282       payload_pcmu = iks_new("payload-type");
00283       payload_eg711u = iks_new("payload-type");
00284 
00285       if(!payload_eg711u || !payload_pcmu) {
00286          iks_delete(payload_pcmu);
00287          iks_delete(payload_eg711u);
00288          ast_log(LOG_WARNING,"Failed to allocate iks node");
00289          return -1;
00290       }
00291       iks_insert_attrib(payload_pcmu, "id", "0");
00292       iks_insert_attrib(payload_pcmu, "name", "PCMU");
00293       iks_insert_attrib(payload_pcmu, "clockrate","8000");
00294       iks_insert_attrib(payload_pcmu, "bitrate","64000");
00295       iks_insert_attrib(payload_eg711u, "id", "100");
00296       iks_insert_attrib(payload_eg711u, "name", "EG711U");
00297       iks_insert_attrib(payload_eg711u, "clockrate","8000");
00298       iks_insert_attrib(payload_eg711u, "bitrate","64000");
00299       iks_insert_node(dcodecs, payload_pcmu);
00300       iks_insert_node(dcodecs, payload_eg711u);
00301       res ++;
00302    }
00303    if (!strcasecmp("alaw", format)) {
00304       iks *payload_eg711a, *payload_pcma;
00305       payload_pcma = iks_new("payload-type");
00306       payload_eg711a = iks_new("payload-type");
00307       if(!payload_eg711a || !payload_pcma) {
00308          iks_delete(payload_eg711a);
00309          iks_delete(payload_pcma);
00310          ast_log(LOG_WARNING,"Failed to allocate iks node");
00311          return -1;
00312       }
00313       iks_insert_attrib(payload_pcma, "id", "8");
00314       iks_insert_attrib(payload_pcma, "name", "PCMA");
00315       iks_insert_attrib(payload_pcma, "clockrate","8000");
00316       iks_insert_attrib(payload_pcma, "bitrate","64000");
00317       payload_eg711a = iks_new("payload-type");
00318       iks_insert_attrib(payload_eg711a, "id", "101");
00319       iks_insert_attrib(payload_eg711a, "name", "EG711A");
00320       iks_insert_attrib(payload_eg711a, "clockrate","8000");
00321       iks_insert_attrib(payload_eg711a, "bitrate","64000");
00322       iks_insert_node(dcodecs, payload_pcma);
00323       iks_insert_node(dcodecs, payload_eg711a);
00324       res ++;
00325    }
00326    if (!strcasecmp("ilbc", format)) {
00327       iks *payload_ilbc = iks_new("payload-type");
00328       if(!payload_ilbc) {
00329          ast_log(LOG_WARNING,"Failed to allocate iks node");
00330          return -1;
00331       }
00332       iks_insert_attrib(payload_ilbc, "id", "97");
00333       iks_insert_attrib(payload_ilbc, "name", "iLBC");
00334       iks_insert_attrib(payload_ilbc, "clockrate","8000");
00335       iks_insert_attrib(payload_ilbc, "bitrate","13300");
00336       iks_insert_node(dcodecs, payload_ilbc);
00337       res ++;
00338    }
00339    if (!strcasecmp("g723", format)) {
00340       iks *payload_g723 = iks_new("payload-type");
00341       if(!payload_g723) {
00342          ast_log(LOG_WARNING,"Failed to allocate iks node");
00343          return -1;
00344       }
00345       iks_insert_attrib(payload_g723, "id", "4");
00346       iks_insert_attrib(payload_g723, "name", "G723");
00347       iks_insert_attrib(payload_g723, "clockrate","8000");
00348       iks_insert_attrib(payload_g723, "bitrate","6300");
00349       iks_insert_node(dcodecs, payload_g723);
00350       res ++;
00351    }
00352    if (!strcasecmp("speex", format)) {
00353       iks *payload_speex = iks_new("payload-type");
00354       if(!payload_speex) {
00355          ast_log(LOG_WARNING,"Failed to allocate iks node");
00356          return -1;
00357       }
00358       iks_insert_attrib(payload_speex, "id", "110");
00359       iks_insert_attrib(payload_speex, "name", "speex");
00360       iks_insert_attrib(payload_speex, "clockrate","8000");
00361       iks_insert_attrib(payload_speex, "bitrate","11000");
00362       iks_insert_node(dcodecs, payload_speex);
00363       res++;
00364    }
00365    if (!strcasecmp("gsm", format)) {
00366       iks *payload_gsm = iks_new("payload-type");
00367       if(!payload_gsm) {
00368          ast_log(LOG_WARNING,"Failed to allocate iks node");
00369          return -1;
00370       }
00371       iks_insert_attrib(payload_gsm, "id", "103");
00372       iks_insert_attrib(payload_gsm, "name", "gsm");
00373       iks_insert_node(dcodecs, payload_gsm);
00374       res++;
00375    }
00376 
00377    return res;
00378 }
00379 
00380 static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, int initiator)
00381 {
00382    struct gtalk *client = p->parent;
00383    iks *iq, *gtalk, *dcodecs, *payload_telephone, *transport;
00384    int x;
00385    int pref_codec = 0;
00386    int alreadysent = 0;
00387    int codecs_num = 0;
00388    char *lowerto = NULL;
00389 
00390    iq = iks_new("iq");
00391    gtalk = iks_new("session");
00392    dcodecs = iks_new("description");
00393    transport = iks_new("transport");
00394    payload_telephone = iks_new("payload-type");
00395    if (!(iq && gtalk && dcodecs && transport && payload_telephone)){
00396       iks_delete(iq);
00397       iks_delete(gtalk);
00398       iks_delete(dcodecs);
00399       iks_delete(transport);
00400       iks_delete(payload_telephone);
00401 
00402       ast_log(LOG_ERROR, "Could not allocate iksemel nodes\n");
00403       return 0;
00404    }
00405    iks_insert_attrib(dcodecs, "xmlns", GOOGLE_AUDIO_NS);
00406    iks_insert_attrib(dcodecs, "xml:lang", "en");
00407 
00408    for (x = 0; x < 64; x++) {
00409       if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
00410          break;
00411       if (!(client->capability & pref_codec))
00412          continue;
00413       if (alreadysent & pref_codec)
00414          continue;
00415       codecs_num = add_codec_to_answer(p, pref_codec, dcodecs);
00416       alreadysent |= pref_codec;
00417    }
00418 
00419    if (codecs_num) {
00420       /* only propose DTMF within an audio session */
00421       iks_insert_attrib(payload_telephone, "id", "101");
00422       iks_insert_attrib(payload_telephone, "name", "telephone-event");
00423       iks_insert_attrib(payload_telephone, "clockrate", "8000");
00424    }
00425    iks_insert_attrib(transport,"xmlns",GOOGLE_TRANSPORT_NS);
00426 
00427    iks_insert_attrib(iq, "type", "set");
00428    iks_insert_attrib(iq, "to", to);
00429    iks_insert_attrib(iq, "from", from);
00430    iks_insert_attrib(iq, "id", client->connection->mid);
00431    ast_aji_increment_mid(client->connection->mid);
00432 
00433    iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
00434    iks_insert_attrib(gtalk, "type",initiator ? "initiate": "accept");
00435    /* put the initiator attribute to lower case if we receive the call
00436     * otherwise GoogleTalk won't establish the session */
00437    if (!initiator) {
00438            char c;
00439            char *t = lowerto = ast_strdupa(to);
00440       while (((c = *t) != '/') && (*t++ = tolower(c)));
00441    }
00442    iks_insert_attrib(gtalk, "initiator", initiator ? from : lowerto);
00443    iks_insert_attrib(gtalk, "id", sid);
00444    iks_insert_node(iq, gtalk);
00445    iks_insert_node(gtalk, dcodecs);
00446    iks_insert_node(dcodecs, payload_telephone);
00447 
00448    ast_aji_send(client->connection, iq);
00449 
00450    iks_delete(payload_telephone);
00451    iks_delete(transport);
00452    iks_delete(dcodecs);
00453    iks_delete(gtalk);
00454    iks_delete(iq);
00455    return 1;
00456 }
00457 
00458 static int gtalk_ringing_ack(void *data, ikspak *pak)
00459 {
00460    struct gtalk_pvt *p = data;
00461 
00462    if (p->ringrule)
00463       iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
00464    p->ringrule = NULL;
00465    if (p->owner)
00466       ast_queue_control(p->owner, AST_CONTROL_RINGING);
00467    return IKS_FILTER_EAT;
00468 }
00469 
00470 static int gtalk_answer(struct ast_channel *ast)
00471 {
00472    struct gtalk_pvt *p = ast->tech_pvt;
00473    int res = 0;
00474 
00475    ast_debug(1, "Answer!\n");
00476    ast_mutex_lock(&p->lock);
00477    gtalk_invite(p, p->them, p->us,p->sid, 0);
00478    manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", "Channel: %s\r\nChanneltype: %s\r\nGtalk-SID: %s\r\n",
00479       ast->name, "GTALK", p->sid);
00480    ast_mutex_unlock(&p->lock);
00481    return res;
00482 }
00483 
00484 static enum ast_rtp_glue_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
00485 {
00486    struct gtalk_pvt *p = chan->tech_pvt;
00487    enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
00488 
00489    if (!p)
00490       return res;
00491 
00492    ast_mutex_lock(&p->lock);
00493    if (p->rtp){
00494       ao2_ref(p->rtp, +1);
00495       *instance = p->rtp;
00496       res = AST_RTP_GLUE_RESULT_LOCAL;
00497    }
00498    ast_mutex_unlock(&p->lock);
00499 
00500    return res;
00501 }
00502 
00503 static format_t gtalk_get_codec(struct ast_channel *chan)
00504 {
00505    struct gtalk_pvt *p = chan->tech_pvt;
00506    return p->peercapability;
00507 }
00508 
00509 static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
00510 {
00511    struct gtalk_pvt *p;
00512 
00513    p = chan->tech_pvt;
00514    if (!p)
00515       return -1;
00516    ast_mutex_lock(&p->lock);
00517 
00518 /* if (rtp)
00519       ast_rtp_get_peer(rtp, &p->redirip);
00520    else
00521       memset(&p->redirip, 0, sizeof(p->redirip));
00522    p->redircodecs = codecs; */
00523 
00524    /* Reset lastrtprx timer */
00525    ast_mutex_unlock(&p->lock);
00526    return 0;
00527 }
00528 
00529 static struct ast_rtp_glue gtalk_rtp_glue = {
00530    .type = "Gtalk",
00531    .get_rtp_info = gtalk_get_rtp_peer,
00532    .get_codec = gtalk_get_codec,
00533    .update_peer = gtalk_set_rtp_peer,
00534 };
00535 
00536 static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const char *reasonstr, const char *reasonstr2)
00537 {
00538    iks *response = NULL, *error = NULL, *reason = NULL;
00539    int res = -1;
00540 
00541    response = iks_new("iq");
00542    if (response) {
00543       iks_insert_attrib(response, "type", "result");
00544       iks_insert_attrib(response, "from", from);
00545       iks_insert_attrib(response, "to", S_OR(iks_find_attrib(pak->x, "from"), ""));
00546       iks_insert_attrib(response, "id", S_OR(iks_find_attrib(pak->x, "id"), ""));
00547       if (reasonstr) {
00548          error = iks_new("error");
00549          if (error) {
00550             iks_insert_attrib(error, "type", "cancel");
00551             reason = iks_new(reasonstr);
00552             if (reason)
00553                iks_insert_node(error, reason);
00554             iks_insert_node(response, error);
00555          }
00556       }
00557       ast_aji_send(client->connection, response);
00558       res = 0;
00559    }
00560 
00561    iks_delete(reason);
00562    iks_delete(error);
00563    iks_delete(response);
00564 
00565    return res;
00566 }
00567 
00568 static int gtalk_is_answered(struct gtalk *client, ikspak *pak)
00569 {
00570    struct gtalk_pvt *tmp = NULL;
00571    char *from;
00572    iks *codec;
00573    char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ];
00574    int peernoncodeccapability;
00575 
00576    ast_log(LOG_DEBUG, "The client is %s\n", client->name);
00577 
00578    /* Make sure our new call does exist */
00579    for (tmp = client->p; tmp; tmp = tmp->next) {
00580       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
00581          break;
00582       } else if (iks_find_with_attrib(pak->x, "ses:session", "id", tmp->sid)) {
00583          break;
00584       }
00585    }
00586 
00587    if (!tmp) {
00588       ast_log(LOG_WARNING, "Could not find session in iq\n");
00589       return -1;
00590    }
00591 
00592    /* codec points to the first <payload-type/> tag */
00593    codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
00594    while (codec) {
00595       char *codec_id = iks_find_attrib(codec, "id");
00596       char *codec_name = iks_find_attrib(codec, "name");
00597       if (!codec_id || !codec_name) {
00598          codec = iks_next_tag(codec);
00599          continue;
00600       }
00601 
00602       ast_rtp_codecs_payloads_set_m_type(
00603          ast_rtp_instance_get_codecs(tmp->rtp),
00604          tmp->rtp,
00605          atoi(codec_id));
00606       ast_rtp_codecs_payloads_set_rtpmap_type(
00607          ast_rtp_instance_get_codecs(tmp->rtp),
00608          tmp->rtp,
00609          atoi(codec_id),
00610          "audio",
00611          codec_name,
00612          0);
00613       codec = iks_next_tag(codec);
00614    }
00615 
00616    /* Now gather all of the codecs that we are asked for */
00617    ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(tmp->rtp), &tmp->peercapability, &peernoncodeccapability);
00618 
00619    /* at this point, we received an awser from the remote Gtalk client,
00620       which allows us to compare capabilities */
00621    tmp->jointcapability = tmp->capability & tmp->peercapability;
00622    if (!tmp->jointcapability) {
00623       ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, tmp->capability),
00624          ast_getformatname_multiple(s2, BUFSIZ, tmp->peercapability),
00625          ast_getformatname_multiple(s3, BUFSIZ, tmp->jointcapability));
00626       /* close session if capabilities don't match */
00627       ast_queue_hangup(tmp->owner);
00628 
00629       return -1;
00630 
00631    }
00632 
00633    from = iks_find_attrib(pak->x, "to");
00634    if (!from) {
00635       from = client->connection->jid->full;
00636    }
00637 
00638    if (tmp->owner) {
00639       ast_queue_control(tmp->owner, AST_CONTROL_ANSWER);
00640    }
00641    gtalk_update_stun(tmp->parent, tmp);
00642    gtalk_response(client, from, pak, NULL, NULL);
00643    return 1;
00644 }
00645 
00646 static int gtalk_is_accepted(struct gtalk *client, ikspak *pak)
00647 {
00648    struct gtalk_pvt *tmp;
00649    char *from;
00650 
00651    ast_log(LOG_DEBUG, "The client is %s\n", client->name);
00652    /* find corresponding call */
00653    for (tmp = client->p; tmp; tmp = tmp->next) {
00654       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
00655          break;
00656       }
00657    }
00658 
00659    from = iks_find_attrib(pak->x, "to");
00660    if (!from) {
00661       from = client->connection->jid->full;
00662    }
00663 
00664    if (tmp) {
00665       gtalk_update_stun(tmp->parent, tmp);
00666    } else {
00667       ast_log(LOG_NOTICE, "Whoa, didn't find call during accept?!\n");
00668    }
00669 
00670    /* answer 'iq' packet to let the remote peer know that we're alive */
00671    gtalk_response(client, from, pak, NULL, NULL);
00672    return 1;
00673 }
00674 
00675 static int gtalk_handle_dtmf(struct gtalk *client, ikspak *pak)
00676 {
00677    struct gtalk_pvt *tmp;
00678    iks *dtmfnode = NULL, *dtmfchild = NULL;
00679    char *dtmf;
00680    char *from;
00681    /* Make sure our new call doesn't exist yet */
00682    for (tmp = client->p; tmp; tmp = tmp->next) {
00683       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) || iks_find_with_attrib(pak->x, "gtalk", "sid", tmp->sid))
00684          break;
00685    }
00686    from = iks_find_attrib(pak->x, "to");
00687    if (!from) {
00688       from = client->connection->jid->full;
00689    }
00690 
00691    if (tmp) {
00692       if(iks_find_with_attrib(pak->x, "dtmf-method", "method", "rtp")) {
00693          gtalk_response(client, from, pak,
00694                "feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'",
00695                "unsupported-dtmf-method xmlns='http://jabber.org/protocol/gtalk/info/dtmf#errors'");
00696          return -1;
00697       }
00698       if ((dtmfnode = iks_find(pak->x, "dtmf"))) {
00699          if((dtmf = iks_find_attrib(dtmfnode, "code"))) {
00700             if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-up")) {
00701                struct ast_frame f = {AST_FRAME_DTMF_BEGIN, };
00702                f.subclass.integer = dtmf[0];
00703                ast_queue_frame(tmp->owner, &f);
00704                ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
00705             } else if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-down")) {
00706                struct ast_frame f = {AST_FRAME_DTMF_END, };
00707                f.subclass.integer = dtmf[0];
00708                ast_queue_frame(tmp->owner, &f);
00709                ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
00710             } else if(iks_find_attrib(pak->x, "dtmf")) { /* 250 millasecond default */
00711                struct ast_frame f = {AST_FRAME_DTMF, };
00712                f.subclass.integer = dtmf[0];
00713                ast_queue_frame(tmp->owner, &f);
00714                ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
00715             }
00716          }
00717       } else if ((dtmfnode = iks_find_with_attrib(pak->x, "gtalk", "action", "session-info"))) {
00718          if((dtmfchild = iks_find(dtmfnode, "dtmf"))) {
00719             if((dtmf = iks_find_attrib(dtmfchild, "code"))) {
00720                if(iks_find_with_attrib(dtmfnode, "dtmf", "action", "button-up")) {
00721                   struct ast_frame f = {AST_FRAME_DTMF_END, };
00722                   f.subclass.integer = dtmf[0];
00723                   ast_queue_frame(tmp->owner, &f);
00724                   ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
00725                } else if(iks_find_with_attrib(dtmfnode, "dtmf", "action", "button-down")) {
00726                   struct ast_frame f = {AST_FRAME_DTMF_BEGIN, };
00727                   f.subclass.integer = dtmf[0];
00728                   ast_queue_frame(tmp->owner, &f);
00729                   ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
00730                }
00731             }
00732          }
00733       }
00734       gtalk_response(client, from, pak, NULL, NULL);
00735       return 1;
00736    } else {
00737       ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
00738    }
00739 
00740    gtalk_response(client, from, pak, NULL, NULL);
00741    return 1;
00742 }
00743 
00744 static int gtalk_hangup_farend(struct gtalk *client, ikspak *pak)
00745 {
00746    struct gtalk_pvt *tmp;
00747    char *from;
00748 
00749    ast_debug(1, "The client is %s\n", client->name);
00750    /* Make sure our new call doesn't exist yet */
00751    for (tmp = client->p; tmp; tmp = tmp->next) {
00752       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
00753          (iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
00754          break;
00755       }
00756    }
00757    from = iks_find_attrib(pak->x, "to");
00758    if (!from) {
00759       from = client->connection->jid->full;
00760    }
00761 
00762    if (tmp) {
00763       tmp->alreadygone = 1;
00764       if (tmp->owner) {
00765          ast_queue_hangup(tmp->owner);
00766       }
00767    } else {
00768       ast_log(LOG_NOTICE, "Whoa, didn't find call during hangup!\n");
00769    }
00770    gtalk_response(client, from, pak, NULL, NULL);
00771    return 1;
00772 }
00773 
00774 static int gtalk_get_local_ip(struct ast_sockaddr *ourip)
00775 {
00776    struct ast_sockaddr root;
00777    struct ast_sockaddr bindaddr_tmp;
00778    struct ast_sockaddr *addrs;
00779    int addrs_cnt;
00780 
00781    /* If bind address is not 0.0.0.0, then bindaddr is our local ip. */
00782    ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
00783    if (!ast_sockaddr_is_any(&bindaddr_tmp)) {
00784       ast_sockaddr_copy(ourip, &bindaddr_tmp);
00785       return 0;
00786    }
00787 
00788    /* If no bind address was provided, lets see what ip we would use to connect to google.com and use that.
00789     * If you can't resolve google.com from your network, then this module is useless for you anyway. */
00790    if ((addrs_cnt = ast_sockaddr_resolve(&addrs, "google.com", PARSE_PORT_FORBID, AF_INET)) > 0) {
00791       ast_sockaddr_copy(&root, &addrs[0]);
00792       ast_free(addrs);
00793       if (!ast_ouraddrfor(&root, ourip)) {
00794          return 0;
00795       }
00796    }
00797 
00798    /* As a last resort, use this function to find our local address. */
00799    return ast_find_ourip(ourip, &bindaddr_tmp, AF_INET);
00800 }
00801 
00802 static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from, char *to)
00803 {
00804    struct gtalk_candidate *tmp;
00805    struct aji_client *c = client->connection;
00806    struct gtalk_candidate *ours1 = NULL, *ours2 = NULL;
00807    struct sockaddr_in sin = { 0, };
00808    struct ast_sockaddr sin_tmp;
00809    struct ast_sockaddr us;
00810    iks *iq, *gtalk, *candidate, *transport;
00811    char user[17], pass[17], preference[5], port[7];
00812    char *lowerfrom = NULL;
00813 
00814    iq = iks_new("iq");
00815    gtalk = iks_new("session");
00816    candidate = iks_new("candidate");
00817    transport = iks_new("transport");
00818    if (!iq || !gtalk || !candidate || !transport) {
00819       ast_log(LOG_ERROR, "Memory allocation error\n");
00820       goto safeout;
00821    }
00822    ours1 = ast_calloc(1, sizeof(*ours1));
00823    ours2 = ast_calloc(1, sizeof(*ours2));
00824    if (!ours1 || !ours2)
00825       goto safeout;
00826 
00827    iks_insert_attrib(transport, "xmlns",GOOGLE_TRANSPORT_NS);
00828    iks_insert_node(iq, gtalk);
00829    iks_insert_node(gtalk,candidate);
00830    iks_insert_node(gtalk,transport);
00831 
00832    for (; p; p = p->next) {
00833       if (!strcasecmp(p->sid, sid))
00834          break;
00835    }
00836 
00837    if (!p) {
00838       ast_log(LOG_NOTICE, "No matching gtalk session - SID %s!\n", sid);
00839       goto safeout;
00840    }
00841 
00842    ast_rtp_instance_get_local_address(p->rtp, &sin_tmp);
00843    ast_sockaddr_to_sin(&sin_tmp, &sin);
00844 
00845    gtalk_get_local_ip(&us);
00846 
00847    if (!strcmp(ast_sockaddr_stringify_addr(&us), "127.0.0.1")) {
00848       ast_log(LOG_WARNING, "Found a loopback IP on the system, check your network configuration or set the bindaddr attribute.");
00849    }
00850 
00851    /* Setup our gtalk candidates */
00852    ast_copy_string(ours1->name, "rtp", sizeof(ours1->name));
00853    ours1->port = ntohs(sin.sin_port);
00854    ours1->preference = 1;
00855    snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
00856    snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
00857    ast_copy_string(ours1->username, user, sizeof(ours1->username));
00858    ast_copy_string(ours1->password, pass, sizeof(ours1->password));
00859    ast_copy_string(ours1->ip, ast_sockaddr_stringify_addr(&us),
00860          sizeof(ours1->ip));
00861    ours1->protocol = AJI_PROTOCOL_UDP;
00862    ours1->type = AJI_CONNECT_LOCAL;
00863    ours1->generation = 0;
00864    p->ourcandidates = ours1;
00865 
00866    /* XXX this is a blocking action.  We send a STUN request to the server
00867     * and wait for the response.  If blocking here is a problem the STUN requests/responses
00868     * for the externip may need to be done differently. */
00869    gtalk_update_externip();
00870    if (!ast_strlen_zero(externip)) {
00871       ast_copy_string(ours2->username, user, sizeof(ours2->username));
00872       ast_copy_string(ours2->password, pass, sizeof(ours2->password));
00873       ast_copy_string(ours2->ip, externip, sizeof(ours2->ip));
00874       ast_copy_string(ours2->name, "rtp", sizeof(ours1->name));
00875       ours2->port = ntohs(sin.sin_port);
00876       ours2->preference = 0.9;
00877       ours2->protocol = AJI_PROTOCOL_UDP;
00878       ours2->type = AJI_CONNECT_STUN;
00879       ours2->generation = 0;
00880       ours1->next = ours2;
00881       ours2 = NULL;
00882    }
00883    ours1 = NULL;
00884 
00885    for (tmp = p->ourcandidates; tmp; tmp = tmp->next) {
00886       snprintf(port, sizeof(port), "%d", tmp->port);
00887       snprintf(preference, sizeof(preference), "%.2f", tmp->preference);
00888       iks_insert_attrib(iq, "from", to);
00889       iks_insert_attrib(iq, "to", from);
00890       iks_insert_attrib(iq, "type", "set");
00891       iks_insert_attrib(iq, "id", c->mid);
00892       ast_aji_increment_mid(c->mid);
00893       iks_insert_attrib(gtalk, "type", "candidates");
00894       iks_insert_attrib(gtalk, "id", sid);
00895       /* put the initiator attribute to lower case if we receive the call
00896        * otherwise GoogleTalk won't establish the session */
00897       if (!p->initiator) {
00898               char c;
00899          char *t = lowerfrom = ast_strdupa(from);
00900          while (((c = *t) != '/') && (*t++ = tolower(c)));
00901       }
00902       iks_insert_attrib(gtalk, "initiator", (p->initiator) ? to : lowerfrom);
00903       iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
00904       iks_insert_attrib(candidate, "name", tmp->name);
00905       iks_insert_attrib(candidate, "address", tmp->ip);
00906       iks_insert_attrib(candidate, "port", port);
00907       iks_insert_attrib(candidate, "username", tmp->username);
00908       iks_insert_attrib(candidate, "password", tmp->password);
00909       iks_insert_attrib(candidate, "preference", preference);
00910       if (tmp->protocol == AJI_PROTOCOL_UDP)
00911          iks_insert_attrib(candidate, "protocol", "udp");
00912       if (tmp->protocol == AJI_PROTOCOL_SSLTCP)
00913          iks_insert_attrib(candidate, "protocol", "ssltcp");
00914       if (tmp->type == AJI_CONNECT_STUN)
00915          iks_insert_attrib(candidate, "type", "stun");
00916       if (tmp->type == AJI_CONNECT_LOCAL)
00917          iks_insert_attrib(candidate, "type", "local");
00918       if (tmp->type == AJI_CONNECT_RELAY)
00919          iks_insert_attrib(candidate, "type", "relay");
00920       iks_insert_attrib(candidate, "network", "0");
00921       iks_insert_attrib(candidate, "generation", "0");
00922       ast_aji_send(c, iq);
00923    }
00924    p->laststun = 0;
00925 
00926 safeout:
00927    if (ours1)
00928       ast_free(ours1);
00929    if (ours2)
00930       ast_free(ours2);
00931    iks_delete(iq);
00932    iks_delete(gtalk);
00933    iks_delete(candidate);
00934    iks_delete(transport);
00935 
00936    return 1;
00937 }
00938 
00939 static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid)
00940 {
00941    struct gtalk_pvt *tmp = NULL;
00942    struct aji_resource *resources = NULL;
00943    struct aji_buddy *buddy;
00944    char idroster[200];
00945    char *data, *exten = NULL;
00946    struct ast_sockaddr bindaddr_tmp;
00947 
00948    ast_debug(1, "The client is %s for alloc\n", client->name);
00949    if (!sid && !strchr(them, '/')) {   /* I started call! */
00950       if (!strcasecmp(client->name, "guest")) {
00951          buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, them);
00952          if (buddy) {
00953             resources = buddy->resources;
00954          }
00955       } else if (client->buddy) {
00956          resources = client->buddy->resources;
00957       }
00958 
00959       while (resources) {
00960          if (resources->cap->jingle) {
00961             break;
00962          }
00963          resources = resources->next;
00964       }
00965       if (resources) {
00966          snprintf(idroster, sizeof(idroster), "%s/%s", them, resources->resource);
00967       } else if ((*them == '+') || (strstr(them, "@voice.google.com"))) {
00968          snprintf(idroster, sizeof(idroster), "%s/srvres", them);
00969       } else {
00970          ast_log(LOG_ERROR, "no gtalk capable clients to talk to.\n");
00971          return NULL;
00972       }
00973    }
00974    if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
00975       return NULL;
00976    }
00977 
00978    memcpy(&tmp->prefs, &client->prefs, sizeof(struct ast_codec_pref));
00979 
00980    if (sid) {
00981       ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
00982       ast_copy_string(tmp->them, them, sizeof(tmp->them));
00983       ast_copy_string(tmp->us, us, sizeof(tmp->us));
00984    } else {
00985       snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random());
00986       ast_copy_string(tmp->them, idroster, sizeof(tmp->them));
00987       ast_copy_string(tmp->us, us, sizeof(tmp->us));
00988       tmp->initiator = 1;
00989    }
00990    /* clear codecs */
00991    bindaddr.sin_family = AF_INET;
00992    ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
00993    if (!(tmp->rtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL))) {
00994      ast_log(LOG_ERROR, "Failed to create a new RTP instance (possibly an invalid bindaddr?)\n");
00995      ast_free(tmp);
00996      return NULL;
00997    }
00998    ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_RTCP, 1);
00999    ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_STUN, 1);
01000    ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_DTMF, 1);
01001    ast_rtp_instance_dtmf_mode_set(tmp->rtp, AST_RTP_DTMF_MODE_RFC2833);
01002    ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp);
01003 
01004    /* add user configured codec capabilites */
01005    if (client->capability) {
01006       tmp->capability = client->capability;
01007    } else if (global_capability) {
01008       tmp->capability = global_capability;
01009    }
01010 
01011    tmp->parent = client;
01012    if (!tmp->rtp) {
01013       ast_log(LOG_WARNING, "Out of RTP sessions?\n");
01014       ast_free(tmp);
01015       return NULL;
01016    }
01017 
01018    /* Set CALLERID(name) to the full JID of the remote peer */
01019    ast_copy_string(tmp->cid_name, tmp->them, sizeof(tmp->cid_name));
01020 
01021    if(strchr(tmp->us, '/')) {
01022       data = ast_strdupa(tmp->us);
01023       exten = strsep(&data, "/");
01024    } else {
01025       exten = tmp->us;
01026    }
01027    ast_copy_string(tmp->exten,  exten, sizeof(tmp->exten));
01028    ast_mutex_init(&tmp->lock);
01029    ast_mutex_lock(&gtalklock);
01030    tmp->next = client->p;
01031    client->p = tmp;
01032    ast_mutex_unlock(&gtalklock);
01033    return tmp;
01034 }
01035 
01036 /*! \brief Start new gtalk channel */
01037 static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i, int state, const char *title, const char *linkedid)
01038 {
01039    struct ast_channel *tmp;
01040    int fmt;
01041    int what;
01042    const char *n2;
01043 
01044    if (title)
01045       n2 = title;
01046    else
01047       n2 = i->us;
01048    tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, linkedid, client->accountcode, i->exten, client->context, client->amaflags, "Gtalk/%s-%04lx", n2, ast_random() & 0xffff);
01049    if (!tmp) {
01050       ast_log(LOG_WARNING, "Unable to allocate Gtalk channel structure!\n");
01051       return NULL;
01052    }
01053    tmp->tech = &gtalk_tech;
01054 
01055    /* Select our native format based on codec preference until we receive
01056       something from another device to the contrary. */
01057    if (i->jointcapability)
01058       what = i->jointcapability;
01059    else if (i->capability)
01060       what = i->capability;
01061    else
01062       what = global_capability;
01063 
01064    /* Set Frame packetization */
01065    if (i->rtp) {
01066       ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
01067    }
01068 
01069    tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
01070    fmt = ast_best_codec(tmp->nativeformats);
01071 
01072    if (i->rtp) {
01073       ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
01074       ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
01075    }
01076    if (i->vrtp) {
01077       ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
01078       ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
01079    }
01080    if (state == AST_STATE_RING)
01081       tmp->rings = 1;
01082    tmp->adsicpe = AST_ADSI_UNAVAILABLE;
01083    tmp->writeformat = fmt;
01084    tmp->rawwriteformat = fmt;
01085    tmp->readformat = fmt;
01086    tmp->rawreadformat = fmt;
01087    tmp->tech_pvt = i;
01088 
01089    tmp->callgroup = client->callgroup;
01090    tmp->pickupgroup = client->pickupgroup;
01091    tmp->caller.id.name.presentation = client->callingpres;
01092    tmp->caller.id.number.presentation = client->callingpres;
01093    if (!ast_strlen_zero(client->accountcode))
01094       ast_string_field_set(tmp, accountcode, client->accountcode);
01095    if (client->amaflags)
01096       tmp->amaflags = client->amaflags;
01097    if (!ast_strlen_zero(client->language))
01098       ast_string_field_set(tmp, language, client->language);
01099    if (!ast_strlen_zero(client->musicclass))
01100       ast_string_field_set(tmp, musicclass, client->musicclass);
01101    if (!ast_strlen_zero(client->parkinglot))
01102       ast_string_field_set(tmp, parkinglot, client->parkinglot);
01103    i->owner = tmp;
01104    ast_module_ref(ast_module_info->self);
01105    ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
01106    ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
01107 
01108    if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) {
01109       tmp->dialed.number.str = ast_strdup(i->exten);
01110    }
01111    tmp->priority = 1;
01112    if (i->rtp)
01113       ast_jb_configure(tmp, &global_jbconf);
01114    if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
01115       ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
01116       tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
01117       ast_hangup(tmp);
01118       tmp = NULL;
01119    } else {
01120       manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate",
01121          "Channel: %s\r\nChanneltype: %s\r\nGtalk-SID: %s\r\n",
01122          i->owner ? i->owner->name : "", "Gtalk", i->sid);
01123    }
01124    return tmp;
01125 }
01126 
01127 static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *action)
01128 {
01129    iks *request, *session = NULL;
01130    int res = -1;
01131    char *lowerthem = NULL;
01132 
01133    request = iks_new("iq");
01134    if (request) {
01135       iks_insert_attrib(request, "type", "set");
01136       iks_insert_attrib(request, "from", p->us);
01137       iks_insert_attrib(request, "to", p->them);
01138       iks_insert_attrib(request, "id", client->connection->mid);
01139       ast_aji_increment_mid(client->connection->mid);
01140       session = iks_new("session");
01141       if (session) {
01142          iks_insert_attrib(session, "type", action);
01143          iks_insert_attrib(session, "id", p->sid);
01144          /* put the initiator attribute to lower case if we receive the call
01145           * otherwise GoogleTalk won't establish the session */
01146          if (!p->initiator) {
01147                  char c;
01148             char *t = lowerthem = ast_strdupa(p->them);
01149             while (((c = *t) != '/') && (*t++ = tolower(c)));
01150          }
01151          iks_insert_attrib(session, "initiator", p->initiator ? p->us : lowerthem);
01152          iks_insert_attrib(session, "xmlns", GOOGLE_NS);
01153          iks_insert_node(request, session);
01154          ast_aji_send(client->connection, request);
01155          res = 0;
01156       }
01157    }
01158 
01159    iks_delete(session);
01160    iks_delete(request);
01161 
01162    return res;
01163 }
01164 
01165 static void gtalk_free_candidates(struct gtalk_candidate *candidate)
01166 {
01167    struct gtalk_candidate *last;
01168    while (candidate) {
01169       last = candidate;
01170       candidate = candidate->next;
01171       ast_free(last);
01172    }
01173 }
01174 
01175 static void gtalk_free_pvt(struct gtalk *client, struct gtalk_pvt *p)
01176 {
01177    struct gtalk_pvt *cur, *prev = NULL;
01178    cur = client->p;
01179    while (cur) {
01180       if (cur == p) {
01181          if (prev)
01182             prev->next = p->next;
01183          else
01184             client->p = p->next;
01185          break;
01186       }
01187       prev = cur;
01188       cur = cur->next;
01189    }
01190    if (p->ringrule)
01191       iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
01192    if (p->owner)
01193       ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
01194    if (p->rtp)
01195       ast_rtp_instance_destroy(p->rtp);
01196    if (p->vrtp)
01197       ast_rtp_instance_destroy(p->vrtp);
01198    gtalk_free_candidates(p->theircandidates);
01199    ast_free(p);
01200 }
01201 
01202 
01203 static int gtalk_newcall(struct gtalk *client, ikspak *pak)
01204 {
01205    struct gtalk_pvt *p, *tmp = client->p;
01206    struct ast_channel *chan;
01207    int res;
01208    iks *codec;
01209    char *from = NULL;
01210    char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ];
01211    int peernoncodeccapability;
01212    char *sid;
01213 
01214    /* Make sure our new call doesn't exist yet */
01215    from = iks_find_attrib(pak->x,"to");
01216    if (!from) {
01217       from = client->connection->jid->full;
01218    }
01219 
01220    while (tmp) {
01221       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
01222          (iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
01223          ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
01224          gtalk_response(client, from, pak, "out-of-order", NULL);
01225          return -1;
01226       }
01227       tmp = tmp->next;
01228    }
01229 
01230    if (!strcasecmp(client->name, "guest")){
01231       /* the guest account is not tied to any configured XMPP client,
01232          let's set it now */
01233       client->connection = ast_aji_get_client(from);
01234       if (!client->connection) {
01235          ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", from);
01236          return -1;
01237       }
01238    }
01239 
01240    if (!(sid = iks_find_attrib(pak->query, "id"))) {
01241       ast_log(LOG_WARNING, "Received Initiate without id attribute. Can not start call.\n");
01242       return -1;
01243    }
01244 
01245    p = gtalk_alloc(client, from, pak->from->full, sid);
01246    if (!p) {
01247       ast_log(LOG_WARNING, "Unable to allocate gtalk structure!\n");
01248       return -1;
01249    }
01250 
01251    chan = gtalk_new(client, p, AST_STATE_DOWN, pak->from->user, NULL);
01252    if (!chan) {
01253       gtalk_free_pvt(client, p);
01254       return -1;
01255    }
01256 
01257    ast_mutex_lock(&p->lock);
01258    ast_copy_string(p->them, pak->from->full, sizeof(p->them));
01259    ast_copy_string(p->sid, sid, sizeof(p->sid));
01260 
01261    /* codec points to the first <payload-type/> tag */
01262    codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
01263 
01264    while (codec) {
01265       char *codec_id = iks_find_attrib(codec, "id");
01266       char *codec_name = iks_find_attrib(codec, "name");
01267       if (!codec_id || !codec_name) {
01268          codec = iks_next_tag(codec);
01269          continue;
01270       }
01271       if (!strcmp(S_OR(iks_name(codec), ""), "vid:payload-type") && p->vrtp) {
01272          ast_rtp_codecs_payloads_set_m_type(
01273             ast_rtp_instance_get_codecs(p->vrtp),
01274             p->vrtp,
01275             atoi(codec_id));
01276          ast_rtp_codecs_payloads_set_rtpmap_type(
01277             ast_rtp_instance_get_codecs(p->vrtp),
01278             p->vrtp,
01279             atoi(codec_id),
01280             "video",
01281             codec_name,
01282             0);
01283       } else {
01284          ast_rtp_codecs_payloads_set_m_type(
01285             ast_rtp_instance_get_codecs(p->rtp),
01286             p->rtp,
01287             atoi(codec_id));
01288          ast_rtp_codecs_payloads_set_rtpmap_type(
01289             ast_rtp_instance_get_codecs(p->rtp),
01290             p->rtp,
01291             atoi(codec_id),
01292             "audio",
01293             codec_name,
01294             0);
01295       }
01296       codec = iks_next_tag(codec);
01297    }
01298 
01299    /* Now gather all of the codecs that we are asked for */
01300    ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(p->rtp), &p->peercapability, &peernoncodeccapability);
01301    p->jointcapability = p->capability & p->peercapability;
01302    ast_mutex_unlock(&p->lock);
01303 
01304    ast_setstate(chan, AST_STATE_RING);
01305    if (!p->jointcapability) {
01306       ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->capability),
01307          ast_getformatname_multiple(s2, BUFSIZ, p->peercapability),
01308          ast_getformatname_multiple(s3, BUFSIZ, p->jointcapability));
01309       /* close session if capabilities don't match */
01310       gtalk_action(client, p, "reject");
01311       p->alreadygone = 1;
01312       gtalk_hangup(chan);
01313       ast_channel_release(chan);
01314       return -1;
01315    }
01316 
01317    res = ast_pbx_start(chan);
01318 
01319    switch (res) {
01320    case AST_PBX_FAILED:
01321       ast_log(LOG_WARNING, "Failed to start PBX :(\n");
01322       gtalk_response(client, from, pak, "service-unavailable", NULL);
01323       break;
01324    case AST_PBX_CALL_LIMIT:
01325       ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
01326       gtalk_response(client, from, pak, "service-unavailable", NULL);
01327       break;
01328    case AST_PBX_SUCCESS:
01329       gtalk_response(client, from, pak, NULL, NULL);
01330       gtalk_create_candidates(client, p, p->sid, p->them, p->us);
01331       /* nothing to do */
01332       break;
01333    }
01334 
01335    return 1;
01336 }
01337 
01338 static int gtalk_update_externip(void)
01339 {
01340    int sock;
01341    char *newaddr;
01342    struct sockaddr_in answer = { 0, };
01343    struct sockaddr_in *dst;
01344    struct ast_sockaddr tmp_dst;
01345 
01346    if (!stunaddr.sin_addr.s_addr) {
01347       return -1;
01348    }
01349    dst = &stunaddr;
01350 
01351    sock = socket(AF_INET, SOCK_DGRAM, 0);
01352    if (sock < 0) {
01353       ast_log(LOG_WARNING, "Unable to create STUN socket: %s\n", strerror(errno));
01354       return -1;
01355    }
01356 
01357    ast_sockaddr_from_sin(&tmp_dst, dst);
01358    if (ast_connect(sock, &tmp_dst) != 0) {
01359       ast_log(LOG_WARNING, "STUN Failed to connect to %s\n", ast_sockaddr_stringify(&tmp_dst));
01360       close(sock);
01361       return -1;
01362    }
01363 
01364    if ((ast_stun_request(sock, &stunaddr, NULL, &answer))) {
01365       close(sock);
01366       return -1;
01367    }
01368 
01369    newaddr = ast_strdupa(ast_inet_ntoa(answer.sin_addr));
01370    memcpy(externip, newaddr, sizeof(externip));
01371 
01372    close(sock);
01373    return 0;
01374 
01375 }
01376 
01377 static int gtalk_update_stun(struct gtalk *client, struct gtalk_pvt *p)
01378 {
01379    struct gtalk_candidate *tmp;
01380    struct hostent *hp;
01381    struct ast_hostent ahp;
01382    struct sockaddr_in sin = { 0, };
01383    struct sockaddr_in aux = { 0, };
01384    struct ast_sockaddr sin_tmp;
01385    struct ast_sockaddr aux_tmp;
01386 
01387    if (time(NULL) == p->laststun)
01388       return 0;
01389 
01390    tmp = p->theircandidates;
01391    p->laststun = time(NULL);
01392    while (tmp) {
01393       char username[256];
01394 
01395       /* Find the IP address of the host */
01396       if (!(hp = ast_gethostbyname(tmp->ip, &ahp))) {
01397          ast_log(LOG_WARNING, "Could not get host by name for %s\n", tmp->ip);
01398          tmp = tmp->next;
01399          continue;
01400       }
01401       sin.sin_family = AF_INET;
01402       memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
01403       sin.sin_port = htons(tmp->port);
01404       snprintf(username, sizeof(username), "%s%s", tmp->username, p->ourcandidates->username);
01405 
01406       /* Find out the result of the STUN */
01407       ast_rtp_instance_get_remote_address(p->rtp, &aux_tmp);
01408       ast_sockaddr_to_sin(&aux_tmp, &aux);
01409 
01410       /* If the STUN result is different from the IP of the hostname,
01411        * lock on the stun IP of the hostname advertised by the
01412        * remote client */
01413       if (aux.sin_addr.s_addr && (aux.sin_addr.s_addr != sin.sin_addr.s_addr)) {
01414          ast_rtp_instance_stun_request(p->rtp, &aux_tmp, username);
01415       } else {
01416          ast_sockaddr_from_sin(&sin_tmp, &sin);
01417          ast_rtp_instance_stun_request(p->rtp, &sin_tmp, username);
01418       }
01419       if (aux.sin_addr.s_addr) {
01420          ast_debug(4, "Receiving RTP traffic from IP %s, matches with remote candidate's IP %s\n", ast_inet_ntoa(aux.sin_addr), tmp->ip);
01421          ast_debug(4, "Sending STUN request to %s\n", tmp->ip);
01422       }
01423 
01424       tmp = tmp->next;
01425    }
01426    return 1;
01427 }
01428 
01429 static int gtalk_add_candidate(struct gtalk *client, ikspak *pak)
01430 {
01431    struct gtalk_pvt *p = NULL, *tmp = NULL;
01432    struct aji_client *c = client->connection;
01433    struct gtalk_candidate *newcandidate = NULL;
01434    iks *traversenodes = NULL, *receipt = NULL;
01435    char *from;
01436 
01437    from = iks_find_attrib(pak->x,"to");
01438    if (!from) {
01439       from = c->jid->full;
01440    }
01441 
01442    for (tmp = client->p; tmp; tmp = tmp->next) {
01443       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
01444          (iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
01445          p = tmp;
01446          break;
01447       }
01448    }
01449 
01450    if (!p) {
01451       return -1;
01452    }
01453    traversenodes = pak->query;
01454    while(traversenodes) {
01455       if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "session")) {
01456          traversenodes = iks_first_tag(traversenodes);
01457          continue;
01458       }
01459       if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "ses:session")) {
01460          traversenodes = iks_child(traversenodes);
01461          continue;
01462       }
01463       if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "candidate") || !strcasecmp(S_OR(iks_name(traversenodes), ""), "ses:candidate")) {
01464          newcandidate = ast_calloc(1, sizeof(*newcandidate));
01465          if (!newcandidate)
01466             return 0;
01467          ast_copy_string(newcandidate->name,
01468             S_OR(iks_find_attrib(traversenodes, "name"), ""),
01469             sizeof(newcandidate->name));
01470          ast_copy_string(newcandidate->ip,
01471             S_OR(iks_find_attrib(traversenodes, "address"), ""),
01472             sizeof(newcandidate->ip));
01473          newcandidate->port = atoi(iks_find_attrib(traversenodes, "port"));
01474          ast_copy_string(newcandidate->username,
01475             S_OR(iks_find_attrib(traversenodes, "username"), ""),
01476             sizeof(newcandidate->username));
01477          ast_copy_string(newcandidate->password,
01478             S_OR(iks_find_attrib(traversenodes, "password"), ""),
01479             sizeof(newcandidate->password));
01480          newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference"));
01481          if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "protocol"), ""), "udp"))
01482             newcandidate->protocol = AJI_PROTOCOL_UDP;
01483          if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "protocol"), ""), "ssltcp"))
01484             newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
01485 
01486          if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "stun"))
01487             newcandidate->type = AJI_CONNECT_STUN;
01488          if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "local"))
01489             newcandidate->type = AJI_CONNECT_LOCAL;
01490          if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "relay"))
01491             newcandidate->type = AJI_CONNECT_RELAY;
01492          ast_copy_string(newcandidate->network,
01493             S_OR(iks_find_attrib(traversenodes, "network"), ""),
01494             sizeof(newcandidate->network));
01495          newcandidate->generation = atoi(S_OR(iks_find_attrib(traversenodes, "generation"), "0"));
01496          newcandidate->next = NULL;
01497 
01498          newcandidate->next = p->theircandidates;
01499          p->theircandidates = newcandidate;
01500          p->laststun = 0;
01501          gtalk_update_stun(p->parent, p);
01502          newcandidate = NULL;
01503       }
01504       traversenodes = iks_next_tag(traversenodes);
01505    }
01506 
01507    receipt = iks_new("iq");
01508    iks_insert_attrib(receipt, "type", "result");
01509    iks_insert_attrib(receipt, "from", from);
01510    iks_insert_attrib(receipt, "to", S_OR(iks_find_attrib(pak->x, "from"), ""));
01511    iks_insert_attrib(receipt, "id", S_OR(iks_find_attrib(pak->x, "id"), ""));
01512    ast_aji_send(c, receipt);
01513 
01514    iks_delete(receipt);
01515 
01516    return 1;
01517 }
01518 
01519 static struct ast_frame *gtalk_rtp_read(struct ast_channel *ast, struct gtalk_pvt *p)
01520 {
01521    struct ast_frame *f;
01522 
01523    if (!p->rtp) {
01524       return &ast_null_frame;
01525    }
01526    f = ast_rtp_instance_read(p->rtp, 0);
01527    gtalk_update_stun(p->parent, p);
01528    if (p->owner) {
01529       /* We already hold the channel lock */
01530       if (f->frametype == AST_FRAME_VOICE) {
01531          if (f->subclass.codec != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
01532             ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(f->subclass.codec));
01533             p->owner->nativeformats =
01534                (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass.codec;
01535             ast_set_read_format(p->owner, p->owner->readformat);
01536             ast_set_write_format(p->owner, p->owner->writeformat);
01537          }
01538          /* if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) {
01539             f = ast_dsp_process(p->owner, p->vad, f);
01540             if (option_debug && f && (f->frametype == AST_FRAME_DTMF))
01541                ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass);
01542            } */
01543       }
01544    }
01545    return f;
01546 }
01547 
01548 static struct ast_frame *gtalk_read(struct ast_channel *ast)
01549 {
01550    struct ast_frame *fr;
01551    struct gtalk_pvt *p = ast->tech_pvt;
01552 
01553    ast_mutex_lock(&p->lock);
01554    fr = gtalk_rtp_read(ast, p);
01555    ast_mutex_unlock(&p->lock);
01556    return fr;
01557 }
01558 
01559 /*! \brief Send frame to media channel (rtp) */
01560 static int gtalk_write(struct ast_channel *ast, struct ast_frame *frame)
01561 {
01562    struct gtalk_pvt *p = ast->tech_pvt;
01563    int res = 0;
01564    char buf[256];
01565 
01566    switch (frame->frametype) {
01567    case AST_FRAME_VOICE:
01568       if (!(frame->subclass.codec & ast->nativeformats)) {
01569          ast_log(LOG_WARNING,
01570                "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
01571                ast_getformatname(frame->subclass.codec),
01572                ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
01573                ast_getformatname(ast->readformat),
01574                ast_getformatname(ast->writeformat));
01575          return 0;
01576       }
01577       if (p) {
01578          ast_mutex_lock(&p->lock);
01579          if (p->rtp) {
01580             res = ast_rtp_instance_write(p->rtp, frame);
01581          }
01582          ast_mutex_unlock(&p->lock);
01583       }
01584       break;
01585    case AST_FRAME_VIDEO:
01586       if (p) {
01587          ast_mutex_lock(&p->lock);
01588          if (p->vrtp) {
01589             res = ast_rtp_instance_write(p->vrtp, frame);
01590          }
01591          ast_mutex_unlock(&p->lock);
01592       }
01593       break;
01594    case AST_FRAME_IMAGE:
01595       return 0;
01596       break;
01597    default:
01598       ast_log(LOG_WARNING, "Can't send %d type frames with Gtalk write\n",
01599             frame->frametype);
01600       return 0;
01601    }
01602 
01603    return res;
01604 }
01605 
01606 static int gtalk_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
01607 {
01608    struct gtalk_pvt *p = newchan->tech_pvt;
01609    ast_mutex_lock(&p->lock);
01610 
01611    if ((p->owner != oldchan)) {
01612       ast_mutex_unlock(&p->lock);
01613       return -1;
01614    }
01615    if (p->owner == oldchan)
01616       p->owner = newchan;
01617    ast_mutex_unlock(&p->lock);
01618    return 0;
01619 }
01620 
01621 static int gtalk_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
01622 {
01623    int res = 0;
01624 
01625    switch (condition) {
01626    case AST_CONTROL_HOLD:
01627       ast_moh_start(ast, data, NULL);
01628       break;
01629    case AST_CONTROL_UNHOLD:
01630       ast_moh_stop(ast);
01631       break;
01632    default:
01633       ast_debug(3, "Don't know how to indicate condition '%d'\n", condition);
01634       res = -1;
01635    }
01636 
01637    return res;
01638 }
01639 
01640 static int gtalk_sendtext(struct ast_channel *chan, const char *text)
01641 {
01642    int res = 0;
01643    struct aji_client *client = NULL;
01644    struct gtalk_pvt *p = chan->tech_pvt;
01645 
01646    if (!p->parent) {
01647       ast_log(LOG_ERROR, "Parent channel not found\n");
01648       return -1;
01649    }
01650    if (!p->parent->connection) {
01651       ast_log(LOG_ERROR, "XMPP client not found\n");
01652       return -1;
01653    }
01654    client = p->parent->connection;
01655    res = ast_aji_send_chat(client, p->them, text);
01656    return res;
01657 }
01658 
01659 static int gtalk_digit_begin(struct ast_channel *chan, char digit)
01660 {
01661    struct gtalk_pvt *p = chan->tech_pvt;
01662    int res = 0;
01663 
01664    ast_mutex_lock(&p->lock);
01665    if (p->rtp) {
01666       ast_rtp_instance_dtmf_begin(p->rtp, digit);
01667    } else {
01668       res = -1;
01669    }
01670    ast_mutex_unlock(&p->lock);
01671 
01672    return res;
01673 }
01674 
01675 static int gtalk_digit_end(struct ast_channel *chan, char digit, unsigned int duration)
01676 {
01677    struct gtalk_pvt *p = chan->tech_pvt;
01678    int res = 0;
01679 
01680    ast_mutex_lock(&p->lock);
01681    if (p->rtp) {
01682       ast_rtp_instance_dtmf_end_with_duration(p->rtp, digit, duration);
01683    } else {
01684       res = -1;
01685    }
01686    ast_mutex_unlock(&p->lock);
01687 
01688    return res;
01689 }
01690 
01691 /* This function is of not in use at the moment, but I am choosing to leave this
01692  * within the code base as a reference to how DTMF is possible through
01693  * jingle signaling.  However, google currently does DTMF through the RTP. */
01694 #if 0
01695 static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duration)
01696 {
01697    struct gtalk_pvt *p = ast->tech_pvt;
01698    struct gtalk *client = p->parent;
01699    iks *iq, *gtalk, *dtmf;
01700    char buffer[2] = {digit, '\0'};
01701    char *lowerthem = NULL;
01702    iq = iks_new("iq");
01703    gtalk = iks_new("gtalk");
01704    dtmf = iks_new("dtmf");
01705    if(!iq || !gtalk || !dtmf) {
01706       iks_delete(iq);
01707       iks_delete(gtalk);
01708       iks_delete(dtmf);
01709       ast_log(LOG_ERROR, "Did not send dtmf do to memory issue\n");
01710       return -1;
01711    }
01712 
01713    iks_insert_attrib(iq, "type", "set");
01714    iks_insert_attrib(iq, "to", p->them);
01715    iks_insert_attrib(iq, "from", p->us);
01716    iks_insert_attrib(iq, "id", client->connection->mid);
01717    ast_aji_increment_mid(client->connection->mid);
01718    iks_insert_attrib(gtalk, "xmlns", "http://jabber.org/protocol/gtalk");
01719    iks_insert_attrib(gtalk, "action", "session-info");
01720    // put the initiator attribute to lower case if we receive the call
01721    // otherwise GoogleTalk won't establish the session
01722    if (!p->initiator) {
01723            char c;
01724            char *t = lowerthem = ast_strdupa(p->them);
01725            while (((c = *t) != '/') && (*t++ = tolower(c)));
01726    }
01727    iks_insert_attrib(gtalk, "initiator", p->initiator ? p->us: lowerthem);
01728    iks_insert_attrib(gtalk, "sid", p->sid);
01729    iks_insert_attrib(dtmf, "xmlns", "http://jabber.org/protocol/gtalk/info/dtmf");
01730    iks_insert_attrib(dtmf, "code", buffer);
01731    iks_insert_node(iq, gtalk);
01732    iks_insert_node(gtalk, dtmf);
01733 
01734    ast_mutex_lock(&p->lock);
01735    if (ast->dtmff.frametype == AST_FRAME_DTMF_BEGIN || duration == 0) {
01736       iks_insert_attrib(dtmf, "action", "button-down");
01737    } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END || duration != 0) {
01738       iks_insert_attrib(dtmf, "action", "button-up");
01739    }
01740    ast_aji_send(client->connection, iq);
01741 
01742    iks_delete(iq);
01743    iks_delete(gtalk);
01744    iks_delete(dtmf);
01745    ast_mutex_unlock(&p->lock);
01746    return 0;
01747 }
01748 #endif
01749 
01750 static int gtalk_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
01751 {
01752    ast_log(LOG_NOTICE, "XXX Implement gtalk sendhtml XXX\n");
01753 
01754    return -1;
01755 }
01756 
01757 /*!\brief Initiate new call, part of PBX interface
01758  * dest is the dial string */
01759 static int gtalk_call(struct ast_channel *ast, char *dest, int timeout)
01760 {
01761    struct gtalk_pvt *p = ast->tech_pvt;
01762 
01763    if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
01764       ast_log(LOG_WARNING, "gtalk_call called on %s, neither down nor reserved\n", ast->name);
01765       return -1;
01766    }
01767 
01768    ast_setstate(ast, AST_STATE_RING);
01769    if (!p->ringrule) {
01770       ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
01771       p->ringrule = iks_filter_add_rule(p->parent->connection->f, gtalk_ringing_ack, p,
01772                      IKS_RULE_ID, p->ring, IKS_RULE_DONE);
01773    } else {
01774       ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
01775    }
01776 
01777    gtalk_invite(p, p->them, p->us, p->sid, 1);
01778    gtalk_create_candidates(p->parent, p, p->sid, p->them, p->us);
01779 
01780    return 0;
01781 }
01782 
01783 /*! \brief Hangup a call through the gtalk proxy channel */
01784 static int gtalk_hangup(struct ast_channel *ast)
01785 {
01786    struct gtalk_pvt *p = ast->tech_pvt;
01787    struct gtalk *client;
01788 
01789    ast_mutex_lock(&p->lock);
01790    client = p->parent;
01791    p->owner = NULL;
01792    ast->tech_pvt = NULL;
01793    if (!p->alreadygone) {
01794       gtalk_action(client, p, "terminate");
01795    }
01796    ast_mutex_unlock(&p->lock);
01797 
01798    gtalk_free_pvt(client, p);
01799    ast_module_unref(ast_module_info->self);
01800 
01801    return 0;
01802 }
01803 
01804 /*!\brief Part of PBX interface */
01805 static struct ast_channel *gtalk_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
01806 {
01807    struct gtalk_pvt *p = NULL;
01808    struct gtalk *client = NULL;
01809    char *sender = NULL, *to = NULL, *s = NULL;
01810    struct ast_channel *chan = NULL;
01811 
01812    if (data) {
01813       s = ast_strdupa(data);
01814       if (s) {
01815          sender = strsep(&s, "/");
01816          if (sender && (sender[0] != '\0')) {
01817             to = strsep(&s, "/");
01818          }
01819          if (!to) {
01820             ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", (char*) data);
01821             return NULL;
01822          }
01823       }
01824    }
01825 
01826    client = find_gtalk(to, sender);
01827    if (!client) {
01828       ast_log(LOG_WARNING, "Could not find recipient.\n");
01829       return NULL;
01830    }
01831    if (!strcasecmp(client->name, "guest")){
01832       /* the guest account is not tied to any configured XMPP client,
01833          let's set it now */
01834       client->connection = ast_aji_get_client(sender);
01835       if (!client->connection) {
01836          ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", sender);
01837          ASTOBJ_UNREF(client, gtalk_member_destroy);
01838          return NULL;
01839       }
01840    }
01841 
01842    ASTOBJ_WRLOCK(client);
01843    p = gtalk_alloc(client, strchr(sender, '@') ? sender : client->connection->jid->full, strchr(to, '@') ? to : client->user, NULL);
01844    if (p) {
01845       chan = gtalk_new(client, p, AST_STATE_DOWN, to, requestor ? requestor->linkedid : NULL);
01846    }
01847    ASTOBJ_UNLOCK(client);
01848    return chan;
01849 }
01850 
01851 /*! \brief CLI command "gtalk show channels" */
01852 static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01853 {
01854 #define FORMAT  "%-30.30s  %-30.30s  %-15.15s  %-5.5s %-5.5s \n"
01855    struct gtalk_pvt *p;
01856    struct ast_channel *chan;
01857    int numchans = 0;
01858    char them[AJI_MAX_JIDLEN];
01859    char *jid = NULL;
01860    char *resource = NULL;
01861 
01862    switch (cmd) {
01863    case CLI_INIT:
01864       e->command = "gtalk show channels";
01865       e->usage =
01866          "Usage: gtalk show channels\n"
01867          "       Shows current state of the Gtalk channels.\n";
01868       return NULL;
01869    case CLI_GENERATE:
01870       return NULL;
01871    }
01872 
01873    if (a->argc != 3)
01874       return CLI_SHOWUSAGE;
01875 
01876    ast_mutex_lock(&gtalklock);
01877    ast_cli(a->fd, FORMAT, "Channel", "Jabber ID", "Resource", "Read", "Write");
01878    ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
01879       ASTOBJ_WRLOCK(iterator);
01880       p = iterator->p;
01881       while(p) {
01882          chan = p->owner;
01883          ast_copy_string(them, p->them, sizeof(them));
01884          jid = them;
01885          resource = strchr(them, '/');
01886          if (!resource)
01887             resource = "None";
01888          else {
01889             *resource = '\0';
01890             resource ++;
01891          }
01892          if (chan)
01893             ast_cli(a->fd, FORMAT,
01894                chan->name,
01895                jid,
01896                resource,
01897                ast_getformatname(chan->readformat),
01898                ast_getformatname(chan->writeformat)
01899                );
01900          else
01901             ast_log(LOG_WARNING, "No available channel\n");
01902          numchans ++;
01903          p = p->next;
01904       }
01905       ASTOBJ_UNLOCK(iterator);
01906    });
01907 
01908    ast_mutex_unlock(&gtalklock);
01909 
01910    ast_cli(a->fd, "%d active gtalk channel%s\n", numchans, (numchans != 1) ? "s" : "");
01911    return CLI_SUCCESS;
01912 #undef FORMAT
01913 }
01914 
01915 /*! \brief CLI command "gtalk reload"
01916  *  \todo XXX TODO make this work. */
01917 #if 0
01918 static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01919 {
01920    switch (cmd) {
01921    case CLI_INIT:
01922       e->command = "gtalk reload";
01923       e->usage =
01924          "Usage: gtalk reload\n"
01925          "       Reload gtalk channel driver.\n";
01926       return NULL;
01927    case CLI_GENERATE:
01928       return NULL;
01929    }
01930 
01931    ast_verbose("IT DOES WORK!\n");
01932    return CLI_SUCCESS;
01933 }
01934 #endif
01935 
01936 static int gtalk_parser(void *data, ikspak *pak)
01937 {
01938    struct gtalk *client = ASTOBJ_REF((struct gtalk *) data);
01939    int res;
01940 
01941    if (!strcmp(S_OR(iks_find_attrib(pak->x, "type"), ""), "error")) {
01942       ast_log(LOG_NOTICE, "Remote peer reported an error, trying to establish the call anyway\n");
01943    }
01944 
01945    if (ast_strlen_zero(iks_find_attrib(pak->query, "type"))) {
01946       ast_log(LOG_NOTICE, "No attribute \"type\" found.  Ignoring message.\n");
01947    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "initiate")) {
01948       /* New call */
01949       gtalk_newcall(client, pak);
01950    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "candidates") || !strcmp(iks_find_attrib(pak->query, "type"), "transport-info")) {
01951       ast_debug(3, "About to add candidate!\n");
01952       res = gtalk_add_candidate(client, pak);
01953       if (!res) {
01954          ast_log(LOG_WARNING, "Could not add any candidate\n");
01955       } else {
01956          ast_debug(3, "Candidate Added!\n");
01957       }
01958    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "accept")) {
01959       gtalk_is_answered(client, pak);
01960    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "transport-accept")) {
01961       gtalk_is_accepted(client, pak);
01962    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "content-info") || iks_find_with_attrib(pak->x, "gtalk", "action", "session-info")) {
01963       gtalk_handle_dtmf(client, pak);
01964    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "terminate")) {
01965       gtalk_hangup_farend(client, pak);
01966    } else if (!strcmp(iks_find_attrib(pak->query, "type"), "reject")) {
01967       gtalk_hangup_farend(client, pak);
01968    }
01969    ASTOBJ_UNREF(client, gtalk_member_destroy);
01970    return IKS_FILTER_EAT;
01971 }
01972 
01973 static int gtalk_create_member(char *label, struct ast_variable *var, int allowguest,
01974                         struct ast_codec_pref prefs, char *context,
01975                         struct gtalk *member)
01976 {
01977    struct aji_client *client;
01978 
01979    if (!member)
01980       ast_log(LOG_WARNING, "Out of memory.\n");
01981 
01982    ast_copy_string(member->name, label, sizeof(member->name));
01983    ast_copy_string(member->user, label, sizeof(member->user));
01984    ast_copy_string(member->context, context, sizeof(member->context));
01985    member->allowguest = allowguest;
01986    member->prefs = prefs;
01987    while (var) {
01988       if (!strcasecmp(var->name, "username"))
01989          ast_copy_string(member->user, var->value, sizeof(member->user));
01990       else if (!strcasecmp(var->name, "disallow"))
01991          ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 0);
01992       else if (!strcasecmp(var->name, "allow"))
01993          ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 1);
01994       else if (!strcasecmp(var->name, "context"))
01995          ast_copy_string(member->context, var->value, sizeof(member->context));
01996       else if (!strcasecmp(var->name, "parkinglot"))
01997          ast_copy_string(member->parkinglot, var->value, sizeof(member->parkinglot));
01998       else if (!strcasecmp(var->name, "connection")) {
01999          if ((client = ast_aji_get_client(var->value))) {
02000             member->connection = client;
02001             iks_filter_add_rule(client->f, gtalk_parser, member,
02002                       IKS_RULE_TYPE, IKS_PAK_IQ,
02003                       IKS_RULE_FROM_PARTIAL, member->user,
02004                       IKS_RULE_NS, GOOGLE_NS,
02005                       IKS_RULE_DONE);
02006          } else {
02007             ast_log(LOG_ERROR, "connection referenced not found!\n");
02008             return 0;
02009          }
02010       }
02011       var = var->next;
02012    }
02013    if (member->connection && member->user)
02014       member->buddy = ASTOBJ_CONTAINER_FIND(&member->connection->buddies, member->user);
02015    else {
02016       ast_log(LOG_ERROR, "No Connection or Username!\n");
02017    }
02018    return 1;
02019 }
02020 
02021 static int gtalk_load_config(void)
02022 {
02023    char *cat = NULL;
02024    struct ast_config *cfg = NULL;
02025    char context[AST_MAX_CONTEXT];
02026    char parkinglot[AST_MAX_CONTEXT];
02027    int allowguest = 1;
02028    struct ast_variable *var;
02029    struct gtalk *member;
02030    struct ast_codec_pref prefs;
02031    struct aji_client_container *clients;
02032    struct gtalk_candidate *global_candidates = NULL;
02033    struct hostent *hp;
02034    struct ast_hostent ahp;
02035    struct ast_flags config_flags = { 0 };
02036 
02037    cfg = ast_config_load(GOOGLE_CONFIG, config_flags);
02038    if (!cfg) {
02039       return 0;
02040    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
02041       ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", GOOGLE_CONFIG);
02042       return 0;
02043    }
02044 
02045    /* Copy the default jb config over global_jbconf */
02046    memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
02047 
02048    /* set defaults */
02049    memset(&stunaddr, 0, sizeof(stunaddr));
02050 
02051    cat = ast_category_browse(cfg, NULL);
02052    for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
02053       /* handle jb conf */
02054       if (!ast_jb_read_conf(&global_jbconf, var->name, var->value))
02055          continue;
02056 
02057       if (!strcasecmp(var->name, "allowguest")) {
02058          allowguest = (ast_true(ast_variable_retrieve(cfg, "general", "allowguest"))) ? 1 : 0;
02059       } else if (!strcasecmp(var->name, "disallow")) {
02060          ast_parse_allow_disallow(&prefs, &global_capability, var->value, 0);
02061       } else if (!strcasecmp(var->name, "allow")) {
02062          ast_parse_allow_disallow(&prefs, &global_capability, var->value, 1);
02063       } else if (!strcasecmp(var->name, "context")) {
02064          ast_copy_string(context, var->value, sizeof(context));
02065       } else if (!strcasecmp(var->name, "externip")) {
02066          ast_copy_string(externip, var->value, sizeof(externip));
02067       } else if (!strcasecmp(var->name, "parkinglot")) {
02068          ast_copy_string(parkinglot, var->value, sizeof(parkinglot));
02069       } else if (!strcasecmp(var->name, "bindaddr")) {
02070          if (!(hp = ast_gethostbyname(var->value, &ahp))) {
02071             ast_log(LOG_WARNING, "Invalid address: %s\n", var->value);
02072          } else {
02073             memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
02074          }
02075       } else if (!strcasecmp(var->name, "stunaddr")) {
02076          stunaddr.sin_port = htons(STANDARD_STUN_PORT);
02077          if (ast_parse_arg(var->value, PARSE_INADDR, &stunaddr)) {
02078             ast_log(LOG_WARNING, "Invalid STUN server address: %s\n", var->value);
02079          }
02080       }
02081    }
02082    while (cat) {
02083       if (strcasecmp(cat, "general")) {
02084          var = ast_variable_browse(cfg, cat);
02085          member = ast_calloc(1, sizeof(*member));
02086          ASTOBJ_INIT(member);
02087          ASTOBJ_WRLOCK(member);
02088          if (!strcasecmp(cat, "guest")) {
02089             ast_copy_string(member->name, "guest", sizeof(member->name));
02090             ast_copy_string(member->user, "guest", sizeof(member->user));
02091             ast_copy_string(member->context, context, sizeof(member->context));
02092             ast_copy_string(member->parkinglot, parkinglot, sizeof(member->parkinglot));
02093             member->allowguest = allowguest;
02094             member->prefs = prefs;
02095             while (var) {
02096                if (!strcasecmp(var->name, "disallow")) {
02097                   ast_parse_allow_disallow(&member->prefs, &member->capability,
02098                                      var->value, 0);
02099                } else if (!strcasecmp(var->name, "allow")) {
02100                   ast_parse_allow_disallow(&member->prefs, &member->capability,
02101                                      var->value, 1);
02102                } else if (!strcasecmp(var->name, "context")) {
02103                   ast_copy_string(member->context, var->value,
02104                               sizeof(member->context));
02105                } else if (!strcasecmp(var->name, "parkinglot")) {
02106                   ast_copy_string(member->parkinglot, var->value,
02107                               sizeof(member->parkinglot));
02108                }
02109                var = var->next;
02110             }
02111             ASTOBJ_UNLOCK(member);
02112             clients = ast_aji_get_clients();
02113             if (clients) {
02114                ASTOBJ_CONTAINER_TRAVERSE(clients, 1, {
02115                   ASTOBJ_WRLOCK(iterator);
02116                   ASTOBJ_WRLOCK(member);
02117                   member->connection = NULL;
02118                   iks_filter_add_rule(iterator->f, gtalk_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, GOOGLE_NS, IKS_RULE_DONE);
02119                   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);
02120                   ASTOBJ_UNLOCK(member);
02121                   ASTOBJ_UNLOCK(iterator);
02122                });
02123                ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
02124                ASTOBJ_UNREF(member, gtalk_member_destroy);
02125             } else {
02126                ASTOBJ_UNLOCK(member);
02127                ASTOBJ_UNREF(member, gtalk_member_destroy);
02128             }
02129          } else {
02130             ASTOBJ_UNLOCK(member);
02131             if (gtalk_create_member(cat, var, allowguest, prefs, context, member))
02132                ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
02133             ASTOBJ_UNREF(member, gtalk_member_destroy);
02134          }
02135       }
02136       cat = ast_category_browse(cfg, cat);
02137    }
02138 
02139    gtalk_update_externip();
02140    gtalk_free_candidates(global_candidates);
02141    return 1;
02142 }
02143 
02144 /*! \brief Load module into PBX, register channel */
02145 static int load_module(void)
02146 {
02147    struct ast_sockaddr bindaddr_tmp;
02148    struct ast_sockaddr ourip_tmp;
02149 
02150    char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
02151    free(jabber_loaded);
02152    if (!jabber_loaded) {
02153       /* If embedded, check for a different module name */
02154       jabber_loaded = ast_module_helper("", "res_jabber", 0, 0, 0, 0);
02155       free(jabber_loaded);
02156       if (!jabber_loaded) {
02157          ast_log(LOG_ERROR, "chan_gtalk.so depends upon res_jabber.so\n");
02158          return AST_MODULE_LOAD_DECLINE;
02159       }
02160    }
02161 
02162    ASTOBJ_CONTAINER_INIT(&gtalk_list);
02163    if (!gtalk_load_config()) {
02164       ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", GOOGLE_CONFIG);
02165       return 0;
02166    }
02167 
02168    sched = sched_context_create();
02169    if (!sched) {
02170       ast_log(LOG_WARNING, "Unable to create schedule context\n");
02171    }
02172 
02173    io = io_context_create();
02174    if (!io) {
02175       ast_log(LOG_WARNING, "Unable to create I/O context\n");
02176    }
02177 
02178    ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
02179    if (gtalk_get_local_ip(&ourip_tmp)) {
02180       ast_log(LOG_WARNING, "Unable to get own IP address, Gtalk disabled\n");
02181       return 0;
02182    }
02183    __ourip.s_addr = htonl(ast_sockaddr_ipv4(&ourip_tmp));
02184 
02185    ast_rtp_glue_register(&gtalk_rtp_glue);
02186    ast_cli_register_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
02187 
02188    /* Make sure we can register our channel type */
02189    if (ast_channel_register(&gtalk_tech)) {
02190       ast_log(LOG_ERROR, "Unable to register channel class %s\n", gtalk_tech.type);
02191       return -1;
02192    }
02193    return 0;
02194 }
02195 
02196 /*! \brief Reload module
02197  *  \todo XXX TODO make this work. */
02198 #if 0
02199 static int reload(void)
02200 {
02201    return 0;
02202 }
02203 #endif
02204 /*! \brief Unload the gtalk channel from Asterisk */
02205 static int unload_module(void)
02206 {
02207    struct gtalk_pvt *privates = NULL;
02208    ast_cli_unregister_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
02209    /* First, take us out of the channel loop */
02210    ast_channel_unregister(&gtalk_tech);
02211    ast_rtp_glue_unregister(&gtalk_rtp_glue);
02212 
02213    if (!ast_mutex_lock(&gtalklock)) {
02214       /* Hangup all interfaces if they have an owner */
02215       ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
02216          ASTOBJ_WRLOCK(iterator);
02217          privates = iterator->p;
02218          while(privates) {
02219             if (privates->owner)
02220                ast_softhangup(privates->owner, AST_SOFTHANGUP_APPUNLOAD);
02221             privates = privates->next;
02222          }
02223          iterator->p = NULL;
02224          ASTOBJ_UNLOCK(iterator);
02225       });
02226       ast_mutex_unlock(&gtalklock);
02227    } else {
02228       ast_log(LOG_WARNING, "Unable to lock the monitor\n");
02229       return -1;
02230    }
02231    ASTOBJ_CONTAINER_DESTROYALL(&gtalk_list, gtalk_member_destroy);
02232    ASTOBJ_CONTAINER_DESTROY(&gtalk_list);
02233    return 0;
02234 }
02235 
02236 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Gtalk Channel Driver",
02237       .load = load_module,
02238       .unload = unload_module,
02239       /* .reload = reload, */
02240       .load_pri = AST_MODPRI_CHANNEL_DRIVER,
02241       );

Generated on Sat Mar 26 11:06:58 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9