Index: pbx.c =================================================================== RCS file: /usr/cvsroot/asterisk/pbx.c,v retrieving revision 1.235 diff -u -r1.235 pbx.c --- pbx.c 1 May 2005 23:09:28 -0000 1.235 +++ pbx.c 2 May 2005 19:09:09 -0000 @@ -1370,6 +1370,50 @@ return ret; } +static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + char md5[50] = ""; + + if (!data || ast_strlen_zero(data)) { + ast_log(LOG_WARNING, "Syntax: MD5() - missing argument!\n"); + } else { + ast_md5_hash(md5, data); + ast_copy_string(buf, md5, len - 1); + } + + 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 = NULL; + char *oldmd5 = NULL; + char *string = NULL; + char newmd5[50] = ""; + + args = ast_strdupa(data); + argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])); + + if (argc > 1) { + oldmd5 = argv[0]; + string = argv[1]; + } else { + ast_log(LOG_WARNING, "Syntax: CheckMD5(,) - missing argument!\n"); + return buf; + } + + ast_md5_hash(newmd5, string); + + if (!strcmp(newmd5, oldmd5)) /* they match */ + ast_copy_string(buf, "1", len - 1); + else + ast_copy_string(buf, "0", len - 1); + + 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 +3598,21 @@ .write = builtin_function_cdr_write, }; +static struct ast_custom_function_obj md5_function = { + .name = "MD5", + .desc = "Computes an MD5 checksum", + .syntax = "md5()", + .read = builtin_function_md5, + .write = NULL, +}; + +static struct ast_custom_function_obj checkmd5_function = { + .name = "CheckMD5", + .desc = "Checks an MD5 checksum. Returns 1 on a match, 0 otherwise", + .syntax = "CheckMD5(,)", + .read = builtin_function_checkmd5, + .write = NULL, +}; /* * CLI entries for upper commands ... @@ -6000,6 +6059,8 @@ 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=) - missing argument!\n"); @@ -77,7 +83,13 @@ char *hash= NULL; /* Hash to compare with */ char *string = NULL; /* String to calculate on */ char newhash[50]; /* Return value */ + static int dep_warning = 0; + if (!dep_warning) { + ast_log(LOG_WARNING, "This application has been deprecated, please use the CheckMD5 function instead.\n"); + dep_warning = 1; + } + if (!data) { ast_log(LOG_WARNING, "Syntax: MD5Check(,) - missing argument!\n"); return -1;