00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "asterisk.h"
00028
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00030
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <sys/types.h>
00035
00036 #include "asterisk/module.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/utils.h"
00041 #include "asterisk/app.h"
00042
00043 static int sha1(struct ast_channel *chan, char *cmd, char *data,
00044 char *buf, size_t len)
00045 {
00046 *buf = '\0';
00047
00048 if (ast_strlen_zero(data)) {
00049 ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
00050 return -1;
00051 }
00052
00053 if (len >= 41)
00054 ast_sha1_hash(buf, data);
00055 else {
00056 ast_log(LOG_ERROR,
00057 "Insufficient space to produce SHA1 hash result (%d < 41)\n",
00058 (int) len);
00059 }
00060
00061 return 0;
00062 }
00063
00064 static struct ast_custom_function sha1_function = {
00065 .name = "SHA1",
00066 .synopsis = "Computes a SHA1 digest",
00067 .syntax = "SHA1(<data>)",
00068 .read = sha1,
00069 .desc = "Generate a SHA1 digest via the SHA1 algorythm.\n"
00070 " Example: Set(sha1hash=${SHA1(junky)})\n"
00071 " Sets the asterisk variable sha1hash to the string '60fa5675b9303eb62f99a9cd47f9f5837d18f9a0'\n"
00072 " which is known as his hash\n",
00073 };
00074
00075 static int unload_module(void)
00076 {
00077 return ast_custom_function_unregister(&sha1_function);
00078 }
00079
00080 static int load_module(void)
00081 {
00082 return ast_custom_function_register(&sha1_function);
00083 }
00084
00085 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");