url 1.13.17
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
66
71typedef struct {
72 char url_pad[sizeof(void *) - 2];
74 signed char url_type;
75 char url_root;
76 char const *url_scheme;
77 char const *url_user;
78 char const *url_password;
79 char const *url_host;
80 char const *url_port;
81 char const *url_path;
82 char const *url_params;
83 char const *url_headers;
84 char const *url_fragment;
85} url_t;
86
87enum {
89 URL_MAXLEN = 65536
90};
91
100typedef union {
101 char us_str[URL_MAXLEN];
102 url_t us_url[1];
104
105#endif
106
107#ifndef URL_H
109#define URL_H
110
111#ifndef SU_ALLOC_H
112#include <sofia-sip/su_alloc.h>
113#endif
114
115SOFIA_BEGIN_DECLS
116
118SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str);
119
121SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...);
122
124SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url);
125
127SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src);
128
131
133SOFIAPUBFUN char const *url_scheme(enum url_type_e type);
134
135/* ---------------------------------------------------------------------- */
136/* URL comparison */
137
139SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b);
140
142SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b);
143
144/* ---------------------------------------------------------------------- */
145/* Parameter handling */
146
148SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
149 char value[], isize_t vlen);
150
152SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
153
155SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
156
158SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
159
162
164SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
165
168
169/* ---------------------------------------------------------------------- */
170/* Query handling */
171
174 char const *query);
175
176/* ---------------------------------------------------------------------- */
177/* Handling url-escque strings */
178
180SOFIAPUBFUN int url_reserved_p(char const *s);
181
183SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]);
184
186SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]);
187
189SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n);
190
192SOFIAPUBFUN char *url_unescape(char *d, char const *s);
193
194#define URL_RESERVED_CHARS ";/?:@&=+$,"
195
196/* ---------------------------------------------------------------------- */
197/* Initializing */
198
207#define URL_INIT_AS(type) \
208 { "\0", url_##type, 0, url_##type != url_any ? #type : "*" }
209
211SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type);
212
213/* ---------------------------------------------------------------------- */
214/* Resolving helpers */
215
217SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type);
218
220SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type);
221
223SOFIAPUBFUN char const *url_port(url_t const *u);
224
226#define URL_PORT(u) \
227 ((u) && (u)->url_port ? (u)->url_port : \
228 url_port_default((u) ? (enum url_type_e)(u)->url_type : url_any))
229
230/* ---------------------------------------------------------------------- */
231/* url_string_t handling */
232
235#define URL_STRING_P(u) ((u) && *((url_string_t*)(u))->us_str != 0)
236
239#define URL_IS_STRING(u) ((u) && *((url_string_t*)(u))->us_str != 0)
240
243SOFIAPUBFUN int url_string_p(url_string_t const * url);
244
247SOFIAPUBFUN int url_is_string(url_string_t const * url);
248
250#define URL_STRING_MAKE(s) \
251 ((url_string_t *)((s) && *((char *)(s)) ? (s) : NULL))
252
253/* ---------------------------------------------------------------------- */
254/* Printing URL */
255
257#define URL_PRINT_FORMAT "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
258#define URL_FORMAT_STRING URL_PRINT_FORMAT
259
261#define URL_PRINT_ARGS(u) \
262 (u)->url_scheme ? (u)->url_scheme : "", \
263 (u)->url_type != url_any && (u)->url_scheme && (u)->url_scheme[0] \
264 ? ":" : "", \
265 (u)->url_root && ((u)->url_host || (u)->url_user) ? "//" : "", \
266 (u)->url_user ? (u)->url_user : "", \
267 (u)->url_user && (u)->url_password ? ":" : "", \
268 (u)->url_user && (u)->url_password ? (u)->url_password : "", \
269 (u)->url_user && (u)->url_host ? "@" : "", \
270 (u)->url_host ? (u)->url_host : "", \
271 (u)->url_host && (u)->url_port ? ":" : "", \
272 (u)->url_host && (u)->url_port ? (u)->url_port : "", \
273 (u)->url_root && (u)->url_path ? "/" : "", \
274 (u)->url_path ? (u)->url_path : "", \
275 (u)->url_params ? ";" : "", (u)->url_params ? (u)->url_params : "", \
276 (u)->url_headers ? "?" : "", (u)->url_headers ? (u)->url_headers : "", \
277 (u)->url_fragment ? "#" : "", (u)->url_fragment ? (u)->url_fragment : ""
278
279/* ---------------------------------------------------------------------- */
280/* URL digests */
281
282struct su_md5_t;
283
285SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url);
286
288SOFIAPUBFUN void url_digest(void *hash, int hsize,
289 url_t const *, char const *key);
290
291/* ---------------------------------------------------------------------- */
292/* Parsing and manipulating URLs */
293
295SOFIAPUBFUN int url_d(url_t *url, char *s);
296
298SOFIAPUBFUN isize_t url_len(url_t const * url);
299
301SOFIAPUBFUN issize_t url_e(char buffer[], isize_t n, url_t const *url);
302
304#define URL_E(buf, end, url) \
305 (buf) += url_e((buf), (buf) < (end) ? (end) - (buf) : 0, (url))
306
308SOFIAPUBFUN isize_t url_xtra(url_t const * url);
309
311SOFIAPUBFUN issize_t url_dup(char *, isize_t , url_t *dst, url_t const *src);
312
314#define URL_DUP(buf, end, dst, src) \
315 (buf) += url_dup((buf), (isize_t)((buf) < (end) ? (end) - (buf) : 0), (dst), (src))
316
317SOFIA_END_DECLS
318#endif
319
URL structure.
Definition url.h:71
char url_root
Nonzero if root "//".
Definition url.h:75
char const * url_port
Port.
Definition url.h:80
char const * url_password
Password.
Definition url.h:78
char const * url_host
Host part.
Definition url.h:79
char const * url_params
Parameters (separated by ;)
Definition url.h:82
char const * url_headers
Headers (separated by ? and &)
Definition url.h:83
signed char url_type
URL type (url_type_e).
Definition url.h:74
char const * url_fragment
Fragment (separated by #)
Definition url.h:84
char const * url_user
User part.
Definition url.h:77
char const * url_path
Path part, starts with "/".
Definition url.h:81
char const * url_scheme
URL type as string.
Definition url.h:76
SU_HOME_T su_home_t
#define SOFIAPUBFUN
Type to present either a parsed URL or string.
Definition url.h:100
isize_t url_param(char const *params, char const *tag, char value[], isize_t vlen)
Search for a parameter.
Definition url.c:1308
@ URL_MAXLEN
Maximum size of a URL.
Definition url.h:89
url_t * url_format(su_home_t *h, char const *fmt,...)
Convert a string formatting result to a url struct.
Definition url.c:1239
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:1435
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:1784
url_t * url_hdup(su_home_t *h, url_t const *src)
Duplicate the url to memory allocated via home.
Definition url.c:1212
isize_t url_have_param(char const *params, char const *tag)
Check for a presence of a parameter in string.
Definition url.c:1354
void url_digest(void *hash, int hsize, url_t const *, char const *key)
Calculate a digest from URL contents.
Definition url.c:2077
issize_t url_e(char buffer[], isize_t n, url_t const *url)
Encode a URL.
Definition url.c:868
char * url_query_as_header_string(su_home_t *home, char const *query)
Convert a URL query to a header string.
Definition url.c:2117
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:53
@ url_wv
"wv:" (Wireless village)
Definition url.h:63
@ url_https
"https:".
Definition url.h:52
@ url_urn
"urn:".
Definition url.h:47
@ url_sips
"sips:".
Definition url.h:46
@ url_msrps
"msrps:" (new in 1.12.2)
Definition url.h:62
@ url_cid
"cid:" (Content-ID).
Definition url.h:60
@ url_unknown
Unknown scheme.
Definition url.h:43
@ url_modem
"modem:".
Definition url.h:50
@ url_rtsp
"rtsp:"
Definition url.h:55
@ url_file
"file:"
Definition url.h:54
@ url_im
"im:" (simple instant messaging).
Definition url.h:58
@ url_pres
"pres:" (simple presence).
Definition url.h:59
@ url_mailto
"mailto:"
Definition url.h:57
@ url_any
"*"
Definition url.h:44
@ url_sip
"sip:".
Definition url.h:45
@ url_rtspu
"rtspu:"
Definition url.h:56
@ url_msrp
"msrp:" (message session relay)
Definition url.h:61
@ url_http
"http:".
Definition url.h:51
@ url_tel
"tel:"
Definition url.h:48
@ url_fax
"fax:".
Definition url.h:49
int url_has_param(url_t const *url, char const *name)
Check for a parameter.
Definition url.c:1360
isize_t url_xtra(url_t const *url)
Calculate the size of srings attached to the url.
Definition url.c:1038
char * url_strip_param_string(char *params, char const *name)
Strip parameter away from URI.
Definition url.c:1391
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:1110
int url_have_transport(url_t const *u)
Test if url has any transport-specific stuff.
Definition url.c:1541
void url_update(struct su_md5_t *md5, url_t const *url)
Update MD5 sum with URL contents.
Definition url.c:2061
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:1826
url_t * url_make(su_home_t *h, char const *str)
Convert a string to a url struct.
Definition url.c:1233
int url_cmp(url_t const *a, url_t const *b)
Compare two URLs lazily.
Definition url.c:1561
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:1899
char const * url_port(url_t const *u)
Return the URL port string, using default port if not present.
Definition url.c:1868
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:510
int url_strip_transport(url_t *u)
Strip transport-specific stuff away from URI.
Definition url.c:1522
isize_t url_len(url_t const *url)
Calculate the encoding length of URL.
Definition url.c:1006
int url_d(url_t *url, char *s)
Decode a URL.
Definition url.c:779
int url_param_add(su_home_t *h, url_t *url, char const *param)
Add a parameter.
Definition url.c:1366
int url_cmp_all(url_t const *a, url_t const *b)
Compare two URLs conservatively.
Definition url.c:1687
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:1430
char * url_as_string(su_home_t *home, url_t const *url)
Convert url_t to a string allocated from home.
Definition url.c:1271

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