Wed Jan 8 2020 09:49:47

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
34 
35 #include "asterisk/module.h"
36 #include "asterisk/pbx.h"
37 
38 /*** DOCUMENTATION
39  <function name="SHA1" language="en_US">
40  <synopsis>
41  Computes a SHA1 digest.
42  </synopsis>
43  <syntax>
44  <parameter name="data" required="true">
45  <para>Input string</para>
46  </parameter>
47  </syntax>
48  <description>
49  <para>Generate a SHA1 digest via the SHA1 algorythm.</para>
50  <para>Example: Set(sha1hash=${SHA1(junky)})</para>
51  <para>Sets the asterisk variable sha1hash to the string <literal>60fa5675b9303eb62f99a9cd47f9f5837d18f9a0</literal>
52  which is known as his hash</para>
53  </description>
54  </function>
55  ***/
56 
57 static 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 
84 static int unload_module(void)
85 {
86  return ast_custom_function_unregister(&sha1_function);
87 }
88 
89 static int load_module(void)
90 {
91  return ast_custom_function_register(&sha1_function);
92 }
93 
94 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
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:57
static int unload_module(void)
Definition: func_sha1.c:84
static struct ast_custom_function sha1_function
Definition: func_sha1.c:78
#define LOG_WARNING
Definition: logger.h:144
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
Core PBX routines and definitions.
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
Definition: utils.c:261
#define LOG_ERROR
Definition: logger.h:155
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int load_module(void)
Definition: func_sha1.c:89
const char * name
Definition: pbx.h:96
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180