mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
add MD5 and CHECK_MD5 functions, deprecate MD5 and MD5Check apps (bug #4123)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5567 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -48,6 +48,12 @@ static int md5_exec(struct ast_channel *chan, void *data)
|
||||
char *varname= NULL; /* Variable to set */
|
||||
char *string = NULL; /* String to calculate on */
|
||||
char retvar[50]; /* Return value */
|
||||
static int dep_warning = 0;
|
||||
|
||||
if (!dep_warning) {
|
||||
ast_log(LOG_WARNING, "This application has been deprecated, please use the MD5 function instead.\n");
|
||||
dep_warning = 1;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
ast_log(LOG_WARNING, "Syntax: md5(<varname>=<string>) - missing argument!\n");
|
||||
@@ -77,6 +83,12 @@ static int md5check_exec(struct ast_channel *chan, void *data)
|
||||
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 CHECK_MD5 function instead.\n");
|
||||
dep_warning = 1;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
ast_log(LOG_WARNING, "Syntax: MD5Check(<md5hash>,<string>) - missing argument!\n");
|
||||
|
62
pbx.c
62
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++) {
|
||||
|
Reference in New Issue
Block a user