Asterisk - The Open Source Telephony Project  18.5.0
func_md5.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2005-2006, Digium, Inc.
5  * Copyright (C) 2005, Olle E. Johansson, Edvina.net
6  * Copyright (C) 2005, Russell Bryant <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief MD5 digest related dialplan functions
22  *
23  * \author Olle E. Johansson <[email protected]>
24  * \author Russell Bryant <[email protected]>
25  *
26  * \ingroup functions
27  */
28 
29 /*** MODULEINFO
30  <support_level>core</support_level>
31  ***/
32 
33 #include "asterisk.h"
34 
35 #include "asterisk/module.h"
36 #include "asterisk/pbx.h"
37 
38 /*** DOCUMENTATION
39  <function name="MD5" language="en_US">
40  <synopsis>
41  Computes an MD5 digest.
42  </synopsis>
43  <syntax>
44  <parameter name="data" required="true" />
45  </syntax>
46  <description>
47  <para>Computes an MD5 digest.</para>
48  </description>
49  </function>
50  ***/
51 
52 static int md5(struct ast_channel *chan, const char *cmd, char *data,
53  char *buf, size_t len)
54 {
55  if (ast_strlen_zero(data)) {
56  ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
57  return -1;
58  }
59 
60  ast_md5_hash(buf, data);
61  buf[32] = '\0';
62 
63  return 0;
64 }
65 
67  .name = "MD5",
68  .read = md5,
69  .read_max = 33,
70 };
71 
72 static int unload_module(void)
73 {
74  return ast_custom_function_unregister(&md5_function);
75 }
76 
77 static int load_module(void)
78 {
79  return ast_custom_function_register(&md5_function);
80 }
81 
82 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MD5 digest dialplan functions");
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.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int unload_module(void)
Definition: func_md5.c:72
#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
static int load_module(void)
Definition: func_md5.c:77
Core PBX routines and definitions.
static int md5(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_md5.c:52
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct ast_custom_function md5_function
Definition: func_md5.c:66
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
Definition: main/utils.c:248
#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