Codename Pineapple

Home page | Mailing list | Docs

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

Asterisk developer's documentation :: Codename Pineapple


chan_jingle.c File Reference


Detailed Description

Jingle Channel Driver.

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

Definition in file chan_jingle.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 "asterisk/jingle.h"

Include dependency graph for chan_jingle.c:

Go to the source code of this file.

Data Structures

struct  jingle
struct  jingle_candidate
struct  jingle_container
struct  jingle_pvt

Defines

#define JINGLE_CONFIG   "jingle.conf"

Enumerations

enum  jingle_connect_type { AJI_CONNECT_STUN = 1, AJI_CONNECT_LOCAL = 2, AJI_CONNECT_RELAY = 3 }
enum  jingle_protocol { AJI_PROTOCOL_UDP = 1, AJI_PROTOCOL_SSLTCP = 2 }

Functions

static void add_codec_to_answer (const struct jingle_pvt *p, int codec, iks *dcodecs)
 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Jingle Channel Driver",.load=load_module,.unload=unload_module,.reload=reload,)
 AST_MUTEX_DEFINE_STATIC (jinglelock)
static struct jinglefind_jingle (char *name, char *connection)
static int jingle_accept_call (struct jingle *client, struct jingle_pvt *p)
static int jingle_action (struct jingle *client, struct jingle_pvt *p, const char *action)
static int jingle_add_candidate (struct jingle *client, ikspak *pak)
static struct jingle_pvtjingle_alloc (struct jingle *client, const char *from, const char *sid)
static int jingle_answer (struct ast_channel *ast)
static int jingle_call (struct ast_channel *ast, char *dest, int timeout)
 Initiate new call, part of PBX interface dest is the dial string.
static int jingle_create_candidates (struct jingle *client, struct jingle_pvt *p, char *sid, char *from)
static int jingle_create_member (char *label, struct ast_variable *var, int allowguest, struct ast_codec_pref prefs, char *context, struct jingle *member)
static int jingle_digit (struct ast_channel *ast, char digit, unsigned int duration)
static int jingle_digit_begin (struct ast_channel *ast, char digit)
static int jingle_digit_end (struct ast_channel *ast, char digit, unsigned int duration)
static int jingle_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static void jingle_free_candidates (struct jingle_candidate *candidate)
static void jingle_free_pvt (struct jingle *client, struct jingle_pvt *p)
static int jingle_get_codec (struct ast_channel *chan)
static enum ast_rtp_get_result jingle_get_rtp_peer (struct ast_channel *chan, struct ast_rtp **rtp)
static int jingle_handle_dtmf (struct jingle *client, ikspak *pak)
static int jingle_hangup (struct ast_channel *ast)
 Hangup a call through the jingle proxy channel.
static int jingle_hangup_farend (struct jingle *client, ikspak *pak)
static int jingle_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen)
static int jingle_is_answered (struct jingle *client, ikspak *pak)
static int jingle_load_config (void)
static void jingle_member_destroy (struct jingle *obj)
static struct ast_channeljingle_new (struct jingle *client, struct jingle_pvt *i, int state, const char *title)
 Start new jingle channel.
static int jingle_newcall (struct jingle *client, ikspak *pak)
static int jingle_parser (void *data, ikspak *pak)
static struct ast_framejingle_read (struct ast_channel *ast)
static struct ast_channeljingle_request (const char *type, int format, void *data, int *cause)
 Part of PBX interface.
static int jingle_response (struct jingle *client, ikspak *pak, const char *reasonstr, const char *reasonstr2)
static int jingle_ringing_ack (void *data, ikspak *pak)
static struct ast_framejingle_rtp_read (struct ast_channel *ast, struct jingle_pvt *p)
static int jingle_sendhtml (struct ast_channel *ast, int subclass, const char *data, int datalen)
static int jingle_set_rtp_peer (struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
static int jingle_transmit_invite (struct jingle_pvt *p)
static int jingle_update_stun (struct jingle *client, struct jingle_pvt *p)
static int jingle_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 jingle channel from Asterisk.

Variables

static struct in_addr __ourip
static struct sockaddr_in bindaddr = { 0, }
static struct ast_jb_conf default_jbconf
static const char desc [] = "Jingle 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 io_contextio
static struct ast_rtp_protocol jingle_rtp
 RTP driver interface.
static const struct ast_channel_tech jingle_tech
 PBX interface structure for channel registration.
static struct jingle_container jingles
static struct sched_contextsched
static const char type [] = "Jingle"


Define Documentation

#define JINGLE_CONFIG   "jingle.conf"
 

Definition at line 76 of file chan_jingle.c.

Referenced by jingle_load_config(), and load_module().


Enumeration Type Documentation

enum jingle_connect_type
 

Enumerator:
AJI_CONNECT_STUN 
AJI_CONNECT_LOCAL 
AJI_CONNECT_RELAY 

Definition at line 93 of file chan_jingle.c.

00093                          {
00094    AJI_CONNECT_STUN = 1,
00095    AJI_CONNECT_LOCAL = 2,
00096    AJI_CONNECT_RELAY = 3,
00097 };

enum jingle_protocol
 

Enumerator:
AJI_PROTOCOL_UDP 
AJI_PROTOCOL_SSLTCP 

Definition at line 88 of file chan_jingle.c.

00088                      {
00089    AJI_PROTOCOL_UDP = 1,
00090    AJI_PROTOCOL_SSLTCP = 2,
00091 };


Function Documentation

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

Definition at line 262 of file chan_jingle.c.

References ast_getformatname(), ast_rtp_lookup_code(), format, jingle::p, and jingle_pvt::rtp.

00263 {
00264    char *format = ast_getformatname(codec);
00265 
00266    if (!strcasecmp("ulaw", format)) {
00267       iks *payload_eg711u, *payload_pcmu;
00268       payload_pcmu = iks_new("payload-type");
00269       iks_insert_attrib(payload_pcmu, "id", "0");
00270       iks_insert_attrib(payload_pcmu, "name", "PCMU");
00271       iks_insert_attrib(payload_pcmu, "xmlns", "http://www.google.com/session/phone");
00272       payload_eg711u = iks_new("payload-type");
00273       iks_insert_attrib(payload_eg711u, "id", "100");
00274       iks_insert_attrib(payload_eg711u, "name", "EG711U");
00275       iks_insert_attrib(payload_eg711u, "xmlns", "http://www.google.com/session/phone");
00276       iks_insert_node(dcodecs, payload_pcmu);
00277       iks_insert_node(dcodecs, payload_eg711u);
00278    }
00279    if (!strcasecmp("alaw", format)) {
00280       iks *payload_eg711a;
00281       iks *payload_pcma = iks_new("payload-type");
00282       iks_insert_attrib(payload_pcma, "id", "8");
00283       iks_insert_attrib(payload_pcma, "name", "PCMA");
00284       iks_insert_attrib(payload_pcma, "xmlns", "http://www.google.com/session/phone");
00285       payload_eg711a = iks_new("payload-type");
00286       iks_insert_attrib(payload_eg711a, "id", "101");
00287       iks_insert_attrib(payload_eg711a, "name", "EG711A");
00288       iks_insert_attrib(payload_eg711a, "xmlns", "http://www.google.com/session/phone");
00289       iks_insert_node(dcodecs, payload_pcma);
00290       iks_insert_node(dcodecs, payload_eg711a);
00291    }
00292    if (!strcasecmp("ilbc", format)) {
00293       iks *payload_ilbc = iks_new("payload-type");
00294       iks_insert_attrib(payload_ilbc, "id", "102");
00295       iks_insert_attrib(payload_ilbc, "name", "iLBC");
00296       iks_insert_attrib(payload_ilbc, "xmlns", "http://www.google.com/session/phone");
00297       iks_insert_node(dcodecs, payload_ilbc);
00298    }
00299    if (!strcasecmp("g723", format)) {
00300       iks *payload_g723 = iks_new("payload-type");
00301       iks_insert_attrib(payload_g723, "id", "4");
00302       iks_insert_attrib(payload_g723, "name", "G723");
00303       iks_insert_attrib(payload_g723, "xmlns", "http://www.google.com/session/phone");
00304       iks_insert_node(dcodecs, payload_g723);
00305    }
00306    ast_rtp_lookup_code(p->rtp, 1, codec);
00307 }

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

AST_MUTEX_DEFINE_STATIC jinglelock   ) 
 

Protect the interface list (of jingle_pvt's)

static struct jingle* find_jingle char *  name,
char *  connection
[static]
 

Definition at line 234 of file chan_jingle.c.

References ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_FIND_FULL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_WRLOCK, jingles, and jingle::user.

Referenced by jingle_request().

00235 {
00236    struct jingle *jingle = NULL;
00237 
00238    jingle = ASTOBJ_CONTAINER_FIND(&jingles, name);
00239    if (!jingle && strchr(name, '@'))
00240       jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingles, name, user,,, strcasecmp);
00241 
00242    if (!jingle) {          /* guest call */
00243       ASTOBJ_CONTAINER_TRAVERSE(&jingles, 1, {
00244          ASTOBJ_WRLOCK(iterator);
00245          if (!strcasecmp(iterator->name, "guest")) {
00246             if (!strcasecmp(iterator->connection->jid->partial, connection)) {
00247                jingle = iterator;
00248                break;
00249             } else if (!strcasecmp(iterator->connection->name, connection)) {
00250                jingle = iterator;
00251                break;
00252             }
00253          }
00254          ASTOBJ_UNLOCK(iterator);
00255       });
00256 
00257    }
00258    return jingle;
00259 }

static int jingle_accept_call struct jingle client,
struct jingle_pvt p
[static]
 

Definition at line 309 of file chan_jingle.c.

References add_codec_to_answer(), ast_aji_increment_mid(), ast_codec_pref_index(), AST_FORMAT_MAX_AUDIO, jingle::capability, jingle::connection, GOOGLE_NODE, GOOGLE_SID, aji_client::jid, JINGLE_ACCEPT, aji_client::mid, aji_client::p, jingle::p, jingle::prefs, jingle_pvt::sid, and jingle::user.

Referenced by jingle_answer().

00310 {
00311    struct jingle_pvt *tmp = client->p;
00312    struct aji_client *c = client->connection;
00313    iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn;
00314    int x;
00315    int pref_codec = 0;
00316    int alreadysent = 0;
00317 
00318    if (p->initiator)
00319       return 1;
00320 
00321    iq = iks_new("iq");
00322    jingle = iks_new(GOOGLE_NODE);
00323    dcodecs = iks_new("description");
00324    if (iq && jingle && dcodecs) {
00325       iks_insert_attrib(dcodecs, "xmlns", "http://www.google.com/session/phone");
00326 
00327       for (x = 0; x < 32; x++) {
00328          if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
00329             break;
00330          if (!(client->capability & pref_codec))
00331             continue;
00332          if (alreadysent & pref_codec)
00333             continue;
00334          if (pref_codec <= AST_FORMAT_MAX_AUDIO)
00335             add_codec_to_answer(p, pref_codec, dcodecs);
00336          else
00337             add_codec_to_answer(p, pref_codec, dcodecs);
00338          alreadysent |= pref_codec;
00339       }
00340       payload_red = iks_new("payload-type");
00341       iks_insert_attrib(payload_red, "id", "117");
00342       iks_insert_attrib(payload_red, "name", "red");
00343       iks_insert_attrib(payload_red, "xmlns", "http://www.google.com/session/phone");
00344       payload_audio = iks_new("payload-type");
00345       iks_insert_attrib(payload_audio, "id", "106");
00346       iks_insert_attrib(payload_audio, "name", "audio/telephone-event");
00347       iks_insert_attrib(payload_audio, "xmlns", "http://www.google.com/session/phone");
00348       payload_cn = iks_new("payload-type");
00349       iks_insert_attrib(payload_cn, "id", "13");
00350       iks_insert_attrib(payload_cn, "name", "CN");
00351       iks_insert_attrib(payload_cn, "xmlns", "http://www.google.com/session/phone");
00352 
00353 
00354       iks_insert_attrib(iq, "type", "set");
00355       iks_insert_attrib(iq, "to", (p->from) ? p->from : client->user);
00356       iks_insert_attrib(iq, "id", client->connection->mid);
00357       ast_aji_increment_mid(client->connection->mid);
00358 
00359       iks_insert_attrib(jingle, "xmlns", "http://www.google.com/session");
00360       iks_insert_attrib(jingle, "type", JINGLE_ACCEPT);
00361       iks_insert_attrib(jingle, "initiator",
00362                     p->initiator ? client->connection->jid->full : p->from);
00363       iks_insert_attrib(jingle, GOOGLE_SID, tmp->sid);
00364       iks_insert_node(iq, jingle);
00365       iks_insert_node(jingle, dcodecs);
00366       iks_insert_node(dcodecs, payload_red);
00367       iks_insert_node(dcodecs, payload_audio);
00368       iks_insert_node(dcodecs, payload_cn);
00369 
00370       iks_send(c->p, iq);
00371       iks_delete(payload_red);
00372       iks_delete(payload_audio);
00373       iks_delete(payload_cn);
00374       iks_delete(dcodecs);
00375       iks_delete(jingle);
00376       iks_delete(iq);
00377    }
00378    return 1;
00379 }

static int jingle_action struct jingle client,
struct jingle_pvt p,
const char *  action
[static]
 

Definition at line 832 of file chan_jingle.c.

References ast_aji_increment_mid(), jingle::connection, jingle_pvt::from, jingle_pvt::initiator, aji_client::jid, aji_client::mid, aji_client::p, and jingle_pvt::sid.

Referenced by jingle_hangup().

00833 {
00834    iks *request, *session = NULL;
00835    int res = -1;
00836 
00837    request = iks_new("iq");
00838    if (request) {
00839       iks_insert_attrib(request, "type", "set");
00840       iks_insert_attrib(request, "from", client->connection->jid->full);
00841       iks_insert_attrib(request, "to", p->from);
00842       iks_insert_attrib(request, "id", client->connection->mid);
00843       ast_aji_increment_mid(client->connection->mid);
00844       session = iks_new("session");
00845       if (session) {
00846          iks_insert_attrib(session, "type", action);
00847          iks_insert_attrib(session, "id", p->sid);
00848          iks_insert_attrib(session, "initiator",
00849                        p->initiator ? client->connection->jid->full : p->from);
00850          iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
00851          iks_insert_node(request, session);
00852          iks_send(client->connection->p, request);
00853          iks_delete(session);
00854          res = 0;
00855       }
00856       iks_delete(request);
00857    }
00858    return res;
00859 }

static int jingle_add_candidate struct jingle client,
ikspak *  pak
[static]
 

Definition at line 992 of file chan_jingle.c.

References AJI_CONNECT_LOCAL, AJI_CONNECT_RELAY, AJI_CONNECT_STUN, AJI_PROTOCOL_SSLTCP, AJI_PROTOCOL_UDP, ast_calloc, jingle::connection, GOOGLE_NODE, GOOGLE_SID, aji_client::jid, jingle_update_stun(), jingle_pvt::laststun, jingle_pvt::next, aji_client::p, jingle::p, jingle_pvt::parent, jingle_candidate::receipt, and jingle_pvt::theircandidates.

Referenced by jingle_parser().

00993 {
00994    struct jingle_pvt *p = NULL, *tmp = NULL;
00995    struct aji_client *c = client->connection;
00996    struct jingle_candidate *newcandidate = NULL;
00997    iks *traversenodes = NULL, *receipt = NULL;
00998    newcandidate = ast_calloc(1, sizeof(*newcandidate));
00999    if (!newcandidate)
01000       return 0;
01001    for (tmp = client->p; tmp; tmp = tmp->next) {
01002       if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
01003          p = tmp;
01004          break;
01005       }
01006    }
01007 
01008    if (!p)
01009       return -1;
01010 
01011    traversenodes = pak->query;
01012    while(traversenodes) {
01013       if(!strcasecmp(iks_name(traversenodes), "session")) {
01014          traversenodes = iks_child(traversenodes);
01015          continue;
01016       }
01017       if(!strcasecmp(iks_name(traversenodes), "candidate")) {
01018          newcandidate = ast_calloc(1, sizeof(*newcandidate));
01019          if (!newcandidate)
01020             return 0;
01021          ast_copy_string(newcandidate->name, iks_find_attrib(traversenodes, "name"),
01022                      sizeof(newcandidate->name));
01023          ast_copy_string(newcandidate->ip, iks_find_attrib(traversenodes, "address"),
01024                      sizeof(newcandidate->ip));
01025          newcandidate->port = atoi(iks_find_attrib(traversenodes, "port"));
01026          ast_copy_string(newcandidate->username, iks_find_attrib(traversenodes, "username"),
01027                      sizeof(newcandidate->username));
01028          ast_copy_string(newcandidate->password, iks_find_attrib(traversenodes, "password"),
01029                      sizeof(newcandidate->password));
01030          newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference"));
01031          if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "udp"))
01032             newcandidate->protocol = AJI_PROTOCOL_UDP;
01033          if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "ssltcp"))
01034             newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
01035       
01036          if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "stun"))
01037             newcandidate->type = AJI_CONNECT_STUN;
01038          if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "local"))
01039             newcandidate->type = AJI_CONNECT_LOCAL;
01040          if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "relay"))
01041             newcandidate->type = AJI_CONNECT_RELAY;
01042          ast_copy_string(newcandidate->network, iks_find_attrib(traversenodes, "network"),
01043                      sizeof(newcandidate->network));
01044          newcandidate->generation = atoi(iks_find_attrib(traversenodes, "generation"));
01045          newcandidate->next = NULL;
01046       
01047          newcandidate->next = p->theircandidates;
01048          p->theircandidates = newcandidate;
01049          p->laststun = 0;
01050          jingle_update_stun(p->parent, p);
01051          newcandidate = NULL;
01052       }
01053       traversenodes = iks_next(traversenodes);
01054    }
01055    
01056    receipt = iks_new("iq");
01057    iks_insert_attrib(receipt, "type", "result");
01058    iks_insert_attrib(receipt, "from", c->jid->full);
01059    iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
01060    iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
01061    iks_send(c->p, receipt);
01062    iks_delete(receipt);
01063 
01064    return 1;
01065 }

static struct jingle_pvt * jingle_alloc struct jingle client,
const char *  from,
const char *  sid
[static]
 

Definition at line 695 of file chan_jingle.c.

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

Referenced by jingle_newcall(), and jingle_request().

00696 {
00697    struct jingle_pvt *tmp = NULL;
00698    struct aji_resource *resources = NULL;
00699    struct aji_buddy *buddy;
00700    char idroster[200];
00701 
00702    if (option_debug)
00703       ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name);
00704    if (!sid && !strchr(from, '/')) {   /* I started call! */
00705       if (!strcasecmp(client->name, "guest")) {
00706          buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, from);
00707          if (buddy)
00708             resources = buddy->resources;
00709       } else 
00710          resources = client->buddy->resources;
00711       while (resources) {
00712          if (resources->cap->jingle) {
00713             break;
00714          }
00715          resources = resources->next;
00716       }
00717       if (resources)
00718          snprintf(idroster, sizeof(idroster), "%s/%s", from, resources->resource);
00719       else {
00720          ast_log(LOG_ERROR, "no jingle capable clients to talk to.\n");
00721          return NULL;
00722       }
00723    }
00724    if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
00725       return NULL;
00726    }
00727    if (sid) {
00728       ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
00729       ast_copy_string(tmp->from, from, sizeof(tmp->from));
00730    } else {
00731       snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random());
00732       ast_copy_string(tmp->from, idroster, sizeof(tmp->from));
00733       tmp->initiator = 1;
00734    }
00735    tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
00736    tmp->parent = client;
00737    if (!tmp->rtp) {
00738       ast_log(LOG_WARNING, "Out of RTP sessions?\n");
00739       free(tmp);
00740       return NULL;
00741    }
00742    ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
00743    ast_mutex_init(&tmp->lock);
00744    ast_mutex_lock(&jinglelock);
00745    tmp->next = client->p;
00746    client->p = tmp;
00747    ast_mutex_unlock(&jinglelock);
00748    return tmp;
00749 }

static int jingle_answer struct ast_channel ast  )  [static]
 

Definition at line 393 of file chan_jingle.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), jingle_accept_call(), jingle_pvt::lock, LOG_DEBUG, option_debug, jingle::p, jingle_pvt::parent, and ast_channel::tech_pvt.

00394 {
00395    struct jingle_pvt *p = ast->tech_pvt;
00396    struct jingle *client = p->parent;
00397    int res = 0;
00398 
00399    if (option_debug)
00400       ast_log(LOG_DEBUG, "Answer!\n");
00401    ast_mutex_lock(&p->lock);
00402    jingle_accept_call(client, p);
00403    ast_mutex_unlock(&p->lock);
00404    return res;
00405 }

static int jingle_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 1310 of file chan_jingle.c.

References ast_channel::_state, ast_log(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RING, jingle_pvt::capability, jingle::connection, aji_client::f, jingle_pvt::from, jingle_create_candidates(), jingle_ringing_ack(), jingle_transmit_invite(), jingle_pvt::jointcapability, LOG_WARNING, aji_client::mid, jingle_pvt::parent, jingle_pvt::ring, jingle_pvt::ringrule, jingle_pvt::sid, and ast_channel::tech_pvt.

01311 {
01312    struct jingle_pvt *p = ast->tech_pvt;
01313 
01314    if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
01315       ast_log(LOG_WARNING, "jingle_call called on %s, neither down nor reserved\n", ast->name);
01316       return -1;
01317    }
01318 
01319    ast_setstate(ast, AST_STATE_RING);
01320    p->jointcapability = p->capability;
01321    if (!p->ringrule) {
01322       ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
01323       p->ringrule = iks_filter_add_rule(p->parent->connection->f, jingle_ringing_ack, p,
01324                      IKS_RULE_ID, p->ring, IKS_RULE_DONE);
01325    } else
01326       ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
01327 
01328    jingle_transmit_invite(p);
01329    jingle_create_candidates(p->parent, p, p->sid, p->from);
01330 
01331    return 0;
01332 }

static int jingle_create_candidates struct jingle client,
struct jingle_pvt p,
char *  sid,
char *  from
[static]
 

Definition at line 573 of file chan_jingle.c.

References ast_calloc, ast_log(), jingle::connection, GOOGLE_NODE, LOG_ERROR, jingle_pvt::next, and jingle_pvt::sid.

Referenced by jingle_call(), and jingle_newcall().

00574 {
00575    struct jingle_candidate *tmp;
00576    struct aji_client *c = client->connection;
00577    struct jingle_candidate *ours1 = NULL, *ours2 = NULL;
00578    struct sockaddr_in sin;
00579    struct sockaddr_in dest;
00580    struct in_addr us;
00581    iks *iq, *jingle, *candidate;
00582    char user[17], pass[17], preference[5], port[7];
00583 
00584 
00585    iq = iks_new("iq");
00586    jingle = iks_new(GOOGLE_NODE);
00587    candidate = iks_new("candidate");
00588    if (!iq || !jingle || !candidate) {
00589       ast_log(LOG_ERROR, "Memory allocation error\n");
00590       goto safeout;
00591    }
00592    ours1 = ast_calloc(1, sizeof(*ours1));
00593    ours2 = ast_calloc(1, sizeof(*ours2));
00594    if (!ours1 || !ours2)
00595       goto safeout;
00596    iks_insert_node(iq, jingle);
00597    iks_insert_node(jingle, candidate);
00598 
00599    for (; p; p = p->next) {
00600       if (!strcasecmp(p->sid, sid))
00601          break;
00602    }
00603 
00604    if (!p) {
00605       ast_log(LOG_NOTICE, "No matching jingle session - SID %s!\n", sid);
00606       goto safeout;
00607    }
00608 
00609    ast_rtp_get_us(p->rtp, &sin);
00610    ast_find_ourip(&us, bindaddr);
00611 
00612    /* Setup our jingle candidates */
00613    ast_copy_string(ours1->name, "rtp", sizeof(ours1->name));
00614    ours1->port = ntohs(sin.sin_port);
00615    ours1->preference = 1;
00616    snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
00617    snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
00618    ast_copy_string(ours1->username, user, sizeof(ours1->username));
00619    ast_copy_string(ours1->password, pass, sizeof(ours1->password));
00620    ast_copy_string(ours1->ip, ast_inet_ntoa(us), sizeof(ours1->ip));
00621    ours1->protocol = AJI_PROTOCOL_UDP;
00622    ours1->type = AJI_CONNECT_LOCAL;
00623    ours1->generation = 0;
00624    p->ourcandidates = ours1;
00625 
00626    if (!ast_strlen_zero(externip)) {
00627       /* XXX We should really stun for this one not just go with externip XXX */
00628       snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
00629       snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
00630       ast_copy_string(ours2->username, user, sizeof(ours2->username));
00631       ast_copy_string(ours2->password, pass, sizeof(ours2->password));
00632       ast_copy_string(ours2->ip, externip, sizeof(ours2->ip));
00633       ast_copy_string(ours2->name, "rtp", sizeof(ours1->name));
00634       ours2->port = ntohs(sin.sin_port);
00635       ours2->preference = 0.9;
00636       ours2->protocol = AJI_PROTOCOL_UDP;
00637       ours2->type = AJI_CONNECT_STUN;
00638       ours2->generation = 0;
00639       ours1->next = ours2;
00640       ours2 = NULL;
00641    }
00642    ours1 = NULL;
00643    dest.sin_addr = __ourip;
00644    dest.sin_port = sin.sin_port;
00645 
00646 
00647    for (tmp = p->ourcandidates; tmp; tmp = tmp->next) {
00648       snprintf(port, sizeof(port), "%d", tmp->port);
00649       snprintf(preference, sizeof(preference), "%.2f", tmp->preference);
00650       iks_insert_attrib(iq, "from", c->jid->full);
00651       iks_insert_attrib(iq, "to", from);
00652       iks_insert_attrib(iq, "type", "set");
00653       iks_insert_attrib(iq, "id", c->mid);
00654       ast_aji_increment_mid(c->mid);
00655       iks_insert_attrib(jingle, "type", "candidates");
00656       iks_insert_attrib(jingle, "id", sid);
00657       iks_insert_attrib(jingle, "initiator", (p->initiator) ? c->jid->full : from);
00658       iks_insert_attrib(jingle, "xmlns", GOOGLE_NS);
00659       iks_insert_attrib(candidate, "name", tmp->name);
00660       iks_insert_attrib(candidate, "address", tmp->ip);
00661       iks_insert_attrib(candidate, "port", port);
00662       iks_insert_attrib(candidate, "username", tmp->username);
00663       iks_insert_attrib(candidate, "password", tmp->password);
00664       iks_insert_attrib(candidate, "preference", preference);
00665       if (tmp->protocol == AJI_PROTOCOL_UDP)
00666          iks_insert_attrib(candidate, "protocol", "udp");
00667       if (tmp->protocol == AJI_PROTOCOL_SSLTCP)
00668          iks_insert_attrib(candidate, "protocol", "ssltcp");
00669       if (tmp->type == AJI_CONNECT_STUN)
00670          iks_insert_attrib(candidate, "type", "stun");
00671       if (tmp->type == AJI_CONNECT_LOCAL)
00672          iks_insert_attrib(candidate, "type", "local");
00673       if (tmp->type == AJI_CONNECT_RELAY)
00674          iks_insert_attrib(candidate, "type", "relay");
00675       iks_insert_attrib(candidate, "network", "0");
00676       iks_insert_attrib(candidate, "generation", "0");
00677       iks_send(c->p, iq);
00678    }
00679    p->laststun = 0;
00680 
00681 safeout:
00682    if (ours1)
00683       free(ours1);
00684    if (ours2)
00685       free(ours2);
00686    if (iq)
00687       iks_delete(iq);
00688    if (jingle)
00689       iks_delete(jingle);
00690    if (candidate)
00691       iks_delete(candidate);
00692    return 1;
00693 }

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

Definition at line 1494 of file chan_jingle.c.

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

01497 {
01498    struct aji_client *client;
01499 
01500    if (!member)
01501       ast_log(LOG_WARNING, "Out of memory.\n");
01502 
01503    ast_copy_string(member->name, label, sizeof(member->name));
01504    ast_copy_string(member->user, label, sizeof(member->