Asterisk - The Open Source Telephony Project GIT-master-7e7a603
func_sha1.c
Go to the documentation of this file.
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
18/*! \file
19 *
20 * \brief SHA1 digest related dialplan functions
21 *
22 * \author Claude Patry <cpatry@gmail.com>
23 *
24 * \ingroup functions
25 */
26
27/*** MODULEINFO
28 <support_level>core</support_level>
29 ***/
30
31#include "asterisk.h"
32
33#include "asterisk/module.h"
34#include "asterisk/pbx.h"
35
36/*** DOCUMENTATION
37 <function name="SHA1" language="en_US">
38 <synopsis>
39 Computes a SHA1 digest.
40 </synopsis>
41 <syntax>
42 <parameter name="data" required="true">
43 <para>Input string</para>
44 </parameter>
45 </syntax>
46 <description>
47 <para>Generate a SHA1 digest via the SHA1 algorythm.</para>
48 <example title="Set sha1hash variable to SHA1 hash of junky">
49 exten => s,1,Set(sha1hash=${SHA1(junky)})
50 </example>
51 <para>The example above sets the asterisk variable sha1hash to the string <literal>60fa5675b9303eb62f99a9cd47f9f5837d18f9a0</literal>
52 which is known as its hash</para>
53 </description>
54 </function>
55 ***/
56
57static int sha1(struct ast_channel *chan, const char *cmd, char *data,
58 char *buf, size_t len)
59{
60 *buf = '\0';
61
62 if (ast_strlen_zero(data)) {
63 ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
64 return -1;
65 }
66
67 if (len >= 41)
68 ast_sha1_hash(buf, data);
69 else {
71 "Insufficient space to produce SHA1 hash result (%d < 41)\n",
72 (int) len);
73 }
74
75 return 0;
76}
77
79 .name = "SHA1",
80 .read = sha1,
81 .read_max = 42,
82};
83
84static int unload_module(void)
85{
87}
88
89static int load_module(void)
90{
92}
93
94AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int load_module(void)
Definition: func_sha1.c:89
static int unload_module(void)
Definition: func_sha1.c:84
static int sha1(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_sha1.c:57
static struct ast_custom_function sha1_function
Definition: func_sha1.c:78
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_ERROR
#define LOG_WARNING
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Core PBX routines and definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
Definition: utils.c:266