[asterisk-commits] rmudgett: branch rmudgett/cid r266283 - in /team/rmudgett/cid: funcs/ include...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 27 17:28:35 CDT 2010


Author: rmudgett
Date: Thu May 27 17:28:33 2010
New Revision: 266283

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

Also made handle parameters in a standard manner with the parameter
parsing support utilities.

Modified:
    team/rmudgett/cid/funcs/func_redirecting.c
    team/rmudgett/cid/include/asterisk/callerid.h
    team/rmudgett/cid/main/callerid.c

Modified: team/rmudgett/cid/funcs/func_redirecting.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/funcs/func_redirecting.c?view=diff&rev=266283&r1=266282&r2=266283
==============================================================================
--- team/rmudgett/cid/funcs/func_redirecting.c (original)
+++ team/rmudgett/cid/funcs/func_redirecting.c Thu May 27 17:28:33 2010
@@ -55,6 +55,14 @@
  * separate.  They represent two different parties and there is a case when
  * they are active at the same time.  The plain pres option will simply
  * live on as a historical relic.
+ *
+ * Do not document the REDIRECTING(from-pres) or REDIRECTING(to-pres) datatypes.
+ * The name and number now have their own presentation value.  The from-pres
+ * and to-pres options will simply live on as a historical relic with as best
+ * as can be managed backward compatible meaning.
+ *
+ * Do not document the REDIRECTING(from-ton) or REDIRECTING(to-ton) datatypes.
+ * They are aliases for from-num-plan and to-num-plan respectively.
  */
 /*** DOCUMENTATION
 	<function name="REDIRECTING" language="en_US">
@@ -66,17 +74,33 @@
 				<para>The allowable datatypes are:</para>
 				<enumlist>
 					<enum name = "from-all" />
+					<enum name = "from-name" />
+					<enum name = "from-name-valid" />
+					<enum name = "from-name-charset" />
+					<enum name = "from-name-pres" />
 					<enum name = "from-num" />
-					<enum name = "from-name" />
+					<enum name = "from-num-valid" />
+					<enum name = "from-num-plan" />
+					<enum name = "from-num-pres" />
+					<enum name = "from-subaddr" />
+					<enum name = "from-subaddr-valid" />
+					<enum name = "from-subaddr-type" />
+					<enum name = "from-subaddr-odd" />
 					<enum name = "from-tag" />
-					<enum name = "from-ton" />
-					<enum name = "from-pres" />
 					<enum name = "to-all" />
+					<enum name = "to-name" />
+					<enum name = "to-name-valid" />
+					<enum name = "to-name-charset" />
+					<enum name = "to-name-pres" />
 					<enum name = "to-num" />
-					<enum name = "to-name" />
+					<enum name = "to-num-valid" />
+					<enum name = "to-num-plan" />
+					<enum name = "to-num-pres" />
+					<enum name = "to-subaddr" />
+					<enum name = "to-subaddr-valid" />
+					<enum name = "to-subaddr-type" />
+					<enum name = "to-subaddr-odd" />
 					<enum name = "to-tag" />
-					<enum name = "to-ton" />
-					<enum name = "to-pres" />
 					<enum name = "reason" />
 					<enum name = "count" />
 				</enumlist>
@@ -87,8 +111,9 @@
 			</parameter>
 		</syntax>
 		<description>
-			<para>Gets or sets Redirecting data on the channel. The allowable values
-			for the <replaceable>reason</replaceable> field are the following:</para>
+			<para>Gets or sets Redirecting data on the channel.</para>
+			<para>The allowable values for the <replaceable>reason</replaceable>
+			field are the following:</para>
 			<enumlist>
 				<enum name = "unknown"><para>Unknown</para></enum>
 				<enum name = "cfb"><para>Call Forwarding Busy</para></enum>
@@ -103,6 +128,20 @@
 				<enum name = "cf_dte"><para>Call Forwarding By The Called DTE</para></enum>
 				<enum name = "cfu"><para>Call Forwarding Unconditional</para></enum>
 			</enumlist>
+			<para>The allowable values for the <replaceable>xxx-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>
  ***/
@@ -113,42 +152,195 @@
 	ID_FIELD_UNKNOWN
 };
 
-/*!
- * \internal
- * \brief Read values from the party id struct.
+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 */
+	);
+
+enum REDIRECTING_OPT_FLAGS {
+	REDIRECTING_OPT_INHIBIT = (1 << 0),
+};
+enum REDIRECTING_OPT_ARGS {
+	REDIRECTING_OPT_DUMMY,	/* Delete this if REDIRECTING ever gets an option with parameters. */
+
+	/* note: this entry _MUST_ be the last one in the enum */
+	REDIRECTING_OPT_ARG_ARRAY_SIZE
+};
+
+AST_APP_OPTIONS(redirecting_opts, BEGIN_OPTIONS
+	AST_APP_OPTION('i', REDIRECTING_OPT_INHIBIT),
+END_OPTIONS);
+
+/*!
+ * \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 data Remaining function datatype string
+ * \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 redirecting_id_read(char *buf, size_t len, char *data, const struct ast_party_id *id)
+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 (!strncasecmp("all", data, 3)) {
+	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 (!strncasecmp("name", data, 4)) {
-		if (id->XXX_name.valid && id->XXX_name.str) {
-			ast_copy_string(buf, id->XXX_name.str, len);
-		}
-	} else if (!strncasecmp("num", data, 3)) {
-		if (id->XXX_number.valid && id->XXX_number.str) {
-			ast_copy_string(buf, id->XXX_number.str, len);
-		}
-	} else if (!strncasecmp("tag", data, 3)) {
+	} 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 (!strncasecmp("ton", data, 3)) {
+	} 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 (!strncasecmp("pres", data, 4)) {
+	} 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 {
@@ -173,6 +365,10 @@
  */
 static int redirecting_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
+	struct ast_party_members member;
+	char *read_what;
+	enum ID_FIELD_STATUS status;
+
 	/* Ensure that the buffer is empty */
 	*buf = 0;
 
@@ -180,10 +376,19 @@
 		return -1;
 	}
 
+	read_what = ast_strdupa(data);
+	AST_NONSTANDARD_APP_ARGS(member, read_what, '-');
+	if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
+		/* Too few or too many subnames */
+		return -1;
+	}
+
 	ast_channel_lock(chan);
 
-	if (!strncasecmp("from-", data, 5)) {
-		switch (redirecting_id_read(buf, len, data + 5, &chan->redirecting.from)) {
+	if (!strcasecmp("from", member.argv[0])) {
+		status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
+			&chan->redirecting.from);
+		switch (status) {
 		case ID_FIELD_VALID:
 		case ID_FIELD_INVALID:
 			break;
@@ -191,8 +396,10 @@
 			ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
 			break;
 		}
-	} else if (!strncasecmp("to-", data, 3)) {
-		switch (redirecting_id_read(buf, len, data + 3, &chan->redirecting.to)) {
+	} else if (!strcasecmp("to", member.argv[0])) {
+		status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
+			&chan->redirecting.to);
+		switch (status) {
 		case ID_FIELD_VALID:
 		case ID_FIELD_INVALID:
 			break;
@@ -200,12 +407,17 @@
 			ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
 			break;
 		}
-	} else if (!strncasecmp("pres", data, 4)) {
+	} else if (!strncasecmp("pres", member.argv[0], 4)) {
+		/*
+		 * Accept pres[entation]
+		 * This is the combined from name/number presentation.
+		 */
 		ast_copy_string(buf,
-			ast_named_caller_presentation(ast_party_id_presentation(&chan->redirecting.from)), len);
-	} else if (!strncasecmp("reason", data, 6)) {
+			ast_named_caller_presentation(
+				ast_party_id_presentation(&chan->redirecting.from)), len);
+	} else if (!strcasecmp("reason", member.argv[0])) {
 		ast_copy_string(buf, ast_redirecting_reason_name(chan->redirecting.reason), len);
-	} else if (!strncasecmp("count", data, 5)) {
+	} else if (!strcasecmp("count", member.argv[0])) {
 		snprintf(buf, len, "%d", chan->redirecting.count);
 	} else {
 		ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
@@ -218,24 +430,208 @@
 
 /*!
  * \internal
- * \brief Write new values to the party id struct
- *
- * \param id Party ID struct to write values
- * \param data Remaining function datatype string
- * \param value Value to assign to the party id.
+ * \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 redirecting_id_write(struct ast_party_id *id, char *data, const char *value)
+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 (!strncasecmp("all", data, 3)) {
+	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];
 
@@ -250,41 +646,40 @@
 		if (!id->XXX_number.str) {
 			return ID_FIELD_INVALID;
 		}
-	} else if (!strncasecmp("name", data, 4)) {
-		id->XXX_name.valid = 1;
-		id->XXX_name.str = ast_strdup(value);
-		ast_trim_blanks(id->XXX_name.str);
-	} else if (!strncasecmp("num", data, 3)) {
-		id->XXX_number.valid = 1;
-		id->XXX_number.str = ast_strdup(value);
-		ast_trim_blanks(id->XXX_number.str);
-	} else if (!strncasecmp("tag", data, 3)) {
+	} 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 (!strncasecmp("ton", data, 3)) {
+	} 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')) {
-			id->XXX_number.plan = atoi(val);
-		} else {
-			ast_log(LOG_ERROR, "Unknown redirecting type of number '%s', value unchanged\n", val);
-			status = ID_FIELD_INVALID;
-		}
-	} else if (!strncasecmp("pres", data, 4)) {
-		int pres;
-
-		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 redirecting combined presentation '%s', value unchanged\n", val);
+			ast_log(LOG_ERROR,
+				"Unknown combined presentation '%s', value unchanged\n", val);
 			status = ID_FIELD_INVALID;
 		} else {
 			id->XXX_name.presentation = pres;
@@ -312,26 +707,40 @@
 static int redirecting_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
 	struct ast_party_redirecting redirecting;
+	enum ID_FIELD_STATUS status;
 	char *val;
-	char *option;
+	char *parms;
 	void (*set_it)(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
+	struct ast_party_func_args args;
+	struct ast_party_members member;
+	struct ast_flags opts;
+	char *opt_args[REDIRECTING_OPT_ARG_ARRAY_SIZE];
 
 	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;
+	}
+
+	if (ast_app_parse_options(redirecting_opts, &opts, opt_args, args.opts)) {
+		/* General invalid option syntax. */
+		return -1;
+	}
+
 	/* Determine if the update indication inhibit option is present */
-	option = strchr(data, ',');
-	if (option) {
-		option = ast_skip_blanks(option + 1);
-		switch (*option) {
-		case 'i':
-			set_it = ast_channel_set_redirecting;
-			break;
-		default:
-			ast_log(LOG_ERROR, "Unknown redirecting option '%s'.\n", option);
-			return 0;
-		}
+	if (ast_test_flag(&opts, REDIRECTING_OPT_INHIBIT)) {
+		set_it = ast_channel_set_redirecting;
 	} else {
 		set_it = ast_channel_update_redirecting;
 	}
@@ -342,8 +751,10 @@
 
 	value = ast_skip_blanks(value);
 
-	if (!strncasecmp("from-", data, 5)) {
-		switch (redirecting_id_write(&redirecting.from, data + 5, value)) {
+	if (!strcasecmp("from", member.argv[0])) {
+		status = party_id_write(&redirecting.from, member.argc - 1, member.argv + 1,
+			value);
+		switch (status) {
 		case ID_FIELD_VALID:
 			set_it(chan, &redirecting, NULL);
 			break;
@@ -354,8 +765,9 @@
 			break;
 		}
 		ast_party_redirecting_free(&redirecting);
-	} else if (!strncasecmp("to-", data, 3)) {
-		switch (redirecting_id_write(&redirecting.to, data + 3, value)) {
+	} else if (!strcasecmp("to", member.argv[0])) {
+		status = party_id_write(&redirecting.to, member.argc - 1, member.argv + 1, value);
+		switch (status) {
 		case ID_FIELD_VALID:
 			set_it(chan, &redirecting, NULL);
 			break;
@@ -366,7 +778,7 @@
 			break;
 		}
 		ast_party_redirecting_free(&redirecting);
-	} else if (!strncasecmp("pres", data, 4)) {
+	} else if (member.argc == 1 && !strncasecmp("pres", member.argv[0], 4)) {
 		int pres;
 
 		val = ast_strdupa(value);
@@ -379,7 +791,8 @@
 		}
 
 		if (pres < 0) {
-			ast_log(LOG_ERROR, "Unknown redirecting combined presentation '%s', value unchanged\n", val);
+			ast_log(LOG_ERROR,
+				"Unknown redirecting combined presentation '%s', value unchanged\n", val);
 		} else {
 			redirecting.from.XXX_name.presentation = pres;
 			redirecting.from.XXX_number.presentation = pres;
@@ -387,7 +800,7 @@
 			redirecting.to.XXX_number.presentation = pres;
 			set_it(chan, &redirecting, NULL);
 		}
-	} else if (!strncasecmp("reason", data, 6)) {
+	} else if (member.argc == 1 && !strcasecmp("reason", member.argv[0])) {
 		int reason;
 
 		val = ast_strdupa(value);
@@ -405,7 +818,7 @@
 			redirecting.reason = reason;
 			set_it(chan, &redirecting, NULL);
 		}
-	} else if (!strncasecmp("count", data, 5)) {
+	} else if (member.argc == 1 && !strcasecmp("count", member.argv[0])) {
 		val = ast_strdupa(value);
 		ast_trim_blanks(val);
 

Modified: team/rmudgett/cid/include/asterisk/callerid.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/include/asterisk/callerid.h?view=diff&rev=266283&r1=266282&r2=266283
==============================================================================
--- team/rmudgett/cid/include/asterisk/callerid.h (original)
+++ team/rmudgett/cid/include/asterisk/callerid.h Thu May 27 17:28:33 2010
@@ -475,5 +475,36 @@
  */
 const char *ast_connected_line_source_name(int data);
 
+/*!
+ * \since 1.8
+ * \brief Convert ast_party_name.char_set text code to value (used in config file parsing)
+ *
+ * \param data text string from config file
+ *
+ * \retval AST_PARTY_CHAR_SET from channel.h
+ * \retval -1 if not in table
+ */
+int ast_party_name_charset_parse(const char *data);
+
+/*!
+ * \since 1.8
+ * \brief Convert ast_party_name.char_set value to explanatory string
+ *
+ * \param data AST_PARTY_CHAR_SET from channel.h
+ *
+ * \return string for human presentation
+ */
+const char *ast_party_name_charset_describe(int data);
+
+/*!
+ * \since 1.8
+ * \brief Convert ast_party_name.char_set value to text code
+ *
+ * \param data AST_PARTY_CHAR_SET from channel.h
+ *
+ * \return string for config file
+ */
+const char *ast_party_name_charset_str(int data);
+
 
 #endif /* _ASTERISK_CALLERID_H */

Modified: team/rmudgett/cid/main/callerid.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/cid/main/callerid.c?view=diff&rev=266283&r1=266282&r2=266283
==============================================================================
--- team/rmudgett/cid/main/callerid.c (original)
+++ team/rmudgett/cid/main/callerid.c Thu May 27 17:28:33 2010
@@ -1282,3 +1282,58 @@
 
 	return "not-known";
 }
+
+/*! \brief Translation table for ast_party_name char-set settings */
+static const struct ast_value_translation party_name_charset_tbl[] = {
+/* *INDENT-OFF* */
+	{ AST_PARTY_CHAR_SET_UNKNOWN,               "unknown",      "Unknown" },
+	{ AST_PARTY_CHAR_SET_ISO8859_1,             "iso8859-1",    "ISO8859-1" },
+	{ AST_PARTY_CHAR_SET_WITHDRAWN,             "withdrawn",    "Withdrawn" },
+	{ AST_PARTY_CHAR_SET_ISO8859_2,             "iso8859-2",    "ISO8859-2" },
+	{ AST_PARTY_CHAR_SET_ISO8859_3,             "iso8859-3",    "ISO8859-3" },
+	{ AST_PARTY_CHAR_SET_ISO8859_4,             "iso8859-4",    "ISO8859-4" },
+	{ AST_PARTY_CHAR_SET_ISO8859_5,             "iso8859-5",    "ISO8859-5" },
+	{ AST_PARTY_CHAR_SET_ISO8859_7,             "iso8859-7",    "ISO8859-7" },
+	{ AST_PARTY_CHAR_SET_ISO10646_BMPSTRING,    "bmp",          "ISO10646 Bmp String" },
+	{ AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING,  "utf8",         "ISO10646 UTF-8 String" },
+/* *INDENT-ON* */
+};
+
+int ast_party_name_charset_parse(const char *data)
+{
+	int index;
+
+	for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
+		if (!strcasecmp(party_name_charset_tbl[index].name, data)) {
+			return party_name_charset_tbl[index].value;
+		}
+	}
+
+	return -1;
+}
+
+const char *ast_party_name_charset_describe(int data)
+{
+	int index;
+
+	for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
+		if (party_name_charset_tbl[index].value == data) {
+			return party_name_charset_tbl[index].description;
+		}
+	}
+
+	return "not-known";
+}
+
+const char *ast_party_name_charset_str(int data)
+{
+	int index;
+
+	for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
+		if (party_name_charset_tbl[index].value == data) {
+			return party_name_charset_tbl[index].name;
+		}
+	}
+
+	return "not-known";
+}




More information about the asterisk-commits mailing list