00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "asterisk.h"
00026
00027 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 228650 $")
00028
00029 #include "asterisk/module.h"
00030 #include "asterisk/pbx.h"
00031 #include "asterisk/utils.h"
00032
00033 static int base64_encode(struct ast_channel *chan, const char *cmd, char *data,
00034 char *buf, size_t len)
00035 {
00036 if (ast_strlen_zero(data)) {
00037 ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
00038 return -1;
00039 }
00040
00041 ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
00042
00043 return 0;
00044 }
00045
00046 static int base64_decode(struct ast_channel *chan, const char *cmd, char *data,
00047 char *buf, size_t len)
00048 {
00049 int decoded_len;
00050
00051 if (ast_strlen_zero(data)) {
00052 ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
00053 return -1;
00054 }
00055
00056 decoded_len = ast_base64decode((unsigned char *) buf, data, len);
00057 if (decoded_len <= (len - 1)) {
00058 buf[decoded_len] = '\0';
00059 } else {
00060 buf[len - 1] = '\0';
00061 }
00062
00063 return 0;
00064 }
00065
00066 static struct ast_custom_function base64_encode_function = {
00067 .name = "BASE64_ENCODE",
00068 .synopsis = "Encode a string in base64",
00069 .desc = "Returns the base64 string\n",
00070 .syntax = "BASE64_ENCODE(<string>)",
00071 .read = base64_encode,
00072 };
00073
00074 static struct ast_custom_function base64_decode_function = {
00075 .name = "BASE64_DECODE",
00076 .synopsis = "Decode a base64 string",
00077 .desc = "Returns the plain text string\n",
00078 .syntax = "BASE64_DECODE(<base64_string>)",
00079 .read = base64_decode,
00080 };
00081
00082 static int unload_module(void)
00083 {
00084 return ast_custom_function_unregister(&base64_encode_function) |
00085 ast_custom_function_unregister(&base64_decode_function);
00086 }
00087
00088 static int load_module(void)
00089 {
00090 return ast_custom_function_register(&base64_encode_function) |
00091 ast_custom_function_register(&base64_decode_function);
00092 }
00093
00094 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "base64 encode/decode dialplan functions");