fix compilation warnings
[asterisk-bristuff.git] / funcs / func_uri.c
blob2680dd678a6f6cf3ac5eb91e837733e68bb16883
1 /*
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.
19 /*! \file
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.
30 #include "asterisk.h"
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
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");
52 return -1;
55 ast_uri_encode(data, buf, len, 1);
57 return 0;
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");
66 return -1;
69 ast_copy_string(buf, data, len);
70 ast_uri_decode(buf);
72 return 0;
75 static struct ast_custom_function urldecode_function = {
76 .name = "URIDECODE",
77 .synopsis = "Decodes a URI-encoded string according to RFC 2396.",
78 .syntax = "URIDECODE(<data>)",
79 .read = uridecode,
82 static struct ast_custom_function urlencode_function = {
83 .name = "URIENCODE",
84 .synopsis = "Encodes a string to URI-safe encoding according to RFC 2396.",
85 .syntax = "URIENCODE(<data>)",
86 .read = uriencode,
89 static int unload_module(void)
91 return ast_custom_function_unregister(&urldecode_function)
92 || ast_custom_function_unregister(&urlencode_function);
95 static int load_module(void)
97 return ast_custom_function_register(&urldecode_function)
98 || ast_custom_function_register(&urlencode_function);
101 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions");