2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Created by Olle E. Johansson, Edvina.net
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief URI encoding / decoding
23 * \author Olle E. Johansson <oej@edvina.net>
25 * \note For now this code only supports 8 bit characters, not unicode,
26 which we ultimately will need to support.
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37 #include <sys/types.h>
39 #include "asterisk/module.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/logger.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/app.h"
46 /*! \brief uriencode: Encode URL according to RFC 2396 */
47 static int uriencode(struct ast_channel *chan, char *cmd, char *data,
48 char *buf, size_t len)
50 if (ast_strlen_zero(data)) {
51 ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n");
55 ast_uri_encode(data, buf, len, 1);
60 /*!\brief uridecode: Decode URI according to RFC 2396 */
61 static int uridecode(struct ast_channel *chan, char *cmd, char *data,
62 char *buf, size_t len)
64 if (ast_strlen_zero(data)) {
65 ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
69 ast_copy_string(buf, data, len);
75 static struct ast_custom_function urldecode_function = {
77 .synopsis = "Decodes an URI-encoded string.",
78 .syntax = "URIDECODE(<data>)",
82 static struct ast_custom_function urlencode_function = {
84 .synopsis = "Encodes a string to URI-safe encoding.",
85 .syntax = "URIENCODE(<data>)",
89 static char *tdesc = "URI encode/decode dialplan functions";
91 static int unload_module(void *mod)
93 return ast_custom_function_unregister(&urldecode_function)
94 || ast_custom_function_unregister(&urlencode_function);
97 static int load_module(void *mod)
99 return ast_custom_function_register(&urldecode_function)
100 || ast_custom_function_register(&urlencode_function);
103 static const char *description(void)
108 static const char *key(void)
110 return ASTERISK_GPL_KEY;
112 STD_MOD(MOD_1 | NO_USECOUNT, NULL, NULL, NULL);