Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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  <para>Example: Set(sha1hash=${SHA1(junky)})</para>
49  <para>Sets the asterisk variable sha1hash to the string <literal>60fa5675b9303eb62f99a9cd47f9f5837d18f9a0</literal>
50  which is known as his hash</para>
51  </description>
52  </function>
53  ***/
54 
55 static int sha1(struct ast_channel *chan, const char *cmd, char *data,
56  char *buf, size_t len)
57 {
58  *buf = '\0';
59 
60  if (ast_strlen_zero(data)) {
61  ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
62  return -1;
63  }
64 
65  if (len >= 41)
66  ast_sha1_hash(buf, data);
67  else {
69  "Insufficient space to produce SHA1 hash result (%d < 41)\n",
70  (int) len);
71  }
72 
73  return 0;
74 }
75 
77  .name = "SHA1",
78  .read = sha1,
79  .read_max = 42,
80 };
81 
82 static int unload_module(void)
83 {
84  return ast_custom_function_unregister(&sha1_function);
85 }
86 
87 static int load_module(void)
88 {
89  return ast_custom_function_register(&sha1_function);
90 }
91 
92 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");
const char * name
Definition: pbx.h:119
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
Asterisk main include file. File version handling, generic pbx functions.
static int sha1(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_sha1.c:55
static int unload_module(void)
Definition: func_sha1.c:82
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct ast_custom_function sha1_function
Definition: func_sha1.c:76
#define LOG_WARNING
Definition: logger.h:274
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
Core PBX routines and definitions.
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
Definition: main/utils.c:264
#define LOG_ERROR
Definition: logger.h:285
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int load_module(void)
Definition: func_sha1.c:87
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508