[asterisk-commits] wdoekes: trunk r343219 - in /trunk: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 2 17:46:33 CDT 2011


Author: wdoekes
Date: Wed Nov  2 17:46:27 2011
New Revision: 343219

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=343219
Log:
Fix improper warning introduced by r342927 and more tweaks

Changeset r342927 introduced a warning which was only supposed to be
emitted when a found realtime peer had an empty (or no) name. It turned
out that there were some inconsistencies left. Now found peers with an
empty name are explicitly ignored like before r342927 but better.

Reviewed by: Stefan Schmidts, Terry Wilson

Review: https://reviewboard.asterisk.org/r/1560
........

Merged revisions 343181 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 343192 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/channels/chan_sip.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=343219&r1=343218&r2=343219
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Nov  2 17:46:27 2011
@@ -4740,10 +4740,21 @@
 
 static const char *get_name_from_variable(const struct ast_variable *var)
 {
+	/* Don't expect this to return non-NULL. Both NULL and empty
+	 * values can cause the option to get removed from the variable
+	 * list. This is called on ast_variables gotten from both
+	 * ast_load_realtime and ast_load_realtime_multientry.
+	 * - ast_load_realtime removes options with empty values
+	 * - ast_load_realtime_multientry does not!
+	 * For consistent behaviour, we check for the empty name and
+	 * return NULL instead. */
 	const struct ast_variable *tmp;
 	for (tmp = var; tmp; tmp = tmp->next) {
 		if (!strcasecmp(tmp->name, "name")) {
-			return tmp->value;
+			if (!ast_strlen_zero(tmp->value)) {
+				return tmp->value;
+			}
+			break;
 		}
 	}
 	return NULL;
@@ -4806,10 +4817,13 @@
  * the sippeer also had it continue look for another match, so we do
  * the same. */
 static struct ast_variable *realtime_peer_get_sippeer_helper(const char **name, struct ast_variable **varregs) {
-	struct ast_variable *var;
+	struct ast_variable *var = NULL;
 	const char *old_name = *name;
 	*name = get_name_from_variable(*varregs);
-	if (!(var = ast_load_realtime("sippeers", "name", *name, SENTINEL))) {
+	if (!*name || !(var = ast_load_realtime("sippeers", "name", *name, SENTINEL))) {
+		if (!*name) {
+			ast_log(LOG_WARNING, "Found sipreg but it has no name\n");
+		}
 		ast_variables_destroy(*varregs);
 		*varregs = NULL;
 		*name = old_name;
@@ -4852,21 +4866,32 @@
 		;
 	}
 
-	/* Did we find anything? */
-	if (*var) {
-		/* Make sure name is populated. */
-		if (!*name) {
-			*name = get_name_from_variable(*var);
-		}
-		/* Make sure varregs is populated if var is. Ensuring
-		 * that var is set when varregs is, is taken care of by
-		 * realtime_peer_get_sippeer_helper(). */
-		if (varregs && !*varregs) {
-			*varregs = ast_load_realtime("sipregs", "name", *name, SENTINEL);
-		}
-		return 1;
-	}
-	return 0;
+	/* Nothing found? */
+	if (!*var) {
+		return 0;
+	}
+
+	/* Check peer name. It must not be empty. There may exist a
+	 * different match that does have a name, but it's too late for
+	 * that now. */
+	if (!*name && !(*name = get_name_from_variable(*var))) {
+		ast_log(LOG_WARNING, "Found peer for IP %s but it has no name\n", ipaddr);
+		ast_variables_destroy(*var);
+		*var = NULL;
+		if (varregs && *varregs) {
+			ast_variables_destroy(*varregs);
+			*varregs = NULL;
+		}
+		return 0;
+	}
+
+	/* Make sure varregs is populated if var is. The inverse,
+	 * ensuring that var is set when varregs is, is taken
+	 * care of by realtime_peer_get_sippeer_helper(). */
+	if (varregs && !*varregs) {
+		*varregs = ast_load_realtime("sipregs", "name", *name, SENTINEL);
+	}
+	return 1;
 }
 
 /*! \brief  realtime_peer: Get peer from realtime storage
@@ -4897,7 +4922,6 @@
 	} else if (addr && realtime_peer_by_addr(&newpeername, addr, ipaddr, &var, realtimeregs ? &varregs : NULL)) {
 		;
 	} else {
-		ast_log(LOG_WARNING, "Cannot Determine peer name ip=%s\n", ipaddr);
 		return NULL;
 	}
 




More information about the asterisk-commits mailing list