[asterisk-commits] bmd: branch group/newcdr r117991 - /team/group/newcdr/main/channel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 22 16:45:50 CDT 2008


Author: bmd
Date: Thu May 22 16:45:50 2008
New Revision: 117991

URL: http://svn.digium.com/view/asterisk?view=rev&rev=117991
Log:
fix the way linkedids are compared so that 1.11 will not seem older than 1.2

Modified:
    team/group/newcdr/main/channel.c

Modified: team/group/newcdr/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/channel.c?view=diff&rev=117991&r1=117990&r2=117991
==============================================================================
--- team/group/newcdr/main/channel.c (original)
+++ team/group/newcdr/main/channel.c Thu May 22 16:45:50 2008
@@ -3820,8 +3820,67 @@
 	}
 }
 
-/* return the oldest of two uniqueids */
-#define OLDEST(a,b) (ast_strlen_zero(a) ? b : (ast_strlen_zero(b) ? a : (strcmp(a, b) < 0 ? a : b)))
+
+
+/* return the oldest of two linkedids.  linkedid is derived from
+   uniqueid which is formed like this: [systemname-]ctime.seq
+
+   The systemname, and the dash are optional, followed by the epoch
+   time followed by an integer sequence.  Note that this is not a
+   decimal number, since 1.2 is less than 1.11 in uniqueid land.
+
+   To compare two uniqueids, we parse out the integer values of the
+   time and the sequence numbers and compare them, with time trumping
+   sequence.
+*/
+static const char *oldest_linkedid(const char *a, const char *b)
+{
+	const char *satime, *saseq;
+	const char *sbtime, *sbseq;
+	const char *dash;
+
+	unsigned int atime, aseq, btime, bseq;
+	
+	if (ast_strlen_zero(a))
+		return b;
+
+	if (ast_strlen_zero(b))
+		return a;
+
+	satime = a;
+	sbtime = b;
+
+	/* jump over the system name */
+	if ((dash = strrchr(satime, '-'))) {
+		satime = dash+1;
+	}
+	if ((dash = strrchr(sbtime, '-'))) {
+		sbtime = dash+1;
+	}
+
+	/* the sequence comes after the '.' */
+	saseq = strchr(satime, '.');
+	sbseq = strchr(sbtime, '.');
+	if (!saseq || !sbseq)
+		return NULL;
+	saseq++;
+	sbseq++;
+
+	/* convert it all to integers */
+	atime = atoi(satime); /* note that atoi is ignoring the '.' after the time string */
+	btime = atoi(sbtime); /* note that atoi is ignoring the '.' after the time string */
+	aseq = atoi(saseq);
+	bseq = atoi(sbseq);
+
+	/* and finally compare */
+	if (atime == btime) {
+		return (aseq < bseq) ? a : b;
+	}
+	else {
+		return (atime < btime) ? a : b;
+	}
+}
+
 
 /*!
   \brief Propagate the linked id from one channel to the other
@@ -3832,21 +3891,21 @@
 	const char* linkedid=NULL;
 	struct ast_channel *bridged;
 
-	linkedid = OLDEST(chan->linkedid, peer->linkedid);
-	linkedid = OLDEST(linkedid, chan->uniqueid);
-	linkedid = OLDEST(linkedid, peer->uniqueid);
+	linkedid = oldest_linkedid(chan->linkedid, peer->linkedid);
+	linkedid = oldest_linkedid(linkedid, chan->uniqueid);
+	linkedid = oldest_linkedid(linkedid, peer->uniqueid);
 	if (chan->_bridge) {
 		bridged = ast_bridged_channel(chan);
 		if (bridged != peer) {
-			linkedid = OLDEST(linkedid, bridged->linkedid);
-			linkedid = OLDEST(linkedid, bridged->uniqueid);
+			linkedid = oldest_linkedid(linkedid, bridged->linkedid);
+			linkedid = oldest_linkedid(linkedid, bridged->uniqueid);
 		}
 	}
 	if (peer->_bridge) {
 		bridged = ast_bridged_channel(peer);
 		if (bridged != chan) {
-			linkedid = OLDEST(linkedid, bridged->linkedid);
-			linkedid = OLDEST(linkedid, bridged->uniqueid);
+			linkedid = oldest_linkedid(linkedid, bridged->linkedid);
+			linkedid = oldest_linkedid(linkedid, bridged->uniqueid);
 		}
 	}
 




More information about the asterisk-commits mailing list