/* * Copyright (C) 2007 Tildeslash Ltd. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * There are special exceptions to the terms and conditions of the GPL * as it is applied to this software. View the full text of the exception * in the file EXCEPTIONS accompanying this software distribution. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBURL_H #define DBURL_H /** * The URL class represent an immutable Uniform Resource Locator. * A Uniform Resource Locator (URL), is used to uniquely identify a * resource on the Internet. The URL is a compact text string with a * restricted syntax that consists of four main components: *
* <protocol>://<authority><path>?<query>
* file protocol only use the path component while a
* http protocol may use all components. Here is an
* example where all components are used:
*
* \htmlonly
*
* http://user:password@www.foo.bar:8080/document/index.csp?querystring#ref
*
* \endhtmlonly
*
* This is a simplified version of the zild
* URL class. The primary purpose of this class is to wrap database connection
* URLs. This class normalize the path if necessary but does not
* url-escape the path nor the query components of the URL, the
* ref part of the URL is also not considered.
*
* For more information about the URL syntax and specification, see,
* RFC2396 -
* Uniform Resource Identifiers (URI): Generic Syntax
*
* @version \$Id: URL.h,v 1.13 2007/01/08 01:47:02 hauk Exp $
* @file
*/
#define T URL_T
typedef struct T *T;
/**
* Create a new URL object from the url parameter
* string. The url string must start with a protocol
* specifier, such as \htmlonlyhttp://\endhtmlonly or
* \htmlonlyftp://\endhtmlonly.
* @param url A string specifying the URL
* @return A URL object or NULL if the url parameter
* cannot be parsed as an URL.
*/
T URL_new(const char *url);
/**
* Factory method for building an URL object using a variable argument
* list. Important: since the '%%' character is used as a format
* specifier (e.g. %%s for string, %%d for integer and so on),
* submitting an URL escaped string (i.e. a %%HEXHEX encoded string)
* in the url parameter can produce undesired results. In
* this case, use either the URL_new() method or URL_unescape() the
* url parameter first.
* @param url A string specifying the URL
* @return A URL object or NULL if the url parameter
* cannot be parsed as an URL.
*/
T URL_create(const char *url, ...);
/**
* Destroy a URL object.
* @param U A URL object reference
*/
void URL_free(T *U);
/**
* Get the protocol of the URL.
* @param U An URL object
* @return The protocol name
*/
const char *URL_getProtocol(T U);
/**
* Get the user name from the authority part of the URL.
* @param U An URL object
* @return A username specified in the URL or NULL if not found
*/
const char *URL_getUser(T U);
/**
* Get the password from the authority part of the URL.
* @param U An URL object
* @return A password specified in the URL or NULL if not found
*/
const char *URL_getPassword(T U);
/**
* Get the hostname of the URL.
* @param U An URL object
* @return The hostname of the URL or NULL if not found
*/
const char *URL_getHost(T U);
/**
* Get the port of the URL.
* @param U An URL object
* @return The port number of the URL or -1 if not specified
*/
int URL_getPort(T U);
/**
* Get the normalized path of the URL.
* @param U An URL object
* @return The path of the URL or NULL if not found
*/
const char *URL_getPath(T U);
/**
* Get the query string of the URL.
* @param U An URL object
* @return The query string of the URL or NULL if not found
*/
const char *URL_getQueryString(T U);
/**
* Returns an array of string objects with the names of the
* parameters contained in this URL. If the URL has no parameters,
* the method returns NULL. The last value in the array is NULL.
* To print all parameter names and their values contained in this
* URL, the following code can be used:
*
* char **parameters= URL_getParameterNames(U);
* if(parameters) for(i= 0; parameters[i]; i++)
* printf("Name: %s Value: %s\n", parameters[i],
URL_getParameter(U, parameters[i]));
*
* @param U An URL object
* @return An array of string objects, each string containing the name
* of a URL parameter; or NULL if the URL has no parameters
*/
const char **URL_getParameterNames(T U);
/**
* Returns the value of a URL parameter as a string, or NULL if
* the parameter does not exist. If you use this method with a
* multi-valued parameter, the value returned is the first value found.
* Lookup is case-sensitive.
* @param U An URL object
* @param name The parameter name to lookup
* @return The parameter value or NULL if not found
*/
const char *URL_getParameter(T U, const char *name);
/**
* Return a string representation of this URL object
* @param U An URL object
* @return The URL string
*/
const char *URL_toString(T U);
/** @name class methods */
//@{
/**
* Class method, unescape an url string. The url
* parameter is modified by this method.
* @param url an escaped url string
* @return A pointer to the unescaped url string
*/
char *URL_unescape(char *url);
/**
* Class method, escape an url string converting unsafe
* characters to a hex (%%HEXHEX) representation. The following URL unsafe
* characters are encoded: <>\"#%%{}|\\^ [] ` as well as
* characters in the interval 00-1F hex (0-31 decimal) and in the interval
* 7F-FF (127-255 decimal) The caller must free the returned string.
* If the url parameter is NULL then this method returns NULL,
* if it is the empty string "" a new empty string is returned.
* @param url an url string
* @return the escaped string
*/
char *URL_escape(const char *url);
/**
* Class method, normalize an URL path string. The
* path parameter is modified by this method. Passing
* a NULL path parameter returns NULL. Examples:
* | path | normalized path | *
| /foo// | /foo/ | *
| /foo/./ | /foo/ | *
| /foo/../bar | /bar | *
| /foo/../bar/ | /bar/ | *
| /foo/../bar/../baz | /baz | *
| //foo//./bar | /foo/bar | *
| /../foo | /foo | *
| /a/../b/../../x | /x | *
| /.././../ | / | *
| /.. | / | *