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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Aug 23 15:57:11 MST 2006


Author: mogorman
Date: Wed Aug 23 17:57:10 2006
New Revision: 40963

URL: http://svn.digium.com/view/asterisk?rev=40963&view=rev
Log:
hugenness

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=40963&r1=40962&r2=40963&view=diff
==============================================================================
--- team/mogorman/asterisk-jabber/channels/chan_gtalk.c (original)
+++ team/mogorman/asterisk-jabber/channels/chan_gtalk.c Wed Aug 23 17:57:10 2006
@@ -74,11 +74,7 @@
 
 #define GOOGLE_CONFIG "gtalk.conf"
 
-#define GOOGLE_NODE "session"
 #define GOOGLE_NS "http://www.google.com/session"
-#define GOOGLE_SID "id"
-#define GOOGLE_ACCEPT "accept"
-#define GOOGLE_NEGOTIATE "candidates"
 
 
 /*! Global jitterbuffer configuration - by default, jb is disabled */
@@ -266,58 +262,102 @@
 }
 
 
-static void add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodecs)
+static int add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodecs)
 {
 	char *format = ast_getformatname(codec);
 
 	if (!strcasecmp("ulaw", format)) {
 		iks *payload_eg711u, *payload_pcmu;
 		payload_pcmu = iks_new("payload-type");
+		payload_eg711u = iks_new("payload-type");
+	
+		if(!payload_eg711u || !payload_pcmu) {
+			if(payload_pcmu)
+				iks_delete(payload_pcmu);
+			if(payload_eg711u)
+				iks_delete(payload_eg711u);
+			ast_log(LOG_WARNING,"Failed to allocate iks node");
+			return -1;
+		}
 		iks_insert_attrib(payload_pcmu, "id", "0");
 		iks_insert_attrib(payload_pcmu, "name", "PCMU");
-		iks_insert_attrib(payload_pcmu, "xmlns", "http://www.google.com/session/phone");
-		payload_eg711u = iks_new("payload-type");
+		iks_insert_attrib(payload_pcmu, "clockrate","8000");
+		iks_insert_attrib(payload_pcmu, "bitrate","64000");
 		iks_insert_attrib(payload_eg711u, "id", "100");
 		iks_insert_attrib(payload_eg711u, "name", "EG711U");
-		iks_insert_attrib(payload_eg711u, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_attrib(payload_eg711u, "clockrate","8000");
+		iks_insert_attrib(payload_eg711u, "bitrate","64000");
 		iks_insert_node(dcodecs, payload_pcmu);
 		iks_insert_node(dcodecs, payload_eg711u);
 	}
 	if (!strcasecmp("alaw", format)) {
-		iks *payload_eg711a;
-		iks *payload_pcma = iks_new("payload-type");
+		iks *payload_eg711a, *payload_pcma;
+		payload_pcma = iks_new("payload-type");
+		payload_eg711a = iks_new("payload-type");
+		if(!payload_eg711a || !payload_pcma) {
+			if(payload_eg711a)
+				iks_delete(payload_eg711a);
+			if(payload_pcma)
+				iks_delete(payload_pcma);
+			ast_log(LOG_WARNING,"Failed to allocate iks node");
+			return -1;
+		}
 		iks_insert_attrib(payload_pcma, "id", "8");
 		iks_insert_attrib(payload_pcma, "name", "PCMA");
-		iks_insert_attrib(payload_pcma, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_attrib(payload_pcma, "clockrate","8000");
+		iks_insert_attrib(payload_pcma, "bitrate","64000");
 		payload_eg711a = iks_new("payload-type");
 		iks_insert_attrib(payload_eg711a, "id", "101");
 		iks_insert_attrib(payload_eg711a, "name", "EG711A");
-		iks_insert_attrib(payload_eg711a, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_attrib(payload_eg711a, "clockrate","8000");
+		iks_insert_attrib(payload_eg711a, "bitrate","64000");
 		iks_insert_node(dcodecs, payload_pcma);
 		iks_insert_node(dcodecs, payload_eg711a);
 	}
 	if (!strcasecmp("ilbc", format)) {
 		iks *payload_ilbc = iks_new("payload-type");
+		if(!payload_ilbc) {
+			ast_log(LOG_WARNING,"Failed to allocate iks node");
+			return -1;
+		}
 		iks_insert_attrib(payload_ilbc, "id", "102");
 		iks_insert_attrib(payload_ilbc, "name", "iLBC");
-		iks_insert_attrib(payload_ilbc, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_attrib(payload_ilbc, "clockrate","8000");
+		iks_insert_attrib(payload_ilbc, "bitrate","13300");
 		iks_insert_node(dcodecs, payload_ilbc);
 	}
 	if (!strcasecmp("g723", format)) {
 		iks *payload_g723 = iks_new("payload-type");
+		if(!payload_g723) {
+			ast_log(LOG_WARNING,"Failed to allocate iks node");
+			return -1;
+		}
 		iks_insert_attrib(payload_g723, "id", "4");
 		iks_insert_attrib(payload_g723, "name", "G723");
-		iks_insert_attrib(payload_g723, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_attrib(payload_g723, "clockrate","8000");
+		iks_insert_attrib(payload_g723, "bitrate","6300");
 		iks_insert_node(dcodecs, payload_g723);
 	}
+	if (!strcasecmp("speex", format)) {
+		iks *payload_speex = iks_new("payload-type");
+		if(!payload_speex) {
+			ast_log(LOG_WARNING,"Failed to allocate iks node");
+			return -1;
+		}
+		iks_insert_attrib(payload_speex, "id", "98");
+		iks_insert_attrib(payload_speex, "name", "G723");
+		iks_insert_attrib(payload_speex, "clockrate","8000");
+		iks_insert_attrib(payload_speex, "bitrate","11000");
+		iks_insert_node(dcodecs, payload_speex);
+	}
 	ast_rtp_lookup_code(p->rtp, 1, codec);
+	return 0;
 }
 
 static int gtalk_accept_call(struct gtalk *client, struct gtalk_pvt *p)
 {
 	struct gtalk_pvt *tmp = client->p;
-	struct aji_client *c = client->connection;
-	iks *iq, *gtalk, *dcodecs, *payload_red, *payload_audio, *payload_cn;
+	iks *iq, *gtalk, *dcodecs, *payload_audio, *transport;
 	int x;
 	int pref_codec = 0;
 	int alreadysent = 0;
@@ -326,62 +366,67 @@
 		return 1;
 
 	iq = iks_new("iq");
-	gtalk = iks_new(GOOGLE_NODE);
+	gtalk = iks_new("session");
 	dcodecs = iks_new("description");
-	if (iq && gtalk && dcodecs) {
-		iks_insert_attrib(dcodecs, "xmlns", "http://www.google.com/session/phone");
-
-		for (x = 0; x < 32; x++) {
-			if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
-				break;
-			if (!(client->capability & pref_codec))
-				continue;
-			if (alreadysent & pref_codec)
-				continue;
-			if (pref_codec <= AST_FORMAT_MAX_AUDIO)
-				add_codec_to_answer(p, pref_codec, dcodecs);
-			else
-				add_codec_to_answer(p, pref_codec, dcodecs);
-			alreadysent |= pref_codec;
-		}
-		payload_red = iks_new("payload-type");
-		iks_insert_attrib(payload_red, "id", "117");
-		iks_insert_attrib(payload_red, "name", "red");
-		iks_insert_attrib(payload_red, "xmlns", "http://www.google.com/session/phone");
-		payload_audio = iks_new("payload-type");
-		iks_insert_attrib(payload_audio, "id", "106");
-		iks_insert_attrib(payload_audio, "name", "audio/telephone-event");
-		iks_insert_attrib(payload_audio, "xmlns", "http://www.google.com/session/phone");
-		payload_cn = iks_new("payload-type");
-		iks_insert_attrib(payload_cn, "id", "13");
-		iks_insert_attrib(payload_cn, "name", "CN");
-		iks_insert_attrib(payload_cn, "xmlns", "http://www.google.com/session/phone");
-
-
-		iks_insert_attrib(iq, "type", "set");
-		iks_insert_attrib(iq, "to", (p->from) ? p->from : client->user);
-		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", GOOGLE_ACCEPT);
-		iks_insert_attrib(gtalk, "initiator",
-						  p->initiator ? client->connection->jid->full : p->from);
-		iks_insert_attrib(gtalk, GOOGLE_SID, tmp->sid);
-		iks_insert_node(iq, gtalk);
-		iks_insert_node(gtalk, dcodecs);
-		iks_insert_node(dcodecs, payload_red);
-		iks_insert_node(dcodecs, payload_audio);
-		iks_insert_node(dcodecs, payload_cn);
-
-		iks_send(c->p, iq);
-		iks_delete(payload_red);
-		iks_delete(payload_audio);
-		iks_delete(payload_cn);
-		iks_delete(dcodecs);
-		iks_delete(gtalk);
-		iks_delete(iq);
-	}
+	transport = iks_new("transport");
+	payload_audio = iks_new("payload-type");
+	if (!(iq && gtalk && dcodecs && transport && payload_audio)){
+		if(iq)
+			iks_delete(iq);
+		if(gtalk)
+			iks_delete(gtalk);
+		if(dcodecs)
+			iks_delete(dcodecs);
+		if(transport)
+			iks_delete(transport);
+		if(payload_audio)
+			iks_delete(payload_audio);
+
+		ast_log(LOG_ERROR, "Could not allocate iksemel nodes\n");
+		return 0;
+	}
+	iks_insert_attrib(dcodecs, "xmlns", "http://www.google.com/session/phone");
+	iks_insert_attrib(dcodecs, "xml:lang", "en");
+
+	for (x = 0; x < 32; x++) {
+		if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
+			break;
+		if (!(client->capability & pref_codec))
+			continue;
+		if (alreadysent & pref_codec)
+			continue;
+		add_codec_to_answer(p, pref_codec, dcodecs);
+		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(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, "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_node(iq, gtalk);
+	iks_insert_node(gtalk, dcodecs);
+	iks_insert_node(gtalk, transport);
+	iks_insert_node(dcodecs, payload_audio);
+
+	iks_send(client->connection->p, iq);
+	iks_delete(payload_audio);
+	iks_delete(transport);
+	iks_delete(dcodecs);
+	iks_delete(gtalk);
+	iks_delete(iq);
 	return 1;
 }
 
@@ -490,7 +535,7 @@
 	ast_log(LOG_DEBUG, "The client is %s\n", client->name);
 	/* Make sure our new call doesn't exist yet */
 	for (tmp = client->p; tmp; tmp = tmp->next) {
-		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid))
 			break;
 	}
 
@@ -510,7 +555,7 @@
 	char *dtmf;
 	/* Make sure our new call doesn't exist yet */
 	for (tmp = client->p; tmp; tmp = tmp->next) {
-		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid))
 			break;
 	}
 
@@ -558,7 +603,7 @@
 	ast_log(LOG_DEBUG, "The client is %s\n", client->name);
 	/* Make sure our new call doesn't exist yet */
 	for (tmp = client->p; tmp; tmp = tmp->next) {
-		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid))
 			break;
 	}
 
@@ -584,7 +629,7 @@
 
 
 	iq = iks_new("iq");
-	gtalk = iks_new(GOOGLE_NODE);
+	gtalk = iks_new("session");
 	candidate = iks_new("candidate");
 	if (!iq || !gtalk || !candidate) {
 		ast_log(LOG_ERROR, "Memory allocation error\n");
@@ -906,7 +951,7 @@
 
 	/* Make sure our new call doesn't exist yet */
 	while (tmp) {
-		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
 			ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
 			gtalk_response(client, pak, "out-of-order", NULL);
 			return -1;
@@ -914,7 +959,7 @@
 		tmp = tmp->next;
 	}
 
-	p = gtalk_alloc(client, pak->from->partial, iks_find_attrib(pak->query, GOOGLE_SID));
+	p = gtalk_alloc(client, pak->from->partial, iks_find_attrib(pak->query, "id"));
 	if (!p) {
 		ast_log(LOG_WARNING, "Unable to allocate gtalk structure!\n");
 		return -1;
@@ -923,8 +968,8 @@
 	if (chan) {
 		ast_mutex_lock(&p->lock);
 		ast_copy_string(p->from, pak->from->full, sizeof(p->from));
-		if (iks_find_attrib(pak->query, GOOGLE_SID)) {
-			ast_copy_string(p->sid, iks_find_attrib(pak->query, GOOGLE_SID),
+		if (iks_find_attrib(pak->query, "id")) {
+			ast_copy_string(p->sid, iks_find_attrib(pak->query, "id"),
 							sizeof(p->sid));
 		}
 
@@ -952,7 +997,7 @@
 		case AST_PBX_SUCCESS:
 			gtalk_response(client, pak, NULL, NULL);
 			gtalk_create_candidates(client, p,
-					iks_find_attrib(pak->query, GOOGLE_SID),
+					iks_find_attrib(pak->query, "id"),
 					iks_find_attrib(pak->x, "from"));
 			/* nothing to do */
 			break;
@@ -1000,7 +1045,7 @@
 	if (!newcandidate)
 		return 0;
 	for (tmp = client->p; tmp; tmp = tmp->next) {
-		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
+		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
 			p = tmp;
 			break;
 		}
@@ -1418,22 +1463,22 @@
 {
 	struct gtalk *client = ASTOBJ_REF((struct gtalk *) data);
 
-	if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "initiate")) {
+	if (iks_find_with_attrib(pak->x, "session", "type", "initiate")) {
 		/* New call */
 		gtalk_newcall(client, pak);
-	} else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", GOOGLE_NEGOTIATE)) {
+	} else if (iks_find_with_attrib(pak->x, "session", "type", "candidates")) {
 		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "About to add candidate!\n");
 		gtalk_add_candidate(client, pak);
 		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "Candidate Added!\n");
-	} else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", GOOGLE_ACCEPT)) {
+	} else if (iks_find_with_attrib(pak->x, "session", "type", "accept")) {
 		gtalk_is_answered(client, pak);
-	} else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "content-info")) {
+	} else if (iks_find_with_attrib(pak->x, "session", "type", "content-info")) {
 		gtalk_handle_dtmf(client, pak);
-	} else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "terminate")) {
+	} else if (iks_find_with_attrib(pak->x, "session", "type", "terminate")) {
 		gtalk_hangup_farend(client, pak);
-	} else if (iks_find_with_attrib(pak->x, GOOGLE_NODE, "type", "reject")) {
+	} else if (iks_find_with_attrib(pak->x, "session", "type", "reject")) {
 		gtalk_hangup_farend(client, pak);
 	}
 	ASTOBJ_UNREF(client, gtalk_member_destroy);
@@ -1578,8 +1623,6 @@
 			ast_parse_allow_disallow(&prefs, &global_capability, var->value, 1);
 		else if (!strcasecmp(var->name, "context"))
 			ast_copy_string(context, var->value, sizeof(context));
-		else if (!strcasecmp(var->name, "externip"))
-			ast_copy_string(externip, var->value, sizeof(externip));
 /*  Idea to allow for custom candidates  */
 /*
 		else if (!strcasecmp(var->name, "candidate")) {



More information about the asterisk-commits mailing list