Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:04 2007

Asterisk developer's documentation :: Codename Pineapple


chan_gtalk.c File Reference


Detailed Description

Gtalk Channel Driver, until google/libjingle works with jingle spec.

Author:
Matt O'Gorman <mogorman@digium.com>

Definition in file chan_gtalk.c.

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/signal.h>
#include <iksemel.h>
#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/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/manager.h"
#include "asterisk/stringfields.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/astobj.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/jabber.h"

Include dependency graph for chan_gtalk.c:

Go to the source code of this file.

Data Structures

struct  gtalk
struct  gtalk_candidate
struct  gtalk_container
struct  gtalk_pvt

Defines

#define GOOGLE_CONFIG   "gtalk.conf"
#define GOOGLE_NS   "http://www.google.com/session"

Enumerations

enum  gtalk_connect_type { AJI_CONNECT_STUN = 1, AJI_CONNECT_LOCAL = 2, AJI_CONNECT_RELAY = 3 }
enum  gtalk_protocol { AJI_PROTOCOL_UDP = 1, AJI_PROTOCOL_SSLTCP = 2 }

Functions

static int add_codec_to_answer (const struct gtalk_pvt *p, int codec, iks *dcodecs)
 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Gtalk Channel Driver",.load=load_module,.unload=unload_module,.reload=reload,)
 AST_MUTEX_DEFINE_STATIC (gtalklock)
static struct gtalkfind_gtalk (char *name, char *connection)
static int gtalk_action (struct gtalk *client, struct gtalk_pvt *p, const char *action)
static int gtalk_add_candidate (struct gtalk *client, ikspak *pak)
static struct gtalk_pvtgtalk_alloc (struct gtalk *client, const char *us, const char *them, const char *sid)
static int gtalk_answer (struct ast_channel *ast)
static int gtalk_call (struct ast_channel *ast, char *dest, int timeout)
 Initiate new call, part of PBX interface dest is the dial string.
static int gtalk_create_candidates (struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from, char *to)
static int gtalk_create_member (char *label, struct ast_variable *var, int allowguest, struct ast_codec_pref prefs, char *context, struct gtalk *member)
static int gtalk_digit (struct ast_channel *ast, char digit, unsigned int duration)
static int gtalk_digit_begin (struct ast_channel *ast, char digit)
static int gtalk_digit_end (struct ast_channel *ast, char digit, unsigned int duration)
static int gtalk_do_reload (int fd, int argc, char **argv)
 CLI command "gtalk show channels".
static int gtalk_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static void gtalk_free_candidates (struct gtalk_candidate *candidate)
static void gtalk_free_pvt (struct gtalk *client, struct gtalk_pvt *p)
static int gtalk_get_codec (struct ast_channel *chan)
static enum ast_rtp_get_result gtalk_get_rtp_peer (struct ast_channel *chan, struct ast_rtp **rtp)
static int gtalk_handle_dtmf (struct gtalk *client, ikspak *pak)
static int gtalk_hangup (struct ast_channel *ast)
 Hangup a call through the gtalk proxy channel.
static int gtalk_hangup_farend (struct gtalk *client, ikspak *pak)
static int gtalk_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen)
static int gtalk_invite (struct gtalk_pvt *p, char *to, char *from, char *sid, int initiator)
static int gtalk_invite_response (struct gtalk_pvt *p, char *to, char *from, char *sid, int initiator)
static int gtalk_is_answered (struct gtalk *client, ikspak *pak)
static int gtalk_load_config (void)
static void gtalk_member_destroy (struct gtalk *obj)
static struct ast_channelgtalk_new (struct gtalk *client, struct gtalk_pvt *i, int state, const char *title)
 Start new gtalk channel.
static int gtalk_newcall (struct gtalk *client, ikspak *pak)
static int gtalk_parser (void *data, ikspak *pak)
static struct ast_framegtalk_read (struct ast_channel *ast)
static struct ast_channelgtalk_request (const char *type, int format, void *data, int *cause)
 Part of PBX interface.
static int gtalk_response (struct gtalk *client, char *from, ikspak *pak, const char *reasonstr, const char *reasonstr2)
static int gtalk_ringing_ack (void *data, ikspak *pak)
static struct ast_framegtalk_rtp_read (struct ast_channel *ast, struct gtalk_pvt *p)
static int gtalk_sendhtml (struct ast_channel *ast, int subclass, const char *data, int datalen)
static int gtalk_set_rtp_peer (struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
static int gtalk_show_channels (int fd, int argc, char **argv)
 CLI command "gtalk show channels".
static int gtalk_update_stun (struct gtalk *client, struct gtalk_pvt *p)
static int gtalk_write (struct ast_channel *ast, struct ast_frame *frame)
 Send frame to media channel (rtp).
static int load_module (void)
 Load module into PBX, register channel.
static int reload (void)
 Reload module.
static int unload_module (void)
 Unload the gtalk channel from Asterisk.

Variables

static struct in_addr __ourip
static struct sockaddr_in bindaddr = { 0, }
static const char debug_usage []
static struct ast_jb_conf default_jbconf
static const char desc [] = "Gtalk Channel"
static char externip [16]
static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263
static struct ast_jb_conf global_jbconf
static struct ast_cli_entry gtalk_cli []
static struct gtalk_container gtalk_list
static struct ast_rtp_protocol gtalk_rtp
 RTP driver interface.
static const struct ast_channel_tech gtalk_tech
 PBX interface structure for channel registration.
static struct io_contextio
static const char reload_usage []
static struct sched_contextsched


Define Documentation

#define GOOGLE_CONFIG   "gtalk.conf"
 

Definition at line 75 of file chan_gtalk.c.

Referenced by gtalk_load_config(), and load_module().

#define GOOGLE_NS   "http://www.google.com/session"
 

Definition at line 77 of file chan_gtalk.c.


Enumeration Type Documentation

enum gtalk_connect_type
 

Enumerator:
AJI_CONNECT_STUN 
AJI_CONNECT_LOCAL 
AJI_CONNECT_RELAY 

Definition at line 95 of file chan_gtalk.c.

00095                         {
00096    AJI_CONNECT_STUN = 1,
00097    AJI_CONNECT_LOCAL = 2,
00098    AJI_CONNECT_RELAY = 3,
00099 };

enum gtalk_protocol
 

Enumerator:
AJI_PROTOCOL_UDP 
AJI_PROTOCOL_SSLTCP 

Definition at line 90 of file chan_gtalk.c.

00090                     {
00091    AJI_PROTOCOL_UDP = 1,
00092    AJI_PROTOCOL_SSLTCP = 2,
00093 };


Function Documentation

static int add_codec_to_answer const struct gtalk_pvt p,
int  codec,
iks *  dcodecs
[static]
 

Definition at line 292 of file chan_gtalk.c.

References ast_getformatname(), ast_log(), ast_rtp_lookup_code(), format, LOG_WARNING, gtalk::p, and gtalk_pvt::rtp.

Referenced by gtalk_invite(), and jingle_accept_call().

00293 {
00294    char *format = ast_getformatname(codec);
00295 
00296    if (!strcasecmp("ulaw", format)) {
00297       iks *payload_eg711u, *payload_pcmu;
00298       payload_pcmu = iks_new("payload-type");
00299       payload_eg711u = iks_new("payload-type");
00300    
00301       if(!payload_eg711u || !payload_pcmu) {
00302          if(payload_pcmu)
00303             iks_delete(payload_pcmu);
00304          if(payload_eg711u)
00305             iks_delete(payload_eg711u);
00306          ast_log(LOG_WARNING,"Failed to allocate iks node");
00307          return -1;
00308       }
00309       iks_insert_attrib(payload_pcmu, "id", "0");
00310       iks_insert_attrib(payload_pcmu, "name", "PCMU");
00311       iks_insert_attrib(payload_pcmu, "clockrate","8000");
00312       iks_insert_attrib(payload_pcmu, "bitrate","64000");
00313       iks_insert_attrib(payload_eg711u, "id", "100");
00314       iks_insert_attrib(payload_eg711u, "name", "EG711U");
00315       iks_insert_attrib(payload_eg711u, "clockrate","8000");
00316       iks_insert_attrib(payload_eg711u, "bitrate","64000");
00317       iks_insert_node(dcodecs, payload_pcmu);
00318       iks_insert_node(dcodecs, payload_eg711u);
00319    }
00320    if (!strcasecmp("alaw", format)) {
00321       iks *payload_eg711a, *payload_pcma;
00322       payload_pcma = iks_new("payload-type");
00323       payload_eg711a = iks_new("payload-type");
00324       if(!payload_eg711a || !payload_pcma) {
00325          if(payload_eg711a)
00326             iks_delete(payload_eg711a);
00327          if(payload_pcma)
00328             iks_delete(payload_pcma);
00329          ast_log(LOG_WARNING,"Failed to allocate iks node");
00330          return -1;
00331       }
00332       iks_insert_attrib(payload_pcma, "id", "8");
00333       iks_insert_attrib(payload_pcma, "name", "PCMA");
00334       iks_insert_attrib(payload_pcma, "clockrate","8000");
00335       iks_insert_attrib(payload_pcma, "bitrate","64000");
00336       payload_eg711a = iks_new("payload-type");
00337       iks_insert_attrib(payload_eg711a, "id", "101");
00338       iks_insert_attrib(payload_eg711a, "name", "EG711A");
00339       iks_insert_attrib(payload_eg711a, "clockrate","8000");
00340       iks_insert_attrib(payload_eg711a, "bitrate","64000");
00341       iks_insert_node(dcodecs, payload_pcma);
00342       iks_insert_node(dcodecs, payload_eg711a);
00343    }
00344    if (!strcasecmp("ilbc", format)) {
00345       iks *payload_ilbc = iks_new("payload-type");
00346       if(!payload_ilbc) {
00347          ast_log(LOG_WARNING,"Failed to allocate iks node");
00348          return -1;
00349       }
00350       iks_insert_attrib(payload_ilbc, "id", "102");
00351       iks_insert_attrib(payload_ilbc, "name", "iLBC");
00352       iks_insert_attrib(payload_ilbc, "clockrate","8000");
00353       iks_insert_attrib(payload_ilbc, "bitrate","13300");
00354       iks_insert_node(dcodecs, payload_ilbc);
00355    }
00356    if (!strcasecmp("g723", format)) {
00357       iks *payload_g723 = iks_new("payload-type");
00358       if(!payload_g723) {
00359          ast_log(LOG_WARNING,"Failed to allocate iks node");
00360          return -1;
00361       }
00362       iks_insert_attrib(payload_g723, "id", "4");
00363       iks_insert_attrib(payload_g723, "name", "G723");
00364       iks_insert_attrib(payload_g723, "clockrate","8000");
00365       iks_insert_attrib(payload_g723, "bitrate","6300");
00366       iks_insert_node(dcodecs, payload_g723);
00367    }
00368    if (!strcasecmp("speex", format)) {
00369       iks *payload_speex = iks_new("payload-type");
00370       if(!payload_speex) {
00371          ast_log(LOG_WARNING,"Failed to allocate iks node");
00372          return -1;
00373       }
00374       iks_insert_attrib(payload_speex, "id", "98");
00375       iks_insert_attrib(payload_speex, "name", "speex");
00376       iks_insert_attrib(payload_speex, "clockrate","8000");
00377       iks_insert_attrib(payload_speex, "bitrate","11000");
00378       iks_insert_node(dcodecs, payload_speex);
00379    }
00380    ast_rtp_lookup_code(p->rtp, 1, codec);
00381    return 0;
00382 }

AST_MODULE_INFO ASTERISK_GPL_KEY  ,
AST_MODFLAG_DEFAULT  ,
"Gtalk Channel Driver"  ,
load = load_module,
unload = unload_module,
reload = reload
 

AST_MUTEX_DEFINE_STATIC gtalklock   ) 
 

Protect the interface list (of gtalk_pvt's)

static struct gtalk* find_gtalk char *  name,
char *  connection
[static]
 

Definition at line 255 of file chan_gtalk.c.

References ast_strdupa, ast_verbose(), ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_FIND_FULL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_WRLOCK, free, gtalk_list, s, strsep(), and gtalk::user.

Referenced by gtalk_request().

00256 {
00257    struct gtalk *gtalk = NULL;
00258    char *domain = NULL , *s = NULL;
00259    if(strchr(connection, '@')) {
00260       s = ast_strdupa((char *) connection);
00261       domain = strsep(&s, "@");
00262       ast_verbose("OOOOH domain = %s\n", domain);
00263       free(s);
00264    }
00265    gtalk = ASTOBJ_CONTAINER_FIND(&gtalk_list, name);
00266    if (!gtalk && strchr(name, '@'))
00267       gtalk = ASTOBJ_CONTAINER_FIND_FULL(&gtalk_list, name, user,,, strcasecmp);
00268 
00269    if (!gtalk) {           /* guest call */
00270       ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
00271          ASTOBJ_WRLOCK(iterator);
00272          if (!strcasecmp(iterator->name, "guest")) {
00273             if (!strcasecmp(iterator->connection->jid->partial, connection)) {
00274                gtalk = iterator;
00275                break;
00276             } else if (!strcasecmp(iterator->connection->name, connection)) {
00277                gtalk = iterator;
00278                break;
00279             } else if (iterator->connection->component && !strcasecmp(iterator->connection->user,domain)) {
00280                gtalk = iterator;
00281                break;
00282             }
00283          }
00284          ASTOBJ_UNLOCK(iterator);
00285       });
00286 
00287    }
00288    return gtalk;
00289 }

static int gtalk_action struct gtalk client,
struct gtalk_pvt p,
const char *  action
[static]
 

Definition at line 978 of file chan_gtalk.c.

References ast_aji_increment_mid(), gtalk::connection, gtalk_pvt::initiator, aji_client::mid, aji_client::p, gtalk_pvt::sid, gtalk_pvt::them, and gtalk_pvt::us.

Referenced by gtalk_hangup().

00979 {
00980    iks *request, *session = NULL;
00981    int res = -1;
00982 
00983    request = iks_new("iq");
00984    if (request) {
00985       iks_insert_attrib(request, "type", "set");
00986       iks_insert_attrib(request, "from", p->us);
00987       iks_insert_attrib(request, "to", p->them);
00988       iks_insert_attrib(request, "id", client->connection->mid);
00989       ast_aji_increment_mid(client->connection->mid);
00990       session = iks_new("session");
00991       if (session) {
00992          iks_insert_attrib(session, "type", action);
00993          iks_insert_attrib(session, "id", p->sid);
00994          iks_insert_attrib(session, "initiator", p->initiator ? p->us : p->them);
00995          iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
00996          iks_insert_node(request, session);
00997          iks_send(client->connection->p, request);
00998          iks_delete(session);
00999          res = 0;
01000       }
01001       iks_delete(request);
01002    }
01003    return res;
01004 }

static int gtalk_add_candidate struct gtalk client,
ikspak *  pak
[static]
 

Definition at line 1140 of file chan_gtalk.c.

References AJI_CONNECT_LOCAL, AJI_CONNECT_RELAY, AJI_CONNECT_STUN, AJI_PROTOCOL_SSLTCP, AJI_PROTOCOL_UDP, ast_calloc, gtalk::connection, gtalk_update_stun(), aji_client::jid, gtalk_pvt::laststun, gtalk_pvt::next, aji_client::p, gtalk::p, gtalk_pvt::parent, gtalk_candidate::receipt, and gtalk_pvt::theircandidates.

Referenced by gtalk_parser().

01141 {
01142    struct gtalk_pvt *p = NULL, *tmp = NULL;
01143    struct aji_client *c = client->connection;
01144    struct gtalk_candidate *newcandidate = NULL;
01145    iks *traversenodes = NULL, *receipt = NULL;
01146    char *from;
01147 
01148    from = iks_find_attrib(pak->x,"to");
01149    if(!from)
01150       from = c->jid->full;
01151 
01152    newcandidate = ast_calloc(1, sizeof(*newcandidate));
01153    if (!newcandidate)
01154       return 0;
01155    for (tmp = client->p; tmp; tmp = tmp->next) {
01156       if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
01157          p = tmp;
01158          break;
01159       }
01160    }
01161 
01162    if (!p)
01163       return -1;
01164 
01165    traversenodes = pak->query;
01166    while(traversenodes) {
01167       if(!strcasecmp(iks_name(traversenodes), "session")) {
01168          traversenodes = iks_child(traversenodes);
01169          continue;
01170       }
01171       if(!strcasecmp(iks_name(traversenodes), "transport")) {
01172          traversenodes = iks_child(traversenodes);
01173          continue;
01174       }
01175       if(!strcasecmp(iks_name(traversenodes), "candidate")) {
01176          newcandidate = ast_calloc(1, sizeof(*newcandidate));
01177          if (!newcandidate)
01178             return 0;
01179          ast_copy_string(newcandidate->name, iks_find_attrib(traversenodes, "name"),
01180                      sizeof(newcandidate->name));
01181          ast_copy_string(newcandidate->ip, iks_find_attrib(traversenodes, "address"),
01182                      sizeof(newcandidate->ip));
01183          newcandidate->port = atoi(iks_find_attrib(traversenodes, "port"));
01184          ast_copy_string(newcandidate->username, iks_find_attrib(traversenodes, "username"),
01185                      sizeof(newcandidate->username));
01186          ast_copy_string(newcandidate->password, iks_find_attrib(traversenodes, "password"),
01187                      sizeof(newcandidate->password));
01188          newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference"));
01189          if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "udp"))
01190             newcandidate->protocol = AJI_PROTOCOL_UDP;
01191          if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "ssltcp"))
01192             newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
01193       
01194          if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "stun"))
01195             newcandidate->type = AJI_CONNECT_STUN;
01196          if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "local"))
01197             newcandidate->type = AJI_CONNECT_LOCAL;
01198          if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "relay"))
01199             newcandidate->type = AJI_CONNECT_RELAY;
01200          ast_copy_string(newcandidate->network, iks_find_attrib(traversenodes, "network"),
01201                      sizeof(newcandidate->network));
01202          newcandidate->generation = atoi(iks_find_attrib(traversenodes, "generation"));
01203          newcandidate->next = NULL;
01204       
01205          newcandidate->next = p->theircandidates;
01206          p->theircandidates = newcandidate;
01207          p->laststun = 0;
01208          gtalk_update_stun(p->parent, p);
01209          newcandidate = NULL;
01210       }
01211       traversenodes = iks_next(traversenodes);
01212    }
01213    
01214    receipt = iks_new("iq");
01215    iks_insert_attrib(receipt, "type", "result");
01216    iks_insert_attrib(receipt, "from", from);
01217    iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
01218    iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
01219    iks_send(c->p, receipt);
01220    iks_delete(receipt);
01221 
01222    return 1;
01223 }

static struct gtalk_pvt * gtalk_alloc struct gtalk client,
const char *  us,
const char *  them,
const char *  sid
[static]
 

Definition at line 826 of file chan_gtalk.c.

References ast_calloc, ast_log(), ast_mutex_init(), ast_mutex_lock(), ast_mutex_unlock(), ast_random(), ast_rtp_new_with_bindaddr(), ast_strdupa, ASTOBJ_CONTAINER_FIND, bindaddr, aji_client::buddies, gtalk::buddy, aji_resource::cap, gtalk::connection, exten, free, io, aji_version::jingle, LOG_DEBUG, LOG_ERROR, LOG_WARNING, aji_resource::next, option_debug, gtalk::p, aji_resource::resource, aji_buddy::resources, and strsep().

Referenced by gtalk_newcall(), and gtalk_request().

00827 {
00828    struct gtalk_pvt *tmp = NULL;
00829    struct aji_resource *resources = NULL;
00830    struct aji_buddy *buddy;
00831    char idroster[200];
00832    char *data, *exten = NULL;
00833 
00834    if (option_debug)
00835       ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name);
00836    if (!sid && !strchr(them, '/')) {   /* I started call! */
00837       if (!strcasecmp(client->name, "guest")) {
00838          buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, them);
00839          if (buddy)
00840             resources = buddy->resources;
00841       } else 
00842          resources = client->buddy->resources;
00843       while (resources) {
00844          if (resources->cap->jingle) {
00845             break;
00846          }
00847          resources = resources->next;
00848       }
00849       if (resources)
00850          snprintf(idroster, sizeof(idroster), "%s/%s", them, resources->resource);
00851       else {
00852          ast_log(LOG_ERROR, "no gtalk capable clients to talk to.\n");
00853          return NULL;
00854       }
00855    }
00856    if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
00857       return NULL;
00858    }
00859    if (sid) {
00860       ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
00861       ast_copy_string(tmp->them, them, sizeof(tmp->them));
00862       ast_copy_string(tmp->us, us, sizeof(tmp->us));
00863    } else {
00864       snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random());
00865       ast_copy_string(tmp->them, idroster, sizeof(tmp->them));
00866       ast_copy_string(tmp->us, us, sizeof(tmp->us));
00867       tmp->initiator = 1;
00868    }
00869    tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
00870    tmp->parent = client;
00871    if (!tmp->rtp) {
00872       ast_log(LOG_WARNING, "Out of RTP sessions?\n");
00873       free(tmp);
00874       return NULL;
00875    }
00876 
00877    if(strchr(tmp->us, '/')) {
00878       data = ast_strdupa((char *) tmp->us);
00879       exten = strsep(&data, "/");
00880    } else
00881       exten = tmp->us;
00882    ast_copy_string(tmp->exten,  exten, sizeof(tmp->exten));
00883    if(data)
00884       free(data);
00885    ast_mutex_init(&tmp->lock);
00886    ast_mutex_lock(&gtalklock);
00887    tmp->next = client->p;
00888    client->p = tmp;
00889    ast_mutex_unlock(&gtalklock);
00890    return tmp;
00891 }

static int gtalk_answer struct ast_channel ast  )  [static]
 

Definition at line 505 of file chan_gtalk.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), gtalk_invite(), gtalk_pvt::lock, LOG_DEBUG, option_debug, gtalk_pvt::sid, ast_channel::tech_pvt, gtalk_pvt::them, and gtalk_pvt::us.

00506 {
00507    struct gtalk_pvt *p = ast->tech_pvt;
00508    int res = 0;
00509    
00510    if (option_debug)
00511       ast_log(LOG_DEBUG, "Answer!\n");
00512    ast_mutex_lock(&p->lock);
00513    gtalk_invite(p, p->them, p->us,p->sid, 0);
00514    ast_mutex_unlock(&p->lock);
00515    return res;
00516 }

static int gtalk_call struct ast_channel ast,
char *  dest,
int  timeout
[static]
 

Initiate new call, part of PBX interface dest is the dial string.

Definition at line 1429 of file chan_gtalk.c.

References ast_channel::_state, ast_log(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RING, gtalk_pvt::capability, gtalk::connection, aji_client::f, gtalk_create_candidates(), gtalk_invite(), gtalk_ringing_ack(), gtalk_pvt::jointcapability, LOG_WARNING, aji_client::mid, gtalk_pvt::parent, gtalk_pvt::ring, gtalk_pvt::ringrule, gtalk_pvt::sid, ast_channel::tech_pvt, gtalk_pvt::them, and gtalk_pvt::us.

01430 {
01431    struct gtalk_pvt *p = ast->tech_pvt;
01432 
01433    if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
01434       ast_log(LOG_WARNING, "gtalk_call called on %s, neither down nor reserved\n", ast->name);
01435       return -1;
01436    }
01437 
01438    ast_setstate(ast, AST_STATE_RING);
01439    p->jointcapability = p->capability;
01440    if (!p->ringrule) {
01441       ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
01442       p->ringrule = iks_filter_add_rule(p->parent->connection->f, gtalk_ringing_ack, p,
01443                      IKS_RULE_ID, p->ring, IKS_RULE_DONE);
01444    } else
01445       ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
01446 
01447    gtalk_invite(p, p->them, p->us, p->sid, 1);
01448    gtalk_create_candidates(p->parent, p, p->sid, p->them, p->us);
01449 
01450    return 0;
01451 }

static int gtalk_create_candidates struct gtalk client,
struct gtalk_pvt p,
char *  sid,
char *  from,
char *  to
[static]
 

Definition at line 698 of file chan_gtalk.c.

References ast_calloc, ast_log(), gtalk::connection, LOG_ERROR, gtalk_pvt::next, and gtalk_pvt::sid.

Referenced by gtalk_call(), and gtalk_newcall().

00699 {
00700    struct gtalk_candidate *tmp;
00701    struct aji_client *c = client->connection;
00702    struct gtalk_candidate *ours1 = NULL, *ours2 = NULL;
00703    struct sockaddr_in sin;
00704    struct sockaddr_in dest;
00705    struct in_addr us;
00706    iks *iq, *gtalk, *candidate, *transport;
00707    char user[17], pass[17], preference[5], port[7];
00708 
00709 
00710    iq = iks_new("iq");
00711    gtalk = iks_new("session");
00712    candidate = iks_new("candidate");
00713    transport = iks_new("transport");
00714    if (!iq || !gtalk || !candidate || !transport) {
00715       ast_log(LOG_ERROR, "Memory allocation error\n");
00716       goto safeout;
00717    }
00718    ours1 = ast_calloc(1, sizeof(*ours1));
00719    ours2 = ast_calloc(1, sizeof(*ours2));
00720    if (!ours1 || !ours2)
00721       goto safeout;
00722 
00723    iks_insert_attrib(transport, "xmlns","http://www.google.com/transport/p2p");
00724    iks_insert_node(iq, gtalk);
00725    iks_insert_node(gtalk,transport);
00726    iks_insert_node(transport, candidate);
00727 
00728    for (; p; p = p->next) {
00729       if (!strcasecmp(p->sid, sid))
00730          break;
00731    }
00732 
00733    if (!p) {
00734       ast_log(LOG_NOTICE, "No matching gtalk session - SID %s!\n", sid);
00735       goto safeout;
00736    }
00737 
00738    ast_rtp_get_us(p->rtp, &sin);
00739    ast_find_ourip(&us, bindaddr);
00740 
00741    /* Setup our gtalk candidates */
00742    ast_copy_string(ours1->name, "rtp", sizeof(ours1->name));
00743    ours1->port = ntohs(sin.sin_port);
00744    ours1->preference = 1;
00745    snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
00746    snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
00747    ast_copy_string(ours1->username, user, sizeof(ours1->username));
00748    ast_copy_string(ours1->password, pass, sizeof(ours1->password));
00749    ast_copy_string(ours1->ip, ast_inet_ntoa(us), sizeof(ours1->ip));
00750    ours1->protocol = AJI_PROTOCOL_UDP;
00751    ours1->type = AJI_CONNECT_LOCAL;
00752    ours1->generation = 0;
00753    p->ourcandidates = ours1;
00754 
00755    if (!ast_strlen_zero(externip)) {
00756       /* XXX We should really stun for this one not just go with externip XXX */
00757       snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
00758       snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
00759       ast_copy_string(ours2->username, user, sizeof(ours2->username));
00760       ast_copy_string(ours2->password, pass, sizeof(ours2->password));
00761       ast_copy_string(ours2->ip, externip, sizeof(ours2->ip));
00762       ast_copy_string(ours2->name, "rtp", sizeof(ours1->name));
00763       ours2->port = ntohs(sin.sin_port);
00764       ours2->preference = 0.9;
00765       ours2->protocol = AJI_PROTOCOL_UDP;
00766       ours2->type = AJI_CONNECT_STUN;
00767       ours2->generation = 0;
00768       ours1->next = ours2;
00769       ours2 = NULL;
00770    }
00771    ours1 = NULL;
00772    dest.sin_addr = __ourip;
00773    dest.sin_port = sin.sin_port;
00774 
00775 
00776    for (tmp = p->ourcandidates; tmp; tmp = tmp->next) {
00777       snprintf(port, sizeof(port), "%d", tmp->port);
00778       snprintf(preference, sizeof(preference), "%.2f", tmp->preference);
00779       iks_insert_attrib(iq, "from", to);
00780       iks_insert_attrib(iq, "to", from);
00781       iks_insert_attrib(iq, "type", "set");
00782       iks_insert_attrib(iq, "id", c->mid);
00783       ast_aji_increment_mid(c->mid);
00784       iks_insert_attrib(gtalk, "type", "transport-info");
00785       iks_insert_attrib(gtalk, "id", sid);
00786       iks_insert_attrib(gtalk, "initiator", (p->initiator) ? to : from);
00787       iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
00788       iks_insert_attrib(candidate, "name", tmp->name);
00789       iks_insert_attrib(candidate, "address", tmp->ip);
00790       iks_insert_attrib(candidate, "port", port);
00791       iks_insert_attrib(candidate, "username", tmp->username);
00792       iks_insert_attrib(candidate, "password", tmp->password);
00793       iks_insert_attrib(candidate, "preference", preference);
00794       if (tmp->protocol == AJI_PROTOCOL_UDP)
00795          iks_insert_attrib(candidate, "protocol", "udp");
00796       if (tmp->protocol == AJI_PROTOCOL_SSLTCP)
00797          iks_insert_attrib(candidate, "protocol", "ssltcp");
00798       if (tmp->type == AJI_CONNECT_STUN)
00799          iks_insert_attrib(candidate, "type", "stun");
00800       if (tmp->type == AJI_CONNECT_LOCAL)
00801          iks_insert_attrib(candidate, "type", "local");
00802       if (tmp->type == AJI_CONNECT_RELAY)
00803          iks_insert_attrib(candidate, "type", "relay");
00804       iks_insert_attrib(candidate, "network", "0");
00805       iks_insert_attrib(candidate, "generation", "0");
00806       iks_send(c->p, iq);
00807    }
00808    p->laststun = 0;
00809 
00810 safeout:
00811    if (ours1)
00812       free(ours1);
00813    if (ours2)
00814       free(ours2);
00815    if (iq)
00816       iks_delete(iq);
00817    if (gtalk)
00818       iks_delete(gtalk);
00819    if (candidate)
00820       iks_delete(candidate);
00821    if(transport)
00822       iks_delete(transport);
00823    return 1;
00824 }

static int gtalk_create_member char *  label,
struct ast_variable var,
int  allowguest,
struct ast_codec_pref  prefs,
char *  context,
struct gtalk member
[static]
 

Definition at line 1602 of file chan_gtalk.c.

References gtalk::allowguest, ast_aji_get_client(), ast_log(), ast_parse_allow_disallow(), ASTOBJ_CONTAINER_FIND, aji_client::buddies, gtalk::buddy, gtalk::capability, gtalk::connection, gtalk::context, aji_client::f, gtalk_parser(), LOG_ERROR, LOG_WARNING, gtalk_candidate::next, prefs, gtalk::prefs, gtalk::user, and var.

01605 {
01606    struct aji_client *client;
01607 
01608    if (!member)
01609