| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  |  * Copyright (C) 1999 - 2006, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Created by Olle E. Johansson, Edvina.net  | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief URI encoding / decoding | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Olle E. Johansson <oej@edvina.net> | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \note For now this code only supports 8 bit characters, not unicode, | 
					
						
							|  |  |  |          which we ultimately will need to support. | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-01-24 09:05:29 +00:00
										 |  |  |  * \ingroup functions | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:28:54 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | #include "asterisk/module.h"
 | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/app.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<function name="URIENCODE" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Encodes a string to URI-safe encoding according to RFC 2396. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="data" required="true"> | 
					
						
							|  |  |  | 				<para>Input string to be encoded.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Returns the encoded string defined in <replaceable>data</replaceable>.</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 	</function> | 
					
						
							|  |  |  | 	<function name="URIDECODE" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Decodes a URI-encoded string according to RFC 2396. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="data" required="true"> | 
					
						
							|  |  |  | 				<para>Input string to be decoded.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Returns the decoded URI-encoded <replaceable>data</replaceable> string.</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 	</function> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | /*! \brief uriencode: Encode URL according to RFC 2396 */ | 
					
						
							| 
									
										
										
										
											2007-01-06 00:13:33 +00:00
										 |  |  | static int uriencode(struct ast_channel *chan, const char *cmd, char *data, | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		     char *buf, size_t len) | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-08 01:55:31 +00:00
										 |  |  | 	if (ast_strlen_zero(data)) { | 
					
						
							| 
									
										
										
										
											2014-07-15 17:57:17 +00:00
										 |  |  | 		buf[0] = '\0'; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-24 18:59:22 +00:00
										 |  |  | 	ast_uri_encode(data, buf, len, ast_uri_http); | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | /*!\brief uridecode: Decode URI according to RFC 2396 */ | 
					
						
							| 
									
										
										
										
											2007-01-06 00:13:33 +00:00
										 |  |  | static int uridecode(struct ast_channel *chan, const char *cmd, char *data, | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		     char *buf, size_t len) | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-08 01:55:31 +00:00
										 |  |  | 	if (ast_strlen_zero(data)) { | 
					
						
							| 
									
										
										
										
											2014-07-15 17:57:17 +00:00
										 |  |  | 		buf[0] = '\0'; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_copy_string(buf, data, len); | 
					
						
							| 
									
										
										
										
											2011-01-24 18:59:22 +00:00
										 |  |  | 	ast_uri_decode(buf, ast_uri_http); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | static struct ast_custom_function urldecode_function = { | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | 	.name = "URIDECODE", | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | 	.read = uridecode, | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | static struct ast_custom_function urlencode_function = { | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | 	.name = "URIENCODE", | 
					
						
							| 
									
										
										
										
											2006-02-11 03:14:05 +00:00
										 |  |  | 	.read = uriencode, | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	return ast_custom_function_unregister(&urldecode_function) | 
					
						
							|  |  |  | 		|| ast_custom_function_unregister(&urlencode_function); | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	return ast_custom_function_register(&urldecode_function) | 
					
						
							|  |  |  | 		|| ast_custom_function_register(&urlencode_function); | 
					
						
							| 
									
										
										
										
											2005-08-29 22:54:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions"); |