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/channel.h"
31 #include "asterisk/pbx.h"
32 #include "asterisk/utils.h"
33 #include "asterisk/app.h"
35 static int base64_encode(struct ast_channel *chan, const char *cmd, char *data,
36 char *buf, size_t len)
38 if (ast_strlen_zero(data)) {
39 ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
43 ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
48 static int base64_decode(struct ast_channel *chan, const char *cmd, char *data,
49 char *buf, size_t len)
51 if (ast_strlen_zero(data)) {
52 ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
56 ast_base64decode((unsigned char *) buf, data, len);
61 static struct ast_custom_function base64_encode_function = {
62 .name = "BASE64_ENCODE",
63 .synopsis = "Encode a string in base64",
64 .desc = "Returns the base64 string\n",
65 .syntax = "BASE64_ENCODE(<string>)",
66 .read = base64_encode,
69 static struct ast_custom_function base64_decode_function = {
70 .name = "BASE64_DECODE",
71 .synopsis = "Decode a base64 string",
72 .desc = "Returns the plain text string\n",
73 .syntax = "BASE64_DECODE(<base64_string>)",
74 .read = base64_decode,
77 static int unload_module(void)
79 return ast_custom_function_unregister(&base64_encode_function) |
80 ast_custom_function_unregister(&base64_decode_function);
83 static int load_module(void)
85 return ast_custom_function_register(&base64_encode_function) |
86 ast_custom_function_register(&base64_decode_function);
89 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "base64 encode/decode dialplan functions");