sofia-sip/url.h

Go to the documentation of this file.
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 
00038 enum url_type_e {
00039   url_invalid = -2,             
00040   url_unknown = -1,             
00041   url_any = 0,                  
00042   url_sip,                      
00043   url_sips,                     
00044   url_tel,                      
00045   url_fax,                      
00046   url_modem,                    
00047   url_http,                     
00048   url_https,                    
00049   url_ftp,                      
00050   url_file,                     
00051   url_rtsp,                     
00052   url_rtspu,                    
00053   url_mailto,                   
00054   url_im,                       
00055   url_pres,                     
00056   url_cid,                      
00057   url_msrp,                     
00058   url_msrps,                    
00059   url_wv,                       
00060   _url_none
00061 };
00062 
00067 typedef struct {
00068   char                url_pad[sizeof(void *) - 2];   
00070   signed char         url_type;     
00071   char                url_root;     
00072   char const         *url_scheme;   
00073   char const         *url_user;     
00074   char const         *url_password; 
00075   char const         *url_host;     
00076   char const         *url_port;     
00077   char const         *url_path;     
00078   char const         *url_params;   
00079   char const         *url_headers;  
00080   char const         *url_fragment; 
00081 } url_t;
00082 
00083 enum { 
00085   URL_MAXLEN = 65536
00086 };
00087 
00096 typedef union {
00097   char  us_str[URL_MAXLEN];     
00098   url_t us_url[1];              
00099 } url_string_t;
00100 
00101 #endif
00102 
00103 #ifndef URL_H
00104 
00105 #define URL_H
00106 
00107 #ifndef SU_ALLOC_H
00108 #include <sofia-sip/su_alloc.h>
00109 #endif
00110 
00111 SOFIA_BEGIN_DECLS
00112 
00114 SOFIAPUBFUN url_t *url_make(su_home_t *h, char const *str);
00115 
00117 SOFIAPUBFUN url_t *url_format(su_home_t *h, char const *fmt, ...);
00118 
00120 SOFIAPUBFUN char *url_as_string(su_home_t *home, url_t const *url);
00121 
00123 SOFIAPUBFUN url_t *url_hdup(su_home_t *h, url_t const *src);
00124 
00126 SOFIAPUBFUN int url_sanitize(url_t *u);
00127 
00129 SOFIAPUBFUN char const *url_scheme(enum url_type_e type);
00130 
00131 /* ---------------------------------------------------------------------- */
00132 /* URL comparison */
00133 
00135 SOFIAPUBFUN int url_cmp(url_t const *a, url_t const *b);
00136 
00138 SOFIAPUBFUN int url_cmp_all(url_t const *a, url_t const *b);
00139 
00140 /* ---------------------------------------------------------------------- */
00141 /* Parameter handling */
00142 
00144 SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
00145                               char value[], isize_t vlen);
00146 
00148 SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
00149 
00151 SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
00152 
00154 SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
00155 
00157 SOFIAPUBFUN int url_strip_transport(url_t *u);
00158 
00160 SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
00161 
00163 SOFIAPUBFUN int url_have_transport(url_t const *u);
00164 
00165 /* ---------------------------------------------------------------------- */
00166 /* Query handling */
00167 
00169 SOFIAPUBFUN char *url_query_as_header_string(su_home_t *home, 
00170                                              char const *query);
00171 
00172 /* ---------------------------------------------------------------------- */
00173 /* Handling url-escque strings */
00174 
00176 SOFIAPUBFUN int url_reserved_p(char const *s);
00177 
00179 SOFIAPUBFUN char *url_escape(char *d, char const *s, char const reserved[]);
00180 
00182 SOFIAPUBFUN isize_t url_esclen(char const *s, char const reserved[]);
00183 
00185 SOFIAPUBFUN size_t url_unescape_to(char *d, char const *s, size_t n);
00186 
00188 SOFIAPUBFUN char *url_unescape(char *d, char const *s);
00189 
00190 #define URL_RESERVED_CHARS ";/?:@&=+$,"
00191 
00192 /* ---------------------------------------------------------------------- */
00193 /* Initializing */
00194 
00203 #define URL_INIT_AS(type)  \
00204   { "\0\0", url_##type, 0, url_##type != url_any ? #type : "*" }
00205 
00207 SOFIAPUBFUN void url_init(url_t *url, enum url_type_e type);
00208 
00209 /* ---------------------------------------------------------------------- */
00210 /* Resolving helpers */
00211 
00213 SOFIAPUBFUN char const *url_port_default(enum url_type_e url_type);
00214 
00216 SOFIAPUBFUN char const *url_tport_default(enum url_type_e url_type);
00217 
00219 SOFIAPUBFUN char const *url_port(url_t const *u);
00220 
00222 #define URL_PORT(u) \
00223   ((u) && (u)->url_port ? (u)->url_port : \
00224   url_port_default((u) ? (u)->url_type : url_any))
00225 
00226 /* ---------------------------------------------------------------------- */
00227 /* url_string_t handling */
00228 
00231 #define URL_STRING_P(u) ((u) && *((url_string_t*)(u))->us_str != 0)
00232 
00235 #define URL_IS_STRING(u) ((u) && *((url_string_t*)(u))->us_str != 0)
00236 
00239 SOFIAPUBFUN int url_string_p(url_string_t const * url);
00240 
00243 SOFIAPUBFUN int url_is_string(url_string_t const * url);
00244 
00246 #define URL_STRING_MAKE(s) \
00247   ((url_string_t *)((s) && *((char *)(s)) ? (s) : NULL))
00248 
00249 /* ---------------------------------------------------------------------- */
00250 /* Printing URL */
00251 
00253 #define URL_PRINT_FORMAT "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
00254 #define URL_FORMAT_STRING URL_PRINT_FORMAT
00255 
00257 #define URL_PRINT_ARGS(u) \
00258   (u)->url_scheme ? (u)->url_scheme : "",       \
00259   (u)->url_type != url_any && (u)->url_scheme && (u)->url_scheme[0] \
00260     ? ":" : "", \
00261   (u)->url_root && ((u)->url_host || (u)->url_user) ? "//" : "", \
00262   (u)->url_user ? (u)->url_user : "", \
00263   (u)->url_user && (u)->url_password ? ":" : "", \
00264   (u)->url_user && (u)->url_password ? (u)->url_password : "", \
00265   (u)->url_user && (u)->url_host ? "@" : "", \
  (u)->url_host ? (u)->url_host : "", \
  (u)->url_host && (u)->url_port ? ":" : "", \
00266   (u)->url_host && (u)->url_port ? (u)->url_port : "", \
00267   (u)->url_root && (u)->url_path ? "/" : "", \
00268   (u)->url_path ? (u)->url_path : "", \
00269   (u)->url_params ? ";" : "", (u)->url_params ? (u)->url_params : "", \
00270   (u)->url_headers ? "?" : "", (u)->url_headers ? (u)->url_headers : "", \
00271   (u)->url_fragment ? "#" : "", (u)->url_fragment ? (u)->url_fragment : ""
00272 
00273 /* ---------------------------------------------------------------------- */
00274 /* URL digests */
00275 
00276 struct su_md5_t;
00277 
00279 SOFIAPUBFUN void url_update(struct su_md5_t *md5, url_t const *url);
00280 
00282 SOFIAPUBFUN void url_digest(void *hash, int hsize,
00283                             url_t const *, char const *key);
00284 
00285 /* ---------------------------------------------------------------------- */
00286 /* Parsing and manipulating URLs */
00287 
00289 SOFIAPUBFUN int url_d(url_t *url, char *s);
00290 
00292 SOFIAPUBFUN isize_t url_len(url_t const * url);
00293 
00295 SOFIAPUBFUN issize_t url_e(char buffer[], isize_t n, url_t const *url);
00296 
00298 #define URL_E(buf, end, url) \
00299   (buf) += url_e((buf), (buf) < (end) ? (end) - (buf) : 0, (url))
00300 
00302 SOFIAPUBFUN isize_t url_xtra(url_t const * url);
00303 
00305 SOFIAPUBFUN issize_t url_dup(char *, isize_t , url_t *dst, url_t const *src);
00306 
00308 #define URL_DUP(buf, end, dst, src) \
00309   (buf) += url_dup((buf), (isize_t)((buf) < (end) ? (end) - (buf) : 0), (dst), (src))
00310 
00311 SOFIA_END_DECLS
00312 #endif
00313 
00314 

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