Paul Gofman : hnetcfg: Open connection to gateway in init_gateway_connection().
Alexandre Julliard
julliard at winehq.org
Tue Feb 1 15:21:34 CST 2022
Module: wine
Branch: master
Commit: c091620889195e761854dfd1cbdfb9ff58548abd
URL: https://source.winehq.org/git/wine.git/?a=commit;h=c091620889195e761854dfd1cbdfb9ff58548abd
Author: Paul Gofman <pgofman at codeweavers.com>
Date: Tue Feb 1 13:49:23 2022 +0300
hnetcfg: Open connection to gateway in init_gateway_connection().
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/hnetcfg/Makefile.in | 2 +-
dlls/hnetcfg/port.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/dlls/hnetcfg/Makefile.in b/dlls/hnetcfg/Makefile.in
index 8d1f1b27ffe..8435de81f94 100644
--- a/dlls/hnetcfg/Makefile.in
+++ b/dlls/hnetcfg/Makefile.in
@@ -1,7 +1,7 @@
EXTRADEFS = -DWINE_NO_LONG_TYPES
MODULE = hnetcfg.dll
IMPORTS = oleaut32 ole32 advapi32 mpr uuid
-DELAYIMPORTS = ws2_32
+DELAYIMPORTS = ws2_32 winhttp
EXTRADLLFLAGS = -Wb,--prefer-native
C_SRCS = \
diff --git a/dlls/hnetcfg/port.c b/dlls/hnetcfg/port.c
index fa866d874c9..b1d5398a01a 100644
--- a/dlls/hnetcfg/port.c
+++ b/dlls/hnetcfg/port.c
@@ -42,6 +42,7 @@ static struct
LONG refs;
BOOL winsock_initialized;
WCHAR locationW[256];
+ HINTERNET session, connection;
}
upnp_gateway_connection;
@@ -84,9 +85,43 @@ static BOOL parse_search_response( char *response, WCHAR *locationW, unsigned in
return FALSE;
}
+static BOOL open_gateway_connection(void)
+{
+ static const int timeout = 3000;
+
+ WCHAR hostname[64], urlpath[128];
+ URL_COMPONENTS url;
+
+ memset( &url, 0, sizeof(url) );
+ url.dwStructSize = sizeof(url);
+ url.lpszHostName = hostname;
+ url.dwHostNameLength = ARRAY_SIZE(hostname);
+ url.lpszUrlPath = urlpath;
+ url.dwUrlPathLength = ARRAY_SIZE(urlpath);
+
+ if (!WinHttpCrackUrl( upnp_gateway_connection.locationW, 0, 0, &url )) return FALSE;
+
+ upnp_gateway_connection.session = WinHttpOpen( L"hnetcfg", WINHTTP_ACCESS_TYPE_NO_PROXY,
+ WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 );
+ if (!upnp_gateway_connection.session) return FALSE;
+ if (!WinHttpSetTimeouts( upnp_gateway_connection.session, timeout, timeout, timeout, timeout ))
+ return FALSE;
+
+ TRACE( "hostname %s, urlpath %s, port %u.\n", debugstr_w(hostname), debugstr_w(urlpath), url.nPort );
+ upnp_gateway_connection.connection = WinHttpConnect ( upnp_gateway_connection.session, hostname, url.nPort, 0 );
+ if (!upnp_gateway_connection.connection)
+ {
+ WARN( "WinHttpConnect error %u.\n", GetLastError() );
+ return FALSE;
+ }
+ return TRUE;
+}
+
static void gateway_connection_cleanup(void)
{
TRACE( ".\n" );
+ WinHttpCloseHandle( upnp_gateway_connection.connection );
+ WinHttpCloseHandle( upnp_gateway_connection.session );
if (upnp_gateway_connection.winsock_initialized) WSACleanup();
memset( &upnp_gateway_connection, 0, sizeof(upnp_gateway_connection) );
}
@@ -164,6 +199,12 @@ static BOOL init_gateway_connection(void)
return FALSE;
}
TRACE( "Gateway description location %s.\n", debugstr_w(upnp_gateway_connection.locationW) );
+ if (!open_gateway_connection())
+ {
+ WARN( "Error opening gateway connection.\n" );
+ return FALSE;
+ }
+ TRACE( "Opened gateway connection.\n" );
return TRUE;
}
More information about the wine-cvs
mailing list