Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 418641 $")
38 
39 #include "asterisk/module.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/utils.h"
43 #include "asterisk/app.h"
44 
45 /*** DOCUMENTATION
46  <function name="URIENCODE" language="en_US">
47  <synopsis>
48  Encodes a string to URI-safe encoding according to RFC 2396.
49  </synopsis>
50  <syntax>
51  <parameter name="data" required="true">
52  <para>Input string to be encoded.</para>
53  </parameter>
54  </syntax>
55  <description>
56  <para>Returns the encoded string defined in <replaceable>data</replaceable>.</para>
57  </description>
58  </function>
59  <function name="URIDECODE" language="en_US">
60  <synopsis>
61  Decodes a URI-encoded string according to RFC 2396.
62  </synopsis>
63  <syntax>
64  <parameter name="data" required="true">
65  <para>Input string to be decoded.</para>
66  </parameter>
67  </syntax>
68  <description>
69  <para>Returns the decoded URI-encoded <replaceable>data</replaceable> string.</para>
70  </description>
71  </function>
72  ***/
73 
74 /*! \brief uriencode: Encode URL according to RFC 2396 */
75 static int uriencode(struct ast_channel *chan, const char *cmd, char *data,
76  char *buf, size_t len)
77 {
78  if (ast_strlen_zero(data)) {
79  buf[0] = '\0';
80  return 0;
81  }
82 
83  ast_uri_encode(data, buf, len, 1);
84 
85  return 0;
86 }
87 
88 /*!\brief uridecode: Decode URI according to RFC 2396 */
89 static int uridecode(struct ast_channel *chan, const char *cmd, char *data,
90  char *buf, size_t len)
91 {
92  if (ast_strlen_zero(data)) {
93  buf[0] = '\0';
94  return 0;
95  }
96 
97  ast_copy_string(buf, data, len);
98  ast_uri_decode(buf);
99 
100  return 0;
101 }
102 
104  .name = "URIDECODE",
105  .read = uridecode,
106 };
107 
109  .name = "URIENCODE",
110  .read = uriencode,
111 };
112 
113 static int unload_module(void)
114 {
115  return ast_custom_function_unregister(&urldecode_function)
116  || ast_custom_function_unregister(&urlencode_function);
117 }
118 
119 static int load_module(void)
120 {
121  return ast_custom_function_register(&urldecode_function)
122  || ast_custom_function_register(&urlencode_function);
123 }
124 
125 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions");
Main Channel structure associated with a channel.
Definition: channel.h:742
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:75
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
static int load_module(void)
Definition: func_uri.c:119
void ast_uri_decode(char *s)
Decode URI, URN, URL (overwrite string)
Definition: utils.c:484
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:89
char * ast_uri_encode(const char *string, char *outbuf, int buflen, int do_special_char)
Turn text string to URI-encoded XX version.
Definition: utils.c:398
static int unload_module(void)
Definition: func_uri.c:113
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
Utility functions.
static struct ast_custom_function urldecode_function
Definition: func_uri.c:103
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
Core PBX routines and definitions.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static struct ast_custom_function urlencode_function
Definition: func_uri.c:108
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
const char * name
Definition: pbx.h:96
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180