func_md5.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/module.h"
  30. #include "asterisk/pbx.h"
  31. static int md5(struct ast_channel *chan, const char *cmd, char *data,
  32. char *buf, size_t len)
  33. {
  34. if (ast_strlen_zero(data)) {
  35. ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
  36. return -1;
  37. }
  38. ast_md5_hash(buf, data);
  39. buf[32] = '\0';
  40. return 0;
  41. }
  42. static struct ast_custom_function md5_function = {
  43. .name = "MD5",
  44. .synopsis = "Computes an MD5 digest",
  45. .syntax = "MD5(<data>)",
  46. .read = md5,
  47. };
  48. static int unload_module(void)
  49. {
  50. return ast_custom_function_unregister(&md5_function);
  51. }
  52. static int load_module(void)
  53. {
  54. return ast_custom_function_register(&md5_function);
  55. }
  56. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MD5 digest dialplan functions");