fix compilation warnings
[asterisk-bristuff.git] / funcs / func_sha1.c
blob01c7eb02384f7e74dd60044c865fe1a884a07a94
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2006, Digium, Inc.
5 * Copyright (C) 2006, Claude Patry
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.
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.
18 /*! \file
20 * \brief SHA1 digest related dialplan functions
22 * \author Claude Patry <cpatry@gmail.com>
25 #include "asterisk.h"
27 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/types.h>
34 #include "asterisk/module.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/logger.h"
38 #include "asterisk/utils.h"
39 #include "asterisk/app.h"
41 static int sha1(struct ast_channel *chan, char *cmd, char *data,
42 char *buf, size_t len)
44 *buf = '\0';
46 if (ast_strlen_zero(data)) {
47 ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
48 return -1;
51 if (len >= 41)
52 ast_sha1_hash(buf, data);
53 else {
54 ast_log(LOG_ERROR,
55 "Insufficient space to produce SHA1 hash result (%d < 41)\n",
56 (int) len);
59 return 0;
62 static struct ast_custom_function sha1_function = {
63 .name = "SHA1",
64 .synopsis = "Computes a SHA1 digest",
65 .syntax = "SHA1(<data>)",
66 .read = sha1,
67 .desc = "Generate a SHA1 digest via the SHA1 algorythm.\n"
68 " Example: Set(sha1hash=${SHA1(junky)})\n"
69 " Sets the asterisk variable sha1hash to the string '60fa5675b9303eb62f99a9cd47f9f5837d18f9a0'\n"
70 " which is known as his hash\n",
73 static int unload_module(void)
75 return ast_custom_function_unregister(&sha1_function);
78 static int load_module(void)
80 return ast_custom_function_register(&sha1_function);
83 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");