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 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <sys/types.h>
00032
00033 #include "asterisk.h"
00034
00035
00036
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/utils.h"
00041 #include "asterisk/app.h"
00042 #include "asterisk/module.h"
00043
00044
00045 static char *builtin_function_uriencode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00046 {
00047 char uri[BUFSIZ];
00048
00049 if (ast_strlen_zero(data)) {
00050 ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n");
00051 return NULL;
00052 }
00053
00054 ast_uri_encode(data, uri, sizeof(uri), 1);
00055 ast_copy_string(buf, uri, len);
00056
00057 return buf;
00058 }
00059
00060
00061 static char *builtin_function_uridecode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00062 {
00063 if (ast_strlen_zero(data)) {
00064 ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
00065 return NULL;
00066 }
00067
00068
00069 ast_copy_string(buf, data, len);
00070 ast_uri_decode(buf);
00071 return buf;
00072 }
00073
00074 #ifndef BUILTIN_FUNC
00075 static
00076 #endif
00077 struct ast_custom_function urldecode_function = {
00078 .name = "URIDECODE",
00079 .synopsis = "Decodes an URI-encoded string.",
00080 .syntax = "URIDECODE(<data>)",
00081 .read = builtin_function_uridecode,
00082 };
00083
00084 #ifndef BUILTIN_FUNC
00085 static
00086 #endif
00087 struct ast_custom_function urlencode_function = {
00088 .name = "URIENCODE",
00089 .synopsis = "Encodes a string to URI-safe encoding.",
00090 .syntax = "URIENCODE(<data>)",
00091 .read = builtin_function_uriencode,
00092 };
00093
00094 #ifndef BUILTIN_FUNC
00095 static char *tdesc = "URI encode/decode functions";
00096
00097 int unload_module(void)
00098 {
00099 return ast_custom_function_unregister(&urldecode_function) || ast_custom_function_unregister(&urlencode_function);
00100 }
00101
00102 int load_module(void)
00103 {
00104 return ast_custom_function_register(&urldecode_function) || ast_custom_function_register(&urlencode_function);
00105 }
00106
00107 char *description(void)
00108 {
00109 return tdesc;
00110 }
00111
00112 int usecount(void)
00113 {
00114 return 0;
00115 }
00116
00117 char *key()
00118 {
00119 return ASTERISK_GPL_KEY;
00120 }
00121 #endif