fix compilation warnings
[asterisk-bristuff.git] / funcs / func_md5.c
blobdb6be8f7bbb217c8b605eafd9e7ef9a76f73abbb
1 /*
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.
19 /*! \file
21 * \brief MD5 digest related dialplan functions
23 * \author Olle E. Johansson <oej@edvina.net>
24 * \author Russell Bryant <russelb@clemson.edu>
27 #include "asterisk.h"
29 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
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");
48 return -1;
51 ast_md5_hash(buf, data);
52 buf[32] = '\0';
54 return 0;
57 static int checkmd5(struct ast_channel *chan, char *cmd, char *parse,
58 char *buf, size_t len)
60 char newmd5[33];
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)) {
65 ast_log(LOG_WARNING,
66 "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
67 return -1;
70 AST_STANDARD_APP_ARGS(args, parse);
72 if (args.argc < 2) {
73 ast_log(LOG_WARNING,
74 "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
75 return -1;
78 if (!deprecated) {
79 deprecated = 1;
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);
87 else
88 ast_copy_string(buf, "0", len);
90 return 0;
93 static struct ast_custom_function md5_function = {
94 .name = "MD5",
95 .synopsis = "Computes an MD5 digest",
96 .syntax = "MD5(<data>)",
97 .read = md5,
100 static struct ast_custom_function checkmd5_function = {
101 .name = "CHECK_MD5",
102 .synopsis = "Checks an MD5 digest",
103 .desc = "Returns 1 on a match, 0 otherwise\n",
104 .syntax = "CHECK_MD5(<digest>,<data>)",
105 .read = checkmd5,
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");