[asterisk-commits] trunk r15581 - /trunk/pbx/pbx_dundi.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 28 08:19:34 MST 2006


Author: rizzo
Date: Tue Mar 28 09:19:32 2006
New Revision: 15581

URL: http://svn.digium.com/view/asterisk?rev=15581&view=rev
Log:
- remove an unnecessary cast and recomputation of (timeout - now);
- remove useless recomputations of strlen(word) in a loop, and
  normalize the form of complete_peer_helper();
- move LOCAL_USER_ADD() to after the verification of arguments,
  thus removing the need for one LOCAL_USER_REMOVE() call.

The three chunks of the patch are fully disjoint.


Modified:
    trunk/pbx/pbx_dundi.c

Modified: trunk/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_dundi.c?rev=15581&r1=15580&r2=15581&view=diff
==============================================================================
--- trunk/pbx/pbx_dundi.c (original)
+++ trunk/pbx/pbx_dundi.c Tue Mar 28 09:19:32 2006
@@ -1129,17 +1129,16 @@
 	int weight;
 	int length;
 	int z;
-	int expiration;
 	char fs[256];
-	time_t timeout;
 
 	/* Build request string */
 	if (!ast_db_get("dundi/cache", key, data, sizeof(data))) {
+		time_t timeout;
 		ptr = data;
 		if (!ast_get_time_t(ptr, &timeout, 0, &length)) {
-			expiration = timeout - now;
+			int expiration = timeout - now;
 			if (expiration > 0) {
-				ast_log(LOG_DEBUG, "Found cache expiring in %d seconds!\n", (int)(timeout - now));
+				ast_log(LOG_DEBUG, "Found cache expiring in %d seconds!\n", expiration);
 				ptr += length + 1;
 				while((sscanf(ptr, "%d/%d/%d/%n", &(flags.flags), &weight, &tech, &length) == 3)) {
 					ptr += length;
@@ -2229,25 +2228,20 @@
 
 static char *complete_peer_helper(const char *line, const char *word, int pos, int state, int rpos)
 {
-	int which=0;
-	char *ret;
+	int which=0, len;
+	char *ret = NULL;
 	struct dundi_peer *p;
 	char eid_str[20];
+
 	if (pos != rpos)
 		return NULL;
 	ast_mutex_lock(&peerlock);
-	p = peers;
-	while(p) {
-		if (!strncasecmp(word, dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid), strlen(word))) {
-			if (++which > state)
-				break;
-		}
-		p = p->next;
-	}
-	if (p) {
-		ret = strdup(dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid));
-	} else
-		ret = NULL;
+	len = strlen(word);
+	for (p = peers; !ret && p; p = p->next) {
+		const char *s = dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid);
+		if (!strncasecmp(word, s, len) && ++which > state)
+			ret = ast_strdup(s);
+	}
 	ast_mutex_unlock(&peerlock);
 	return ret;
 }
@@ -3846,15 +3840,14 @@
 	struct localuser *u;
 	struct dundi_result dr[MAX_RESULTS];
 
-	LOCAL_USER_ADD(u);
-
 	buf[0] = '\0';
 
 	if (ast_strlen_zero(num)) {
 		ast_log(LOG_WARNING, "DUNDILOOKUP requires an argument (number)\n");
-		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
+
+	LOCAL_USER_ADD(u);
 
 	context = strchr(num, '|');
 	if (context) {



More information about the asterisk-commits mailing list