[asterisk-commits] rmudgett: branch rmudgett/cid r266387 - in /team/rmudgett/cid: ./ funcs/ incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 28 18:00:04 CDT 2010


Author: rmudgett
Date: Fri May 28 18:00:02 2010
New Revision: 266387

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=266387
Log:
Convert CALLERID() to support new party id fields.

* Made CALLERID() handle parameters in a standard manner with the
parameter parsing support utilities.

* CALLERPRES() is now deprecated because the name and number have their
own presentation values.

* Made ast_channel_set_caller_event() generate the NewCallerid event only
if the caller id name or number changed.

* Added ast_party_dialed_set_init() and ast_party_dialed_set().

Modified:
    team/rmudgett/cid/UPGRADE.txt
    team/rmudgett/cid/funcs/func_callerid.c
    team/rmudgett/cid/include/asterisk/channel.h
    team/rmudgett/cid/main/channel.c

Modified: team/rmudgett/cid/UPGRADE.txt
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/UPGRADE.txt?view=diff&rev=266387&r1=266386&r2=266387
==============================================================================
--- team/rmudgett/cid/UPGRADE.txt (original)
+++ team/rmudgett/cid/UPGRADE.txt Fri May 28 18:00:02 2010
@@ -81,6 +81,9 @@
 * VoiceMailMain and VMAuthenticate, if a '*' is entered in the first position
   of a Mailbox or Password, will, if it exists, jump to the 'a' extension in
   the current dialplan context.
+
+* The CALLERPRES() dialplan function is deprecated in favor of
+  CALLERID(num-pres) and CALLERID(name-pres).
 
 From 1.6.1 to 1.6.2:
 

Modified: team/rmudgett/cid/funcs/func_callerid.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/funcs/func_callerid.c?view=diff&rev=266387&r1=266386&r2=266387
==============================================================================
--- team/rmudgett/cid/funcs/func_callerid.c (original)
+++ team/rmudgett/cid/funcs/func_callerid.c Fri May 28 18:00:02 2010
@@ -32,6 +32,15 @@
 #include "asterisk/app.h"
 #include "asterisk/callerid.h"
 
+/*
+ * Do not document the CALLERID(pres) datatype.
+ * The name and number now have their own presentation value.  The pres
+ * option will simply live on as a historical relic with as best
+ * as can be managed backward compatible meaning.
+ *
+ * Do not document the CALLERID(ton) datatype.
+ * It is an alias for num-plan.
+ */
 /*** DOCUMENTATION
 	<function name="CALLERID" language="en_US">
 		<synopsis>
@@ -41,21 +50,28 @@
 			<parameter name="datatype" required="true">
 				<para>The allowable datatypes are:</para>
 				<enumlist>
-					<enum name="all" />
-					<enum name="num" />
-					<enum name="name" />
-					<enum name="tag" />
-					<enum name="ANI" />
-					<enum name="DNID" />
-					<enum name="RDNIS" />
-					<enum name="pres" />
-					<enum name="ton" />
-					<enum name="subaddr[-valid]|[-type]|[-odd]">
-						<para>ISDN Calling Subaddress</para>
-					</enum>
-					<enum name="dnid-subaddr[-valid]|[-type]|[-odd]">
-						<para>ISDN Called Subaddress</para>
-					</enum>
+					<enum name = "all" />
+					<enum name = "name" />
+					<enum name = "name-valid" />
+					<enum name = "name-charset" />
+					<enum name = "name-pres" />
+					<enum name = "num" />
+					<enum name = "num-valid" />
+					<enum name = "num-plan" />
+					<enum name = "num-pres" />
+					<enum name = "subaddr" />
+					<enum name = "subaddr-valid" />
+					<enum name = "subaddr-type" />
+					<enum name = "subaddr-odd" />
+					<enum name = "tag" />
+					<enum name = "ANI" />
+					<enum name = "RDNIS" />
+					<enum name = "DNID" />
+					<enum name = "dnid-num-plan" />
+					<enum name = "dnid-subaddr" />
+					<enum name = "dnid-subaddr-valid" />
+					<enum name = "dnid-subaddr-type" />
+					<enum name = "dnid-subaddr-odd" />
 				</enumlist>
 			</parameter>
 			<parameter name="CID">
@@ -63,8 +79,22 @@
 			</parameter>
 		</syntax>
 		<description>
-			<para>Gets or sets Caller*ID data on the channel. Uses channel callerid by default or optional
-			callerid, if specified.</para>
+			<para>Gets or sets Caller*ID data on the channel. Uses channel callerid by
+			default or optional callerid, if specified.</para>
+			<para>The allowable values for the <replaceable>name-charset</replaceable>
+			field are the following:</para>
+			<enumlist>
+				<enum name = "unknown"><para>Unknown</para></enum>
+				<enum name = "iso8859-1"><para>ISO8859-1</para></enum>
+				<enum name = "withdrawn"><para>Withdrawn</para></enum>
+				<enum name = "iso8859-2"><para>ISO8859-2</para></enum>
+				<enum name = "iso8859-3"><para>ISO8859-3</para></enum>
+				<enum name = "iso8859-4"><para>ISO8859-4</para></enum>
+				<enum name = "iso8859-5"><para>ISO8859-5</para></enum>
+				<enum name = "iso8859-7"><para>ISO8859-7</para></enum>
+				<enum name = "bmp"><para>ISO10646 Bmp String</para></enum>
+				<enum name = "utf8"><para>ISO10646 UTF-8 String</para></enum>
+			</enumlist>
 		</description>
 	</function>
 	<function name="CALLERPRES" language="en_US">
@@ -73,8 +103,10 @@
 		</synopsis>
 		<syntax />
 		<description>
-			<para>Gets or sets Caller*ID presentation on the channel. The following values
-			are valid:</para>
+			<para>Gets or sets Caller*ID presentation on the channel.
+			This function is deprecated in favor of CALLERID(num-pres)
+			and CALLERID(name-pres).
+			The following values are valid:</para>
 			<enumlist>
 				<enum name="allowed_not_screened">
 					<para>Presentation Allowed, Not Screened.</para>
@@ -108,8 +140,470 @@
 	</function>
  ***/
 
+enum ID_FIELD_STATUS {
+	ID_FIELD_VALID,
+	ID_FIELD_INVALID,
+	ID_FIELD_UNKNOWN
+};
+
+AST_DEFINE_APP_ARGS_TYPE(ast_party_func_args,
+	AST_APP_ARG(member);	/* Member name */
+	AST_APP_ARG(opts);		/* Options token */
+	AST_APP_ARG(other);		/* Any remining unused arguments */
+	);
+
+AST_DEFINE_APP_ARGS_TYPE(ast_party_members,
+	AST_APP_ARG(subnames[10]);	/* Option member subnames */
+	);
+
+/*!
+ * \internal
+ * \brief Read values from the party name struct.
+ * \since 1.8
+ *
+ * \param buf Buffer to fill with read value.
+ * \param len Length of the buffer.
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param name Party name to get values from.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_name_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_name *name)
+{
+	enum ID_FIELD_STATUS status;
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 0) {
+		/* We want the name string */
+		if (name->valid && name->str) {
+			ast_copy_string(buf, name->str, len);
+		}
+	} else if (argc == 1 && !strcasecmp("valid", argv[0])) {
+		snprintf(buf, len, "%d", name->valid);
+	} else if (argc == 1 && !strcasecmp("charset", argv[0])) {
+		ast_copy_string(buf, ast_party_name_charset_str(name->char_set), len);
+	} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
+		/* Accept pres[entation] */
+		ast_copy_string(buf, ast_named_caller_presentation(name->presentation), len);
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Read values from the party number struct.
+ * \since 1.8
+ *
+ * \param buf Buffer to fill with read value.
+ * \param len Length of the buffer.
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param number Party number to get values from.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_number_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_number *number)
+{
+	enum ID_FIELD_STATUS status;
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 0) {
+		/* We want the number string */
+		if (number->valid && number->str) {
+			ast_copy_string(buf, number->str, len);
+		}
+	} else if (argc == 1 && !strcasecmp("valid", argv[0])) {
+		snprintf(buf, len, "%d", number->valid);
+	} else if (argc == 1 && !strcasecmp("plan", argv[0])) {
+		snprintf(buf, len, "%d", number->plan);
+	} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
+		/* Accept pres[entation] */
+		ast_copy_string(buf, ast_named_caller_presentation(number->presentation), len);
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Read values from the party subaddress struct.
+ * \since 1.8
+ *
+ * \param buf Buffer to fill with read value.
+ * \param len Length of the buffer.
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param subaddress Party subaddress to get values from.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_subaddress_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_subaddress *subaddress)
+{
+	enum ID_FIELD_STATUS status;
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 0) {
+		/* We want the subaddress string */
+		if (subaddress->str) {
+			ast_copy_string(buf, subaddress->str, len);
+		}
+	} else if (argc == 1 && !strcasecmp("valid", argv[0])) {
+		snprintf(buf, len, "%d", subaddress->valid);
+	} else if (argc == 1 && !strcasecmp("type", argv[0])) {
+		snprintf(buf, len, "%d", subaddress->type);
+	} else if (argc == 1 && !strcasecmp("odd", argv[0])) {
+		snprintf(buf, len, "%d", subaddress->odd_even_indicator);
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Read values from the party id struct.
+ * \since 1.8
+ *
+ * \param buf Buffer to fill with read value.
+ * \param len Length of the buffer.
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param id Party id to get values from.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_id_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_id *id)
+{
+	enum ID_FIELD_STATUS status;
+
+	if (argc == 0) {
+		/* Must have at least one subname. */
+		return ID_FIELD_UNKNOWN;
+	}
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 1 && !strcasecmp("all", argv[0])) {
+		snprintf(buf, len, "\"%s\" <%s>",
+			 S_COR(id->XXX_name.valid, id->XXX_name.str, ""),
+			 S_COR(id->XXX_number.valid, id->XXX_number.str, ""));
+	} else if (!strcasecmp("name", argv[0])) {
+		status = party_name_read(buf, len, argc - 1, argv + 1, &id->XXX_name);
+	} else if (!strncasecmp("num", argv[0], 3)) {
+		/* Accept num[ber] */
+		status = party_number_read(buf, len, argc - 1, argv + 1, &id->XXX_number);
+	} else if (!strncasecmp("subaddr", argv[0], 7)) {
+		/* Accept subaddr[ess] */
+		status = party_subaddress_read(buf, len, argc - 1, argv + 1, &id->subaddress);
+	} else if (argc == 1 && !strcasecmp("tag", argv[0])) {
+		if (id->tag) {
+			ast_copy_string(buf, id->tag, len);
+		}
+	} else if (argc == 1 && !strcasecmp("ton", argv[0])) {
+		/* ton is an alias for num-plan */
+		snprintf(buf, len, "%d", id->XXX_number.plan);
+	} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
+		/*
+		 * Accept pres[entation]
+		 * This is the combined name/number presentation.
+		 */
+		ast_copy_string(buf,
+			ast_named_caller_presentation(ast_party_id_presentation(id)), len);
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Write new values to the party name struct
+ * \since 1.8
+ *
+ * \param name Party name struct to write values
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param value Value to assign to the party name.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_INVALID on error with field value.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_name_write(struct ast_party_name *name, int argc, char *argv[], const char *value)
+{
+	char *val;
+	enum ID_FIELD_STATUS status;
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 0) {
+		/* We are setting the name string */
+		name->valid = 1;
+		name->str = ast_strdup(value);
+		ast_trim_blanks(name->str);
+	} else if (argc == 1 && !strcasecmp("valid", argv[0])) {
+		name->valid = atoi(value) ? 1 : 0;
+	} else if (argc == 1 && !strcasecmp("charset", argv[0])) {
+		int char_set;
+
+		val = ast_strdupa(value);
+		ast_trim_blanks(val);
+
+		if (('0' <= val[0]) && (val[0] <= '9')) {
+			char_set = atoi(val);
+		} else {
+			char_set = ast_party_name_charset_parse(val);
+		}
+
+		if (char_set < 0) {
+			ast_log(LOG_ERROR,
+				"Unknown name char-set '%s', value unchanged\n", val);
+			status = ID_FIELD_INVALID;
+		} else {
+			name->char_set = char_set;
+		}
+	} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
+		int pres;
+
+		/* Accept pres[entation] */
+		val = ast_strdupa(value);
+		ast_trim_blanks(val);
+
+		if (('0' <= val[0]) && (val[0] <= '9')) {
+			pres = atoi(val);
+		} else {
+			pres = ast_parse_caller_presentation(val);
+		}
+
+		if (pres < 0) {
+			ast_log(LOG_ERROR,
+				"Unknown name presentation '%s', value unchanged\n", val);
+			status = ID_FIELD_INVALID;
+		} else {
+			name->presentation = pres;
+		}
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Write new values to the party number struct
+ * \since 1.8
+ *
+ * \param number Party number struct to write values
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param value Value to assign to the party number.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_INVALID on error with field value.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_number_write(struct ast_party_number *number, int argc, char *argv[], const char *value)
+{
+	char *val;
+	enum ID_FIELD_STATUS status;
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 0) {
+		/* We are setting the number string */
+		number->valid = 1;
+		number->str = ast_strdup(value);
+		ast_trim_blanks(number->str);
+	} else if (argc == 1 && !strcasecmp("valid", argv[0])) {
+		number->valid = atoi(value) ? 1 : 0;
+	} else if (argc == 1 && !strcasecmp("plan", argv[0])) {
+		val = ast_strdupa(value);
+		ast_trim_blanks(val);
+
+		if (('0' <= val[0]) && (val[0] <= '9')) {
+			number->plan = atoi(val);
+		} else {
+			ast_log(LOG_ERROR,
+				"Unknown type-of-number/numbering-plan '%s', value unchanged\n", val);
+			status = ID_FIELD_INVALID;
+		}
+	} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
+		int pres;
+
+		/* Accept pres[entation] */
+		val = ast_strdupa(value);
+		ast_trim_blanks(val);
+
+		if (('0' <= val[0]) && (val[0] <= '9')) {
+			pres = atoi(val);
+		} else {
+			pres = ast_parse_caller_presentation(val);
+		}
+
+		if (pres < 0) {
+			ast_log(LOG_ERROR,
+				"Unknown number presentation '%s', value unchanged\n", val);
+			status = ID_FIELD_INVALID;
+		} else {
+			number->presentation = pres;
+		}
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Write new values to the party subaddress struct
+ * \since 1.8
+ *
+ * \param subaddress Party subaddress struct to write values
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param value Value to assign to the party subaddress.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_INVALID on error with field value.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_subaddress_write(struct ast_party_subaddress *subaddress, int argc, char *argv[], const char *value)
+{
+	enum ID_FIELD_STATUS status;
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 0) {
+		/* We are setting the subaddress string */
+		subaddress->str = ast_strdup(value);
+		ast_trim_blanks(subaddress->str);
+	} else if (argc == 1 && !strcasecmp("valid", argv[0])) {
+		subaddress->valid = atoi(value) ? 1 : 0;
+	} else if (argc == 1 && !strcasecmp("type", argv[0])) {
+		subaddress->type = atoi(value) ? 2 : 0;
+	} else if (argc == 1 && !strcasecmp("odd", argv[0])) {
+		subaddress->odd_even_indicator = atoi(value) ? 1 : 0;
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*!
+ * \internal
+ * \brief Write new values to the party id struct
+ * \since 1.8
+ *
+ * \param id Party ID struct to write values
+ * \param argc Number of party member subnames.
+ * \param argv Party member subnames given.
+ * \param value Value to assign to the party id.
+ *
+ * \retval ID_FIELD_VALID on success.
+ * \retval ID_FIELD_INVALID on error with field value.
+ * \retval ID_FIELD_UNKNOWN on unknown field name.
+ */
+static enum ID_FIELD_STATUS party_id_write(struct ast_party_id *id, int argc, char *argv[], const char *value)
+{
+	char *val;
+	enum ID_FIELD_STATUS status;
+
+	if (argc == 0) {
+		/* Must have at least one subname. */
+		return ID_FIELD_UNKNOWN;
+	}
+
+	status = ID_FIELD_VALID;
+
+	if (argc == 1 && !strcasecmp("all", argv[0])) {
+		char name[256];
+		char num[256];
+
+		ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
+		id->XXX_name.valid = 1;
+		id->XXX_name.str = ast_strdup(name);
+		if (!id->XXX_name.str) {
+			return ID_FIELD_INVALID;
+		}
+		id->XXX_number.valid = 1;
+		id->XXX_number.str = ast_strdup(num);
+		if (!id->XXX_number.str) {
+			return ID_FIELD_INVALID;
+		}
+	} else if (!strcasecmp("name", argv[0])) {
+		status = party_name_write(&id->XXX_name, argc - 1, argv + 1, value);
+	} else if (!strncasecmp("num", argv[0], 3)) {
+		/* Accept num[ber] */
+		status = party_number_write(&id->XXX_number, argc - 1, argv + 1, value);
+	} else if (!strncasecmp("subaddr", argv[0], 7)) {
+		/* Accept subaddr[ess] */
+		status = party_subaddress_write(&id->subaddress, argc - 1, argv + 1, value);
+	} else if (argc == 1 && !strcasecmp("tag", argv[0])) {
+		id->tag = ast_strdup(value);
+		ast_trim_blanks(id->tag);
+	} else if (argc == 1 && !strcasecmp("ton", argv[0])) {
+		/* ton is an alias for num-plan */
+		argv[0] = "plan";
+		status = party_number_write(&id->XXX_number, argc, argv, value);
+	} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
+		int pres;
+
+		/*
+		 * Accept pres[entation]
+		 * This is the combined name/number presentation.
+		 */
+		val = ast_strdupa(value);
+		ast_trim_blanks(val);
+
+		if (('0' <= val[0]) && (val[0] <= '9')) {
+			pres = atoi(val);
+		} else {
+			pres = ast_parse_caller_presentation(val);
+		}
+
+		if (pres < 0) {
+			ast_log(LOG_ERROR,
+				"Unknown combined presentation '%s', value unchanged\n", val);
+			status = ID_FIELD_INVALID;
+		} else {
+			id->XXX_name.presentation = pres;
+			id->XXX_number.presentation = pres;
+		}
+	} else {
+		status = ID_FIELD_UNKNOWN;
+	}
+
+	return status;
+}
+
+/*! TRUE if we have already notified about CALLERPRES being deprecated. */
+static int callerpres_deprecate_notify;
+
 static int callerpres_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
+	if (!callerpres_deprecate_notify) {
+		callerpres_deprecate_notify = 1;
+		ast_log(LOG_WARNING, "CALLERPRES is deprecated."
+			"  Use CALLERID(name-pres) or CALLERID(num-pres) instead.\n");
+	}
 	ast_copy_string(buf,
 		ast_named_caller_presentation(ast_party_id_presentation(&chan->caller.id)), len);
 	return 0;
@@ -117,8 +611,15 @@
 
 static int callerpres_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
-	int pres = ast_parse_caller_presentation(value);
-
+	int pres;
+
+	if (!callerpres_deprecate_notify) {
+		callerpres_deprecate_notify = 1;
+		ast_log(LOG_WARNING, "CALLERPRES is deprecated."
+			"  Use CALLERID(name-pres) or CALLERID(num-pres) instead.\n");
+	}
+
+	pres = ast_parse_caller_presentation(value);
 	if (pres < 0) {
 		ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
 	} else {
@@ -130,26 +631,46 @@
 
 static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-	char *opt = data;
+	enum ID_FIELD_STATUS status;
+	char *parms;
+	struct ast_party_members member;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(member);	/* Member name */
+		AST_APP_ARG(cid);		/* Optional caller id to parse instead of from the channel. */
+		);
 
 	/* Ensure that the buffer is empty */
 	*buf = 0;
 
-	if (!chan)
+	if (!chan) {
 		return -1;
-
-	if (strchr(opt, ',')) {
-		char name[80], num[80];
-
-		data = strsep(&opt, ",");
-		ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));
-
-		if (!strncasecmp("all", data, 3)) {
+	}
+
+	parms = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parms);
+	if (args.argc == 0) {
+		/* Must have at least one argument. */
+		return -1;
+	}
+
+	AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
+	if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
+		/* Too few or too many subnames */
+		return -1;
+	}
+
+	if (args.argc == 2) {
+		char name[80];
+		char num[80];
+
+		ast_callerid_split(args.cid, name, sizeof(name), num, sizeof(num));
+
+		if (member.argc == 1 && !strcasecmp("all", member.argv[0])) {
 			snprintf(buf, len, "\"%s\" <%s>", name, num);
-		} else if (!strncasecmp("name", data, 4)) {
+		} else if (member.argc == 1 && !strcasecmp("name", member.argv[0])) {
 			ast_copy_string(buf, name, len);
-		} else if (!strncasecmp("num", data, 3)) {
-			/* also matches "number" */
+		} else if (member.argc == 1 && !strncasecmp("num", member.argv[0], 3)) {
+			/* Accept num[ber] */
 			ast_copy_string(buf, num, len);
 		} else {
 			ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
@@ -157,77 +678,67 @@
 	} else {
 		ast_channel_lock(chan);
 
-		if (!strncasecmp("all", data, 3)) {
-			snprintf(buf, len, "\"%s\" <%s>",
-				S_COR(chan->caller.id.XXX_name.valid, chan->caller.id.XXX_name.str, ""),
-				S_COR(chan->caller.id.XXX_number.valid, chan->caller.id.XXX_number.str, ""));
-		} else if (!strncasecmp("name", data, 4)) {
-			if (chan->caller.id.XXX_name.valid && chan->caller.id.XXX_name.str) {
-				ast_copy_string(buf, chan->caller.id.XXX_name.str, len);
+		if (member.argc == 1 && !strcasecmp("rdnis", member.argv[0])) {
+			if (chan->redirecting.from.XXX_number.valid
+				&& chan->redirecting.from.XXX_number.str) {
+				ast_copy_string(buf, chan->redirecting.from.XXX_number.str, len);
 			}
-		} else if (!strncasecmp("tag", data, 3)) {
-			if (chan->caller.id.tag) {
-				ast_copy_string(buf, chan->caller.id.tag, len);
+		} else if (!strcasecmp("dnid", member.argv[0])) {
+			if (member.argc == 1) {
+				/* Setup as if user had given dnid-num instead. */
+				member.argc = 2;
+				member.argv[1] = "num";
 			}
-		} else if (!strncasecmp("num", data, 3)) {
-			/* also matches "number" */
-			if (chan->caller.id.XXX_number.valid && chan->caller.id.XXX_number.str) {
-				ast_copy_string(buf, chan->caller.id.XXX_number.str, len);
+			if (!strncasecmp("num", member.argv[1], 3)) {
+				/*
+				 * Accept num[ber]
+				 * dnid-num...
+				 */
+				if (member.argc == 2) {
+					/* dnid-num */
+					if (chan->dialed.number.str) {
+						ast_copy_string(buf, chan->dialed.number.str, len);
+					}
+				} else if (member.argc == 3 && !strcasecmp("plan", member.argv[2])) {
+					/* dnid-num-plan */
+					snprintf(buf, len, "%d", chan->dialed.number.plan);
+				} else {
+					ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+				}
+			} else if (!strncasecmp("subaddr", member.argv[1], 7)) {
+				/*
+				 * Accept subaddr[ess]
+				 * dnid-subaddr...
+				 */
+				status = party_subaddress_read(buf, len, member.argc - 2, member.argv + 2,
+					&chan->dialed.subaddress);
+				switch (status) {
+				case ID_FIELD_VALID:
+				case ID_FIELD_INVALID:
+					break;
+				default:
+					ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+					break;
+				}
+			} else {
+				ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
 			}
-		} else if (!strncasecmp("ani", data, 3)) {
-			if (!strncasecmp(data + 3, "2", 1)) {
-				snprintf(buf, len, "%d", chan->caller.ani2);
-			} else if (chan->caller.ani) {
+		} else if (member.argc == 1 && !strcasecmp("ani2", member.argv[0])) {
+			snprintf(buf, len, "%d", chan->caller.ani2);
+		} else if (member.argc == 1 && !strcasecmp("ani", member.argv[0])) {
+			if (chan->caller.ani) {
 				ast_copy_string(buf, chan->caller.ani, len);
 			}
-		} else if (!strncasecmp("dnid", data, 4)) {
-			/* Called parties info */
-
-			/* also matches dnid-subaddr-valid, dnid-subaddr-type, dnid-subaddr-odd, dnid-subaddr */
-			if (!strncasecmp(data + 4 ,"-subaddr", 8)) {
-				if (!strncasecmp(data + 12 ,"-valid", 6)) {		/* dnid-subaddr-valid */
-					snprintf(buf, len, "%d", chan->dialed.subaddress.valid);
-				} else if (!strncasecmp(data + 12 ,"-type", 5)) {	/* dnid-subaddr-type */
-					snprintf(buf, len, "%d", chan->dialed.subaddress.type);
-				} else if (!strncasecmp(data + 12 ,"-odd", 4)) {	/* dnid-subaddr-odd */
-					snprintf(buf, len, "%d", chan->dialed.subaddress.odd_even_indicator);
-				} else {						/* dnid-subaddr */
-					if (chan->dialed.subaddress.str) {
-						ast_copy_string(buf, chan->dialed.subaddress.str, len);
-					}
-				}
-			} else {							/* dnid */
-				if (chan->dialed.number.str) {
-					ast_copy_string(buf, chan->dialed.number.str, len);
-				}
+		} else {
+			status = party_id_read(buf, len, member.argc, member.argv, &chan->caller.id);
+			switch (status) {
+			case ID_FIELD_VALID:
+			case ID_FIELD_INVALID:
+				break;
+			default:
+				ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+				break;
 			}
-		} else if (!strncasecmp("subaddr", data, 7)) {
-			/* Calling parties info */
-
-			/* also matches subaddr-valid, subaddr-type, subaddr-odd, subaddr */
-			if (!strncasecmp(data + 7 ,"-valid", 6)) {		/* subaddr-valid */
-				snprintf(buf, len, "%d", chan->caller.id.subaddress.valid);
-			} else if (!strncasecmp(data + 7 ,"-type", 5)) {	/* subaddr-type */
-				snprintf(buf, len, "%d", chan->caller.id.subaddress.type);
-			} else if (!strncasecmp(data + 7 ,"-odd", 4)) {		/* subaddr-odd */
-				snprintf(buf, len, "%d", chan->caller.id.subaddress.odd_even_indicator);
-			} else {						/* subaddr */
-				if (chan->caller.id.subaddress.str) {
-					ast_copy_string(buf, chan->caller.id.subaddress.str, len);
-				}
-			}
-		} else if (!strncasecmp("rdnis", data, 5)) {
-			if (chan->redirecting.from.XXX_number.valid && chan->redirecting.from.XXX_number.str) {
-				ast_copy_string(buf, chan->redirecting.from.XXX_number.str, len);
-			}
-		} else if (!strncasecmp("pres", data, 4)) {
-			ast_copy_string(buf,
-				ast_named_caller_presentation(ast_party_id_presentation(&chan->caller.id)),
-				len);
-		} else if (!strncasecmp("ton", data, 3)) {
-			snprintf(buf, len, "%d", chan->caller.id.XXX_number.plan);
-		} else {
-			ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
 		}
 
 		ast_channel_unlock(chan);
@@ -238,118 +749,142 @@
 
 static int callerid_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
-	if (!value || !chan)
+	struct ast_party_caller caller;
+	struct ast_party_dialed dialed;
+	enum ID_FIELD_STATUS status;
+	char *val;
+	char *parms;
+	struct ast_party_func_args args;
+	struct ast_party_members member;
+
+	if (!value || !chan) {
 		return -1;
+	}
+
+	parms = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parms);
+	if (args.argc == 0) {
+		/* Must have at least one argument. */
+		return -1;
+	}
+
+	AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
+	if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
+		/* Too few or too many subnames */
+		return -1;
+	}
 
 	value = ast_skip_blanks(value);
 
-	if (!strncasecmp("all", data, 3)) {
-		char name[256];
-		char num[256];
-
-		ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
-		ast_set_callerid(chan, num, name, num);
-		if (chan->cdr) {
-			ast_cdr_setcid(chan->cdr, chan);
-		}
-	} else if (!strncasecmp("name", data, 4)) {
-		ast_set_callerid(chan, NULL, value, NULL);
-		if (chan->cdr) {
-			ast_cdr_setcid(chan->cdr, chan);
-		}
-	} else if (!strncasecmp("num", data, 3)) {
-		/* also matches "number" */
-		ast_set_callerid(chan, value, NULL, NULL);
-		if (chan->cdr) {
-			ast_cdr_setcid(chan->cdr, chan);
-		}
-	} else if (!strncasecmp("tag", data, 3)) {
-		ast_channel_lock(chan);
-		ast_free(chan->caller.id.tag);
-		chan->caller.id.tag = ast_strdup(value);
-		ast_channel_unlock(chan);
-	} else if (!strncasecmp("ani", data, 3)) {
-		if (!strncasecmp(data + 3, "2", 1)) {
-			chan->caller.ani2 = atoi(value);
-		} else {
-			ast_set_callerid(chan, NULL, NULL, value);
-		}
-		if (chan->cdr) {
-			ast_cdr_setcid(chan->cdr, chan);
-		}
-	} else if (!strncasecmp("dnid", data, 4)) {
-		ast_channel_lock(chan);
-		/* also matches dnid-subaddr-valid, dnid-subaddr-type, dnid-subaddr-odd, dnid-subaddr */
-		if (!strncasecmp(data + 4 ,"-subaddr", 8)) {
-			if (!strncasecmp(data + 12 ,"-valid", 6)) {		/* dnid-subaddr-valid */
-				chan->dialed.subaddress.valid = atoi(value) ? 1 : 0;
-			} else if (!strncasecmp(data + 12 ,"-type", 5)) {	/* dnid-subaddr-type */
-				chan->dialed.subaddress.type = atoi(value) ? 2 : 0;
-			} else if (!strncasecmp(data + 12 ,"-odd", 4)) {	/* dnid-subaddr-odd */
-				chan->dialed.subaddress.odd_even_indicator = atoi(value) ? 1 : 0;
-			} else {						/* dnid-subaddr */
-				ast_free(chan->dialed.subaddress.str);
-				chan->dialed.subaddress.str = ast_strdup(value);
-			}
-		} else {							/* dnid */
-			ast_free(chan->dialed.number.str);
-			chan->dialed.number.str = ast_strdup(value);
-		}
-
-		if (chan->cdr) {
-			ast_cdr_setcid(chan->cdr, chan);
-		}
-		ast_channel_unlock(chan);
-	} else if (!strncasecmp("subaddr", data, 7)) {
-		ast_channel_lock(chan);
-		/* also matches subaddr-valid, subaddr-type, subaddr-odd, subaddr */
-		if (!strncasecmp(data + 7 ,"-valid", 6)) {		/* subaddr-valid */
-			chan->caller.id.subaddress.valid = atoi(value) ? 1 : 0;
-		} else if (!strncasecmp(data + 7 ,"-type", 5)) {	/* subaddr-type */
-			chan->caller.id.subaddress.type = atoi(value) ? 2 : 0;
-		} else if (!strncasecmp(data + 7 ,"-odd", 4)) {		/* subaddr-odd */
-			chan->caller.id.subaddress.odd_even_indicator = atoi(value) ? 1 : 0;
-		} else {						/* subaddr */
-			ast_free(chan->caller.id.subaddress.str);
-			chan->caller.id.subaddress.str = ast_strdup(value);
-		}
-		if (chan->cdr) {
-			ast_cdr_setcid(chan->cdr, chan);
-		}
-		ast_channel_unlock(chan);
-	} else if (!strncasecmp("rdnis", data, 5)) {
-		ast_channel_lock(chan);
+	ast_channel_lock(chan);
+	if (member.argc == 1 && !strcasecmp("rdnis", member.argv[0])) {
 		chan->redirecting.from.XXX_number.valid = 1;
 		ast_free(chan->redirecting.from.XXX_number.str);
 		chan->redirecting.from.XXX_number.str = ast_strdup(value);
 		if (chan->cdr) {
 			ast_cdr_setcid(chan->cdr, chan);
 		}
-		ast_channel_unlock(chan);
-	} else if (!strncasecmp("pres", data, 4)) {
-		int i;
-		char *val;
-
+	} else if (!strcasecmp("dnid", member.argv[0])) {
+		ast_party_dialed_set_init(&dialed, &chan->dialed);
+		if (member.argc == 1) {
+			/* Setup as if user had given dnid-num instead. */
+			member.argc = 2;
+			member.argv[1] = "num";
+		}
+		if (!strncasecmp("num", member.argv[1], 3)) {
+			/*
+			 * Accept num[ber]
+			 * dnid-num...
+			 */
+			if (member.argc == 2) {
+				/* dnid-num */
+				dialed.number.str = ast_strdup(value);
+				ast_trim_blanks(dialed.number.str);
+				ast_party_dialed_set(&chan->dialed, &dialed);
+				if (chan->cdr) {
+					ast_cdr_setcid(chan->cdr, chan);
+				}
+			} else if (member.argc == 3 && !strcasecmp("plan", member.argv[2])) {
+				/* dnid-num-plan */
+				val = ast_strdupa(value);
+				ast_trim_blanks(val);
+
+				if (('0' <= val[0]) && (val[0] <= '9')) {
+					chan->dialed.number.plan = atoi(val);
+					if (chan->cdr) {
+						ast_cdr_setcid(chan->cdr, chan);
+					}
+				} else {
+					ast_log(LOG_ERROR,
+						"Unknown type-of-number/numbering-plan '%s', value unchanged\n", val);
+				}
+			} else {
+				ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+			}
+		} else if (!strncasecmp("subaddr", member.argv[1], 7)) {
+			/*
+			 * Accept subaddr[ess]
+			 * dnid-subaddr...
+			 */
+			status = party_subaddress_write(&dialed.subaddress, member.argc, member.argv,
+				value);
+			switch (status) {
+			case ID_FIELD_VALID:
+				ast_party_dialed_set(&chan->dialed, &dialed);
+				if (chan->cdr) {
+					ast_cdr_setcid(chan->cdr, chan);
+				}
+				break;
+			case ID_FIELD_INVALID:
+				break;
+			default:
+				ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+				break;
+			}
+		} else {
+			ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+		}
+		ast_party_dialed_free(&dialed);
+	} else if (member.argc == 1 && !strcasecmp("ani2", member.argv[0])) {
 		val = ast_strdupa(value);
 		ast_trim_blanks(val);
 
-		if ((val[0] >= '0') && (val[0] <= '9')) {
-			i = atoi(val);
-		} else {
-			i = ast_parse_caller_presentation(val);
-		}
-
-		if (i < 0) {
-			ast_log(LOG_ERROR, "Unknown callerid combined presentation '%s', value unchanged\n", val);
-		} else {
-			chan->caller.id.XXX_name.presentation = i;
-			chan->caller.id.XXX_number.presentation = i;
-		}
-	} else if (!strncasecmp("ton", data, 3)) {
-		chan->caller.id.XXX_number.plan = atoi(value);
-	} else {
-		ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
-	}
+		if (('0' <= val[0]) && (val[0] <= '9')) {
+			chan->caller.ani2 = atoi(val);
+			if (chan->cdr) {
+				ast_cdr_setcid(chan->cdr, chan);
+			}
+		} else {
+			ast_log(LOG_ERROR, "Unknown callerid ani2 '%s', value unchanged\n", val);
+		}
+	} else if (member.argc == 1 && !strcasecmp("ani", member.argv[0])) {
+		ast_party_caller_set_init(&caller, &chan->caller);
+		caller.ani = ast_strdup(value);
+		ast_trim_blanks(caller.ani);
+		ast_party_caller_set(&chan->caller, &caller, NULL);
+		if (chan->cdr) {
+			ast_cdr_setcid(chan->cdr, chan);
+		}
+		ast_party_caller_free(&caller);
+	} else {
+		ast_party_caller_set_init(&caller, &chan->caller);
+		status = party_id_write(&caller.id, member.argc, member.argv, value);
+		switch (status) {
+		case ID_FIELD_VALID:
+			ast_channel_set_caller_event(chan, &caller, NULL);
+			if (chan->cdr) {
+				ast_cdr_setcid(chan->cdr, chan);
+			}
+			break;
+		case ID_FIELD_INVALID:
+			break;
+		default:
+			ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
+			break;
+		}
+		ast_party_caller_free(&caller);
+	}
+	ast_channel_unlock(chan);
 
 	return 0;
 }

Modified: team/rmudgett/cid/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/include/asterisk/channel.h?view=diff&rev=266387&r1=266386&r2=266387
==============================================================================
--- team/rmudgett/cid/include/asterisk/channel.h (original)
+++ team/rmudgett/cid/include/asterisk/channel.h Fri May 28 18:00:02 2010
@@ -1982,7 +1982,8 @@
 
 /*!
  * \since 1.8
- * \brief Set the caller id information in the Asterisk channel and generate AMI event.
+ * \brief Set the caller id information in the Asterisk channel and generate an AMI event
+ * if the caller id name or number changed.
  *
  * \param chan Asterisk channel to set caller id information
  * \param caller Caller id information
@@ -2761,6 +2762,39 @@
 
 /*!
  * \since 1.8
+ * \brief Initialize the given dialed structure using the given
+ * guide for a set update operation.
+ *
+ * \details
+ * The initialization is needed to allow a set operation to know if a
+ * value needs to be updated.  Simple integers need the guide's original
+ * value in case the set operation is not trying to set a new value.
+ * String values are simply set to NULL pointers if they are not going
+ * to be updated.
+ *
+ * \param init Caller structure to initialize.
+ * \param guide Source dialed to use as a guide in initializing.
+ *
+ * \return Nothing
+ */
+void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);
+
+/*!
+ * \since 1.8
+ * \brief Set the dialed information based on another dialed source
+ *
+ * This is similar to ast_party_dialed_copy, except that NULL values for
+ * strings in the src parameter indicate not to update the corresponding dest values.
+ *
+ * \param dest The dialed one wishes to update
+ * \param src The new dialed values to update the dest
+ *
+ * \return Nada
+ */
+void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
+
+/*!
+ * \since 1.8
  * \brief Destroy the dialed party contents
  *
  * \param doomed The dialed party to destroy.

Modified: team/rmudgett/cid/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/main/channel.c?view=diff&rev=266387&r1=266386&r2=266387
==============================================================================
--- team/rmudgett/cid/main/channel.c (original)
+++ team/rmudgett/cid/main/channel.c Fri May 28 18:00:02 2010
@@ -1892,6 +1892,27 @@
 	dest->number.str = ast_strdup(src->number.str);
 	dest->number.plan = src->number.plan;
 	ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);
+	dest->transit_network_select = src->transit_network_select;
+}
+
+void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide)
+{
+	init->number.str = NULL;
+	init->number.plan = guide->number.plan;
+	ast_party_subaddress_set_init(&init->subaddress, &guide->subaddress);
+	init->transit_network_select = guide->transit_network_select;
+}
+
+void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src)
+{
+	if (src->number.str && src->number.str != dest->number.str) {
+		ast_free(dest->number.str);
+		dest->number.str = ast_strdup(src->number.str);
+	}
+	dest->number.plan = src->number.plan;
+
+	ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
+
 	dest->transit_network_select = src->transit_network_select;
 }
 
@@ -5930,14 +5951,23 @@
 
 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 {
+	struct ast_party_caller pre_set;
+
 	if (&chan->caller == caller) {
 		/* Don't set to self */
 		return;
 	}
 
 	ast_channel_lock(chan);
+	pre_set = chan->caller;
 	ast_party_caller_set(&chan->caller, caller, update);
-	report_new_callerid(chan);
+	if (S_COR(pre_set.id.XXX_number.valid, pre_set.id.XXX_number.str, NULL)
+			!= S_COR(chan->caller.id.XXX_number.valid, chan->caller.id.XXX_number.str, NULL)
+		|| S_COR(pre_set.id.XXX_name.valid, pre_set.id.XXX_name.str, NULL)
+			!= S_COR(chan->caller.id.XXX_name.valid, chan->caller.id.XXX_name.str, NULL)) {
+		/* The caller id name or number changed. */
+		report_new_callerid(chan);
+	}
 	ast_channel_unlock(chan);
 }
 




More information about the asterisk-commits mailing list