func_md5.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <russelb@clemson.edu>
  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. /*! \file
  19. *
  20. * \brief MD5 digest related dialplan functions
  21. *
  22. * \author Olle E. Johansson <oej@edvina.net>
  23. * \author Russell Bryant <russelb@clemson.edu>
  24. *
  25. * \ingroup functions
  26. */
  27. /*** MODULEINFO
  28. <support_level>core</support_level>
  29. ***/
  30. #include "asterisk.h"
  31. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  32. #include "asterisk/module.h"
  33. #include "asterisk/pbx.h"
  34. /*** DOCUMENTATION
  35. <function name="MD5" language="en_US">
  36. <synopsis>
  37. Computes an MD5 digest.
  38. </synopsis>
  39. <syntax>
  40. <parameter name="data" required="true" />
  41. </syntax>
  42. <description>
  43. <para>Computes an MD5 digest.</para>
  44. </description>
  45. </function>
  46. ***/
  47. static int md5(struct ast_channel *chan, const char *cmd, char *data,
  48. char *buf, size_t len)
  49. {
  50. if (ast_strlen_zero(data)) {
  51. ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
  52. return -1;
  53. }
  54. ast_md5_hash(buf, data);
  55. buf[32] = '\0';
  56. return 0;
  57. }
  58. static struct ast_custom_function md5_function = {
  59. .name = "MD5",
  60. .read = md5,
  61. .read_max = 33,
  62. };
  63. static int unload_module(void)
  64. {
  65. return ast_custom_function_unregister(&md5_function);
  66. }
  67. static int load_module(void)
  68. {
  69. return ast_custom_function_register(&md5_function);
  70. }
  71. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MD5 digest dialplan functions");