2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2005 - 2006, Digium, Inc.
5 * Copyright (C) 2005, Claude Patry
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.
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.
20 * \brief Use the base64 as functions
27 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
29 #include "asterisk/module.h"
30 #include "asterisk/pbx.h" /* function register/unregister */
31 #include "asterisk/utils.h"
33 static int base64_encode(struct ast_channel
*chan
, const char *cmd
, char *data
,
34 char *buf
, size_t len
)
36 if (ast_strlen_zero(data
)) {
37 ast_log(LOG_WARNING
, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
41 ast_base64encode(buf
, (unsigned char *) data
, strlen(data
), len
);
46 static int base64_decode(struct ast_channel
*chan
, const char *cmd
, char *data
,
47 char *buf
, size_t len
)
49 if (ast_strlen_zero(data
)) {
50 ast_log(LOG_WARNING
, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
54 ast_base64decode((unsigned char *) buf
, data
, len
);
59 static struct ast_custom_function base64_encode_function
= {
60 .name
= "BASE64_ENCODE",
61 .synopsis
= "Encode a string in base64",
62 .desc
= "Returns the base64 string\n",
63 .syntax
= "BASE64_ENCODE(<string>)",
64 .read
= base64_encode
,
67 static struct ast_custom_function base64_decode_function
= {
68 .name
= "BASE64_DECODE",
69 .synopsis
= "Decode a base64 string",
70 .desc
= "Returns the plain text string\n",
71 .syntax
= "BASE64_DECODE(<base64_string>)",
72 .read
= base64_decode
,
75 static int unload_module(void)
77 return ast_custom_function_unregister(&base64_encode_function
) |
78 ast_custom_function_unregister(&base64_decode_function
);
81 static int load_module(void)
83 return ast_custom_function_register(&base64_encode_function
) |
84 ast_custom_function_register(&base64_decode_function
);
87 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "base64 encode/decode dialplan functions");