belle_sip_headers_tester.c 63 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  Belledonne Communications SARL

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation, either version 2 of the License, or
jehan's avatar
jehan committed
8 9 10 11 12 13 14 15 16 17 18 19 20
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "belle-sip/belle-sip.h"
jehan's avatar
jehan committed
21
#include "belle_sip_internal.h"
Ghislain MARY's avatar
Ghislain MARY committed
22
#include "belle_sip_tester.h"
jehan's avatar
jehan committed
23 24


Ghislain MARY's avatar
Ghislain MARY committed
25
static void test_simple_contact_header(void) {
26
	belle_sip_header_contact_t* L_tmp;
27
	belle_sip_uri_t* L_uri;
28
	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("m:sip:titi.com");
29 30
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
31 32 33
	L_tmp = belle_sip_header_contact_parse(l_raw_header);
	L_contact = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
34 35
	belle_sip_free(l_raw_header);

36
	L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);
jehan's avatar
jehan committed
37

38 39 40
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_transport_param(L_uri));
41
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
42

43
	BC_ASSERT_PTR_NULL(belle_sip_header_contact_parse("nimportequoi"));
jehan's avatar
jehan committed
44

jehan's avatar
jehan committed
45 46
}

Ghislain MARY's avatar
Ghislain MARY committed
47
static void test_complex_contact_header(void) {
48
	belle_sip_header_contact_t* L_contact;
49
	belle_sip_uri_t* L_uri;
50
	belle_sip_header_contact_t* L_tmp = belle_sip_header_contact_parse("Contact: \"j\x8eremis\" <sip:sip.linphone.org>;expires=3600;q=0.7, sip:titi.com");
51 52 53 54
	belle_sip_header_t* l_next;
	belle_sip_header_contact_t* L_next_contact;
	char* l_raw_header;
	float l_qvalue;
jehan's avatar
jehan committed
55

56 57
	L_contact = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
58

59
	L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);
jehan's avatar
jehan committed
60

61 62
	BC_ASSERT_PTR_NOT_NULL(L_uri);
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org");
jehan's avatar
jehan committed
63

64
	BC_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname((belle_sip_header_address_t*)L_contact), "j\x8eremis");
jehan's avatar
jehan committed
65

66
	BC_ASSERT_EQUAL(belle_sip_header_contact_get_expires(L_contact),3600,int,"%d");
67
	l_qvalue = belle_sip_header_contact_get_qvalue(L_contact);
68
	BC_ASSERT_EQUAL(l_qvalue,0.7f,float,"%f");
jehan's avatar
jehan committed
69

70 71
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_contact));
	L_next_contact = BELLE_SIP_HEADER_CONTACT(l_next);
72
	BC_ASSERT_PTR_NOT_NULL(L_next_contact);
Simon Morlat's avatar
Simon Morlat committed
73
	BC_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_contact)));
jehan's avatar
jehan committed
74

75
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
76

77
	L_contact = belle_sip_header_contact_parse("Contact: super toto <sip:titi.com>;expires=3600; q=0.7");
78
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
79
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
80

81 82
	L_contact = belle_sip_header_contact_parse(l_raw_header);
	belle_sip_free(l_raw_header);
83
	BC_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname((belle_sip_header_address_t*)L_contact), "super toto");
84
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
85

86
	BC_ASSERT_PTR_NULL(belle_sip_header_contact_parse("m:sip:titi.com, nimportequoi"));
jehan's avatar
jehan committed
87 88
}

Ghislain MARY's avatar
Ghislain MARY committed
89
static void test_from_header(void) {
90
	belle_sip_header_from_t* L_tmp;
91
	belle_sip_uri_t* L_uri;
92
	belle_generic_uri_t* L_absoluteUri;
93
	belle_sip_header_from_t* L_from = belle_sip_header_from_parse("f:<sip:titi.com;transport=tcp>;tag=dlfjklcn6545614XX");
94 95
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_from));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
96 97 98
	L_tmp = belle_sip_header_from_parse(l_raw_header);
	L_from = BELLE_SIP_HEADER_FROM(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
99 100
	belle_sip_free(l_raw_header);

101
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
102

103 104 105
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
106
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
jehan's avatar
jehan committed
107

108 109 110 111 112 113 114 115 116
	L_from = belle_sip_header_from_parse("From: <tel:+33124585454;toto=titi>;tag=dlfjklcn6545614XX");
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_from));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
	L_tmp = belle_sip_header_from_parse(l_raw_header);
	L_from = BELLE_SIP_HEADER_FROM(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);

	L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
117 118 119 120
	BC_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from)));
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "+33124585454;toto=titi");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
121 122 123
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));


jehan's avatar
jehan committed
124
	/*test factory*/
jehan's avatar
jehan committed
125
	L_from = belle_sip_header_from_create2("super <sip:titi.com:5060;lr;ttl=1;method=INVITE;maddr=192.168.0.1;transport=tcp?header=123>","12345-abc");
126
	if (!BC_ASSERT_PTR_NOT_NULL(L_from)) return;
jehan's avatar
jehan committed
127
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
128
	if (!BC_ASSERT_PTR_NOT_NULL(L_uri)) return;
129 130 131 132 133 134
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"lr"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"ttl"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"method"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"maddr"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"transport"));
	BC_ASSERT_FALSE(belle_sip_uri_get_port(L_uri)>0);
135
	BC_ASSERT_EQUAL((unsigned int)belle_sip_list_size(belle_sip_uri_get_header_names(L_uri)),0,unsigned int,"%u");
136 137 138

	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"12345-abc");
jehan's avatar
jehan committed
139
	belle_sip_object_unref(L_from);
jehan's avatar
jehan committed
140

141
	BC_ASSERT_PTR_NULL(belle_sip_header_from_parse("nimportequoi"));
142 143
}

Ghislain MARY's avatar
Ghislain MARY committed
144
static void test_from_header_with_paramless_address_spec(void) {
145
	belle_generic_uri_t *L_absoluteUri;
jehan's avatar
jehan committed
146
	belle_sip_header_from_t* L_from = belle_sip_header_from_parse("From: sip:bob@titi.com;tag=dlfjklcn6545614XX");
147
	if (!BC_ASSERT_PTR_NOT_NULL(belle_sip_header_from_get_tag(L_from))) return;
148
	BC_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
jehan's avatar
jehan committed
149
	belle_sip_object_unref(L_from);
150 151

	L_from = belle_sip_header_from_parse("From: tel:1234567;tag=dlfjklcn6545614XX");
152
	if (!BC_ASSERT_PTR_NOT_NULL(belle_sip_header_from_get_tag(L_from))) return;
153
	L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
154 155 156 157
	BC_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from)));
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "1234567");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
158 159
	belle_sip_object_unref(L_from);

jehan's avatar
jehan committed
160
}
Ghislain MARY's avatar
Ghislain MARY committed
161 162

static void test_to_header_with_paramless_address_spec(void) {
163
	belle_generic_uri_t *L_absoluteUri;
jehan's avatar
jehan committed
164
	belle_sip_header_to_t* L_to = belle_sip_header_to_parse("To: sip:bob@titi.com;tag=dlfjklcn6545614XX");
165
	belle_sip_uri_t *L_uri;
166
	if (!BC_ASSERT_PTR_NOT_NULL(belle_sip_header_to_get_tag(L_to))) return;
167
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
jehan's avatar
jehan committed
168
	belle_sip_object_unref(L_to);
169

170
	L_to = belle_sip_header_to_parse("To:sip:1002@192.168.1.199;tag=as1f0a0817");
171
	if (!BC_ASSERT_PTR_NOT_NULL(belle_sip_header_to_get_tag(L_to))) return;
172
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
173 174
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"1002");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "192.168.1.199");
175

176
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"as1f0a0817");
177 178
	belle_sip_object_unref(L_to);

179
	L_to = belle_sip_header_to_parse("To: tel:1234567;tag=dlfjklcn6545614XX");
180
	if (!BC_ASSERT_PTR_NOT_NULL(belle_sip_header_to_get_tag(L_to))) return;
181
	L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
182 183 184 185
	BC_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to)));
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "1234567");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
186
	belle_sip_object_unref(L_to);
187
	BC_ASSERT_PTR_NULL(belle_sip_header_to_parse("nimportequoi"));
jehan's avatar
jehan committed
188
}
Ghislain MARY's avatar
Ghislain MARY committed
189 190

static void test_contact_header_with_paramless_address_spec(void) {
jehan's avatar
jehan committed
191
	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact: sip:bob@titi.com;expires=60");
192
	BC_ASSERT_EQUAL(belle_sip_header_contact_get_expires(L_contact),60,int,"%d");
jehan's avatar
jehan committed
193 194 195
	belle_sip_object_unref(L_contact);
}

Ghislain MARY's avatar
Ghislain MARY committed
196
static void test_to_header(void) {
197
	belle_sip_uri_t* L_uri;
198 199
	belle_generic_uri_t* L_absoluteUri;
	belle_sip_header_to_t *L_tmp, *L_to = belle_sip_header_to_parse("t : < sip:titi.com;transport=tcp> ; tag = dlfjklcn6545614XX");
200 201 202 203 204
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_to));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
	L_to = belle_sip_header_to_parse(l_raw_header);
	belle_sip_free(l_raw_header);

205
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
206

207 208 209
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
210
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
jehan's avatar
jehan committed
211
	/*test factory*/
jehan's avatar
jehan committed
212
	L_to = belle_sip_header_to_create2("\"super man\" <sip:titi.com:5060;lr;ttl=1;method=INVITE;maddr=192.168.0.1;transport=tcp?header=123>","12345-abc");
213
	if (!BC_ASSERT_PTR_NOT_NULL(L_to)) return;
jehan's avatar
jehan committed
214
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
215 216 217 218 219 220
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"lr"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"ttl"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"method"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"maddr"));
	BC_ASSERT_FALSE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri),"transport"));
	BC_ASSERT_FALSE(belle_sip_uri_get_port(L_uri)>0);
221
	BC_ASSERT_EQUAL((unsigned int)belle_sip_list_size(belle_sip_uri_get_header_names(L_uri)),0,unsigned int,"%u");
222

223
	if (!BC_ASSERT_PTR_NOT_NULL(L_uri)) return;
224 225
	BC_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(L_to)), "super man");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"12345-abc");
jehan's avatar
jehan committed
226 227
	belle_sip_object_unref(L_to);

228 229 230 231 232 233 234 235 236
	L_to = belle_sip_header_to_parse("To: <tel:+33124585454;toto=titi>;tag=dlfjklcn6545614XX");
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_to));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
	L_tmp = belle_sip_header_to_parse(l_raw_header);
	L_to = BELLE_SIP_HEADER_TO(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);

	L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
237 238 239 240
	BC_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to)));
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "+33124585454;toto=titi");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
241 242 243
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));


244
}
Ghislain MARY's avatar
Ghislain MARY committed
245 246

static void test_via_header(void) {
247
	belle_sip_header_via_t* L_tmp;
248 249
	belle_sip_header_t* l_next;
	belle_sip_header_via_t* L_next_via;
250
	belle_sip_header_via_t* L_via = belle_sip_header_via_parse("v: SIP/2.0/UDP [::1]:5062;rport;received=::1;branch=z9hG4bK368560724");
251 252
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_via));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
253 254 255
	L_tmp = belle_sip_header_via_parse(l_raw_header);
	L_via = BELLE_SIP_HEADER_VIA(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
256 257
	belle_sip_free(l_raw_header);

258 259 260 261
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_protocol(L_via), "SIP/2.0");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_transport(L_via), "UDP");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_via), "::1");
	BC_ASSERT_EQUAL(belle_sip_header_via_get_port(L_via),5062,int,"%d");
262

263 264 265
	BC_ASSERT_TRUE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_via),"rport"));
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_received(L_via),"::1");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_branch(L_via),"z9hG4bK368560724");
266
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
jehan's avatar
jehan committed
267

268
	L_via = belle_sip_header_via_parse("Via: SIP/2.0/UDP 192.168.0.19:5062;received=192.169.0.4;rport=1234;branch=z9hG4bK368560724, SIP/2.0/UDP 192.168.0.19:5062");
jehan's avatar
jehan committed
269

270 271
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_via));
	L_next_via = BELLE_SIP_HEADER_VIA(l_next);
272 273 274 275
	BC_ASSERT_PTR_NOT_NULL(L_next_via);
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_next_via),"192.168.0.19");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_via_get_received(L_via),"192.169.0.4");
	BC_ASSERT_EQUAL(belle_sip_header_via_get_rport(L_via),1234,int,"%d");
jehan's avatar
jehan committed
276 277
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));

278 279
	BC_ASSERT_PTR_NULL(belle_sip_header_via_parse("nimportequoi"));
	BC_ASSERT_PTR_NULL(belle_sip_header_contact_parse("Via: SIP/2.0/UDP 192.168.0.19:5062;branch=z9hG4bK368560724, nimportequoi"));
280
}
Ghislain MARY's avatar
Ghislain MARY committed
281 282

static void test_call_id_header(void) {
283
	belle_sip_header_call_id_t* L_tmp;
284
	belle_sip_header_call_id_t* L_call_id = belle_sip_header_call_id_parse("i: 1665237789@titi.com");
285 286
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_call_id));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_call_id));
287 288 289
	L_tmp= belle_sip_header_call_id_parse(l_raw_header);
	L_call_id = BELLE_SIP_HEADER_CALL_ID(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
290 291
	belle_sip_free(l_raw_header);

292
	BC_ASSERT_STRING_EQUAL(belle_sip_header_call_id_get_call_id(L_call_id), "1665237789@titi.com");
jehan's avatar
jehan committed
293
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_call_id));
294
	BC_ASSERT_PTR_NULL(belle_sip_header_call_id_parse("nimportequoi"));
295
}
Ghislain MARY's avatar
Ghislain MARY committed
296 297

static void test_cseq_header(void) {
298
	belle_sip_header_cseq_t* L_tmp;
299
	belle_sip_header_cseq_t* L_cseq = belle_sip_header_cseq_parse("CSeq: 21 INVITE");
300 301
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_cseq));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_cseq));
302 303 304
	L_tmp = belle_sip_header_cseq_parse(l_raw_header);
	L_cseq = BELLE_SIP_HEADER_CSEQ(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
305 306
	belle_sip_free(l_raw_header);

307 308
	BC_ASSERT_EQUAL(belle_sip_header_cseq_get_seq_number(L_cseq),21,int,"%d");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_cseq_get_method(L_cseq),"INVITE");
309
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_cseq));
jehan's avatar
jehan committed
310 311 312

	/*test factory*/
	L_cseq = belle_sip_header_cseq_create(1,"INFO");
313 314
	BC_ASSERT_EQUAL(belle_sip_header_cseq_get_seq_number(L_cseq),1,int,"%d");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_cseq_get_method(L_cseq),"INFO");
jehan's avatar
jehan committed
315
	belle_sip_object_unref(L_cseq);
316
	BC_ASSERT_PTR_NULL(belle_sip_header_cseq_parse("nimportequoi"));
317
}
Ghislain MARY's avatar
Ghislain MARY committed
318 319

static void test_content_type_header(void) {
320
	belle_sip_header_content_type_t* L_tmp;
321
	belle_sip_header_content_type_t* L_content_type = belle_sip_header_content_type_parse("c: text/html; charset=ISO-8859-4");
322 323
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
324 325 326
	L_tmp = belle_sip_header_content_type_parse(l_raw_header);
	L_content_type = BELLE_SIP_HEADER_CONTENT_TYPE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
327 328
	belle_sip_free(l_raw_header);

329 330 331
	BC_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_type(L_content_type),"text");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"html");
	BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_content_type),"charset"),"ISO-8859-4");
332
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
333 334

	L_content_type = belle_sip_header_content_type_parse("Content-Type: application/sdp");
335 336 337 338
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
	L_content_type = belle_sip_header_content_type_parse(l_raw_header);
	belle_sip_free(l_raw_header);
339 340
	BC_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_type(L_content_type),"application");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"sdp");
341 342 343
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));

	L_content_type = belle_sip_header_content_type_parse("Content-Type: application/pkcs7-mime; smime-type=enveloped-data; \r\n name=smime.p7m");
344 345 346 347
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
	L_content_type = belle_sip_header_content_type_parse(l_raw_header);
	belle_sip_free(l_raw_header);
348
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
jehan's avatar
jehan committed
349 350 351 352 353 354 355 356

	L_content_type = belle_sip_header_content_type_parse("Content-Type: multipart/related; type=application/rlmi+xml");
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
	L_tmp = belle_sip_header_content_type_parse(l_raw_header);
	L_content_type = BELLE_SIP_HEADER_CONTENT_TYPE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);
357

jehan's avatar
jehan committed
358 359 360 361 362
	BC_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_type(L_content_type),"multipart");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"related");
	BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_content_type),"type"),"application/rlmi+xml");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));

363 364 365



366
	BC_ASSERT_PTR_NULL(belle_sip_header_content_type_parse("nimportequoi"));
367
}
Ghislain MARY's avatar
Ghislain MARY committed
368 369

static void test_record_route_header(void) {
370 371 372
	belle_sip_uri_t* L_uri;
	belle_sip_header_t* l_next;
	belle_sip_header_record_route_t* L_next_route;
373
	belle_sip_header_record_route_t* L_record_route = belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4");
374 375 376 377
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_record_route));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
	L_record_route = belle_sip_header_record_route_parse(l_raw_header);
	belle_sip_free(l_raw_header);
378
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_record_route));
379 380 381
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "212.27.52.5");
	BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_record_route),"charset"),"ISO-8859-4");
382
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
jehan's avatar
jehan committed
383 384

	L_record_route = belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:212.27.52.5:5060;transport=udp;lr>");
385 386
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_record_route));
	L_next_route = BELLE_SIP_HEADER_RECORD_ROUTE(l_next);
387 388
	BC_ASSERT_PTR_NOT_NULL(L_next_route);
	BC_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
jehan's avatar
jehan committed
389
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
390 391 392
	BC_ASSERT_PTR_NULL(belle_sip_header_record_route_parse("nimportequoi"));
	BC_ASSERT_PTR_NULL(belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060>, nimportequoi"));

393 394 395 396
	L_record_route=belle_sip_header_record_route_parse("Record-route: <sip:212.27.52.5:5060>");
	l_raw_header=belle_sip_object_to_string(L_record_route);
	belle_sip_object_unref(L_record_route);
	L_record_route=belle_sip_header_record_route_parse(l_raw_header);
397
	BC_ASSERT_PTR_NOT_NULL(L_record_route);
398 399
	if (L_record_route) belle_sip_object_unref(L_record_route);
	belle_sip_free(l_raw_header);
400
}
Ghislain MARY's avatar
Ghislain MARY committed
401 402

static void test_route_header(void) {
403 404 405 406
	belle_sip_header_route_t* L_route;
	belle_sip_uri_t* L_uri;
	belle_sip_header_t* l_next;
	belle_sip_header_route_t* L_next_route;
jehan's avatar
jehan committed
407
	belle_sip_header_address_t* address = belle_sip_header_address_parse("<sip:212.27.52.5:5060;transport=udp;lr>");
408
	char* l_raw_header;
409
	belle_sip_header_record_route_t* L_record_route;
410

411
	if (!BC_ASSERT_PTR_NOT_NULL(address)) return;
412
	L_route = belle_sip_header_route_create(address);
Simon Morlat's avatar
Simon Morlat committed
413
	belle_sip_object_unref(address);
414
	if (!BC_ASSERT_PTR_NOT_NULL(L_route)) return;
415
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_route));
416 417 418
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
	L_route = belle_sip_header_route_parse(l_raw_header);
	belle_sip_free(l_raw_header);
419
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_route));
420 421
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060,int,"%d");
jehan's avatar
jehan committed
422

423
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
424 425

	L_route = belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:titi.com>");
426 427
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_route));
	L_next_route = BELLE_SIP_HEADER_ROUTE(l_next);
428 429
	BC_ASSERT_PTR_NOT_NULL(L_next_route);
	BC_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
jehan's avatar
jehan committed
430
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
431

432 433
	BC_ASSERT_PTR_NULL(belle_sip_header_route_parse("nimportequoi"));
	BC_ASSERT_PTR_NULL(belle_sip_header_contact_parse("Route: <sip:212.27.52.5:5060>, nimportequoi"));
jehan's avatar
jehan committed
434

435 436 437 438
	L_route=belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060>");
	l_raw_header=belle_sip_object_to_string(L_route);
	belle_sip_object_unref(L_route);
	L_route=belle_sip_header_route_parse(l_raw_header);
439
	BC_ASSERT_PTR_NOT_NULL(L_route);
440
	if (L_route) belle_sip_object_unref(L_route);
441

442 443 444 445 446 447 448 449 450
	L_record_route = belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:212.27.52.5:5060;transport=udp;lr>");
	L_route = belle_sip_header_route_create(BELLE_SIP_HEADER_ADDRESS(L_record_route));
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_route));
	BC_ASSERT_PTR_NULL(belle_sip_header_get_next(BELLE_SIP_HEADER(L_route)));
	BC_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060,int,"%d");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "212.27.52.5");
	belle_sip_object_unref(L_record_route);
	belle_sip_object_unref(L_route);
451
	belle_sip_free(l_raw_header);
452

453
}
Ghislain MARY's avatar
Ghislain MARY committed
454 455

static void test_service_route_header(void) {
jehan's avatar
jehan committed
456
	belle_sip_header_service_route_t* L_service_route = belle_sip_header_service_route_parse("Service-Route: <sip:orig@scscf.ims.linphone.com:6060;lr>");
457 458
	belle_sip_uri_t* L_uri;
	char* l_raw_header;
459
	if (!BC_ASSERT_PTR_NOT_NULL(L_service_route)) return;
460
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_service_route));
jehan's avatar
jehan committed
461 462 463
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
	L_service_route = belle_sip_header_service_route_parse(l_raw_header);
	belle_sip_free(l_raw_header);
464
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_service_route));
465 466
	BC_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 6060,int,"%d");
jehan's avatar
jehan committed
467
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
468
	BC_ASSERT_PTR_NULL(belle_sip_header_service_route_parse("nimportequoi"));
jehan's avatar
jehan committed
469
}
Ghislain MARY's avatar
Ghislain MARY committed
470 471

static void test_content_length_header(void) {
472
	belle_sip_header_content_length_t* L_tmp;
jehan's avatar
jehan committed
473
	belle_sip_header_content_length_t* L_content_length = belle_sip_header_content_length_parse("Content-Length: 3495");
474 475
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_length));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_length));
476 477 478
	L_tmp = belle_sip_header_content_length_parse(l_raw_header);
	L_content_length = BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
479
	belle_sip_free(l_raw_header);
480
	BC_ASSERT_EQUAL((unsigned int)belle_sip_header_content_length_get_content_length(L_content_length), 3495, unsigned int, "%u");
jehan's avatar
jehan committed
481
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_length));
482
	BC_ASSERT_PTR_NULL(belle_sip_header_content_length_parse("nimportequoi"));
jehan's avatar
jehan committed
483
}
Ghislain MARY's avatar
Ghislain MARY committed
484

jehan's avatar
jehan committed
485 486
static belle_sip_header_t* test_header_extension(const char* name,const char* value) {
	belle_sip_header_t* L_tmp;
487
	belle_sip_header_t* L_extension;
488 489 490
	char header[256];
	char* l_raw_header=NULL;
	snprintf(header,sizeof(header),"%s:%s",name,value);
jehan's avatar
jehan committed
491
	L_extension = belle_sip_header_parse(header);
492
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_extension));
493
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_extension));
jehan's avatar
jehan committed
494 495
	L_tmp = belle_sip_header_parse(l_raw_header);
	L_extension = BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
496
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
497 498
	belle_sip_free(l_raw_header);

499
	BC_ASSERT_STRING_EQUAL(belle_sip_header_get_unparsed_value(L_extension), value);
jehan's avatar
jehan committed
500

jehan's avatar
jehan committed
501
	/*FIXME jehan check why missing colon does not lead an exception
502
	BC_ASSERT_PTR_NULL(belle_sip_header_extension_parse("nimportequoi"));*/
jehan's avatar
jehan committed
503
	return L_extension;
504
}
505
static void test_header_extension_1(void) {
jehan's avatar
jehan committed
506
	belle_sip_object_unref(test_header_extension("toto","titi"));
507
}
508
static void test_header_extension_2(void) {
jehan's avatar
jehan committed
509
	belle_sip_header_t* header = test_header_extension("From","sip:localhost");
510
	BC_ASSERT_TRUE(BELLE_SIP_OBJECT_IS_INSTANCE_OF(header,belle_sip_header_from_t));
jehan's avatar
jehan committed
511
	belle_sip_object_unref(header);
512
}
Ghislain MARY's avatar
Ghislain MARY committed
513 514

static void test_authorization_header(void) {
515
	const char* l_header = "Authorization: Digest username=\"0033482532176\", "\
516
			"realm=\"sip.ovh.net\", nonce=\"1bcdcb194b30df5f43973d4c69bdf54f\", uri=\"sip:sip.ovh.net\", response=\"eb36c8d5c8642c1c5f44ec3404613c81\","\
517 518
			"algorithm=MD5, opaque=\"1bc7f9097684320\","
			"\r\n qop=auth, nc=00000001,cnonce=\"0a4f113b\", blabla=\"toto\"";
519
	belle_sip_header_authorization_t* L_tmp;
520 521 522
	belle_sip_header_authorization_t* L_authorization = belle_sip_header_authorization_parse(l_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_authorization));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
523 524 525
	L_tmp = belle_sip_header_authorization_parse(l_raw_header);
	L_authorization = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
526 527
	belle_sip_free(l_raw_header);

528
	if (!BC_ASSERT_PTR_NOT_NULL(L_authorization)) return;
529 530 531 532 533 534 535 536 537 538 539 540 541
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_scheme(L_authorization), "Digest");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(L_authorization), "0033482532176");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_realm(L_authorization), "sip.ovh.net");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(L_authorization), "1bcdcb194b30df5f43973d4c69bdf54f");
	BC_ASSERT_PTR_NOT_NULL(belle_sip_header_authorization_get_uri(L_authorization));
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(L_authorization), "eb36c8d5c8642c1c5f44ec3404613c81");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_algorithm(L_authorization), "MD5");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_opaque(L_authorization), "1bc7f9097684320");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_qop(L_authorization), "auth");

	BC_ASSERT_EQUAL(belle_sip_header_authorization_get_nonce_count(L_authorization), 1,int,"%d");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_cnonce(L_authorization), "0a4f113b");
	BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_authorization), "blabla"),"\"toto\"");
542
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
543
	BC_ASSERT_PTR_NULL(belle_sip_header_authorization_parse("nimportequoi"));
544
}
Ghislain MARY's avatar
Ghislain MARY committed
545 546

static void test_proxy_authorization_header(void) {
547
	const char* l_header = "Proxy-Authorization: Digest username=\"Alice\""
548 549
			", realm=\"atlanta.com\", nonce=\"c60f3082ee1212b402a21831ae\""
			", response=\"245f23415f11432b3434341c022\"";
550 551 552 553 554
	belle_sip_header_proxy_authorization_t* L_authorization = belle_sip_header_proxy_authorization_parse(l_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_authorization));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
	L_authorization = belle_sip_header_proxy_authorization_parse(l_raw_header);
	belle_sip_free(l_raw_header);
555 556 557 558
	BC_ASSERT_PTR_NOT_NULL(L_authorization);
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "Alice");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_realm(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "atlanta.com");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "c60f3082ee1212b402a21831ae");
jehan's avatar
jehan committed
559
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
560
	BC_ASSERT_PTR_NULL(belle_sip_header_proxy_authorization_parse("nimportequoi"));
jehan's avatar
jehan committed
561
}
Ghislain MARY's avatar
Ghislain MARY committed
562

jehan's avatar
jehan committed
563 564
static void check_header_authenticate(belle_sip_header_www_authenticate_t* authenticate) {
	belle_sip_list_t* qop;
565 566 567 568 569 570 571
	BC_ASSERT_PTR_NOT_NULL(authenticate);
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_realm(authenticate), "atlanta.com");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_domain(authenticate), "sip:boxesbybob.com");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_nonce(authenticate), "c60f3082ee1212b402a21831ae");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_algorithm(authenticate), "MD5");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_opaque(authenticate), "1bc7f9097684320");

572
	if (!BC_ASSERT_PTR_NOT_NULL(qop=belle_sip_header_www_authenticate_get_qop(authenticate))) return;
573
	BC_ASSERT_STRING_EQUAL((const char*)qop->data, "auth");
574
	if (!BC_ASSERT_PTR_NOT_NULL(qop=qop->next)) return;
575 576 577 578 579
	BC_ASSERT_STRING_EQUAL((const char*)qop->data, "auth-int");

	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_qop(authenticate)->data, "auth");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_scheme(authenticate), "Digest");
	BC_ASSERT_EQUAL(belle_sip_header_www_authenticate_is_stale(authenticate),1,int,"%d");
jehan's avatar
jehan committed
580
	belle_sip_object_unref(BELLE_SIP_OBJECT(authenticate));
jehan's avatar
jehan committed
581

jehan's avatar
jehan committed
582
}
Ghislain MARY's avatar
Ghislain MARY committed
583 584

static void test_www_authenticate_header(void) {
585
	const char* l_header = "WWW-Authenticate: Digest "
586
			"algorithm=MD5,\r\n   realm=\"atlanta.com\",\r\n  opaque=\"1bc7f9097684320\","
jehan's avatar
jehan committed
587
			" qop=\"auth,auth-int\", nonce=\"c60f3082ee1212b402a21831ae\", stale=true, domain=\"sip:boxesbybob.com\"";
588 589 590 591
	const char* l_header_1 = "WWW-Authenticate: Digest realm=\"toto.com\",\r\n   nonce=\"b543409177c9036dbf3054aea940e9703dc8f84c0108\""
			",\r\n   opaque=\"ALU:QbkRBthOEgEQAkgVEwwHRAIBHgkdHwQCQ1lFRkRWEAkic203MSEzJCgoZS8iI3VlYWRj\",\r\n   algorithm=MD5"
			",\r\n   qop=\"auth\"";

592 593 594
	const char* l_header_2 = "WWW-Authenticate: Basic realm=\"WallyWorld\"";


595
	belle_sip_header_www_authenticate_t* L_tmp;
596
	belle_sip_header_www_authenticate_t *l_authenticate = belle_sip_header_www_authenticate_parse(l_header);
jehan's avatar
jehan committed
597 598 599 600


	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_authenticate));
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));
601
	L_tmp = belle_sip_header_www_authenticate_parse(l_raw_header);
jehan's avatar
jehan committed
602
	l_authenticate = BELLE_SIP_HEADER_WWW_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
603
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
604
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
605
	check_header_authenticate(l_authenticate);
606 607 608 609 610 611


	l_authenticate = belle_sip_header_www_authenticate_parse(l_header_1);
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_authenticate));
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));
	L_tmp = belle_sip_header_www_authenticate_parse(l_raw_header);
612
	belle_sip_free(l_raw_header);
613
	l_authenticate = BELLE_SIP_HEADER_WWW_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
614 615 616 617 618
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));

	l_authenticate = belle_sip_header_www_authenticate_parse(l_header_2);
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_authenticate));
619
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));
620 621 622 623 624 625 626 627
	L_tmp = belle_sip_header_www_authenticate_parse(l_raw_header);
	belle_sip_free(l_raw_header);
	l_authenticate = BELLE_SIP_HEADER_WWW_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(l_authenticate),"realm"),"\"WallyWorld\"");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_scheme(l_authenticate),"Basic");
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));

628

629
	BC_ASSERT_PTR_NULL(belle_sip_header_www_authenticate_parse("nimportequoi"));
jehan's avatar
jehan committed
630 631

}
Ghislain MARY's avatar
Ghislain MARY committed
632 633

static void test_proxy_authenticate_header(void) {
jehan's avatar
jehan committed
634 635 636 637 638
	const char* l_header = "Proxy-Authenticate: Digest "
			"algorithm=MD5, realm=\"atlanta.com\", opaque=\"1bc7f9097684320\","
			" qop=\"auth,auth-int\", nonce=\"c60f3082ee1212b402a21831ae\", stale=true, domain=\"sip:boxesbybob.com\"";
	belle_sip_header_proxy_authenticate_t* L_tmp;
	belle_sip_header_proxy_authenticate_t* L_proxy_authorization = belle_sip_header_proxy_authenticate_parse(l_header);
639
	//belle_sip_list_t* qop;
jehan's avatar
jehan committed
640 641 642 643 644 645 646 647

	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_proxy_authorization));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_proxy_authorization));
	L_tmp = belle_sip_header_proxy_authenticate_parse(l_raw_header);
	L_proxy_authorization = BELLE_SIP_HEADER_PROXY_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);
	check_header_authenticate(BELLE_SIP_HEADER_WWW_AUTHENTICATE(L_proxy_authorization));
648
	BC_ASSERT_PTR_NULL(belle_sip_header_proxy_authenticate_parse("nimportequoi"));
jehan's avatar
jehan committed
649
}
jehan's avatar
jehan committed
650

Ghislain MARY's avatar
Ghislain MARY committed
651
static void test_max_forwards_header(void) {
jehan's avatar
jehan committed
652
	const char* l_header = "Max-Forwards: 6";
653
	belle_sip_header_max_forwards_t* L_tmp;
jehan's avatar
jehan committed
654
	belle_sip_header_max_forwards_t* L_max_forwards = belle_sip_header_max_forwards_parse(l_header);
655
	char* l_raw_header;
jehan's avatar
jehan committed
656
	belle_sip_header_max_forwards_decrement_max_forwards(L_max_forwards);
657
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_max_forwards));
jehan's avatar
jehan committed
658
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
659 660 661 662
	L_tmp = belle_sip_header_max_forwards_parse(l_raw_header);
	L_max_forwards = BELLE_SIP_HEADER_MAX_FORWARDS(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));

jehan's avatar
jehan committed
663
	belle_sip_free(l_raw_header);
664 665
	BC_ASSERT_PTR_NOT_NULL(L_max_forwards);
	BC_ASSERT_EQUAL(belle_sip_header_max_forwards_get_max_forwards(L_max_forwards), 5,int,"%d");
jehan's avatar
jehan committed
666 667

	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
668
	BC_ASSERT_PTR_NULL(belle_sip_header_max_forwards_parse("nimportequoi"));
jehan's avatar
jehan committed
669

670
}
Ghislain MARY's avatar
Ghislain MARY committed
671 672

static void test_user_agent_header(void) {
673
	const char* l_header = "User-Agent: Linphone/3.4.99.1 (eXosip2/3.3.0)";
674 675 676
	const char* values[] ={"Linphone/3.4.99.1"
				,"(eXosip2/3.3.0)"};
	belle_sip_list_t* products;
677
	belle_sip_header_user_agent_t* L_tmp;
678 679
	belle_sip_header_user_agent_t* L_user_agent = belle_sip_header_user_agent_parse(l_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_user_agent));
680
	int i=0;
681
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
682 683 684 685
	L_tmp = belle_sip_header_user_agent_parse(l_raw_header);
	L_user_agent = BELLE_SIP_HEADER_USER_AGENT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));

686 687
	belle_sip_free(l_raw_header);

688
	products = belle_sip_header_user_agent_get_products(L_user_agent);
689 690

	for(i=0;i<2;i++){
691 692
		BC_ASSERT_PTR_NOT_NULL(products);
		BC_ASSERT_STRING_EQUAL((const char *)(products->data),values[i]);
693 694 695 696
		products=products->next;
	}

	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
697
	BC_ASSERT_PTR_NULL(belle_sip_header_user_agent_parse("nimportequoi"));
698 699

}
Ghislain MARY's avatar
Ghislain MARY committed
700 701

static void test_expires_header(void) {
702
	belle_sip_header_expires_t* L_tmp;
703 704 705
	belle_sip_header_expires_t* L_expires = belle_sip_header_expires_parse("Expires: 3600");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_expires));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
706 707 708
	L_tmp= belle_sip_header_expires_parse(l_raw_header);
	L_expires = BELLE_SIP_HEADER_EXPIRES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
709
	belle_sip_free(l_raw_header);
710
	BC_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 3600,int,"%d");
711
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
jehan's avatar
jehan committed
712 713
	/*test factory*/
	L_expires = belle_sip_header_expires_create(600);
714
	BC_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 600,int,"%d");
jehan's avatar
jehan committed
715
	belle_sip_object_unref(L_expires);
716
	BC_ASSERT_PTR_NULL(belle_sip_header_expires_parse("nimportequoi"));
717
}
Ghislain MARY's avatar
Ghislain MARY committed
718 719

static void test_allow_header(void) {
720
	belle_sip_header_allow_t* L_tmp;
721 722 723
	belle_sip_header_allow_t* L_allow = belle_sip_header_allow_parse("Allow:INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_allow));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
724 725 726
	L_tmp = belle_sip_header_allow_parse(l_raw_header);
	L_allow = BELLE_SIP_HEADER_ALLOW(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
727 728
	belle_sip_free(l_raw_header);

729
	BC_ASSERT_STRING_EQUAL(belle_sip_header_allow_get_method(L_allow), "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
730
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
731
	BC_ASSERT_PTR_NULL(belle_sip_header_allow_parse("nimportequoi"));
732 733
}

Ghislain MARY's avatar
Ghislain MARY committed
734
static void test_address_with_error_header(void) {
jehan's avatar
jehan committed
735
	belle_sip_header_address_t* laddress = belle_sip_header_address_parse("sip:liblinphone_tester@=auth1.example.org");
736
	BC_ASSERT_PTR_NULL(laddress);
737
	laddress = belle_sip_header_address_parse("liblinphone_tester");
738
	BC_ASSERT_PTR_NULL(laddress);
jehan's avatar
jehan committed
739
}
jehan's avatar
jehan committed
740

Ghislain MARY's avatar
Ghislain MARY committed
741
static void test_address_header(void) {
742
	belle_sip_uri_t* L_uri;
743
	char* L_raw;
744
	belle_sip_header_address_t* laddress = belle_sip_header_address_fast_parse("\"toto\" <sip:liblinphone_tester@81.56.11.2:5060>");
745
	BC_ASSERT_PTR_NOT_NULL(laddress);
746
	L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
747
	BC_ASSERT_PTR_NOT_NULL(L_raw);
748 749 750 751
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
	laddress = belle_sip_header_address_parse(L_raw);
	belle_sip_free(L_raw);

752
	BC_ASSERT_STRING_EQUAL("toto",belle_sip_header_address_get_displayname(laddress));
753
	L_uri = belle_sip_header_address_get_uri(laddress);
jehan's avatar
jehan committed
754

755 756 757 758
	BC_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "81.56.11.2");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "liblinphone_tester");
	BC_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060,int,"%d");
jehan's avatar
jehan committed
759
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
760 761

	laddress = belle_sip_header_address_parse("\"\\\"to\\\\to\\\"\" <sip:liblinphone_tester@81.56.11.2:5060>");
762
	BC_ASSERT_PTR_NOT_NULL(laddress);
763
	L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
764
	BC_ASSERT_PTR_NOT_NULL(L_raw);
765 766 767
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
	laddress = belle_sip_header_address_parse(L_raw);
	belle_sip_free(L_raw);
768
	BC_ASSERT_STRING_EQUAL("\"to\\to\"",belle_sip_header_address_get_displayname(laddress));
769 770
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));

771 772 773 774 775 776 777 778 779
	laddress = belle_sip_header_address_parse("sips:example.com;transport=tls;maddr=sip1.example.com");
	BC_ASSERT_PTR_NOT_NULL(laddress);
	L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
	BC_ASSERT_PTR_NOT_NULL(L_raw);
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
	laddress = belle_sip_header_address_parse(L_raw);
	belle_sip_free(L_raw);
	BC_ASSERT_STRING_EQUAL("sip1.example.com",belle_sip_uri_get_maddr_param(belle_sip_header_address_get_uri(laddress)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
780 781


jehan's avatar
jehan committed
782
}
Ghislain MARY's avatar
Ghislain MARY committed
783

784 785 786
static void test_address_header_with_tel_uri(void) {
	belle_generic_uri_t* L_uri;
	char* L_raw;
787
	belle_sip_header_address_t* laddress = belle_sip_header_address_fast_parse("\"toto\" <tel:123456>");
788
	BC_ASSERT_PTR_NOT_NULL(laddress);
789
	L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
790
	BC_ASSERT_PTR_NOT_NULL(L_raw);
791 792 793 794
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
	laddress = belle_sip_header_address_parse(L_raw);
	belle_sip_free(L_raw);

795
	BC_ASSERT_STRING_EQUAL("toto",belle_sip_header_address_get_displayname(laddress));
796 797
	L_uri = belle_sip_header_address_get_absolute_uri(laddress);

798 799
	BC_ASSERT_PTR_NOT_NULL(belle_generic_uri_get_opaque_part(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_uri), "123456");
800 801 802
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}

803 804 805 806
static void test_very_long_address_header(void) {
	belle_sip_uri_t* L_uri;
	const char* raw = "<sip:jehan@sip.linphone.org"
					";app-id=622464153529"
jehan's avatar
jehan committed
807
					"; pn-type=google"
808
					";pn-tok=APA91bHPVa4PuKOMnr6ppWb3XYUL06QO-ND4eeiw7dG49q4o_Ywzal7BxVRgH-wvqH9iB9V7h6kfb-DCiVdSpnl6CeWO25FAkM4eh6DJyWcbP7SzhKdku_-r9936kJW7-4drI6-Om4qp"
jehan's avatar
jehan committed
809
					";pn-msg-str=IM_MSG "
810 811 812 813 814 815
					";pn-call-str=IC_MSG"
					";pn-call-snd=ring.caf"
					";pn-msg-snd=msg.caf"
					";>"; /*not compliant but*/

	belle_sip_header_address_t* laddress = belle_sip_header_address_parse(raw);
816
	if (!BC_ASSERT_PTR_NOT_NULL(laddress)) return;
817 818
	L_uri = belle_sip_header_address_get_uri(laddress);

819 820 821
	BC_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "jehan");
822
	do {
823 824 825 826 827 828 829 830 831
		char format[512];
		const char * cactual = (belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_uri),"pn-tok"));
		const char * cexpected = ("APA91bHPVa4PuKOMnr6ppWb3XYUL06QO-ND4eeiw7dG49q4o_Ywzal7BxVRgH-wvqH9iB9V7h6kfb-DCiVdSpnl6CeWO25FAkM4eh6DJyWcbP7SzhKdku_-r9936kJW7-4drI6-Om4qp");
		sprintf(format, "name" "(" "#actual" ", " "#expected" ") - " "Expected %s but was %s.\n", cexpected, cactual);
		printf("%s\n", format);
	} while (0);


	BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_uri),"pn-tok")
832 833 834 835 836 837
			,"APA91bHPVa4PuKOMnr6ppWb3XYUL06QO-ND4eeiw7dG49q4o_Ywzal7BxVRgH-wvqH9iB9V7h6kfb-DCiVdSpnl6CeWO25FAkM4eh6DJyWcbP7SzhKdku_-r9936kJW7-4drI6-Om4qp");
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}



Ghislain MARY's avatar
Ghislain MARY committed
838
static void test_subscription_state_header(void) {
jehan's avatar
jehan committed
839 840 841 842 843 844 845 846 847
	belle_sip_header_subscription_state_t* L_tmp;
	belle_sip_header_subscription_state_t* L_subscription_state = belle_sip_header_subscription_state_parse("Subscription-State: terminated;expires=600");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_subscription_state));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_subscription_state));
	L_tmp = belle_sip_header_subscription_state_parse(l_raw_header);
	L_subscription_state = BELLE_SIP_HEADER_SUBSCRIPTION_STATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);

848 849
	BC_ASSERT_STRING_EQUAL(belle_sip_header_subscription_state_get_state(L_subscription_state), "terminated");
	BC_ASSERT_EQUAL(belle_sip_header_subscription_state_get_expires(L_subscription_state), 600,int,"%d");
jehan's avatar
jehan committed
850
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_subscription_state));
851
	BC_ASSERT_PTR_NULL(belle_sip_header_subscription_state_parse("nimportequoi"));
jehan's avatar
jehan committed
852
}
Ghislain MARY's avatar
Ghislain MARY committed
853 854

static void test_refer_to_header(void) {
jehan's avatar
jehan committed
855
	belle_sip_uri_t* L_uri;
Simon Morlat's avatar
Simon Morlat committed
856
	belle_sip_header_address_t *ha;
jehan's avatar
jehan committed
857 858 859 860 861 862 863 864
	belle_sip_header_refer_to_t* L_refer_to = belle_sip_header_refer_to_parse("Refer-To: <sip:dave@denver.example.org?Replaces=12345%40192.168.118.3%3Bto-tag%3D12345%3Bfrom-tag%3D5FFE-3994>");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_refer_to));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
	L_refer_to = belle_sip_header_refer_to_parse(l_raw_header);
	belle_sip_free(l_raw_header);

	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));

865 866
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"dave");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "denver.example.org");
jehan's avatar
jehan committed
867 868
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
	/*test factory*/
Simon Morlat's avatar
Simon Morlat committed
869 870
	L_refer_to = belle_sip_header_refer_to_create((ha=belle_sip_header_address_parse("\"super man\" <sip:titi.com>")));
	belle_sip_object_unref(ha);
871
	if (!BC_ASSERT_PTR_NOT_NULL(L_refer_to)) return;
jehan's avatar
jehan committed
872
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));
873
	if (!BC_ASSERT_PTR_NOT_NULL(L_uri)) return;
874
	BC_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(L_refer_to)), "super man");
jehan's avatar
jehan committed
875
	belle_sip_object_unref(L_refer_to);
876
	BC_ASSERT_PTR_NULL(belle_sip_header_refer_to_parse("nimportequoi"));
jehan's avatar
jehan committed
877 878

}
Ghislain MARY's avatar
Ghislain MARY committed
879 880

static void test_referred_by_header(void) {
jehan's avatar
jehan committed
881 882 883 884 885 886 887 888 889
	belle_sip_uri_t* L_uri;
	belle_sip_header_referred_by_t* L_referred_by = belle_sip_header_referred_by_parse("Referred-By: sip:r@ref.example;cid=\"2UWQFN309shb3@ref.example\"");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_referred_by));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_referred_by));
	L_referred_by = belle_sip_header_referred_by_parse(l_raw_header);
	belle_sip_free(l_raw_header);

	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_referred_by));

890 891
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"r");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "ref.example");
jehan's avatar
jehan committed
892
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_referred_by));
893
	BC_ASSERT_PTR_NULL(belle_sip_header_referred_by_parse("nimportequoi"));
jehan's avatar
jehan committed
894
}
Ghislain MARY's avatar
Ghislain MARY committed
895 896

static void test_replaces_header(void) {
jehan's avatar
jehan committed
897 898 899 900 901 902 903 904 905
	belle_sip_header_replaces_t* L_tmp;
	belle_sip_header_replaces_t* L_replaces = belle_sip_header_replaces_parse("Replaces: 12345@149.112.118.3;to-tag=12345;from-tag=54321");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_replaces));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
	L_tmp= belle_sip_header_replaces_parse(l_raw_header);
	L_replaces = BELLE_SIP_HEADER_REPLACES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);

906 907 908
	BC_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_call_id(L_replaces), "12345@149.112.118.3");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_from_tag(L_replaces), "54321");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_to_tag(L_replaces), "12345");
jehan's avatar
jehan committed
909
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
910
	BC_ASSERT_PTR_NULL(belle_sip_header_replaces_parse("nimportequoi"));
jehan's avatar
jehan committed
911 912
}

Ghislain MARY's avatar
Ghislain MARY committed
913
static void test_replaces_escaped_header(void) {
914 915
	belle_sip_header_replaces_t* L_replaces;
	char* escaped_to_string;
916
	char* l_raw_header;
917 918 919
	belle_sip_header_replaces_t* L_tmp = belle_sip_header_replaces_create("12345@192.168.118.3","5FFE-3994","12345");
	escaped_to_string=belle_sip_header_replaces_value_to_escaped_string(L_tmp);
	L_replaces=belle_sip_header_replaces_create2(escaped_to_string);
920
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_replaces));
jehan's avatar
jehan committed
921
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
Simon Morlat's avatar
Simon Morlat committed
922
	belle_sip_object_unref(L_tmp);
jehan's avatar
jehan committed
923 924 925 926
	L_tmp= belle_sip_header_replaces_parse(l_raw_header);
	L_replaces = BELLE_SIP_HEADER_REPLACES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);
927
	belle_sip_free(escaped_to_string);
jehan's avatar
jehan committed
928

929 930 931
	BC_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_call_id(L_replaces), "12345@192.168.118.3");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_from_tag(L_replaces), "5FFE-3994");
	BC_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_to_tag(L_replaces), "12345");
932
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
jehan's avatar
jehan committed
933

Simon Morlat's avatar
Simon Morlat committed
934 935
}

936
#ifndef _WIN32
937
static void _test_date_header(void){
Simon Morlat's avatar
Simon Morlat committed
938 939 940
	belle_sip_header_date_t *date,*date2;
	time_t utc;
#define DATE_EXAMPLE "Thu, 21 Feb 2002 13:02:03 GMT"
941
#define DATE_UTC_EXAMPLE 1014296523L /* the above date in UTC */
Simon Morlat's avatar
Simon Morlat committed
942
	date=belle_sip_header_date_parse("Date: " DATE_EXAMPLE);
943
	BC_ASSERT_PTR_NOT_NULL(date);
Simon Morlat's avatar
Simon Morlat committed
944 945 946 947 948
	if (date){
		utc=belle_sip_header_date_get_time(date);
		BC_ASSERT_EQUAL(utc,DATE_UTC_EXAMPLE,int,"%d");
		belle_sip_object_unref(date);
	}
949

Simon Morlat's avatar
Simon Morlat committed
950
	date2=belle_sip_header_date_create_from_time(&utc);
951
	BC_ASSERT_PTR_NOT_NULL(date2);
Simon Morlat's avatar
Simon Morlat committed
952
	if (date2){
953
		BC_ASSERT_STRING_EQUAL(belle_sip_header_date_get_date(date2),DATE_EXAMPLE);
Simon Morlat's avatar
Simon Morlat committed
954 955 956
		BC_ASSERT_PTR_NULL(belle_sip_header_date_parse("nimportequoi"));
		belle_sip_object_unref(date2);
	}
957
}
958

959 960
#endif

961
static void test_date_header(void){
962
#ifdef _WIN32
963
	// TODO: setenv and unsetenv are not available for Windows
964
#else
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
	char *tz;
	/* test in our timezone */
	_test_date_header();

	/* test within another timezone */
	tz = getenv("TZ");
	setenv("TZ","Etc/GMT+4",1);
	tzset();

	_test_date_header();

	/* reset to original timezone */
	if(tz)
		setenv("TZ", tz, 1);
	else
		unsetenv("TZ");
	tzset();
982
#endif
jehan's avatar
jehan committed
983
}
jehan's avatar
jehan committed
984

jehan's avatar
jehan committed
985 986 987 988 989 990 991 992 993
static void test_p_preferred_identity_header(void) {
	belle_sip_uri_t* L_uri;
	belle_sip_header_p_preferred_identity_t* L_p_preferred_identity = belle_sip_header_p_preferred_identity_parse("P-Preferred-Identity: \"Cullen Jennings\" <sip:fluffy@cisco.com>");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_p_preferred_identity));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_p_preferred_identity));
	L_p_preferred_identity = belle_sip_header_p_preferred_identity_parse(l_raw_header);
	belle_sip_free(l_raw_header);

	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_p_preferred_identity));
994 995 996
	BC_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(L_p_preferred_identity)),"Cullen Jennings");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"fluffy");
	BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "cisco.com");
jehan's avatar
jehan committed
997
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_p_preferred_identity));
998
	BC_ASSERT_PTR_NULL(belle_sip_header_p_preferred_identity_parse("nimportequoi"));
jehan's avatar
jehan committed
999 1000
}

jehan's avatar
jehan committed
1001
static void test_privacy(const char* raw_header,const char* values[],size_t number_values) {
Ghislain MARY's avatar
Ghislain MARY committed
1002

jehan's avatar
jehan committed
1003 1004 1005 1006
	belle_sip_list_t* list;
	belle_sip_header_privacy_t* L_tmp;
	belle_sip_header_privacy_t* L_privacy = belle_sip_header_privacy_parse(raw_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_privacy));
1007
	size_t i=0;
jehan's avatar
jehan committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_privacy));
	L_tmp = belle_sip_header_privacy_parse(l_raw_header);
	L_privacy = BELLE_SIP_HEADER_PRIVACY(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));

	belle_sip_free(l_raw_header);

	list = belle_sip_header_privacy_get_privacy(L_privacy);

	for(i=0;i<number_values;i++){
1018 1019
		BC_ASSERT_PTR_NOT_NULL(list);
		BC_ASSERT_STRING_EQUAL((const char *)(list->data),values[i]);
jehan's avatar
jehan committed
1020 1021 1022
		list=list->next;
	}
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_privacy));
1023
	BC_ASSERT_PTR_NULL(belle_sip_header_privacy_parse("nimportequoi"));
jehan's avatar
jehan committed
1024 1025

}
1026
static void test_privacy_header(void) {
jehan's avatar
jehan committed
1027 1028 1029 1030 1031 1032

	const char* value1[] ={"user","critical"};
	const char* value2[] ={"id"};
	test_privacy("Privacy: user; critical",value1,2);
	test_privacy("Privacy: id",value2,1);
}
jehan's avatar
jehan committed
1033

1034 1035 1036 1037 1038