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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "asterisk.h"
00036
00037 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00038
00039 #include "asterisk/module.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/utils.h"
00043 #include "asterisk/app.h"
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
00073
00074
00075 static int uriencode(struct ast_channel *chan, const char *cmd, char *data,
00076 char *buf, size_t len)
00077 {
00078 if (ast_strlen_zero(data)) {
00079 ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n");
00080 return -1;
00081 }
00082
00083 ast_uri_encode(data, buf, len, 1);
00084
00085 return 0;
00086 }
00087
00088
00089 static int uridecode(struct ast_channel *chan, const char *cmd, char *data,
00090 char *buf, size_t len)
00091 {
00092 if (ast_strlen_zero(data)) {
00093 ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
00094 return -1;
00095 }
00096
00097 ast_copy_string(buf, data, len);
00098 ast_uri_decode(buf);
00099
00100 return 0;
00101 }
00102
00103 static struct ast_custom_function urldecode_function = {
00104 .name = "URIDECODE",
00105 .read = uridecode,
00106 };
00107
00108 static struct ast_custom_function urlencode_function = {
00109 .name = "URIENCODE",
00110 .read = uriencode,
00111 };
00112
00113 static int unload_module(void)
00114 {
00115 return ast_custom_function_unregister(&urldecode_function)
00116 || ast_custom_function_unregister(&urlencode_function);
00117 }
00118
00119 static int load_module(void)
00120 {
00121 return ast_custom_function_register(&urldecode_function)
00122 || ast_custom_function_register(&urlencode_function);
00123 }
00124
00125 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions");