[asterisk-commits] branch group/asterisk-xmpp r26083 -
/team/group/asterisk-xmpp/channels/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue May 9 07:05:36 MST 2006
Author: russell
Date: Tue May 9 09:05:36 2006
New Revision: 26083
URL: http://svn.digium.com/view/asterisk?rev=26083&view=rev
Log:
more fun with indent ...
Modified:
team/group/asterisk-xmpp/channels/chan_jingle.c
Modified: team/group/asterisk-xmpp/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/group/asterisk-xmpp/channels/chan_jingle.c?rev=26083&r1=26082&r2=26083&view=diff
==============================================================================
--- team/group/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/group/asterisk-xmpp/channels/chan_jingle.c Tue May 9 09:05:36 2006
@@ -47,7 +47,6 @@
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
@@ -76,25 +75,25 @@
#define JINGLE_CONFIG "jingle.conf"
enum jingle_protocol {
- AJI_PROTOCOL_UDP=1,
- AJI_PROTOCOL_SSLTCP=2,
+ AJI_PROTOCOL_UDP = 1,
+ AJI_PROTOCOL_SSLTCP = 2,
};
enum jingle_connect_type {
- AJI_CONNECT_STUN=1,
- AJI_CONNECT_LOCAL=2,
- AJI_CONNECT_RELAY=3,
+ AJI_CONNECT_STUN = 1,
+ AJI_CONNECT_LOCAL = 2,
+ AJI_CONNECT_RELAY = 3,
};
struct jingle_pvt {
- ast_mutex_t lock; /* Channel private lock */
+ ast_mutex_t lock; /* Channel private lock */
time_t laststun;
- struct jingle *parent; /* Parent client */
+ struct jingle *parent; /* Parent client */
char sid[100];
char from[100];
- char ring[10]; /* Message ID of ring */
- iksrule *ringrule; /* Rule for matching RING request */
- int initiator; /* If we're the initiator */
+ char ring[10]; /* Message ID of ring */
+ iksrule *ringrule; /* Rule for matching RING request */
+ int initiator; /* If we're the initiator */
int alreadygone;
int capability;
struct ast_codec_pref prefs;
@@ -102,21 +101,21 @@
struct jingle_candidate *ourcandidates;
char cid_num[80]; /*!< Caller ID num */
char cid_name[80]; /*!< Caller ID name */
- char exten[80]; /* Called extension */
- struct ast_channel *owner; /* Master Channel */
- struct ast_rtp *rtp; /*!< RTP Session */
+ char exten[80]; /* Called extension */
+ struct ast_channel *owner; /* Master Channel */
+ struct ast_rtp *rtp; /*!< RTP Session */
struct ast_rtp *vrtp;
- int jointcapability; /*!< Supported capability at both ends (codecs ) */
+ int jointcapability; /*!< Supported capability at both ends (codecs ) */
int peercapability;
- struct jingle_pvt *next; /* Next entity */
+ struct jingle_pvt *next; /* Next entity */
};
struct jingle_candidate {
char name[100];
enum jingle_protocol protocol;
double preference;
- char username [100];
- char password [100];
+ char username[100];
+ char password[100];
enum jingle_connect_type type;
int network;
int generation;
@@ -132,28 +131,28 @@
struct aji_buddy *buddy;
struct jingle_pvt *p;
struct ast_codec_pref prefs;
- int amaflags; /*!< AMA Flags */
+ int amaflags; /*!< AMA Flags */
char user[100];
char context[100];
char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */
int capability;
- ast_group_t callgroup; /*!< Call group */
- ast_group_t pickupgroup; /*!< Pickup group */
- int callingpres; /*!< Calling presentation */
+ ast_group_t callgroup; /*!< Call group */
+ ast_group_t pickupgroup; /*!< Pickup group */
+ int callingpres; /*!< Calling presentation */
int allowguest;
char language[MAX_LANGUAGE]; /*!< Default language for prompts */
- char musicclass[MAX_MUSICCLASS];/*!< Music on Hold class */
+ char musicclass[MAX_MUSICCLASS]; /*!< Music on Hold class */
};
struct jingle_container {
- ASTOBJ_CONTAINER_COMPONENTS(struct jingle);
+ ASTOBJ_CONTAINER_COMPONENTS(struct jingle);
};
static const char desc[] = "Jingle Channel";
static const char type[] = "Jingle";
static const char tdesc[] = "Jingle Channel Driver";
-static int usecnt =0;
+static int usecnt = 0;
AST_MUTEX_DEFINE_STATIC(usecnt_lock);
@@ -162,7 +161,7 @@
/* Protect the interface list (of sip_pvt's) */
AST_MUTEX_DEFINE_STATIC(jinglelock);
-AST_MUTEX_DEFINE_STATIC(rand_lock); /*!< Lock for thread-safe random generator */
+AST_MUTEX_DEFINE_STATIC(rand_lock); /*!< Lock for thread-safe random generator */
static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause);
@@ -185,8 +184,8 @@
.capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1),
.requester = jingle_request,
.send_digit = jingle_digit,
-// .devicestate = jingle_devicestate,
-// .transfer = jingle_transfer,
+// .devicestate = jingle_devicestate,
+// .transfer = jingle_transfer,
.bridge = ast_rtp_bridge,
.call = jingle_call,
.hangup = jingle_hangup,
@@ -202,10 +201,11 @@
static struct sockaddr_in bindaddr = { 0, }; /*!< The address we bind to */
static struct sched_context *sched; /*!< The scheduling context */
-static struct io_context *io; /*!< The IO context */
+static struct io_context *io; /*!< The IO context */
static struct in_addr __ourip;
/*----- RTP interface functions */
-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_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
+ struct ast_rtp *vrtp, int codecs, int nat_active);
static struct ast_rtp *jingle_get_rtp_peer(struct ast_channel *chan);
static int jingle_get_codec(struct ast_channel *chan);
@@ -223,29 +223,27 @@
static void jingle_member_destroy(struct jingle *obj)
{
free(obj);
- obj = NULL;
}
static struct jingle *find_jingle(char *name, char *connection)
{
struct jingle *jingle = NULL;
- jingle = ASTOBJ_CONTAINER_FIND(&jingles,name);
- if(!jingle && strchr(name, '@'))
- jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingles,name,user,,,strcasecmp);
-
- if(!jingle) { /* guest call */
- ASTOBJ_CONTAINER_TRAVERSE(&jingles,1,{
+ jingle = ASTOBJ_CONTAINER_FIND(&jingles, name);
+ if (!jingle && strchr(name, '@'))
+ jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingles, name, user,,, strcasecmp);
+
+ if (!jingle) { /* guest call */
+ ASTOBJ_CONTAINER_TRAVERSE(&jingles, 1, {
ASTOBJ_WRLOCK(iterator);
- if(!strcasecmp(iterator->name,"guest")) {
- if(!strcasecmp(iterator->connection->jid->partial, connection)) {
+ if (!strcasecmp(iterator->name, "guest")) {
+ if (!strcasecmp(iterator->connection->jid->partial, connection)) {
jingle = iterator;
break;
- } else if(!strcasecmp(iterator->connection->name, connection)) {
+ } else if (!strcasecmp(iterator->connection->name, connection)) {
jingle = iterator;
break;
}
-
}
ASTOBJ_UNLOCK(iterator);
});
@@ -258,47 +256,47 @@
static void add_codec_to_answer(const struct jingle_pvt *p, int codec, iks *description)
{
ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
- if(!strcasecmp("ulaw",ast_getformatname(codec))) {
- iks *payload_eg711u , *payload_pcmu;
+ if (!strcasecmp("ulaw", ast_getformatname(codec))) {
+ iks *payload_eg711u, *payload_pcmu;
payload_pcmu = iks_new("payload-type");
- iks_insert_attrib(payload_pcmu,"id","0");
- iks_insert_attrib(payload_pcmu,"name","PCMU");
- iks_insert_attrib(payload_pcmu,"xmlns","http://www.google.com/session/phone");
+ iks_insert_attrib(payload_pcmu, "id", "0");
+ iks_insert_attrib(payload_pcmu, "name", "PCMU");
+ iks_insert_attrib(payload_pcmu, "xmlns", "http://www.google.com/session/phone");
payload_eg711u = iks_new("payload-type");
- iks_insert_attrib(payload_eg711u,"id","100");
- iks_insert_attrib(payload_eg711u,"name","EG711U");
- iks_insert_attrib(payload_eg711u,"xmlns","http://www.google.com/session/phone");
- iks_insert_node(description,payload_pcmu);
- iks_insert_node(description,payload_eg711u);
- }
- if(!strcasecmp("alaw",ast_getformatname(codec))) {
- iks *payload_eg711a , *payload_pcma;
+ iks_insert_attrib(payload_eg711u, "id", "100");
+ iks_insert_attrib(payload_eg711u, "name", "EG711U");
+ iks_insert_attrib(payload_eg711u, "xmlns", "http://www.google.com/session/phone");
+ iks_insert_node(description, payload_pcmu);
+ iks_insert_node(description, payload_eg711u);
+ }
+ if (!strcasecmp("alaw", ast_getformatname(codec))) {
+ iks *payload_eg711a, *payload_pcma;
payload_pcma = iks_new("payload-type");
- iks_insert_attrib(payload_pcma,"id","8");
- iks_insert_attrib(payload_pcma,"name","PCMA");
- iks_insert_attrib(payload_pcma,"xmlns","http://www.google.com/session/phone");
+ iks_insert_attrib(payload_pcma, "id", "8");
+ iks_insert_attrib(payload_pcma, "name", "PCMA");
+ iks_insert_attrib(payload_pcma, "xmlns", "http://www.google.com/session/phone");
payload_eg711a = iks_new("payload-type");
- iks_insert_attrib(payload_eg711a,"id","101");
- iks_insert_attrib(payload_eg711a,"name","EG711A");
- iks_insert_attrib(payload_eg711a,"xmlns","http://www.google.com/session/phone");
- iks_insert_node(description,payload_pcma);
- iks_insert_node(description,payload_eg711a);
- }
- if(!strcasecmp("ilbc",ast_getformatname(codec))) {
+ iks_insert_attrib(payload_eg711a, "id", "101");
+ iks_insert_attrib(payload_eg711a, "name", "EG711A");
+ iks_insert_attrib(payload_eg711a, "xmlns", "http://www.google.com/session/phone");
+ iks_insert_node(description, payload_pcma);
+ iks_insert_node(description, payload_eg711a);
+ }
+ if (!strcasecmp("ilbc", ast_getformatname(codec))) {
iks *payload_ilbc;
- payload_ilbc= iks_new("payload-type");
- iks_insert_attrib(payload_ilbc,"id","102");
- iks_insert_attrib(payload_ilbc,"name","iLBC");
- iks_insert_attrib(payload_ilbc,"xmlns","http://www.google.com/session/phone");
- iks_insert_node(description,payload_ilbc);
- }
- if(!strcasecmp("g723",ast_getformatname(codec))) {
+ payload_ilbc = iks_new("payload-type");
+ iks_insert_attrib(payload_ilbc, "id", "102");
+ iks_insert_attrib(payload_ilbc, "name", "iLBC");
+ iks_insert_attrib(payload_ilbc, "xmlns", "http://www.google.com/session/phone");
+ iks_insert_node(description, payload_ilbc);
+ }
+ if (!strcasecmp("g723", ast_getformatname(codec))) {
iks *payload_g723;
- payload_g723= iks_new("payload-type");
- iks_insert_attrib(payload_g723,"id","4");
- iks_insert_attrib(payload_g723,"name","G723");
- iks_insert_attrib(payload_g723,"xmlns","http://www.google.com/session/phone");
- iks_insert_node(description,payload_g723);
+ payload_g723 = iks_new("payload-type");
+ iks_insert_attrib(payload_g723, "id", "4");
+ iks_insert_attrib(payload_g723, "name", "G723");
+ iks_insert_attrib(payload_g723, "xmlns", "http://www.google.com/session/phone");
+ iks_insert_node(description, payload_g723);
}
ast_rtp_lookup_code(p->rtp, 1, codec);
}
@@ -311,19 +309,19 @@
int x;
int pref_codec = 0;
int alreadysent = 0;
-
- if(p->initiator)
+
+ if (p->initiator)
return 1;
iq = iks_new("iq");
jingle = iks_new(GOOGLE_NODE);
description = iks_new("description");
if (iq && jingle && description) {
- iks_insert_attrib(description,"xmlns","http://www.google.com/session/phone");
+ iks_insert_attrib(description, "xmlns", "http://www.google.com/session/phone");
for (x = 0; x < 32; x++) {
if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
- break;
+ break;
if (!(client->capability & pref_codec))
continue;
if (alreadysent & pref_codec)
@@ -334,44 +332,45 @@
add_codec_to_answer(p, pref_codec, description);
alreadysent |= pref_codec;
}
- payload_red= iks_new("payload-type");
- iks_insert_attrib(payload_red,"id","117");
- iks_insert_attrib(payload_red,"name","red");
- iks_insert_attrib(payload_red,"xmlns","http://www.google.com/session/phone");
- payload_audio= iks_new("payload-type");
- iks_insert_attrib(payload_audio,"id","106");
- iks_insert_attrib(payload_audio,"name","audio/telephone-event");
- iks_insert_attrib(payload_audio,"xmlns","http://www.google.com/session/phone");
- payload_cn= iks_new("payload-type");
- iks_insert_attrib(payload_cn,"id","13");
- iks_insert_attrib(payload_cn,"name","CN");
- iks_insert_attrib(payload_cn,"xmlns","http://www.google.com/session/phone");
-
-
- iks_insert_attrib(iq,"type","set");
- // iks_insert_attrib(iq,"from",client->connection->jid->full);
- iks_insert_attrib(iq,"to",(p->from)?p->from:client->user);
- iks_insert_attrib(iq,"id",client->connection->mid);
- ast_aji_increment_mid(client->connection->mid);
-
- iks_insert_attrib(jingle, "xmlns", "http://www.google.com/session");
- iks_insert_attrib(jingle, "type", JINGLE_ACCEPT);
- ast_verbose("WOOH %d\n",p->initiator);
- iks_insert_attrib(jingle, "initiator", p->initiator ? client->connection->jid->full : p->from);
- iks_insert_attrib(jingle, GOOGLE_SID, tmp->sid);
- iks_insert_node(iq,jingle);
- iks_insert_node(jingle,description);
- iks_insert_node(description,payload_red);
- iks_insert_node(description,payload_audio);
- iks_insert_node(description,payload_cn);
-
- iks_send(c->p,iq);
- iks_delete(payload_red);
- iks_delete(payload_audio);
- iks_delete(payload_cn);
- iks_delete(description);
- iks_delete(jingle);
- iks_delete(iq);
+ payload_red = iks_new("payload-type");
+ iks_insert_attrib(payload_red, "id", "117");
+ iks_insert_attrib(payload_red, "name", "red");
+ iks_insert_attrib(payload_red, "xmlns", "http://www.google.com/session/phone");
+ payload_audio = iks_new("payload-type");
+ iks_insert_attrib(payload_audio, "id", "106");
+ iks_insert_attrib(payload_audio, "name", "audio/telephone-event");
+ iks_insert_attrib(payload_audio, "xmlns", "http://www.google.com/session/phone");
+ payload_cn = iks_new("payload-type");
+ iks_insert_attrib(payload_cn, "id", "13");
+ iks_insert_attrib(payload_cn, "name", "CN");
+ iks_insert_attrib(payload_cn, "xmlns", "http://www.google.com/session/phone");
+
+
+ iks_insert_attrib(iq, "type", "set");
+ // iks_insert_attrib(iq,"from",client->connection->jid->full);
+ iks_insert_attrib(iq, "to", (p->from) ? p->from : client->user);
+ iks_insert_attrib(iq, "id", client->connection->mid);
+ ast_aji_increment_mid(client->connection->mid);
+
+ iks_insert_attrib(jingle, "xmlns", "http://www.google.com/session");
+ iks_insert_attrib(jingle, "type", JINGLE_ACCEPT);
+ ast_verbose("WOOH %d\n", p->initiator);
+ iks_insert_attrib(jingle, "initiator",
+ p->initiator ? client->connection->jid->full : p->from);
+ iks_insert_attrib(jingle, GOOGLE_SID, tmp->sid);
+ iks_insert_node(iq, jingle);
+ iks_insert_node(jingle, description);
+ iks_insert_node(description, payload_red);
+ iks_insert_node(description, payload_audio);
+ iks_insert_node(description, payload_cn);
+
+ iks_send(c->p, iq);
+ iks_delete(payload_red);
+ iks_delete(payload_audio);
+ iks_delete(payload_cn);
+ iks_delete(description);
+ iks_delete(jingle);
+ iks_delete(iq);
}
return 1;
}
@@ -406,7 +405,7 @@
ast_mutex_lock(&rand_lock);
val = rand();
ast_mutex_unlock(&rand_lock);
-
+
return val;
}
@@ -419,7 +418,7 @@
return NULL;
ast_mutex_lock(&p->lock);
if (p->rtp)
- rtp = p->rtp;
+ rtp = p->rtp;
ast_mutex_unlock(&p->lock);
return rtp;
}
@@ -435,7 +434,7 @@
struct jingle_pvt *p;
p = chan->tech_pvt;
- if (!p)
+ if (!p)
return -1;
ast_mutex_lock(&p->lock);
@@ -452,15 +451,15 @@
static int jingle_response(struct jingle *client, ikspak *pak, const char *reasonstr)
{
- iks *response, *error=NULL, *reason=NULL;
+ iks *response, *error = NULL, *reason = NULL;
int res = -1;
-
+
response = iks_new("iq");
if (response) {
- iks_insert_attrib(response,"type","result");
- iks_insert_attrib(response,"from", client->connection->jid->full);
- iks_insert_attrib(response,"to",iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(response,"id",iks_find_attrib(pak->x,"id"));
+ iks_insert_attrib(response, "type", "result");
+ iks_insert_attrib(response, "from", client->connection->jid->full);
+ iks_insert_attrib(response, "to", iks_find_attrib(pak->x, "from"));
+ iks_insert_attrib(response, "id", iks_find_attrib(pak->x, "id"));
if (reasonstr) {
error = iks_new("error");
if (error) {
@@ -482,21 +481,21 @@
return res;
}
-static int jingle_is_answered(struct jingle *client,ikspak *pak)
+static int jingle_is_answered(struct jingle *client, ikspak *pak)
{
struct jingle_pvt *tmp;
ast_log(LOG_DEBUG, "The client is %s\n", client->name);
tmp = client->p;
/* Make sure our new call doesn't exist yet */
- while(tmp) {
- ast_verbose("FFFFF %s\n",tmp->sid);
- if (iks_find_with_attrib(pak->x, GOOGLE_NODE,GOOGLE_SID, tmp->sid)) {
+ while (tmp) {
+ ast_verbose("FFFFF %s\n", tmp->sid);
+ if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
break;
}
- tmp=tmp->next;
- }
-
+ tmp = tmp->next;
+ }
+
if (tmp) {
if (tmp->owner)
ast_queue_control(tmp->owner, AST_CONTROL_ANSWER);
@@ -506,20 +505,20 @@
return 1;
}
-static int jingle_hangup_farend(struct jingle *client,ikspak *pak)
+static int jingle_hangup_farend(struct jingle *client, ikspak *pak)
{
struct jingle_pvt *tmp;
ast_log(LOG_DEBUG, "The client is %s\n", client->name);
tmp = client->p;
/* Make sure our new call doesn't exist yet */
- while(tmp) {
- if (iks_find_with_attrib(pak->x, GOOGLE_NODE,GOOGLE_SID, tmp->sid)) {
+ while (tmp) {
+ if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
break;
}
- tmp=tmp->next;
- }
-
+ tmp = tmp->next;
+ }
+
if (tmp) {
tmp->alreadygone = 1;
ast_queue_hangup(tmp->owner);
@@ -530,11 +529,11 @@
return 1;
}
-static int jingle_create_candidates(struct jingle *client, struct jingle_pvt *p,char *sid, char *from)
+static int jingle_create_candidates(struct jingle *client, struct jingle_pvt *p, char *sid, char *from)
{
struct jingle_candidate *tmp;
struct aji_client *c = client->connection;
- struct jingle_candidate *ours1 = NULL , *ours2 =NULL;
+ struct jingle_candidate *ours1 = NULL, *ours2 = NULL;
struct sockaddr_in sin;
struct sockaddr_in dest;
struct in_addr us;
@@ -547,23 +546,23 @@
iq = iks_new("iq");
jingle = iks_new(GOOGLE_NODE);
candidate = iks_new("candidate");
- ours1 = (struct jingle_candidate *)ast_calloc(1, sizeof(struct jingle_candidate));
- ours2 = (struct jingle_candidate *)ast_calloc(1, sizeof(struct jingle_candidate));
- if (!iq || !jingle || !candidate ||!ours1 ||!ours2) {
+ ours1 = (struct jingle_candidate *) ast_calloc(1, sizeof(struct jingle_candidate));
+ ours2 = (struct jingle_candidate *) ast_calloc(1, sizeof(struct jingle_candidate));
+ if (!iq || !jingle || !candidate || !ours1 || !ours2) {
ast_log(LOG_WARNING, "out of memory!\n");
goto safeout;
}
- iks_insert_node(iq,jingle);
- iks_insert_node(jingle,candidate);
-
- while(p) {
- if(!strcasecmp(p->sid,sid)) {
+ iks_insert_node(iq, jingle);
+ iks_insert_node(jingle, candidate);
+
+ while (p) {
+ if (!strcasecmp(p->sid, sid)) {
break;
}
p = p->next;
}
-
+
if (!p) {
ast_log(LOG_NOTICE, "No matching jingle session!\n");
goto safeout;
@@ -573,74 +572,74 @@
ast_find_ourip(&us, bindaddr);
/* Setup our jingle candidates */
- ast_copy_string(ours1->name,"rtp",sizeof(ours1->name));
- ours1->port= ntohs(sin.sin_port);
- ours1->preference=1;
- snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
- snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
- ast_copy_string(ours1->username,user,sizeof(ours1->username));
- ast_copy_string(ours1->password,pass,sizeof(ours1->password));
+ ast_copy_string(ours1->name, "rtp", sizeof(ours1->name));
+ ours1->port = ntohs(sin.sin_port);
+ ours1->preference = 1;
+ snprintf(user, sizeof(user), "%08x%08x", thread_safe_rand(), thread_safe_rand());
+ snprintf(pass, sizeof(pass), "%08x%08x", thread_safe_rand(), thread_safe_rand());
+ ast_copy_string(ours1->username, user, sizeof(ours1->username));
+ ast_copy_string(ours1->password, pass, sizeof(ours1->password));
ast_inet_ntoa(ours1->ip, sizeof(ours1->ip), us);
- ours1->protocol=AJI_PROTOCOL_UDP;
- ours1->type=AJI_CONNECT_LOCAL;
- ours1->generation=0;
- p->ourcandidates=ours1;
+ ours1->protocol = AJI_PROTOCOL_UDP;
+ ours1->type = AJI_CONNECT_LOCAL;
+ ours1->generation = 0;
+ p->ourcandidates = ours1;
if (!ast_strlen_zero(externip)) {
/* XXX We should really stun for this one not just go with externip XXX */
- snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
- snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
- ast_copy_string(ours2->username,user,sizeof(ours2->username));
- ast_copy_string(ours2->password,pass,sizeof(ours2->password));
- ast_copy_string(ours2->ip,externip,sizeof(ours2->ip));
- ast_copy_string(ours2->name,"rtp",sizeof(ours1->name));
- ours2->port= ntohs(sin.sin_port);
- ours2->preference=0.9;
- ours2->protocol=AJI_PROTOCOL_UDP;
- ours2->type=AJI_CONNECT_STUN;
- ours2->generation=0;
- ours1->next=ours2;
+ snprintf(user, sizeof(user), "%08x%08x", thread_safe_rand(), thread_safe_rand());
+ snprintf(pass, sizeof(pass), "%08x%08x", thread_safe_rand(), thread_safe_rand());
+ ast_copy_string(ours2->username, user, sizeof(ours2->username));
+ ast_copy_string(ours2->password, pass, sizeof(ours2->password));
+ ast_copy_string(ours2->ip, externip, sizeof(ours2->ip));
+ ast_copy_string(ours2->name, "rtp", sizeof(ours1->name));
+ ours2->port = ntohs(sin.sin_port);
+ ours2->preference = 0.9;
+ ours2->protocol = AJI_PROTOCOL_UDP;
+ ours2->type = AJI_CONNECT_STUN;
+ ours2->generation = 0;
+ ours1->next = ours2;
ours2 = NULL;
}
ours1 = NULL;
- dest.sin_addr = __ourip; /// THIS IS BAD NEED TO FIX
+ dest.sin_addr = __ourip; /// THIS IS BAD NEED TO FIX
dest.sin_port = sin.sin_port;
-
- ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), us), ntohs(sin.sin_port)); /// THIS IS BAD NEED TO FIX
+
+ ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), us), ntohs(sin.sin_port)); /// THIS IS BAD NEED TO FIX
tmp = p->ourcandidates;
- while(tmp) { /*send standard candidates*/
- snprintf(port, sizeof(port),"%d",tmp->port);
- snprintf(preference,sizeof(preference),"%.2f",tmp->preference);
- iks_insert_attrib(iq,"from", c->jid->full);
- iks_insert_attrib(iq,"to", from);
- iks_insert_attrib(iq,"type", "set");
- iks_insert_attrib(iq,"id", c->mid);
+ while (tmp) { /*send standard candidates */
+ snprintf(port, sizeof(port), "%d", tmp->port);
+ snprintf(preference, sizeof(preference), "%.2f", tmp->preference);
+ iks_insert_attrib(iq, "from", c->jid->full);
+ iks_insert_attrib(iq, "to", from);
+ iks_insert_attrib(iq, "type", "set");
+ iks_insert_attrib(iq, "id", c->mid);
ast_aji_increment_mid(c->mid);
- iks_insert_attrib(jingle,"type", "candidates");
- iks_insert_attrib(jingle,"id", sid);
- iks_insert_attrib(jingle,"initiator",(p->initiator)?c->jid->full:from);
- iks_insert_attrib(jingle,"xmlns", GOOGLE_NS);
+ iks_insert_attrib(jingle, "type", "candidates");
+ iks_insert_attrib(jingle, "id", sid);
+ iks_insert_attrib(jingle, "initiator", (p->initiator) ? c->jid->full : from);
+ iks_insert_attrib(jingle, "xmlns", GOOGLE_NS);
iks_insert_attrib(candidate, "name", tmp->name);
- iks_insert_attrib(candidate, "address",tmp->ip);
+ iks_insert_attrib(candidate, "address", tmp->ip);
iks_insert_attrib(candidate, "port", port);
iks_insert_attrib(candidate, "username", tmp->username);
iks_insert_attrib(candidate, "password", tmp->password);
iks_insert_attrib(candidate, "preference", preference);
- if(tmp->protocol == AJI_PROTOCOL_UDP)
+ if (tmp->protocol == AJI_PROTOCOL_UDP)
iks_insert_attrib(candidate, "protocol", "udp");
- if(tmp->protocol == AJI_PROTOCOL_SSLTCP)
+ if (tmp->protocol == AJI_PROTOCOL_SSLTCP)
iks_insert_attrib(candidate, "protocol", "ssltcp");
- if(tmp->type == AJI_CONNECT_STUN)
+ if (tmp->type == AJI_CONNECT_STUN)
iks_insert_attrib(candidate, "type", "stun");
- if(tmp->type == AJI_CONNECT_LOCAL)
+ if (tmp->type == AJI_CONNECT_LOCAL)
iks_insert_attrib(candidate, "type", "local");
- if(tmp->type == AJI_CONNECT_RELAY)
+ if (tmp->type == AJI_CONNECT_RELAY)
iks_insert_attrib(candidate, "type", "relay");
iks_insert_attrib(candidate, "network", "0");
iks_insert_attrib(candidate, "generation", "0");
- iks_send(c->p,iq);
- tmp=tmp->next;
+ iks_send(c->p, iq);
+ tmp = tmp->next;
}
p->laststun = 0;
@@ -666,24 +665,26 @@
char idroster[200];
ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name);
- if(!sid && !strchr(from,'/')) { /*I started call! */
+ if (!sid && !strchr(from, '/')) { /*I started call! */
ast_verbose("shouldnt be called on inbound!\n");
- if(!strcasecmp(client->name, "guest")) {
- buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies,from);
- if(buddy) resources=buddy->resources;
- ast_verbose("shouldnt be called on inbound! %s ----- %s ---- %s\n",client->name, from,buddy->name);
+ if (!strcasecmp(client->name, "guest")) {
+ buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, from);
+ if (buddy)
+ resources = buddy->resources;
+ ast_verbose("shouldnt be called on inbound! %s ----- %s ---- %s\n",
+ client->name, from, buddy->name);
} else {
- resources=client->buddy->resources;
- }
- while(resources) {
- if(resources->jinglecapable) {
+ resources = client->buddy->resources;
+ }
+ while (resources) {
+ if (resources->jinglecapable) {
ast_verbose("WOW FOUND\n");
break;
}
- resources=resources->next;
- }
- if(resources)
- snprintf(idroster,sizeof(idroster), "%s/%s",from,resources->resource);
+ resources = resources->next;
+ }
+ if (resources)
+ snprintf(idroster, sizeof(idroster), "%s/%s", from, resources->resource);
else {
ast_log(LOG_ERROR, "no jingle capable clients to talk to.\n");
return NULL;
@@ -698,9 +699,9 @@
} else {
snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random());
ast_copy_string(tmp->from, idroster, sizeof(tmp->from));
- tmp->initiator=1;
- }
- tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+ tmp->initiator = 1;
+ }
+ tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
tmp->parent = client;
if (!tmp->rtp) {
ast_log(LOG_WARNING, "Out of RTP sessions?\n");
@@ -738,13 +739,17 @@
what = i->capability;
else
what = global_capability;
- tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
+ tmp->nativeformats =
+ ast_codec_choose(&i->prefs, what,
+ 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
fmt = ast_best_codec(tmp->nativeformats);
if (title)
- ast_string_field_build(tmp, name, "Jingle/%s-%04lx", title, ast_random() & 0xffff);
+ ast_string_field_build(tmp, name, "Jingle/%s-%04lx", title,
+ ast_random() & 0xffff);
else
- ast_string_field_build(tmp, name, "Jingle/%s-%04lx", i->from, ast_random() & 0xffff);
+ ast_string_field_build(tmp, name, "Jingle/%s-%04lx", i->from,
+ ast_random() & 0xffff);
if (i->rtp) {
tmp->fds[0] = ast_rtp_fd(i->rtp);
@@ -780,7 +785,7 @@
ast_mutex_unlock(&usecnt_lock);
ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
- if (!ast_strlen_zero(i->cid_num))
+ if (!ast_strlen_zero(i->cid_num))
tmp->cid.cid_num = ast_strdup(i->cid_num);
if (!ast_strlen_zero(i->cid_name))
tmp->cid.cid_name = ast_strdup(i->cid_name);
@@ -799,21 +804,22 @@
static int jingle_action(struct jingle *client, struct jingle_pvt *p, const char *action)
{
- iks *request, *session=NULL;
+ iks *request, *session = NULL;
int res = -1;
-
+
request = iks_new("iq");
if (request) {
- iks_insert_attrib(request,"type","set");
- iks_insert_attrib(request,"from", client->connection->jid->full);
- iks_insert_attrib(request,"to",p->from);
- iks_insert_attrib(request,"id",client->connection->mid);
+ iks_insert_attrib(request, "type", "set");
+ iks_insert_attrib(request, "from", client->connection->jid->full);
+ iks_insert_attrib(request, "to", p->from);
+ iks_insert_attrib(request, "id", client->connection->mid);
ast_aji_increment_mid(client->connection->mid);
session = iks_new("session");
if (session) {
iks_insert_attrib(session, "type", action);
iks_insert_attrib(session, "id", p->sid);
- iks_insert_attrib(session, "initiator", p->initiator ? client->connection->jid->full : p->from);
+ iks_insert_attrib(session, "initiator",
+ p->initiator ? client->connection->jid->full : p->from);
iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
iks_insert_node(request, session);
iks_send(client->connection->p, request);
@@ -837,13 +843,13 @@
static struct jingle_candidate *jingle_dup_candidates(struct jingle_candidate *candidate)
{
- struct jingle_candidate *newcan=NULL, *prev=NULL, *tmp;
+ struct jingle_candidate *newcan = NULL, *prev = NULL, *tmp;
while (candidate) {
tmp = malloc(sizeof(struct jingle_candidate));
if (tmp) {
memcpy(tmp, candidate, sizeof(struct jingle_candidate));
tmp->next = NULL;
- if (prev)
+ if (prev)
prev->next = tmp;
else
newcan = tmp;
@@ -884,22 +890,22 @@
static int jingle_newcall(struct jingle *client, ikspak *pak)
{
- struct jingle_pvt *p ,*tmp = client->p;
+ struct jingle_pvt *p, *tmp = client->p;
struct ast_channel *chan;
int res;
iks *codec;
/* Make sure our new call doesn't exist yet */
- while(tmp) {
- if (iks_find_with_attrib(pak->x, GOOGLE_NODE,GOOGLE_SID, tmp->sid)) {
+ while (tmp) {
+ if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
jingle_response(client, pak, "out-of-order");
return -1;
}
- tmp=tmp->next;
- }
-
- p = jingle_alloc(client, pak->from->partial, iks_find_attrib(pak->query,GOOGLE_SID));
+ tmp = tmp->next;
+ }
+
+ p = jingle_alloc(client, pak->from->partial, iks_find_attrib(pak->query, GOOGLE_SID));
if (!p) {
ast_log(LOG_WARNING, "Unable to allocate jingle structure!\n");
return -1;
@@ -908,18 +914,21 @@
if (chan) {
ast_mutex_lock(&p->lock);
ast_copy_string(p->from, pak->from->full, sizeof(p->from));
- if(iks_find_attrib(pak->query,GOOGLE_SID)) {
- ast_copy_string(p->sid,iks_find_attrib(pak->query,GOOGLE_SID),sizeof(p->sid));
- }
-
+ if (iks_find_attrib(pak->query, GOOGLE_SID)) {
+ ast_copy_string(p->sid, iks_find_attrib(pak->query, GOOGLE_SID),
+ sizeof(p->sid));
+ }
+
codec = iks_child(iks_child(iks_child(pak->x)));
- while(codec) {
- ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec,"id")));
- ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec,"id")), "audio", iks_find_attrib(codec,"name"));
+ while (codec) {
+ ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
+ ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio",
+ iks_find_attrib(codec, "name"));
ast_verbose("yatta!!\n");
- codec= iks_next(codec);
- }
- jingle_create_candidates(client, p, iks_find_attrib(pak->query,GOOGLE_SID), iks_find_attrib(pak->x,"from"));
+ codec = iks_next(codec);
+ }
+ jingle_create_candidates(client, p, iks_find_attrib(pak->query, GOOGLE_SID),
+ iks_find_attrib(pak->x, "from"));
ast_mutex_unlock(&p->lock);
ast_setstate(chan, AST_STATE_RING);
res = ast_pbx_start(chan);
@@ -956,62 +965,68 @@
tmp = p->theircandidates;
p->laststun = time(NULL);
- while(tmp) {
- char username[256];
+ while (tmp) {
+ char username[256];
hp = ast_gethostbyname(tmp->ip, &ahp);
sin.sin_family = AF_INET;
memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
sin.sin_port = htons(tmp->port);
- snprintf(username, sizeof(username), "%s%s", tmp->username, p->ourcandidates->username);
-
+ snprintf(username, sizeof(username), "%s%s", tmp->username,
+ p->ourcandidates->username);
+
ast_rtp_stun_request(p->rtp, &sin, username);
tmp = tmp->next;
}
return 1;
}
-static int jingle_add_candidate(struct jingle *client,ikspak *pak)
-{
- struct jingle_pvt *p =NULL,*tmp = NULL;
+static int jingle_add_candidate(struct jingle *client, ikspak *pak)
+{
+ struct jingle_pvt *p = NULL, *tmp = NULL;
struct aji_client *c = client->connection;
struct jingle_candidate *newcandidate = NULL;
iks *candidate_node = NULL;
iks *receipt = NULL;
- newcandidate = (struct jingle_candidate *)ast_calloc(1, sizeof(struct jingle_candidate));
- if(!newcandidate)
+ newcandidate =
+ (struct jingle_candidate *) ast_calloc(1, sizeof(struct jingle_candidate));
+ if (!newcandidate)
return 0;
- memset(newcandidate,0,sizeof(struct jingle_candidate));
+ memset(newcandidate, 0, sizeof(struct jingle_candidate));
tmp = client->p;
- while(tmp) {
- if(iks_find_with_attrib(pak->x,GOOGLE_NODE,GOOGLE_SID,tmp->sid)) {
+ while (tmp) {
+ if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
p = tmp;
break;
}
- tmp=tmp->next;
- }
-
- if(!p) {
+ tmp = tmp->next;
+ }
+
+ if (!p) {
ast_verbose("NO MATCH\n");
return -1;
}
- candidate_node = iks_find(pak->query,"candidate");
- ast_copy_string(newcandidate->name,iks_find_attrib(candidate_node, "name"),sizeof(newcandidate->name));
- ast_copy_string(newcandidate->ip, iks_find_attrib(candidate_node, "address"),sizeof(newcandidate->ip));
+ candidate_node = iks_find(pak->query, "candidate");
+ ast_copy_string(newcandidate->name, iks_find_attrib(candidate_node, "name"),
+ sizeof(newcandidate->name));
+ ast_copy_string(newcandidate->ip, iks_find_attrib(candidate_node, "address"),
+ sizeof(newcandidate->ip));
newcandidate->port = atoi(iks_find_attrib(candidate_node, "port"));
- ast_copy_string(newcandidate->username, iks_find_attrib(candidate_node, "username"),sizeof(newcandidate->username));
- ast_copy_string(newcandidate->password, iks_find_attrib(candidate_node, "password"),sizeof(newcandidate->password));
+ ast_copy_string(newcandidate->username, iks_find_attrib(candidate_node, "username"),
+ sizeof(newcandidate->username));
+ ast_copy_string(newcandidate->password, iks_find_attrib(candidate_node, "password"),
+ sizeof(newcandidate->password));
newcandidate->preference = atof(iks_find_attrib(candidate_node, "preference"));
- if(!strcasecmp(iks_find_attrib(candidate_node, "protocol"),"udp"))
+ if (!strcasecmp(iks_find_attrib(candidate_node, "protocol"), "udp"))
newcandidate->protocol = AJI_PROTOCOL_UDP;
- if(!strcasecmp(iks_find_attrib(candidate_node, "protocol"),"ssltcp"))
+ if (!strcasecmp(iks_find_attrib(candidate_node, "protocol"), "ssltcp"))
newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
- if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"stun"))
+ if (!strcasecmp(iks_find_attrib(candidate_node, "type"), "stun"))
newcandidate->type = AJI_CONNECT_STUN;
- if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"local"))
+ if (!strcasecmp(iks_find_attrib(candidate_node, "type"), "local"))
newcandidate->type = AJI_CONNECT_LOCAL;
- if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"relay"))
+ if (!strcasecmp(iks_find_attrib(candidate_node, "type"), "relay"))
newcandidate->type = AJI_CONNECT_RELAY;
newcandidate->network = atoi(iks_find_attrib(candidate_node, "network"));
@@ -1022,11 +1037,11 @@
p->theircandidates = newcandidate;
p->laststun = 0;
receipt = iks_new("iq");
- iks_insert_attrib(receipt,"type","result");
- iks_insert_attrib(receipt,"from",c->jid->full);
- iks_insert_attrib(receipt,"to",iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(receipt,"id",iks_find_attrib(pak->x,"id"));
- iks_send(c->p,receipt);
+ iks_insert_attrib(receipt, "type", "result");
+ iks_insert_attrib(receipt, "from", c->jid->full);
+ iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
+ iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
+ iks_send(c->p, receipt);
iks_delete(receipt);
jingle_update_stun(p->parent, p);
return 1;
@@ -1046,7 +1061,8 @@
if (f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
if (option_debug)
ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
- p->owner->nativeformats = (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
+ p->owner->nativeformats =
+ (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
ast_set_read_format(p->owner, p->owner->readformat);
ast_set_write_format(p->owner, p->owner->writeformat);
}
@@ -1060,11 +1076,11 @@
return f;
}
-static struct ast_frame *jingle_read(struct ast_channel *ast)
+static struct ast_frame *jingle_read(struct ast_channel *ast)
{
struct ast_frame *fr;
struct jingle_pvt *p = ast->tech_pvt;
-
+
ast_mutex_lock(&p->lock);
fr = jingle_rtp_read(ast, p);
ast_mutex_unlock(&p->lock);
@@ -1080,14 +1096,16 @@
switch (frame->frametype) {
case AST_FRAME_VOICE:
if (!(frame->subclass & ast->nativeformats)) {
- ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
+ ast_log(LOG_WARNING,
+ "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
+ frame->subclass, ast->nativeformats, ast->readformat,
+ ast->writeformat);
return 0;
}
if (p) {
ast_mutex_lock(&p->lock);
if (p->rtp) {
- res = ast_rtp_write(p->rtp, frame);
+ res = ast_rtp_write(p->rtp, frame);
}
ast_mutex_unlock(&p->lock);
}
@@ -1096,7 +1114,7 @@
if (p) {
ast_mutex_lock(&p->lock);
if (p->vrtp) {
- res = ast_rtp_write(p->vrtp, frame);
+ res = ast_rtp_write(p->vrtp, frame);
}
ast_mutex_unlock(&p->lock);
}
@@ -1104,8 +1122,9 @@
case AST_FRAME_IMAGE:
return 0;
break;
- default:
- ast_log(LOG_WARNING, "Can't send %d type frames with Jingle write\n", frame->frametype);
+ default:
+ ast_log(LOG_WARNING, "Can't send %d type frames with Jingle write\n",
+ frame->frametype);
return 0;
}
@@ -1117,7 +1136,7 @@
struct jingle_pvt *p = newchan->tech_pvt;
ast_mutex_lock(&p->lock);
- if ((p->owner != oldchan) ) {
+ if ((p->owner != oldchan)) {
ast_mutex_unlock(&p->lock);
return -1;
}
@@ -1144,7 +1163,8 @@
return res;
}
-static int jingle_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
+static int jingle_sendhtml(struct ast_channel *ast, int subclass, const char *data,
+ int datalen)
{
struct jingle_pvt *p = ast->tech_pvt;
int res = -1;
@@ -1157,34 +1177,34 @@
struct jingle *jingle = NULL;
struct aji_client *client = NULL;
iks *iq, *desc, *session;
- iks *payload_eg711u , *payload_pcmu;
+ iks *payload_eg711u, *payload_pcmu;
jingle = p->parent;
client = jingle->connection;
iq = iks_new("iq");
desc = iks_new("description");
session = iks_new("session");
- iks_insert_attrib(iq,"type","set");
- iks_insert_attrib(iq,"to",p->from);
- iks_insert_attrib(iq,"from",client->jid->full);
- iks_insert_attrib(iq,"id",client->mid);
+ iks_insert_attrib(iq, "type", "set");
+ iks_insert_attrib(iq, "to", p->from);
+ iks_insert_attrib(iq, "from", client->jid->full);
+ iks_insert_attrib(iq, "id", client->mid);
ast_aji_increment_mid(client->mid);
- iks_insert_attrib(session,"type","initiate");
+ iks_insert_attrib(session, "type", "initiate");
iks_insert_attrib(session, "id", p->sid);
- iks_insert_attrib(session,"initiator",client->jid->full);
- iks_insert_attrib(session,"xmlns","http://www.google.com/session");
- iks_insert_attrib(desc,"xmlns","http://www.google.com/session/phone");
+ iks_insert_attrib(session, "initiator", client->jid->full);
+ iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
+ iks_insert_attrib(desc, "xmlns", "http://www.google.com/session/phone");
[... 569 lines stripped ...]
More information about the asterisk-commits
mailing list