2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2005, Digium, Inc.
5 * Copyright (C) 2005, Olle E. Johansson, Edvina.net
6 * Copyright (C) 2005, Russell Bryant <russelb@clemson.edu>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief MD5 digest related dialplan functions
23 * \author Olle E. Johansson <oej@edvina.net>
24 * \author Russell Bryant <russelb@clemson.edu>
29 #include <sys/types.h>
33 /* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/logger.h"
38 #include "asterisk/utils.h"
39 #include "asterisk/app.h"
41 static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
45 if (ast_strlen_zero(data)) {
46 ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
50 ast_md5_hash(md5, data);
51 ast_copy_string(buf, md5, len);
56 static char *builtin_function_checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
60 static int deprecated = 0;
61 AST_DECLARE_APP_ARGS(args,
66 if (ast_strlen_zero(data)) {
67 ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
71 if (!(parse = ast_strdupa(data)))
74 AST_STANDARD_APP_ARGS(args, parse);
77 ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
83 ast_log(LOG_WARNING, "CHECK_MD5() is deprecated in Asterisk 1.4 and later.\n");
86 ast_md5_hash(newmd5, args.data);
88 if (!strcasecmp(newmd5, args.digest) ) /* they match */
89 ast_copy_string(buf, "1", len);
91 ast_copy_string(buf, "0", len);
99 struct ast_custom_function md5_function = {
101 .synopsis = "Computes an MD5 digest",
102 .syntax = "MD5(<data>)",
103 .read = builtin_function_md5,
109 struct ast_custom_function checkmd5_function = {
111 .synopsis = "Checks an MD5 digest",
112 .desc = "Returns 1 on a match, 0 otherwise\n",
113 .syntax = "CHECK_MD5(<digest>,<data>)",
114 .read = builtin_function_checkmd5,