xref: /reactos/dll/win32/winhttp/winhttp_ros.diff (revision 40462c92)
1diff -pudN e:\wine\dlls\winhttp/net.c e:\reactos\dll\win32\winhttp/net.c
2--- e:\wine\dlls\winhttp/net.c	2016-11-16 17:36:37 +0100
3+++ e:\reactos\dll\win32\winhttp/net.c	2016-10-13 11:15:39 +0100
4@@ -50,6 +50,7 @@ static CRITICAL_SECTION cs_gethostbyname
5 #endif
6
7 /* translate a unix error code into a winsock error code */
8+#ifndef __REACTOS__
9 static int sock_get_error( int err )
10 {
11 #if !defined(__MINGW32__) && !defined (_MSC_VER)
12@@ -115,6 +116,15 @@ static int sock_get_error( int err )
13 #endif
14     return err;
15 }
16+#else
17+#define sock_get_error(x) WSAGetLastError()
18+
19+static inline int unix_ioctl(int filedes, long request, void *arg)
20+{
21+    return ioctlsocket(filedes, request, arg);
22+}
23+#define ioctlsocket unix_ioctl
24+#endif
25
26 static int sock_send(int fd, const void *msg, size_t len, int flags)
27 {
28@@ -266,6 +276,28 @@ static BOOL ensure_cred_handle(void)
29     return ret;
30 }
31
32+#ifdef __REACTOS__
33+static BOOL winsock_initialized = FALSE;
34+BOOL netconn_init_winsock()
35+{
36+    WSADATA wsaData;
37+    int error;
38+    if (!winsock_initialized)
39+    {
40+        error = WSAStartup(MAKEWORD(1, 1), &wsaData);
41+        if (error)
42+        {
43+            ERR("WSAStartup failed: %d\n", error);
44+            return FALSE;
45+        }
46+        else
47+            winsock_initialized = TRUE;
48+    }
49+    return winsock_initialized;
50+}
51+
52+#endif
53+
54 BOOL netconn_init( netconn_t *conn )
55 {
56     memset(conn, 0, sizeof(*conn));
57@@ -281,6 +313,10 @@ void netconn_unload( void )
58 #ifndef HAVE_GETADDRINFO
59     DeleteCriticalSection(&cs_gethostbyname);
60 #endif
61+#ifdef __REACTOS__
62+    if(winsock_initialized)
63+        WSACleanup();
64+#endif
65 }
66
67 BOOL netconn_connected( netconn_t *conn )
68@@ -343,11 +379,25 @@ BOOL netconn_connect( netconn_t *conn, c
69         res = sock_get_error( errno );
70         if (res == WSAEWOULDBLOCK || res == WSAEINPROGRESS)
71         {
72+#ifdef __REACTOS__
73+            /* ReactOS: use select instead of poll */
74+            fd_set outfd;
75+            struct timeval tv;
76+
77+            FD_ZERO(&outfd);
78+            FD_SET(conn->socket, &outfd);
79+
80+            tv.tv_sec = 0;
81+            tv.tv_usec = timeout * 1000;
82+
83+            if (select( 0, NULL, &outfd, NULL, &tv ) > 0)
84+#else
85             struct pollfd pfd;
86
87             pfd.fd = conn->socket;
88             pfd.events = POLLOUT;
89             if (poll( &pfd, 1, timeout ) > 0)
90+#endif
91                 ret = TRUE;
92             else
93                 res = sock_get_error( errno );
94diff -pudN e:\wine\dlls\winhttp/request.c e:\reactos\dll\win32\winhttp/request.c
95--- e:\wine\dlls\winhttp/request.c	2016-11-16 17:36:37 +0100
96+++ e:\reactos\dll\win32\winhttp/request.c	2016-02-27 16:08:59 +0100
97@@ -1258,6 +1258,7 @@ BOOL WINAPI WinHttpSendRequest( HINTERNE
98     return ret;
99 }
100
101+#undef ARRAYSIZE
102 #define ARRAYSIZE(array) (sizeof(array) / sizeof((array)[0]))
103
104 static const WCHAR basicW[]     = {'B','a','s','i','c',0};
105@@ -2758,8 +2759,8 @@ static void free_request( struct winhttp
106     CloseHandle( request->thread );
107     CloseHandle( request->wait );
108     CloseHandle( request->cancel );
109-    heap_free( request->proxy.lpszProxy );
110-    heap_free( request->proxy.lpszProxyBypass );
111+    heap_free( (WCHAR *)request->proxy.lpszProxy );
112+    heap_free( (WCHAR *)request->proxy.lpszProxyBypass );
113     heap_free( request->buffer );
114     heap_free( request->verb );
115     VariantClear( &request->data );
116@@ -3005,16 +3006,16 @@ static HRESULT WINAPI winhttp_request_Se
117     {
118     case HTTPREQUEST_PROXYSETTING_DEFAULT:
119         request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_DEFAULT_PROXY;
120-        heap_free( request->proxy.lpszProxy );
121-        heap_free( request->proxy.lpszProxyBypass );
122+        heap_free( (WCHAR *)request->proxy.lpszProxy );
123+        heap_free( (WCHAR *)request->proxy.lpszProxyBypass );
124         request->proxy.lpszProxy = NULL;
125         request->proxy.lpszProxyBypass = NULL;
126         break;
127
128     case HTTPREQUEST_PROXYSETTING_DIRECT:
129         request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
130-        heap_free( request->proxy.lpszProxy );
131-        heap_free( request->proxy.lpszProxyBypass );
132+        heap_free( (WCHAR *)request->proxy.lpszProxy );
133+        heap_free( (WCHAR *)request->proxy.lpszProxyBypass );
134         request->proxy.lpszProxy = NULL;
135         request->proxy.lpszProxyBypass = NULL;
136         break;
137@@ -3023,12 +3024,12 @@ static HRESULT WINAPI winhttp_request_Se
138         request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
139         if (V_VT( &proxy_server ) == VT_BSTR)
140         {
141-            heap_free( request->proxy.lpszProxy );
142+            heap_free( (WCHAR *)request->proxy.lpszProxy );
143             request->proxy.lpszProxy = strdupW( V_BSTR( &proxy_server ) );
144         }
145         if (V_VT( &bypass_list ) == VT_BSTR)
146         {
147-            heap_free( request->proxy.lpszProxyBypass );
148+            heap_free( (WCHAR *)request->proxy.lpszProxyBypass );
149             request->proxy.lpszProxyBypass = strdupW( V_BSTR( &bypass_list ) );
150         }
151         break;
152diff -pudN e:\wine\dlls\winhttp/session.c e:\reactos\dll\win32\winhttp/session.c
153--- e:\wine\dlls\winhttp/session.c	2016-11-16 17:36:37 +0100
154+++ e:\reactos\dll\win32\winhttp/session.c	2016-11-17 00:14:49 +0100
155@@ -197,6 +197,9 @@ static const object_vtbl_t session_vtbl
156     session_set_option
157 };
158
159+#ifdef __REACTOS__
160+BOOL netconn_init_winsock();
161+#endif /* __REACTOS__ */
162 /***********************************************************************
163  *          WinHttpOpen (winhttp.@)
164  */
165@@ -204,6 +207,9 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR ag
166 {
167     session_t *session;
168     HINTERNET handle = NULL;
169+#ifdef __REACTOS__
170+    if (!netconn_init_winsock()) return NULL;
171+#endif
172
173     TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
174
175@@ -230,14 +236,14 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR ag
176         session->access = info.dwAccessType;
177         if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy )))
178         {
179-            GlobalFree( info.lpszProxy );
180-            GlobalFree( info.lpszProxyBypass );
181+            GlobalFree( (LPWSTR)info.lpszProxy );
182+            GlobalFree( (LPWSTR)info.lpszProxyBypass );
183             goto end;
184         }
185         if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass )))
186         {
187-            GlobalFree( info.lpszProxy );
188-            GlobalFree( info.lpszProxyBypass );
189+            GlobalFree( (LPWSTR)info.lpszProxy );
190+            GlobalFree( (LPWSTR)info.lpszProxyBypass );
191             goto end;
192         }
193     }
194@@ -610,7 +616,7 @@ static WCHAR *blob_to_str( DWORD encodin
195
196 static BOOL convert_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage )
197 {
198-#ifndef __MINGW32__
199+#if !defined(__MINGW32__) && !defined(_MSC_VER)
200     switch (addr->sa_family)
201     {
202     case AF_INET:
203