Esempio n. 1
0
void belle_sip_multipart_body_handler_progress_cb(belle_sip_body_handler_t *obj, belle_sip_message_t *msg, void *user_data, size_t transfered, size_t expected_total) {
	if (transfered == expected_total) {
		/* The full multipart body has been received, we can now parse it and split the different parts,
		 * creating a belle_sip_memory_body_handler for each part and adding them to the belle_sip_multipart_body_handler
		 * parts list. */
		belle_sip_multipart_body_handler_t *obj_multipart = (belle_sip_multipart_body_handler_t *)obj;
		belle_sip_memory_body_handler_t *memorypart;
		belle_sip_header_t *header;
		uint8_t *end_part_cursor;
		uint8_t *end_headers_cursor;
		uint8_t *end_header_cursor;
		uint8_t *cursor = obj_multipart->buffer;
		char *boundary = belle_sip_strdup_printf("--%s", obj_multipart->boundary);
		if (strncmp((char *)cursor, boundary, strlen(boundary))) {
			belle_sip_warning("belle_sip_multipart_body_handler [%p]: body not starting by specified boundary '%s'", obj_multipart, obj_multipart->boundary);
			belle_sip_free(boundary);
			return;
		}
		cursor += strlen(boundary);
		do {
			if (strncmp((char *)cursor, "\r\n", 2)) {
				belle_sip_warning("belle_sip_multipart_body_handler [%p]: no new-line after boundary", obj_multipart);
				return;
			}
			cursor += 2;
			end_part_cursor = (uint8_t *)strstr((char *)cursor, boundary);
			if (end_part_cursor == NULL) {
				belle_sip_warning("belle_sip_multipart_body_handler [%p]: cannot find next boundary", obj_multipart);
				return;
			} else {
				*end_part_cursor = 0;
				end_headers_cursor = (uint8_t *)strstr((char *)cursor, "\r\n\r\n");
				if (end_headers_cursor == NULL) {
					memorypart = belle_sip_memory_body_handler_new_copy_from_buffer(cursor, strlen((char *)cursor), NULL, NULL);
				} else {
					uint8_t *begin_body_cursor = end_headers_cursor + 4;
					memorypart = belle_sip_memory_body_handler_new_copy_from_buffer(begin_body_cursor, strlen((char *)begin_body_cursor), NULL, NULL);
					do {
						end_header_cursor = (uint8_t *)strstr((char *)cursor, "\r\n");
						*end_header_cursor = 0;
						header = belle_sip_header_parse((char *)cursor);
						if (header != NULL) {
							belle_sip_body_handler_add_header(BELLE_SIP_BODY_HANDLER(memorypart), header);
						}
						cursor = end_header_cursor + 2;
					} while (end_header_cursor != end_headers_cursor);
				}
				belle_sip_multipart_body_handler_add_part(obj_multipart, BELLE_SIP_BODY_HANDLER(memorypart));
				cursor = end_part_cursor + strlen(boundary);
			}
		} while (strcmp((char *)cursor, "--\r\n"));
		belle_sip_free(boundary);
	}
}
Esempio n. 2
0
void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) {
    belle_http_request_listener_callbacks_t cbs = { 0 };
    belle_http_request_listener_t *l;
    belle_generic_uri_t *uri;
    belle_http_request_t *req;
    belle_sip_memory_body_handler_t *bh;
    const char *data;
    LinphoneContent *content;
    linphone_xml_rpc_request_ref(request);

    uri = belle_generic_uri_parse(session->url);
    if (!uri) {
        ms_error("Could not send request, URL %s is invalid", session->url);
        process_io_error_from_post_xml_rpc_request(request, NULL);
        return;
    }
    req = belle_http_request_create("POST", uri, belle_sip_header_content_type_create("text", "xml"), NULL);
    if (!req) {
        belle_sip_object_unref(uri);
        process_io_error_from_post_xml_rpc_request(request, NULL);
    }
    content = linphone_content_new();
    linphone_content_set_type(content, "text");
    linphone_content_set_subtype(content, "xml");
    linphone_content_set_string_buffer(content, linphone_xml_rpc_request_get_content(request));
    data = linphone_xml_rpc_request_get_content(request);
    bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, NULL);
    belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh));
    cbs.process_response = process_response_from_post_xml_rpc_request;
    cbs.process_io_error = process_io_error_from_post_xml_rpc_request;
    cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request;
    l = belle_http_request_listener_create_from_callbacks(&cbs, request);
    belle_http_provider_send_request(session->core->http_provider, req, l);
    linphone_content_unref(content);
}
Esempio n. 3
0
void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) {
	belle_http_request_listener_callbacks_t cbs = { 0 };
	belle_http_request_listener_t *l;
	belle_generic_uri_t *uri;
	belle_http_request_t *req;
	belle_sip_memory_body_handler_t *bh;
	const char *data;
	linphone_xml_rpc_request_ref(request);

	uri = belle_generic_uri_parse(session->url);
	if (!uri) {
		ms_error("Could not send request, URL %s is invalid", session->url);
		process_io_error_from_post_xml_rpc_request(request, NULL);
		return;
	}
	req = belle_http_request_create("POST", uri, belle_sip_header_content_type_create("text", "xml"), NULL);
	if (!req) {
		belle_sip_object_unref(uri);
		process_io_error_from_post_xml_rpc_request(request, NULL);
		return;
	}
	data = linphone_xml_rpc_request_get_content(request);
	bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, NULL);
	belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh));
	cbs.process_response = process_response_from_post_xml_rpc_request;
	cbs.process_io_error = process_io_error_from_post_xml_rpc_request;
	cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request;
	l = belle_http_request_listener_create_from_callbacks(&cbs, request);
	belle_http_provider_send_request(session->core->http_provider, req, l);
	/*ensure that the listener object will be destroyed with the request*/
	belle_sip_object_data_set(BELLE_SIP_OBJECT(request), "listener", l, belle_sip_object_unref);
	/*prevent destruction of the session while there are still pending http requests*/
	belle_sip_object_data_set(BELLE_SIP_OBJECT(request), "session", belle_sip_object_ref(session), belle_sip_object_unref);
}
Esempio n. 4
0
static void prepare_query(CardDavRequest *request) {
	belle_http_request_listener_callbacks_t cbs = { 0 };
	belle_http_request_listener_t *l = NULL;
	belle_generic_uri_t *uri = NULL;
	belle_http_request_t *req = NULL;
	belle_sip_memory_body_handler_t *bh = NULL;
	belle_sip_stack_t *stack = NULL;
	belle_http_provider_t *http_provider = NULL;

	belle_sip_set_log_level(BELLE_SIP_LOG_MESSAGE);
	uri = belle_generic_uri_parse(request->url);
	if (!uri) {
		belle_sip_error("Could not send request, URL %s is invalid", request->url);
		return;
	}
	req = belle_http_request_create(request->method, uri, belle_sip_header_content_type_create("application", "xml; charset=utf-8"), belle_sip_header_create("Depth", request->depth), NULL);
	if (!req) {
		belle_sip_object_unref(uri);
		belle_sip_error("Could not create request");
		return;
	}
	
	bh = belle_sip_memory_body_handler_new_copy_from_buffer(request->body, strlen(request->body), NULL, NULL);
	belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh));
	
	cbs.process_response = process_response_from_post_xml_rpc_request;
	cbs.process_io_error = process_io_error_from_post_xml_rpc_request;
	cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request;
	l = belle_http_request_listener_create_from_callbacks(&cbs, request);
	
	stack = belle_sip_stack_new(NULL);
	http_provider = belle_sip_stack_create_http_provider(stack, "0.0.0.0");
	
	request->request_in_progress = 1;
	belle_http_provider_send_request(http_provider, req, l);
	while (request->request_in_progress) {
		belle_sip_stack_sleep(stack, 0);
	}
}