static void belle_request_process_response_event(void *ctx, const belle_http_response_event_t *event) {
	LinphoneCore *lc = (LinphoneCore *)ctx;
	belle_sip_message_t *message = BELLE_SIP_MESSAGE(event->response);
	const char *body = belle_sip_message_get_body(message);

	if (belle_http_response_get_status_code(event->response) == 200) {
		linphone_remote_provisioning_apply(lc, body);
	} else {
		linphone_configuring_terminated(lc, LinphoneConfiguringFailed, "http error");
	}
}
static void process_response_from_post_xml_rpc_request(void *data, const belle_http_response_event_t *event) {
	CardDavRequest *request = (CardDavRequest *)data;
	
	if (event->response) {
		int code = belle_http_response_get_status_code(event->response);
		belle_sip_message("HTTP code: %i", code);
		if (code == 207 || code == 200) {
			/*const char *body = belle_sip_message_get_body((belle_sip_message_t *)event->response);
			belle_sip_message("%s", body);*/
			request->request_in_progress = 0;
		}
	}
}
belle_sip_error_code belle_http_response_marshal(belle_http_response_t *resp, char* buff, size_t buff_size, size_t *offset) {
	belle_sip_error_code error=belle_sip_snprintf(	buff
													,buff_size
													,offset
													,"HTTP/1.1 %i %s\r\n"
													,belle_http_response_get_status_code(resp)
													,belle_http_response_get_reason_phrase(resp)?belle_http_response_get_reason_phrase(resp):"");
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_headers_marshal(BELLE_SIP_MESSAGE(resp),buff,buff_size,offset);
	if (error!=BELLE_SIP_OK) return error;
	
	return error;
}
Exemple #4
0
static void process_response_from_post_xml_rpc_request(void *data, const belle_http_response_event_t *event) {
    LinphoneXmlRpcRequest *request = (LinphoneXmlRpcRequest *)data;

    /* Check the answer code */
    if (event->response) {
        int code = belle_http_response_get_status_code(event->response);
        if (code == 200) { /* Valid response from the server. */
            parse_valid_xml_rpc_response(request, belle_sip_message_get_body((belle_sip_message_t *)event->response));
        } else {
            notify_xml_rpc_error(request);
        }
    }
    linphone_xml_rpc_request_unref(request);
}
Exemple #5
0
static void process_response(void *data, const belle_http_response_event_t *event){
	http_counters_t *counters=(http_counters_t*)data;
	counters->response_count++;
	CU_ASSERT_PTR_NOT_NULL(event->response);
	if (event->response){
		int code=belle_http_response_get_status_code(event->response);
		const char *body=belle_sip_message_get_body(BELLE_SIP_MESSAGE(event->response));
		if (code>=200 && code <300)
			counters->two_hundred++;
		else if (code>=300 && code <400)
			counters->three_hundred++;
		else if (code>=300 && code <400)
			counters->four_hundred++;

		CU_ASSERT_PTR_NOT_NULL(body);
	}
}
static void testHttp200Ok(void)  {
	const char* raw_message = 	"HTTP/1.1 200 OK\r\n"
								"Date: Tue, 07 Jan 2014 09:28:43 GMT\r\n"
								"Server: Apache\r\n"
								"Last-Modified: Tue, 18 Aug 1998 20:19:11 GMT\r\n"
								"ETag: \"8982a60-14a17-335b3dcdcadc0\"\r\n"
								"Accept-Ranges: bytes\r\n"
								"Vary: Accept-Encoding\r\n"
								"Content-Encoding: gzip\r\n"
								"Content-Length: 6\r\n"
								"Keep-Alive: timeout=15, max=100\r\n"
								"Connection: Keep-Alive\r\n"
								"Content-Type: text/plain\r\n"
								"\r\n"
								"blabla";

	char* marshaled_msg;
	belle_sip_message_t* msg = belle_sip_message_parse(raw_message);
	belle_http_response_t* http_response;
	belle_sip_header_extension_t* host_header;
	belle_sip_object_t* tmp;

	CU_ASSERT_PTR_NOT_NULL_FATAL(msg);

	marshaled_msg=belle_sip_object_to_string(BELLE_SIP_OBJECT(msg));
	belle_sip_object_unref(msg);
	msg = belle_sip_message_parse(marshaled_msg);
	belle_sip_free(marshaled_msg);
	tmp=belle_sip_object_clone(BELLE_SIP_OBJECT(msg));
	belle_sip_object_unref(msg);
	msg=BELLE_SIP_MESSAGE(tmp);

	CU_ASSERT_TRUE(BELLE_SIP_IS_INSTANCE_OF(msg,belle_http_response_t));
	http_response=BELLE_HTTP_RESPONSE(msg);

	CU_ASSERT_EQUAL(belle_http_response_get_status_code(http_response),200);
	CU_ASSERT_STRING_EQUAL(belle_http_response_get_reason_phrase(http_response),"OK");

	CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Date"));
	CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"ETag"));
	CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Connection"));
	CU_ASSERT_PTR_NOT_NULL(host_header=BELLE_SIP_HEADER_EXTENSION(belle_sip_message_get_header(msg,"Server")));
	CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(host_header),"Apache");
	belle_sip_object_unref(msg);
}
void channel_parser_http_response () {
	belle_sip_stack_t* stack = belle_sip_stack_new(NULL);
	belle_sip_channel_t* channel = belle_sip_stream_channel_new_client(stack
																	, NULL
																	, 45421
																	, NULL
																	, "127.0.0.1"
																	, 45421);

	const char * raw_message=	"HTTP/1.1 200 OK\r\n"
								"Cache-Control: private\r\n"
								"Date: Tue, 07 Jan 2014 13:51:57 GMT\r\n"
								"Content-Type: text/html; charset=utf-8\r\n"
								"Server: Microsoft-IIS/6.0\r\n"
								"X-Powered-By: ASP.NET\r\n"
								"Content-Encoding: gzip\r\n"
								"Vary: Accept-Encoding\r\n"
								"Transfer-Encoding: chunked\r\n"
								"\r\n"
								"<html></html>\r\n\r\n";
	belle_http_response_t* response;
	belle_sip_message_t* message;
	channel->input_stream.write_ptr = strcpy(channel->input_stream.write_ptr,raw_message);
	channel->input_stream.write_ptr+=strlen(raw_message);

	belle_sip_channel_parse_stream(channel,TRUE);

	CU_ASSERT_PTR_NOT_NULL(channel->incoming_messages);
	CU_ASSERT_PTR_NOT_NULL(channel->incoming_messages->data);
	message=BELLE_SIP_MESSAGE(channel->incoming_messages->data);
	CU_ASSERT_TRUE(BELLE_SIP_OBJECT_IS_INSTANCE_OF(message,belle_http_response_t));
	response = BELLE_HTTP_RESPONSE(message);
	CU_ASSERT_STRING_EQUAL(belle_http_response_get_reason_phrase(response),"OK");
	CU_ASSERT_EQUAL(belle_http_response_get_status_code(response),200);
	CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Cache-Control"));
	CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Vary"));

	belle_sip_object_unref(BELLE_SIP_OBJECT(message));
	belle_sip_object_unref(stack);
}
static void http_channel_context_handle_response_headers(belle_http_channel_context_t *ctx , belle_sip_channel_t *chan, belle_http_response_t *response){
	belle_http_request_t *req=ctx->pending_requests ? (belle_http_request_t*) ctx->pending_requests->data : NULL;
	belle_http_response_event_t ev={0};
	int code;

	if (req==NULL){
		belle_sip_error("Receiving http response headers not matching any request.");
		return;
	}
	if (belle_http_request_is_cancelled(req)) {
		belle_sip_warning("Receiving http response headers for a cancelled request.");
		return;
	}
	code=belle_http_response_get_status_code(response);
	if (code!=401 && code!=407){
		/*else notify the app about the response headers received*/
		ev.source=(belle_sip_object_t*)ctx->provider;
		ev.request=req;
		ev.response=response;
		BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_response_headers,&ev);
	}
}
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);
}