Michael Jerris 058ab862b3 sync to current darcs tree:
Tue Nov 20 11:46:34 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * nua_register.c: silenced warning with URL_INIT_AS() on Sun CC

Tue Nov 20 11:47:06 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * test_register.c: fixed authentication caching issue

Tue Nov 20 12:09:19 EST 2007  Pekka.Pessi@nokia.com
  * tport: tport_name_is_resolved() now uses host_is_ip_address()

Tue Nov 20 12:53:54 EST 2007  Pekka.Pessi@nokia.com
  * tport.c: fixed EXPENSIVE unresolved bug.

Wed Nov 21 07:10:40 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * test_tport.c: skipping tests on TLS if send fails. 

Wed Nov 21 11:46:42 EST 2007  Pekka.Pessi@nokia.com
  * test_nta.c: removed dead code

Thu Nov 22 08:42:14 EST 2007  Pekka.Pessi@nokia.com
  * test_nta.c: refactored client side tests

Thu Nov 22 09:39:45 EST 2007  Pekka.Pessi@nokia.com
  * nta: added nta_sip_is_internal().

Tue Nov 27 13:43:41 EST 2007  Pekka.Pessi@nokia.com
  * test_htable2.c: removed conversion warning 
  
  Conversion of size_t to isize_t when compiled wihout --disable-size-compat.

Wed Nov 21 11:16:04 EST 2007  Daniele Rondina <geaaru at gmail dot com>
  * nta.c: nta_outgoing_*create() now uses NTATAG_TPORT() even if NTATAG_DEFAULT_PROXY() is set

Thu Nov 22 09:36:21 EST 2007  Pekka.Pessi@nokia.com
  * nta.c: always use tport from NTATAG_TPORT() (even if it is bad)
  
  Add tests, too.

Thu Nov 22 10:01:33 EST 2007  Pekka.Pessi@nokia.com
  * nta: added nta_msg_is_internal().

Mon Nov 26 17:08:16 EST 2007  Pekka.Pessi@nokia.com
  * test_proxy.c: removed memory leaks

Mon Nov 26 17:08:35 EST 2007  Pekka.Pessi@nokia.com
  * test_basic_call.c: fixed --no-proxy tests

Mon Nov 26 17:12:27 EST 2007  Pekka.Pessi@nokia.com
  * sofia-sip/su_wait.h: added su_msg_new(), su_msg_send_to(), su_msg_deinitializer()
  
  Reduce overhead from message passing.

Mon Nov 26 19:15:41 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * configure.ac: defining HAVE_SOFIA_HTTP

Mon Nov 26 19:23:05 EST 2007  Pekka.Pessi@nokia.com
  * nua: moved message passing into nua_stack.c. Recfactored reference counting.
  
  This seems to fix the memory leak within 1.12.7.

Wed Nov 28 10:15:07 EST 2007  Pekka.Pessi@nokia.com
  * test_su.c: removed calls of deprecated (and unimplemented) functions su_clone_pause()/su_clone_resume()

Thu Nov 22 09:59:13 EST 2007  Pekka.Pessi@nokia.com
  * nua_stack.c: more logging on bad authentication

Mon Nov 26 19:49:34 EST 2007  Pekka.Pessi@nokia.com
  * tport.h, tport.c: updated tport_create() docs

Thu Nov 29 12:17:40 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * tport: collecting statistics

Thu Nov 29 12:21:10 EST 2007  Pekka.Pessi@nokia.com
  * rules/sofia.am: defining INTERNAL_INCLUDES so it can be used from any subdir
  
  utils/Makefile.am, libsofia-sip-ua/nua/Makefile.am: using INCLUDES from sofia.am

Thu Nov 29 13:03:44 EST 2007  Pekka.Pessi@nokia.com
  * nua: moved test_nua contents in ltlibraries

Thu Nov 29 13:05:25 EST 2007  Pekka.Pessi@nokia.com
  * Makefile.am, configure.ac: added subdir tests for Check-based module tests

Fri Nov 30 09:03:14 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * nua_session.c: avoid NULL nua_session_state_t pointer in nua_update_client_report
  
  Thanks to Fabio Margarido for reporting this problem.



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6539 d0543943-73ff-0310-b7d9-9358b9ac24b2
2007-12-06 18:44:14 +00:00

319 lines
11 KiB
C

/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@file sofia-sip/url.h
*
* URL struct and helper functions.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Thu Jun 8 19:28:55 2000 ppessi
*/
#ifndef URL_H_TYPES
#define URL_H_TYPES
/** Recognized URL schemes (value of url_t.url_type).
*
* @sa &lt;<a href="http://www.iana.org/assignments/uri-schemes.html">http://www.iana.org/assignments/uri-schemes.html</a>&gt;
*/
enum url_type_e {
url_invalid = -2, /**< Invalid url. */
url_unknown = -1, /**< Unknown scheme. */
url_any = 0, /**< "*" */
url_sip, /**< "sip:". @sa @RFC3261 */
url_sips, /**< "sips:". @sa @RFC3261 */
url_tel, /**< "tel:" @sa RFC3966 */
url_fax, /**< "fax:". @note Obsolete. @sa @RFC2806 */
url_modem, /**< "modem:". @note Obsolete. @sa @RFC2806 */
url_http, /**< "http:". @sa @RFC2616, @RFC3986 */
url_https, /**< "https:". @sa @RFC2618, @RFC3986 */
url_ftp, /**< "ftp:". @sa @RFC1738 */
url_file, /**< "file:" @sa @RFC1738 */
url_rtsp, /**< "rtsp:" @sa @RFC2326 */
url_rtspu, /**< "rtspu:" @sa @RFC2326 */
url_mailto, /**< "mailto:" @sa @RFC2368 */
url_im, /**< "im:" (simple instant messaging). @sa @RFC3860 */
url_pres, /**< "pres:" (simple presence). @sa @RFC3859 */
url_cid, /**< "cid:" (Content-ID). @sa @RFC2392 */
url_msrp, /**< "msrp:" (message session relay) */
url_msrps, /**< "msrps:" (new in @VERSION_1_12_2) */
url_wv, /**< "wv:" (Wireless village) */
_url_none
};
/** URL structure.
*
* This structure is used to present a parsed URL.
*/
typedef struct {
char url_pad[sizeof(void *) - 2];
/**< Zero pad for URL_STRING_P(). */
signed char url_type; /**< URL type (url_type_e). */
char url_root; /**< Nonzero if root "//" */
char const *url_scheme; /**< URL type as string. */
char const *url_user; /**< User part */
char const *url_password; /**< Password */
char const *url_host; /**< Host part */
char const *url_port; /**< Port */
char const *url_path; /**< Path part, starts with "/" */
char const *url_params; /**< Parameters (separated by ;) */
char const *url_headers; /**< Headers (separated by ? and &) */
char const *url_fragment; /**< Fragment (separated by #) */
} url_t;
enum {
/** Maximum size of a URL. */
URL_MAXLEN = 65536
};
/** Type to present either a parsed URL or string.
*
* The union type url_string_t is used to pass a parsed URL or string as a
* parameter. The URL_STRING_P() checks if a passed pointer points to a
* string or a parsed URL. Testing requires that the first character of the
* string is nonzero. Use URL_STRING_MAKE() to properly cast a string
* pointer as a pointer to url_string_t.
*/
typedef union {
char us_str[URL_MAXLEN]; /**< URL as a string. */
url_t us_url[1]; /**< Parsed URL. */
} url_string_t;
#endif
#ifndef URL_H
/** Defined when <sofia-sip/url.h> has been included. */
#define URL_H
#ifndef SU_ALLOC_H
#include <sofia-sip/su_alloc.h>
#endif
SOFIA_BEGIN_DECLS
/** Convert a string to a url struct. */
SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str);
/** Convert a string formatting result to a url struct. */
SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...);
/** Convert #url_t to a string allocated from @a home */
SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url);
/** Duplicate the url to memory allocated via home */
SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src);
/** Sanitize a URL. */
SOFIAPUBFUN int url_sanitize(url_t *u);
/** Get URL scheme by type. */
SOFIAPUBFUN char const *url_scheme(enum url_type_e type);
/* ---------------------------------------------------------------------- */
/* URL comparison */
/** Compare two URLs lazily. */
SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b);
/** Compare two URLs conservatively. */
SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b);
/* ---------------------------------------------------------------------- */
/* Parameter handling */
/** Search for a parameter. */
SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
char value[], isize_t vlen);
/** Check for a parameter. */
SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
/** Check for a presence of a parameter in string. */
SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
/** Add a parameter. */
SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
/** Strip transport-specific stuff away from URI. */
SOFIAPUBFUN int url_strip_transport(url_t *u);
/** Strip parameter away from URI. */
SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
/** Test if url has any transport-specific stuff. */
SOFIAPUBFUN int url_have_transport(url_t const *u);
/* ---------------------------------------------------------------------- */
/* Query handling */
/** Convert a URL query to a header string. */
SOFIAPUBFUN char *url_query_as_header_string(su_home_t *home,
char const *query);
/* ---------------------------------------------------------------------- */
/* Handling url-escque strings */
/** Test if string contains url-reserved characters. */
SOFIAPUBFUN int url_reserved_p(char const *s);
/** Escape a string. */
SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]);
/** Calculate length of string when escaped. */
SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]);
/** Unescape characters from string */
SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n);
/** Unescape a string */
SOFIAPUBFUN char *url_unescape(char *d, char const *s);
#define URL_RESERVED_CHARS ";/?:@&=+$,"
/* ---------------------------------------------------------------------- */
/* Initializing */
/** Initializer for an #url_t structure. @HI
*
* The macro URL_INIT_AS() is used to initialize a #url_t structure with a
* known url type:
* @code
* url_t urls[2] = { URL_INIT_AS(sip), URL_INIT_AS(http) };
* @endcode
*/
#define URL_INIT_AS(type) \
{ "\0", url_##type, 0, url_##type != url_any ? #type : "*" }
/** Init a url structure as given type */
SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type);
/* ---------------------------------------------------------------------- */
/* Resolving helpers */
/** Return default port number corresponding to the url type. */
SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type);
/** Return default transport name corresponding to the url type */
SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type);
/** Return the URL port string, using default port if not present. */
SOFIAPUBFUN char const *url_port(url_t const *u);
/** Return the URL port string, using default port if none present. */
#define URL_PORT(u) \
((u) && (u)->url_port ? (u)->url_port : \
url_port_default((u) ? (u)->url_type : url_any))
/* ---------------------------------------------------------------------- */
/* url_string_t handling */
/** Test if a pointer to #url_string_t is a string
* (not a pointer to a #url_t structure). */
#define URL_STRING_P(u) ((u) && *((url_string_t*)(u))->us_str != 0)
/** Test if a pointer to #url_string_t is a string
* (not a pointer to a #url_t structure). */
#define URL_IS_STRING(u) ((u) && *((url_string_t*)(u))->us_str != 0)
/** Test if a pointer to #url_string_t is a string
* (not a pointer to a #url_t structure). */
SOFIAPUBFUN int url_string_p(url_string_t const * url);
/** Test if a pointer to #url_string_t is a string
* (not a pointer to a #url_t structure). */
SOFIAPUBFUN int url_is_string(url_string_t const * url);
/** Cast a string to a #url_string_t. @HI */
#define URL_STRING_MAKE(s) \
((url_string_t *)((s) && *((char *)(s)) ? (s) : NULL))
/* ---------------------------------------------------------------------- */
/* Printing URL */
/** Format string used when printing url with printf(). @HI */
#define URL_PRINT_FORMAT "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
#define URL_FORMAT_STRING URL_PRINT_FORMAT
/** Argument list used when printing url with printf(). @HI */
#define URL_PRINT_ARGS(u) \
(u)->url_scheme ? (u)->url_scheme : "", \
(u)->url_type != url_any && (u)->url_scheme && (u)->url_scheme[0] \
? ":" : "", \
(u)->url_root && ((u)->url_host || (u)->url_user) ? "//" : "", \
(u)->url_user ? (u)->url_user : "", \
(u)->url_user && (u)->url_password ? ":" : "", \
(u)->url_user && (u)->url_password ? (u)->url_password : "", \
(u)->url_user && (u)->url_host ? "@" : "", \
(u)->url_host ? (u)->url_host : "", \
(u)->url_host && (u)->url_port ? ":" : "", \
(u)->url_host && (u)->url_port ? (u)->url_port : "", \
(u)->url_root && (u)->url_path ? "/" : "", \
(u)->url_path ? (u)->url_path : "", \
(u)->url_params ? ";" : "", (u)->url_params ? (u)->url_params : "", \
(u)->url_headers ? "?" : "", (u)->url_headers ? (u)->url_headers : "", \
(u)->url_fragment ? "#" : "", (u)->url_fragment ? (u)->url_fragment : ""
/* ---------------------------------------------------------------------- */
/* URL digests */
struct su_md5_t;
/** Update MD5 sum with URL contents. */
SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url);
/** Calculate a digest from URL contents. */
SOFIAPUBFUN void url_digest(void *hash, int hsize,
url_t const *, char const *key);
/* ---------------------------------------------------------------------- */
/* Parsing and manipulating URLs */
/** Decode a URL. */
SOFIAPUBFUN int url_d(url_t *url, char *s);
/** Calculate the encoding length of URL. */
SOFIAPUBFUN isize_t url_len(url_t const * url);
/** Encode a URL. */
SOFIAPUBFUN issize_t url_e(char buffer[], isize_t n, url_t const *url);
/** Encode a URL: use @a buf up to @a end. @HI */
#define URL_E(buf, end, url) \
(buf) += url_e((buf), (buf) < (end) ? (end) - (buf) : 0, (url))
/** Calculate the size of srings attached to the url. */
SOFIAPUBFUN isize_t url_xtra(url_t const * url);
/** Duplicate the url in the provided memory area. */
SOFIAPUBFUN issize_t url_dup(char *, isize_t , url_t *dst, url_t const *src);
/** Duplicate the url: use @a buf up to @a end. @HI */
#define URL_DUP(buf, end, dst, src) \
(buf) += url_dup((buf), (isize_t)((buf) < (end) ? (end) - (buf) : 0), (dst), (src))
SOFIA_END_DECLS
#endif