belle_sip_headers_tester.c 64 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;
jehan's avatar
jehan committed
28
	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("m:sip:titi.com");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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

jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
79
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
80

jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
93
	belle_sip_header_from_t* L_from = belle_sip_header_from_parse("f:<sip:titi.com;transport=tcp>;tag=dlfjklcn6545614XX");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
99 100
	belle_sip_free(l_raw_header);

101
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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);
Ghislain MARY's avatar
Ghislain MARY committed
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"));
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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

jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
175

176
	BC_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"as1f0a0817");
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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);
Ghislain MARY's avatar
Ghislain MARY committed
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));


jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
284
	belle_sip_header_call_id_t* L_call_id = belle_sip_header_call_id_parse("i: 1665237789@titi.com");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
321
	belle_sip_header_content_type_t* L_content_type = belle_sip_header_content_type_parse("c: text/html; charset=ISO-8859-4");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
333 334

	L_content_type = belle_sip_header_content_type_parse("Content-Type: application/sdp");
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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);
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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);
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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

jehan's avatar
jehan committed
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

jehan's avatar
jehan committed
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");
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
479
	belle_sip_free(l_raw_header);
Ghislain MARY's avatar
Ghislain MARY committed
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;
jehan's avatar
jehan committed
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);
jehan's avatar
jehan committed
492
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_extension));
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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"));
jehan's avatar
jehan committed
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);
jehan's avatar
jehan committed
512
}
Ghislain MARY's avatar
Ghislain MARY committed
513 514

static void test_authorization_header(void) {
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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) {
jehan's avatar
jehan committed
547
	const char* l_header = "Proxy-Authorization: Digest username=\"Alice\""
548 549
			", realm=\"atlanta.com\", nonce=\"c60f3082ee1212b402a21831ae\""
			", response=\"245f23415f11432b3434341c022\"";
jehan's avatar
jehan committed
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) {
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
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) {
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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));

jehan's avatar
jehan committed
686 687
	belle_sip_free(l_raw_header);

688
	products = belle_sip_header_user_agent_get_products(L_user_agent);
jehan's avatar
jehan committed
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]);
jehan's avatar
jehan committed
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"));
jehan's avatar
jehan committed
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;
jehan's avatar
jehan committed
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));
jehan's avatar
jehan committed
709
	belle_sip_free(l_raw_header);
710
	BC_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 3600,int,"%d");
jehan's avatar
jehan committed
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"));
jehan's avatar
jehan committed
717
}
Ghislain MARY's avatar
Ghislain MARY committed
718 719

static void test_allow_header(void) {