2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2005-2006, 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 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
34 #include <sys/types.h>
36 #include "asterisk/module.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/utils.h"
41 #include "asterisk/app.h"
43 static int md5(struct ast_channel
*chan
, char *cmd
, char *data
,
44 char *buf
, size_t len
)
46 if (ast_strlen_zero(data
)) {
47 ast_log(LOG_WARNING
, "Syntax: MD5(<data>) - missing argument!\n");
51 ast_md5_hash(buf
, data
);
57 static int checkmd5(struct ast_channel
*chan
, char *cmd
, char *parse
,
58 char *buf
, size_t len
)
61 static int deprecated
= 0;
62 AST_DECLARE_APP_ARGS(args
, AST_APP_ARG(digest
); AST_APP_ARG(data
););
64 if (ast_strlen_zero(parse
)) {
66 "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
70 AST_STANDARD_APP_ARGS(args
, parse
);
74 "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
80 ast_log(LOG_WARNING
, "CHECK_MD5() is deprecated in Asterisk 1.4 and later.\n");
83 ast_md5_hash(newmd5
, args
.data
);
85 if (!strcasecmp(newmd5
, args
.digest
)) /* they match */
86 ast_copy_string(buf
, "1", len
);
88 ast_copy_string(buf
, "0", len
);
93 static struct ast_custom_function md5_function
= {
95 .synopsis
= "Computes an MD5 digest",
96 .syntax
= "MD5(<data>)",
100 static struct ast_custom_function checkmd5_function
= {
102 .synopsis
= "Checks an MD5 digest",
103 .desc
= "Returns 1 on a match, 0 otherwise\n",
104 .syntax
= "CHECK_MD5(<digest>,<data>)",
108 static int unload_module(void)
110 return ast_custom_function_unregister(&md5_function
) |
111 ast_custom_function_unregister(&checkmd5_function
);
114 static int load_module(void)
116 return ast_custom_function_register(&md5_function
) |
117 ast_custom_function_register(&checkmd5_function
);
120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "MD5 digest dialplan functions");