Sat Aug 6 00:39:29 2011

Asterisk developer's documentation


func_uri.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * Created by Olle E. Johansson, Edvina.net 
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief URI encoding / decoding
00022  *
00023  * \author Olle E. Johansson <oej@edvina.net>
00024  * 
00025  * \note For now this code only supports 8 bit characters, not unicode,
00026          which we ultimately will need to support.
00027  * 
00028  */
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 47625 $")
00033 
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <sys/types.h>
00038 
00039 #include "asterisk/module.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/logger.h"
00043 #include "asterisk/utils.h"
00044 #include "asterisk/app.h"
00045 
00046 /*! \brief uriencode: Encode URL according to RFC 2396 */
00047 static int uriencode(struct ast_channel *chan, char *cmd, char *data,
00048            char *buf, size_t len)
00049 {
00050    if (ast_strlen_zero(data)) {
00051       ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n");
00052       return -1;
00053    }
00054 
00055    ast_uri_encode(data, buf, len, 1);
00056 
00057    return 0;
00058 }
00059 
00060 /*!\brief uridecode: Decode URI according to RFC 2396 */
00061 static int uridecode(struct ast_channel *chan, char *cmd, char *data,
00062            char *buf, size_t len)
00063 {
00064    if (ast_strlen_zero(data)) {
00065       ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
00066       return -1;
00067    }
00068 
00069    ast_copy_string(buf, data, len);
00070    ast_uri_decode(buf);
00071 
00072    return 0;
00073 }
00074 
00075 static struct ast_custom_function urldecode_function = {
00076    .name = "URIDECODE",
00077    .synopsis = "Decodes a URI-encoded string according to RFC 2396.",
00078    .syntax = "URIDECODE(<data>)",
00079    .read = uridecode,
00080 };
00081 
00082 static struct ast_custom_function urlencode_function = {
00083    .name = "URIENCODE",
00084    .synopsis = "Encodes a string to URI-safe encoding according to RFC 2396.",
00085    .syntax = "URIENCODE(<data>)",
00086    .read = uriencode,
00087 };
00088 
00089 static int unload_module(void)
00090 {
00091    return ast_custom_function_unregister(&urldecode_function)
00092       || ast_custom_function_unregister(&urlencode_function);
00093 }
00094 
00095 static int load_module(void)
00096 {
00097    return ast_custom_function_register(&urldecode_function)
00098       || ast_custom_function_register(&urlencode_function);
00099 }
00100 
00101 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "URI encode/decode dialplan functions");

Generated on Sat Aug 6 00:39:29 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7