Exemple #1
0
static void channel_end_recv_background_task(belle_sip_channel_t *obj){
	if (obj->recv_bg_task_id){
		belle_sip_message("channel [%p]: ending recv background task with id=[%x].",obj,obj->recv_bg_task_id);
		belle_sip_end_background_task(obj->recv_bg_task_id);
		obj->recv_bg_task_id=0;
	}
}
static void http_channel_context_handle_io_error(belle_http_channel_context_t *ctx, belle_sip_channel_t *chan){
	belle_http_request_t *req=NULL;
	belle_sip_io_error_event_t ev={0};
	belle_sip_list_t *elem;

	/*if the error happens before attempting to send the message, the pending_requests is empty*/
	if (ctx->pending_requests==NULL) elem=chan->outgoing_messages;
	else elem=ctx->pending_requests;
	/*pop the requests for which this error is reported*/
	for(;elem!=NULL;elem=elem->next){
		req=(belle_http_request_t *)elem->data;
		/*else notify the app about the response received*/
		/*TODO: would be nice to put the message in the event*/
		ev.source=(belle_sip_object_t*)ctx->provider;
		ev.host=chan->peer_cname;
		ev.port=chan->peer_port;
		ev.transport=belle_sip_channel_get_transport_name(chan);
		BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_io_error,&ev);
		if( req->background_task_id ){
			belle_sip_warning("IO Error on HTTP request: ending bg task id=[%x]", req->background_task_id);
			belle_sip_end_background_task(req->background_task_id);
			req->background_task_id = 0;
		}
	}

}
static void belle_http_end_background_task(void* data) {
	belle_http_request_t *req = BELLE_HTTP_REQUEST(data);
	belle_sip_warning("Ending unfinished HTTP transfer background task id=[%x]", req->background_task_id);
	if( req->background_task_id ){
		belle_sip_end_background_task(req->background_task_id);
		req->background_task_id = 0;
	}
}
static void http_channel_context_handle_response(belle_http_channel_context_t *ctx , belle_sip_channel_t *chan, belle_http_response_t *response){
	belle_http_request_t *req=NULL;
	belle_http_response_event_t ev={0};
	int code;
	belle_sip_header_t *connection;
	/*pop the request matching this response*/
	ctx->pending_requests=belle_sip_list_pop_front(ctx->pending_requests,(void**)&req);
	if (req==NULL){
		belle_sip_error("Receiving http response not matching any request.");
		return;
	}
	if (belle_http_request_is_cancelled(req)) {
		belle_sip_warning("Receiving http response for a cancelled request.");
		return;
	}
	connection=belle_sip_message_get_header((belle_sip_message_t *)response,"Connection");
	if (connection && strstr(belle_sip_header_get_unparsed_value(connection),"close")!=NULL)
		chan->about_to_be_closed=TRUE;

	belle_http_request_set_response(req,response);
	code=belle_http_response_get_status_code(response);
	if ((code==401 || code==407) && http_channel_context_handle_authentication(ctx,req)==0 ){
		/*nothing to do, the request has been resubmitted with authentication*/
	}else{
		/*else notify the app about the response received*/
		ev.source=(belle_sip_object_t*)ctx->provider;
		ev.request=req;
		ev.response=response;
		BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_response,&ev);
		if( req->background_task_id ){
			belle_sip_warning("HTTP request finished: ending bg task id=[%x]", req->background_task_id);
			belle_sip_end_background_task(req->background_task_id);
			req->background_task_id = 0;
		}
	}
	belle_sip_object_unref(req);
}
Exemple #5
0
void sal_end_background_task(unsigned long id){
	belle_sip_end_background_task(id);
}