aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-04 04:05:34 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-04 04:05:34 +0000
commitce9a0b7459733b1c74d196f6076fdd77858596a9 (patch)
treeef383426d6a691d67f95b3285a996b13754ccd21 /pbx.c
parent1d2cc0bca445bdfd8a45920b6f52553215ca5414 (diff)
add MD5 and CHECK_MD5 functions, deprecate MD5 and MD5Check apps (bug #4123)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5567 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rwxr-xr-xpbx.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/pbx.c b/pbx.c
index bf9db3d0a..311ab075f 100755
--- a/pbx.c
+++ b/pbx.c
@@ -1370,6 +1370,51 @@ static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *d
return ret;
}
+static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ char md5[33];
+
+ if (!data || ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
+ return NULL;
+ }
+
+ ast_md5_hash(md5, data);
+ ast_copy_string(buf, md5, len);
+
+ return buf;
+}
+
+static char *builtin_function_checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ int argc;
+ char *argv[2];
+ char *args;
+ char newmd5[33];
+
+ if (!data || ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
+ return NULL;
+ }
+
+ args = ast_strdupa(data);
+ argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0]));
+
+ if (argc < 2) {
+ ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
+ return NULL;
+ }
+
+ ast_md5_hash(newmd5, argv[1]);
+
+ if (!strcasecmp(newmd5, argv[0])) /* they match */
+ ast_copy_string(buf, "1", len);
+ else
+ ast_copy_string(buf, "0", len);
+
+ return buf;
+}
+
static void pbx_substitute_variables_helper_full(struct ast_channel *c, const char *cp1, char *cp2, int count, struct varshead *headp)
{
char *cp4;
@@ -3554,6 +3599,21 @@ static struct ast_custom_function_obj cdr_function = {
.write = builtin_function_cdr_write,
};
+static struct ast_custom_function_obj md5_function = {
+ .name = "MD5",
+ .desc = "Computes an MD5 digest",
+ .syntax = "MD5(<data>)",
+ .read = builtin_function_md5,
+ .write = NULL,
+};
+
+static struct ast_custom_function_obj checkmd5_function = {
+ .name = "CHECK_MD5",
+ .desc = "Checks an MD5 digest. Returns 1 on a match, 0 otherwise",
+ .syntax = "CHECK_MD5(<digest>,<data>)",
+ .read = builtin_function_checkmd5,
+ .write = NULL,
+};
/*
* CLI entries for upper commands ...
@@ -6000,6 +6060,8 @@ int load_pbx(void)
ast_custom_function_register(&env_function);
ast_custom_function_register(&len_function);
ast_custom_function_register(&cdr_function);
+ ast_custom_function_register(&md5_function);
+ ast_custom_function_register(&checkmd5_function);
/* Register builtin applications */
for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {