[asterisk-commits] phsultan: branch 1.4 r79665 - /branches/1.4/res/res_jabber.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 16 04:37:11 CDT 2007


Author: phsultan
Date: Thu Aug 16 04:37:10 2007
New Revision: 79665

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79665
Log:
A fix for two critical problems detected while working with Daniel
McKeehan in issue #10184. 

Upon priority change, the resource list is not NULL terminated when
moving an item to the end of the list. This makes Asterisk endlessy
loop whenever it needs to read the list. Jids with different resource and
priority values, like in Gmail's and GoogleTalk's jabber clients put
that problem in evidence.

Upon reception of a 'from' attribute with an empty resource string,
Asterisk crashes when trying to access the found->cap pointer if the
resource list for the given buddy is not empty. This situation is
perfectly valid and must be handled. The Gizmoproject's jabber client
put that problem in evidence.

Also added a few comments in the code as well as a handle for the
capabilities from Gmail's jabber client, which are stored in a caps:c tag
rather than the usual c tag.

Closes issue #10184.

Modified:
    branches/1.4/res/res_jabber.c

Modified: branches/1.4/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/res/res_jabber.c?view=diff&rev=79665&r1=79664&r2=79665
==============================================================================
--- branches/1.4/res/res_jabber.c (original)
+++ branches/1.4/res/res_jabber.c Thu Aug 16 04:37:10 2007
@@ -1209,29 +1209,42 @@
 				found = NULL;
 				break;
 			}
+			/* resource list is sorted by descending priority */
 			if (tmp->priority != priority) {
 				found->priority = priority;
 				if (!last && !found->next)
+					/* resource was found to be unique,
+					   leave loop */
 					break;
+				/* search for resource in our list
+				   and take it out for the moment */
 				if (last)
 					last->next = found->next;
 				else
 					buddy->resources = found->next;
+
 				last = NULL;
 				tmp = buddy->resources;
 				if (!buddy->resources)
 					buddy->resources = found;
+				/* priority processing */
 				while (tmp) {
+					/* insert resource back according to 
+					   its priority value */
 					if (found->priority > tmp->priority) {
 						if (last)
+							/* insert within list */
 							last->next = found;
 						found->next = tmp;
 						if (!last)
+							/* insert on top */
 							buddy->resources = found;
 						break;
 					}
 					if (!tmp->next) {
+						/* insert at the end of the list */
 						tmp->next = found;
+						found->next = NULL;
 						break;
 					}
 					last = tmp;
@@ -1244,6 +1257,7 @@
 		tmp = tmp->next;
 	}
 
+	/* resource not found in our list, create it */
 	if (!found && status != 6) {
 		found = (struct aji_resource *) malloc(sizeof(struct aji_resource));
 		memset(found, 0, sizeof(struct aji_resource));
@@ -1278,11 +1292,24 @@
 		if (!tmp)
 			buddy->resources = found;
 	}
+	
+	/* if 'from' attribute does not contain 'resource' string
+	   point to the top of our resource list */
+	if (!found && !pak->from->resource && buddy->resources) {
+		found = buddy->resources;
+	}
+
 	ASTOBJ_UNLOCK(buddy);
 	ASTOBJ_UNREF(buddy, aji_buddy_destroy);
 
 	node = iks_find_attrib(iks_find(pak->x, "c"), "node");
 	ver = iks_find_attrib(iks_find(pak->x, "c"), "ver");
+
+	/* handle gmail client's special caps:c tag */
+	if (!node && !ver) {
+		node = iks_find_attrib(iks_find(pak->x, "caps:c"), "node");
+		ver = iks_find_attrib(iks_find(pak->x, "caps:c"), "ver");
+	}
 
 	if(status !=6 && !found->cap) {
 		found->cap = aji_find_version(node, ver, pak);




More information about the asterisk-commits mailing list