[asterisk-commits] phsultan: branch phsultan/jingle-support r231400 - in /team/phsultan/jingle-s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 26 09:39:28 CST 2009


Author: phsultan
Date: Thu Nov 26 09:39:26 2009
New Revision: 231400

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=231400
Log:
Advertize our Jingle capabilities, various fixes.

* Set the callerid (name) to the full JID of the caller for incoming Jingle
  calls.
* Fix the length of STUN packets we copy locally (thanks Vadim!).
* Advertize our Jingle capabilities in presence packets.
  This is needed if we want to be able to place calls from XMPP clients like
  Empathy and Pidgin.
* Use switch/case statements where appropriate. 

Modified:
    team/phsultan/jingle-support/channels/chan_jingle.c
    team/phsultan/jingle-support/main/stun.c
    team/phsultan/jingle-support/res/res_jabber.c

Modified: team/phsultan/jingle-support/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/team/phsultan/jingle-support/channels/chan_jingle.c?view=diff&rev=231400&r1=231399&r2=231400
==============================================================================
--- team/phsultan/jingle-support/channels/chan_jingle.c (original)
+++ team/phsultan/jingle-support/channels/chan_jingle.c Thu Nov 26 09:39:26 2009
@@ -735,6 +735,9 @@
 		tmp->initiator = 1;
 	}
 
+	/* Set CALLERID(name) to the full JID of the remote peer */
+	ast_copy_string(tmp->cid_name, tmp->them, sizeof(tmp->cid_name));
+
 	tmp->parent = client;
 	ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
 	ast_mutex_init(&tmp->lock);
@@ -993,7 +996,7 @@
 		}
 	}
 
-	p = jingle_alloc(client, pak->from->partial, iks_find_attrib(pak->query, JINGLE_SID));
+	p = jingle_alloc(client, pak->from->full, iks_find_attrib(pak->query, JINGLE_SID));
 	if (!p) {
 		ast_log(LOG_WARNING, "Unable to allocate jingle structure!\n");
 		jingle_response(client, pak, "resource-constraint", NULL);

Modified: team/phsultan/jingle-support/main/stun.c
URL: http://svnview.digium.com/svn/asterisk/team/phsultan/jingle-support/main/stun.c?view=diff&rev=231400&r1=231399&r2=231400
==============================================================================
--- team/phsultan/jingle-support/main/stun.c (original)
+++ team/phsultan/jingle-support/main/stun.c Thu Nov 26 09:39:26 2009
@@ -321,7 +321,7 @@
 	struct stun_header *hdr = (struct stun_header *)data;
 	struct stun_attr *attr;
 	struct stun_state st;
-	unsigned char stun_pkt[len - sizeof(struct stun_header)];
+	unsigned char stun_pkt[len];
 	int ret = AST_STUN_IGNORE;
 	int x;
 	unsigned char respdata[1024];

Modified: team/phsultan/jingle-support/res/res_jabber.c
URL: http://svnview.digium.com/svn/asterisk/team/phsultan/jingle-support/res/res_jabber.c?view=diff&rev=231400&r1=231399&r2=231400
==============================================================================
--- team/phsultan/jingle-support/res/res_jabber.c (original)
+++ team/phsultan/jingle-support/res/res_jabber.c Thu Nov 26 09:39:26 2009
@@ -1535,28 +1535,29 @@
 	iq = iks_new("iq");
 	presence = iks_new("presence");
 	x = iks_new("x");
-	if (client && iq && presence && x) {
-		if (!iks_find(pak->query, "remove")) {
-			iks_insert_attrib(iq, "from", client->jid->full);
-			iks_insert_attrib(iq, "to", pak->from->full);
-			iks_insert_attrib(iq, "id", pak->id);
-			iks_insert_attrib(iq, "type", "result");
-			ast_aji_send(client, iq);
-
-			iks_insert_attrib(presence, "from", client->jid->full);
-			iks_insert_attrib(presence, "to", pak->from->partial);
-			iks_insert_attrib(presence, "id", client->mid);
-			ast_aji_increment_mid(client->mid);
-			iks_insert_attrib(presence, "type", "subscribe");
-			iks_insert_attrib(x, "xmlns", "vcard-temp:x:update");
-			iks_insert_node(presence, x);
-			ast_aji_send(client, presence); 
-		}
-	} else {
+	if (client || !iq || !presence  || !x) {
 		ast_log(LOG_ERROR, "Out of memory.\n");
-	}
-
-
+		goto safeout;
+	}
+
+	if (!iks_find(pak->query, "remove")) {
+		iks_insert_attrib(iq, "from", client->jid->full);
+		iks_insert_attrib(iq, "to", pak->from->full);
+		iks_insert_attrib(iq, "id", pak->id);
+		iks_insert_attrib(iq, "type", "result");
+		ast_aji_send(client, iq);
+
+		iks_insert_attrib(presence, "from", client->jid->full);
+		iks_insert_attrib(presence, "to", pak->from->partial);
+		iks_insert_attrib(presence, "id", client->mid);
+		ast_aji_increment_mid(client->mid);
+		iks_insert_attrib(presence, "type", "subscribe");
+		iks_insert_attrib(x, "xmlns", "vcard-temp:x:update");
+		iks_insert_node(presence, x);
+		ast_aji_send(client, presence); 
+	}
+
+safeout:
 	iks_delete(iq);
 	iks_delete(presence);
 	iks_delete(x);
@@ -1735,7 +1736,7 @@
 
 /*!
  * \internal
- * \brief Handle add extra info
+ * \brief Handle discovery features in client mode
  * \param data void
  * \param pak ikspak
  * \return IKS_FILTER_EAT
@@ -1745,29 +1746,40 @@
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	struct aji_resource *resource = NULL;
 	struct aji_buddy *buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
+	iks *iq, *ident, *google, *query, *jingle, *jingletransport, *jingleappsrtp, *jingleappsrtpaudio;
+
+	iq = iks_new("iq");
+	query = iks_new("query");
+	ident = iks_new("identity");
+	google = iks_new("feature");
+	jingle = iks_new("feature");
+	jingletransport = iks_new("feature");
+	jingleappsrtp = iks_new("feature");
+	jingleappsrtpaudio = iks_new("feature");
 
 	resource = aji_find_resource(buddy, pak->from->resource);
-	if (pak->subtype == IKS_TYPE_RESULT) {
-		if (!resource) {
-			ast_log(LOG_NOTICE, "JABBER: Received client info from %s when not requested.\n", pak->from->full);
-			ASTOBJ_UNREF(client, aji_client_destroy);
-			return IKS_FILTER_EAT;
-		}
-		if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
-			resource->cap->jingle = 1;
-		} else
-			resource->cap->jingle = 0;
-	} else if (pak->subtype == IKS_TYPE_GET) {
-		iks *iq, *ident, *google, *query, *jingle, *jingletransport, *jingleappsrtp, *jingleappsrtpaudio;
-		iq = iks_new("iq");
-		query = iks_new("query");
-		ident = iks_new("identity");
-		google = iks_new("feature");
-		jingle = iks_new("feature");
-		jingletransport = iks_new("feature");
-		jingleappsrtp = iks_new("feature");
-		jingleappsrtpaudio = iks_new("feature");
-		if (iq && ident && google && jingle && jingletransport && jingleappsrtp && jingleappsrtpaudio) {
+
+	switch(pak->subtype) {
+		case IKS_TYPE_RESULT:
+			/* Process the response we received from the remote
+			 * client */
+			if (!resource) {
+				ast_log(LOG_NOTICE, "JABBER: Received client info from %s when not requested.\n", pak->from->full);
+				ASTOBJ_UNREF(client, aji_client_destroy);
+				goto safeout;
+			}
+			if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1") || iks_find_with_attrib(pak->query, "feature", "var", "urn:xmpp:jingle:1")) {
+				resource->cap->jingle = 1;
+			} else {
+				resource->cap->jingle = 0;
+			}
+			break;
+		case IKS_TYPE_GET:
+			/* Respond to a disco request we received */
+			if (!iq || !ident || !google || !jingle || !jingletransport || !jingleappsrtp || !jingleappsrtpaudio) {
+				ast_log(LOG_ERROR, "Out of Memory.\n");
+				goto safeout;
+			}
 			iks_insert_attrib(iq, "from", client->jid->full);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "type", "result");
@@ -1781,6 +1793,7 @@
 			iks_insert_attrib(jingletransport, "var", "urn:xmpp:jingle:transports:ice-udp:1");
 			iks_insert_attrib(jingleappsrtp, "var", "urn:xmpp:jingle:apps:rtp:1");
 			iks_insert_attrib(jingleappsrtpaudio, "var", "urn:xmpp:jingle:apps:rtp:audio");
+
 			iks_insert_node(iq, query);
 			iks_insert_node(query, ident);
 			iks_insert_node(query, google);
@@ -1789,23 +1802,33 @@
 			iks_insert_node(query, jingleappsrtp);
 			iks_insert_node(query, jingleappsrtpaudio);
 			ast_aji_send(client, iq);
-		} else
-			ast_log(LOG_ERROR, "Out of Memory.\n");
-
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(ident);
-		iks_delete(google);
-	} else if (pak->subtype == IKS_TYPE_ERROR) {
-		ast_log(LOG_NOTICE, "User %s does not support discovery.\n", pak->from->full);
-	}
+
+			break;
+		case IKS_TYPE_ERROR:
+			ast_log(LOG_NOTICE, "User %s does not support discovery.\n", pak->from->full);
+			break;
+		default :
+			/* Discard packet silently */
+			break;
+	}
+
+safeout:
+	iks_delete(iq);
+	iks_delete(query);
+	iks_delete(ident);
+	iks_delete(google);
+	iks_delete(jingle);
+	iks_delete(jingletransport);
+	iks_delete(jingleappsrtp);
+	iks_delete(jingleappsrtpaudio);
+
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_FILTER_EAT;
 }
 
 /*!
  * \internal
- * \brief Handler of the return info packet
+ * \brief Handle discovery features in component mode
  * \param data aji_client
  * \param pak ikspak
  * \return IKS_FILTER_EAT
@@ -1816,130 +1839,131 @@
 	char *node = NULL;
 	struct aji_resource *resource = NULL;
 	struct aji_buddy *buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
+	iks *iq, *query, *identity, *disco, *reg, *commands, *gateway, *version, *vcard, *search;
+
+	iq = iks_new("iq");
+	query = iks_new("query");
+	identity = iks_new("identity");
+	disco = iks_new("feature");
+	reg = iks_new("feature");
+	commands = iks_new("feature");
+	gateway = iks_new("feature");
+	version = iks_new("feature");
+	vcard = iks_new("feature");
+	search = iks_new("feature");
 
 	resource = aji_find_resource(buddy, pak->from->resource);
-	if (pak->subtype == IKS_TYPE_ERROR) {
-		ast_log(LOG_WARNING, "Received error from a client, turn on jabber debug!\n");
-		return IKS_FILTER_EAT;
-	}
-	if (pak->subtype == IKS_TYPE_RESULT) {
-		if (!resource) {
-			ast_log(LOG_NOTICE,"JABBER: Received client info from %s when not requested.\n", pak->from->full);
-			ASTOBJ_UNREF(client, aji_client_destroy);
-			return IKS_FILTER_EAT;
-		}
-		if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
-			resource->cap->jingle = 1;
-		} else
-			resource->cap->jingle = 0;
-	} else if (pak->subtype == IKS_TYPE_GET && !(node = iks_find_attrib(pak->query, "node"))) {
-		iks *iq, *query, *identity, *disco, *reg, *commands, *gateway, *version, *vcard, *search;
-
-		iq = iks_new("iq");
-		query = iks_new("query");
-		identity = iks_new("identity");
-		disco = iks_new("feature");
-		reg = iks_new("feature");
-		commands = iks_new("feature");
-		gateway = iks_new("feature");
-		version = iks_new("feature");
-		vcard = iks_new("feature");
-		search = iks_new("feature");
-
-		if (iq && query && identity && disco && reg && commands && gateway && version && vcard && search && client) {
-			iks_insert_attrib(iq, "from", client->user);
-			iks_insert_attrib(iq, "to", pak->from->full);
-			iks_insert_attrib(iq, "id", pak->id);
-			iks_insert_attrib(iq, "type", "result");
-			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
-			iks_insert_attrib(identity, "category", "gateway");
-			iks_insert_attrib(identity, "type", "pstn");
-			iks_insert_attrib(identity, "name", "Asterisk The Open Source PBX");
-			iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco");
-			iks_insert_attrib(reg, "var", "jabber:iq:register");
-			iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
-			iks_insert_attrib(gateway, "var", "jabber:iq:gateway");
-			iks_insert_attrib(version, "var", "jabber:iq:version");
-			iks_insert_attrib(vcard, "var", "vcard-temp");
-			iks_insert_attrib(search, "var", "jabber:iq:search");
-
-			iks_insert_node(iq, query);
-			iks_insert_node(query, identity);
-			iks_insert_node(query, disco);
-			iks_insert_node(query, reg);
-			iks_insert_node(query, commands);
-			iks_insert_node(query, gateway);
-			iks_insert_node(query, version);
-			iks_insert_node(query, vcard);
-			iks_insert_node(query, search);
-			ast_aji_send(client, iq);
-		} else {
-			ast_log(LOG_ERROR, "Out of memory.\n");
-		}
-
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(identity);
-		iks_delete(disco);
-		iks_delete(reg);
-		iks_delete(commands);
-		iks_delete(gateway);
-		iks_delete(version);
-		iks_delete(vcard);
-		iks_delete(search);
-
-	} else if (pak->subtype == IKS_TYPE_GET && !strcasecmp(node, "http://jabber.org/protocol/commands")) {
-		iks *iq, *query, *confirm;
-		iq = iks_new("iq");
-		query = iks_new("query");
-		confirm = iks_new("item");
-
-		if (iq && query && confirm && client) {
-			iks_insert_attrib(iq, "from", client->user);
-			iks_insert_attrib(iq, "to", pak->from->full);
-			iks_insert_attrib(iq, "id", pak->id);
-			iks_insert_attrib(iq, "type", "result");
-			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
-			iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
-			iks_insert_attrib(confirm, "node", "confirmaccount");
-			iks_insert_attrib(confirm, "name", "Confirm AIM account");
-			iks_insert_attrib(confirm, "jid", client->user);
-			iks_insert_node(iq, query);
-			iks_insert_node(query, confirm);
-			ast_aji_send(client, iq);
-		} else {
-			ast_log(LOG_ERROR, "Out of memory.\n");
-		}
-
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(confirm);
-
-	} else if (pak->subtype == IKS_TYPE_GET && !strcasecmp(node, "confirmaccount")) {
-		iks *iq, *query, *feature;
-
-		iq = iks_new("iq");
-		query = iks_new("query");
-		feature = iks_new("feature");
-
-		if (iq && query && feature && client) {
-			iks_insert_attrib(iq, "from", client->user);
-			iks_insert_attrib(iq, "to", pak->from->full);
-			iks_insert_attrib(iq, "id", pak->id);
-			iks_insert_attrib(iq, "type", "result");
-			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
-			iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
-			iks_insert_node(iq, query);
-			iks_insert_node(query, feature);
-			ast_aji_send(client, iq);
-		} else {
-			ast_log(LOG_ERROR, "Out of memory.\n");
-		}
-
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(feature);
-	}
+
+	switch (pak->subtype) {
+		case IKS_TYPE_RESULT:
+			/* Process the response we received from the remote
+			 * client */
+			if (!resource) {
+				ast_log(LOG_NOTICE,"JABBER: Received client info from %s when not requested.\n", pak->from->full);
+				ASTOBJ_UNREF(client, aji_client_destroy);
+				goto safeout;
+			}
+			if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
+				resource->cap->jingle = 1;
+			} else {
+				resource->cap->jingle = 0;
+			}
+			break;
+		case IKS_TYPE_GET:
+			/* Respond to a disco request we received */
+			if (!iq || !query || !identity || !disco || !reg || !commands || !gateway || !version || !vcard || !search || !client) {
+				ast_log(LOG_ERROR, "Out of memory.\n");
+				goto safeout;	
+			}
+			if (!(node = iks_find_attrib(pak->query, "node"))) {
+				iks_insert_attrib(iq, "from", client->user);
+				iks_insert_attrib(iq, "to", pak->from->full);
+				iks_insert_attrib(iq, "id", pak->id);
+				iks_insert_attrib(iq, "type", "result");
+				iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
+				iks_insert_attrib(identity, "category", "gateway");
+				iks_insert_attrib(identity, "type", "pstn");
+				iks_insert_attrib(identity, "name", "Asterisk The Open Source PBX");
+				iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco");
+				iks_insert_attrib(reg, "var", "jabber:iq:register");
+				iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
+				iks_insert_attrib(gateway, "var", "jabber:iq:gateway");
+				iks_insert_attrib(version, "var", "jabber:iq:version");
+				iks_insert_attrib(vcard, "var", "vcard-temp");
+				iks_insert_attrib(search, "var", "jabber:iq:search");
+
+				iks_insert_node(iq, query);
+				iks_insert_node(query, identity);
+				iks_insert_node(query, disco);
+				iks_insert_node(query, reg);
+				iks_insert_node(query, commands);
+				iks_insert_node(query, gateway);
+				iks_insert_node(query, version);
+				iks_insert_node(query, vcard);
+				iks_insert_node(query, search);
+				ast_aji_send(client, iq);
+
+			} else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
+				iks *confirm = iks_new("item");
+				if (!confirm) {
+					ast_log(LOG_ERROR, "Out of memory.\n");
+					goto safeout;
+				}
+
+				iks_insert_attrib(iq, "from", client->user);
+				iks_insert_attrib(iq, "to", pak->from->full);
+				iks_insert_attrib(iq, "id", pak->id);
+				iks_insert_attrib(iq, "type", "result");
+				iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
+				iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
+				iks_insert_attrib(confirm, "node", "confirmaccount");
+				iks_insert_attrib(confirm, "name", "Confirm AIM account");
+				iks_insert_attrib(confirm, "jid", client->user);
+				iks_insert_node(iq, query);
+				iks_insert_node(query, confirm);
+				ast_aji_send(client, iq);
+				iks_delete(confirm);
+
+			} else if (!strcasecmp(node, "confirmaccount")) {
+				iks *feature = iks_new("feature");
+				if (!feature) {
+					ast_log(LOG_ERROR, "Out of memory.\n");
+					goto safeout;
+				}
+				
+				iks_insert_attrib(iq, "from", client->user);
+				iks_insert_attrib(iq, "to", pak->from->full);
+				iks_insert_attrib(iq, "id", pak->id);
+				iks_insert_attrib(iq, "type", "result");
+				iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
+				iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
+				iks_insert_node(iq, query);
+				iks_insert_node(query, feature);
+				ast_aji_send(client, iq);
+				iks_delete(feature);
+			}
+
+			break;
+		case IKS_TYPE_ERROR:
+			ast_log(LOG_WARNING, "Received error from a client, turn on jabber debug!\n");
+			goto safeout;
+			break;
+		default :
+			/* Discard packet silently */
+			break;
+	}
+
+safeout:
+	iks_delete(iq);
+	iks_delete(query);
+	iks_delete(identity);
+	iks_delete(disco);
+	iks_delete(reg);
+	iks_delete(commands);
+	iks_delete(gateway);
+	iks_delete(version);
+	iks_delete(vcard);
+	iks_delete(search);
 
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_FILTER_EAT;




More information about the asterisk-commits mailing list