[asterisk-commits] branch mogorman/asterisk-xmpp r9843 - in
/team/mogorman/asterisk-xmpp: channe...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Feb 13 18:57:30 MST 2006
Author: mogorman
Date: Mon Feb 13 19:57:29 2006
New Revision: 9843
URL: http://svn.digium.com/view/asterisk?rev=9843&view=rev
Log:
more updates, making things really work.
Modified:
team/mogorman/asterisk-xmpp/channels/chan_xmpp.c
team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h
team/mogorman/asterisk-xmpp/res/res_xmpp.c
Modified: team/mogorman/asterisk-xmpp/channels/chan_xmpp.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/chan_xmpp.c?rev=9843&r1=9842&r2=9843&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_xmpp.c Mon Feb 13 19:57:29 2006
@@ -74,6 +74,9 @@
/* Protect the interface list (of sip_pvt's) */
AST_MUTEX_DEFINE_STATIC(xmpplock);
+
+AST_MUTEX_DEFINE_STATIC(rand_lock); /*!< Lock for thread-safe random generator */
+
static struct ast_channel *xmpp_request(const char *type, int format, void *data, int *cause);
static int xmpp_digit(struct ast_channel *ast, char digit);
@@ -171,100 +174,116 @@
return res;
}
+static force_inline int thread_safe_rand(void)
+{
+ int val;
+
+ ast_mutex_lock(&rand_lock);
+ val = rand();
+ ast_mutex_unlock(&rand_lock);
+
+ return val;
+}
+
static int xmpp_create_candidates(struct axi_client *client,ikspak *pak)
{
- if(!client->candidates) { /*send standard candidates*/
- iks *iq1, *iq2, *iq3, *jingle1, *jingle2, *jingle3, *candidate1, *candidate2, *candidate3;
- iq1 = iks_new("iq");
- iq2 = iks_new("iq");
- iq3 = iks_new("iq");
- jingle1 = iks_new(GOOGLE_NODE);
- jingle2 = iks_new(GOOGLE_NODE);
- jingle3 = iks_new(GOOGLE_NODE);
- candidate1 = iks_new("candidate");
- candidate2 = iks_new("candidate");
- candidate3 = iks_new("candidate");
-
- iks_insert_attrib(iq1,"from", client->jid->full);
- iks_insert_attrib(iq1,"to", iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(iq1,"type", "set");
- iks_insert_attrib(iq1,"id", client->mid);
+ struct axi_candidate *tmp;
+ iks *iq, *jingle, *candidate;
+ char user[17], pass[17], preference[5];
+ tmp = client->candidates;
+ iq = iks_new("iq");
+ jingle = iks_new(GOOGLE_NODE);
+ candidate = iks_new("candidate");
+ iks_insert_node(iq,jingle);
+ iks_insert_node(jingle,candidate);
+
+ while(tmp) { /*send standard candidates*/
+ snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand() ,thread_safe_rand());
+ snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(), thread_safe_rand());
+ snprintf(preference,sizeof(preference),"%.2f",tmp->preference);
+ iks_insert_attrib(iq,"from", client->jid->full);
+ iks_insert_attrib(iq,"to", iks_find_attrib(pak->x,"from"));
+ iks_insert_attrib(iq,"type", "set");
+ iks_insert_attrib(iq,"id", client->mid);
axi_increment_mid(client->mid);
- iks_insert_attrib(iq2,"from", client->jid->full);
- iks_insert_attrib(iq2,"to", iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(iq2,"type", "set");
- iks_insert_attrib(iq2,"id", client->mid);
+ iks_insert_attrib(jingle,"type", "candidates");
+ iks_insert_attrib(jingle,"id", iks_find_attrib(pak->query,GOOGLE_SID));
+ iks_insert_attrib(jingle,"initiator",iks_find_attrib(pak->x,"from"));
+ iks_insert_attrib(jingle,"xmlns", GOOGLE_NS);
+ iks_insert_attrib(candidate, "name", tmp->name);
+ iks_insert_attrib(candidate, "address", client->localip);
+ iks_insert_attrib(candidate, "port", "1234"); /*FIX ME*/
+ iks_insert_attrib(candidate, "username", user);
+ iks_insert_attrib(candidate, "password", pass);
+
+ iks_insert_attrib(candidate, "preference", preference);
+ if(tmp->protocol == AXI_PROTOCOL_UDP)
+ iks_insert_attrib(candidate, "protocol", "udp");
+ if(tmp->protocol == AXI_PROTOCOL_SSLTCP)
+ iks_insert_attrib(candidate, "protocol", "ssltcp");
+ if(tmp->type == AXI_CONNECT_STUN)
+ iks_insert_attrib(candidate, "type", "stun");
+ if(tmp->type == AXI_CONNECT_LOCAL)
+ iks_insert_attrib(candidate, "type", "local");
+ if(tmp->type == AXI_CONNECT_RELAY)
+ iks_insert_attrib(candidate, "type", "relay");
+ iks_insert_attrib(candidate, "network", "0");
+ iks_insert_attrib(candidate, "generation", "0");
+ iks_send(client->p,iq);
+ tmp=tmp->next;
+ }
+ if(!client->candidates) { /*send default stun, and local, and relay */
+ snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
+ snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
+ iks_insert_attrib(iq,"from", client->jid->full);
+ iks_insert_attrib(iq,"to", iks_find_attrib(pak->x,"from"));
+ iks_insert_attrib(iq,"type", "set");
+ iks_insert_attrib(iq,"id", client->mid);
axi_increment_mid(client->mid);
- iks_insert_attrib(iq3,"from", client->jid->full);
- iks_insert_attrib(iq3,"to", iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(iq3,"type", "set");
- iks_insert_attrib(iq3,"id", client->mid);
+ iks_insert_attrib(jingle,"type", "candidates");
+ iks_insert_attrib(jingle,"id", iks_find_attrib(pak->query,GOOGLE_SID));
+ iks_insert_attrib(jingle,"initiator",iks_find_attrib(pak->x,"from"));
+ iks_insert_attrib(jingle,"xmlns", GOOGLE_NS);
+ iks_insert_attrib(candidate, "name", "rtp");
+ iks_insert_attrib(candidate, "address", client->localip);
+ iks_insert_attrib(candidate, "port", "1234"); /*FIX ME*/
+ iks_insert_attrib(candidate, "username", user);
+ iks_insert_attrib(candidate, "password", pass);
+ iks_insert_attrib(candidate, "preference", "1");
+ iks_insert_attrib(candidate, "protocol", "udp");
+ iks_insert_attrib(candidate, "type", "local");
+ iks_insert_attrib(candidate, "network", "0");
+ iks_insert_attrib(candidate, "generation", "0");
+ iks_send(client->p,iq);
+
+ snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
+ snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
+ iks_insert_attrib(iq,"id", client->mid);
axi_increment_mid(client->mid);
-
- iks_insert_attrib(jingle1,"type", "candidates");
- iks_insert_attrib(jingle1,"id", iks_find_attrib(pak->query,GOOGLE_SID));
- iks_insert_attrib(jingle1,"initiator",iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(jingle1,"xmlns", GOOGLE_NS);
- iks_insert_attrib(jingle2,"type", "candidates");
- iks_insert_attrib(jingle2,"id", iks_find_attrib(pak->query,GOOGLE_SID));
- iks_insert_attrib(jingle2,"initiator",iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(jingle2,"xmlns", GOOGLE_NS);
- iks_insert_attrib(jingle3,"type", "candidates");
- iks_insert_attrib(jingle3,"id", iks_find_attrib(pak->query,GOOGLE_SID));
- iks_insert_attrib(jingle3,"initiator",iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(jingle3,"xmlns", GOOGLE_NS);
-
- iks_insert_attrib(candidate1, "name", "rtp");
- iks_insert_attrib(candidate1, "address", client->localip);
- iks_insert_attrib(candidate1, "port", "1234"); /*FIX ME*/
- iks_insert_attrib(candidate1, "username", "abcdefghijk23456");
- iks_insert_attrib(candidate1, "password", "sdf432kjhhijk2ka");
- iks_insert_attrib(candidate1, "preference", "1");
- iks_insert_attrib(candidate1, "protocol", "udp");
- iks_insert_attrib(candidate1, "type", "local");
- iks_insert_attrib(candidate1, "network", "0");
- iks_insert_attrib(candidate1, "generation", "0");
- iks_insert_attrib(candidate2, "name", "rtp");
- iks_insert_attrib(candidate2, "address", client->externip);
- iks_insert_attrib(candidate2, "port", "1235");
- iks_insert_attrib(candidate2, "username", "dasasdf432kjhkjl");
- iks_insert_attrib(candidate2, "password", "sdfee2keheqjk2ka");
- iks_insert_attrib(candidate2, "preference", "0.9");
- iks_insert_attrib(candidate2, "protocol", "udp");
- iks_insert_attrib(candidate2, "type", "stun");
- iks_insert_attrib(candidate2, "network", "0");
- iks_insert_attrib(candidate2, "generation", "0");
- iks_insert_attrib(candidate3, "name", "rtp");
- iks_insert_attrib(candidate3, "address", client->localip);
- iks_insert_attrib(candidate3, "port", "19295"); /*FIX ME*/
- iks_insert_attrib(candidate3, "username", "aeeeefghijk23456");
- iks_insert_attrib(candidate3, "password", "sdf432kjhhijk2ka");
- iks_insert_attrib(candidate3, "preference", "0.5");
- iks_insert_attrib(candidate3, "protocol", "ssltcp");
- iks_insert_attrib(candidate3, "type", "relay");
- iks_insert_attrib(candidate3, "network", "0");
- iks_insert_attrib(candidate3, "generation", "0");
-
+ iks_insert_attrib(candidate, "address", client->externip);
+ iks_insert_attrib(candidate, "port", "1235");
+ iks_insert_attrib(candidate, "username", user);
+ iks_insert_attrib(candidate, "password", pass);
+ iks_insert_attrib(candidate, "preference", "0.9");
+ iks_insert_attrib(candidate, "type", "stun");
+ iks_send(client->p,iq);
- iks_insert_node(iq1,jingle1);
- iks_insert_node(jingle1,candidate1);
- iks_send(client->p,iq1);
- iks_delete(candidate1);
- iks_delete(jingle1);
- iks_delete(iq1);
- iks_insert_node(iq2,jingle2);
- iks_insert_node(jingle2,candidate2);
- iks_send(client->p,iq2);
- iks_delete(candidate2);
- iks_delete(jingle2);
- iks_delete(iq2);
- iks_insert_node(iq3,jingle3);
- iks_insert_node(jingle3,candidate3);
- iks_send(client->p,iq3);
- iks_delete(candidate3);
- iks_delete(jingle3);
- iks_delete(iq3);
- }
+ snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
+ snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
+ iks_insert_attrib(iq,"id", client->mid);
+ axi_increment_mid(client->mid);
+ iks_insert_attrib(candidate, "address", client->localip);
+ iks_insert_attrib(candidate, "port", "19295"); /*FIX ME*/
+ iks_insert_attrib(candidate, "username", user);
+ iks_insert_attrib(candidate, "password", pass);
+ iks_insert_attrib(candidate, "preference", "0.5");
+ iks_insert_attrib(candidate, "protocol", "ssltcp");
+ iks_insert_attrib(candidate, "type", "relay");
+ iks_send(client->p,iq);
+ }
+ iks_delete(candidate);
+ iks_delete(jingle);
+ iks_delete(iq);
}
static int xmpp_accept_call(struct axi_client *client, ikspak *pak)
@@ -398,16 +417,16 @@
}
p = xmpp_alloc2(client);
ast_mutex_lock(&p->lock);
- if(iks_find_attrib(pak->x,JINGLE_FROM))
- ast_copy_string(p->from,iks_find_attrib(pak->x,JINGLE_FROM),sizeof(p->from));
+ if(iks_find_attrib(pak->x,"from"))
+ ast_copy_string(p->from,iks_find_attrib(pak->x,"from"),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));
}
ast_mutex_unlock(&p->lock);
accept = iks_new("iq");
iks_insert_attrib(accept,"type","result");
- iks_insert_attrib(accept,JINGLE_FROM,client->jid->full);
- iks_insert_attrib(accept,"to",iks_find_attrib(pak->x,JINGLE_FROM));
+ iks_insert_attrib(accept,"from",client->jid->full);
+ iks_insert_attrib(accept,"to",iks_find_attrib(pak->x,"from"));
iks_insert_attrib(accept,"id",iks_find_attrib(pak->x,"id"));
iks_send(client->p,accept);
iks_delete(accept);
@@ -464,8 +483,8 @@
ast_verbose("sending\n");
receipt = iks_new("iq");
iks_insert_attrib(receipt,"type","result");
- iks_insert_attrib(receipt,JINGLE_FROM,client->jid->full);
- iks_insert_attrib(receipt,"to",iks_find_attrib(pak->x,JINGLE_FROM));
+ iks_insert_attrib(receipt,"from",client->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(client->p,receipt);
iks_delete(receipt);
Modified: team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h?rev=9843&r1=9842&r2=9843&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h Mon Feb 13 19:57:29 2006
@@ -70,13 +70,6 @@
struct axi_candidate *next;
};
-struct axi_send_candidate {
- iks *iq;
- iks *jingle;
- iks *candidate;
- struct axi_send_candidate *next;
-};
-
struct axi_buddy {
ASTOBJ_COMPONENTS(struct axi_buddy);
char user[160];
@@ -133,7 +126,7 @@
char localip[16];
enum axi_type component;
struct axi_buddy_container buddies;
- struct axi_send_candidate *candidates;
+ struct axi_candidate *candidates;
iks *accept;
struct xmpp_pvt *xmpps;
pthread_t thread;
@@ -189,8 +182,6 @@
#define JINGLE_SID "sid"
#define GOOGLE_SID "id"
-#define JINGLE_FROM "from"
-
#define JINGLE_INITIATE "initiate"
#define JINGLE_ACCEPT "accept"
Modified: team/mogorman/asterisk-xmpp/res/res_xmpp.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/res_xmpp.c?rev=9843&r1=9842&r2=9843&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_xmpp.c Mon Feb 13 19:57:29 2006
@@ -1184,49 +1184,56 @@
return 1;
}
-//static struct axi_send_candidate *axi_create_candidate(char *args)
-//{
-// char *name, *preference, *protocol, *type;
-// struct axi_send_candidate *res;
-// res= malloc(sizeof(struct axi_send_candidate));
-// memset(res,0,sizeof(struct axi_send_candidate));
-// res->iq = iks_new("iq");
-// res->jingle = iks_new(GOOGLE_NODE);
-// res->candidate = iks_new(GOOGLE_NEGOTIATE);
-// if(args)
-// name = args;
-// if((args = strchr(args,','))) {
-// *args='\0';
-// args++;
-// preference = args;
-// }
-// if((args = strchr(args, ','))) {
-// *args='\0';
-// args++;
-// protocol=args;
-// }
-// if((args = strchr(args, ','))) {
-// *args='\0';
-// args++;
-// type=args;
-// }
-// iks_insert_attrib(res->iq,"type","set");
-// if(name)
-// iks_insert_attrib(res->candidate,"name",name);
-// if(preference)
-// iks_insert_attrib(res->candidate,"preference",preference);
-// if(protocol)
-// iks_insert_attrib(res->candidate,"protocol",protocol);
-// if(type)
-// iks_insert_attrib(res->candidate,"type",type);
-//
-// return res;
-//}
+static struct axi_candidate *axi_create_candidate(char *args)
+{
+ char *name, *type, *preference, *protocol;
+ struct axi_candidate *res;
+ res= malloc(sizeof(struct axi_candidate));
+ memset(res,0,sizeof(struct axi_candidate));
+ if(args)
+ name = args;
+ if((args = strchr(args,','))) {
+ *args='\0';
+ args++;
+ preference = args;
+ }
+ if((args = strchr(args, ','))) {
+ *args='\0';
+ args++;
+ protocol=args;
+ }
+ if((args = strchr(args, ','))) {
+ *args='\0';
+ args++;
+ type=args;
+ }
+ if(name)
+ ast_copy_string(res->name,name,sizeof(res->name));
+ if(preference) {
+ res->preference = atof(preference);
+ }
+ if(protocol) {
+ if(!strcasecmp("udp",protocol))
+ res->protocol=AXI_PROTOCOL_UDP;
+ if(!strcasecmp("ssltcp",protocol))
+ res->protocol=AXI_PROTOCOL_SSLTCP;
+ }
+ if(type) {
+ if(!strcasecmp("stun",type))
+ res->type = AXI_CONNECT_STUN;
+ if(!strcasecmp("local",type))
+ res->type = AXI_CONNECT_LOCAL;
+ if(!strcasecmp("relay",type))
+ res->type = AXI_CONNECT_RELAY;
+ }
+
+ return res;
+}
static int *axi_create_client(char *label,struct ast_variable *var, int debug, int pruneregister,char *utype, struct axi_client *client)
{
struct axi_buddy *buddy;
- struct axi_send_candidate *sc;
+ struct axi_candidate *sc;
if(!client)
ast_log(LOG_WARNING, "Out of memory\n");
@@ -1292,11 +1299,11 @@
ASTOBJ_CONTAINER_LINK(&client->buddies,buddy);
ASTOBJ_UNREF(buddy,axi_buddy_destroy);
}
-// if(!strcasecmp(var->name,"candidate")) {
-// sc = axi_create_candidate(var->value);
-// sc->next = client->candidates;
-// client->candidates = sc;
-// }
+ if(!strcasecmp(var->name,"candidate")) {
+ sc = axi_create_candidate(var->value);
+ sc->next = client->candidates;
+ client->candidates = sc;
+ }
var = var->next;
}
More information about the asterisk-commits
mailing list