3 Copyright (C) 2009 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "linphonecore.h"
23 #include <eXosip2/eXosip.h>
26 * @addtogroup linphone_address
31 * Constructs a LinphoneAddress object by parsing the user supplied address,
34 LinphoneAddress * linphone_address_new(const char *uri){
36 osip_from_init(&from);
37 if (osip_from_parse(from,uri)!=0){
45 * Clones a LinphoneAddress object.
47 LinphoneAddress * linphone_address_clone(const LinphoneAddress *uri){
48 osip_from_t *ret=NULL;
49 osip_from_clone(uri,&ret);
53 #define null_if_empty(s) (((s)!=NULL && (s)[0]!='\0') ? (s) : NULL )
56 * Returns the address scheme, normally "sip".
58 const char *linphone_address_get_scheme(const LinphoneAddress *u){
59 return null_if_empty(u->url->scheme);
63 * Returns the display name.
65 const char *linphone_address_get_display_name(const LinphoneAddress* u){
66 return null_if_empty(u->displayname);
70 * Returns the username.
72 const char *linphone_address_get_username(const LinphoneAddress *u){
73 return null_if_empty(u->url->username);
77 * Returns the domain name.
79 const char *linphone_address_get_domain(const LinphoneAddress *u){
80 return null_if_empty(u->url->host);
84 * Sets the display name.
86 void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
87 if (u->displayname!=NULL){
88 osip_free(u->displayname);
91 if (display_name!=NULL)
92 u->displayname=osip_strdup(display_name);
98 void linphone_address_set_username(LinphoneAddress *uri, const char *username){
99 if (uri->url->username!=NULL){
100 osip_free(uri->url->username);
101 uri->url->username=NULL;
104 uri->url->username=osip_strdup(username);
110 void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
111 if (uri->url->host!=NULL){
112 osip_free(uri->url->host);
116 uri->url->host=osip_strdup(host);
120 * Sets the port number.
122 void linphone_address_set_port(LinphoneAddress *uri, const char *port){
123 if (uri->url->port!=NULL){
124 osip_free(uri->url->port);
128 uri->url->port=osip_strdup(port);
132 * Sets the port number.
134 void linphone_address_set_port_int(LinphoneAddress *uri, int port){
137 /*this is the default, special case to leave the port field blank*/
138 linphone_address_set_port(uri,NULL);
141 snprintf(tmp,sizeof(tmp),"%i",port);
142 linphone_address_set_port(uri,tmp);
146 * Removes address's tags and uri headers so that it is displayable to the user.
148 void linphone_address_clean(LinphoneAddress *uri){
149 osip_generic_param_freelist(&uri->gen_params);
153 * Returns the address as a string.
154 * The returned char * must be freed by the application. Use ms_free().
156 char *linphone_address_as_string(const LinphoneAddress *u){
158 osip_from_to_str(u,&tmp);
165 * Returns the SIP uri only as a string, that is display name is removed.
166 * The returned char * must be freed by the application. Use ms_free().
168 char *linphone_address_as_string_uri_only(const LinphoneAddress *u){
170 osip_uri_to_str(u->url,&tmp);
177 * Destroys a LinphoneAddress object.
179 void linphone_address_destroy(LinphoneAddress *u){