func_sha1.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /*** MODULEINFO
  26. <support_level>core</support_level>
  27. ***/
  28. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/module.h"
  31. #include "asterisk/pbx.h"
  32. /*** DOCUMENTATION
  33. <function name="SHA1" language="en_US">
  34. <synopsis>
  35. Computes a SHA1 digest.
  36. </synopsis>
  37. <syntax>
  38. <parameter name="data" required="true">
  39. <para>Input string</para>
  40. </parameter>
  41. </syntax>
  42. <description>
  43. <para>Generate a SHA1 digest via the SHA1 algorythm.</para>
  44. <para>Example: Set(sha1hash=${SHA1(junky)})</para>
  45. <para>Sets the asterisk variable sha1hash to the string <literal>60fa5675b9303eb62f99a9cd47f9f5837d18f9a0</literal>
  46. which is known as his hash</para>
  47. </description>
  48. </function>
  49. ***/
  50. static int sha1(struct ast_channel *chan, const char *cmd, char *data,
  51. char *buf, size_t len)
  52. {
  53. *buf = '\0';
  54. if (ast_strlen_zero(data)) {
  55. ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
  56. return -1;
  57. }
  58. if (len >= 41)
  59. ast_sha1_hash(buf, data);
  60. else {
  61. ast_log(LOG_ERROR,
  62. "Insufficient space to produce SHA1 hash result (%d < 41)\n",
  63. (int) len);
  64. }
  65. return 0;
  66. }
  67. static struct ast_custom_function sha1_function = {
  68. .name = "SHA1",
  69. .read = sha1,
  70. .read_max = 42,
  71. };
  72. static int unload_module(void)
  73. {
  74. return ast_custom_function_unregister(&sha1_function);
  75. }
  76. static int load_module(void)
  77. {
  78. return ast_custom_function_register(&sha1_function);
  79. }
  80. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");