Go to the documentation of this file.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: 228649 $")
00028
00029 #include "asterisk/module.h"
00030 #include "asterisk/pbx.h"
00031 #include "asterisk/utils.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 static int base64_encode(struct ast_channel *chan, const char *cmd, char *data,
00063 char *buf, size_t len)
00064 {
00065 if (ast_strlen_zero(data)) {
00066 ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
00067 return -1;
00068 }
00069
00070 ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
00071
00072 return 0;
00073 }
00074
00075 static int base64_decode(struct ast_channel *chan, const char *cmd, char *data,
00076 char *buf, size_t len)
00077 {
00078 int decoded_len;
00079
00080 if (ast_strlen_zero(data)) {
00081 ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
00082 return -1;
00083 }
00084
00085 decoded_len = ast_base64decode((unsigned char *) buf, data, len);
00086 if (decoded_len <= (len - 1)) {
00087 buf[decoded_len] = '\0';
00088 } else {
00089 buf[len - 1] = '\0';
00090 }
00091
00092 return 0;
00093 }
00094
00095 static struct ast_custom_function base64_encode_function = {
00096 .name = "BASE64_ENCODE",
00097 .read = base64_encode,
00098 };
00099
00100 static struct ast_custom_function base64_decode_function = {
00101 .name = "BASE64_DECODE",
00102 .read = base64_decode,
00103 };
00104
00105 static int unload_module(void)
00106 {
00107 return ast_custom_function_unregister(&base64_encode_function) |
00108 ast_custom_function_unregister(&base64_decode_function);
00109 }
00110
00111 static int load_module(void)
00112 {
00113 return ast_custom_function_register(&base64_encode_function) |
00114 ast_custom_function_register(&base64_decode_function);
00115 }
00116
00117 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "base64 encode/decode dialplan functions");