func_md5.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include "asterisk/module.h"
  32. #include "asterisk/pbx.h"
  33. /*** DOCUMENTATION
  34. <function name="MD5" language="en_US">
  35. <synopsis>
  36. Computes an MD5 digest.
  37. </synopsis>
  38. <syntax>
  39. <parameter name="data" required="true" />
  40. </syntax>
  41. <description>
  42. <para>Computes an MD5 digest.</para>
  43. </description>
  44. </function>
  45. ***/
  46. static int md5(struct ast_channel *chan, const char *cmd, char *data,
  47. char *buf, size_t len)
  48. {
  49. if (ast_strlen_zero(data)) {
  50. ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
  51. return -1;
  52. }
  53. ast_md5_hash(buf, data);
  54. buf[32] = '\0';
  55. return 0;
  56. }
  57. static struct ast_custom_function md5_function = {
  58. .name = "MD5",
  59. .read = md5,
  60. .read_max = 33,
  61. };
  62. static int unload_module(void)
  63. {
  64. return ast_custom_function_unregister(&md5_function);
  65. }
  66. static int load_module(void)
  67. {
  68. return ast_custom_function_register(&md5_function);
  69. }
  70. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MD5 digest dialplan functions");