| 1 | /* |
| 2 | * Asterisk -- An open source telephony toolkit. |
| 3 | * |
| 4 | * Copyright (C) 2005-2006, Digium, Inc. |
| 5 | * Copyright (C) 2005, Olle E. Johansson, Edvina.net |
| 6 | * Copyright (C) 2005, Russell Bryant <[email protected]> |
| 7 | * |
| 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. |
| 13 | * |
| 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. |
| 17 | */ |
| 18 | |
| 19 | /*! \file |
| 20 | * |
| 21 | * \brief MD5 digest related dialplan functions |
| 22 | * |
| 23 | * \author Olle E. Johansson <[email protected]> |
| 24 | * \author Russell Bryant <[email protected]> |
| 25 | * |
| 26 | * \ingroup functions |
| 27 | */ |
| 28 | |
| 29 | /*** MODULEINFO |
| 30 | <support_level>core</support_level> |
| 31 | ***/ |
| 32 | |
| 33 | #include "asterisk.h" |
| 34 | |
| 35 | #include "asterisk/module.h" |
| 36 | #include "asterisk/pbx.h" |
| 37 | |
| 38 | /*** DOCUMENTATION |
| 39 | <function name="MD5" language="en_US"> |
| 40 | <since> |
| 41 | <version>1.2.0</version> |
| 42 | </since> |
| 43 | <synopsis> |
| 44 | Computes an MD5 digest. |
| 45 | </synopsis> |
| 46 | <syntax> |
| 47 | <parameter name="data" required="true" /> |
| 48 | </syntax> |
| 49 | <description> |
| 50 | <para>Computes an MD5 digest.</para> |
| 51 | </description> |
| 52 | </function> |
| 53 | ***/ |
| 54 | |
| 55 | static int md5(struct ast_channel *chan, const char *cmd, char *data, |
| 56 | char *buf, size_t len) |
| 57 | { |
| 58 | if (ast_strlen_zero(data)) { |
| 59 | ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n"); |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | ast_md5_hash(buf, data); |
| 64 | buf[32] = '\0'; |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static struct ast_custom_function md5_function = { |
| 70 | .name = "MD5", |
| 71 | .read = md5, |
| 72 | .read_max = 33, |
| 73 | }; |
| 74 | |
| 75 | static int unload_module(void) |
| 76 | { |
| 77 | return ast_custom_function_unregister(&md5_function); |
| 78 | } |
| 79 | |
| 80 | static int load_module(void) |
| 81 | { |
| 82 | return ast_custom_function_register(&md5_function); |
| 83 | } |
| 84 | |
| 85 | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MD5 digest dialplan functions"); |