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"
25 * @addtogroup linphone_address
30 * Constructs a LinphoneAddress object by parsing the user supplied address,
33 LinphoneAddress * linphone_address_new(const char *addr){
34 SalAddress *saddr=sal_address_new(addr);
35 if (saddr==NULL) ms_error("Cannot create LinphoneAddress, bad uri [%s]",addr);
40 * Clones a LinphoneAddress object.
42 LinphoneAddress * linphone_address_clone(const LinphoneAddress *addr){
43 return sal_address_clone(addr);
47 * Returns the address scheme, normally "sip".
49 const char *linphone_address_get_scheme(const LinphoneAddress *u){
50 return sal_address_get_scheme(u);
54 * Returns the display name.
56 const char *linphone_address_get_display_name(const LinphoneAddress* u){
57 return sal_address_get_display_name(u);
61 * Returns the username.
63 const char *linphone_address_get_username(const LinphoneAddress *u){
64 return sal_address_get_username(u);
68 * Returns the domain name.
70 const char *linphone_address_get_domain(const LinphoneAddress *u){
71 return sal_address_get_domain(u);
75 * Sets the display name.
77 void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
78 sal_address_set_display_name(u,display_name);
84 void linphone_address_set_username(LinphoneAddress *uri, const char *username){
85 sal_address_set_username(uri,username);
91 void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
92 sal_address_set_domain(uri,host);
96 * Sets the port number.
98 void linphone_address_set_port(LinphoneAddress *uri, const char *port){
99 sal_address_set_port(uri,port);
103 * Sets the port number.
105 void linphone_address_set_port_int(LinphoneAddress *uri, int port){
106 sal_address_set_port_int(uri,port);
110 * Removes address's tags and uri headers so that it is displayable to the user.
112 void linphone_address_clean(LinphoneAddress *uri){
113 sal_address_clean(uri);
117 * Returns the address as a string.
118 * The returned char * must be freed by the application. Use ms_free().
120 char *linphone_address_as_string(const LinphoneAddress *u){
121 return sal_address_as_string(u);
125 * Returns the SIP uri only as a string, that is display name is removed.
126 * The returned char * must be freed by the application. Use ms_free().
128 char *linphone_address_as_string_uri_only(const LinphoneAddress *u){
129 return sal_address_as_string_uri_only(u);
132 static bool_t strings_equals(const char *s1, const char *s2){
133 if (s1==NULL && s2==NULL) return TRUE;
134 if (s1!=NULL && s2!=NULL && strcmp(s1,s2)==0) return TRUE;
139 * Compare two LinphoneAddress ignoring tags and headers, basically just domain, username, and port.
140 * Returns TRUE if they are equal.
142 bool_t linphone_address_weak_equal(const LinphoneAddress *a1, const LinphoneAddress *a2){
146 u1=linphone_address_get_username(a1);
147 u2=linphone_address_get_username(a2);
148 p1=linphone_address_get_port_int(a1);
149 p2=linphone_address_get_port_int(a2);
150 h1=linphone_address_get_domain(a1);
151 h2=linphone_address_get_domain(a2);
152 return strings_equals(u1,u2) && strings_equals(h1,h2) && p1==p2;
156 * Destroys a LinphoneAddress object.
158 void linphone_address_destroy(LinphoneAddress *u){
159 sal_address_destroy(u);
162 int linphone_address_get_port_int(const LinphoneAddress *u) {
163 return sal_address_get_port_int(u);
166 const char* linphone_address_get_port(const LinphoneAddress *u) {
167 return sal_address_get_port(u);