[asterisk-commits] trunk r10113 - /trunk/funcs/func_strings.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Feb 14 17:59:02 MST 2006


Author: kpfleming
Date: Tue Feb 14 18:59:01 2006
New Revision: 10113

URL: http://svn.digium.com/view/asterisk?rev=10113&view=rev
Log:
add KEYPADHASH dialplan function (issue #6441)

Modified:
    trunk/funcs/func_strings.c

Modified: trunk/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_strings.c?rev=10113&r1=10112&r2=10113&view=diff
==============================================================================
--- trunk/funcs/func_strings.c (original)
+++ trunk/funcs/func_strings.c Tue Feb 14 18:59:01 2006
@@ -349,6 +349,49 @@
 	.read = function_eval,
 };
 
+static int keypadhash(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+	char *bufptr, *dataptr;
+
+	for (bufptr = buf, dataptr = data; bufptr < buf + len - 1; dataptr++) {
+		if (*dataptr == '1') {
+			*bufptr++ = '1';
+		} else if (strchr("AaBbCc2", *dataptr)) {
+			*bufptr++ = '2';
+		} else if (strchr("DdEeFf3", *dataptr)) {
+			*bufptr++ = '3';
+		} else if (strchr("GgHhIi4", *dataptr)) {
+			*bufptr++ = '4';
+		} else if (strchr("JjKkLl5", *dataptr)) {
+			*bufptr++ = '5';
+		} else if (strchr("MmNnOo6", *dataptr)) {
+			*bufptr++ = '6';
+		} else if (strchr("PpQqRrSs7", *dataptr)) {
+			*bufptr++ = '7';
+		} else if (strchr("TtUuVv8", *dataptr)) {
+			*bufptr++ = '8';
+		} else if (strchr("WwXxYyZz9", *dataptr)) {
+			*bufptr++ = '9';
+		} else if (*dataptr == '0') {
+			*bufptr++ = '0';
+		} else if (*dataptr == '\0') {
+			*bufptr++ = '\0';
+			break;
+		}
+	}
+	buf[len - 1] = '\0';
+
+	return 0;
+}
+
+static struct ast_custom_function keypadhash_function = {
+	.name = "KEYPADHASH",
+	.synopsis = "Hash the letters in the string into the equivalent keypad numbers.",
+	.syntax = "KEYPADHASH(<string>)",
+	.read = keypadhash,
+	.desc = "Example:  ${KEYPADHASH(Les)} returns \"537\"\n",
+};
+
 static char *tdesc = "String handling dialplan functions";
 
 int unload_module(void)
@@ -363,6 +406,7 @@
 	res |= ast_custom_function_unregister(&strftime_function);
 	res |= ast_custom_function_unregister(&strptime_function);
 	res |= ast_custom_function_unregister(&eval_function);
+	res |= ast_custom_function_unregister(&keypadhash_function);
 
 	return res;
 }
@@ -379,6 +423,7 @@
 	res |= ast_custom_function_register(&strftime_function);
 	res |= ast_custom_function_register(&strptime_function);
 	res |= ast_custom_function_register(&eval_function);
+	res |= ast_custom_function_register(&keypadhash_function);
 
 	return res;
 }



More information about the asterisk-commits mailing list