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$")
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <sys/types.h>
00033
00034 #include "asterisk/module.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/utils.h"
00039 #include "asterisk/app.h"
00040
00041 static int base64_encode(struct ast_channel *chan, char *cmd, char *data,
00042 char *buf, size_t len)
00043 {
00044 if (ast_strlen_zero(data)) {
00045 ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
00046 return -1;
00047 }
00048
00049 ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
00050
00051 return 0;
00052 }
00053
00054 static int base64_decode(struct ast_channel *chan, char *cmd, char *data,
00055 char *buf, size_t len)
00056 {
00057 if (ast_strlen_zero(data)) {
00058 ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
00059 return -1;
00060 }
00061
00062 ast_base64decode((unsigned char *) buf, data, len);
00063
00064 return 0;
00065 }
00066
00067 static struct ast_custom_function base64_encode_function = {
00068 .name = "BASE64_ENCODE",
00069 .synopsis = "Encode a string in base64",
00070 .desc = "Returns the base64 string\n",
00071 .syntax = "BASE64_ENCODE(<string>)",
00072 .read = base64_encode,
00073 };
00074
00075 static struct ast_custom_function base64_decode_function = {
00076 .name = "BASE64_DECODE",
00077 .synopsis = "Decode a base64 string",
00078 .desc = "Returns the plain text string\n",
00079 .syntax = "BASE64_DECODE(<base64_string>)",
00080 .read = base64_decode,
00081 };
00082
00083 static int unload_module(void)
00084 {
00085 return ast_custom_function_unregister(&base64_encode_function) |
00086 ast_custom_function_unregister(&base64_decode_function);
00087 }
00088
00089 static int load_module(void)
00090 {
00091 return ast_custom_function_register(&base64_encode_function) |
00092 ast_custom_function_register(&base64_decode_function);
00093 }
00094
00095 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "base64 encode/decode dialplan functions");