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
26 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
31 #include <sys/types.h>
33 #include "asterisk/module.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/logger.h"
37 #include "asterisk/utils.h"
38 #include "asterisk/app.h"
40 static int base64_encode(struct ast_channel
*chan
, char *cmd
, char *data
,
41 char *buf
, size_t len
)
43 if (ast_strlen_zero(data
)) {
44 ast_log(LOG_WARNING
, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
48 ast_base64encode(buf
, (unsigned char *) data
, strlen(data
), len
);
53 static int base64_decode(struct ast_channel
*chan
, char *cmd
, char *data
,
54 char *buf
, size_t len
)
56 if (ast_strlen_zero(data
)) {
57 ast_log(LOG_WARNING
, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
61 ast_base64decode((unsigned char *) buf
, data
, len
);
66 static struct ast_custom_function base64_encode_function
= {
67 .name
= "BASE64_ENCODE",
68 .synopsis
= "Encode a string in base64",
69 .desc
= "Returns the base64 string\n",
70 .syntax
= "BASE64_ENCODE(<string>)",
71 .read
= base64_encode
,
74 static struct ast_custom_function base64_decode_function
= {
75 .name
= "BASE64_DECODE",
76 .synopsis
= "Decode a base64 string",
77 .desc
= "Returns the plain text string\n",
78 .syntax
= "BASE64_DECODE(<base64_string>)",
79 .read
= base64_decode
,
82 static int unload_module(void)
84 return ast_custom_function_unregister(&base64_encode_function
) |
85 ast_custom_function_unregister(&base64_decode_function
);
88 static int load_module(void)
90 return ast_custom_function_register(&base64_encode_function
) |
91 ast_custom_function_register(&base64_decode_function
);
94 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "base64 encode/decode dialplan functions");