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->user));
01505    ast_copy_string(member->context, context, sizeof(member->context));
01506    member->allowguest = allowguest;
01507    member->prefs = prefs;
01508    while (var) {
01509 #if 0
01510       struct jingle_candidate *candidate = NULL;
01511 #endif
01512       if (!strcasecmp(var->name, "username"))
01513          ast_copy_string(member->user, var->value, sizeof(member->user));
01514       else if (!strcasecmp(var->name, "disallow"))
01515          ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 0);
01516       else if (!strcasecmp(var->name, "allow"))
01517          ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 1);
01518       else if (!strcasecmp(var->name, "context"))
01519          ast_copy_string(member->context, var->value, sizeof(member->context));
01520 #if 0
01521       else if (!strcasecmp(var->name, "candidate")) {
01522          candidate = jingle_create_candidate(var->value);
01523          if (candidate) {
01524             candidate->next = member->ourcandidates;
01525             member->ourcandidates = candidate;
01526          }
01527       }
01528 #endif
01529       else if (!strcasecmp(var->name, "connection")) {
01530          if ((client = ast_aji_get_client(var->value))) {
01531             member->connection = client;
01532             iks_filter_add_rule(client->f, jingle_parser, member, IKS_RULE_TYPE,
01533                            IKS_PAK_IQ, IKS_RULE_FROM_PARTIAL, member->user,
01534                            IKS_RULE_NS, "http://jabber.org/protocol/jingle",
01535                            IKS_RULE_DONE);
01536          } else {
01537             ast_log(LOG_ERROR, "connection referenced not found!\n");
01538             return 0;
01539          }
01540       }
01541       var = var->next;
01542    }
01543    if (member->connection && member->user)
01544       member->buddy = ASTOBJ_CONTAINER_FIND(&member->connection->buddies, member->user);
01545    else {
01546       ast_log(LOG_ERROR, "No Connection or Username!\n");
01547    }
01548    return 1;
01549 }

static int jingle_digit struct ast_channel ast,
char  digit,
unsigned int  duration
[static]
 

Definition at line 1185 of file chan_jingle.c.

References ast_aji_increment_mid(), AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), jingle::connection, ast_channel::dtmff, ast_frame::frametype, jingle_pvt::from, jingle_pvt::initiator, aji_client::jid, jingle_pvt::lock, LOG_ERROR, aji_client::mid, aji_client::p, jingle::p, jingle_pvt::parent, jingle_pvt::sid, and ast_channel::tech_pvt.

Referenced by jingle_digit_begin(), and jingle_digit_end().

01186 {
01187    struct jingle_pvt *p = ast->tech_pvt;
01188    struct jingle *client = p->parent;
01189    iks *iq, *jingle, *dtmf;
01190    char buffer[2] = {digit, '\0'};
01191    iq = iks_new("iq");
01192    jingle = iks_new("jingle");
01193    dtmf = iks_new("dtmf");
01194    if(!iq || !jingle || !dtmf) {
01195       if(iq)
01196          iks_delete(iq);
01197       if(jingle)
01198          iks_delete(jingle);
01199       if(dtmf)
01200          iks_delete(dtmf);
01201       ast_log(LOG_ERROR, "Did not send dtmf do to memory issue\n");
01202       return -1;
01203    }
01204 
01205    iks_insert_attrib(iq, "type", "set");
01206    iks_insert_attrib(iq, "to", p->from);
01207    iks_insert_attrib(iq, "from", client->connection->jid->full);
01208    iks_insert_attrib(iq, "id", client->connection->mid);
01209    ast_aji_increment_mid(client->connection->mid);
01210    iks_insert_attrib(jingle, "xmlns", "http://jabber.org/protocol/jingle");
01211    iks_insert_attrib(jingle, "action", "content-info");
01212    iks_insert_attrib(jingle, "initiator", p->initiator ? client->connection->jid->full : p->from);
01213    iks_insert_attrib(jingle, "sid", p->sid);
01214    iks_insert_attrib(dtmf, "xmlns", "http://jabber.org/protocol/jingle/info/dtmf");
01215    iks_insert_attrib(dtmf, "code", buffer);
01216    iks_insert_node(iq, jingle);
01217    iks_insert_node(jingle, dtmf);
01218 
01219    ast_mutex_lock(&p->lock);
01220    if (ast->dtmff.frametype == AST_FRAME_DTMF_BEGIN) {
01221       iks_insert_attrib(dtmf, "action", "button-down");
01222    } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END) {
01223       iks_insert_attrib(dtmf, "action", "button-up");
01224    }
01225    iks_send(client->connection->p, iq);
01226    iks_delete(iq);
01227    iks_delete(jingle);
01228    iks_delete(dtmf);
01229    ast_mutex_unlock(&p->lock);
01230    return 0;
01231 }

static int jingle_digit_begin struct ast_channel ast,
char  digit
[static]
 

Definition at line 1233 of file chan_jingle.c.

References jingle_digit().

01234 {
01235    return jingle_digit(chan, digit, 0);
01236 }

static int jingle_digit_end struct ast_channel ast,
char  digit,
unsigned int  duration
[static]
 

Definition at line 1238 of file chan_jingle.c.

References jingle_digit().

01239 {
01240    return jingle_digit(ast, digit, duration);
01241 }

static int jingle_fixup struct ast_channel oldchan,
struct ast_channel newchan
[static]
 

Definition at line 1151 of file chan_jingle.c.

References ast_mutex_lock(), ast_mutex_unlock(), jingle_pvt::lock, jingle_pvt::owner, and ast_channel::tech_pvt.

01152 {
01153    struct jingle_pvt *p = newchan->tech_pvt;
01154    ast_mutex_lock(&p->lock);
01155 
01156    if ((p->owner != oldchan)) {
01157       ast_mutex_unlock(&p->lock);
01158       return -1;
01159    }
01160    if (p->owner == oldchan)
01161       p->owner = newchan;
01162    ast_mutex_unlock(&p->lock);
01163    return 0;
01164 }

static void jingle_free_candidates struct jingle_candidate candidate  )  [static]
 

Definition at line 861 of file chan_jingle.c.

References free, last, and jingle_candidate::next.

Referenced by jingle_free_pvt().

00862 {
00863    struct jingle_candidate *last;
00864    while (candidate) {
00865       last = candidate;
00866       candidate = candidate->next;
00867       free(last);
00868    }
00869 }

static void jingle_free_pvt struct jingle client,
struct jingle_pvt p
[static]
 

Definition at line 871 of file chan_jingle.c.

References ast_log(), ast_rtp_destroy(), jingle::connection, aji_client::f, free, jingle_free_candidates(), LOG_WARNING, jingle_pvt::next, jingle_pvt::owner, jingle::p, jingle_pvt::parent, jingle_pvt::ringrule, jingle_pvt::rtp, jingle_pvt::theircandidates, and jingle_pvt::vrtp.

Referenced by jingle_hangup(), and jingle_newcall().

00872 {
00873    struct jingle_pvt *cur, *prev = NULL;
00874    cur = client->p;
00875    while (cur) {
00876       if (cur == p) {
00877          if (prev)
00878             prev->next = p->next;
00879          else
00880             client->p = p->next;
00881          break;
00882       }
00883       prev = cur;
00884       cur = cur->next;
00885    }
00886    if (p->ringrule)
00887       iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
00888    if (p->owner)
00889       ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
00890    if (p->rtp)
00891       ast_rtp_destroy(p->rtp);
00892    if (p->vrtp)
00893       ast_rtp_destroy(p->vrtp);
00894    jingle_free_candidates(p->theircandidates);
00895    free(p);
00896 }

static int jingle_get_codec struct ast_channel chan  )  [static]
 

Definition at line 425 of file chan_jingle.c.

References jingle_pvt::peercapability, and ast_channel::tech_pvt.

00426 {
00427    struct jingle_pvt *p = chan->tech_pvt;
00428    return p->peercapability;
00429 }

static enum ast_rtp_get_result jingle_get_rtp_peer struct ast_channel chan,
struct ast_rtp **  rtp
[static]
 

Definition at line 407 of file chan_jingle.c.

References ast_mutex_lock(), ast_mutex_unlock(), AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, jingle_pvt::lock, jingle_pvt::rtp, and ast_channel::tech_pvt.

00408 {
00409    struct jingle_pvt *p = chan->tech_pvt;
00410    enum ast_rtp_get_result res = AST_RTP_GET_FAILED;
00411 
00412    if (!p)
00413       return res;
00414 
00415    ast_mutex_lock(&p->lock);
00416    if (p->rtp) {
00417       *rtp = p->rtp;
00418       res = AST_RTP_TRY_NATIVE;
00419    }
00420    ast_mutex_unlock(&p->lock);
00421 
00422    return res;
00423 }

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

Definition at line 504 of file chan_jingle.c.

References AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_log(), ast_queue_frame(), ast_verbose(), GOOGLE_NODE, GOOGLE_SID, jingle_response(), LOG_NOTICE, jingle_pvt::next, jingle_pvt::owner, jingle::p, jingle_pvt::sid, and ast_frame::subclass.

Referenced by jingle_parser().

00505 {
00506    struct jingle_pvt *tmp;
00507    iks *dtmfnode = NULL;
00508    char *dtmf;
00509    /* Make sure our new call doesn't exist yet */
00510    for (tmp = client->p; tmp; tmp = tmp->next) {
00511       if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
00512          break;
00513    }
00514 
00515    if (tmp) {
00516       if(iks_find_with_attrib(pak->x, "dtmf-method", "method", "rtp")) {
00517          jingle_response(client,pak,
00518                "feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'",
00519                "unsupported-dtmf-method xmlns='http://jabber.org/protocol/jingle/info/dtmf#errors'");
00520          return -1;
00521       }
00522       if ((dtmfnode = iks_find(pak->x, "dtmf"))) {
00523          if((dtmf = iks_find_attrib(dtmfnode, "code"))) {
00524             if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-up")) {
00525                struct ast_frame f = {AST_FRAME_DTMF_BEGIN, };
00526                f.subclass = dtmf[0];
00527                ast_queue_frame(tmp->owner, &f);
00528                ast_verbose("JINGLE! DTMF-relay event received: %c\n", f.subclass);
00529             } else if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-down")) {
00530                struct ast_frame f = {AST_FRAME_DTMF_END, };
00531                f.subclass = dtmf[0];
00532                ast_queue_frame(tmp->owner, &f);
00533                ast_verbose("JINGLE! DTMF-relay event received: %c\n", f.subclass);
00534             } else if(iks_find_attrib(pak->x, "dtmf")) { /* 250 millasecond default */
00535                struct ast_frame f = {AST_FRAME_DTMF, };
00536                f.subclass = dtmf[0];
00537                ast_queue_frame(tmp->owner, &f);
00538                ast_verbose("JINGLE! DTMF-relay event received: %c\n", f.subclass);
00539             }
00540          }
00541       }
00542       jingle_response(client, pak, NULL, NULL);
00543       return 1;
00544    } else
00545       ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
00546 
00547    jingle_response(client, pak, NULL, NULL);
00548    return 1;
00549 }

static int jingle_hangup struct ast_channel ast  )  [static]
 

Hangup a call through the jingle proxy channel.

Definition at line 1335 of file chan_jingle.c.

References jingle_pvt::alreadygone, ast_mutex_lock(), ast_mutex_unlock(), jingle_action(), jingle_free_pvt(), jingle_pvt::lock, jingle_pvt::owner, jingle::p, jingle_pvt::parent, and ast_channel::tech_pvt.

01336 {
01337    struct jingle_pvt *p = ast->tech_pvt;
01338    struct jingle *client;
01339 
01340    ast_mutex_lock(&p->lock);
01341    client = p->parent;
01342    p->owner = NULL;
01343    ast->tech_pvt = NULL;
01344    if (!p->alreadygone)
01345       jingle_action(client, p, "terminate");
01346    ast_mutex_unlock(&p->lock);
01347 
01348    jingle_free_pvt(client, p);
01349 
01350    return 0;
01351 }

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

Definition at line 552 of file chan_jingle.c.

References jingle_pvt::alreadygone, ast_log(), ast_queue_hangup(), GOOGLE_NODE, GOOGLE_SID, jingle_response(), LOG_DEBUG, LOG_NOTICE, jingle_pvt::next, option_debug, jingle_pvt::owner, jingle::p, and jingle_pvt::sid.

Referenced by jingle_parser().

00553 {
00554    struct jingle_pvt *tmp;
00555 
00556    if (option_debug)
00557       ast_log(LOG_DEBUG, "The client is %s\n", client->name);
00558    /* Make sure our new call doesn't exist yet */
00559    for (tmp = client->p; tmp; tmp = tmp->next) {
00560       if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
00561          break;
00562    }
00563 
00564    if (tmp) {
00565       tmp->alreadygone = 1;
00566       ast_queue_hangup(tmp->owner);
00567    } else
00568       ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
00569    jingle_response(client, pak, NULL, NULL);
00570    return 1;
00571 }

static int jingle_indicate struct ast_channel ast,
int  condition,
const void *  data,
size_t  datalen
[static]
 

Definition at line 1166 of file chan_jingle.c.

References AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, ast_log(), ast_moh_start(), ast_moh_stop(), and LOG_NOTICE.

01167 {
01168    int res = 0;
01169 
01170    switch (condition) {
01171    case AST_CONTROL_HOLD:
01172       ast_moh_start(ast, data, NULL);
01173       break;
01174    case AST_CONTROL_UNHOLD:
01175       ast_moh_stop(ast);
01176       break;
01177    default:
01178       ast_log(LOG_NOTICE, "Don't know how to indicate condition '%d'\n", condition);
01179       res = -1;
01180    }
01181 
01182    return res;
01183 }

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

Definition at line 483 of file chan_jingle.c.

References AST_CONTROL_ANSWER, ast_log(), ast_queue_control(), GOOGLE_NODE, GOOGLE_SID, jingle_response(), LOG_DEBUG, LOG_NOTICE, jingle_pvt::next, option_debug, jingle_pvt::owner, jingle::p, and jingle_pvt::sid.

Referenced by jingle_parser().

00484 {
00485    struct jingle_pvt *tmp;
00486 
00487    if (option_debug)
00488       ast_log(LOG_DEBUG, "The client is %s\n", client->name);
00489    /* Make sure our new call doesn't exist yet */
00490    for (tmp = client->p; tmp; tmp = tmp->next) {
00491       if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
00492          break;
00493    }
00494 
00495    if (tmp) {
00496       if (tmp->owner)
00497          ast_queue_control(tmp->owner, AST_CONTROL_ANSWER);
00498    } else
00499       ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
00500    jingle_response(client, pak, NULL, NULL);
00501    return 1;
00502 }

static int jingle_load_config void   )  [static]
 

Definition at line 1551 of file chan_jingle.c.

References ast_category_browse(), ast_config_load(), ast_jb_read_conf(), ast_parse_allow_disallow(), ast_true(), ast_variable_browse(), ast_variable_retrieve(), clients, context, default_jbconf, externip, global_capability, global_jbconf, JINGLE_CONFIG, prefs, and var.

Referenced by load_module().

01552 {
01553    char *cat = NULL;
01554    struct ast_config *cfg = NULL;
01555    char context[100];
01556    int allowguest = 1;
01557    struct ast_variable *var;
01558    struct jingle *member;
01559    struct ast_codec_pref prefs;
01560    struct aji_client_container *clients;
01561    struct jingle_candidate *global_candidates = NULL;
01562 
01563    cfg = ast_config_load(JINGLE_CONFIG);
01564    if (!cfg)
01565       return 0;
01566 
01567    /* Copy the default jb config over global_jbconf */
01568    memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
01569 
01570    cat = ast_category_browse(cfg, NULL);
01571    for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
01572       /* handle jb conf */
01573       if (!ast_jb_read_conf(&global_jbconf, var->name, var->value))
01574          continue;
01575 
01576       if (!strcasecmp(var->name, "allowguest"))
01577          allowguest =
01578             (ast_true(ast_variable_retrieve(cfg, "general", "allowguest"))) ? 1 : 0;
01579       else if (!strcasecmp(var->name, "disallow"))
01580          ast_parse_allow_disallow(&prefs, &global_capability, var->value, 0);
01581       else if (!strcasecmp(var->name, "allow"))
01582          ast_parse_allow_disallow(&prefs, &global_capability, var->value, 1);
01583       else if (!strcasecmp(var->name, "context"))
01584          ast_copy_string(context, var->value, sizeof(context));
01585       else if (!strcasecmp(var->name, "externip"))
01586          ast_copy_string(externip, var->value, sizeof(externip));
01587 /*  Idea to allow for custom candidates  */
01588 /*
01589       else if (!strcasecmp(var->name, "candidate")) {
01590          candidate = jingle_create_candidate(var->value);
01591          if (candidate) {
01592             candidate->next = global_candidates;
01593             global_candidates = candidate;
01594          }
01595       }
01596 */
01597    }
01598    while (cat) {
01599       if (strcasecmp(cat, "general")) {
01600          var = ast_variable_browse(cfg, cat);
01601          member = (struct jingle *) malloc(sizeof(struct jingle));
01602          memset(member, 0, sizeof(struct jingle));
01603          ASTOBJ_INIT(member);
01604          ASTOBJ_WRLOCK(member);
01605          if (!strcasecmp(cat, "guest")) {
01606             ast_copy_string(member->name, "guest", sizeof(member->name));
01607             ast_copy_string(member->user, "guest", sizeof(member->user));
01608             ast_copy_string(member->context, context, sizeof(member->context));
01609             member->allowguest = allowguest;
01610             member->prefs = prefs;
01611             while (var) {
01612                if (!strcasecmp(var->name, "disallow"))
01613                   ast_parse_allow_disallow(&member->prefs, &member->capability,
01614                                      var->value, 0);
01615                else if (!strcasecmp(var->name, "allow"))
01616                   ast_parse_allow_disallow(&member->prefs, &member->capability,
01617                                      var->value, 1);
01618                else if (!strcasecmp(var->name, "context"))
01619                   ast_copy_string(member->context, var->value,
01620                               sizeof(member->context));
01621 /*  Idea to allow for custom candidates  */
01622 /*
01623                else if (!strcasecmp(var->name, "candidate")) {
01624                   candidate = jingle_create_candidate(var->value);
01625                   if (candidate) {
01626                      candidate->next = member->ourcandidates;
01627                      member->ourcandidates = candidate;
01628                   }
01629                }
01630 */
01631                var = var->next;
01632             }
01633             ASTOBJ_UNLOCK(member);
01634             clients = ast_aji_get_clients();
01635             if (clients) {
01636                ASTOBJ_CONTAINER_TRAVERSE(clients, 1, {
01637                   ASTOBJ_WRLOCK(iterator);
01638                   ASTOBJ_WRLOCK(member);
01639                   member->connection = iterator;
01640                   iks_filter_add_rule(iterator->f, jingle_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS,
01641                               "http://jabber.org/protocol/jingle", IKS_RULE_DONE);
01642                   ASTOBJ_UNLOCK(member);
01643                   ASTOBJ_CONTAINER_LINK(&jingles, member);
01644                   ASTOBJ_UNLOCK(iterator);
01645                });
01646             } else {
01647                ASTOBJ_UNLOCK(member);
01648                ASTOBJ_UNREF(member, jingle_member_destroy);
01649             }
01650          } else {
01651             ASTOBJ_UNLOCK(member);
01652             if (jingle_create_member(cat, var, allowguest, prefs, context, member))
01653                ASTOBJ_CONTAINER_LINK(&jingles, member);
01654             ASTOBJ_UNREF(member, jingle_member_destroy);
01655          }
01656       }
01657       cat = ast_category_browse(cfg, cat);
01658    }
01659    jingle_free_candidates(global_candidates);
01660    return 1;
01661 }

static void jingle_member_destroy struct jingle obj  )  [static]
 

Definition at line 229 of file chan_jingle.c.

References free.

Referenced by jingle_parser().

00230 {
00231    free(obj);
00232 }

static struct ast_channel* jingle_new struct jingle client,
struct jingle_pvt i,
int  state,
const char *  title
[static]
 

Start new jingle channel.

Definition at line 752 of file chan_jingle.c.

References accountcode, jingle::accountcode, ast_channel::adsicpe, ast_channel::amaflags, jingle::amaflags, AST_ADSI_UNAVAILABLE, ast_best_codec(), AST_CAUSE_SWITCH_CONGESTION, ast_channel_alloc(), ast_codec_choose(), AST_FORMAT_VIDEO_MASK, ast_hangup(), ast_jb_configure(), ast_log(), ast_pbx_start(), ast_random(), ast_rtcp_fd(), ast_rtp_fd(), AST_STATE_DOWN, AST_STATE_RING, ast_strdup, ast_string_field_set, ast_strlen_zero(), jingle::callgroup, ast_channel::callgroup, jingle::callingpres, jingle_pvt::capability, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, jingle_pvt::cid_name, ast_callerid::cid_num, jingle_pvt::cid_num, ast_callerid::cid_pres, jingle::context, ast_channel::context, jingle_pvt::exten, ast_channel::exten, ast_channel::fds, fmt, jingle_pvt::from, global_capability, global_jbconf, ast_channel::hangupcause, jingle_tech, jingle_pvt::jointcapability, language, jingle::language, LOG_WARNING, musicclass, jingle::musicclass, ast_channel::nativeformats, jingle_pvt::owner, jingle::pickupgroup, ast_channel::pickupgroup, jingle_pvt::prefs, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::rings, jingle_pvt::rtp, ast_channel::tech, ast_channel::tech_pvt, jingle_pvt::vrtp, and ast_channel::writeformat.

Referenced by jingle_newcall(), and jingle_request().

00753 {
00754    struct ast_channel *tmp;
00755    int fmt;
00756    int what;
00757    const char *str;
00758 
00759    if (title)
00760       str = title;
00761    else
00762       str = i->from;
00763    tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", str, ast_random() & 0xffff);
00764    if (!tmp) {
00765       ast_log(LOG_WARNING, "Unable to allocate Jingle channel structure!\n");
00766       return NULL;
00767    }
00768    tmp->tech = &jingle_tech;
00769 
00770    /* Select our native format based on codec preference until we receive
00771       something from another device to the contrary. */
00772    if (i->jointcapability)
00773       what = i->jointcapability;
00774    else if (i->capability)
00775       what = i->capability;
00776    else
00777       what = global_capability;
00778    tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
00779    fmt = ast_best_codec(tmp->nativeformats);
00780 
00781    if (i->rtp) {
00782       tmp->fds[0] = ast_rtp_fd(i->rtp);
00783       tmp->fds[1] = ast_rtcp_fd(i->rtp);
00784    }
00785    if (i->vrtp) {
00786       tmp->fds[2] = ast_rtp_fd(i->vrtp);
00787       tmp->fds[3] = ast_rtcp_fd(i->vrtp);
00788    }
00789    if (state == AST_STATE_RING)
00790       tmp->rings = 1;
00791    tmp->adsicpe = AST_ADSI_UNAVAILABLE;
00792    tmp->writeformat = fmt;
00793    tmp->rawwriteformat = fmt;
00794    tmp->readformat = fmt;
00795    tmp->rawreadformat = fmt;
00796    tmp->tech_pvt = i;
00797 
00798    tmp->callgroup = client->callgroup;
00799    tmp->pickupgroup = client->pickupgroup;
00800    tmp->cid.cid_pres = client->callingpres;
00801    if (!ast_strlen_zero(client->accountcode))
00802       ast_string_field_set(tmp, accountcode, client->accountcode);
00803    if (client->amaflags)
00804       tmp->amaflags = client->amaflags;
00805    if (!ast_strlen_zero(client->language))
00806       ast_string_field_set(tmp, language, client->language);
00807    if (!ast_strlen_zero(client->musicclass))
00808       ast_string_field_set(tmp, musicclass, client->musicclass);
00809    i->owner = tmp;
00810    ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
00811    ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
00812    /* Don't use ast_set_callerid() here because it will
00813     * generate an unnecessary NewCallerID event  */
00814    tmp->cid.cid_num = ast_strdup(i->cid_num);
00815    tmp->cid.cid_ani = ast_strdup(i->cid_num);
00816    tmp->cid.cid_name = ast_strdup(i->cid_name);
00817    if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
00818       tmp->cid.cid_dnid = ast_strdup(i->exten);
00819    tmp->priority = 1;
00820    if (i->rtp)
00821       ast_jb_configure(tmp, &global_jbconf);
00822    if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
00823       ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
00824       tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
00825       ast_hangup(tmp);
00826       tmp = NULL;
00827    }
00828 
00829    return tmp;
00830 }

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

Definition at line 899 of file chan_jingle.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_PBX_CALL_LIMIT, AST_PBX_FAILED, ast_pbx_start(), AST_PBX_SUCCESS, ast_rtp_set_m_type(), ast_rtp_set_rtpmap_type(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RING, jingle_pvt::from, GOOGLE_NODE, GOOGLE_SID, jingle_alloc(), jingle_create_candidates(), jingle_free_pvt(), jingle_new(), jingle_response(), jingle_pvt::lock, LOG_NOTICE, LOG_WARNING, jingle_pvt::next, jingle::p, jingle_pvt::rtp, and jingle_pvt::sid.

Referenced by jingle_parser().

00900 {
00901    struct jingle_pvt *p, *tmp = client->p;
00902    struct ast_channel *chan;
00903    int res;
00904    iks *codec;
00905 
00906    /* Make sure our new call doesn't exist yet */
00907    while (tmp) {
00908       if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
00909          ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
00910          jingle_response(client, pak, "out-of-order", NULL);
00911          return -1;
00912       }
00913       tmp = tmp->next;
00914    }
00915 
00916    p = jingle_alloc(client, pak->from->partial, iks_find_attrib(pak->query, GOOGLE_SID));
00917    if (!p) {
00918       ast_log(LOG_WARNING, "Unable to allocate jingle structure!\n");
00919       return -1;
00920    }
00921    chan = jingle_new(client, p, AST_STATE_DOWN, pak->from->user);
00922    if (chan) {
00923       ast_mutex_lock(&p->lock);
00924       ast_copy_string(p->from, pak->from->full, sizeof(p->from));
00925       if (iks_find_attrib(pak->query, GOOGLE_SID)) {
00926          ast_copy_string(p->sid, iks_find_attrib(pak->query, GOOGLE_SID),
00927                      sizeof(p->sid));
00928       }
00929 
00930       codec = iks_child(iks_child(iks_child(pak->x)));
00931       while (codec) {
00932          ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
00933          ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio",
00934                   iks_find_attrib(codec, "name"), 0);
00935          codec = iks_next(codec);
00936       }
00937       
00938       ast_mutex_unlock(&p->lock);
00939       ast_setstate(chan, AST_STATE_RING);
00940       res = ast_pbx_start(chan);
00941 
00942       switch (res) {
00943       case AST_PBX_FAILED:
00944          ast_log(LOG_WARNING, "Failed to start PBX :(\n");
00945          jingle_response(client, pak, "service-unavailable", NULL);
00946          break;
00947       case AST_PBX_CALL_LIMIT:
00948          ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
00949          jingle_response(client, pak, "service-unavailable", NULL);
00950          break;
00951       case AST_PBX_SUCCESS:
00952          jingle_response(client, pak, NULL, NULL);
00953          jingle_create_candidates(client, p,
00954                iks_find_attrib(pak->query, GOOGLE_SID),
00955                iks_find_attrib(pak->x, "from"));
00956          /* nothing to do */
00957          break;
00958       }
00959    } else {
00960       jingle_free_pvt(client, p);
00961    }
00962    return 1;
00963 }

static int jingle_parser void *  data,
ikspak *  pak
[static]
 

Definition at line 1421 of file chan_jingle.c.

References ast_log(), ASTOBJ_REF, ASTOBJ_UNREF, GOOGLE_ACCEPT, GOOGLE_NEGOTIATE, GOOGLE_NODE, jingle_add_candidate(), jingle_handle_dtmf(), jingle_hangup_farend(), JINGLE_INITIATE, jingle_is_answered(), jingle_member_destroy(), jingle_newcall(), LOG_DEBUG, and option_debug.

Referenced by jingle_create_member().

01422 {
01423    struct jingle *client = ASTOBJ_REF((struct jingle *) data);
01424 
01425    if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", JINGLE_INITIATE)) {
01426       /* New call */
01427       jingle_newcall(client, pak);
01428    } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", GOOGLE_NEGOTIATE)) {
01429       if (option_debug > 2)
01430          ast_log(LOG_DEBUG, "About to add candidate!\n");
01431       jingle_add_candidate(client, pak);
01432       if (option_debug > 2)
01433          ast_log(LOG_DEBUG, "Candidate Added!\n");
01434    } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", GOOGLE_ACCEPT)) {
01435       jingle_is_answered(client, pak);
01436    } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "content-info")) {
01437       jingle_handle_dtmf(client, pak);
01438    } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "terminate")) {
01439       jingle_hangup_farend(client, pak);
01440    } else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "reject")) {
01441       jingle_hangup_farend(client, pak);
01442    }
01443    ASTOBJ_UNREF(client, jingle_member_destroy);
01444    return IKS_FILTER_EAT;
01445 }

static struct ast_frame * jingle_read struct ast_channel ast  )  [static]
 

Definition at line 1096 of file chan_jingle.c.

References ast_mutex_lock(), ast_mutex_unlock(), jingle_rtp_read(), jingle_pvt::lock, and ast_channel::tech_pvt.

01097 {
01098    struct ast_frame *fr;
01099    struct jingle_pvt *p = ast->tech_pvt;
01100 
01101    ast_mutex_lock(&p->lock);
01102    fr = jingle_rtp_read(ast, p);
01103    ast_mutex_unlock(&p->lock);
01104    return fr;
01105 }

static struct ast_channel * jingle_request const char *  type,
int  format,
void *  data,
int *  cause
[static]
 

Part of PBX interface.

Definition at line 1354 of file chan_jingle.c.

References ast_log(), AST_STATE_DOWN, ast_strdupa, find_jingle(), free, jingle_alloc(), jingle_new(), LOG_ERROR, LOG_WARNING, s, and strsep().

01355 {
01356    struct jingle_pvt *p = NULL;
01357    struct jingle *client = NULL;
01358    char *sender = NULL, *to = NULL, *s = NULL;
01359    struct ast_channel *chan = NULL;
01360 
01361    if (data) {
01362       s = ast_strdupa((char *) data);
01363       if (s) {
01364          sender = strsep(&s, "/");
01365          if (sender && (sender[0] != '\0'))
01366             to = strsep(&s, "/");
01367          if (!to) {
01368             ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", (char*) data);
01369             if (s)
01370                free(s);
01371             return NULL;
01372          }
01373       }
01374    }
01375    client = find_jingle(to, sender);
01376    if (!client) {
01377       ast_log(LOG_WARNING, "Could not find recipient.\n");
01378       if (s)
01379          free(s);
01380       return NULL;
01381    }
01382    p = jingle_alloc(client, to, NULL);
01383    if (p)
01384       chan = jingle_new(client, p, AST_STATE_DOWN, to);
01385 
01386    return chan;
01387 }

static int jingle_response struct jingle client,
ikspak *  pak,
const char *  reasonstr,
const char *  reasonstr2
[static]
 

Definition at line 451 of file chan_jingle.c.

References jingle::connection, error(), aji_client::jid, and aji_client::p.

Referenced by jingle_handle_dtmf(), jingle_hangup_farend(), jingle_is_answered(), and jingle_newcall().

00452 {
00453    iks *response = NULL, *error = NULL, *reason = NULL;
00454    int res = -1;
00455 
00456    response = iks_new("iq");
00457    if (response) {
00458       iks_insert_attrib(response, "type", "result");
00459       iks_insert_attrib(response, "from", client->connection->jid->full);
00460       iks_insert_attrib(response, "to", iks_find_attrib(pak->x, "from"));
00461       iks_insert_attrib(response, "id", iks_find_attrib(pak->x, "id"));
00462       if (reasonstr) {
00463          error = iks_new("error");
00464          if (error) {
00465             iks_insert_attrib(error, "type", "cancel");
00466             reason = iks_new(reasonstr);
00467             if (reason)
00468                iks_insert_node(error, reason);
00469             iks_insert_node(response, error);
00470          }
00471       }
00472       iks_send(client->connection->p, response);
00473       if (reason)
00474          iks_delete(reason);
00475       if (error)
00476          iks_delete(error);
00477       iks_delete(response);
00478       res = 0;
00479    }
00480    return res;
00481 }

static int jingle_ringing_ack void *  data,
ikspak *  pak
[static]
 

Definition at line 381 of file chan_jingle.c.

References AST_CONTROL_RINGING, ast_queue_control(), jingle::connection, aji_client::f, jingle_pvt::owner, jingle_pvt::parent, and jingle_pvt::ringrule.

Referenced by jingle_call().

00382 {
00383    struct jingle_pvt *p = data;
00384 
00385    if (p->ringrule)
00386       iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
00387    p->ringrule = NULL;
00388    if (p->owner)
00389       ast_queue_control(p->owner, AST_CONTROL_RINGING);
00390    return IKS_FILTER_EAT;
00391 }

static struct ast_frame* jingle_rtp_read struct ast_channel ast,
struct jingle_pvt p
[static]
 

Definition at line 1067 of file chan_jingle.c.

References AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, AST_FRAME_VOICE, ast_log(), ast_null_frame, ast_rtp_read(), ast_set_read_format(), ast_set_write_format(), ast_frame::frametype, jingle_update_stun(), LOG_DEBUG, ast_channel::nativeformats, option_debug, jingle_pvt::owner, jingle_pvt::parent, ast_channel::readformat, jingle_pvt::rtp, ast_frame::subclass, and ast_channel::writeformat.

Referenced by jingle_read().

01068 {
01069    struct ast_frame *f;
01070 
01071    if (!p->rtp)
01072       return &ast_null_frame;
01073    f = ast_rtp_read(p->rtp);
01074    jingle_update_stun(p->parent, p);
01075    if (p->owner) {
01076       /* We already hold the channel lock */
01077       if (f->frametype == AST_FRAME_VOICE) {
01078          if (f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
01079             if (option_debug)
01080                ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
01081             p->owner->nativeformats =
01082                (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
01083             ast_set_read_format(p->owner, p->owner->readformat);
01084             ast_set_write_format(p->owner, p->owner->writeformat);
01085          }
01086 /*       if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) {
01087             f = ast_dsp_process(p->owner, p->vad, f);
01088             if (option_debug && f && (f->frametype == AST_FRAME_DTMF))
01089                ast_log(LOG_DEBUG, "* Detected inband DTMF '%c'\n", f->subclass);
01090               } */
01091       }
01092    }
01093    return f;
01094 }

static int jingle_sendhtml struct ast_channel ast,
int  subclass,
const char *  data,
int  datalen
[static]
 

Definition at line 1243 of file chan_jingle.c.

References ast_log(), and LOG_NOTICE.

01244 {
01245    ast_log(LOG_NOTICE, "XXX Implement jingle sendhtml XXX\n");
01246 
01247    return -1;
01248 }

static int jingle_set_rtp_peer struct ast_channel chan,
struct ast_rtp rtp,
struct ast_rtp vrtp,
int  codecs,
int  nat_active
[static]
 

Definition at line 431 of file chan_jingle.c.

References ast_mutex_lock(), ast_mutex_unlock(), jingle_pvt::lock, and ast_channel::tech_pvt.

00432 {
00433    struct jingle_pvt *p;
00434 
00435    p = chan->tech_pvt;
00436    if (!p)
00437       return -1;
00438    ast_mutex_lock(&p->lock);
00439 
00440 /* if (rtp)
00441       ast_rtp_get_peer(rtp, &p->redirip);
00442    else
00443       memset(&p->redirip, 0, sizeof(p->redirip));
00444    p->redircodecs = codecs; */
00445 
00446    /* Reset lastrtprx timer */
00447    ast_mutex_unlock(&p->lock);
00448    return 0;
00449 }

static int jingle_transmit_invite struct jingle_pvt p  )  [static]
 

Definition at line 1249 of file chan_jingle.c.

References ast_aji_increment_mid(), desc, aji_client::jid, aji_client::jingle, aji_client::mid, and aji_client::p.

Referenced by jingle_call().

01250 {
01251    struct jingle *jingle = NULL;
01252    struct aji_client *client = NULL;
01253    iks *iq, *desc, *session;
01254    iks *payload_eg711u, *payload_pcmu;
01255 
01256    jingle = p->parent;
01257    client = jingle->connection;
01258    iq = iks_new("iq");
01259    desc = iks_new("description");
01260    session = iks_new("session");
01261    iks_insert_attrib(iq, "type", "set");
01262    iks_insert_attrib(iq, "to", p->from);
01263    iks_insert_attrib(iq, "from", client->jid->full);
01264    iks_insert_attrib(iq, "id", client->mid);
01265    ast_aji_increment_mid(client->mid);
01266    iks_insert_attrib(session, "type", "initiate");
01267    iks_insert_attrib(session, "id", p->sid);
01268    iks_insert_attrib(session, "initiator", client->jid->full);
01269    iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
01270    iks_insert_attrib(desc, "xmlns", "http://www.google.com/session/phone");
01271    payload_pcmu = iks_new("payload-type");
01272    iks_insert_attrib(payload_pcmu, "id", "0");
01273    iks_insert_attrib(payload_pcmu, "name", "PCMU");
01274    payload_eg711u = iks_new("payload-type");
01275    iks_insert_attrib(payload_eg711u, "id", "100");
01276    iks_insert_attrib(payload_eg711u, "name", "EG711U");
01277    iks_insert_node(desc, payload_pcmu);
01278    iks_insert_node(desc, payload_eg711u);
01279    iks_insert_node(iq, session);
01280    iks_insert_node(session, desc);
01281    iks_send(client->p, iq);
01282    iks_delete(iq);
01283    iks_delete(desc);
01284    iks_delete(session);
01285    iks_delete(payload_eg711u);
01286    iks_delete(payload_pcmu);
01287    return 0;
01288 }

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

Definition at line 965 of file chan_jingle.c.

References ahp, ast_gethostbyname(), ast_rtp_stun_request(), hp, jingle_candidate::ip, jingle_pvt::laststun, jingle_candidate::next, jingle_pvt::ourcandidates, jingle_candidate::port, jingle_pvt::rtp, jingle_pvt::theircandidates, and jingle_candidate::username.

Referenced by jingle_add_candidate(), and jingle_rtp_read().

00966 {
00967    struct jingle_candidate *tmp;
00968    struct hostent *hp;
00969    struct ast_hostent ahp;
00970    struct sockaddr_in sin;
00971 
00972    if (time(NULL) == p->laststun)
00973       return 0;
00974 
00975    tmp = p->theircandidates;
00976    p->laststun = time(NULL);
00977    while (tmp) {
00978       char username[256];
00979       hp = ast_gethostbyname(tmp->ip, &ahp);
00980       sin.sin_family = AF_INET;
00981       memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
00982       sin.sin_port = htons(tmp->port);
00983       snprintf(username, sizeof(username), "%s%s", tmp->username,
00984              p->ourcandidates->username);
00985 
00986       ast_rtp_stun_request(p->rtp, &sin, username);
00987       tmp = tmp->next;
00988    }
00989    return 1;
00990 }

static int jingle_write struct ast_channel ast,
struct ast_frame f
[static]
 

Send frame to media channel (rtp).

Definition at line 1108 of file chan_jingle.c.

References AST_FRAME_IMAGE, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_write(), ast_frame::frametype, jingle_pvt::lock, LOG_WARNING, ast_channel::nativeformats, ast_channel::readformat, jingle_pvt::rtp, ast_frame::subclass, ast_channel::tech_pvt, jingle_pvt::vrtp, and ast_channel::writeformat.

01109 {
01110    struct jingle_pvt *p = ast->tech_pvt;
01111    int res = 0;
01112 
01113    switch (frame->frametype) {
01114    case AST_FRAME_VOICE:
01115       if (!(frame->subclass & ast->nativeformats)) {
01116          ast_log(LOG_WARNING,
01117                "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
01118                frame->subclass, ast->nativeformats, ast->readformat,
01119                ast->writeformat);
01120          return 0;
01121       }
01122       if (p) {
01123          ast_mutex_lock(&p->lock);
01124          if (p->rtp) {
01125             res = ast_rtp_write(p->rtp, frame);
01126          }
01127          ast_mutex_unlock(&p->lock);
01128       }
01129       break;
01130    case AST_FRAME_VIDEO:
01131       if (p) {
01132          ast_mutex_lock(&p->lock);
01133          if (p->vrtp) {
01134             res = ast_rtp_write(p->vrtp, frame);
01135          }
01136          ast_mutex_unlock(&p->lock);
01137       }
01138       break;
01139    case AST_FRAME_IMAGE:
01140       return 0;
01141       break;
01142    default:
01143       ast_log(LOG_WARNING, "Can't send %d type frames with Jingle write\n",
01144             frame->frametype);
01145       return 0;
01146    }
01147 
01148    return res;
01149 }

static int load_module void   )  [static]
 

Load module into PBX, register channel.

Definition at line 1664 of file chan_jingle.c.

References __ourip, ast_channel_register(), ast_find_ourip(), ast_log(), AST_MODULE_LOAD_DECLINE, ast_rtp_proto_register(), ASTOBJ_CONTAINER_INIT, bindaddr, io, io_context_create(), JINGLE_CONFIG, jingle_load_config(), jingle_rtp, jingle_tech, jingles, LOG_ERROR, LOG_WARNING, sched_context_create(), and type.

01665 {
01666    ASTOBJ_CONTAINER_INIT(&jingles);
01667    if (!jingle_load_config()) {
01668       ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", JINGLE_CONFIG);
01669       return AST_MODULE_LOAD_DECLINE;
01670    }
01671 
01672    sched = sched_context_create();
01673    if (!sched) 
01674       ast_log(LOG_WARNING, "Unable to create schedule context\n");
01675 
01676    io = io_context_create();
01677    if (!io) 
01678       ast_log(LOG_WARNING, "Unable to create I/O context\n");
01679 
01680    if (ast_find_ourip(&__ourip, bindaddr)) {
01681       ast_log(LOG_WARNING, "Unable to get own IP address, Jingle disabled\n");
01682       return 0;
01683    }
01684 
01685    ast_rtp_proto_register(&jingle_rtp);
01686 
01687    /* Make sure we can register our channel type */
01688    if (ast_channel_register(&jingle_tech)) {
01689       ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
01690       return -1;
01691    }
01692    return 0;
01693 }

static int reload void   )  [static]
 

Reload module.

Definition at line 1696 of file chan_jingle.c.

01697 {
01698    return 0;
01699 }

static int unload_module void   )  [static]
 

Unload the jingle channel from Asterisk.

Definition at line 1702 of file chan_jingle.c.

References ast_channel_unregister(), ast_mutex_lock(), ast_rtp_proto_unregister(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, jingle_rtp, jingle_tech, and jingles.

01703 {
01704    struct jingle_pvt *privates = NULL;
01705 
01706    /* First, take us out of the channel loop */
01707    ast_channel_unregister(&jingle_tech);
01708    ast_rtp_proto_unregister(&jingle_rtp);
01709 
01710    if (!ast_mutex_lock(&jinglelock)) {
01711       /* Hangup all interfaces if they have an owner */
01712       ASTOBJ_CONTAINER_TRAVERSE(&jingles, 1, {
01713          ASTOBJ_WRLOCK(iterator);
01714          privates = iterator->p;
01715          while(privates) {
01716             if (privates->owner)
01717                ast_softhangup(privates->owner, AST_SOFTHANGUP_APPUNLOAD);
01718             privates = privates->next;
01719          }
01720          iterator->p = NULL;
01721          ASTOBJ_UNLOCK(iterator);
01722       });
01723       ast_mutex_unlock(&jinglelock);
01724    } else {
01725       ast_log(LOG_WARNING, "Unable to lock the monitor\n");
01726       return -1;
01727    }
01728    ASTOBJ_CONTAINER_DESTROYALL(&jingles, jingle_member_destroy);
01729    ASTOBJ_CONTAINER_DESTROY(&jingles);
01730    return 0;
01731 }


Variable Documentation

struct in_addr __ourip [static]
 

Definition at line 214 of file chan_jingle.c.

struct sockaddr_in bindaddr = { 0, } [static]
 

The address we bind to

Definition at line 210 of file chan_jingle.c.

struct ast_jb_conf default_jbconf [static]
 

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 79 of file chan_jingle.c.

const char desc[] = "Jingle Channel" [static]
 

Definition at line 162 of file chan_jingle.c.

char externip[16] [static]
 

Definition at line 225 of file chan_jingle.c.

int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263 [static]
 

Definition at line 165 of file chan_jingle.c.

struct ast_jb_conf global_jbconf [static]
 

Definition at line 86 of file chan_jingle.c.

struct io_context* io [static]
 

The IO context

Definition at line 213 of file chan_jingle.c.

struct ast_rtp_protocol jingle_rtp [static]
 

RTP driver interface.

Definition at line 218 of file chan_jingle.c.

Referenced by load_module(), and unload_module().

const struct ast_channel_tech jingle_tech [static]
 

PBX interface structure for channel registration.

Definition at line 190 of file chan_jingle.c.

Referenced by jingle_new(), load_module(), and unload_module().

struct jingle_container jingles [static]
 

Definition at line 227 of file chan_jingle.c.

Referenced by find_jingle(), load_module(), and unload_module().

struct sched_context* sched [static]
 

The scheduling context

Definition at line 212 of file chan_jingle.c.

const char type[] = "Jingle" [static]
 

Definition at line 163 of file chan_jingle.c.


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen