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){
39 ms_error("Cannot create LinphoneAddress, bad uri [%s]",uri);
46 * Clones a LinphoneAddress object.
48 LinphoneAddress * linphone_address_clone(const LinphoneAddress *uri){
49 osip_from_t *ret=NULL;
50 osip_from_clone(uri,&ret);
54 #define null_if_empty(s) (((s)!=NULL && (s)[0]!='\0') ? (s) : NULL )
57 * Returns the address scheme, normally "sip".
59 const char *linphone_address_get_scheme(const LinphoneAddress *u){
60 return null_if_empty(u->url->scheme);
64 * Returns the display name.
66 const char *linphone_address_get_display_name(const LinphoneAddress* u){
67 return null_if_empty(u->displayname);
71 * Returns the username.
73 const char *linphone_address_get_username(const LinphoneAddress *u){
74 return null_if_empty(u->url->username);
78 * Returns the domain name.
80 const char *linphone_address_get_domain(const LinphoneAddress *u){
81 return null_if_empty(u->url->host);
85 * Sets the display name.
87 void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
88 if (u->displayname!=NULL){
89 osip_free(u->displayname);
92 if (display_name!=NULL)
93 u->displayname=osip_strdup(display_name);
99 void linphone_address_set_username(LinphoneAddress *uri, const char *username){
100 if (uri->url->username!=NULL){
101 osip_free(uri->url->username);
102 uri->url->username=NULL;
105 uri->url->username=osip_strdup(username);
111 void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
112 if (uri->url->host!=NULL){
113 osip_free(uri->url->host);
117 uri->url->host=osip_strdup(host);
121 * Sets the port number.
123 void linphone_address_set_port(LinphoneAddress *uri, const char *port){
124 if (uri->url->port!=NULL){
125 osip_free(uri->url->port);
129 uri->url->port=osip_strdup(port);
133 * Sets the port number.
135 void linphone_address_set_port_int(LinphoneAddress *uri, int port){
138 /*this is the default, special case to leave the port field blank*/
139 linphone_address_set_port(uri,NULL);
142 snprintf(tmp,sizeof(tmp),"%i",port);
143 linphone_address_set_port(uri,tmp);
147 * Removes address's tags and uri headers so that it is displayable to the user.
149 void linphone_address_clean(LinphoneAddress *uri){
150 osip_generic_param_freelist(&uri->gen_params);
154 * Returns the address as a string.
155 * The returned char * must be freed by the application. Use ms_free().
157 char *linphone_address_as_string(const LinphoneAddress *u){
159 osip_from_to_str(u,&tmp);
166 * Returns the SIP uri only as a string, that is display name is removed.
167 * The returned char * must be freed by the application. Use ms_free().
169 char *linphone_address_as_string_uri_only(const LinphoneAddress *u){
171 osip_uri_to_str(u->url,&tmp);
178 * Destroys a LinphoneAddress object.
180 void linphone_address_destroy(LinphoneAddress *u){