[PATCH v3 0/4] MR10223: Wininet refactors
This is the second set of patches towards the mfplat network bytestream, after !9369. Mostly preparatory work and refactors. -- v3: wininet: Factor request creation out of HTTP_HttpSendRequestW. wininet: Do not reset content_pos in reset_data_stream. wininet: Factor out writing of cache file. include: Add MFNETSOURCE_STATISTICS_SERVICE definition. https://gitlab.winehq.org/wine/wine/-/merge_requests/10223
From: Torge Matthies <openglfreak@googlemail.com> --- include/mfidl.idl | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mfidl.idl b/include/mfidl.idl index 23bfeb532b7..e7258f26ed6 100644 --- a/include/mfidl.idl +++ b/include/mfidl.idl @@ -1628,6 +1628,7 @@ cpp_quote("EXTERN_GUID(MR_STREAM_VOLUME_SERVICE, 0xf8b5fa2f, 0x32ef, 0x46f5, 0xb cpp_quote("EXTERN_GUID(MR_AUDIO_POLICY_SERVICE, 0x911fd737, 0x6775, 0x4ab0, 0xa6, 0x14, 0x29, 0x78, 0x62, 0xfd, 0xac, 0x88);") cpp_quote("EXTERN_GUID(MF_PROPERTY_HANDLER_SERVICE, 0xa3face02, 0x32b8, 0x41dd, 0x90, 0xe7, 0x5f, 0xef, 0x7c, 0x89, 0x91, 0xb5);") cpp_quote("EXTERN_GUID(MF_WORKQUEUE_SERVICES, 0x8e37d489, 0x41e0, 0x413a, 0x90, 0x68, 0x28, 0x7c, 0x88, 0x6d, 0x8d, 0xda);") +cpp_quote("EXTERN_GUID(MFNETSOURCE_STATISTICS_SERVICE, 0x3cb1f275, 0x0505, 0x4c5d, 0xae, 0x71, 0x0a, 0x55, 0x63, 0x44, 0xef, 0xa1);") cpp_quote("EXTERN_GUID(MF_PROGRESSIVE_CODING_CONTENT, 0x8f020eea, 0x1508, 0x471f, 0x9d, 0xa6, 0x50, 0x7d, 0x7c, 0xfa, 0x40, 0xdb);") cpp_quote("EXTERN_GUID(MF_NALU_LENGTH_SET, 0xa7911d53, 0x12a4, 0x4965, 0xae, 0x70, 0x6e, 0xad, 0xd6, 0xff, 0x05, 0x51);") -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10223
From: Torge Matthies <openglfreak@googlemail.com> --- dlls/wininet/http.c | 50 +++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index e5ef9e473e9..34f16e3a42c 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2428,6 +2428,27 @@ static void commit_cache_entry(http_request_t *req) free(header); } +static void write_cache_file(http_request_t *req, const BYTE *buf, DWORD len) +{ + if(!req->hCacheFile) { + return; + } + + if(len) { + BOOL bres; + DWORD written; + + bres = WriteFile(req->hCacheFile, buf, len, &written, NULL); + if(bres) + req->cache_size += written; + else + FIXME("WriteFile failed: %lu\n", GetLastError()); + } + + if(req->data_stream->vtbl->end_of_data(req->data_stream, req)) + commit_cache_entry(req); +} + static void create_cache_entry(http_request_t *req) { WCHAR file_name[MAX_PATH+1]; @@ -2513,18 +2534,7 @@ static void create_cache_entry(http_request_t *req) return; } - if(req->read_size) { - DWORD written; - - b = WriteFile(req->hCacheFile, req->read_buf+req->read_pos, req->read_size, &written, NULL); - if(b) - req->cache_size += written; - else - FIXME("WriteFile failed: %lu\n", GetLastError()); - - if(req->data_stream->vtbl->end_of_data(req->data_stream, req)) - commit_cache_entry(req); - } + write_cache_file(req, req->read_buf+req->read_pos, req->read_size); } /* read some more data into the read buffer (the read section must be held) */ @@ -2622,21 +2632,7 @@ static DWORD read_http_stream(http_request_t *req, BYTE *buf, DWORD size, DWORD *read = 0; assert(*read <= size); - if(req->hCacheFile) { - if(*read) { - BOOL bres; - DWORD written; - - bres = WriteFile(req->hCacheFile, buf, *read, &written, NULL); - if(bres) - req->cache_size += written; - else - FIXME("WriteFile failed: %lu\n", GetLastError()); - } - - if((res == ERROR_SUCCESS && !*read) || req->data_stream->vtbl->end_of_data(req->data_stream, req)) - commit_cache_entry(req); - } + write_cache_file(req, buf, *read); return res; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10223
From: Torge Matthies <openglfreak@googlemail.com> --- dlls/wininet/http.c | 1 - 1 file changed, 1 deletion(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 34f16e3a42c..70f9074ea06 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -329,7 +329,6 @@ static void reset_data_stream(http_request_t *req) destroy_data_stream(req->data_stream); req->data_stream = &req->netconn_stream.data_stream; req->read_pos = req->read_size = req->netconn_stream.content_read = 0; - req->content_pos = 0; req->read_gzip = FALSE; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10223
From: Torge Matthies <openglfreak@googlemail.com> --- dlls/wininet/http.c | 150 +++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 70 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 70f9074ea06..eb486d8eb29 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -5005,80 +5005,17 @@ static void set_content_length_header( http_request_t *request, DWORD len, DWORD HTTP_HttpAddRequestHeadersW( request, buf, ~0u, flags ); } -/*********************************************************************** - * HTTP_HttpSendRequestW (internal) - * - * Sends the specified request to the HTTP server - * - * RETURNS - * ERROR_SUCCESS on success - * win32 error code on failure - * - */ -static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, - DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, - DWORD dwContentLength, BOOL bEndRequest) +static DWORD create_request(http_request_t *request, void *optional, DWORD optlen, DWORD content_length, + BOOL end_request) { BOOL redirected = FALSE, secure_proxy_connect = FALSE, loop_next; WCHAR *request_header = NULL; INT responseLen, cnt; DWORD res; - const WCHAR *appinfo_agent; - - TRACE("--> %p\n", request); - - assert(request->hdr.htype == WH_HHTTPREQ); - - /* if the verb is NULL default to GET */ - if (!request->verb) - request->verb = wcsdup(L"GET"); - - HTTP_ProcessHeader(request, L"Host", request->server->canon_host_port, - HTTP_ADDREQ_FLAG_ADD_IF_NEW | HTTP_ADDHDR_FLAG_REQ); - - if (dwContentLength || wcscmp(request->verb, L"GET")) - { - set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_ADD_IF_NEW); - request->bytesToWrite = dwContentLength; - } - - appinfo_agent = request->session->appInfo->agent; - - if (appinfo_agent && *appinfo_agent) - { - WCHAR *agent_header; - int len; - - len = lstrlenW(appinfo_agent) + lstrlenW(L"User-Agent: %s\r\n"); - agent_header = malloc(len * sizeof(WCHAR)); - swprintf(agent_header, len, L"User-Agent: %s\r\n", appinfo_agent); - - HTTP_HttpAddRequestHeadersW(request, agent_header, lstrlenW(agent_header), HTTP_ADDREQ_FLAG_ADD_IF_NEW); - free(agent_header); - } - if (request->hdr.dwFlags & INTERNET_FLAG_PRAGMA_NOCACHE) - { - HTTP_HttpAddRequestHeadersW(request, L"Pragma: no-cache\r\n", - lstrlenW(L"Pragma: no-cache\r\n"), HTTP_ADDREQ_FLAG_ADD_IF_NEW); - } - if ((request->hdr.dwFlags & INTERNET_FLAG_NO_CACHE_WRITE) && wcscmp(request->verb, L"GET")) - { - HTTP_HttpAddRequestHeadersW(request, L"Cache-Control: no-cache\r\n", - lstrlenW(L"Cache-Control: no-cache\r\n"), HTTP_ADDREQ_FLAG_ADD_IF_NEW); - } - - /* add the headers the caller supplied */ - if (lpszHeaders) - { - if (dwHeaderLength == 0) - dwHeaderLength = lstrlenW(lpszHeaders); - - HTTP_HttpAddRequestHeadersW(request, lpszHeaders, dwHeaderLength, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE); - } do { - DWORD len, data_len = dwOptionalLength; + DWORD len, data_len = optlen; BOOL reusing_connection; char *ascii_req; @@ -5147,7 +5084,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, else { if (request->proxy && HTTP_GetCustomHeaderIndex(request, L"Content-Length", 0, TRUE) >= 0) - set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_REPLACE); + set_content_length_header(request, content_length, HTTP_ADDREQ_FLAG_REPLACE); request_header = build_request_header(request, request->verb, request->path, request->version, TRUE); } @@ -5155,10 +5092,10 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, TRACE("Request header -> %s\n", debugstr_w(request_header) ); /* send the request as ASCII, tack on the optional data */ - if (!lpOptional || redirected || secure_proxy_connect) + if (!optional || redirected || secure_proxy_connect) data_len = 0; - ascii_req = build_ascii_request(request_header, lpOptional, data_len, &len); + ascii_req = build_ascii_request(request_header, optional, data_len, &len); free(request_header); TRACE("full request -> %s\n", debugstr_a(ascii_req) ); @@ -5183,7 +5120,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, INTERNET_STATUS_REQUEST_SENT, &len, sizeof(DWORD)); - if (bEndRequest) + if (end_request) { DWORD dwBufferSize; @@ -5338,6 +5275,79 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, while (loop_next); lend: + return res; +} + +/*********************************************************************** + * HTTP_HttpSendRequestW (internal) + * + * Sends the specified request to the HTTP server + * + * RETURNS + * ERROR_SUCCESS on success + * win32 error code on failure + * + */ +static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, + DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, + DWORD dwContentLength, BOOL bEndRequest) +{ + DWORD res; + const WCHAR *appinfo_agent; + + TRACE("--> %p\n", request); + + assert(request->hdr.htype == WH_HHTTPREQ); + + /* if the verb is NULL default to GET */ + if (!request->verb) + request->verb = wcsdup(L"GET"); + + HTTP_ProcessHeader(request, L"Host", request->server->canon_host_port, + HTTP_ADDREQ_FLAG_ADD_IF_NEW | HTTP_ADDHDR_FLAG_REQ); + + if (dwContentLength || wcscmp(request->verb, L"GET")) + { + set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_ADD_IF_NEW); + request->bytesToWrite = dwContentLength; + } + + appinfo_agent = request->session->appInfo->agent; + + if (appinfo_agent && *appinfo_agent) + { + WCHAR *agent_header; + int len; + + len = lstrlenW(appinfo_agent) + lstrlenW(L"User-Agent: %s\r\n"); + agent_header = malloc(len * sizeof(WCHAR)); + swprintf(agent_header, len, L"User-Agent: %s\r\n", appinfo_agent); + + HTTP_HttpAddRequestHeadersW(request, agent_header, lstrlenW(agent_header), HTTP_ADDREQ_FLAG_ADD_IF_NEW); + free(agent_header); + } + if (request->hdr.dwFlags & INTERNET_FLAG_PRAGMA_NOCACHE) + { + HTTP_HttpAddRequestHeadersW(request, L"Pragma: no-cache\r\n", + lstrlenW(L"Pragma: no-cache\r\n"), HTTP_ADDREQ_FLAG_ADD_IF_NEW); + } + if ((request->hdr.dwFlags & INTERNET_FLAG_NO_CACHE_WRITE) && wcscmp(request->verb, L"GET")) + { + HTTP_HttpAddRequestHeadersW(request, L"Cache-Control: no-cache\r\n", + lstrlenW(L"Cache-Control: no-cache\r\n"), HTTP_ADDREQ_FLAG_ADD_IF_NEW); + } + + /* add the headers the caller supplied */ + if (lpszHeaders) + { + if (dwHeaderLength == 0) + dwHeaderLength = lstrlenW(lpszHeaders); + + HTTP_HttpAddRequestHeadersW(request, lpszHeaders, dwHeaderLength, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE); + } + + res = create_request(request, lpOptional, dwOptionalLength, dwContentLength, bEndRequest); + /* TODO: send notification for P3P header */ if(res == ERROR_SUCCESS) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10223
On Tue Mar 3 15:43:09 2026 +0000, Reyka Matthies wrote:
changed this line in [version 3 of the diff](/wine/wine/-/merge_requests/10223/diffs?diff_id=248156&start_sha=ea9799cdd8a5d05014ec2da5f0054f5b4fd77c87#5257c8cfe2c57bd3f642ff218718644d33ec40ef_273_269) Done, dropped the commit for now.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10223#note_131119
This merge request was approved by Jacek Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10223
participants (3)
-
Jacek Caban (@jacek) -
Reyka Matthies (@tmatthies) -
Torge Matthies