Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
func_uri.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2006, Digium, Inc.
5 *
6 * Created by Olle E. Johansson, Edvina.net
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief URI encoding / decoding
22 *
23 * \author Olle E. Johansson <oej@edvina.net>
24 *
25 * \note For now this code only supports 8 bit characters, not unicode,
26 which we ultimately will need to support.
27 *
28 * \ingroup functions
29 */
30
31/*** MODULEINFO
32 <support_level>core</support_level>
33 ***/
34
35#include "asterisk.h"
36
37#include "asterisk/module.h"
38#include "asterisk/channel.h"
39#include "asterisk/pbx.h"
40#include "asterisk/utils.h"
41#include "asterisk/app.h"
42
43/*** DOCUMENTATION
44 <function name="URIENCODE" language="en_US">
45 <since>
46 <version>1.2.0</version>
47 </since>
48 <synopsis>
49 Encodes a string to URI-safe encoding according to RFC 2396.
50 </synopsis>
51 <syntax>
52 <parameter name="data" required="true">
53 <para>Input string to be encoded.</para>
54 </parameter>
55 </syntax>
56 <description>
57 <para>Returns the encoded string defined in <replaceable>data</replaceable>.</para>
58 </description>
59 </function>
60 <function name="URIDECODE" language="en_US">
61 <since>
62 <version>1.2.0</version>
63 </since>
64 <synopsis>
65 Decodes a URI-encoded string according to RFC 2396.
66 </synopsis>
67 <syntax>
68 <parameter name="data" required="true">
69 <para>Input string to be decoded.</para>
70 </parameter>
71 </syntax>
72 <description>
73 <para>Returns the decoded URI-encoded <replaceable>data</replaceable> string.</para>
74 </description>
75 </function>
76 ***/
77
78/*! \brief uriencode: Encode URL according to RFC 2396 */
79static int uriencode(struct ast_channel *chan, const char *cmd, char *data,
80 char *buf, size_t len)
81{
82 if (ast_strlen_zero(data)) {
83 buf[0] = '\0';
84 return 0;
85 }
86
88
89 return 0;
90}
91
92/*!\brief uridecode: Decode URI according to RFC 2396 */
93static int uridecode(struct ast_channel *chan, const char *cmd, char *data,
94 char *buf, size_t len)
95{
96 if (ast_strlen_zero(data)) {
97 buf[0] = '\0';
98 return 0;
99 }
100
101 ast_copy_string(buf, data, len);
103
104 return 0;
105}
106
108 .name = "URIDECODE",
109 .read = uridecode,
110};
111
113 .name = "URIENCODE",
114 .read = uriencode,
115};
116
117static int unload_module(void)
118{
121}
122
123static int load_module(void)
124{
127}
128
129AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions");
Asterisk main include file. File version handling, generic pbx functions.
General Asterisk PBX channel definitions.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct ast_custom_function urldecode_function
Definition: func_uri.c:107
static int uriencode(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
uriencode: Encode URL according to RFC 2396
Definition: func_uri.c:79
static int uridecode(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
uridecode: Decode URI according to RFC 2396
Definition: func_uri.c:93
static int load_module(void)
Definition: func_uri.c:123
static int unload_module(void)
Definition: func_uri.c:117
static struct ast_custom_function urlencode_function
Definition: func_uri.c:112
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Core PBX routines and definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Utility functions.
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition: utils.c:723
const struct ast_flags ast_uri_http
Definition: utils.c:719
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
Definition: utils.c:762