[asterisk-commits] wdoekes: branch 10 r343192 - in /branches/10: ./ channels/chan_sip.c

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


Author: wdoekes
Date: Wed Nov  2 17:24:23 2011
New Revision: 343192

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=343192
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

Modified:
    branches/10/   (props changed)
    branches/10/channels/chan_sip.c

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

Modified: branches/10/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/channels/chan_sip.c?view=diff&rev=343192&r1=343191&r2=343192
==============================================================================
--- branches/10/channels/chan_sip.c (original)
+++ branches/10/channels/chan_sip.c Wed Nov  2 17:24:23 2011
@@ -4738,10 +4738,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;
@@ -4804,10 +4815,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;
@@ -4850,21 +4864,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
@@ -4895,7 +4920,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