Zebediah Figura : httpapi: Implement HttpReceiveRequestEntityBody().
Alexandre Julliard
julliard at winehq.org
Mon Nov 4 16:40:25 CST 2019
Module: wine
Branch: master
Commit: c1a62e0167835e85d4abcb4c362be25f492d4cb1
URL: https://source.winehq.org/git/wine.git/?a=commit;h=c1a62e0167835e85d4abcb4c362be25f492d4cb1
Author: Zebediah Figura <z.figura12 at gmail.com>
Date: Sun Nov 3 20:20:38 2019 -0600
httpapi: Implement HttpReceiveRequestEntityBody().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48017
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/httpapi/httpapi_main.c | 31 ++++++++++--
dlls/httpapi/tests/httpapi.c | 118 ++++++++++++++++++++++++++++++++++++++++++-
include/http.h | 2 +
3 files changed, 147 insertions(+), 4 deletions(-)
diff --git a/dlls/httpapi/httpapi_main.c b/dlls/httpapi/httpapi_main.c
index 47b5d8a2bb..0449d53045 100644
--- a/dlls/httpapi/httpapi_main.c
+++ b/dlls/httpapi/httpapi_main.c
@@ -284,12 +284,37 @@ ULONG WINAPI HttpRemoveUrl(HANDLE queue, const WCHAR *url)
ULONG WINAPI HttpReceiveRequestEntityBody(HANDLE queue, HTTP_REQUEST_ID id, ULONG flags,
void *buffer, ULONG size, ULONG *ret_size, OVERLAPPED *ovl)
{
- *ret_size = 0;
+ struct http_receive_body_params params =
+ {
+ .id = id,
+ .bits = sizeof(void *) * 8,
+ };
+ ULONG ret = ERROR_SUCCESS;
+ OVERLAPPED sync_ovl;
- FIXME("stub: queue %p, id %s, flags %#x, buffer %p, size %#x, ret_size %p, ovl %p.\n",
+ TRACE("queue %p, id %s, flags %#x, buffer %p, size %#x, ret_size %p, ovl %p.\n",
queue, wine_dbgstr_longlong(id), flags, buffer, size, ret_size, ovl);
- return ERROR_HANDLE_EOF;
+ if (flags)
+ FIXME("Ignoring flags %#x.\n", flags);
+
+ if (!ovl)
+ {
+ sync_ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+ ovl = &sync_ovl;
+ }
+
+ if (!DeviceIoControl(queue, IOCTL_HTTP_RECEIVE_BODY, ¶ms, sizeof(params), buffer, size, NULL, ovl))
+ ret = GetLastError();
+
+ if (ovl == &sync_ovl)
+ {
+ if (!GetOverlappedResult(queue, ovl, ret_size, TRUE))
+ ret = GetLastError();
+ CloseHandle(sync_ovl.hEvent);
+ }
+
+ return ret;
}
/***********************************************************************
diff --git a/dlls/httpapi/tests/httpapi.c b/dlls/httpapi/tests/httpapi.c
index 5c3b4ec13c..c506023ee7 100644
--- a/dlls/httpapi/tests/httpapi.c
+++ b/dlls/httpapi/tests/httpapi.c
@@ -546,12 +546,13 @@ static void test_v1_short_buffer(void)
static void test_v1_entity_body(void)
{
- char DECLSPEC_ALIGN(8) req_buffer[4096], response_buffer[2048], req_body[2048];
+ char DECLSPEC_ALIGN(8) req_buffer[4096], response_buffer[2048], req_body[2048], recv_body[2000];
HTTP_REQUEST_V1 *req = (HTTP_REQUEST_V1 *)req_buffer;
HTTP_RESPONSE_V1 response = {};
HTTP_DATA_CHUNK chunks[2] = {};
ULONG ret, chunk_size;
unsigned int i;
+ OVERLAPPED ovl;
DWORD ret_size;
HANDLE queue;
SOCKET s;
@@ -571,6 +572,8 @@ static void test_v1_entity_body(void)
"Content-Length: 2048\r\n"
"\r\n";
+ ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
+
for (i = 0; i < sizeof(req_body); ++i)
req_body[i] = i / 111;
@@ -708,6 +711,119 @@ static void test_v1_entity_body(void)
send_response_v1(queue, req->RequestId, s);
+ /* Test HttpReceiveRequestEntityBody(). */
+
+ ret = send(s, post_req, sizeof(post_req), 0);
+ ok(ret == sizeof(post_req), "send() returned %d.\n", ret);
+ Sleep(100);
+
+ ret = HttpReceiveHttpRequest(queue, HTTP_NULL_ID, 0, (HTTP_REQUEST *)req, sizeof(req_buffer), &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+
+ ret = HttpReceiveRequestEntityBody(queue, HTTP_NULL_ID, 0, recv_body, sizeof(recv_body), &ret_size, NULL);
+ ok(ret == ERROR_CONNECTION_INVALID, "Got error %u.\n", ret);
+
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+ ok(ret_size == 5, "Got size %u.\n", ret_size);
+ ok(!memcmp(recv_body, "ping", 5), "Entity body didn't match.\n");
+
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), &ret_size, NULL);
+ ok(ret == ERROR_HANDLE_EOF, "Got error %u.\n", ret);
+ ok(ret_size == 0xdeadbeef || !ret_size /* Win10+ */, "Got size %u.\n", ret_size);
+
+ send_response_v1(queue, req->RequestId, s);
+
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), &ret_size, NULL);
+ ok(ret == ERROR_CONNECTION_INVALID, "Got error %u.\n", ret);
+
+ ret = send(s, post_req, sizeof(post_req), 0);
+ ok(ret == sizeof(post_req), "send() returned %d.\n", ret);
+ Sleep(100);
+
+ ret = HttpReceiveHttpRequest(queue, HTTP_NULL_ID, 0, (HTTP_REQUEST *)req, sizeof(req_buffer), &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+
+ memset(recv_body, 0xcc, sizeof(recv_body));
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, 2, &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+ ok(ret_size == 2, "Got size %u.\n", ret_size);
+ ok(!memcmp(recv_body, "pi", 2), "Entity body didn't match.\n");
+
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, 4, &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+ ok(ret_size == 3, "Got size %u.\n", ret_size);
+ ok(!memcmp(recv_body, "ng", 3), "Entity body didn't match.\n");
+
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), &ret_size, NULL);
+ ok(ret == ERROR_HANDLE_EOF, "Got error %u.\n", ret);
+ ok(ret_size == 0xdeadbeef || !ret_size /* Win10+ */, "Got size %u.\n", ret_size);
+
+ send_response_v1(queue, req->RequestId, s);
+
+ ret = send(s, post_req, sizeof(post_req), 0);
+ ok(ret == sizeof(post_req), "send() returned %d.\n", ret);
+ Sleep(100);
+
+ ret = HttpReceiveHttpRequest(queue, HTTP_NULL_ID, 0, (HTTP_REQUEST *)req, sizeof(req_buffer), &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+
+ memset(recv_body, 0xcc, sizeof(recv_body));
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), NULL, &ovl);
+ ok(!ret || ret == ERROR_IO_PENDING, "Got error %u.\n", ret);
+ ret = GetOverlappedResult(queue, &ovl, &ret_size, TRUE);
+ ok(ret, "Got error %u.\n", GetLastError());
+ ok(ret_size == 5, "Got size %u.\n", ret_size);
+ ok(!memcmp(recv_body, "ping", 5), "Entity body didn't match.\n");
+
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), NULL, &ovl);
+ ok(ret == ERROR_HANDLE_EOF, "Got error %u.\n", ret);
+
+ send_response_v1(queue, req->RequestId, s);
+
+ ret = send(s, post_req, sizeof(post_req), 0);
+ ok(ret == sizeof(post_req), "send() returned %d.\n", ret);
+ Sleep(100);
+
+ ret = HttpReceiveHttpRequest(queue, HTTP_NULL_ID, HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
+ (HTTP_REQUEST *)req, sizeof(req_buffer), &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), NULL, &ovl);
+ ok(ret == ERROR_HANDLE_EOF, "Got error %u.\n", ret);
+
+ send_response_v1(queue, req->RequestId, s);
+
+ ret = send(s, post_req2, strlen(post_req2), 0);
+ ok(ret == strlen(post_req2), "send() returned %d.\n", ret);
+ ret = send(s, req_body, sizeof(req_body), 0);
+ ok(ret == sizeof(req_body), "send() returned %d.\n", ret);
+
+ Sleep(100);
+
+ ret = HttpReceiveHttpRequest(queue, HTTP_NULL_ID, HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
+ (HTTP_REQUEST *)req, 2000, &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+ ok(ret_size == 2000, "Got size %u.\n", ret_size);
+ ok(req->Flags == HTTP_REQUEST_FLAG_MORE_ENTITY_BODY_EXISTS, "Got flags %#x.\n", req->Flags);
+ chunk_size = req->pEntityChunks[0].FromMemory.BufferLength;
+
+ memset(recv_body, 0xcc, sizeof(recv_body));
+ ret_size = 0xdeadbeef;
+ ret = HttpReceiveRequestEntityBody(queue, req->RequestId, 0, recv_body, sizeof(recv_body), &ret_size, NULL);
+ ok(!ret, "Got error %u.\n", ret);
+ ok(ret_size == 2048 - chunk_size, "Got size %u.\n", ret_size);
+ ok(!memcmp(recv_body, req_body + chunk_size, ret_size), "Entity body didn't match.\n");
+
+ send_response_v1(queue, req->RequestId, s);
+
+ CloseHandle(ovl.hEvent);
ret = HttpRemoveUrl(queue, localhost_urlW);
ok(!ret, "Got error %u.\n", ret);
closesocket(s);
diff --git a/include/http.h b/include/http.h
index 49eb557fae..394167fd68 100644
--- a/include/http.h
+++ b/include/http.h
@@ -46,6 +46,8 @@ typedef struct _HTTPAPI_VERSION
#define HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY 0x00000001
#define HTTP_RECEIVE_REQUEST_FLAG_FLUSH_BODY 0x00000002
+#define HTTP_RECEIVE_REQUEST_ENTITY_BODY_FLAG_FILL_BUFFER 0x00000001
+
#define HTTP_REQUEST_FLAG_MORE_ENTITY_BODY_EXISTS 0x00000001
#define HTTP_REQUEST_FLAG_IP_ROUTED 0x00000002
#define HTTP_REQUEST_FLAG_HTTP2 0x00000004
More information about the wine-cvs
mailing list