url 1.12.11devel
Loading...
Searching...
No Matches
url.h
Go to the documentation of this file.
1/*
2 * This file is part of the Sofia-SIP package
3 *
4 * Copyright (C) 2005 Nokia Corporation.
5 *
6 * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
34#ifndef URL_H_TYPES
35#define URL_H_TYPES
36
65
70typedef struct {
71 char url_pad[sizeof(void *) - 2];
73 signed char url_type;
74 char url_root;
75 char const *url_scheme;
76 char const *url_user;
77 char const *url_password;
78 char const *url_host;
79 char const *url_port;
80 char const *url_path;
81 char const *url_params;
82 char const *url_headers;
83 char const *url_fragment;
84} url_t;
85
86enum {
88 URL_MAXLEN = 65536
89};
90
99typedef union {
100 char us_str[URL_MAXLEN];
101 url_t us_url[1];
103
104#endif
105
106#ifndef URL_H
108#define URL_H
109
110#ifndef SU_ALLOC_H
111#include <sofia-sip/su_alloc.h>
112#endif
113
114SOFIA_BEGIN_DECLS
115
117SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str);
118
120SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...);
121
123SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url);
124
126SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src);
127
130
132SOFIAPUBFUN char const *url_scheme(enum url_type_e type);
133
134/* ---------------------------------------------------------------------- */
135/* URL comparison */
136
138SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b);
139
141SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b);
142
143/* ---------------------------------------------------------------------- */
144/* Parameter handling */
145
147SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
148 char value[], isize_t vlen);
149
151SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
152
154SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
155
157SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
158
161
163SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
164
167
168/* ---------------------------------------------------------------------- */
169/* Query handling */
170
173 char const *query);
174
175/* ---------------------------------------------------------------------- */
176/* Handling url-escque strings */
177
179SOFIAPUBFUN int url_reserved_p(char const *s);
180
182SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]);
183
185SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]);
186
188SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n);
189
191SOFIAPUBFUN char *url_unescape(char *d, char const *s);
192
193#define URL_RESERVED_CHARS ";/?:@&=+$,"
194
195/* ---------------------------------------------------------------------- */
196/* Initializing */
197
206#define URL_INIT_AS(type) \
207 { "\0", url_##type, 0, url_##type != url_any ? #type : "*" }
208
210SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type);
211
212/* ---------------------------------------------------------------------- */
213/* Resolving helpers */
214
216SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type);
217
219SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type);
220
222SOFIAPUBFUN char const *url_port(url_t const *u);
223
225#define URL_PORT(u) \
226 ((u) && (u)->url_port ? (u)->url_port : \
227 url_port_default((u) ? (enum url_type_e)(u)->url_type : url_any))
228
229/* ---------------------------------------------------------------------- */
230/* url_string_t handling */
231
234#define URL_STRING_P(u) ((u) && *((url_string_t*)(u))->us_str != 0)
235
238#define URL_IS_STRING(u) ((u) && *((url_string_t*)(u))->us_str != 0)
239
242SOFIAPUBFUN int url_string_p(url_string_t const * url);
243
246SOFIAPUBFUN int url_is_string(url_string_t const * url);
247
249#define URL_STRING_MAKE(s) \
250 ((url_string_t *)((s) && *((char *)(s)) ? (s) : NULL))
251
252/* ---------------------------------------------------------------------- */
253/* Printing URL */
254
256#define URL_PRINT_FORMAT "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
257#define URL_FORMAT_STRING URL_PRINT_FORMAT
258
260#define URL_PRINT_ARGS(u) \
261 (u)->url_scheme ? (u)->url_scheme : "", \
262 (u)->url_type != url_any && (u)->url_scheme && (u)->url_scheme[0] \
263 ? ":" : "", \
264 (u)->url_root && ((u)->url_host || (u)->url_user) ? "//" : "", \
265 (u)->url_user ? (u)->url_user : "", \
266 (u)->url_user && (u)->url_password ? ":" : "", \
267 (u)->url_user && (u)->url_password ? (u)->url_password : "", \
268 (u)->url_user && (u)->url_host ? "@" : "", \
269 (u)->url_host ? (u)->url_host : "", \
270 (u)->url_host && (u)->url_port ? ":" : "", \
271 (u)->url_host && (u)->url_port ? (u)->url_port : "", \
272 (u)->url_root && (u)->url_path ? "/" : "", \
273 (u)->url_path ? (u)->url_path : "", \
274 (u)->url_params ? ";" : "", (u)->url_params ? (u)->url_params : "", \
275 (u)->url_headers ? "?" : "", (u)->url_headers ? (u)->url_headers : "", \
276 (u)->url_fragment ? "#" : "", (u)->url_fragment ? (u)->url_fragment : ""
277
278/* ---------------------------------------------------------------------- */
279/* URL digests */
280
281struct su_md5_t;
282
284SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url);
285
287SOFIAPUBFUN void url_digest(void *hash, int hsize,
288 url_t const *, char const *key);
289
290/* ---------------------------------------------------------------------- */
291/* Parsing and manipulating URLs */
292
294SOFIAPUBFUN int url_d(url_t *url, char *s);
295
297SOFIAPUBFUN isize_t url_len(url_t const * url);
298
300SOFIAPUBFUN issize_t url_e(char buffer[], isize_t n, url_t const *url);
301
303#define URL_E(buf, end, url) \
304 (buf) += url_e((buf), (buf) < (end) ? (end) - (buf) : 0, (url))
305
307SOFIAPUBFUN isize_t url_xtra(url_t const * url);
308
310SOFIAPUBFUN issize_t url_dup(char *, isize_t , url_t *dst, url_t const *src);
311
313#define URL_DUP(buf, end, dst, src) \
314 (buf) += url_dup((buf), (isize_t)((buf) < (end) ? (end) - (buf) : 0), (dst), (src))
315
316SOFIA_END_DECLS
317#endif
318
URL structure.
Definition url.h:70
char url_root
Nonzero if root "//".
Definition url.h:74
char const * url_port
Port.
Definition url.h:79
char const * url_password
Password.
Definition url.h:77
char const * url_host
Host part.
Definition url.h:78
char const * url_params
Parameters (separated by ;)
Definition url.h:81
char const * url_headers
Headers (separated by ? and &)
Definition url.h:82
signed char url_type
URL type (url_type_e).
Definition url.h:73
char const * url_fragment
Fragment (separated by #)
Definition url.h:83
char const * url_user
User part.
Definition url.h:76
char const * url_path
Path part, starts with "/".
Definition url.h:80
char const * url_scheme
URL type as string.
Definition url.h:75
SU_HOME_T su_home_t
#define SOFIAPUBFUN
Type to present either a parsed URL or string.
Definition url.h:99
isize_t url_param(char const *params, char const *tag, char value[], isize_t vlen)
Search for a parameter.
Definition url.c:1317
@ URL_MAXLEN
Maximum size of a URL.
Definition url.h:88
url_t * url_format(su_home_t *h, char const *fmt,...)
Convert a string formatting result to a url struct.
Definition url.c:1248
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
char const * url_scheme(enum url_type_e type)
Get URL scheme by type.
Definition url.c:469
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_t * url_hdup(su_home_t *h, url_t const *src)
Duplicate the url to memory allocated via home.
Definition url.c:1221
isize_t url_have_param(char const *params, char const *tag)
Check for a presence of a parameter in string.
Definition url.c:1363
void url_digest(void *hash, int hsize, url_t const *, char const *key)
Calculate a digest from URL contents.
Definition url.c:2083
issize_t url_e(char buffer[], isize_t n, url_t const *url)
Encode a URL.
Definition url.c:877
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
char * url_escape(char *d, char const *s, char const reserved[])
Escape a string.
Definition url.c:229
url_type_e
Recognized URL schemes (value of url_t.url_type).
Definition url.h:41
@ url_invalid
Invalid url.
Definition url.h:42
@ url_ftp
"ftp:".
Definition url.h:52
@ url_wv
"wv:" (Wireless village)
Definition url.h:62
@ url_https
"https:".
Definition url.h:51
@ url_sips
"sips:".
Definition url.h:46
@ url_msrps
"msrps:" (new in 1.12.2)
Definition url.h:61
@ url_cid
"cid:" (Content-ID).
Definition url.h:59
@ url_unknown
Unknown scheme.
Definition url.h:43
@ url_modem
"modem:".
Definition url.h:49
@ url_rtsp
"rtsp:"
Definition url.h:54
@ url_file
"file:"
Definition url.h:53
@ url_im
"im:" (simple instant messaging).
Definition url.h:57
@ url_pres
"pres:" (simple presence).
Definition url.h:58
@ url_mailto
"mailto:"
Definition url.h:56
@ url_any
"*"
Definition url.h:44
@ url_sip
"sip:".
Definition url.h:45
@ url_rtspu
"rtspu:"
Definition url.h:55
@ url_msrp
"msrp:" (message session relay)
Definition url.h:60
@ url_http
"http:".
Definition url.h:50
@ url_tel
"tel:"
Definition url.h:47
@ url_fax
"fax:".
Definition url.h:48
int url_has_param(url_t const *url, char const *name)
Check for a parameter.
Definition url.c:1369
isize_t url_xtra(url_t const *url)
Calculate the size of srings attached to the url.
Definition url.c:1047
char * url_strip_param_string(char *params, char const *name)
Strip parameter away from URI.
Definition url.c:1400
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
int url_have_transport(url_t const *u)
Test if url has any transport-specific stuff.
Definition url.c:1549
void url_update(struct su_md5_t *md5, url_t const *url)
Update MD5 sum with URL contents.
Definition url.c:2067
char * url_unescape(char *d, char const *s)
Unescape a string.
Definition url.c:320
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_t * url_make(su_home_t *h, char const *str)
Convert a string to a url struct.
Definition url.c:1242
int url_cmp(url_t const *a, url_t const *b)
Compare two URLs lazily.
Definition url.c:1569
isize_t url_esclen(char const *s, char const reserved[])
Calculate length of string when escaped.
Definition url.c:198
int url_reserved_p(char const *s)
Test if string contains url-reserved characters.
Definition url.c:163
int url_sanitize(url_t *u)
Sanitize a URL.
Definition url.c:1905
char const * url_port(url_t const *u)
Return the URL port string, using default port if not present.
Definition url.c:1874
size_t url_unescape_to(char *d, char const *s, size_t n)
Unescape characters from string.
Definition url.c:275
void url_init(url_t *url, enum url_type_e type)
Init a url structure as given type.
Definition url.c:509
int url_strip_transport(url_t *u)
Strip transport-specific stuff away from URI.
Definition url.c:1530
isize_t url_len(url_t const *url)
Calculate the encoding length of URL.
Definition url.c:1015
int url_d(url_t *url, char *s)
Decode a URL.
Definition url.c:788
int url_param_add(su_home_t *h, url_t *url, char const *param)
Add a parameter.
Definition url.c:1375
int url_cmp_all(url_t const *a, url_t const *b)
Compare two URLs conservatively.
Definition url.c:1695
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
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.