belle_sip_dialog_tester.c 20.6 KB
Newer Older
jehan's avatar
jehan committed
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * Copyright (c) 2012-2019 Belledonne Communications SARL.
 *
 * This file is part of belle-sip.
 *
 * 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
 * the Free Software Foundation, either version 3 of the License, or
 * (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/>.
 */
jehan's avatar
jehan committed
19 20

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

Simon Morlat's avatar
Simon Morlat committed
23
#include "register_tester.h"
jehan's avatar
jehan committed
24
int call_endeed;
jehan's avatar
jehan committed
25 26


jehan's avatar
jehan committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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
48 49 50 51
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
52
static belle_sip_client_transaction_t* pauline_reg_transaction;
jehan's avatar
jehan committed
53 54 55 56 57 58 59 60 61 62 63 64 65


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;
66
	BELLESIP_UNUSED(stack);
jehan's avatar
jehan committed
67 68 69 70 71 72 73

	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
74 75 76
	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
77 78 79 80 81 82 83 84 85
	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
86
	
jehan's avatar
jehan committed
87 88 89 90 91 92 93 94
	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){
95 96
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
jehan's avatar
jehan committed
97 98
	belle_sip_message("process_dialog_terminated not implemented yet");
}
Ghislain MARY's avatar
Ghislain MARY committed
99

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

jehan's avatar
jehan committed
106
static void caller_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) {
107 108 109
	belle_sip_server_transaction_t* server_transaction;
	belle_sip_response_t* resp;
	belle_sip_dialog_t* dialog;
jehan's avatar
jehan committed
110 111
	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)))) {
112
		belle_sip_message("Message [%p] not for caller, skipping",belle_sip_request_event_get_request(event));
jehan's avatar
jehan committed
113 114 115
		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)));
116
	server_transaction=belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
117
	BC_ASSERT_STRING_EQUAL("BYE",belle_sip_request_get_method(belle_sip_request_event_get_request(event)));
118
	dialog =  belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(server_transaction));
119 120 121
	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
122 123 124 125
	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
126

127
static void callee_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) {
128 129 130 131
	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
132
	belle_sip_server_transaction_t* server_transaction = belle_sip_request_event_get_server_transaction(event);
133 134 135
	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)))) {
136
		belle_sip_message("Message [%p] not for callee, skipping",belle_sip_request_event_get_request(event));
137 138
		return; /*not for the callee*/
	}
139
	method = belle_sip_request_get_method(belle_sip_request_event_get_request(event));
jehan's avatar
jehan committed
140 141 142 143 144 145 146 147
	
	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;
	}
	
148
	if (!server_transaction && strcmp(method,"ACK")!=0) {
jehan's avatar
jehan committed
149 150
		server_transaction= belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
	}
151

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

jehan's avatar
jehan committed
161
	if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_NULL) {
jehan's avatar
jehan committed
162
		/*prepare 180*/
jehan's avatar
jehan committed
163
		ringing_response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(server_transaction)),180);
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 189 190
		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
191 192 193 194 195 196 197
		/*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));
198
		belle_sip_object_ref(ok_response);
jehan's avatar
jehan committed
199
		
jehan's avatar
jehan committed
200
		/*only send ringing*/
jehan's avatar
jehan committed
201
		belle_sip_server_transaction_send_response(server_transaction,ringing_response);
jehan's avatar
jehan committed
202 203 204 205
	} 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
206 207
	} 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
208
	}
209

jehan's avatar
jehan committed
210 211
}

jehan's avatar
jehan committed
212 213
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
214
	if (client_transaction == NULL)
215
		return; //fix for received 200 of PRACK
216 217 218
	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;
219 220
	belle_sip_dialog_t* dialog;
	int status;
221

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

227
	status = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event));
jehan's avatar
jehan committed
228
	belle_sip_message("caller_process_response_event [%i]",status);
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	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
246
	}
jehan's avatar
jehan committed
247
}
Ghislain MARY's avatar
Ghislain MARY committed
248

jehan's avatar
jehan committed
249
static void callee_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
250
	belle_sip_dialog_t* dialog;
jehan's avatar
jehan committed
251
	belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event);
252 253 254
	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)))) {
255
		belle_sip_message("Message [%p] not for callee, skipping",belle_sip_response_event_get_response(event));
256 257
		return; /*not for the callee*/
	}
258 259 260 261 262 263 264 265 266 267 268 269
	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
270
	}
jehan's avatar
jehan committed
271

jehan's avatar
jehan committed
272
}
Ghislain MARY's avatar
Ghislain MARY committed
273

jehan's avatar
jehan committed
274
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
275
	BELLESIP_UNUSED(user_ctx);
jehan's avatar
jehan committed
276 277 278 279 280 281 282 283
/*	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
284

jehan's avatar
jehan committed
285
static void process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
286
	BELLESIP_UNUSED(user_ctx);
jehan's avatar
jehan committed
287 288 289 290 291 292 293 294 295
/*	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);
	}
}

296 297 298 299
static void listener_destroyed(void *user_ctx){
	belle_sip_object_unref(user_ctx);
}

300
static void do_simple_call(int enable_100rel) {
jehan's avatar
jehan committed
301 302 303 304 305
#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
306
	belle_sip_listener_t* caller_listener;
jehan's avatar
jehan committed
307
	belle_sip_listener_callbacks_t callee_listener_callbacks;
jehan's avatar
jehan committed
308
	belle_sip_listener_t* callee_listener;
jehan's avatar
jehan committed
309 310 311 312 313 314 315 316
	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;
317
	char  cookie[4];
jehan's avatar
jehan committed
318 319 320

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

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

jehan's avatar
jehan committed
335 336
	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);
337
	if (belle_sip_provider_get_listening_point(prov, "tls")) {
jehan's avatar
jehan committed
338
		marie_register_req = register_user(stack, prov, "TLS", 1, CALLER, NULL);
339
	} else {
jehan's avatar
jehan committed
340
		marie_register_req = register_user(stack, prov, "TCP", 1, CALLER, NULL);
341
	}
jehan's avatar
jehan committed
342

jehan's avatar
jehan committed
343
	from = belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLER,test_domain));
344 345 346
	/*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
347
	to = belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLEE,test_domain));
348
	belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(to),"cookie",belle_sip_random_token(cookie,sizeof(cookie)));
349

jehan's avatar
jehan committed
350 351
	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))));
352

jehan's avatar
jehan committed
353 354 355
	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
356 357
	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
358
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(header_allow));
jehan's avatar
jehan committed
359
	
360 361 362 363
	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
364

jehan's avatar
jehan committed
365
	content_length = belle_sip_header_content_length_create(strlen(sdp));
jehan's avatar
jehan committed
366 367 368 369 370 371 372
	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
373
	caller_dialog = belle_sip_provider_create_dialog(prov,BELLE_SIP_TRANSACTION(client_transaction));
374
	BC_ASSERT_PTR_NOT_NULL(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction)));
jehan's avatar
jehan committed
375
	//belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),op);
jehan's avatar
jehan committed
376
	call_endeed = 0;
jehan's avatar
jehan committed
377
	belle_sip_client_transaction_send_request(client_transaction);
jehan's avatar
jehan committed
378 379
	//int i=0;
	//for(i=0;i<10 &&!call_endeed;i++)
jehan's avatar
jehan committed
380
	belle_sip_stack_sleep(stack,30000);
jehan's avatar
jehan committed
381

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

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

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

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

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

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

411 412 413 414 415 416 417 418 419 420
/*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);
}*/
421

jehan's avatar
jehan committed
422

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

429 430 431
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};