GWinHttpVfs: Link to WinHTTP using the import library

WinHTTP.DLL is present on all supported versions of Windows
This commit is contained in:
Luca Bacci 2024-02-21 11:01:55 +01:00 committed by Philip Withnall
parent 8006fd0431
commit 62a5df4741
7 changed files with 135 additions and 257 deletions

View File

@ -40,6 +40,7 @@
static void g_winhttp_file_file_iface_init (GFileIface *iface);
#define g_winhttp_file_get_type _g_winhttp_file_get_type
G_DEFINE_TYPE_WITH_CODE (GWinHttpFile, g_winhttp_file, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
g_winhttp_file_file_iface_init))
@ -47,9 +48,7 @@ G_DEFINE_TYPE_WITH_CODE (GWinHttpFile, g_winhttp_file, G_TYPE_OBJECT,
static void
g_winhttp_file_finalize (GObject *object)
{
GWinHttpFile *file;
file = G_WINHTTP_FILE (object);
GWinHttpFile *file = G_WINHTTP_FILE (object);
g_free (file->url.lpszScheme);
g_free (file->url.lpszHostName);
@ -107,7 +106,7 @@ _g_winhttp_file_new (GWinHttpVfs *vfs,
file->url.dwUrlPathLength = 1;
file->url.dwExtraInfoLength = 1;
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpCrackUrl (wuri, 0, 0, &file->url))
if (!WinHttpCrackUrl (wuri, 0, 0, &file->url))
{
g_free (wuri);
return NULL;
@ -120,7 +119,7 @@ _g_winhttp_file_new (GWinHttpVfs *vfs,
file->url.lpszUrlPath = g_new (wchar_t, ++file->url.dwUrlPathLength);
file->url.lpszExtraInfo = g_new (wchar_t, ++file->url.dwExtraInfoLength);
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpCrackUrl (wuri, 0, 0, &file->url))
if (!WinHttpCrackUrl (wuri, 0, 0, &file->url))
{
g_free (file->url.lpszScheme);
g_free (file->url.lpszHostName);
@ -208,13 +207,13 @@ g_winhttp_file_get_uri (GFile *file)
char *retval;
len = 0;
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpCreateUrl (&winhttp_file->url, ICU_ESCAPE, NULL, &len) &&
if (!WinHttpCreateUrl (&winhttp_file->url, ICU_ESCAPE, NULL, &len) &&
GetLastError () != ERROR_INSUFFICIENT_BUFFER)
return NULL;
wuri = g_new (wchar_t, ++len);
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpCreateUrl (&winhttp_file->url, ICU_ESCAPE, wuri, &len))
if (!WinHttpCreateUrl (&winhttp_file->url, ICU_ESCAPE, wuri, &len))
{
g_free (wuri);
return NULL;
@ -505,44 +504,36 @@ g_winhttp_file_query_info (GFile *file,
return info;
}
connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect
(G_WINHTTP_VFS (winhttp_file->vfs)->session,
winhttp_file->url.lpszHostName,
winhttp_file->url.nPort,
0);
connection = WinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session,
winhttp_file->url.lpszHostName,
winhttp_file->url.nPort,
0);
if (connection == NULL)
{
_g_winhttp_set_error (error, GetLastError (), "HTTP connection");
return NULL;
}
request = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpOpenRequest
(connection,
L"HEAD",
winhttp_file->url.lpszUrlPath,
NULL,
WINHTTP_NO_REFERER,
accept_types,
winhttp_file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
request = WinHttpOpenRequest (connection,
L"HEAD",
winhttp_file->url.lpszUrlPath,
NULL,
WINHTTP_NO_REFERER,
accept_types,
winhttp_file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
if (request == NULL)
{
_g_winhttp_set_error (error, GetLastError (), "HEAD request");
return NULL;
}
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpSendRequest
(request,
NULL, 0,
NULL, 0,
0,
0))
if (!WinHttpSendRequest (request,
NULL, 0,
NULL, 0,
0,
0))
{
_g_winhttp_set_error (error, GetLastError (), "HEAD request");
return NULL;
}
@ -602,13 +593,12 @@ g_winhttp_file_query_info (GFile *file,
}
last_modified_len = sizeof (last_modified);
if (G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpQueryHeaders
(request,
WINHTTP_QUERY_LAST_MODIFIED | WINHTTP_QUERY_FLAG_SYSTEMTIME,
NULL,
&last_modified,
&last_modified_len,
NULL) &&
if (WinHttpQueryHeaders (request,
WINHTTP_QUERY_LAST_MODIFIED | WINHTTP_QUERY_FLAG_SYSTEMTIME,
NULL,
&last_modified,
&last_modified_len,
NULL) &&
last_modified_len == sizeof (last_modified) &&
/* Don't bother comparing to the exact Y2038 moment */
last_modified.wYear >= 1970 &&
@ -643,32 +633,26 @@ g_winhttp_file_read (GFile *file,
NULL,
};
connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect
(G_WINHTTP_VFS (winhttp_file->vfs)->session,
winhttp_file->url.lpszHostName,
winhttp_file->url.nPort,
0);
connection = WinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session,
winhttp_file->url.lpszHostName,
winhttp_file->url.nPort,
0);
if (connection == NULL)
{
_g_winhttp_set_error (error, GetLastError (), "HTTP connection");
return NULL;
}
request = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpOpenRequest
(connection,
L"GET",
winhttp_file->url.lpszUrlPath,
NULL,
WINHTTP_NO_REFERER,
accept_types,
winhttp_file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
request = WinHttpOpenRequest (connection,
L"GET",
winhttp_file->url.lpszUrlPath,
NULL,
WINHTTP_NO_REFERER,
accept_types,
winhttp_file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
if (request == NULL)
{
_g_winhttp_set_error (error, GetLastError (), "GET request");
return NULL;
}
@ -684,16 +668,13 @@ g_winhttp_file_create (GFile *file,
GWinHttpFile *winhttp_file = G_WINHTTP_FILE (file);
HINTERNET connection;
connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect
(G_WINHTTP_VFS (winhttp_file->vfs)->session,
winhttp_file->url.lpszHostName,
winhttp_file->url.nPort,
0);
connection = WinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session,
winhttp_file->url.lpszHostName,
winhttp_file->url.nPort,
0);
if (connection == NULL)
{
_g_winhttp_set_error (error, GetLastError (), "HTTP connection");
return NULL;
}

View File

@ -45,6 +45,7 @@ struct _GWinHttpFileInputStreamClass
};
#define g_winhttp_file_input_stream_get_type _g_winhttp_file_input_stream_get_type
G_DEFINE_TYPE (GWinHttpFileInputStream, g_winhttp_file_input_stream, G_TYPE_FILE_INPUT_STREAM)
static gssize g_winhttp_file_input_stream_read (GInputStream *stream,
@ -65,12 +66,11 @@ g_winhttp_file_input_stream_finalize (GObject *object)
winhttp_stream = G_WINHTTP_FILE_INPUT_STREAM (object);
if (winhttp_stream->request != NULL)
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (winhttp_stream->request);
WinHttpCloseHandle (winhttp_stream->request);
if (winhttp_stream->connection != NULL)
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (winhttp_stream->connection);
WinHttpCloseHandle (winhttp_stream->connection);
g_object_unref (winhttp_stream->file);
winhttp_stream->file = NULL;
g_clear_object (&winhttp_stream->file);
G_OBJECT_CLASS (g_winhttp_file_input_stream_parent_class)->finalize (object);
}
@ -129,15 +129,13 @@ g_winhttp_file_input_stream_read (GInputStream *stream,
if (!winhttp_stream->request_sent)
{
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpSendRequest
(winhttp_stream->request,
NULL, 0,
NULL, 0,
0,
0))
if (!WinHttpSendRequest (winhttp_stream->request,
NULL, 0,
NULL, 0,
0,
0))
{
_g_winhttp_set_error (error, GetLastError (), "GET request");
return -1;
}
@ -150,11 +148,9 @@ g_winhttp_file_input_stream_read (GInputStream *stream,
winhttp_stream->request_sent = TRUE;
}
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpReadData
(winhttp_stream->request, buffer, count, &bytes_read))
if (!WinHttpReadData (winhttp_stream->request, buffer, count, &bytes_read))
{
_g_winhttp_set_error (error, GetLastError (), "GET request");
return -1;
}
@ -169,7 +165,10 @@ g_winhttp_file_input_stream_close (GInputStream *stream,
GWinHttpFileInputStream *winhttp_stream = G_WINHTTP_FILE_INPUT_STREAM (stream);
if (winhttp_stream->connection != NULL)
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (winhttp_stream->connection);
winhttp_stream->connection = NULL;
{
WinHttpCloseHandle (winhttp_stream->connection);
winhttp_stream->connection = NULL;
}
return TRUE;
}

View File

@ -44,6 +44,7 @@ struct _GWinHttpFileOutputStreamClass
};
#define g_winhttp_file_output_stream_get_type _g_winhttp_file_output_stream_get_type
G_DEFINE_TYPE (GWinHttpFileOutputStream, g_winhttp_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM)
static gssize g_winhttp_file_output_stream_write (GOutputStream *stream,
@ -60,7 +61,7 @@ g_winhttp_file_output_stream_finalize (GObject *object)
winhttp_stream = G_WINHTTP_FILE_OUTPUT_STREAM (object);
if (winhttp_stream->connection != NULL)
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (winhttp_stream->connection);
WinHttpCloseHandle (winhttp_stream->connection);
G_OBJECT_CLASS (g_winhttp_file_output_stream_parent_class)->finalize (object);
}
@ -117,19 +118,16 @@ g_winhttp_file_output_stream_write (GOutputStream *stream,
wchar_t *wheaders;
DWORD bytes_written;
request = G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpOpenRequest
(winhttp_stream->connection,
L"PUT",
winhttp_stream->file->url.lpszUrlPath,
NULL,
WINHTTP_NO_REFERER,
NULL,
winhttp_stream->file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
request = WinHttpOpenRequest (winhttp_stream->connection,
L"PUT",
winhttp_stream->file->url.lpszUrlPath,
NULL,
WINHTTP_NO_REFERER,
NULL,
winhttp_stream->file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
if (request == NULL)
{
_g_winhttp_set_error (error, GetLastError (), "PUT request");
return -1;
}
@ -138,16 +136,15 @@ g_winhttp_file_output_stream_write (GOutputStream *stream,
wheaders = g_utf8_to_utf16 (headers, -1, NULL, NULL, NULL);
g_free (headers);
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpSendRequest
(request,
wheaders, -1,
NULL, 0,
count,
0))
if (!WinHttpSendRequest (request,
wheaders, -1,
NULL, 0,
count,
0))
{
_g_winhttp_set_error (error, GetLastError (), "PUT request");
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (request);
WinHttpCloseHandle (request);
g_free (wheaders);
return -1;
@ -155,12 +152,11 @@ g_winhttp_file_output_stream_write (GOutputStream *stream,
g_free (wheaders);
if (!G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpWriteData
(request, buffer, count, &bytes_written))
if (!WinHttpWriteData (request, buffer, count, &bytes_written))
{
_g_winhttp_set_error (error, GetLastError (), "PUT request");
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (request);
WinHttpCloseHandle (request);
return -1;
}
@ -172,12 +168,12 @@ g_winhttp_file_output_stream_write (GOutputStream *stream,
error,
"PUT request"))
{
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (request);
WinHttpCloseHandle (request);
return -1;
}
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (request);
WinHttpCloseHandle (request);
return bytes_written;
}

View File

@ -26,94 +26,33 @@
#include "gio/gioerror.h"
#include "gio/giomodule.h"
#include "gio/giomodule-priv.h"
#include "gio/gvfs.h"
#include "gwinhttpfile.h"
#include "gwinhttpvfs.h"
static gboolean lookup_done = FALSE;
static gboolean funcs_found = FALSE;
static GWinHttpDllFuncs funcs;
static void
lookup_funcs (void)
{
HMODULE winhttp = NULL;
WCHAR winhttp_dll[MAX_PATH + 100];
int n;
if (lookup_done)
return;
n = GetSystemDirectoryW (winhttp_dll, MAX_PATH);
if (n > 0 && n < MAX_PATH)
{
if (winhttp_dll[n-1] != L'\\' &&
winhttp_dll[n-1] != L'/')
wcscat (winhttp_dll, L"\\");
wcscat (winhttp_dll, L"winhttp.dll");
winhttp = LoadLibraryW (winhttp_dll);
}
if (winhttp != NULL)
{
funcs.pWinHttpCloseHandle = (BOOL (WINAPI *) (HINTERNET)) GetProcAddress (winhttp, "WinHttpCloseHandle");
funcs.pWinHttpCrackUrl = (BOOL (WINAPI *) (LPCWSTR,DWORD,DWORD,LPURL_COMPONENTS)) GetProcAddress (winhttp, "WinHttpCrackUrl");
funcs.pWinHttpConnect = (HINTERNET (WINAPI *) (HINTERNET,LPCWSTR,INTERNET_PORT,DWORD)) GetProcAddress (winhttp, "WinHttpConnect");
funcs.pWinHttpCreateUrl = (BOOL (WINAPI *) (LPURL_COMPONENTS,DWORD,LPWSTR,LPDWORD)) GetProcAddress (winhttp, "WinHttpCreateUrl");
funcs.pWinHttpOpen = (HINTERNET (WINAPI *) (LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD)) GetProcAddress (winhttp, "WinHttpOpen");
funcs.pWinHttpOpenRequest = (HINTERNET (WINAPI *) (HINTERNET,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR*,DWORD)) GetProcAddress (winhttp, "WinHttpOpenRequest");
funcs.pWinHttpQueryDataAvailable = (BOOL (WINAPI *) (HINTERNET,LPDWORD)) GetProcAddress (winhttp, "WinHttpQueryDataAvailable");
funcs.pWinHttpQueryHeaders = (BOOL (WINAPI *) (HINTERNET,DWORD,LPCWSTR,LPVOID,LPDWORD,LPDWORD)) GetProcAddress (winhttp, "WinHttpQueryHeaders");
funcs.pWinHttpReadData = (BOOL (WINAPI *) (HINTERNET,LPVOID,DWORD,LPDWORD)) GetProcAddress (winhttp, "WinHttpReadData");
funcs.pWinHttpReceiveResponse = (BOOL (WINAPI *) (HINTERNET,LPVOID)) GetProcAddress (winhttp, "WinHttpReceiveResponse");
funcs.pWinHttpSendRequest = (BOOL (WINAPI *) (HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR)) GetProcAddress (winhttp, "WinHttpSendRequest");
funcs.pWinHttpWriteData = (BOOL (WINAPI *) (HINTERNET,LPCVOID,DWORD,LPDWORD)) GetProcAddress (winhttp, "WinHttpWriteData");
if (funcs.pWinHttpCloseHandle &&
funcs.pWinHttpCrackUrl &&
funcs.pWinHttpConnect &&
funcs.pWinHttpCreateUrl &&
funcs.pWinHttpOpen &&
funcs.pWinHttpOpenRequest &&
funcs.pWinHttpQueryDataAvailable &&
funcs.pWinHttpQueryHeaders &&
funcs.pWinHttpReadData &&
funcs.pWinHttpReceiveResponse &&
funcs.pWinHttpSendRequest &&
funcs.pWinHttpWriteData)
funcs_found = TRUE;
}
lookup_done = TRUE;
}
#define g_winhttp_vfs_get_type _g_winhttp_vfs_get_type
G_DEFINE_TYPE_WITH_CODE (GWinHttpVfs, g_winhttp_vfs, G_TYPE_VFS,
{
lookup_funcs ();
if (funcs_found)
g_io_extension_point_implement (G_VFS_EXTENSION_POINT_NAME,
g_define_type_id,
"winhttp",
10);
})
_g_io_modules_ensure_extension_points_registered ();
g_io_extension_point_implement (G_VFS_EXTENSION_POINT_NAME,
g_define_type_id,
"winhttp",
10);)
static const gchar *winhttp_uri_schemes[] = { "http", "https" };
static void
g_winhttp_vfs_finalize (GObject *object)
{
GWinHttpVfs *vfs;
GWinHttpVfs *vfs = G_WINHTTP_VFS (object);
vfs = G_WINHTTP_VFS (object);
g_clear_object (&vfs->wrapped_vfs);
(G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpCloseHandle) (vfs->session);
WinHttpCloseHandle (vfs->session);
vfs->session = NULL;
if (vfs->wrapped_vfs)
g_object_unref (vfs->wrapped_vfs);
vfs->wrapped_vfs = NULL;
G_OBJECT_CLASS (g_winhttp_vfs_parent_class)->finalize (object);
}
@ -130,12 +69,11 @@ g_winhttp_vfs_init (GWinHttpVfs *vfs)
else
wagent = g_utf8_to_utf16 ("GWinHttpVfs", -1, NULL, NULL, NULL);
vfs->session = (G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpOpen)
(wagent,
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0);
vfs->session = WinHttpOpen (wagent,
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0);
g_free (wagent);
}
@ -260,12 +198,6 @@ g_winhttp_vfs_class_init (GWinHttpVfsClass *class)
vfs_class->get_file_for_uri = g_winhttp_vfs_get_file_for_uri;
vfs_class->get_supported_uri_schemes = g_winhttp_vfs_get_supported_uri_schemes;
vfs_class->parse_name = g_winhttp_vfs_parse_name;
lookup_funcs ();
if (funcs_found)
class->funcs = &funcs;
else
class->funcs = NULL;
}
char *
@ -354,41 +286,36 @@ _g_winhttp_response (GWinHttpVfs *vfs,
wchar_t *status_code;
DWORD status_code_len;
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpReceiveResponse (request, NULL))
if (!WinHttpReceiveResponse (request, NULL))
{
_g_winhttp_set_error (error, GetLastError (), what);
return FALSE;
}
status_code_len = 0;
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpQueryHeaders
(request,
WINHTTP_QUERY_STATUS_CODE,
NULL,
NULL,
&status_code_len,
NULL) &&
if (!WinHttpQueryHeaders (request,
WINHTTP_QUERY_STATUS_CODE,
NULL,
NULL,
&status_code_len,
NULL) &&
GetLastError () != ERROR_INSUFFICIENT_BUFFER)
{
_g_winhttp_set_error (error, GetLastError (), what);
return FALSE;
}
status_code = g_malloc (status_code_len);
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpQueryHeaders
(request,
WINHTTP_QUERY_STATUS_CODE,
NULL,
status_code,
&status_code_len,
NULL))
if (!WinHttpQueryHeaders (request,
WINHTTP_QUERY_STATUS_CODE,
NULL,
status_code,
&status_code_len,
NULL))
{
_g_winhttp_set_error (error, GetLastError (), what);
g_free (status_code);
return FALSE;
}
@ -397,24 +324,22 @@ _g_winhttp_response (GWinHttpVfs *vfs,
wchar_t *status_text = NULL;
DWORD status_text_len;
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpQueryHeaders
(request,
WINHTTP_QUERY_STATUS_TEXT,
NULL,
NULL,
&status_text_len,
NULL) &&
if (!WinHttpQueryHeaders (request,
WINHTTP_QUERY_STATUS_TEXT,
NULL,
NULL,
&status_text_len,
NULL) &&
GetLastError () == ERROR_INSUFFICIENT_BUFFER)
{
status_text = g_malloc (status_text_len);
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpQueryHeaders
(request,
WINHTTP_QUERY_STATUS_TEXT,
NULL,
status_text,
&status_text_len,
NULL))
if (!WinHttpQueryHeaders (request,
WINHTTP_QUERY_STATUS_TEXT,
NULL,
status_text,
&status_text_len,
NULL))
{
g_free (status_text);
status_text = NULL;
@ -424,6 +349,7 @@ _g_winhttp_response (GWinHttpVfs *vfs,
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"%s failed: %S %S",
what, status_code, status_text ? status_text : L"");
g_free (status_code);
g_free (status_text);
@ -445,33 +371,28 @@ _g_winhttp_query_header (GWinHttpVfs *vfs,
{
DWORD header_len = 0;
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpQueryHeaders
(request,
which_header,
NULL,
NULL,
&header_len,
NULL) &&
if (!WinHttpQueryHeaders (request,
which_header,
NULL,
NULL,
&header_len,
NULL) &&
GetLastError () != ERROR_INSUFFICIENT_BUFFER)
{
_g_winhttp_set_error (error, GetLastError (), request_description);
return FALSE;
}
*header = g_malloc (header_len);
if (!G_WINHTTP_VFS_GET_CLASS (vfs)->funcs->pWinHttpQueryHeaders
(request,
which_header,
NULL,
*header,
&header_len,
NULL))
if (!WinHttpQueryHeaders (request,
which_header,
NULL,
*header,
&header_len,
NULL))
{
_g_winhttp_set_error (error, GetLastError (), request_description);
g_free (*header);
*header = NULL;
g_clear_pointer (header, g_free);
return FALSE;
}

View File

@ -2,6 +2,7 @@
*
* Copyright (C) 2006-2007 Red Hat, Inc.
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2024 Luca Bacci
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -39,7 +40,6 @@ G_BEGIN_DECLS
#define G_WINHTTP_VFS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_WINHTTP_VFS, GWinHttpVfsClass))
typedef struct _GWinHttpVfs GWinHttpVfs;
typedef struct _GWinHttpDllFuncs GWinHttpDllFuncs;
typedef struct _GWinHttpVfsClass GWinHttpVfsClass;
struct _GWinHttpVfs
@ -50,31 +50,9 @@ struct _GWinHttpVfs
HINTERNET session;
};
struct _GWinHttpDllFuncs
{
BOOL (WINAPI *pWinHttpCloseHandle) (HINTERNET);
BOOL (WINAPI *pWinHttpCrackUrl) (LPCWSTR,DWORD,DWORD,LPURL_COMPONENTS);
HINTERNET (WINAPI *pWinHttpConnect) (HINTERNET,LPCWSTR,INTERNET_PORT,DWORD);
BOOL (WINAPI *pWinHttpCreateUrl) (LPURL_COMPONENTS,DWORD,LPWSTR,LPDWORD);
HINTERNET (WINAPI *pWinHttpOpen) (LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD);
HINTERNET (WINAPI *pWinHttpOpenRequest) (HINTERNET,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR*,DWORD);
BOOL (WINAPI *pWinHttpQueryDataAvailable) (HINTERNET,LPDWORD);
BOOL (WINAPI *pWinHttpQueryHeaders) (HINTERNET,DWORD,LPCWSTR,LPVOID,LPDWORD,LPDWORD);
BOOL (WINAPI *pWinHttpReadData) (HINTERNET,LPVOID,DWORD,LPDWORD);
BOOL (WINAPI *pWinHttpReceiveResponse) (HINTERNET,LPVOID);
BOOL (WINAPI *pWinHttpSendRequest) (HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR);
BOOL (WINAPI *pWinHttpWriteData) (HINTERNET,LPCVOID,DWORD,LPDWORD);
};
struct _GWinHttpVfsClass
{
GVfsClass parent_class;
/* As there is no import library for winhttp.dll in mingw, and
* winhttp.dll isn't present on Windows 2000 anyway, we must look up
* the functions we need dynamically. Store the pointers here.
*/
GWinHttpDllFuncs *funcs;
};

View File

@ -15,6 +15,7 @@ giowin32_lib = static_library('giowin32',
gioenumtypes_dep,
libglib_dep,
gmodule_inc_dep,
winhttp,
],
gnu_symbol_visibility : 'hidden',
pic : true,

View File

@ -2326,8 +2326,10 @@ endif
if host_system == 'windows'
winsock2 = cc.find_library('ws2_32')
winhttp = cc.find_library('winhttp')
else
winsock2 = not_found
winhttp = not_found
endif
selinux_dep = []