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 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00034
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <sys/types.h>
00039
00040 #include "asterisk/module.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/logger.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/app.h"
00046
00047
00048 static int uriencode(struct ast_channel *chan, char *cmd, char *data,
00049 char *buf, size_t len)
00050 {
00051 if (ast_strlen_zero(data)) {
00052 ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n");
00053 return -1;
00054 }
00055
00056 ast_uri_encode(data, buf, len, 1);
00057
00058 return 0;
00059 }
00060
00061
00062 static int uridecode(struct ast_channel *chan, char *cmd, char *data,
00063 char *buf, size_t len)
00064 {
00065 if (ast_strlen_zero(data)) {
00066 ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
00067 return -1;
00068 }
00069
00070 ast_copy_string(buf, data, len);
00071 ast_uri_decode(buf);
00072
00073 return 0;
00074 }
00075
00076 static struct ast_custom_function urldecode_function = {
00077 .name = "URIDECODE",
00078 .synopsis = "Decodes a URI-encoded string according to RFC 2396.",
00079 .syntax = "URIDECODE(<data>)",
00080 .read = uridecode,
00081 };
00082
00083 static struct ast_custom_function urlencode_function = {
00084 .name = "URIENCODE",
00085 .synopsis = "Encodes a string to URI-safe encoding according to RFC 2396.",
00086 .syntax = "URIENCODE(<data>)",
00087 .read = uriencode,
00088 };
00089
00090 static int unload_module(void)
00091 {
00092 return ast_custom_function_unregister(&urldecode_function)
00093 || ast_custom_function_unregister(&urlencode_function);
00094 }
00095
00096 static int load_module(void)
00097 {
00098 return ast_custom_function_register(&urldecode_function)
00099 || ast_custom_function_register(&urlencode_function);
00100 }
00101
00102 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions");