func_sha1.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2006, Digium, Inc.
  5. * Copyright (C) 2006, Claude Patry
  6. *
  7. * See http://www.asterisk.org for more information about
  8. * the Asterisk project. Please do not directly contact
  9. * any of the maintainers of this project for assistance;
  10. * the project provides a web site, mailing lists and IRC
  11. * channels for your use.
  12. *
  13. * This program is free software, distributed under the terms of
  14. * the GNU General Public License Version 2. See the LICENSE file
  15. * at the top of the source tree.
  16. */
  17. /*! \file
  18. *
  19. * \brief SHA1 digest related dialplan functions
  20. *
  21. * \author Claude Patry <cpatry@gmail.com>
  22. *
  23. * \ingroup functions
  24. */
  25. #include "asterisk.h"
  26. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  27. #include "asterisk/module.h"
  28. #include "asterisk/pbx.h"
  29. static int sha1(struct ast_channel *chan, const char *cmd, char *data,
  30. char *buf, size_t len)
  31. {
  32. *buf = '\0';
  33. if (ast_strlen_zero(data)) {
  34. ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
  35. return -1;
  36. }
  37. if (len >= 41)
  38. ast_sha1_hash(buf, data);
  39. else {
  40. ast_log(LOG_ERROR,
  41. "Insufficient space to produce SHA1 hash result (%d < 41)\n",
  42. (int) len);
  43. }
  44. return 0;
  45. }
  46. static struct ast_custom_function sha1_function = {
  47. .name = "SHA1",
  48. .synopsis = "Computes a SHA1 digest",
  49. .syntax = "SHA1(<data>)",
  50. .read = sha1,
  51. .desc = "Generate a SHA1 digest via the SHA1 algorythm.\n"
  52. " Example: Set(sha1hash=${SHA1(junky)})\n"
  53. " Sets the asterisk variable sha1hash to the string '60fa5675b9303eb62f99a9cd47f9f5837d18f9a0'\n"
  54. " which is known as his hash\n",
  55. };
  56. static int unload_module(void)
  57. {
  58. return ast_custom_function_unregister(&sha1_function);
  59. }
  60. static int load_module(void)
  61. {
  62. return ast_custom_function_register(&sha1_function);
  63. }
  64. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");