Loading...
Searching...
No Matches
url.h
Go to the documentation of this file.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* 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
*
*/
#ifndef URL_H_TYPES
#define URL_H_TYPES
enum url_type_e {
url_invalid = -2,
url_unknown = -1,
url_any = 0,
url_sip,
url_sips,
url_tel,
url_fax,
url_modem,
url_http,
url_https,
url_ftp,
url_file,
url_rtsp,
url_rtspu,
url_mailto,
url_im,
url_pres,
url_cid,
url_msrp,
url_msrps,
url_wv,
_url_none
};
typedef struct {
char url_pad[sizeof(void *) - 2];
signed char url_type;
char url_root;
char const *url_scheme;
char const *url_user;
char const *url_password;
char const *url_host;
char const *url_port;
char const *url_path;
char const *url_params;
char const *url_headers;
char const *url_fragment;
} url_t;
enum {
URL_MAXLEN = 65536
};
typedef union {
char us_str[URL_MAXLEN];
url_t us_url[1];
} url_string_t;
#endif
#ifndef URL_H
#define URL_H
#ifndef SU_ALLOC_H
#include <sofia-sip/su_alloc.h>
#endif
SOFIA_BEGIN_DECLS
SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str);
SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...);
SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url);
SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src);
SOFIAPUBFUN int url_sanitize(url_t *u);
SOFIAPUBFUN char const *url_scheme(enum url_type_e type);
/* ---------------------------------------------------------------------- */
/* URL comparison */
SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b);
SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b);
/* ---------------------------------------------------------------------- */
/* Parameter handling */
SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
char value[], isize_t vlen);
SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
SOFIAPUBFUN int url_strip_transport(url_t *u);
SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
SOFIAPUBFUN int url_have_transport(url_t const *u);
/* ---------------------------------------------------------------------- */
/* Query handling */
SOFIAPUBFUN char *url_query_as_header_string(su_home_t *home,
char const *query);
/* ---------------------------------------------------------------------- */
/* Handling url-escque strings */
SOFIAPUBFUN int url_reserved_p(char const *s);
SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]);
SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]);
SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n);
SOFIAPUBFUN char *url_unescape(char *d, char const *s);
#define URL_RESERVED_CHARS ";/?:@&=+$,"
/* ---------------------------------------------------------------------- */
/* Initializing */
#define URL_INIT_AS(type) \
{ "\0", url_##type, 0, url_##type != url_any ? #type : "*" }
SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type);
/* ---------------------------------------------------------------------- */
/* Resolving helpers */
SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type);
SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type);
SOFIAPUBFUN char const *url_port(url_t const *u);
#define URL_PORT(u) \
((u) && (u)->url_port ? (u)->url_port : \
url_port_default((u) ? (enum url_type_e)(u)->url_type : url_any))
/* ---------------------------------------------------------------------- */
/* url_string_t handling */
#define URL_STRING_P(u) ((u) && *((url_string_t*)(u))->us_str != 0)
#define URL_IS_STRING(u) ((u) && *((url_string_t*)(u))->us_str != 0)
SOFIAPUBFUN int url_string_p(url_string_t const * url);
SOFIAPUBFUN int url_is_string(url_string_t const * url);
#define URL_STRING_MAKE(s) \
((url_string_t *)((s) && *((char *)(s)) ? (s) : NULL))
/* ---------------------------------------------------------------------- */
/* Printing URL */
#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
#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;
SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url);
SOFIAPUBFUN void url_digest(void *hash, int hsize,
url_t const *, char const *key);
/* ---------------------------------------------------------------------- */
/* Parsing and manipulating URLs */
SOFIAPUBFUN int url_d(url_t *url, char *s);
SOFIAPUBFUN isize_t url_len(url_t const * url);
SOFIAPUBFUN issize_t url_e(char buffer[], isize_t n, url_t const *url);
#define URL_E(buf, end, url) \
(buf) += url_e((buf), (buf) < (end) ? (end) - (buf) : 0, (url))
SOFIAPUBFUN isize_t url_xtra(url_t const * url);
SOFIAPUBFUN issize_t url_dup(char *, isize_t , url_t *dst, url_t const *src);
#define URL_DUP(buf, end, dst, src) \
(buf) += url_dup((buf), (isize_t)((buf) < (end) ? (end) - (buf) : 0), (dst), (src))
SOFIA_END_DECLS
#endif
su_md5_t
url_t
URL structure.
Definition url.h:70
url_t::url_root
char url_root
Nonzero if root "//".
Definition url.h:74
url_t::url_port
char const * url_port
Port.
Definition url.h:79
url_t::url_password
char const * url_password
Password.
Definition url.h:77
url_t::url_host
char const * url_host
Host part.
Definition url.h:78
url_t::url_params
char const * url_params
Parameters (separated by ;).
Definition url.h:81
url_t::url_pad
char url_pad[sizeof(void *) - 2]
Zero pad for URL_STRING_P().
Definition url.h:71
url_t::url_headers
char const * url_headers
Headers (separated by ?
Definition url.h:82
url_t::url_type
signed char url_type
URL type (url_type_e).
Definition url.h:73
url_t::url_fragment
char const * url_fragment
Fragment (separated by #).
Definition url.h:83
url_t::url_user
char const * url_user
User part.
Definition url.h:76
url_t::url_path
char const * url_path
Path part, starts with "/".
Definition url.h:80
url_t::url_scheme
char const * url_scheme
URL type as string.
Definition url.h:75
su_alloc.h
su_home_t
SU_HOME_T su_home_t
SOFIAPUBFUN
#define SOFIAPUBFUN
url_string_t
Type to present either a parsed URL or string.
Definition url.h:99
url_string_t::us_url
url_t us_url[1]
Parsed URL.
Definition url.h:101
url_string_t::us_str
char us_str[URL_MAXLEN]
URL as a string.
Definition url.h:100
url_param
isize_t url_param(char const *params, char const *tag, char value[], isize_t vlen)
Search for a parameter.
Definition url.c:1317
url_format
url_t * url_format(su_home_t *h, char const *fmt,...)
Convert a string formatting result to a url struct.
Definition url.c:1248
url_is_string
int url_is_string(url_string_t const *url)
Test if a pointer to url_string_t is a string (not a pointer to a url_t structure).
Definition url.c:1443
url_scheme
char const * url_scheme(enum url_type_e type)
Get URL scheme by type.
Definition url.c:469
url_port_default
char const * url_port_default(enum url_type_e url_type)
Return default port number corresponding to the url type.
Definition url.c:1792
url_hdup
url_t * url_hdup(su_home_t *h, url_t const *src)
Duplicate the url to memory allocated via home.
Definition url.c:1221
url_have_param
isize_t url_have_param(char const *params, char const *tag)
Check for a presence of a parameter in string.
Definition url.c:1363
url_digest
void url_digest(void *hash, int hsize, url_t const *, char const *key)
Calculate a digest from URL contents.
Definition url.c:2083
url_e
issize_t url_e(char buffer[], isize_t n, url_t const *url)
Encode a URL.
Definition url.c:877
url_query_as_header_string
char * url_query_as_header_string(su_home_t *home, char const *query)
Convert a URL query to a header string.
Definition url.c:2123
url_escape
char * url_escape(char *d, char const *s, char const reserved[])
Escape a string.
Definition url.c:229
url_type_e
url_type_e
Recognized URL schemes (value of url_t.url_type).
Definition url.h:41
url_invalid
@ url_invalid
Invalid url.
Definition url.h:42
url_ftp
@ url_ftp
"ftp:".
Definition url.h:52
url_wv
@ url_wv
"wv:" (Wireless village)
Definition url.h:62
url_https
@ url_https
"https:".
Definition url.h:51
url_sips
@ url_sips
"sips:".
Definition url.h:46
url_msrps
@ url_msrps
"msrps:" (new in 1.12.2)
Definition url.h:61
url_cid
@ url_cid
"cid:" (Content-ID).
Definition url.h:59
url_unknown
@ url_unknown
Unknown scheme.
Definition url.h:43
url_modem
@ url_modem
"modem:".
Definition url.h:49
url_rtsp
@ url_rtsp
"rtsp:"
Definition url.h:54
url_file
@ url_file
"file:"
Definition url.h:53
url_im
@ url_im
"im:" (simple instant messaging).
Definition url.h:57
url_pres
@ url_pres
"pres:" (simple presence).
Definition url.h:58
url_mailto
@ url_mailto
"mailto:"
Definition url.h:56
url_any
@ url_any
"*"
Definition url.h:44
url_sip
@ url_sip
"sip:".
Definition url.h:45
url_rtspu
@ url_rtspu
"rtspu:"
Definition url.h:55
url_msrp
@ url_msrp
"msrp:" (message session relay)
Definition url.h:60
url_http
@ url_http
"http:".
Definition url.h:50
url_tel
@ url_tel
"tel:"
Definition url.h:47
url_fax
@ url_fax
"fax:".
Definition url.h:48
url_has_param
int url_has_param(url_t const *url, char const *name)
Check for a parameter.
Definition url.c:1369
url_xtra
isize_t url_xtra(url_t const *url)
Calculate the size of srings attached to the url.
Definition url.c:1047
url_strip_param_string
char * url_strip_param_string(char *params, char const *name)
Strip parameter away from URI.
Definition url.c:1400
url_dup
issize_t url_dup(char *, isize_t, url_t *dst, url_t const *src)
Duplicate the url in the provided memory area.
Definition url.c:1119
url_have_transport
int url_have_transport(url_t const *u)
Test if url has any transport-specific stuff.
Definition url.c:1549
URL_MAXLEN
@ URL_MAXLEN
Maximum size of a URL.
Definition url.h:88
url_update
void url_update(struct su_md5_t *md5, url_t const *url)
Update MD5 sum with URL contents.
Definition url.c:2067
url_unescape
char * url_unescape(char *d, char const *s)
Unescape a string.
Definition url.c:320
url_tport_default
char const * url_tport_default(enum url_type_e url_type)
Return default transport name corresponding to the url type.
Definition url.c:1833
url_make
url_t * url_make(su_home_t *h, char const *str)
Convert a string to a url struct.
Definition url.c:1242
url_cmp
int url_cmp(url_t const *a, url_t const *b)
Compare two URLs lazily.
Definition url.c:1569
url_esclen
isize_t url_esclen(char const *s, char const reserved[])
Calculate length of string when escaped.
Definition url.c:198
url_reserved_p
int url_reserved_p(char const *s)
Test if string contains url-reserved characters.
Definition url.c:163
url_sanitize
int url_sanitize(url_t *u)
Sanitize a URL.
Definition url.c:1905
url_port
char const * url_port(url_t const *u)
Return the URL port string, using default port if not present.
Definition url.c:1874
url_unescape_to
size_t url_unescape_to(char *d, char const *s, size_t n)
Unescape characters from string.
Definition url.c:275
url_init
void url_init(url_t *url, enum url_type_e type)
Init a url structure as given type.
Definition url.c:509
url_strip_transport
int url_strip_transport(url_t *u)
Strip transport-specific stuff away from URI.
Definition url.c:1530
url_len
isize_t url_len(url_t const *url)
Calculate the encoding length of URL.
Definition url.c:1015
url_d
int url_d(url_t *url, char *s)
Decode a URL.
Definition url.c:788
url_param_add
int url_param_add(su_home_t *h, url_t *url, char const *param)
Add a parameter.
Definition url.c:1375
url_cmp_all
int url_cmp_all(url_t const *a, url_t const *b)
Compare two URLs conservatively.
Definition url.c:1695
url_string_p
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).
Definition url.c:1438
url_as_string
char * url_as_string(su_home_t *home, url_t const *url)
Convert url_t to a string allocated from home.
Definition url.c:1280

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.