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: 301848 $")
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
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 static int base64_encode(struct ast_channel *chan, const char *cmd, char *data,
00073 char *buf, size_t len)
00074 {
00075 if (ast_strlen_zero(data)) {
00076 ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
00077 return -1;
00078 }
00079
00080 ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
00081
00082 return 0;
00083 }
00084
00085 static int base64_decode(struct ast_channel *chan, const char *cmd, char *data,
00086 char *buf, size_t len)
00087 {
00088 int decoded_len;
00089
00090 if (ast_strlen_zero(data)) {
00091 ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
00092 return -1;
00093 }
00094
00095 decoded_len = ast_base64decode((unsigned char *) buf, data, len);
00096 if (decoded_len <= (len - 1)) {
00097 buf[decoded_len] = '\0';
00098 } else {
00099 buf[len - 1] = '\0';
00100 }
00101
00102 return 0;
00103 }
00104
00105 static struct ast_custom_function base64_encode_function = {
00106 .name = "BASE64_ENCODE",
00107 .read = base64_encode,
00108 };
00109
00110 static struct ast_custom_function base64_decode_function = {
00111 .name = "BASE64_DECODE",
00112 .read = base64_decode,
00113 };
00114
00115 static int unload_module(void)
00116 {
00117 return ast_custom_function_unregister(&base64_encode_function) |
00118 ast_custom_function_unregister(&base64_decode_function);
00119 }
00120
00121 static int load_module(void)
00122 {
00123 return ast_custom_function_register(&base64_encode_function) |
00124 ast_custom_function_register(&base64_decode_function);
00125 }
00126
00127 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "base64 encode/decode dialplan functions");