]> sjero.net Git - linphone/blob - coreapi/address.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / coreapi / address.c
1 /*
2 linphone
3 Copyright (C) 2009  Simon MORLAT (simon.morlat@linphone.org)
4
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.
9
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.
14
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.
18 */
19
20 #include "linphonecore.h"
21 #include "lpconfig.h"
22 #include "private.h"
23
24 /**
25  * @addtogroup linphone_address
26  * @{
27 **/
28
29 /**
30  * Constructs a LinphoneAddress object by parsing the user supplied address,
31  * given as a string.
32 **/
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);
36         return saddr;
37 }
38
39 /**
40  * Clones a LinphoneAddress object.
41 **/
42 LinphoneAddress * linphone_address_clone(const LinphoneAddress *addr){
43         return sal_address_clone(addr);
44 }
45
46 /**
47  * Returns the address scheme, normally "sip".
48 **/
49 const char *linphone_address_get_scheme(const LinphoneAddress *u){
50         return sal_address_get_scheme(u);
51 }
52
53 /**
54  * Returns the display name.
55 **/
56 const char *linphone_address_get_display_name(const LinphoneAddress* u){
57         return sal_address_get_display_name(u);
58 }
59
60 /**
61  * Returns the username.
62 **/
63 const char *linphone_address_get_username(const LinphoneAddress *u){
64         return sal_address_get_username(u);
65 }
66
67 /**
68  * Returns the domain name.
69 **/
70 const char *linphone_address_get_domain(const LinphoneAddress *u){
71         return sal_address_get_domain(u);
72 }
73
74 /**
75  * Sets the display name.
76 **/
77 void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
78         sal_address_set_display_name(u,display_name);
79 }
80
81 /**
82  * Sets the username.
83 **/
84 void linphone_address_set_username(LinphoneAddress *uri, const char *username){
85         sal_address_set_username(uri,username);
86 }
87
88 /**
89  * Sets the domain.
90 **/
91 void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
92         sal_address_set_domain(uri,host);
93 }
94
95 /**
96  * Sets the port number.
97 **/
98 void linphone_address_set_port(LinphoneAddress *uri, const char *port){
99         sal_address_set_port(uri,port);
100 }
101
102 /**
103  * Sets the port number.
104 **/
105 void linphone_address_set_port_int(LinphoneAddress *uri, int port){
106         sal_address_set_port_int(uri,port);
107 }
108
109 /**
110  * Removes address's tags and uri headers so that it is displayable to the user.
111 **/
112 void linphone_address_clean(LinphoneAddress *uri){
113         sal_address_clean(uri);
114 }
115
116 /**
117  * Returns the address as a string.
118  * The returned char * must be freed by the application. Use ms_free().
119 **/
120 char *linphone_address_as_string(const LinphoneAddress *u){
121         return sal_address_as_string(u);
122 }
123
124 /**
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().
127 **/
128 char *linphone_address_as_string_uri_only(const LinphoneAddress *u){
129         return sal_address_as_string_uri_only(u);
130 }
131
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;
135         return FALSE;
136 }
137
138 /**
139  * Compare two LinphoneAddress ignoring tags and headers, basically just domain, username, and port.
140  * Returns TRUE if they are equal.
141 **/
142 bool_t linphone_address_weak_equal(const LinphoneAddress *a1, const LinphoneAddress *a2){
143         const char *u1,*u2;
144         const char *h1,*h2;
145         int p1,p2;
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;
153 }
154
155 /**
156  * Destroys a LinphoneAddress object.
157 **/
158 void linphone_address_destroy(LinphoneAddress *u){
159         sal_address_destroy(u);
160 }
161
162 int linphone_address_get_port_int(const LinphoneAddress *u) {
163         return sal_address_get_port_int(u);
164 }
165
166 const char* linphone_address_get_port(const LinphoneAddress *u) {
167         return sal_address_get_port(u);
168 }
169
170 /** @} */