[asterisk-commits] branch mogorman/asterisk-xmpp r24161 - in /team/mogorman/asterisk-xmpp: chann...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon May 1 22:19:43 MST 2006


Author: markster
Date: Tue May  2 00:19:42 2006
New Revision: 24161

URL: http://svn.digium.com/view/asterisk?rev=24161&view=rev
Log:
Make outbound calling work

Modified:
    team/mogorman/asterisk-xmpp/channels/chan_jingle.c
    team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
    team/mogorman/asterisk-xmpp/include/asterisk/jingle.h

Modified: team/mogorman/asterisk-xmpp/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/chan_jingle.c?rev=24161&r1=24160&r2=24161&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_jingle.c Tue May  2 00:19:42 2006
@@ -74,6 +74,80 @@
 
 #define JINGLE_CONFIG "jingle.conf"
 
+enum jingle_protocol {
+	AJI_PROTOCOL_UDP=1,
+	AJI_PROTOCOL_SSLTCP=2,
+};
+
+enum jingle_connect_type {
+	AJI_CONNECT_STUN=1,
+	AJI_CONNECT_LOCAL=2,
+	AJI_CONNECT_RELAY=3,
+};
+
+struct jingle_pvt {
+	ast_mutex_t lock;			/* Channel private lock */
+	time_t laststun;
+	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 */
+	int alreadygone;
+	int capability;
+	struct ast_codec_pref prefs;
+	struct jingle_candidate *theircandidates;
+	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 */
+	struct ast_rtp *vrtp;
+	int jointcapability;			/*!< Supported capability at both ends (codecs ) */
+	int peercapability;
+	struct jingle_pvt *next;		/* Next entity */
+};
+
+struct jingle_candidate {
+	char name[100];
+	enum jingle_protocol protocol;
+	double preference;
+	char username [100];
+	char password [100];
+	enum jingle_connect_type type;
+	int network;
+	int generation;
+	char ip[16];
+	int port;
+	int receipt;
+	struct jingle_candidate *next;
+};
+
+struct jingle {
+	ASTOBJ_COMPONENTS(struct jingle);
+	struct aji_client *connection;
+	struct aji_buddy *buddy;
+	struct jingle_pvt *p;
+	struct ast_codec_pref prefs;
+	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 */
+	int allowguest;
+	char language[MAX_LANGUAGE];	/*!<  Default language for prompts */
+	char musicclass[MAX_MUSICCLASS];/*!<  Music on Hold class */
+};
+
+struct jingle_container {
+	ASTOBJ_CONTAINER_COMPONENTS(struct jingle);
+};
+
 static const char desc[] = "Jingle Channel";
 static const char type[] = "Jingle";
 static const char tdesc[] = "Jingle Channel Driver";
@@ -146,12 +220,14 @@
 struct jingle_container jingles;
 
 
-struct jingle *find_jingle(char *name, char *connection)
+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,{
 			ASTOBJ_WRLOCK(iterator);
@@ -290,6 +366,17 @@
 	return 1;
 }
 
+static int jingle_ringing_ack(void *data, ikspak *pak)
+{
+	struct jingle_pvt *p = data;
+	if (p->ringrule)
+		iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
+	p->ringrule = NULL;
+	if (p->owner)
+		ast_queue_control(p->owner, AST_CONTROL_RINGING);
+	return IKS_FILTER_EAT;
+}
+
 static int jingle_answer(struct ast_channel *ast)
 {
 	struct jingle_pvt *p = ast->tech_pvt;
@@ -385,14 +472,38 @@
 	return res;
 }
 
-static int jingle_hangup_farend(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)) {
+			break;
+		}
+		tmp=tmp->next;
+	}
+	
+	if (tmp) {
+		if (tmp->owner)
+			ast_queue_control(tmp->owner, AST_CONTROL_ANSWER);
+	} else
+		ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
+	jingle_response(client, pak, NULL);
+	return 1;
+}
+
+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)) {
 			break;
 		}
@@ -544,6 +655,7 @@
 	struct aji_buddy *buddy;
 	char idroster[200];
 
+	ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name);
 	if(!sid && !strchr(from,'/')) { /*I started call! */
 		ast_verbose("shouldnt be called on inbound!\n");
 		if(!strcasecmp(client->name, "guest")) {
@@ -747,6 +859,8 @@
 		prev = cur;
 		cur = cur->next;
 	}
+	if (p->ringrule)
+		iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
 	if (p->owner)
 		ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
 	if (p->rtp)
@@ -851,15 +965,12 @@
 	struct jingle_pvt *p =NULL,*tmp = NULL;
 	struct aji_client *c = client->connection;
 	struct jingle_candidate *newcandidate = NULL;
-	struct sockaddr_in sin;
-	struct hostent *hp;
-	struct ast_hostent ahp;
-	char iabuf[INET_ADDRSTRLEN];
 	iks *candidate_node = NULL;
 	iks *receipt = NULL;
 	newcandidate = (struct jingle_candidate *)ast_calloc(1, sizeof(struct jingle_candidate));
 	if(!newcandidate)
 		return 0;
+
 	memset(newcandidate,0,sizeof(struct jingle_candidate));
 	candidate_node = iks_find(pak->query,"candidate");
 	ast_copy_string(newcandidate->name,iks_find_attrib(candidate_node, "name"),sizeof(newcandidate->name));
@@ -1035,11 +1146,11 @@
 {
 	struct jingle *jingle = NULL;
 	struct aji_client *client = NULL;
+	iks *iq, *desc, *session;
+	iks *payload_eg711u , *payload_pcmu;
+
 	jingle = p->parent;
 	client = jingle->connection;
-	iks *iq, *desc, *session;
-	iks *payload_eg711u , *payload_pcmu;
-	ast_verbose("I am here right?\n");
 	iq = iks_new("iq");
 	desc = iks_new("description");
 	session = iks_new("session");
@@ -1106,12 +1217,17 @@
 		 return -1;
 	 }
 	 
-	 	ast_setstate(ast, AST_STATE_RING);
-		p->jointcapability = p->capability;
-		jingle_transmit_invite(p);
-		jingle_create_candidates(p->parent, p,p->sid, p->from);
-
-	 return 0;
+	ast_setstate(ast, AST_STATE_RING);
+	p->jointcapability = p->capability;
+	if (!p->ringrule) {
+		ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
+		p->ringrule = iks_filter_add_rule(p->parent->connection->f, jingle_ringing_ack, p, IKS_RULE_ID, p->ring, IKS_RULE_DONE);
+	} else {
+		ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
+	}
+	jingle_transmit_invite(p);
+	jingle_create_candidates(p->parent, p,p->sid, p->from);
+	return 0;
 }
 
 /*! \brief Hangup a call through the jingle proxy channel */
@@ -1233,13 +1349,15 @@
 		jingle_newcall(client, pak);
 	} else if (iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",GOOGLE_NEGOTIATE)) {
 		ast_log(LOG_DEBUG, "About to add candidate!\n");
-		jingle_add_candidate(client,pak);
+		jingle_add_candidate(client, pak);
 		ast_log(LOG_DEBUG, "Candidate Added!\n");
+	} else if (iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",GOOGLE_ACCEPT)) {
+		jingle_is_answered(client, pak);
 	} else if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type","terminate")) {
 		ast_verbose("not this\n");
 		jingle_hangup_farend(client, pak);
 	}
-	return 1;
+	return IKS_FILTER_EAT;
 }
 
 static struct jingle_candidate *jingle_create_candidate(char *args)
@@ -1323,7 +1441,7 @@
 		else if (!strcasecmp(var->name, "connection")) {
 			if((client = ast_aji_get_client(var->value))) {
 				member->connection=client;
-				iks_filter_add_rule(client->f,jingle_parser, member, IKS_RULE_TYPE, IKS_RULE_FROM_PARTIAL, member->user, IKS_PAK_IQ, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
+				iks_filter_add_rule(client->f,jingle_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_FROM_PARTIAL, member->user, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
 			} else {
 				ast_log(LOG_ERROR, "connection referenced not found!\n");			return 0;
 			}

Modified: team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/jabber.h?rev=24161&r1=24160&r2=24161&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jabber.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jabber.h Tue May  2 00:19:42 2006
@@ -132,22 +132,4 @@
 struct aji_client *ast_aji_get_client(char *name);
 struct aji_client_container *ast_aji_get_clients(void);
 
-/* 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_INITIATE "initiate"
-
-#define JINGLE_ACCEPT "accept"
-
-#define JINGLE_NEGOTIATE "negotiate"
-#define GOOGLE_NEGOTIATE "candidates"
-
 #endif

Modified: team/mogorman/asterisk-xmpp/include/asterisk/jingle.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/jingle.h?rev=24161&r1=24160&r2=24161&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jingle.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jingle.h Tue May  2 00:19:42 2006
@@ -23,76 +23,23 @@
 #include "asterisk/astobj.h"
 
 
-enum jingle_protocol {
-	AJI_PROTOCOL_UDP=1,
-	AJI_PROTOCOL_SSLTCP=2,
-};
+/* Jingle Constants */
 
-enum jingle_connect_type {
-	AJI_CONNECT_STUN=1,
-	AJI_CONNECT_LOCAL=2,
-	AJI_CONNECT_RELAY=3,
-};
+#define JINGLE_NODE "jingle"
+#define GOOGLE_NODE "session"
 
-struct jingle_candidate {
-	char name[100];
-	enum jingle_protocol protocol;
-	double preference;
-	char username [100];
-	char password [100];
-	enum jingle_connect_type type;
-	int network;
-	int generation;
-	char ip[16];
-	int port;
-	int receipt;
-	struct jingle_candidate *next;
-};
+#define JINGLE_NS "http://jabber.org/protocol/jingle"
+#define GOOGLE_NS "http://www.google.com/session"
 
-struct jingle_pvt {
-	ast_mutex_t lock;			/* Channel private lock */
-	time_t laststun;
-	struct jingle *parent;		/* Parent client */
-	char sid[100];
-	char from[100];
-	int initiator;				/* If we're the initiator */
-	int alreadygone;
-	int capability;
-	struct ast_codec_pref prefs;
-	struct jingle_candidate *theircandidates;
-	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 */
-	struct ast_rtp *vrtp;
-	int jointcapability;			/*!< Supported capability at both ends (codecs ) */
-	int peercapability;
-	struct jingle_pvt *next;		/* Next entity */
-};
+#define JINGLE_SID "sid"
+#define GOOGLE_SID "id"
 
-struct jingle {
-	ASTOBJ_COMPONENTS(struct jingle);
-	struct aji_client *connection;
-	struct aji_buddy *buddy;
-	struct jingle_pvt *p;
-	struct ast_codec_pref prefs;
-	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 */
-	int allowguest;
-	char language[MAX_LANGUAGE];	/*!<  Default language for prompts */
-	char musicclass[MAX_MUSICCLASS];/*!<  Music on Hold class */
-};
+#define JINGLE_INITIATE "initiate"
 
-struct jingle_container {
-	ASTOBJ_CONTAINER_COMPONENTS(struct jingle);
-};
+#define JINGLE_ACCEPT "accept"
+#define GOOGLE_ACCEPT "accept"
+
+#define JINGLE_NEGOTIATE "negotiate"
+#define GOOGLE_NEGOTIATE "candidates"
 
 #endif



More information about the asterisk-commits mailing list