transaction.c 15.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
	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
    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/>.
*/

#include "belle_sip_internal.h"

21 22 23 24 25 26 27 28 29 30 31 32
const char *belle_sip_transaction_state_to_string(belle_sip_transaction_state_t state){
	switch(state){
		case BELLE_SIP_TRANSACTION_INIT:
			return "INIT";
		case BELLE_SIP_TRANSACTION_TRYING:
			return "TRYING";
		case BELLE_SIP_TRANSACTION_CALLING:
			return "CALLING";
		case BELLE_SIP_TRANSACTION_COMPLETED:
			return "COMPLETED";
		case BELLE_SIP_TRANSACTION_CONFIRMED:
			return "CONFIRMED";
33 34
		case BELLE_SIP_TRANSACTION_ACCEPTED:
			return "ACCEPTED";
35 36 37 38 39 40 41 42 43
		case BELLE_SIP_TRANSACTION_PROCEEDING:
			return "PROCEEDING";
		case BELLE_SIP_TRANSACTION_TERMINATED:
			return "TERMINATED";
	}
	belle_sip_fatal("Invalid transaction state.");
	return "INVALID";
}

44
static void belle_sip_transaction_init(belle_sip_transaction_t *t, belle_sip_provider_t *prov, belle_sip_request_t *req){
Simon Morlat's avatar
Simon Morlat committed
45
	t->request=(belle_sip_request_t*)belle_sip_object_ref(req);
46 47 48 49 50
	t->provider=prov;
}

static void transaction_destroy(belle_sip_transaction_t *t){
	if (t->request) belle_sip_object_unref(t->request);
51
	if (t->last_response) belle_sip_object_unref(t->last_response);
Simon Morlat's avatar
Simon Morlat committed
52
	if (t->channel) belle_sip_object_unref(t->channel);
53
	if (t->branch_id) belle_sip_free(t->branch_id);
jehan's avatar
jehan committed
54

55
}
56

57
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_transaction_t);
Simon Morlat's avatar
Simon Morlat committed
58 59

BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_transaction_t)={
Simon Morlat's avatar
Simon Morlat committed
60
	{
Simon Morlat's avatar
Simon Morlat committed
61 62 63 64
		BELLE_SIP_VPTR_INIT(belle_sip_transaction_t,belle_sip_object_t,FALSE),
		(belle_sip_object_destroy_t) transaction_destroy,
		NULL,/*no clone*/
		NULL,/*no marshall*/
Simon Morlat's avatar
Simon Morlat committed
65 66
	},
	NULL /*on_terminate*/
Simon Morlat's avatar
Simon Morlat committed
67
};
Simon Morlat's avatar
Simon Morlat committed
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
void *belle_sip_transaction_get_application_data(const belle_sip_transaction_t *t){
	return t->appdata;
}

void belle_sip_transaction_set_application_data(belle_sip_transaction_t *t, void *data){
	t->appdata=data;
}

const char *belle_sip_transaction_get_branch_id(const belle_sip_transaction_t *t){
	return t->branch_id;
}

belle_sip_transaction_state_t belle_sip_transaction_get_state(const belle_sip_transaction_t *t){
	return t->state;
}

void belle_sip_transaction_terminate(belle_sip_transaction_t *t){
86
	t->state=BELLE_SIP_TRANSACTION_TERMINATED;
Simon Morlat's avatar
Simon Morlat committed
87
	BELLE_SIP_OBJECT_VPTR(t,belle_sip_transaction_t)->on_terminate(t);
88
	belle_sip_provider_set_transaction_terminated(t->provider,t);
89 90
}

jehan's avatar
jehan committed
91
belle_sip_request_t *belle_sip_transaction_get_request(const belle_sip_transaction_t *t){
92 93 94
	return t->request;
}

Simon Morlat's avatar
Simon Morlat committed
95 96 97 98 99
void belle_sip_transaction_notify_timeout(belle_sip_transaction_t *t){
	belle_sip_timeout_event_t ev;
	ev.source=t->provider;
	ev.transaction=t;
	ev.is_server_transaction=BELLE_SIP_OBJECT_IS_INSTANCE_OF(t,belle_sip_server_transaction_t);
jehan's avatar
jehan committed
100 101 102 103 104
	BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(t,process_timeout,&ev);
}

belle_sip_dialog_t*  belle_sip_transaction_get_dialog(const belle_sip_transaction_t *t) {
	return t->dialog;
Simon Morlat's avatar
Simon Morlat committed
105 106
}

107
/*
Simon Morlat's avatar
Simon Morlat committed
108 109
 * Server transaction
 */
110

111 112 113
static void server_transaction_destroy(belle_sip_server_transaction_t *t){
}

Simon Morlat's avatar
Simon Morlat committed
114

115
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_server_transaction_t);
Simon Morlat's avatar
Simon Morlat committed
116
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_server_transaction_t)={
Simon Morlat's avatar
Simon Morlat committed
117
	{
Simon Morlat's avatar
Simon Morlat committed
118 119 120 121 122
		{
			BELLE_SIP_VPTR_INIT(belle_sip_server_transaction_t,belle_sip_transaction_t,FALSE),
			(belle_sip_object_destroy_t) server_transaction_destroy,
			NULL,
			NULL
Simon Morlat's avatar
Simon Morlat committed
123 124 125
		},
		NULL
	}
Simon Morlat's avatar
Simon Morlat committed
126
};
Simon Morlat's avatar
Simon Morlat committed
127

128
void belle_sip_server_transaction_init(belle_sip_server_transaction_t *t, belle_sip_provider_t *prov,belle_sip_request_t *req){
129 130
	belle_sip_header_via_t *via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)req,"via"));
	t->base.branch_id=belle_sip_strdup(belle_sip_header_via_get_branch(via));
131
	belle_sip_transaction_init((belle_sip_transaction_t*)t,prov,req);
132
	belle_sip_random_token(t->to_tag,sizeof(t->to_tag));
133 134
}

Simon Morlat's avatar
Simon Morlat committed
135
void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *t, belle_sip_response_t *resp){
136
	belle_sip_transaction_t *base=(belle_sip_transaction_t*)t;
137
	belle_sip_header_to_t *to=(belle_sip_header_to_t*)belle_sip_message_get_header((belle_sip_message_t*)resp,"to");
Simon Morlat's avatar
Simon Morlat committed
138
	belle_sip_dialog_t *dialog=base->dialog;
Simon Morlat's avatar
Simon Morlat committed
139
	int status_code;
Simon Morlat's avatar
Simon Morlat committed
140
	
141 142 143 144 145 146
	belle_sip_object_ref(resp);
	if (!base->last_response){
		belle_sip_hop_t hop;
		belle_sip_response_get_return_hop(resp,&hop);
		base->channel=belle_sip_provider_get_channel(base->provider,hop.host, hop.port, hop.transport);
		belle_sip_object_ref(base->channel);
147
		belle_sip_hop_free(&hop);
148
	}
Simon Morlat's avatar
Simon Morlat committed
149 150 151 152 153 154 155 156 157 158 159
	status_code=belle_sip_response_get_status_code(resp);
	if (status_code!=100){
		if (belle_sip_header_to_get_tag(to)==NULL){
			//add a random to tag
			belle_sip_header_to_set_tag(to,t->to_tag);
		}
		if (dialog && status_code>=200 && status_code<300){
			/*response establishes a dialog*/
			/*fill dialog related fields accordingly*/
			belle_sip_response_fill_for_dialog(resp,base->request);
		}
160
	}
161 162 163 164 165
	if (BELLE_SIP_OBJECT_VPTR(t,belle_sip_server_transaction_t)->send_new_response(t,resp)==0){
		if (base->last_response)
			belle_sip_object_unref(base->last_response);
		base->last_response=resp;
	}
Simon Morlat's avatar
Simon Morlat committed
166 167
	if (dialog)
		belle_sip_dialog_update(dialog,base->request,resp,TRUE);
168 169
}

170 171 172 173 174 175 176
static void server_transaction_notify(belle_sip_server_transaction_t *t, belle_sip_request_t *req, belle_sip_dialog_t *dialog){
	belle_sip_request_event_t event;

	event.source=t->base.provider;
	event.server_transaction=t;
	event.dialog=dialog;
	event.request=req;
jehan's avatar
jehan committed
177
	BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(((belle_sip_transaction_t*) t),process_request_event,&event);
178 179
}

Simon Morlat's avatar
Simon Morlat committed
180 181 182
void belle_sip_server_transaction_on_request(belle_sip_server_transaction_t *t, belle_sip_request_t *req){
	const char *method=belle_sip_request_get_method(req);
	if (strcmp(method,"ACK")==0){
183 184 185
		/*this must be for an INVITE server transaction */
		if (BELLE_SIP_OBJECT_IS_INSTANCE_OF(t,belle_sip_ist_t)){
			belle_sip_ist_t *ist=(belle_sip_ist_t*)t;
186 187 188 189 190 191
			if (belle_sip_ist_process_ack(ist,(belle_sip_message_t*)req)==0){
				belle_sip_dialog_t *dialog=t->base.dialog;
				if (dialog && belle_sip_dialog_handle_ack(dialog,req)==-1)
					dialog=NULL;
				server_transaction_notify(t,req,dialog);
			}
192 193 194
		}else{
			belle_sip_warning("ACK received for non-invite server transaction ?");
		}
Simon Morlat's avatar
Simon Morlat committed
195
	}else if (strcmp(method,"CANCEL")==0){
196
		server_transaction_notify(t,req,t->base.dialog);
Simon Morlat's avatar
Simon Morlat committed
197 198
	}else
		BELLE_SIP_OBJECT_VPTR(t,belle_sip_server_transaction_t)->on_request_retransmission(t);
Simon Morlat's avatar
Simon Morlat committed
199
}
200

Simon Morlat's avatar
Simon Morlat committed
201 202 203 204
/*
 * client transaction
 */

205

206

207
belle_sip_request_t * belle_sip_client_transaction_create_cancel(belle_sip_client_transaction_t *t){
208 209 210 211 212 213 214
	belle_sip_message_t *orig=(belle_sip_message_t*)t->base.request;
	belle_sip_request_t *req;
	const char *orig_method=belle_sip_request_get_method((belle_sip_request_t*)orig);
	if (strcmp(orig_method,"ACK")==0 || strcmp(orig_method,"INVITE")!=0){
		belle_sip_error("belle_sip_client_transaction_create_cancel() cannot be used for ACK or non-INVITE transactions.");
		return NULL;
	}
215
	if (t->base.state!=BELLE_SIP_TRANSACTION_PROCEEDING){
216 217
		belle_sip_error("belle_sip_client_transaction_create_cancel() can only be used in state BELLE_SIP_TRANSACTION_PROCEEDING"
		               " but current transaction state is %s",belle_sip_transaction_state_to_string(t->base.state));
218
		return NULL;
219 220 221 222
	}
	req=belle_sip_request_new();
	belle_sip_request_set_method(req,"CANCEL");
	belle_sip_request_set_uri(req,(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_request_get_uri((belle_sip_request_t*)orig)));
223 224 225 226 227
	belle_sip_util_copy_headers(orig,(belle_sip_message_t*)req,"via",FALSE);
	belle_sip_util_copy_headers(orig,(belle_sip_message_t*)req,"call-id",FALSE);
	belle_sip_util_copy_headers(orig,(belle_sip_message_t*)req,"from",FALSE);
	belle_sip_util_copy_headers(orig,(belle_sip_message_t*)req,"to",FALSE);
	belle_sip_util_copy_headers(orig,(belle_sip_message_t*)req,"route",TRUE);
228 229 230 231 232
	belle_sip_message_add_header((belle_sip_message_t*)req,
		(belle_sip_header_t*)belle_sip_header_cseq_create(
			belle_sip_header_cseq_get_seq_number((belle_sip_header_cseq_t*)belle_sip_message_get_header(orig,"cseq")),
		    "CANCEL"));
	return req;
233
}
Simon Morlat's avatar
Simon Morlat committed
234

235

236
int belle_sip_client_transaction_send_request(belle_sip_client_transaction_t *t){
Simon Morlat's avatar
Simon Morlat committed
237 238
	belle_sip_hop_t hop={0};
	belle_sip_channel_t *chan;
Simon Morlat's avatar
Simon Morlat committed
239
	belle_sip_provider_t *prov=t->base.provider;
Simon Morlat's avatar
Simon Morlat committed
240
	
Simon Morlat's avatar
Simon Morlat committed
241 242
	if (t->base.state!=BELLE_SIP_TRANSACTION_INIT){
		belle_sip_error("belle_sip_client_transaction_send_request: bad state.");
243
		return -1;
Simon Morlat's avatar
Simon Morlat committed
244
	}
jehan's avatar
jehan committed
245 246 247 248
	/*store preset route for futur use by refresher*/
	t->preset_route=BELLE_SIP_HEADER_ROUTE(belle_sip_message_get_header(BELLE_SIP_MESSAGE(t->base.request),"route"));
	if (t->preset_route) belle_sip_object_ref(t->preset_route);

Simon Morlat's avatar
Simon Morlat committed
249 250 251
	belle_sip_stack_get_next_hop(prov->stack,t->base.request,&hop);
	chan=belle_sip_provider_get_channel(prov,hop.host, hop.port, hop.transport);
	if (chan){
252
		belle_sip_provider_add_client_transaction(t->base.provider,t);
Simon Morlat's avatar
Simon Morlat committed
253
		belle_sip_object_ref(chan);
Simon Morlat's avatar
Simon Morlat committed
254 255
		belle_sip_channel_add_listener(chan,BELLE_SIP_CHANNEL_LISTENER(t));
		t->base.channel=chan;
Simon Morlat's avatar
Simon Morlat committed
256 257 258 259
		if (belle_sip_channel_get_state(chan)==BELLE_SIP_CHANNEL_INIT)
			belle_sip_channel_prepare(chan);
		if (belle_sip_channel_get_state(chan)!=BELLE_SIP_CHANNEL_READY){
			belle_sip_message("belle_sip_client_transaction_send_request(): waiting channel to be ready");
260 261
		} else {
			BELLE_SIP_OBJECT_VPTR(t,belle_sip_client_transaction_t)->send_request(t);
Simon Morlat's avatar
Simon Morlat committed
262
		}
Simon Morlat's avatar
Simon Morlat committed
263
	}else belle_sip_error("belle_sip_client_transaction_send_request(): no channel available");
264
	belle_sip_hop_free(&hop);
265
	return 0;
Simon Morlat's avatar
Simon Morlat committed
266
}
jehan's avatar
jehan committed
267 268 269 270 271 272
static unsigned int should_dialog_be_created(belle_sip_client_transaction_t *t, belle_sip_response_t *resp){
	belle_sip_request_t* req = belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(t));
	const char* method = belle_sip_request_get_method(req);
	int status_code = belle_sip_response_get_status_code(resp);
	return status_code>=200 && status_code<300 && (strcmp(method,"INVITE")==0 || strcmp(method,"SUBSCRIBE")==0);
}
273
void belle_sip_client_transaction_notify_response(belle_sip_client_transaction_t *t, belle_sip_response_t *resp){
Simon Morlat's avatar
Simon Morlat committed
274
	belle_sip_transaction_t *base=(belle_sip_transaction_t*)t;
275
	belle_sip_response_event_t event;
Simon Morlat's avatar
Simon Morlat committed
276
	belle_sip_dialog_t *dialog=base->dialog;
277
	int status_code =  belle_sip_response_get_status_code(resp);
278 279
	if (base->last_response)
		belle_sip_object_unref(base->last_response);
280

Simon Morlat's avatar
Simon Morlat committed
281
	if (dialog){
282 283
		if (status_code>=200 && status_code<300
				&& (dialog->state==BELLE_SIP_DIALOG_EARLY || dialog->state==BELLE_SIP_DIALOG_CONFIRMED)){
Simon Morlat's avatar
Simon Morlat committed
284 285
			/*make sure this response matches the current dialog, or creates a new one*/
			if (!belle_sip_dialog_match(dialog,(belle_sip_message_t*)resp,FALSE)){
jehan's avatar
jehan committed
286
				dialog=belle_sip_provider_create_dialog(t->base.provider,BELLE_SIP_TRANSACTION(t));/*belle_sip_dialog_new(base);*/
Simon Morlat's avatar
Simon Morlat committed
287
				if (dialog){
jehan's avatar
jehan committed
288 289
					/*copy userdata to avoid application from being lost*/
					belle_sip_dialog_set_application_data(dialog,belle_sip_dialog_get_application_data(base->dialog));
Simon Morlat's avatar
Simon Morlat committed
290 291 292 293
					belle_sip_message("Handling response creating a new dialog !");
				}
			}
		}
jehan's avatar
jehan committed
294 295
	} else if (should_dialog_be_created(t,resp)) {
		dialog=belle_sip_provider_create_dialog(t->base.provider,BELLE_SIP_TRANSACTION(t));
Simon Morlat's avatar
Simon Morlat committed
296
	}
jehan's avatar
jehan committed
297 298 299 300
	base->last_response=(belle_sip_response_t*)belle_sip_object_ref(resp);
	if (dialog)
		belle_sip_dialog_update(dialog,base->request,resp,FALSE);

301 302
	event.source=base->provider;
	event.client_transaction=t;
Simon Morlat's avatar
Simon Morlat committed
303
	event.dialog=dialog;
304
	event.response=(belle_sip_response_t*)resp;
jehan's avatar
jehan committed
305
	BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(((belle_sip_transaction_t*)t),process_response_event,&event);
Simon Morlat's avatar
Simon Morlat committed
306 307
	/*check that 200Ok for INVITEs have been acknoledged by listener*/
	if (dialog) belle_sip_dialog_check_ack_sent(dialog);
308 309 310 311 312
}


void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t, belle_sip_response_t *resp){
	BELLE_SIP_OBJECT_VPTR(t,belle_sip_client_transaction_t)->on_response(t,resp);
Simon Morlat's avatar
Simon Morlat committed
313 314
}

Simon Morlat's avatar
Simon Morlat committed
315
static void client_transaction_destroy(belle_sip_client_transaction_t *t ){
jehan's avatar
jehan committed
316
	if (t->preset_route) belle_sip_object_unref(t->preset_route);
Simon Morlat's avatar
Simon Morlat committed
317 318
}

Simon Morlat's avatar
Simon Morlat committed
319 320
static void on_channel_state_changed(belle_sip_channel_listener_t *l, belle_sip_channel_t *chan, belle_sip_channel_state_t state){
	belle_sip_client_transaction_t *t=(belle_sip_client_transaction_t*)l;
Simon Morlat's avatar
Simon Morlat committed
321
	belle_sip_message("transaction on_channel_state_changed");
Simon Morlat's avatar
Simon Morlat committed
322 323 324 325 326 327 328 329
	switch(state){
		case BELLE_SIP_CHANNEL_READY:
			BELLE_SIP_OBJECT_VPTR(t,belle_sip_client_transaction_t)->send_request(t);
		break;
		default:
			/*ignored*/
		break;
	}
Simon Morlat's avatar
Simon Morlat committed
330 331
}

Simon Morlat's avatar
Simon Morlat committed
332 333 334 335 336 337 338 339 340
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_sip_client_transaction_t,belle_sip_channel_listener_t)
on_channel_state_changed,
NULL,
NULL
BELLE_SIP_IMPLEMENT_INTERFACE_END

BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_sip_client_transaction_t, belle_sip_channel_listener_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_client_transaction_t)={
	{
Simon Morlat's avatar
Simon Morlat committed
341 342 343 344 345 346
		{
			BELLE_SIP_VPTR_INIT(belle_sip_client_transaction_t,belle_sip_transaction_t,FALSE),
			(belle_sip_object_destroy_t)client_transaction_destroy,
			NULL,
			NULL
		},
Simon Morlat's avatar
Simon Morlat committed
347 348 349 350 351
		NULL
	},
	NULL,
	NULL
};
Simon Morlat's avatar
Simon Morlat committed
352

Simon Morlat's avatar
Simon Morlat committed
353
void belle_sip_client_transaction_init(belle_sip_client_transaction_t *obj, belle_sip_provider_t *prov, belle_sip_request_t *req){
Simon Morlat's avatar
Simon Morlat committed
354 355
	belle_sip_header_via_t *via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)req,"via"));
	char token[10];
356 357 358 359 360 361 362

	if (!via){
		belle_sip_fatal("belle_sip_client_transaction_init(): No via in request.");
	}
	
	if (strcmp(belle_sip_request_get_method(req),"CANCEL")!=0){
		obj->base.branch_id=belle_sip_strdup_printf(BELLE_SIP_BRANCH_MAGIC_COOKIE ".%s",belle_sip_random_token(token,sizeof(token)));
Simon Morlat's avatar
Simon Morlat committed
363 364
		belle_sip_header_via_set_branch(via,obj->base.branch_id);
	}else{
365
		obj->base.branch_id=belle_sip_strdup(belle_sip_header_via_get_branch(via));
Simon Morlat's avatar
Simon Morlat committed
366
	}
Simon Morlat's avatar
Simon Morlat committed
367
	belle_sip_transaction_init((belle_sip_transaction_t*)obj, prov,req);
368 369
}

jehan's avatar
jehan committed
370 371 372 373 374 375
belle_sip_refresher_t* belle_sip_client_transaction_create_refresher(belle_sip_client_transaction_t *t) {
	belle_sip_refresher_t* refresher = belle_sip_refresher_new(t);
	if (refresher) {
		belle_sip_refresher_start(refresher);
	}
	return refresher;
jehan's avatar
jehan committed
376
}
377

jehan's avatar
jehan committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
belle_sip_request_t* belle_sip_client_transaction_create_authenticated_request(belle_sip_client_transaction_t *t) {
	belle_sip_request_t* req=BELLE_SIP_REQUEST(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(t)))));
	belle_sip_header_cseq_t* cseq=belle_sip_message_get_header_by_type(req,belle_sip_header_cseq_t);
	belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1);
	if (belle_sip_transaction_get_state(BELLE_SIP_TRANSACTION(t)) != BELLE_SIP_TRANSACTION_COMPLETED) {
		belle_sip_error("Invalid state [%s] for transaction [%p], should be BELLE_SIP_TRANSACTION_COMPLETED"
					,belle_sip_transaction_state_to_string(belle_sip_transaction_get_state(BELLE_SIP_TRANSACTION(t)))
					,t);
		return NULL;
	}
	/*remove auth headers*/
	belle_sip_message_remove_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_AUTHORIZATION);
	belle_sip_message_remove_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_PROXY_AUTHORIZATION);
	/*add preset route if any*/
	if (t->preset_route) {
		belle_sip_object_ref(t->preset_route);
		belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(t->preset_route));
	}
	/*put auth header*/
	belle_sip_provider_add_authorization(t->base.provider,req,t->base.last_response);
	return req;
}
400