libosip 3.6.0

osip_uri.h

Go to the documentation of this file.
00001 /*
00002   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
00003   Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Aymeric MOIZARD jack@atosc.org
00004   
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #ifndef _URLS_H_
00021 #define _URLS_H_
00022 
00023 #include <osipparser2/osip_const.h>
00024 #include <osipparser2/osip_list.h>
00025 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00049         typedef struct osip_uri_param osip_uri_param_t;
00050 
00055         struct osip_uri_param {
00056                 char *gname;
00057                 char *gvalue;
00059         };
00060 
00065         typedef osip_uri_param_t osip_uri_header_t;
00066 
00071         int osip_uri_param_init(osip_uri_param_t ** url_param);
00076         void osip_uri_param_free(osip_uri_param_t * url_param);
00083         int osip_uri_param_set(osip_uri_param_t * url_param, char *name, char *value);
00089         int osip_uri_param_clone(const osip_uri_param_t * url_param,
00090                                                          osip_uri_param_t ** dest);
00091 #ifndef DOXYGEN
00092 /*
00093  * Free a list of a url parameter element.
00094  * @param url_params The list of url parameter element to free.
00095  */
00096         void osip_uri_param_freelist(osip_list_t * url_params);
00097 #endif
00098 
00104         int osip_uri_param_add(osip_list_t * url_params, char *name, char *value);
00111         int osip_uri_param_get_byname(osip_list_t * url_params, char *name,
00112                                                                   osip_uri_param_t ** dest);
00113 
00118 #define osip_uri_header_init(url_header) osip_uri_param_init(url_header)
00119 
00123 #define osip_uri_header_free(url_header) osip_uri_param_free(url_header)
00124 
00130 #define osip_uri_header_set(url_header, name, value)  osip_uri_param_set(url_header, name, value)
00131 
00136 #define osip_uri_header_clone(url_header,dest)    osip_uri_param_clone(url_header,dest)
00137 #ifndef DOXYGEN
00138 /*
00139  * Free a list of a generic parameter element.
00140  * @param LIST The list of generic parameter element to free.
00141  */
00142 #define osip_uri_header_freelist(LIST)       osip_uri_param_freelist(LIST)
00143 #endif
00144 
00150 #define osip_uri_header_add(url_headers,name,value)        osip_uri_param_add(url_headers,name,value)
00151 
00157 #define osip_uri_header_get_byname(url_headers,name,dest) osip_uri_param_get_byname(url_headers,name,dest)
00158 
00163         typedef struct osip_uri osip_uri_t;
00164 
00169         struct osip_uri {
00170                 char *scheme;              
00171                 char *username;            
00172                 char *password;            
00173                 char *host;                        
00174                 char *port;                        
00175                 osip_list_t url_params;
00176                 osip_list_t url_headers;
00179                 char *string;
00181         };
00182 
00187         int osip_uri_init(osip_uri_t ** url);
00192         void osip_uri_free(osip_uri_t * url);
00198         int osip_uri_parse(osip_uri_t * url, const char *buf);
00199 #ifndef DOXYGEN
00200 
00205         int osip_uri_parse_headers(osip_uri_t * url, const char *buf);
00211         int osip_uri_parse_params(osip_uri_t * url, const char *buf);
00212 #endif
00213 
00218         int osip_uri_to_str(const osip_uri_t * url, char **dest);
00224         int osip_uri_clone(const osip_uri_t * url, osip_uri_t ** dest);
00231         int osip_uri_to_str_canonical(const osip_uri_t * url, char **dest);
00232 
00238         void osip_uri_set_scheme(osip_uri_t * url, char *value);
00243         char *osip_uri_get_scheme(osip_uri_t * url);
00249         void osip_uri_set_host(osip_uri_t * url, char *value);
00254         char *osip_uri_get_host(osip_uri_t * url);
00260         void osip_uri_set_username(osip_uri_t * url, char *value);
00265         char *osip_uri_get_username(osip_uri_t * url);
00271         void osip_uri_set_password(osip_uri_t * url, char *value);
00276         char *osip_uri_get_password(osip_uri_t * url);
00282         void osip_uri_set_port(osip_uri_t * url, char *value);
00287         char *osip_uri_get_port(osip_uri_t * url);
00288 
00289 
00290 
00295 #define osip_uri_set_transport_udp(url)   osip_uri_param_add((&(url)->url_params), osip_strdup("transport"), osip_strdup("udp"))
00296 
00300 #define osip_uri_set_transport_tcp(url)   osip_uri_param_add((&(url)->url_params), osip_strdup("transport"), osip_strdup("tcp"))
00301 
00305 #define osip_uri_set_transport_sctp(url)  osip_uri_param_add((&(url)->url_params), osip_strdup("transport"), osip_strdup("sctp"))
00306 
00310 #define osip_uri_set_transport_tls(url)   osip_uri_param_add((&(url)->url_params), osip_strdup("transport"), osip_strdup("tls"))
00311 
00316 #define osip_uri_set_transport(url,value) osip_uri_param_add((&(url)->url_params), osip_strdup("transport"), value)
00317 
00322 #define osip_uri_set_user_phone(url)   osip_uri_param_add((&(url)->url_params), osip_strdup("user"), osip_strdup("phone"))
00323 
00327 #define osip_uri_set_user_ip(url)      osip_uri_param_add((&(url)->url_params), osip_strdup("user"), osip_strdup("ip"))
00328 
00332 #define osip_uri_set_method_invite(url)  osip_uri_param_add((&(url)->url_params), osip_strdup("method"), osip_strdup("INVITE"))
00333 
00337 #define osip_uri_set_method_ack(url)     osip_uri_param_add((&(url)->url_params), osip_strdup("method"), osip_strdup("ACK"))
00338 
00342 #define osip_uri_set_method_options(url) osip_uri_param_add((&(url)->url_params), osip_strdup("method"), osip_strdup("OPTIONS"))
00343 
00347 #define osip_uri_set_method_bye(url)     osip_uri_param_add((&(url)->url_params), osip_strdup("method"), osip_strdup("BYE"))
00348 
00352 #define osip_uri_set_method_cancel(url)  osip_uri_param_add((&(url)->url_params), osip_strdup("method"), osip_strdup("CANCEL"))
00353 
00357 #define osip_uri_set_method_register(url) osip_uri_param_add((&(url)->url_params),osip_strdup("method"), osip_strdup("REGISTER"))
00358 
00363 #define osip_uri_set_method(url, value) osip_uri_param_add((&(url)->url_params), osip_strdup("method"), value)
00364 
00369 #define osip_uri_set_ttl(url, value)    osip_uri_param_add((&(url)->url_params), osip_strdup("ttl"), value)
00370 
00375 #define osip_uri_set_maddr(url, value)  osip_uri_param_add((&(url)->url_params), osip_strdup("maddr"), value)
00376 
00383 #define osip_uri_uparam_add(url,name,value) osip_uri_param_add((&(url)->url_params),name,value)
00384 
00390 #define osip_uri_uparam_get_byname(url,name,dest)  osip_uri_param_get_byname((&(url)->url_params),name,dest)
00391 
00398 #define osip_uri_uheader_add(url,name,value)    osip_uri_header_add((&(url)->url_headers),name,value)
00399 
00405 #define osip_uri_uheader_get_byname(url,name,dest) osip_uri_header_get_byname((&(url)->url_headers),name,dest)
00406 
00407 #ifndef DOXYGEN
00408 /* internal method */
00409         char *next_separator(const char *ch, int separator_osip_to_find,
00410                                                  int before_separator);
00411 
00412         char *__osip_uri_escape_nonascii_and_nondef(const char *string,
00413                                                                                                 const char *def);
00414         char *__osip_uri_escape_userinfo(const char *string);
00415         char *__osip_uri_escape_password(const char *string);
00416         char *__osip_uri_escape_uri_param(char *string);
00417         char *__osip_uri_escape_header_param(char *string);
00418         void __osip_uri_unescape(char *string);
00419 
00420 #endif
00421 
00424 #ifdef __cplusplus
00425 }
00426 #endif
00427 #endif                                                  /*  _URLS_H_ */