belle_sip_headers_tester.c 53.1 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));
Simon Morlat's avatar
Simon Morlat committed
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));
Simon Morlat's avatar
Simon Morlat committed
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
	BC_ASSERT_PTR_NOT_NULL_FATAL(L_from);
jehan's avatar
jehan committed
127
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
128 129 130 131 132 133 134 135 136 137 138
	BC_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
	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);
	BC_ASSERT_EQUAL(belle_sip_list_size(belle_sip_uri_get_header_names(L_uri)),0,int,"%d");

	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 148
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_from_get_tag(L_from));
	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
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_from_get_tag(L_from));
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 167
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
	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
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
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
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
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
	BC_ASSERT_PTR_NOT_NULL_FATAL(L_to);
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 221 222 223 224 225
	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);
	BC_ASSERT_EQUAL(belle_sip_list_size(belle_sip_uri_get_header_names(L_uri)),0,int,"%d");

	BC_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
	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));
349
	BC_ASSERT_PTR_NULL(belle_sip_header_content_type_parse("nimportequoi"));
350
}
Ghislain MARY's avatar
Ghislain MARY committed
351 352

static void test_record_route_header(void) {
353 354 355
	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
356
	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
357 358 359 360
	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);
361
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_record_route));
362 363 364
	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
365
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
jehan's avatar
jehan committed
366 367

	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>");
368 369
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_record_route));
	L_next_route = BELLE_SIP_HEADER_RECORD_ROUTE(l_next);
370 371
	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
372
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
373 374 375
	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"));

376 377 378 379
	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);
380
	BC_ASSERT_PTR_NOT_NULL(L_record_route);
381 382
	if (L_record_route) belle_sip_object_unref(L_record_route);
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
383
}
Ghislain MARY's avatar
Ghislain MARY committed
384 385

static void test_route_header(void) {
386 387 388 389
	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
390
	belle_sip_header_address_t* address = belle_sip_header_address_parse("<sip:212.27.52.5:5060;transport=udp;lr>");
391
	char* l_raw_header;
392
	BC_ASSERT_PTR_NOT_NULL_FATAL(address);
393
	L_route = belle_sip_header_route_create(address);
Simon Morlat's avatar
Simon Morlat committed
394
	belle_sip_object_unref(address);
395
	BC_ASSERT_PTR_NOT_NULL_FATAL(L_route);
396
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
397 398 399
	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);
400
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_route));
401 402
	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
403

jehan's avatar
jehan committed
404
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
405 406

	L_route = belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:titi.com>");
407 408
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_route));
	L_next_route = BELLE_SIP_HEADER_ROUTE(l_next);
409 410
	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
411
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
412

413 414
	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
415

416 417 418 419
	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);
420
	BC_ASSERT_PTR_NOT_NULL(L_route);
421 422
	if (L_route) belle_sip_object_unref(L_route);
	belle_sip_free(l_raw_header);
423

jehan's avatar
jehan committed
424
}
Ghislain MARY's avatar
Ghislain MARY committed
425 426

static void test_service_route_header(void) {
jehan's avatar
jehan committed
427
	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>");
428 429
	belle_sip_uri_t* L_uri;
	char* l_raw_header;
430
	BC_ASSERT_PTR_NOT_NULL_FATAL(L_service_route);
431
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_service_route));
jehan's avatar
jehan committed
432 433 434
	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);
435
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_service_route));
436 437
	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
438
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
439
	BC_ASSERT_PTR_NULL(belle_sip_header_service_route_parse("nimportequoi"));
jehan's avatar
jehan committed
440
}
Ghislain MARY's avatar
Ghislain MARY committed
441 442

static void test_content_length_header(void) {
443
	belle_sip_header_content_length_t* L_tmp;
jehan's avatar
jehan committed
444
	belle_sip_header_content_length_t* L_content_length = belle_sip_header_content_length_parse("Content-Length: 3495");
jehan's avatar
jehan committed
445 446
	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));
447 448 449
	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
450
	belle_sip_free(l_raw_header);
451
	BC_ASSERT_EQUAL(belle_sip_header_content_length_get_content_length(L_content_length), 3495,int,"%d");
jehan's avatar
jehan committed
452
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_length));
453
	BC_ASSERT_PTR_NULL(belle_sip_header_content_length_parse("nimportequoi"));
jehan's avatar
jehan committed
454
}
Ghislain MARY's avatar
Ghislain MARY committed
455

jehan's avatar
jehan committed
456 457
static belle_sip_header_t* test_header_extension(const char* name,const char* value) {
	belle_sip_header_t* L_tmp;
458
	belle_sip_header_t* L_extension;
jehan's avatar
jehan committed
459 460 461
	char header[256];
	char* l_raw_header=NULL;
	snprintf(header,sizeof(header),"%s:%s",name,value);
jehan's avatar
jehan committed
462
	L_extension = belle_sip_header_parse(header);
jehan's avatar
jehan committed
463
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_extension));
jehan's avatar
jehan committed
464
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_extension));
jehan's avatar
jehan committed
465 466
	L_tmp = belle_sip_header_parse(l_raw_header);
	L_extension = BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
467
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
468 469
	belle_sip_free(l_raw_header);

470
	BC_ASSERT_STRING_EQUAL(belle_sip_header_get_unparsed_value(L_extension), value);
jehan's avatar
jehan committed
471

jehan's avatar
jehan committed
472
	/*FIXME jehan check why missing colon does not lead an exception
473
	BC_ASSERT_PTR_NULL(belle_sip_header_extension_parse("nimportequoi"));*/
jehan's avatar
jehan committed
474
	return L_extension;
475
}
476
static void test_header_extension_1(void) {
jehan's avatar
jehan committed
477
	belle_sip_object_unref(test_header_extension("toto","titi"));
jehan's avatar
jehan committed
478
}
479
static void test_header_extension_2(void) {
jehan's avatar
jehan committed
480
	belle_sip_header_t* header = test_header_extension("From","sip:localhost");
481
	BC_ASSERT_TRUE(BELLE_SIP_OBJECT_IS_INSTANCE_OF(header,belle_sip_header_from_t));
jehan's avatar
jehan committed
482
	belle_sip_object_unref(header);
jehan's avatar
jehan committed
483
}
Ghislain MARY's avatar
Ghislain MARY committed
484 485

static void test_authorization_header(void) {
jehan's avatar
jehan committed
486
	const char* l_header = "Authorization: Digest username=\"0033482532176\", "\
487
			"realm=\"sip.ovh.net\", nonce=\"1bcdcb194b30df5f43973d4c69bdf54f\", uri=\"sip:sip.ovh.net\", response=\"eb36c8d5c8642c1c5f44ec3404613c81\","\
488 489
			"algorithm=MD5, opaque=\"1bc7f9097684320\","
			"\r\n qop=auth, nc=00000001,cnonce=\"0a4f113b\", blabla=\"toto\"";
490
	belle_sip_header_authorization_t* L_tmp;
jehan's avatar
jehan committed
491 492 493
	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));
494 495 496
	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
497 498
	belle_sip_free(l_raw_header);

499 500 501 502 503 504 505 506 507 508 509 510 511 512
	BC_ASSERT_PTR_NOT_NULL_FATAL(L_authorization);
	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\"");
513
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
514
	BC_ASSERT_PTR_NULL(belle_sip_header_authorization_parse("nimportequoi"));
515
}
Ghislain MARY's avatar
Ghislain MARY committed
516 517

static void test_proxy_authorization_header(void) {
jehan's avatar
jehan committed
518
	const char* l_header = "Proxy-Authorization: Digest username=\"Alice\""
519 520
			", realm=\"atlanta.com\", nonce=\"c60f3082ee1212b402a21831ae\""
			", response=\"245f23415f11432b3434341c022\"";
jehan's avatar
jehan committed
521 522 523 524 525
	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);
526 527 528 529
	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
530
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
531
	BC_ASSERT_PTR_NULL(belle_sip_header_proxy_authorization_parse("nimportequoi"));
jehan's avatar
jehan committed
532
}
Ghislain MARY's avatar
Ghislain MARY committed
533

jehan's avatar
jehan committed
534 535
static void check_header_authenticate(belle_sip_header_www_authenticate_t* authenticate) {
	belle_sip_list_t* qop;
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
	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");

	BC_ASSERT_PTR_NOT_NULL_FATAL(qop=belle_sip_header_www_authenticate_get_qop(authenticate));
	BC_ASSERT_STRING_EQUAL((const char*)qop->data, "auth");
	BC_ASSERT_PTR_NOT_NULL_FATAL(qop=qop->next);
	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
551
	belle_sip_object_unref(BELLE_SIP_OBJECT(authenticate));
jehan's avatar
jehan committed
552

jehan's avatar
jehan committed
553
}
Ghislain MARY's avatar
Ghislain MARY committed
554 555

static void test_www_authenticate_header(void) {
jehan's avatar
jehan committed
556
	const char* l_header = "WWW-Authenticate: Digest "
557
			"algorithm=MD5,\r\n   realm=\"atlanta.com\",\r\n  opaque=\"1bc7f9097684320\","
jehan's avatar
jehan committed
558
			" qop=\"auth,auth-int\", nonce=\"c60f3082ee1212b402a21831ae\", stale=true, domain=\"sip:boxesbybob.com\"";
559 560 561 562
	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\"";

563 564 565
	const char* l_header_2 = "WWW-Authenticate: Basic realm=\"WallyWorld\"";


566
	belle_sip_header_www_authenticate_t* L_tmp;
567
	belle_sip_header_www_authenticate_t *l_authenticate = belle_sip_header_www_authenticate_parse(l_header);
jehan's avatar
jehan committed
568 569 570 571


	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_authenticate));
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));
572
	L_tmp = belle_sip_header_www_authenticate_parse(l_raw_header);
jehan's avatar
jehan committed
573
	l_authenticate = BELLE_SIP_HEADER_WWW_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
574
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
575
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
576
	check_header_authenticate(l_authenticate);
577 578 579 580 581 582


	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);
583
	belle_sip_free(l_raw_header);
584
	l_authenticate = BELLE_SIP_HEADER_WWW_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
585 586 587 588 589
	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));
590
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));
591 592 593 594 595 596 597 598
	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));

599

600
	BC_ASSERT_PTR_NULL(belle_sip_header_www_authenticate_parse("nimportequoi"));
jehan's avatar
jehan committed
601 602

}
Ghislain MARY's avatar
Ghislain MARY committed
603 604

static void test_proxy_authenticate_header(void) {
jehan's avatar
jehan committed
605 606 607 608 609
	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);
610
	//belle_sip_list_t* qop;
jehan's avatar
jehan committed
611 612 613 614 615 616 617 618

	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));
619
	BC_ASSERT_PTR_NULL(belle_sip_header_proxy_authenticate_parse("nimportequoi"));
jehan's avatar
jehan committed
620
}
jehan's avatar
jehan committed
621

Ghislain MARY's avatar
Ghislain MARY committed
622
static void test_max_forwards_header(void) {
jehan's avatar
jehan committed
623
	const char* l_header = "Max-Forwards: 6";
624
	belle_sip_header_max_forwards_t* L_tmp;
jehan's avatar
jehan committed
625
	belle_sip_header_max_forwards_t* L_max_forwards = belle_sip_header_max_forwards_parse(l_header);
626
	char* l_raw_header;
jehan's avatar
jehan committed
627
	belle_sip_header_max_forwards_decrement_max_forwards(L_max_forwards);
628
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_max_forwards));
jehan's avatar
jehan committed
629
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
630 631 632 633
	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
634
	belle_sip_free(l_raw_header);
635 636
	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
637 638

	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
639
	BC_ASSERT_PTR_NULL(belle_sip_header_max_forwards_parse("nimportequoi"));
jehan's avatar
jehan committed
640

641
}
Ghislain MARY's avatar
Ghislain MARY committed
642 643

static void test_user_agent_header(void) {
jehan's avatar
jehan committed
644
	const char* l_header = "User-Agent: Linphone/3.4.99.1 (eXosip2/3.3.0)";
645 646 647
	const char* values[] ={"Linphone/3.4.99.1"
				,"(eXosip2/3.3.0)"};
	belle_sip_list_t* products;
648
	belle_sip_header_user_agent_t* L_tmp;
jehan's avatar
jehan committed
649 650
	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));
651
	int i=0;
jehan's avatar
jehan committed
652
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
653 654 655 656
	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
657 658
	belle_sip_free(l_raw_header);

659
	products = belle_sip_header_user_agent_get_products(L_user_agent);
jehan's avatar
jehan committed
660 661

	for(i=0;i<2;i++){
662 663
		BC_ASSERT_PTR_NOT_NULL(products);
		BC_ASSERT_STRING_EQUAL((const char *)(products->data),values[i]);
jehan's avatar
jehan committed
664 665 666 667
		products=products->next;
	}

	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
668
	BC_ASSERT_PTR_NULL(belle_sip_header_user_agent_parse("nimportequoi"));
jehan's avatar
jehan committed
669 670

}
Ghislain MARY's avatar
Ghislain MARY committed
671 672

static void test_expires_header(void) {
673
	belle_sip_header_expires_t* L_tmp;
jehan's avatar
jehan committed
674 675 676
	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));
677 678 679
	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
680
	belle_sip_free(l_raw_header);
681
	BC_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 3600,int,"%d");
jehan's avatar
jehan committed
682
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
jehan's avatar
jehan committed
683 684
	/*test factory*/
	L_expires = belle_sip_header_expires_create(600);
685
	BC_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 600,int,"%d");
jehan's avatar
jehan committed
686
	belle_sip_object_unref(L_expires);
687
	BC_ASSERT_PTR_NULL(belle_sip_header_expires_parse("nimportequoi"));
jehan's avatar
jehan committed
688
}
Ghislain MARY's avatar
Ghislain MARY committed
689 690

static void test_allow_header(void) {
691
	belle_sip_header_allow_t* L_tmp;
jehan's avatar
jehan committed
692 693 694
	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));
695 696 697
	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));
jehan's avatar
jehan committed
698 699
	belle_sip_free(l_raw_header);

700
	BC_ASSERT_STRING_EQUAL(belle_sip_header_allow_get_method(L_allow), "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
jehan's avatar
jehan committed
701
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
702
	BC_ASSERT_PTR_NULL(belle_sip_header_allow_parse("nimportequoi"));
jehan's avatar
jehan committed
703 704
}

Ghislain MARY's avatar
Ghislain MARY committed
705
static void test_address_with_error_header(void) {
jehan's avatar
jehan committed
706
	belle_sip_header_address_t* laddress = belle_sip_header_address_parse("sip:liblinphone_tester@=auth1.example.org");
707
	BC_ASSERT_PTR_NULL(laddress);
708
	laddress = belle_sip_header_address_parse("liblinphone_tester");
709
	BC_ASSERT_PTR_NULL(laddress);
jehan's avatar
jehan committed
710
}
jehan's avatar
jehan committed
711

Ghislain MARY's avatar
Ghislain MARY committed
712
static void test_address_header(void) {
713
	belle_sip_uri_t* L_uri;
714
	char* L_raw;
jehan's avatar
jehan committed
715
	belle_sip_header_address_t* laddress = belle_sip_header_address_parse("\"toto\" <sip:liblinphone_tester@81.56.11.2:5060>");
716
	BC_ASSERT_PTR_NOT_NULL(laddress);
717
	L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
718
	BC_ASSERT_PTR_NOT_NULL(L_raw);
719 720 721 722
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
	laddress = belle_sip_header_address_parse(L_raw);
	belle_sip_free(L_raw);

723
	BC_ASSERT_STRING_EQUAL("toto",belle_sip_header_address_get_displayname(laddress));