[svn-commits] mogorman: branch mogorman/asterisk-jabber r41010 - /team/mogorman/asterisk-ja...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Aug 24 14:39:52 MST 2006


Author: mogorman
Date: Thu Aug 24 16:39:52 2006
New Revision: 41010

URL: http://svn.digium.com/view/asterisk?rev=41010&view=rev
Log:
woohoo new gtalk syntax.

Modified:
    team/mogorman/asterisk-jabber/channels/chan_gtalk.c

Modified: team/mogorman/asterisk-jabber/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-jabber/channels/chan_gtalk.c?rev=41010&r1=41009&r2=41010&view=diff
==============================================================================
--- team/mogorman/asterisk-jabber/channels/chan_gtalk.c (original)
+++ team/mogorman/asterisk-jabber/channels/chan_gtalk.c Thu Aug 24 16:39:52 2006
@@ -354,23 +354,21 @@
 	return 0;
 }
 
-static int gtalk_accept_call(struct gtalk *client, struct gtalk_pvt *p)
-{
-	struct gtalk_pvt *tmp = client->p;
-	iks *iq, *gtalk, *dcodecs, *payload_audio, *transport;
+static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, int initiator)
+{
+	struct gtalk *client = p->parent;
+	iks *iq, *gtalk, *dcodecs, *payload_telephone, *transport;
 	int x;
 	int pref_codec = 0;
 	int alreadysent = 0;
 
-	if (p->initiator)
-		return 1;
 
 	iq = iks_new("iq");
 	gtalk = iks_new("session");
 	dcodecs = iks_new("description");
 	transport = iks_new("transport");
-	payload_audio = iks_new("payload-type");
-	if (!(iq && gtalk && dcodecs && transport && payload_audio)){
+	payload_telephone = iks_new("payload-type");
+	if (!(iq && gtalk && dcodecs && transport && payload_telephone)){
 		if(iq)
 			iks_delete(iq);
 		if(gtalk)
@@ -379,8 +377,8 @@
 			iks_delete(dcodecs);
 		if(transport)
 			iks_delete(transport);
-		if(payload_audio)
-			iks_delete(payload_audio);
+		if(payload_telephone)
+			iks_delete(payload_telephone);
 
 		ast_log(LOG_ERROR, "Could not allocate iksemel nodes\n");
 		return 0;
@@ -399,35 +397,70 @@
 		alreadysent |= pref_codec;
 	}
 	
-	iks_insert_attrib(payload_audio, "id", "106");
-	iks_insert_attrib(payload_audio, "name", "audio/telephone-event");
-	iks_insert_attrib(payload_audio, "clockrate", "8000");
+	iks_insert_attrib(payload_telephone, "id", "106");
+	iks_insert_attrib(payload_telephone, "name", "telephone-event");
+	iks_insert_attrib(payload_telephone, "clockrate", "8000");
 	
 	iks_insert_attrib(transport,"xmlns","http://www.google.com/transport/p2p");
 	
 	iks_insert_attrib(iq, "type", "set");
-	iks_insert_attrib(iq, "to", (p->from) ? p->from : client->user);
-	iks_insert_attrib(iq, "from", client->connection->jid->full);
+	iks_insert_attrib(iq, "to", to);
+	iks_insert_attrib(iq, "from", from);
 	iks_insert_attrib(iq, "id", client->connection->mid);
 	ast_aji_increment_mid(client->connection->mid);
 
 	iks_insert_attrib(gtalk, "xmlns", "http://www.google.com/session");
-	iks_insert_attrib(gtalk, "type", "accept");
-	iks_insert_attrib(gtalk, "initiator",
-					  p->initiator ? client->connection->jid->full : p->from);
-	iks_insert_attrib(gtalk, "id", tmp->sid);
+	iks_insert_attrib(gtalk, "type",initiator ? "initiate": "accept");
+	iks_insert_attrib(gtalk, "initiator", initiator ? from : to);
+	iks_insert_attrib(gtalk, "id", sid);
 	iks_insert_node(iq, gtalk);
 	iks_insert_node(gtalk, dcodecs);
 	iks_insert_node(gtalk, transport);
-	iks_insert_node(dcodecs, payload_audio);
+	iks_insert_node(dcodecs, payload_telephone);
 
 	iks_send(client->connection->p, iq);
-	iks_delete(payload_audio);
+	iks_delete(payload_telephone);
 	iks_delete(transport);
 	iks_delete(dcodecs);
 	iks_delete(gtalk);
 	iks_delete(iq);
 	return 1;
+}
+
+static int gtalk_invite_response(struct gtalk_pvt *p, char *to , char *from, char *sid, int initiator)
+{
+	iks *iq, *session, *transport;
+	iq = iks_new("iq");
+	session = iks_new("session");
+	transport = iks_new("transport");
+	if(!(iq && session && transport)) {
+		if(iq)
+			iks_delete(iq);
+		if(session)
+			iks_delete(session);
+		if(transport)
+			iks_delete(transport);
+		ast_log(LOG_ERROR, " Unable to allocate IKS node\n");
+		return -1;
+	}
+	iks_insert_attrib(iq, "from", from);
+	iks_insert_attrib(iq, "to", to);
+	iks_insert_attrib(iq, "type", "set");
+	iks_insert_attrib(iq, "id",p->parent->connection->mid);
+	ast_aji_increment_mid(p->parent->connection->mid);
+	iks_insert_attrib(session, "type", "transport-accept");
+	iks_insert_attrib(session, "id", sid);
+	iks_insert_attrib(session, "initiator", initiator ? from : to);
+	iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
+	iks_insert_attrib(transport, "xmlns", "http://www.google.com/transport/p2p");
+	iks_insert_node(iq,session);
+	iks_insert_node(session,transport);
+	iks_send(p->parent->connection->p, iq);
+	iks_delete(transport);
+	iks_delete(session);
+	iks_delete(iq);
+	return 1;
+
 }
 
 static int gtalk_ringing_ack(void *data, ikspak *pak)
@@ -451,7 +484,7 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Answer!\n");
 	ast_mutex_lock(&p->lock);
-	gtalk_accept_call(client, p);
+	gtalk_invite(p, (p->from) ? p->from : client->user, client->connection->jid->full,p->sid, 0);
 	ast_mutex_unlock(&p->lock);
 	return res;
 }
@@ -624,14 +657,15 @@
 	struct sockaddr_in sin;
 	struct sockaddr_in dest;
 	struct in_addr us;
-	iks *iq, *gtalk, *candidate;
+	iks *iq, *gtalk, *candidate, *transport;
 	char user[17], pass[17], preference[5], port[7];
 
 
 	iq = iks_new("iq");
 	gtalk = iks_new("session");
 	candidate = iks_new("candidate");
-	if (!iq || !gtalk || !candidate) {
+	transport = iks_new("transport");
+	if (!iq || !gtalk || !candidate || !transport) {
 		ast_log(LOG_ERROR, "Memory allocation error\n");
 		goto safeout;
 	}
@@ -639,8 +673,11 @@
 	ours2 = ast_calloc(1, sizeof(*ours2));
 	if (!ours1 || !ours2)
 		goto safeout;
+
+	iks_insert_attrib(transport, "xmlns","http://www.google.com/transport/p2p");
 	iks_insert_node(iq, gtalk);
-	iks_insert_node(gtalk, candidate);
+	iks_insert_node(gtalk,transport);
+	iks_insert_node(transport, candidate);
 
 	for (; p; p = p->next) {
 		if (!strcasecmp(p->sid, sid))
@@ -698,7 +735,7 @@
 		iks_insert_attrib(iq, "type", "set");
 		iks_insert_attrib(iq, "id", c->mid);
 		ast_aji_increment_mid(c->mid);
-		iks_insert_attrib(gtalk, "type", "candidates");
+		iks_insert_attrib(gtalk, "type", "transport-info");
 		iks_insert_attrib(gtalk, "id", sid);
 		iks_insert_attrib(gtalk, "initiator", (p->initiator) ? c->jid->full : from);
 		iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
@@ -735,6 +772,8 @@
 		iks_delete(gtalk);
 	if (candidate)
 		iks_delete(candidate);
+	if(transport)
+		iks_delete(transport);
 	return 1;
 }
 
@@ -948,7 +987,7 @@
 	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, "session", "id", tmp->sid)) {
@@ -996,6 +1035,7 @@
 			break;
 		case AST_PBX_SUCCESS:
 			gtalk_response(client, pak, NULL, NULL);
+			gtalk_invite_response(p, pak->from->full, p->parent->connection->jid->full,p->sid, 0);
 			gtalk_create_candidates(client, p,
 					iks_find_attrib(pak->query, "id"),
 					iks_find_attrib(pak->x, "from"));
@@ -1057,6 +1097,10 @@
 	traversenodes = pak->query;
 	while(traversenodes) {
 		if(!strcasecmp(iks_name(traversenodes), "session")) {
+			traversenodes = iks_child(traversenodes);
+			continue;
+		}
+		if(!strcasecmp(iks_name(traversenodes), "transport")) {
 			traversenodes = iks_child(traversenodes);
 			continue;
 		}
@@ -1284,46 +1328,6 @@
 
 	return -1;
 }
-static int gtalk_transmit_invite(struct gtalk_pvt *p)
-{
-	struct gtalk *gtalk = NULL;
-	struct aji_client *client = NULL;
-	iks *iq, *desc, *session;
-	iks *payload_eg711u, *payload_pcmu;
-
-	gtalk = p->parent;
-	client = gtalk->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);
-	ast_aji_increment_mid(client->mid);
-	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");
-	payload_pcmu = iks_new("payload-type");
-	iks_insert_attrib(payload_pcmu, "id", "0");
-	iks_insert_attrib(payload_pcmu, "name", "PCMU");
-	payload_eg711u = iks_new("payload-type");
-	iks_insert_attrib(payload_eg711u, "id", "100");
-	iks_insert_attrib(payload_eg711u, "name", "EG711U");
-	iks_insert_node(desc, payload_pcmu);
-	iks_insert_node(desc, payload_eg711u);
-	iks_insert_node(iq, session);
-	iks_insert_node(session, desc);
-	iks_send(client->p, iq);
-	iks_delete(iq);
-	iks_delete(desc);
-	iks_delete(session);
-	iks_delete(payload_eg711u);
-	iks_delete(payload_pcmu);
-	return 0;
-}
 
 /* Not in use right now.
 static int gtalk_auto_congest(void *nothing)
@@ -1363,7 +1367,7 @@
 	} else
 		ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
 
-	gtalk_transmit_invite(p);
+	gtalk_invite(p, p->from, p->parent->connection->jid->full, p->sid, 1);
 	gtalk_create_candidates(p->parent, p, p->sid, p->from);
 
 	return 0;
@@ -1466,7 +1470,7 @@
 	if (iks_find_with_attrib(pak->x, "session", "type", "initiate")) {
 		/* New call */
 		gtalk_newcall(client, pak);
-	} else if (iks_find_with_attrib(pak->x, "session", "type", "candidates")) {
+	} else if (iks_find_with_attrib(pak->x, "session", "type", "candidates") || iks_find_with_attrib(pak->x, "session", "type", "transport-info") ) {
 		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "About to add candidate!\n");
 		gtalk_add_candidate(client, pak);



More information about the svn-commits mailing list