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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Apr 13 20:37:43 MST 2006


Author: markster
Date: Thu Apr 13 22:37:42 2006
New Revision: 19940

URL: http://svn.digium.com/view/asterisk?rev=19940&view=rev
Log:
Get hangup working inbound / outbound

Modified:
    team/mogorman/asterisk-xmpp/channels/chan_jingle.c
    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=19940&r1=19939&r2=19940&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_jingle.c Thu Apr 13 22:37:42 2006
@@ -350,8 +350,57 @@
 	return 1;
 }
 
+static int jingle_response(struct jingle *client, ikspak *pak, const char *reasonstr)
+{
+	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"));
+		if (reasonstr) {
+			error = iks_new("error");
+			if (error) {
+				iks_insert_attrib(error, "type", "cancel");
+				reason = iks_new(reasonstr);
+				if (reason)
+					iks_insert_node(error, reason);
+				iks_insert_node(response, error);
+			}
+		}
+		iks_send(client->connection->p, response);
+		if (reason)
+			iks_delete(reason);
+		if (error)
+			iks_delete(error);
+		iks_delete(response);
+		res = 0;
+	}
+	return res;
+}
+
 static int jingle_hangup_farend(struct jingle *client,ikspak *pak)
 {
+	struct jingle_pvt *tmp;
+
+	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;
+		}
+		tmp=tmp->next;
+	}
+	
+	if (tmp) {
+		tmp->alreadygone = 1;
+		ast_queue_hangup(tmp->owner);
+	} else
+		ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
+	jingle_response(client, pak, NULL);
 	ast_verbose("END CALL\n");
 	return 1;
 }
@@ -631,6 +680,7 @@
 		return NULL;
 	}
 	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");
 		free(tmp);
@@ -730,34 +780,30 @@
 	return tmp;
 }
 
-static int jingle_response(struct jingle *client, ikspak *pak, const char *reasonstr)
-{
-	iks *response, *error=NULL, *reason=NULL;
+static int jingle_action(struct jingle *client, struct jingle_pvt *p, const char *action)
+{
+	iks *request, *session=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"));
-		if (reasonstr) {
-			error = iks_new("error");
-			if (error) {
-				iks_insert_attrib(error, "type", "cancel");
-				reason = iks_new(reasonstr);
-				if (reason)
-					iks_insert_node(error, reason);
-				iks_insert_node(response, error);
-			}
-		}
-		iks_send(client->connection->p, response);
-		if (reason)
-			iks_delete(reason);
-		if (error)
-			iks_delete(error);
-		iks_delete(response);
-		res = 0;
+	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);
+		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, "xmlns", "http://www.google.com/session");
+			iks_insert_node(request, session);
+			iks_send(client->connection->p, request);
+			iks_delete(session);
+			res = 0;
+		}
+		iks_delete(request);
 	}
 	return res;
 }
@@ -791,7 +837,7 @@
 	return newcan;
 }
 
-static void jingle_free(struct jingle *client, struct jingle_pvt *p)
+static void jingle_free_pvt(struct jingle *client, struct jingle_pvt *p)
 {
 	struct jingle_pvt *cur, *prev = NULL;
 	cur = client->p;
@@ -873,7 +919,7 @@
 			break;
 		}
 	} else {
-		jingle_free(client, p);
+		jingle_free_pvt(client, p);
 	}
 	return 1;
 }
@@ -1167,7 +1213,6 @@
 	struct jingle_pvt *p = ast->tech_pvt;
 	struct jingle *peer = NULL;
 	struct jingle *client = NULL;
-	client = ast_aji_get_client("asterisk");
 	int isoutbound;
 	struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
 	struct jingle_pvt *cur, *prev=NULL;
@@ -1176,30 +1221,20 @@
 	const char *status;
 
 	ast_mutex_lock(&p->lock);
+	client = p->parent;
 	p->owner = NULL;
 	ast->tech_pvt = NULL;
 	if (!p->alreadygone) {
-		
+		jingle_action(client, p, "terminate");
 	}
 	ast_mutex_unlock(&p->lock);
+
+	jingle_free_pvt(client, p);
 	ast_mutex_lock(&usecnt_lock);
 	usecnt--;
 	ast_mutex_unlock(&usecnt_lock);
 	return 0;
 }
-
-#if 0
-/*! \brief Create a call structure */
-static struct jingle_pvt *jingle_alloc(char *data, int format)
-{
-	struct jingle_pvt *tmp;
-
-	if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
-		return NULL;
-	}
-	return tmp;
-}
-#endif
 
 /*! \brief Part of PBX interface */
 static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause)
@@ -1262,10 +1297,10 @@
 	struct jingle *client= ASTOBJ_REF((struct jingle *) udata);;
 	
 	ast_verbose("WOOHOO!!!\n");
-	if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",JINGLE_INITIATE)) {
+	if (iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",JINGLE_INITIATE)) {
 		/* New call */
 		jingle_newcall(client, pak);
-	} else if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",GOOGLE_NEGOTIATE)) {
+	} else if (iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",GOOGLE_NEGOTIATE)) {
 		jingle_add_candidate(client,pak);
 		if(flipflop == 2) {
 			flipflop = 0;
@@ -1275,8 +1310,7 @@
 			ast_verbose("COUNT IS %d\n",flipflop);
 			flipflop++;
 		}
-	}
-	else if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type","terminate")) {
+	} else if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type","terminate")) {
 		jingle_hangup_farend(client, pak);
 	}
 	

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=19940&r1=19939&r2=19940&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jingle.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jingle.h Thu Apr 13 22:37:42 2006
@@ -51,8 +51,11 @@
 
 struct jingle_pvt {
 	ast_mutex_t lock;			/* Channel private lock */
+	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;



More information about the asterisk-commits mailing list