Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 <since>
39 <version>1.4.0</version>
40 </since>
41 <synopsis>
42 Computes a SHA1 digest.
43 </synopsis>
44 <syntax>
45 <parameter name="data" required="true">
46 <para>Input string</para>
47 </parameter>
48 </syntax>
49 <description>
50 <para>Generate a SHA1 digest via the SHA1 algorythm.</para>
51 <example title="Set sha1hash variable to SHA1 hash of junky">
52 exten => s,1,Set(sha1hash=${SHA1(junky)})
53 </example>
54 <para>The example above sets the asterisk variable sha1hash to the string <literal>60fa5675b9303eb62f99a9cd47f9f5837d18f9a0</literal>
55 which is known as its hash</para>
56 </description>
57 </function>
58 ***/
59
60static int sha1(struct ast_channel *chan, const char *cmd, char *data,
61 char *buf, size_t len)
62{
63 *buf = '\0';
64
65 if (ast_strlen_zero(data)) {
66 ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
67 return -1;
68 }
69
70 if (len >= 41)
71 ast_sha1_hash(buf, data);
72 else {
74 "Insufficient space to produce SHA1 hash result (%d < 41)\n",
75 (int) len);
76 }
77
78 return 0;
79}
80
82 .name = "SHA1",
83 .read = sha1,
84 .read_max = 42,
85};
86
87static int unload_module(void)
88{
90}
91
92static int load_module(void)
93{
95}
96
97AST_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:92
static int unload_module(void)
Definition: func_sha1.c:87
static int sha1(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_sha1.c:60
static struct ast_custom_function sha1_function
Definition: func_sha1.c:81
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:581
#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:1559
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