[asterisk-commits] mmichelson: branch group/issue8824 r154961 - in /team/group/issue8824: ./ app...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 5 17:06:05 CST 2008


Author: mmichelson
Date: Wed Nov  5 17:06:04 2008
New Revision: 154961

URL: http://svn.digium.com/view/asterisk?view=rev&rev=154961
Log:
Resolve conflicts and reset automerge


Modified:
    team/group/issue8824/   (props changed)
    team/group/issue8824/CHANGES
    team/group/issue8824/apps/app_directed_pickup.c
    team/group/issue8824/funcs/func_strings.c
    team/group/issue8824/include/asterisk.h
    team/group/issue8824/include/asterisk/app.h
    team/group/issue8824/main/app.c
    team/group/issue8824/main/asterisk.c
    team/group/issue8824/main/features.c

Propchange: team/group/issue8824/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/issue8824/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Nov  5 17:06:04 2008
@@ -1,1 +1,1 @@
-/trunk:1-154887
+/trunk:1-154947

Modified: team/group/issue8824/CHANGES
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/CHANGES?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/CHANGES (original)
+++ team/group/issue8824/CHANGES Wed Nov  5 17:06:04 2008
@@ -68,6 +68,9 @@
  * Added debugging CLI functions to func_odbc, 'odbc read' and 'odbc write'.
  * func_odbc now may specify an insert query to execute, when the write query
    affects 0 rows (usually indicating that no such row exists).
+ * Added a new dialplan function, LISTFILTER, which permits removing elements
+   from a set list, by name.  Uses the same general syntax as the existing CUT
+   and FIELDQTY dialplan functions, which also manage lists.
 
 Applications
 ------------

Modified: team/group/issue8824/apps/app_directed_pickup.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/apps/app_directed_pickup.c?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/apps/app_directed_pickup.c (original)
+++ team/group/issue8824/apps/app_directed_pickup.c Wed Nov  5 17:06:04 2008
@@ -182,42 +182,46 @@
 /* Attempt to pick up specified extension with context */
 static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
 {
-	int res = -1;
-	struct ast_channel *target = NULL;
-
-	while ((target = ast_channel_walk_locked(target))) {
-		if ((!strcasecmp(target->macroexten, exten) || !strcasecmp(target->exten, exten)) &&
-			!strcasecmp(target->dialcontext, context) &&
-			can_pickup(target)) {
-			res = pickup_do(chan, target);
-			ast_channel_unlock(target);
-			break;
-		}
+	auto int find_by_exten(struct ast_channel *c);
+	int find_by_exten(struct ast_channel *c) {
+		return (!strcasecmp(c->macroexten, exten) || !strcasecmp(c->exten, exten)) &&
+			!strcasecmp(c->dialcontext, context) &&
+			can_pickup(c);
+	}
+
+	struct ast_channel *target = ast_channel_search_locked(find_by_exten);
+
+	if (target) {
+		int res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-	}
-
-	return res;
+		target = NULL;
+		return res;
+	}
+
+	return -1;
 }
 
 /* Attempt to pick up specified mark */
 static int pickup_by_mark(struct ast_channel *chan, const char *mark)
 {
-	int res = -1;
-	const char *tmp = NULL;
-	struct ast_channel *target = NULL;
-
-	while ((target = ast_channel_walk_locked(target))) {
-		if ((tmp = pbx_builtin_getvar_helper(target, PICKUPMARK)) &&
+	auto int find_by_mark(struct ast_channel *);
+	int find_by_mark(struct ast_channel *c) {
+		const char *tmp;
+		return (tmp = pbx_builtin_getvar_helper(c, PICKUPMARK)) &&
 			!strcasecmp(tmp, mark) &&
-			can_pickup(target)) {
-			res = pickup_do(chan, target);
-			ast_channel_unlock(target);
-			break;
-		}
+			can_pickup(c);
+	}	
+
+	struct ast_channel *target = ast_channel_search_locked(find_by_mark);
+
+	if (target) {
+		int res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-	}
-
-	return res;
+		target = NULL;
+		return res;
+	}
+
+	return -1;
 }
 
 /* application entry point for Pickup() */

Modified: team/group/issue8824/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/funcs/func_strings.c?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/funcs/func_strings.c (original)
+++ team/group/issue8824/funcs/func_strings.c Wed Nov  5 17:06:04 2008
@@ -39,6 +39,8 @@
 #include "asterisk/app.h"
 #include "asterisk/localtime.h"
 
+AST_THREADSTORAGE(result_buf);
+
 /*** DOCUMENTATION
 	<function name="FIELDQTY" language="en_US">
 		<synopsis>
@@ -50,6 +52,19 @@
 		</syntax>
 		<description>
 			<para>Example: ${FIELDQTY(ex-amp-le,-)} returns 3</para>
+		</description>
+	</function>
+	<function name="LISTFILTER" language="en_US">
+		<synopsis>Remove an item from a list, by name.</synopsis>
+		<syntax>
+			<parameter name="varname" required="true" />
+			<parameter name="delim" required="true" default="," />
+			<parameter name="value" required="true" />
+		</syntax>
+		<description>
+			<para>Remove <replaceable>value</replaceable> from the list contained in the <replaceable>varname</replaceable>
+			variable, where the list delimiter is specified by the <replaceable>delim</replaceable> parameter.  This is
+			very useful for removing a single channel name from a list of channels, for example.</para>
 		</description>
 	</function>
 	<function name="FILTER" language="en_US">
@@ -320,6 +335,105 @@
 static struct ast_custom_function fieldqty_function = {
 	.name = "FIELDQTY",
 	.read = function_fieldqty,
+};
+
+static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
+{
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(listname);
+		AST_APP_ARG(delimiter);
+		AST_APP_ARG(fieldvalue);
+	);
+	const char *orig_list, *ptr;
+	const char *begin, *cur, *next;
+	int dlen, flen;
+	struct ast_str *result = ast_str_thread_get(&result_buf, 16);
+	char *delim;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (args.argc < 3) {
+		ast_log(LOG_ERROR, "Usage: LISTFILTER(<listname>,<delimiter>,<fieldvalue>)\n");
+		return -1;
+	}
+
+	/* If we don't lock the channel, the variable could disappear out from underneath us. */
+	if (chan) {
+		ast_channel_lock(chan);
+	}
+	if (!(orig_list = pbx_builtin_getvar_helper(chan, args.listname))) {
+		ast_log(LOG_ERROR, "List variable '%s' not found\n", args.listname);
+		if (chan) {
+			ast_channel_unlock(chan);
+		}
+		return -1;
+	}
+
+	/* If the string isn't there, just copy out the string and be done with it. */
+	if (!(ptr = strstr(orig_list, args.fieldvalue))) {
+		ast_copy_string(buf, orig_list, len);
+		if (chan) {
+			ast_channel_unlock(chan);
+		}
+		return 0;
+	}
+
+	dlen = strlen(args.delimiter);
+	delim = alloca(dlen + 1);
+	ast_get_encoded_str(args.delimiter, delim, dlen + 1);
+
+	if ((dlen = strlen(delim)) == 0) {
+		delim = ",";
+		dlen = 1;
+	}
+
+	flen = strlen(args.fieldvalue);
+
+	ast_str_reset(result);
+	/* Enough space for any result */
+	ast_str_make_space(&result, strlen(orig_list) + 1);
+
+	begin = orig_list;
+	next = strstr(begin, delim);
+
+	do {
+		/* Find next boundary */
+		if (next) {
+			cur = next;
+			next = strstr(cur + dlen, delim);
+		} else {
+			cur = strchr(begin + dlen, '\0');
+		}
+
+		if (flen == cur - begin && !strncmp(begin, args.fieldvalue, flen)) {
+			/* Skip field */
+			begin += flen + dlen;
+		} else {
+			/* Copy field to output */
+			if (result->used) {
+				ast_str_append(&result, 0, "%s", delim);
+			}
+
+			/* Have to do it this way, since we're not null-terminated. */
+			strncpy(result->str + result->used, begin, cur - begin);
+			result->used += cur - begin;
+			result->str[result->used] = '\0';
+
+			begin = cur + dlen;
+		}
+	} while (*cur != '\0');
+	if (chan) {
+		ast_channel_unlock(chan);
+	}
+
+	ast_copy_string(buf, result->str, len);
+
+	return 0;
+}
+
+static struct ast_custom_function listfilter_function = {
+	.name = "LISTFILTER",
+	.read = listfilter,
 };
 
 static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf,
@@ -997,6 +1111,7 @@
 
 	res |= ast_custom_function_unregister(&fieldqty_function);
 	res |= ast_custom_function_unregister(&filter_function);
+	res |= ast_custom_function_unregister(&listfilter_function);
 	res |= ast_custom_function_unregister(&regex_function);
 	res |= ast_custom_function_unregister(&array_function);
 	res |= ast_custom_function_unregister(&quote_function);
@@ -1021,6 +1136,7 @@
 
 	res |= ast_custom_function_register(&fieldqty_function);
 	res |= ast_custom_function_register(&filter_function);
+	res |= ast_custom_function_register(&listfilter_function);
 	res |= ast_custom_function_register(&regex_function);
 	res |= ast_custom_function_register(&array_function);
 	res |= ast_custom_function_register(&quote_function);

Modified: team/group/issue8824/include/asterisk.h
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/include/asterisk.h?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/include/asterisk.h (original)
+++ team/group/issue8824/include/asterisk.h Wed Nov  5 17:06:04 2008
@@ -176,6 +176,14 @@
 struct ast_variable;
 struct ast_str;
 
+#ifdef bzero
+#undef bzero
+#endif
+
+#ifdef bcopy
+#undef bcopy
+#endif
+
 #define bzero  0x__dont_use_bzero__use_memset_instead""
 #define bcopy  0x__dont_use_bcopy__use_memmove_instead()
 

Modified: team/group/issue8824/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/include/asterisk/app.h?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/include/asterisk/app.h (original)
+++ team/group/issue8824/include/asterisk/app.h Wed Nov  5 17:06:04 2008
@@ -488,6 +488,9 @@
 /*! \brief Decode an encoded control or extended ASCII character */
 int ast_get_encoded_char(const char *stream, char *result, size_t *consumed);
 
+/*! \brief Decode a stream of encoded control or extended ASCII characters */
+int ast_get_encoded_str(const char *stream, char *result, size_t result_len);
+
 /*! \brief Common routine for child processes, to close all fds prior to exec(2) */
 void ast_close_fds_above_n(int n);
 

Modified: team/group/issue8824/main/app.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/main/app.c?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/main/app.c (original)
+++ team/group/issue8824/main/app.c Wed Nov  5 17:06:04 2008
@@ -1815,6 +1815,19 @@
 	return 0;
 }
 
+int ast_get_encoded_str(const char *stream, char *result, size_t result_size)
+{
+	char *cur = result;
+	size_t consumed;
+
+	while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) {
+		cur++;
+		stream += consumed;
+	}
+	*cur = '\0';
+	return 0;
+}
+
 void ast_close_fds_above_n(int n)
 {
 	int x, null;

Modified: team/group/issue8824/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/main/asterisk.c?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/main/asterisk.c (original)
+++ team/group/issue8824/main/asterisk.c Wed Nov  5 17:06:04 2008
@@ -1374,7 +1374,7 @@
 		if (niceness)
 			ast_module_shutdown();
 	}
-	if (ast_opt_console || ast_opt_remote) {
+	if (ast_opt_console || (ast_opt_remote && !ast_opt_exec)) {
 		if (getenv("HOME")) 
 			snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
 		if (!ast_strlen_zero(filename))
@@ -2474,17 +2474,6 @@
 		else 
 			printf("log and verbose output currently muted ('logger mute' to unmute)\n");
 	}
-	ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
-	remotehostname = hostname;
-	if (getenv("HOME")) 
-		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
-	if (el_hist == NULL || el == NULL)
-		ast_el_initialize();
-
-	el_set(el, EL_GETCFN, ast_el_read_char);
-
-	if (!ast_strlen_zero(filename))
-		ast_el_read_history(filename);
 
 	if (ast_opt_exec && data) {  /* hack to print output then exit if asterisk -rx is used */
 		struct pollfd fds;
@@ -2523,6 +2512,19 @@
 		}
 		return;
 	}
+
+	ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
+	remotehostname = hostname;
+	if (getenv("HOME")) 
+		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
+	if (el_hist == NULL || el == NULL)
+		ast_el_initialize();
+
+	el_set(el, EL_GETCFN, ast_el_read_char);
+
+	if (!ast_strlen_zero(filename))
+		ast_el_read_history(filename);
+
 	for (;;) {
 		ebuf = (char *)el_gets(el, &num);
 

Modified: team/group/issue8824/main/features.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/main/features.c?view=diff&rev=154961&r1=154960&r2=154961
==============================================================================
--- team/group/issue8824/main/features.c (original)
+++ team/group/issue8824/main/features.c Wed Nov  5 17:06:04 2008
@@ -4015,22 +4015,20 @@
 */
 int ast_pickup_call(struct ast_channel *chan)
 {
-	struct ast_channel *cur = NULL;
-	int res = -1;
-
-	while ((cur = ast_channel_walk_locked(cur)) != NULL) {
-		if (!cur->pbx && 
-			(cur != chan) &&
-			(chan->pickupgroup & cur->callgroup) &&
-			((cur->_state == AST_STATE_RINGING) ||
-			 (cur->_state == AST_STATE_RING))) {
-			 	break;
-		}
-		ast_channel_unlock(cur);
-	}
+	auto int find_channel_by_group(struct ast_channel *);
+	int find_channel_by_group(struct ast_channel *c) {
+		return !c->pbx &&
+			(c != chan) &&
+			(chan->pickupgroup & c->callgroup) &&
+			((c->_state == AST_STATE_RINGING) ||
+			 (c->_state == AST_STATE_RING));
+	}
+	struct ast_channel *cur = ast_channel_search_locked(find_channel_by_group);
+
 	if (cur) {
 		struct ast_party_connected_line connected_caller;
 
+		int res = -1;
 		ast_debug(1, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
 
 		connected_caller = cur->connected;
@@ -4051,10 +4049,11 @@
 		if (res)
 			ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);		/* Done */
 		ast_channel_unlock(cur);
+		return res;
 	} else	{
 		ast_debug(1, "No call pickup possible...\n");
 	}
-	return res;
+	return -1;
 }
 
 static char *app_bridge = "Bridge";




More information about the asterisk-commits mailing list