url  1.12.11devel
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
41 enum url_type_e {
42  url_invalid = -2,
43  url_unknown = -1,
44  url_any = 0,
63  _url_none
64 };
65 
70 typedef 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 
86 enum {
88  URL_MAXLEN = 65536
89 };
90 
99 typedef union {
100  char us_str[URL_MAXLEN];
101  url_t us_url[1];
102 } url_string_t;
103 
104 #endif
105 
106 #ifndef URL_H
107 
108 #define URL_H
109 
110 #ifndef SU_ALLOC_H
111 #include <sofia-sip/su_alloc.h>
112 #endif
113 
114 SOFIA_BEGIN_DECLS
115 
117 SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str);
118 
120 SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...);
121 
123 SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url);
124 
126 SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src);
127 
130 
132 SOFIAPUBFUN char const *url_scheme(enum url_type_e type);
133 
134 /* ---------------------------------------------------------------------- */
135 /* URL comparison */
136 
138 SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b);
139 
141 SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b);
142 
143 /* ---------------------------------------------------------------------- */
144 /* Parameter handling */
145 
147 SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
148  char value[], isize_t vlen);
149 
151 SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
152 
154 SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
155 
157 SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
158 
161 
163 SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
164 
166 SOFIAPUBFUN int url_have_transport(url_t const *u);
167 
168 /* ---------------------------------------------------------------------- */
169 /* Query handling */
170 
173  char const *query);
174 
175 /* ---------------------------------------------------------------------- */
176 /* Handling url-escque strings */
177 
179 SOFIAPUBFUN int url_reserved_p(char const *s);
180 
182 SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]);
183 
185 SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]);
186 
188 SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n);
189 
191 SOFIAPUBFUN 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 
210 SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type);
211 
212 /* ---------------------------------------------------------------------- */
213 /* Resolving helpers */
214 
216 SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type);
217 
219 SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type);
220 
222 SOFIAPUBFUN 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 
242 SOFIAPUBFUN int url_string_p(url_string_t const * url);
243 
246 SOFIAPUBFUN 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 
281 struct su_md5_t;
282 
284 SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url);
285 
287 SOFIAPUBFUN void url_digest(void *hash, int hsize,
288  url_t const *, char const *key);
289 
290 /* ---------------------------------------------------------------------- */
291 /* Parsing and manipulating URLs */
292 
294 SOFIAPUBFUN int url_d(url_t *url, char *s);
295 
297 SOFIAPUBFUN isize_t url_len(url_t const * url);
298 
300 SOFIAPUBFUN 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 
307 SOFIAPUBFUN isize_t url_xtra(url_t const * url);
308 
310 SOFIAPUBFUN 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 
316 SOFIA_END_DECLS
317 #endif
318 

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