[asterisk-commits] branch mogorman/asterisk-xmpp r9208 - in
/team/mogorman/asterisk-xmpp: channe...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Feb 7 18:35:53 MST 2006
Author: mogorman
Date: Tue Feb 7 19:35:51 2006
New Revision: 9208
URL: http://svn.digium.com/view/asterisk?rev=9208&view=rev
Log:
call setup seems to work but does not appeared
answered.
Modified:
team/mogorman/asterisk-xmpp/channels/Makefile
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/Makefile
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/Makefile?rev=9208&r1=9207&r2=9208&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/Makefile (original)
+++ team/mogorman/asterisk-xmpp/channels/Makefile Tue Feb 7 19:35:51 2006
@@ -56,6 +56,16 @@
endif
endif
endif
+
+ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/iksemel.h),)
+ CHANNEL_LIBS+=chan_xmpp.so
+ XMPPLIB=$(CROSS_COMPILE_TARGET)/usr/local/lib/libiksemel.a
+ else
+ ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/iksemel.h),)
+ CHANNEL_LIBS+=chan_xmpp.so
+ XMPPLIB=$(CROSS_COMPILE_TARGET)/usr/lib/libiksemel.a
+ endif
+ endif
ifeq (${OSARCH},SunOS)
SOLINK+=-lrt
@@ -230,6 +240,9 @@
chan_misdn.o: chan_misdn.c
$(CC) $(CFLAGS) -DCHAN_MISDN_VERSION=\"0.2.1\" -c $< -o $@
+chan_xmpp.so: chan_xmpp.o
+ $(CC) $(SOLINK) -o $@ $< $(XMPP_LIB)
+
install: all
for x in $(CHANNEL_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
if ! [ -f chan_iax.so ]; then rm -f $(DESTDIR)$(MODULES_DIR)/chan_iax.so ; fi
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=9208&r1=9207&r2=9208&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_xmpp.c Tue Feb 7 19:35:51 2006
@@ -40,7 +40,7 @@
#include "asterisk.h"
-ASTERISK_FILE_VERSION(__FILE__, "$Revision: 8513 $")
+ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1 $")
#include "asterisk/lock.h"
#include "asterisk/channel.h"
@@ -60,6 +60,7 @@
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/manager.h"
+#include "asterisk/stringfields.h"
#include "asterisk/xmpp.h"
static const char desc[] = "XMPP Channel";
@@ -69,7 +70,7 @@
static int usecnt =0;
AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
+//#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
/* Protect the interface list (of sip_pvt's) */
AST_MUTEX_DEFINE_STATIC(xmpplock);
@@ -79,6 +80,7 @@
static int xmpp_call(struct ast_channel *ast, char *dest, int timeout);
static int xmpp_hangup(struct ast_channel *ast);
static int xmpp_answer(struct ast_channel *ast);
+static int xmpp_answer2(struct axi_client *client, ikspak *pak);
static struct ast_frame *xmpp_read(struct ast_channel *ast);
static int xmpp_write(struct ast_channel *ast, struct ast_frame *f);
static int xmpp_indicate(struct ast_channel *ast, int condition);
@@ -111,74 +113,77 @@
// int alreadymasqed; /* Already masqueraded */
// int launchedpbx; /* Did we launch the PBX */
// int nooptimization; /* Don't leave masq state */
- AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(callid); /*!< Global CallID */
- AST_STRING_FIELD(randdata); /*!< Random data */
- AST_STRING_FIELD(accountcode); /*!< Account code */
- AST_STRING_FIELD(realm); /*!< Authorization realm */
- AST_STRING_FIELD(nonce); /*!< Authorization nonce */
- AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
- AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
- AST_STRING_FIELD(domain); /*!< Authorization domain */
- AST_STRING_FIELD(refer_to); /*!< Place to store REFER-TO extension */
- AST_STRING_FIELD(referred_by); /*!< Place to store REFERRED-BY extension */
- AST_STRING_FIELD(refer_contact);/*!< Place to store Contact info from a REFER extension */
- AST_STRING_FIELD(from); /*!< The From: header */
- AST_STRING_FIELD(useragent); /*!< User agent in SIP request */
- AST_STRING_FIELD(exten); /*!< Extension where to start */
- AST_STRING_FIELD(context); /*!< Context for this call */
- AST_STRING_FIELD(subscribecontext); /*!< Subscribecontext */
- AST_STRING_FIELD(fromdomain); /*!< Domain to show in the from field */
- AST_STRING_FIELD(fromuser); /*!< User to show in the user field */
- AST_STRING_FIELD(fromname); /*!< Name to show in the user field */
- AST_STRING_FIELD(tohost); /*!< Host we should put in the "to" field */
- AST_STRING_FIELD(language); /*!< Default language for this call */
- AST_STRING_FIELD(musicclass); /*!< Music on Hold class */
- AST_STRING_FIELD(rdnis); /*!< Referring DNIS */
- AST_STRING_FIELD(theirtag); /*!< Their tag */
- AST_STRING_FIELD(username); /*!< [user] name */
- AST_STRING_FIELD(peername); /*!< [peer] name, not set if [user] */
- AST_STRING_FIELD(authname); /*!< Who we use for authentication */
- AST_STRING_FIELD(uri); /*!< Original requested URI */
- AST_STRING_FIELD(okcontacturi); /*!< URI from the 200 OK on INVITE */
- AST_STRING_FIELD(peersecret); /*!< Password */
- AST_STRING_FIELD(peermd5secret);
- AST_STRING_FIELD(cid_num); /*!< Caller*ID */
- AST_STRING_FIELD(cid_name); /*!< Caller*ID */
- AST_STRING_FIELD(via); /*!< Via: header */
- AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
- AST_STRING_FIELD(our_contact); /*!< Our contact header */
- AST_STRING_FIELD(rpid); /*!< Our RPID header */
- AST_STRING_FIELD(rpid_from); /*!< Our RPID From header */
- );
+ char sid[100];
+ char from[100];
+// AST_DECLARE_STRING_FIELDS(
+// AST_STRING_FIELD(callid); /*!< Global CallID */
+// AST_STRING_FIELD(randdata); /*!< Random data */
+// AST_STRING_FIELD(accountcode); /*!< Account code */
+// AST_STRING_FIELD(realm); /*!< Authorization realm */
+// AST_STRING_FIELD(nonce); /*!< Authorization nonce */
+// AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
+// AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
+// AST_STRING_FIELD(domain); /*!< Authorization domain */
+// AST_STRING_FIELD(refer_to); /*!< Place to store REFER-TO extension */
+// AST_STRING_FIELD(referred_by); /*!< Place to store REFERRED-BY extension */
+// AST_STRING_FIELD(refer_contact);/*!< Place to store Contact info from a REFER extension */
+// AST_STRING_FIELD(useragent); /*!< User agent in SIP request */
+// AST_STRING_FIELD(exten); /*!< Extension where to start */
+// AST_STRING_FIELD(context); /*!< Context for this call */
+// AST_STRING_FIELD(subscribecontext); /*!< Subscribecontext */
+// AST_STRING_FIELD(fromdomain); /*!< Domain to show in the from field */
+// AST_STRING_FIELD(fromuser); /*!< User to show in the user field */
+// AST_STRING_FIELD(fromname); /*!< Name to show in the user field */
+// AST_STRING_FIELD(tohost); /*!< Host we should put in the "to" field */
+// AST_STRING_FIELD(language); /*!< Default language for this call */
+// AST_STRING_FIELD(musicclass); /*!< Music on Hold class */
+// AST_STRING_FIELD(rdnis); /*!< Referring DNIS */
+// AST_STRING_FIELD(theirtag); /*!< Their tag */
+// AST_STRING_FIELD(username); /*!< [user] name */
+// AST_STRING_FIELD(peername); /*!< [peer] name, not set if [user] */
+// AST_STRING_FIELD(authname); /*!< Who we use for authentication */
+// AST_STRING_FIELD(uri); /*!< Original requested URI */
+// AST_STRING_FIELD(okcontacturi); /*!< URI from the 200 OK on INVITE */
+// AST_STRING_FIELD(peersecret); /*!< Password */
+// AST_STRING_FIELD(peermd5secret);
+// AST_STRING_FIELD(cid_num); /*!< Caller*ID */
+// AST_STRING_FIELD(cid_name); /*!< Caller*ID */
+// AST_STRING_FIELD(via); /*!< Via: header */
+// AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
+// AST_STRING_FIELD(our_contact); /*!< Our contact header */
+// AST_STRING_FIELD(rpid); /*!< Our RPID header */
+// AST_STRING_FIELD(rpid_from); /*!< Our RPID From header */
+// );
struct axi_candidate *candidates;
struct ast_channel *owner; /* Master Channel */
struct xmpp_pvt *next; /* Next entity */
} *xmpps = NULL;
+int flipflop = 0;
+static struct xmpp_pvt *xmpp_alloc(char *data, int format);
static int xmpp_queue_frame(struct xmpp_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
{
struct ast_channel *other;
retrylock:
/* Recalculate outbound channel */
- if (isoutbound) {
+/* if (isoutbound) {
other = p->owner;
} else {
other = p->chan;
- }
+ }*/
/* Set glare detection */
- p->glaredetect = 1;
- if (p->cancelqueue) {
- /* We had a glare on the hangup. Forget all this business,
- return and destroy p. */
+/* p->glaredetect = 1; */
+/* if (p->cancelqueue) {
+ // We had a glare on the hangup. Forget all this business,
+ //return and destroy p.
ast_mutex_unlock(&p->lock);
ast_mutex_destroy(&p->lock);
free(p);
return -1;
- }
+ } */
if (!other) {
- p->glaredetect = 0;
+// p->glaredetect = 0;
return 0;
}
if (ast_mutex_trylock(&other->lock)) {
@@ -201,7 +206,7 @@
}
ast_queue_frame(other, f);
ast_mutex_unlock(&other->lock);
- p->glaredetect = 0;
+// p->glaredetect = 0;
return 0;
}
@@ -212,9 +217,9 @@
int res = -1;
ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
+// isoutbound = IS_OUTBOUND(ast, p);
if (isoutbound) {
- /* Pass along answer since somebody answered us */
+ // Pass along answer since somebody answered us
struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
res = xmpp_queue_frame(p, isoutbound, &answer, ast);
} else
@@ -223,44 +228,192 @@
return res;
}
+static int xmpp_create_candidates(struct axi_client *client,ikspak *pak)
+{
+ if(!client->candidates) { /*send standard candidates*/
+ iks *iq1, *iq2, *jingle1, *jingle2, *candidate1, *candidate2;
+ iq1 = iks_new("iq");
+ iq2 = iks_new("iq");
+ jingle1 = iks_new(GOOGLE_NODE);
+ jingle2 = iks_new(GOOGLE_NODE);
+ candidate1 = iks_new("candidate");
+ candidate2 = 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);
+ 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);
+ 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,"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,"xmlns", GOOGLE_NS);
+
+ iks_insert_attrib(candidate1, "type", "candidates");
+ 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, "type", "candidates");
+ 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_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);
+
+ }
+}
+
+static int xmpp_accept_call(struct axi_client *client, ikspak *pak)
+{
+ struct xmpp_pvt *tmp = xmpps;
+ iks *iq, *jingle;
+ while(tmp) {
+ if(!strcasecmp(tmp->sid,iks_find_attrib(pak->query,GOOGLE_SID))) {
+ iq = iks_new("iq");
+ jingle = iks_new(GOOGLE_NODE);
+ iks_insert_attrib(iq,"type","set");
+ iks_insert_attrib(iq,"from",client->jid->full);
+ iks_insert_attrib(iq,"to",iks_find_attrib(pak->x,"from"));
+ iks_insert_attrib(iq,"id",client->mid);
+ axi_increment_mid(client->mid);
+
+ iks_insert_attrib(jingle, "xmlns", GOOGLE_NS);
+ iks_insert_attrib(jingle, "action", JINGLE_ACCEPT);
+ iks_insert_attrib(jingle, "initiator", iks_find_attrib(pak->x,"from"));
+ iks_insert_attrib(jingle, GOOGLE_SID, tmp->sid);
+ iks_insert_node(iq,jingle);
+ iks_send(client->p,iq);
+ iks_delete(jingle);
+ iks_delete(iq);
+ }
+ tmp=tmp->next;
+ }
+ return 1;
+}
+static int xmpp_answer2(struct axi_client *client,ikspak *pak)
+{
+ struct xmpp_pvt *p ,*tmp = xmpps;
+ iks *accept;
+ char *data = "1234 at local";
+ while(tmp) {
+ if(iks_find_with_attrib(pak->x,GOOGLE_NODE,GOOGLE_SID,tmp->sid))
+ {
+ return -1;
+ }
+ tmp=tmp->next;
+ }
+ p = xmpp_alloc(data, 1);
+ 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->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,"id",client->mid);
+ iks_send(client->p,accept);
+ iks_delete(accept);
+ xmpp_create_candidates(client,pak);
+ return 1;
+}
+
+static int xmpp_add_candidate(struct axi_client *client,ikspak *pak)
+{
+ struct xmpp_pvt *p =NULL,*tmp = xmpps;
+ struct axi_candidate *newcandidate = NULL, *tmpcan = NULL;
+ iks *candidate_node = NULL;
+ iks *receipt = NULL;
+ newcandidate = (struct axi_candidate *)malloc(sizeof(struct axi_candidate));
+ memset(newcandidate,0,sizeof(struct axi_candidate));
+ 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));
+ newcandidate->preference = atof(iks_find_attrib(candidate_node, "preference"));
+ if(!strcasecmp(iks_find_attrib(candidate_node, "protocol"),"udp"))
+ newcandidate->protocol = AXI_PROTOCOL_UDP;
+ if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"stun"))
+ newcandidate->type = AXI_CONNECT_STUN;
+ if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"stun"))
+ newcandidate->type = AXI_CONNECT_LOCAL;
+ newcandidate->network = atoi(iks_find_attrib(candidate_node, "network"));
+ newcandidate->generation = atoi(iks_find_attrib(candidate_node, "generation"));
+ newcandidate->next = NULL;
+ while(tmp) {
+ if(iks_find_with_attrib(pak->x,GOOGLE_NODE,GOOGLE_SID,tmp->sid)) {
+ p = tmp;
+ break;
+ }
+ tmp=tmp->next;
+ }
+
+ if(!p) {
+ return -1;
+ } else {
+ tmpcan = p->candidates;
+ if(tmpcan) {
+ while(tmpcan->next) {
+ if(tmpcan->next)
+ tmpcan->next;
+ }
+ tmpcan->next = newcandidate;
+ } else
+ p->candidates = newcandidate;
+
+ 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,"id",iks_find_attrib(pak->x,"id"));
+ iks_send(client->p,receipt);
+ iks_delete(receipt);
+ return 1;
+ }
+ return 0;
+}
+
static void check_bridge(struct xmpp_pvt *p, int isoutbound)
{
- if (p->alreadymasqed || p->nooptimization)
- return;
- if (!p->chan || !p->owner)
- return;
- if (isoutbound&& p->chan->_bridge /* Not ast_bridged_channel! Only go one step! */ && !p->owner->readq) {
- /* Masquerade bridged channel into owner */
- /* Lock everything we need, one by one, and give up if
- we can't get everything. Remember, we'll get another
- chance in just a little bit */
- if (!ast_mutex_trylock(&(p->chan->_bridge)->lock)) {
- if (!p->chan->_bridge->_softhangup) {
- if (!ast_mutex_trylock(&p->owner->lock)) {
- if (!p->owner->_softhangup) {
- ast_channel_masquerade(p->owner, p->chan->_bridge);
- p->alreadymasqed = 1;
- }
- ast_mutex_unlock(&p->owner->lock);
- }
- ast_mutex_unlock(&(p->chan->_bridge)->lock);
- }
- }
- } else if (!isoutbound && p->owner && p->owner->_bridge && p->chan && !p->chan->readq) {
- /* Masquerade bridged channel into chan */
- if (!ast_mutex_trylock(&(p->owner->_bridge)->lock)) {
- if (!p->owner->_bridge->_softhangup) {
- if (!ast_mutex_trylock(&p->chan->lock)) {
- if (!p->chan->_softhangup) {
- ast_channel_masquerade(p->chan, p->owner->_bridge);
- p->alreadymasqed = 1;
- }
- ast_mutex_unlock(&p->chan->lock);
- }
- }
- ast_mutex_unlock(&(p->owner->_bridge)->lock);
- }
- }
}
static struct ast_frame *xmpp_read(struct ast_channel *ast)
@@ -278,15 +431,15 @@
/* Just queue for delivery to the other side */
ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
+// isoutbound = IS_OUTBOUND(ast, p);
if (f && (f->frametype == AST_FRAME_VOICE))
check_bridge(p, isoutbound);
- if (!p->alreadymasqed)
- res = xmpp_queue_frame(p, isoutbound, f, ast);
- else {
- ast_log(LOG_DEBUG, "Not posting to queue since already masked on '%s'\n", ast->name);
- res = 0;
- }
+// if (!p->alreadymasqed)
+// res = xmpp_queue_frame(p, isoutbound, f, ast);
+// else {
+// ast_log(LOG_DEBUG, "Not posting to queue since already masked on '%s'\n", ast->name);
+// res = 0;
+// }
ast_mutex_unlock(&p->lock);
return res;
}
@@ -296,15 +449,12 @@
struct xmpp_pvt *p = newchan->tech_pvt;
ast_mutex_lock(&p->lock);
- if ((p->owner != oldchan) && (p->chan != oldchan)) {
- ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
+ if ((p->owner != oldchan) ) {
ast_mutex_unlock(&p->lock);
return -1;
}
if (p->owner == oldchan)
p->owner = newchan;
- else
- p->chan = newchan;
ast_mutex_unlock(&p->lock);
return 0;
}
@@ -318,7 +468,7 @@
/* Queue up a frame representing the indication as a control frame */
ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
+// isoutbound = IS_OUTBOUND(ast, p);
f.subclass = condition;
res = xmpp_queue_frame(p, isoutbound, &f, ast);
ast_mutex_unlock(&p->lock);
@@ -333,7 +483,7 @@
int isoutbound;
ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
+// isoutbound = IS_OUTBOUND(ast, p);
f.subclass = digit;
res = xmpp_queue_frame(p, isoutbound, &f, ast);
ast_mutex_unlock(&p->lock);
@@ -348,7 +498,7 @@
int isoutbound;
ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
+// isoutbound = IS_OUTBOUND(ast, p);
f.subclass = subclass;
f.data = (char *)data;
f.datalen = datalen;
@@ -368,14 +518,14 @@
ast_mutex_lock(&p->lock);
- p->chan->cid.cid_num = ast_strdup(p->owner->cid.cid_num);
- p->chan->cid.cid_name = ast_strdup(p->owner->cid.cid_name);
- p->chan->cid.cid_rdnis = ast_strdup(p->owner->cid.cid_rdnis);
- p->chan->cid.cid_ani = ast_strdup(p->owner->cid.cid_ani);
-
- strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1);
- strncpy(p->chan->accountcode, p->owner->accountcode, sizeof(p->chan->accountcode) - 1);
- p->chan->cdrflags = p->owner->cdrflags;
+// p->chan->cid.cid_num = ast_strdup(p->owner->cid.cid_num);
+// p->chan->cid.cid_name = ast_strdup(p->owner->cid.cid_name);
+// p->chan->cid.cid_rdnis = ast_strdup(p->owner->cid.cid_rdnis);
+// p->chan->cid.cid_ani = ast_strdup(p->owner->cid.cid_ani);
+//
+// strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1);
+// strncpy(p->chan->accountcode, p->owner->accountcode, sizeof(p->chan->accountcode) - 1);
+// p->chan->cdrflags = p->owner->cdrflags;
/* copy the channel variables from the incoming channel to the outgoing channel */
/* Note that due to certain assumptions, they MUST be in the same order */
@@ -385,14 +535,14 @@
if ((new = ast_calloc(1, len))) {
memcpy(new, varptr, len);
new->value = &(new->name[0]) + namelen + 1;
- AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
- }
- }
-
- p->launchedpbx = 1;
+ // AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
+ }
+ }
+
+// p->launchedpbx = 1;
/* Start switch on sub channel */
- res = ast_pbx_start(p->chan);
+// res = ast_pbx_start(p->chan);
ast_mutex_unlock(&p->lock);
return res;
}
@@ -427,20 +577,20 @@
{
struct xmpp_pvt *p = ast->tech_pvt;
int isoutbound;
- struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
+// struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
struct xmpp_pvt *cur, *prev=NULL;
struct ast_channel *ochan = NULL;
- int glaredetect;
+// int glaredetect;
const char *status;
ast_mutex_lock(&p->lock);
- isoutbound = IS_OUTBOUND(ast, p);
+// isoutbound = IS_OUTBOUND(ast, p);
if (isoutbound) {
- status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
+// status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
if(status)
pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status);
- p->chan = NULL;
- p->launchedpbx = 0;
+// p->chan = NULL;
+// p->launchedpbx = 0;
} else
p->owner = NULL;
ast->tech_pvt = NULL;
@@ -449,13 +599,13 @@
usecnt--;
ast_mutex_unlock(&usecnt_lock);
- if (!p->owner && !p->chan) {
+ if (!p->owner ) {
/* Okay, done with the private part now, too. */
- glaredetect = p->glaredetect;
+// glaredetect = p->glaredetect;
/* If we have a queue holding, don't actually destroy p yet, but
let xmpp_queue do it. */
- if (p->glaredetect)
- p->cancelqueue = 1;
+// if (p->glaredetect)
+// p->cancelqueue = 1;
ast_mutex_unlock(&p->lock);
/* Remove from list */
ast_mutex_lock(&xmpplock);
@@ -476,17 +626,17 @@
ast_mutex_lock(&p->lock);
ast_mutex_unlock(&p->lock);
/* And destroy */
- if (!glaredetect) {
+/* if (!glaredetect) {
ast_mutex_destroy(&p->lock);
free(p);
- }
+ }*/
return 0;
}
- if (p->chan && !p->launchedpbx)
- /* Need to actually hangup since there is no PBX */
- ochan = p->chan;
- else
- xmpp_queue_frame(p, isoutbound, &f, NULL);
+// if (p->chan )
+// /* Need to actually hangup since there is no PBX */
+// ochan = p->chan;
+// else
+// xmpp_queue_frame(p, isoutbound, &f, NULL);
ast_mutex_unlock(&p->lock);
if (ochan)
ast_hangup(ochan);
@@ -500,91 +650,29 @@
char *c;
char *opts;
- if (!(tmp = ast_calloc(1, sizeof(*tmp))))
+ if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
return NULL;
+ }
ast_mutex_init(&tmp->lock);
- strncpy(tmp->exten, data, sizeof(tmp->exten) - 1);
- opts = strchr(tmp->exten, '/');
- if (opts) {
- *opts='\0';
- opts++;
- if (strchr(opts, 'n'))
- tmp->nooptimization = 1;
- }
- c = strchr(tmp->exten, '@');
- if (c) {
- *c = '\0';
- c++;
- strncpy(tmp->context, c, sizeof(tmp->context) - 1);
- } else
- strncpy(tmp->context, "default", sizeof(tmp->context) - 1);
- tmp->reqformat = format;
- if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
- ast_log(LOG_NOTICE, "No such extension/context %s@%s creating xmpp channel\n", tmp->exten, tmp->context);
- ast_mutex_destroy(&tmp->lock);
- free(tmp);
- tmp = NULL;
- } else {
- /* Add to list */
- ast_mutex_lock(&xmpplock);
- tmp->next = xmpps;
- xmpps = tmp;
- ast_mutex_unlock(&xmpplock);
- }
-
+// strncpy(tmp->exten, data, sizeof(tmp->exten) - 1);
+ ast_mutex_lock(&xmpplock);
+ tmp->next = xmpps;
+ xmpps = tmp;
+ ast_mutex_unlock(&xmpplock);
return tmp;
}
/*! \brief Start new xmpp channel */
static struct ast_channel *xmpp_new(struct xmpp_pvt *p, int state)
{
- struct ast_channel *tmp, *tmp2;
- int randnum = rand() & 0xffff;
+ struct ast_channel *tmp;
tmp = ast_channel_alloc(1);
- tmp2 = ast_channel_alloc(1);
- if (!tmp || !tmp2) {
- if (tmp)
- ast_channel_free(tmp);
- if (tmp2)
- ast_channel_free(tmp2);
- ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
- return NULL;
- }
-
- tmp2->tech = tmp->tech = &xmpp_tech;
- tmp->nativeformats = p->reqformat;
- tmp2->nativeformats = p->reqformat;
- snprintf(tmp->name, sizeof(tmp->name), "Local/%s@%s-%04x,1", p->exten, p->context, randnum);
- snprintf(tmp2->name, sizeof(tmp2->name), "Local/%s@%s-%04x,2", p->exten, p->context, randnum);
- tmp->type = type;
- tmp2->type = type;
- ast_setstate(tmp, state);
- ast_setstate(tmp2, AST_STATE_RING);
- tmp->writeformat = p->reqformat;
- tmp2->writeformat = p->reqformat;
- tmp->rawwriteformat = p->reqformat;
- tmp2->rawwriteformat = p->reqformat;
- tmp->readformat = p->reqformat;
- tmp2->readformat = p->reqformat;
- tmp->rawreadformat = p->reqformat;
- tmp2->rawreadformat = p->reqformat;
- tmp->tech_pvt = p;
- tmp2->tech_pvt = p;
- p->owner = tmp;
- p->chan = tmp2;
ast_mutex_lock(&usecnt_lock);
- usecnt++;
usecnt++;
ast_mutex_unlock(&usecnt_lock);
ast_update_use_count();
- ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
- ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context));
- ast_copy_string(tmp2->exten, p->exten, sizeof(tmp->exten));
- tmp->priority = 1;
- tmp2->priority = 1;
-
return tmp;
}
@@ -605,14 +693,19 @@
static int xmpp_show(int fd, int argc, char **argv)
{
struct xmpp_pvt *p;
-
+ struct axi_candidate *tmp;
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_mutex_lock(&xmpplock);
p = xmpps;
while(p) {
ast_mutex_lock(&p->lock);
- ast_cli(fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
+ ast_cli(fd, "SID = %s\n",p->sid );
+ tmp = p->candidates;
+ while(tmp) {
+ ast_verbose("port %d\n",tmp->port);
+ tmp=tmp->next;
+ }
ast_mutex_unlock(&p->lock);
p = p->next;
}
@@ -630,9 +723,31 @@
{ "xmpp", "show", "channels", NULL }, xmpp_show,
"Show status of xmpp channels", show_xmpps_usage, NULL };
+
+static int xmpp_parser(struct axi_client *client, iks *node)
+{
+ ikspak *pak;
+ pak = iks_packet(node);
+ if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",JINGLE_INITIATE))
+ xmpp_answer2(client, pak);
+ if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",GOOGLE_NEGOTIATE)) {
+ xmpp_add_candidate(client,pak);
+ if(flipflop) {
+ flipflop--;
+ xmpp_accept_call(client,pak);
+ }
+ else
+ flipflop++;
+ }
+ if(node)
+ iks_delete(node);
+
+ return 1;
+}
/*! \brief Load module into PBX, register channel */
int load_module()
{
+ ast_axi_jingle_register(xmpp_parser);
/* Make sure we can register our channel type */
if (ast_channel_register(&xmpp_tech)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
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=9208&r1=9207&r2=9208&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h Tue Feb 7 19:35:51 2006
@@ -45,25 +45,26 @@
};
enum axi_protocol {
- AXI_PROTOCOL_UDP=0,
+ AXI_PROTOCOL_UDP=1,
};
enum axi_connect_type {
- AXI_CONNECT_STUN=0,
- AXI_CONNECT_LOCAL=1,
+ AXI_CONNECT_STUN=1,
+ AXI_CONNECT_LOCAL=2,
};
struct axi_candidate {
char name[100];
enum axi_protocol protocol;
- double prefrence;
+ double preference;
char username [100];
char password [100];
enum axi_connect_type type;
int network;
int generation;
- char ip[13];
+ char ip[16];
int port;
+ int receipt;
struct axi_candidate *next;
};
@@ -109,14 +110,18 @@
int pruneregister;
int timeout;
int authorized;
+ char externip[16];
+ char localip[16];
enum axi_type component;
struct axi_buddy_container buddies;
+ struct axi_candidate *candidates;
pthread_t thread;
};
struct axi_client_container{
ASTOBJ_CONTAINER_COMPONENTS(struct axi_client);
};
+
struct axi_action {
/*! Name of the action */
char action[100];
@@ -143,10 +148,32 @@
\param description Help text, several lines
*/
int ast_axi_register2(const char *action, int (*func)(struct axi_client *client,char *user, char *m,int type), const char *synopsis, const char *description);
+int ast_axi_jingle_register(int (*func)(struct axi_client *client, iks *node));
int ast_axi_send(struct axi_client *client, char *address, char *message);
int ast_axi_disconnect(struct axi_client *client);
int ast_axi_check_roster(void);
int ast_axi_create_chat(struct axi_client *client,char *room, char *server, char *topic);
int ast_axi_invite_chat(struct axi_client *client, char *user, char *room, char *message);
int ast_axi_join_chat(struct axi_client *client,char *room);
+
+/* Jingle Constants */
+
+#define JINGLE_NODE "jingle"
+#define GOOGLE_NODE "session"
+
+#define JINGLE_NS "http://jabber.org/protocol/jingle"
+#define GOOGLE_NS "http://www.google.com/session"
+
+#define JINGLE_SID "sid"
+#define GOOGLE_SID "id"
+
+#define JINGLE_FROM "from"
+
+#define JINGLE_INITIATE "initiate"
+
+#define JINGLE_ACCEPT "accept"
+
+#define JINGLE_NEGOTIATE "negotiate"
+#define GOOGLE_NEGOTIATE "candidates"
+
#endif
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=9208&r1=9207&r2=9208&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_xmpp.c Tue Feb 7 19:35:51 2006
@@ -61,7 +61,7 @@
static void axi_log_hook(void *udata, const char *data, size_t size,int is_incoming);
static int axi_execute(struct axi_client *client,char *action, char *user, char *message, int type);
static int axi_act_hook(void *udata, int type, iks * node);
-static void axi_handle_iq(struct axi_client *client, ikspak *pak);
+static void axi_handle_iq(struct axi_client *client, iks *node);
static void axi_handle_presence(struct axi_client *client, ikspak *pak);
static void axi_handle_subscribe(struct axi_client *client, ikspak *pak);
static int axi_recv(struct axi_client *client,int timeout);
@@ -86,7 +86,7 @@
static void axi_pruneregister(struct axi_client *client);
static int axi_register_transport(void *udata,ikspak *pak);
static int axi_register_transport2(void *udata,ikspak *pak);
-static void axi_increment_mid(char *mid);
+void axi_increment_mid(char *mid);
static int axi_filter_roster(void *udata,ikspak *pak);
static void axi_handle_discovery(struct axi_client *client, ikspak *pak);
@@ -119,6 +119,7 @@
struct axi_client_container clients;
+int (*jingle_callback)(struct axi_client *client, iks *node) = NULL;
/*!
* \brief Deletes the axi_client data structure.
@@ -283,7 +284,6 @@
static int axi_act_hook(void *udata, int type, iks * node)
{
- ast_verbose("Stuck on you\n");
struct axi_client *client = ASTOBJ_REF((struct axi_client *) udata);
ikspak *pak;
pak=iks_packet(node);
@@ -341,18 +341,22 @@
iks *x;
x = iks_new ("auth");
iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
- int len = iks_strlen (client->jid->user) + iks_strlen (client->password) + 2;
- char *s = iks_malloc (80+len);
+ int len = strlen (client->jid->user) + strlen (client->password) + 2;
+ char *s = ast_malloc (80+len);
char *base64;
iks_insert_attrib (x, "mechanism", "PLAIN");
sprintf (s, "%c%s%c%s", 0, client->jid->user, 0, client->password);
- ast_base64encode(base64,s,len,((len/3+1)*4 +1));
+ ast_base64encode(base64, s,len,((len/3+1)*4 +1));
iks_insert_cdata (x, base64, 0);
- iks_free (base64);
- iks_free (s);
iks_send (client->p, x);
- iks_delete (x);
+ if(x)
+ iks_delete (x);
+ if(base64)
+ free (base64);
+ if(s)
+ free (s);
+
}
}
}
@@ -382,7 +386,7 @@
break;
case IKS_PAK_IQ:
ast_verbose(VERBOSE_PREFIX_3 "XMPP: I Dont have an IQ!!!\n");
- axi_handle_iq(client,pak);
+ axi_handle_iq(client,node);
break;
default:
ast_verbose(VERBOSE_PREFIX_3 "XMPP: I Dont know %i\n",pak->type );
@@ -417,33 +421,19 @@
*/
}
-static void axi_handle_jingle(struct axi_client *client, ikspak *pak)
-{
- if(iks_find_with_attrib(pak->x,"session","type","initiate")) {
- iks *accept;
- accept = iks_new("iq");
- iks_insert_attrib(accept,"type","result");
- iks_insert_attrib(accept,"from",client->jid->full);
- iks_insert_attrib(accept,"to",iks_find_attrib(pak->x,"from"));
- iks_insert_attrib(accept,"id",client->mid);
- iks_send(client->p,accept);
- iks_delete(accept);
- }
-
-}
-
-static void axi_handle_iq(struct axi_client *client, ikspak *pak)
-{
- if(pak->subtype==IKS_TYPE_GET) {
- ast_verbose("this is it %s\n",iks_string(client->stack,pak->query));
- if(iks_find_with_attrib(pak->x,"query","xmlns","http://jabber.org/protocol/disco#info")) {
- axi_handle_discovery(client,pak);
- }
- }
- if(pak->subtype==IKS_TYPE_SET) {
- if(iks_find_with_attrib(pak->x,"session","xmlns","http://www.google.com/session"))
- axi_handle_jingle(client,pak);
- }
+static void axi_handle_iq(struct axi_client *client, iks *node)
+{
+ if(iks_packet(node)->subtype==IKS_TYPE_GET) {
+ ast_verbose("this is it %s\n",iks_string(client->stack,iks_packet(node)->query));
+ if(iks_find_with_attrib(iks_packet(node)->x,"query","xmlns","http://jabber.org/protocol/disco#info")) {
+ axi_handle_discovery(client,iks_packet(node));
+ }
+ }
+ if(iks_packet(node)->subtype==IKS_TYPE_SET) {
+ if(iks_find_with_attrib(iks_packet(node)->x,GOOGLE_NODE,"xmlns",GOOGLE_NS))
+ jingle_callback(client,iks_copy(node));
+ // axi_handle_jingle(client,pak);
+ }
}
static void axi_handle_discovery(struct axi_client *client, ikspak *pak)
@@ -534,7 +524,7 @@
message_packet=iks_make_msg(IKS_TYPE_CHAT, address, message);
iks_insert_attrib(message_packet,"from",client->jid->full);
res =iks_send(client->p,message_packet);
- iks_delete(message_packet);
+ iks_delete(message_packet);
} else
ast_verbose("We arent connected dont send\n");
return 1;
@@ -635,9 +625,8 @@
return 0;
}
-static void axi_increment_mid(char *mid)
-{
-
+void axi_increment_mid(char *mid)
+{
int i=0;
for(i=4;i >= 0;i--)
{
@@ -689,8 +678,8 @@
struct axi_client *client;
struct axi_buddy *buddy=NULL;
iks *regquery, *reguser, *regpass, *regiq;
- client = (struct axi_client *)malloc(sizeof(struct axi_client));
- memset(client,0,sizeof(struct axi_client));
+ client = (struct axi_client *)malloc(sizeof(struct axi_client));
+ memset(client,0,sizeof(struct axi_client));
client =ASTOBJ_REF((struct axi_client *) udata);
ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
ASTOBJ_RDLOCK(iterator);
@@ -979,9 +968,9 @@
iks_filter_add_rule (client->f, axi_component_connect, client, IKS_RULE_FROM, client->server, IKS_RULE_DONE);
client->jid = iks_id_new(client->stack, client->user);
client->p = iks_stream_new("jabber:component:accept", client, axi_act_hook);
- iks_set_log_hook(client->p, axi_log_hook);
- connected =iks_connect_via(client->p, client->server, client->port, client->user);
- return 1;
+iks_set_log_hook(client->p, axi_log_hook);
+connected =iks_connect_via(client->p, client->server, client->port, client->user);
+return 1;
}
int ast_axi_disconnect(struct axi_client *client)
@@ -1203,6 +1192,19 @@
return 0;
}
+int ast_axi_jingle_register(int (*func)(struct axi_client *client, iks *node))
+{
+ if(func) {
+ ast_verbose("XXXXXXXXXXXXXXXXXX REGISTERED\n");
+ jingle_callback = func;
+ }
+ else {
+ ast_verbose("XXXXXXXXXXXXXXXXXX UNREGISTERED");
+ jingle_callback = NULL;
+ }
+ return 1;
+}
+
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;
@@ -1220,7 +1222,9 @@
client->timeout=20;
client->authorized=0;
client->usesasl=0;
-
+ ast_copy_string(client->externip, "216.207.245.1", sizeof(client->externip));
+ ast_copy_string(client->localip, "10.16.3.55", sizeof(client->localip));
+
client->state=AXI_DISCONNECTED;
if(!strcasecmp(utype,"component"))
client->component=AXI_COMPONENT;
More information about the asterisk-commits
mailing list