url 1.12.11devel
|
00001 /* 00002 * This file is part of the Sofia-SIP package 00003 * 00004 * Copyright (C) 2005 Nokia Corporation. 00005 * 00006 * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden> 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation; either version 2.1 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA 00022 * 00023 */ 00024 00034 #ifndef URL_H_TYPES 00035 #define URL_H_TYPES 00036 00041 enum url_type_e { 00042 url_invalid = -2, 00043 url_unknown = -1, 00044 url_any = 0, 00045 url_sip, 00046 url_sips, 00047 url_tel, 00048 url_fax, 00049 url_modem, 00050 url_http, 00051 url_https, 00052 url_ftp, 00053 url_file, 00054 url_rtsp, 00055 url_rtspu, 00056 url_mailto, 00057 url_im, 00058 url_pres, 00059 url_cid, 00060 url_msrp, 00061 url_msrps, 00062 url_wv, 00063 _url_none 00064 }; 00065 00070 typedef struct { 00071 char url_pad[sizeof(void *) - 2]; 00073 signed char url_type; 00074 char url_root; 00075 char const *url_scheme; 00076 char const *url_user; 00077 char const *url_password; 00078 char const *url_host; 00079 char const *url_port; 00080 char const *url_path; 00081 char const *url_params; 00082 char const *url_headers; 00083 char const *url_fragment; 00084 } url_t; 00085 00086 enum { 00088 URL_MAXLEN = 65536 00089 }; 00090 00099 typedef union { 00100 char us_str[URL_MAXLEN]; 00101 url_t us_url[1]; 00102 } url_string_t; 00103 00104 #endif 00105 00106 #ifndef URL_H 00107 00108 #define URL_H 00109 00110 #ifndef SU_ALLOC_H 00111 #include <sofia-sip/su_alloc.h> 00112 #endif 00113 00114 SOFIA_BEGIN_DECLS 00115 00117 SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str); 00118 00120 SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...); 00121 00123 SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url); 00124 00126 SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src); 00127 00129 SOFIAPUBFUN int url_sanitize(url_t *u); 00130 00132 SOFIAPUBFUN char const *url_scheme(enum url_type_e type); 00133 00134 /* ---------------------------------------------------------------------- */ 00135 /* URL comparison */ 00136 00138 SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b); 00139 00141 SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b); 00142 00143 /* ---------------------------------------------------------------------- */ 00144 /* Parameter handling */ 00145 00147 SOFIAPUBFUN isize_t url_param(char const *params, char const *tag, 00148 char value[], isize_t vlen); 00149 00151 SOFIAPUBFUN int url_has_param(url_t const *url, char const *name); 00152 00154 SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag); 00155 00157 SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param); 00158 00160 SOFIAPUBFUN int url_strip_transport(url_t *u); 00161 00163 SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name); 00164 00166 SOFIAPUBFUN int url_have_transport(url_t const *u); 00167 00168 /* ---------------------------------------------------------------------- */ 00169 /* Query handling */ 00170 00172 SOFIAPUBFUN char *url_query_as_header_string(su_home_t *home, 00173 char const *query); 00174 00175 /* ---------------------------------------------------------------------- */ 00176 /* Handling url-escque strings */ 00177 00179 SOFIAPUBFUN int url_reserved_p(char const *s); 00180 00182 SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]); 00183 00185 SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]); 00186 00188 SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n); 00189 00191 SOFIAPUBFUN char *url_unescape(char *d, char const *s); 00192 00193 #define URL_RESERVED_CHARS ";/?:@&=+$," 00194 00195 /* ---------------------------------------------------------------------- */ 00196 /* Initializing */ 00197 00206 #define URL_INIT_AS(type) \ 00207 { "\0", url_##type, 0, url_##type != url_any ? #type : "*" } 00208 00210 SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type); 00211 00212 /* ---------------------------------------------------------------------- */ 00213 /* Resolving helpers */ 00214 00216 SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type); 00217 00219 SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type); 00220 00222 SOFIAPUBFUN char const *url_port(url_t const *u); 00223 00225 #define URL_PORT(u) \ 00226 ((u) && (u)->url_port ? (u)->url_port : \ 00227 url_port_default((u) ? (enum url_type_e)(u)->url_type : url_any)) 00228 00229 /* ---------------------------------------------------------------------- */ 00230 /* url_string_t handling */ 00231 00234 #define URL_STRING_P(u) ((u) && *((url_string_t*)(u))->us_str != 0) 00235 00238 #define URL_IS_STRING(u) ((u) && *((url_string_t*)(u))->us_str != 0) 00239 00242 SOFIAPUBFUN int url_string_p(url_string_t const * url); 00243 00246 SOFIAPUBFUN int url_is_string(url_string_t const * url); 00247 00249 #define URL_STRING_MAKE(s) \ 00250 ((url_string_t *)((s) && *((char *)(s)) ? (s) : NULL)) 00251 00252 /* ---------------------------------------------------------------------- */ 00253 /* Printing URL */ 00254 00256 #define URL_PRINT_FORMAT "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" 00257 #define URL_FORMAT_STRING URL_PRINT_FORMAT 00258 00260 #define URL_PRINT_ARGS(u) \ 00261 (u)->url_scheme ? (u)->url_scheme : "", \ 00262 (u)->url_type != url_any && (u)->url_scheme && (u)->url_scheme[0] \ 00263 ? ":" : "", \ 00264 (u)->url_root && ((u)->url_host || (u)->url_user) ? "//" : "", \ 00265 (u)->url_user ? (u)->url_user : "", \ 00266 (u)->url_user && (u)->url_password ? ":" : "", \ 00267 (u)->url_user && (u)->url_password ? (u)->url_password : "", \ 00268 (u)->url_user && (u)->url_host ? "@" : "", \ 00269 (u)->url_host ? (u)->url_host : "", \ 00270 (u)->url_host && (u)->url_port ? ":" : "", \ 00271 (u)->url_host && (u)->url_port ? (u)->url_port : "", \ 00272 (u)->url_root && (u)->url_path ? "/" : "", \ 00273 (u)->url_path ? (u)->url_path : "", \ 00274 (u)->url_params ? ";" : "", (u)->url_params ? (u)->url_params : "", \ 00275 (u)->url_headers ? "?" : "", (u)->url_headers ? (u)->url_headers : "", \ 00276 (u)->url_fragment ? "#" : "", (u)->url_fragment ? (u)->url_fragment : "" 00277 00278 /* ---------------------------------------------------------------------- */ 00279 /* URL digests */ 00280 00281 struct su_md5_t; 00282 00284 SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url); 00285 00287 SOFIAPUBFUN void url_digest(void *hash, int hsize, 00288 url_t const *, char const *key); 00289 00290 /* ---------------------------------------------------------------------- */ 00291 /* Parsing and manipulating URLs */ 00292 00294 SOFIAPUBFUN int url_d(url_t *url, char *s); 00295 00297 SOFIAPUBFUN isize_t url_len(url_t const * url); 00298 00300 SOFIAPUBFUN issize_t url_e(char buffer[], isize_t n, url_t const *url); 00301 00303 #define URL_E(buf, end, url) \ 00304 (buf) += url_e((buf), (buf) < (end) ? (end) - (buf) : 0, (url)) 00305 00307 SOFIAPUBFUN isize_t url_xtra(url_t const * url); 00308 00310 SOFIAPUBFUN issize_t url_dup(char *, isize_t , url_t *dst, url_t const *src); 00311 00313 #define URL_DUP(buf, end, dst, src) \ 00314 (buf) += url_dup((buf), (isize_t)((buf) < (end) ? (end) - (buf) : 0), (dst), (src)) 00315 00316 SOFIA_END_DECLS 00317 #endif 00318