belle_sip_dialog_tester.c 20.6 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
    (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"
Ghislain MARY's avatar
Ghislain MARY committed
20
#include "belle_sip_tester.h"
jehan's avatar
jehan committed
21

Simon Morlat's avatar
Simon Morlat committed
22
#include "register_tester.h"
jehan's avatar
jehan committed
23 24


jehan's avatar
jehan committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
static const char* sdp = 		"v=0\r\n"\
								"o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\
								"s=Talk\r\n"\
								"c=IN IP4 192.168.0.18\r\n"\
								"t=0 0\r\n"\
								"m=audio 7078 RTP/AVP 111 110 3 0 8 101\r\n"\
								"a=rtpmap:111 speex/16000\r\n"\
								"a=fmtp:111 vbr=on\r\n"\
								"a=rtpmap:110 speex/8000\r\n"\
								"a=fmtp:110 vbr=on\r\n"\
								"a=rtpmap:101 telephone-event/8000\r\n"\
								"a=fmtp:101 0-11\r\n"\
								"m=video 8078 RTP/AVP 99 97 98\r\n"\
								"c=IN IP4 192.168.0.18\r\n"\
								"b=AS:380\r\n"\
								"a=rtpmap:99 MP4V-ES/90000\r\n"\
								"a=fmtp:99 profile-level-id=3\r\n"\
								"a=rtpmap:97 theora/90000\r\n"\
								"a=rtpmap:98 H263-1998/90000\r\n"\
								"a=fmtp:98 CIF=1;QCIF=1\r\n";

Ghislain MARY's avatar
Ghislain MARY committed
46 47 48 49
static belle_sip_dialog_t* caller_dialog;
static belle_sip_dialog_t* callee_dialog;
static belle_sip_response_t* ok_response;
static belle_sip_server_transaction_t* inserv_transaction;
jehan's avatar
jehan committed
50
static belle_sip_client_transaction_t* pauline_reg_transaction;
jehan's avatar
jehan committed
51 52 53 54 55 56 57 58 59 60 61 62 63


belle_sip_request_t* build_request(belle_sip_stack_t * stack
									, belle_sip_provider_t *prov
									,belle_sip_header_address_t* from
									,belle_sip_header_address_t* to
									,belle_sip_header_address_t* route
									,const char* method) {
	belle_sip_header_from_t* from_header;
	belle_sip_header_to_t* to_header;
	belle_sip_request_t *req;
	belle_sip_uri_t* req_uri;
	belle_sip_header_contact_t* contact_header;
64
	BELLESIP_UNUSED(stack);
jehan's avatar
jehan committed
65 66 67 68 69 70 71

	from_header = belle_sip_header_from_create(from,BELLE_SIP_RANDOM_TAG);
	to_header = belle_sip_header_to_create(to,NULL);
	req_uri = (belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_header_address_get_uri((belle_sip_header_address_t*)to_header));

	contact_header= belle_sip_header_contact_new();
	belle_sip_header_address_set_uri((belle_sip_header_address_t*)contact_header,belle_sip_uri_new());
jehan's avatar
jehan committed
72 73 74
	belle_sip_uri_set_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)contact_header),
						   belle_sip_uri_get_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)from_header)));
	
jehan's avatar
jehan committed
75 76 77 78 79 80 81 82 83
	req=belle_sip_request_create(
							req_uri,
							method,
		                    belle_sip_provider_create_call_id(prov),
		                    belle_sip_header_cseq_create(20,method),
		                    from_header,
		                    to_header,
		                    belle_sip_header_via_new(),
		                    70);
jehan's avatar
jehan committed
84
	
jehan's avatar
jehan committed
85 86 87 88 89 90 91 92
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact_header));
	if (route) {
		belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_route_create(route)));
	}
	return req;
}

static void process_dialog_terminated(void *user_ctx, const belle_sip_dialog_terminated_event_t *event){
93 94
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
jehan's avatar
jehan committed
95 96
	belle_sip_message("process_dialog_terminated not implemented yet");
}
Ghislain MARY's avatar
Ghislain MARY committed
97

jehan's avatar
jehan committed
98
static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){
99 100
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
jehan's avatar
jehan committed
101 102
	belle_sip_message("process_io_error not implemented yet");
}
Ghislain MARY's avatar
Ghislain MARY committed
103

jehan's avatar
jehan committed
104
static void caller_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) {
105 106 107
	belle_sip_server_transaction_t* server_transaction;
	belle_sip_response_t* resp;
	belle_sip_dialog_t* dialog;
jehan's avatar
jehan committed
108 109
	belle_sip_header_to_t* to=belle_sip_message_get_header_by_type(belle_sip_request_event_get_request(event),belle_sip_header_to_t);
	if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(to)))) {
110
		belle_sip_message("Message [%p] not for caller, skipping",belle_sip_request_event_get_request(event));
jehan's avatar
jehan committed
111 112 113
		return; /*not for the caller*/
	}
	belle_sip_message("caller_process_request_event received [%s] message",belle_sip_request_get_method(belle_sip_request_event_get_request(event)));
114
	server_transaction=belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
115
	BC_ASSERT_STRING_EQUAL("BYE",belle_sip_request_get_method(belle_sip_request_event_get_request(event)));
116
	dialog =  belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(server_transaction));
117 118 119
	if (BC_ASSERT_PTR_NOT_NULL(dialog)) {
		BC_ASSERT_EQUAL(belle_sip_dialog_get_state(dialog) , BELLE_SIP_DIALOG_CONFIRMED, int, "%d");
	}
jehan's avatar
jehan committed
120 121 122 123
	resp=belle_sip_response_create_from_request(belle_sip_request_event_get_request(event),200);
	belle_sip_server_transaction_send_response(server_transaction,resp);

}
Ghislain MARY's avatar
Ghislain MARY committed
124

125
static void callee_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) {
126 127 128 129
	belle_sip_dialog_t* dialog;
	belle_sip_response_t* ringing_response;
	belle_sip_header_content_type_t* content_type ;
	belle_sip_header_content_length_t* content_length;
jehan's avatar
jehan committed
130
	belle_sip_server_transaction_t* server_transaction = belle_sip_request_event_get_server_transaction(event);
131 132 133
	belle_sip_header_to_t* to=belle_sip_message_get_header_by_type(belle_sip_request_event_get_request(event),belle_sip_header_to_t);
	const char* method;
	if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(to)))) {
134
		belle_sip_message("Message [%p] not for callee, skipping",belle_sip_request_event_get_request(event));
135 136
		return; /*not for the callee*/
	}
137
	method = belle_sip_request_get_method(belle_sip_request_event_get_request(event));
jehan's avatar
jehan committed
138 139 140 141 142 143 144 145
	
	if (strcmp(method,"PRACK") == 0){
		belle_sip_server_transaction_t* server_trans = belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
		belle_sip_response_t* prack_resp_ok = belle_sip_response_create_from_request(belle_sip_request_event_get_request(event), 200);
		belle_sip_server_transaction_send_response(server_trans, prack_resp_ok);
		return;
	}
	
146
	if (!server_transaction && strcmp(method,"ACK")!=0) {
jehan's avatar
jehan committed
147 148
		server_transaction= belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
	}
149

150
	belle_sip_message("callee_process_request_event received [%s] message",method);
151
	dialog = belle_sip_request_event_get_dialog(event);
jehan's avatar
jehan committed
152
	if (!dialog ) {
153
		BC_ASSERT_STRING_EQUAL("INVITE",method);
jehan's avatar
jehan committed
154
		dialog=belle_sip_provider_create_dialog(prov,BELLE_SIP_TRANSACTION(server_transaction));
jehan's avatar
jehan committed
155
		callee_dialog=dialog;
jehan's avatar
jehan committed
156
		inserv_transaction=server_transaction;
jehan's avatar
jehan committed
157
	}
jehan's avatar
jehan committed
158

jehan's avatar
jehan committed
159
	if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_NULL) {
jehan's avatar
jehan committed
160
		/*prepare 180*/
jehan's avatar
jehan committed
161
		ringing_response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(server_transaction)),180);
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
		belle_sip_header_supported_t* header_supported = belle_sip_message_get_header_by_type(belle_sip_request_event_get_request(event),belle_sip_header_supported_t);
		if (header_supported){
			belle_sip_list_t* list = belle_sip_header_supported_get_supported(header_supported);
			int supported_100rel = 0;
			while (list){
				if (strcmp(list->data, "100rel") == 0){
					supported_100rel = 1;
					break;
				}
				list=list->next;
			}
			if (supported_100rel){
				belle_sip_message("Found supported 100rel in message [%p]. PRACK will be required in response 180.", belle_sip_request_event_get_request(event));
				belle_sip_header_t* header_require = belle_sip_header_create("Require", "100rel");
				belle_sip_header_t* header_rseq = belle_sip_header_create("RSeq", "1");
				belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response), BELLE_SIP_HEADER(header_require));
				belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response), BELLE_SIP_HEADER(header_rseq));
				
				//workaround for PRACK message. Server will correct Contact header that will be used during create PRACK massege (dialog->remote_target)
				belle_sip_response_t* marie_reg_response = belle_sip_transaction_get_response((belle_sip_transaction_t*)pauline_reg_transaction);
				BC_ASSERT_PTR_NOT_NULL(marie_reg_response);
				belle_sip_header_contact_t* L_tmp = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(marie_reg_response), belle_sip_header_contact_t);
				belle_sip_header_contact_t* contact_header = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
				belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response),BELLE_SIP_HEADER(contact_header));
			}
		}

jehan's avatar
jehan committed
189 190 191 192 193 194 195
		/*prepare 200ok*/
		ok_response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(server_transaction)),200);
		content_length= belle_sip_header_content_length_create(strlen(sdp));
		content_type = belle_sip_header_content_type_create("application","sdp");
		belle_sip_message_add_header(BELLE_SIP_MESSAGE(ok_response),BELLE_SIP_HEADER(content_type));
		belle_sip_message_add_header(BELLE_SIP_MESSAGE(ok_response),BELLE_SIP_HEADER(content_length));
		belle_sip_message_set_body(BELLE_SIP_MESSAGE(ok_response),sdp,strlen(sdp));
196
		belle_sip_object_ref(ok_response);
jehan's avatar
jehan committed
197
		
jehan's avatar
jehan committed
198
		/*only send ringing*/
jehan's avatar
jehan committed
199
		belle_sip_server_transaction_send_response(server_transaction,ringing_response);
jehan's avatar
jehan committed
200 201 202 203
	} else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_CONFIRMED) {
		/*time to send bye*/
		belle_sip_client_transaction_t* client_transaction = belle_sip_provider_create_client_transaction(prov,belle_sip_dialog_create_request(dialog,"BYE"));
		belle_sip_client_transaction_send_request(client_transaction);
jehan's avatar
jehan committed
204 205
	} else {
		belle_sip_warning("Unexpected state [%s] for dialog [%p]",belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog)),dialog );
jehan's avatar
jehan committed
206
	}
207

jehan's avatar
jehan committed
208 209
}

jehan's avatar
jehan committed
210 211
static void caller_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
	belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event);
jehan's avatar
jehan committed
212
	if (client_transaction == NULL)
213
		return; //fix for received 200 of PRACK
214 215 216
	belle_sip_header_from_t* from=belle_sip_message_get_header_by_type(belle_sip_response_event_get_response(event),belle_sip_header_from_t);
	belle_sip_header_cseq_t* invite_cseq=belle_sip_message_get_header_by_type(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(client_transaction)),belle_sip_header_cseq_t);
	belle_sip_request_t* ack;
217 218
	belle_sip_dialog_t* dialog;
	int status;
219

220
	if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from)))) {
221
		belle_sip_message("Message [%p] not for caller, skipping",belle_sip_response_event_get_response(event));
222 223 224
		return; /*not for the caller*/
	}

225
	status = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event));
jehan's avatar
jehan committed
226
	belle_sip_message("caller_process_response_event [%i]",status);
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
	if (BC_ASSERT_PTR_NOT_NULL(client_transaction)) {
		dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction));
		if (BC_ASSERT_PTR_NOT_NULL(dialog)) {
			BC_ASSERT_PTR_EQUAL(caller_dialog,dialog);
			if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_NULL) {
				BC_ASSERT_EQUAL(status,100, int, "%d");
			} else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_EARLY){
				BC_ASSERT_EQUAL(status,180, int, "%d");
				/*send 200ok from callee*/
				belle_sip_server_transaction_send_response(inserv_transaction,ok_response);
				belle_sip_object_unref(ok_response);
				ok_response=NULL;
			} else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_CONFIRMED) {
				ack=belle_sip_dialog_create_ack(dialog,belle_sip_header_cseq_get_seq_number(invite_cseq));
				belle_sip_dialog_send_ack(dialog,ack);
			}
		}
jehan's avatar
jehan committed
244
	}
jehan's avatar
jehan committed
245
}
Ghislain MARY's avatar
Ghislain MARY committed
246

jehan's avatar
jehan committed
247
static void callee_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
248
	belle_sip_dialog_t* dialog;
jehan's avatar
jehan committed
249
	belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event);
250 251 252
	belle_sip_header_from_t* from=belle_sip_message_get_header_by_type(belle_sip_response_event_get_response(event),belle_sip_header_from_t);
	int status = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event));
	if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from)))) {
253
		belle_sip_message("Message [%p] not for callee, skipping",belle_sip_response_event_get_response(event));
254 255
		return; /*not for the callee*/
	}
256 257 258 259 260 261 262 263 264 265 266 267
	if (BC_ASSERT_PTR_NOT_NULL(client_transaction)) {
		dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction));
		if (BC_ASSERT_PTR_NOT_NULL(dialog)) {
			BC_ASSERT_PTR_EQUAL(callee_dialog,dialog);
			if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_TERMINATED) {
				call_endeed=1;
				belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
			}
			belle_sip_message("callee_process_response_event [%i] on dialog [%p] for state [%s]",status
						,dialog
						,belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog)));
		}
jehan's avatar
jehan committed
268
	}
jehan's avatar
jehan committed
269

jehan's avatar
jehan committed
270
}
Ghislain MARY's avatar
Ghislain MARY committed
271

jehan's avatar
jehan committed
272
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
273
	BELLESIP_UNUSED(user_ctx);
jehan's avatar
jehan committed
274 275 276 277 278 279 280 281
/*	belle_sip_client_transaction_t* client_transaction = belle_sip_timeout_event_get_client_transaction(event);
	SalOp* op = (SalOp*)belle_sip_transaction_get_application_data(BELLE_SIP_TRANSACTION(client_transaction));
	if (op->callbacks.process_timeout) {
		op->callbacks.process_timeout(op,event);
	} else*/ {
		belle_sip_message("Unhandled event timeout [%p]",event);
	}
}
Ghislain MARY's avatar
Ghislain MARY committed
282

jehan's avatar
jehan committed
283
static void process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
284
	BELLESIP_UNUSED(user_ctx);
jehan's avatar
jehan committed
285 286 287 288 289 290 291 292 293
/*	belle_sip_client_transaction_t* client_transaction = belle_sip_transaction_terminated_event_get_client_transaction(event);
	SalOp* op = (SalOp*)belle_sip_transaction_get_application_data(client_transaction);
	if (op->calbacks.process_transaction_terminated) {
		op->calbacks.process_transaction_terminated(op,event);
	} else */{
		belle_sip_message("Unhandled transaction terminated [%p]",event);
	}
}

294 295 296 297
static void listener_destroyed(void *user_ctx){
	belle_sip_object_unref(user_ctx);
}

298
static void do_simple_call(int enable_100rel) {
jehan's avatar
jehan committed
299 300 301 302 303
#define CALLER "marie"
#define CALLEE "pauline"
	belle_sip_request_t *pauline_register_req;
	belle_sip_request_t *marie_register_req;
	belle_sip_listener_callbacks_t caller_listener_callbacks;
jehan's avatar
jehan committed
304
	belle_sip_listener_t* caller_listener;
jehan's avatar
jehan committed
305
	belle_sip_listener_callbacks_t callee_listener_callbacks;
jehan's avatar
jehan committed
306
	belle_sip_listener_t* callee_listener;
jehan's avatar
jehan committed
307 308 309 310 311 312 313 314
	belle_sip_request_t* req;
	belle_sip_header_address_t* from;
	belle_sip_header_address_t* to;
	belle_sip_header_address_t* route;
	belle_sip_header_allow_t* header_allow;
	belle_sip_header_content_type_t* content_type ;
	belle_sip_header_content_length_t* content_length;
	belle_sip_client_transaction_t* client_transaction;
315
	char  cookie[4];
jehan's avatar
jehan committed
316 317 318

	caller_listener_callbacks.process_dialog_terminated=process_dialog_terminated;
	caller_listener_callbacks.process_io_error=process_io_error;
jehan's avatar
jehan committed
319
	caller_listener_callbacks.process_request_event=caller_process_request_event;
jehan's avatar
jehan committed
320
	caller_listener_callbacks.process_response_event=caller_process_response_event;
jehan's avatar
jehan committed
321 322
	caller_listener_callbacks.process_timeout=process_timeout;
	caller_listener_callbacks.process_transaction_terminated=process_transaction_terminated;
323
	caller_listener_callbacks.listener_destroyed=listener_destroyed;
jehan's avatar
jehan committed
324 325 326

	callee_listener_callbacks.process_dialog_terminated=process_dialog_terminated;
	callee_listener_callbacks.process_io_error=process_io_error;
327
	callee_listener_callbacks.process_request_event=callee_process_request_event;
jehan's avatar
jehan committed
328
	callee_listener_callbacks.process_response_event=callee_process_response_event;
jehan's avatar
jehan committed
329 330
	callee_listener_callbacks.process_timeout=process_timeout;
	callee_listener_callbacks.process_transaction_terminated=process_transaction_terminated;
331
	callee_listener_callbacks.listener_destroyed=listener_destroyed;
jehan's avatar
jehan committed
332

jehan's avatar
jehan committed
333 334
	pauline_reg_transaction = register_user_with_transaction(stack, prov, "TCP", CALLEE, NULL);
	pauline_register_req = belle_sip_transaction_get_request((belle_sip_transaction_t*)pauline_reg_transaction);
335
	if (belle_sip_provider_get_listening_point(prov, "tls")) {
jehan's avatar
jehan committed
336
		marie_register_req = register_user(stack, prov, "TLS", 1, CALLER, NULL);
337
	} else {
jehan's avatar
jehan committed
338
		marie_register_req = register_user(stack, prov, "TCP", 1, CALLER, NULL);
339
	}
jehan's avatar
jehan committed
340

jehan's avatar
jehan committed
341
	from = belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLER,test_domain));
342 343 344
	/*to make sure unexpected messages are ignored*/
	belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(from),"cookie",belle_sip_random_token(cookie,sizeof(cookie)));
	/*to make sure unexpected messages are ignored*/
jehan's avatar
jehan committed
345
	to = belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLEE,test_domain));
346
	belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(to),"cookie",belle_sip_random_token(cookie,sizeof(cookie)));
347

jehan's avatar
jehan committed
348 349
	belle_sip_provider_add_sip_listener(prov, caller_listener = belle_sip_listener_create_from_callbacks(&caller_listener_callbacks, belle_sip_object_ref(belle_sip_header_address_get_uri((belle_sip_header_address_t*)from))));
	belle_sip_provider_add_sip_listener(prov, callee_listener = belle_sip_listener_create_from_callbacks(&callee_listener_callbacks, belle_sip_object_ref(belle_sip_header_address_get_uri((belle_sip_header_address_t*)to))));
350

jehan's avatar
jehan committed
351 352 353
	route = belle_sip_header_address_create(NULL,belle_sip_uri_create(NULL,test_domain));
	belle_sip_uri_set_transport_param(belle_sip_header_address_get_uri(route),"tcp");

jehan's avatar
jehan committed
354 355
	req = build_request(stack,prov,from,to,route,"INVITE");
	header_allow = belle_sip_header_allow_create("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK");
jehan's avatar
jehan committed
356
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(header_allow));
jehan's avatar
jehan committed
357
	
358 359 360 361
	if (enable_100rel){
		belle_sip_header_supported_t* header_supported = belle_sip_header_supported_create("100rel");
		belle_sip_message_add_header(BELLE_SIP_MESSAGE(req), BELLE_SIP_HEADER(header_supported));
	}
jehan's avatar
jehan committed
362

jehan's avatar
jehan committed
363
	content_length = belle_sip_header_content_length_create(strlen(sdp));
jehan's avatar
jehan committed
364 365 366 367 368 369 370
	content_type = belle_sip_header_content_type_create("application","sdp");
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(content_type));
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(content_length));
	belle_sip_message_set_body(BELLE_SIP_MESSAGE(req),sdp,strlen(sdp));


	client_transaction = belle_sip_provider_create_client_transaction(prov,req);
jehan's avatar
jehan committed
371
	caller_dialog = belle_sip_provider_create_dialog(prov,BELLE_SIP_TRANSACTION(client_transaction));
372
	BC_ASSERT_PTR_NOT_NULL(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction)));
jehan's avatar
jehan committed
373
	//belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),op);
jehan's avatar
jehan committed
374
	call_endeed = 0;
jehan's avatar
jehan committed
375
	belle_sip_client_transaction_send_request(client_transaction);
jehan's avatar
jehan committed
376 377
	//int i=0;
	//for(i=0;i<10 &&!call_endeed;i++)
jehan's avatar
jehan committed
378
	belle_sip_stack_sleep(stack,30000);
jehan's avatar
jehan committed
379

380
	BC_ASSERT_EQUAL(call_endeed,1, int, "%d");
jehan's avatar
jehan committed
381

jehan's avatar
jehan committed
382 383
	belle_sip_provider_remove_sip_listener(prov,caller_listener);
	belle_sip_provider_remove_sip_listener(prov,callee_listener);
384 385
	belle_sip_object_unref(caller_listener);
	belle_sip_object_unref(callee_listener);
jehan's avatar
jehan committed
386

jehan's avatar
jehan committed
387
	unregister_user(stack, prov, pauline_register_req ,1);
388
	belle_sip_object_unref(pauline_register_req);
jehan's avatar
jehan committed
389
	unregister_user(stack, prov, marie_register_req ,1);
390
	belle_sip_object_unref(marie_register_req);
jehan's avatar
jehan committed
391
}
392

393 394
static void simple_call(void){
	belle_sip_stack_set_tx_delay(stack,0);
395
	do_simple_call(0);
396 397
}

398
static void simple_call_with_delay(void){
399
	belle_sip_stack_set_tx_delay(stack,2000);
400
	do_simple_call(0);
401 402
	belle_sip_stack_set_tx_delay(stack,0);
}
403 404 405 406 407 408

static void simple_call_with_prack(void){
	belle_sip_stack_set_tx_delay(stack,0);
	do_simple_call(1);
}

409 410 411 412 413 414 415 416 417 418
/*static void simple_call_udp_tcp_with_delay(void){
	belle_sip_listening_point_t* lp=belle_sip_provider_get_listening_point(prov,"tls");
	belle_sip_object_ref(lp);
	belle_sip_stack_set_tx_delay(stack,2000);
	belle_sip_provider_remove_listening_point(prov,lp);
	do_simple_call();
	belle_sip_stack_set_tx_delay(stack,0);
	belle_sip_provider_add_listening_point(prov,lp);
	belle_sip_object_unref(lp);
}*/
419

jehan's avatar
jehan committed
420

Ghislain MARY's avatar
Ghislain MARY committed
421
test_t dialog_tests[] = {
422 423
	TEST_ONE_TAG("Simple call", simple_call, "LeaksMemory"),
	TEST_ONE_TAG("Simple call with delay", simple_call_with_delay, "LeaksMemory"),
424
	TEST_ONE_TAG("Simple call with prack", simple_call_with_prack, "LeaksMemory"),
Ghislain MARY's avatar
Ghislain MARY committed
425 426
};

427 428 429
test_suite_t dialog_test_suite = {"Dialog", register_before_all, register_after_all, belle_sip_tester_before_each,
								  belle_sip_tester_after_each, sizeof(dialog_tests) / sizeof(dialog_tests[0]),
								  dialog_tests};