[WINHTTP] Sync with Wine Staging 3.9. CORE-14656
[reactos.git] / dll / win32 / winhttp / session.c
index 7ab10a6..7cfc240 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+#include "wine/debug.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#ifdef HAVE_CORESERVICES_CORESERVICES_H
+#define GetCurrentThread MacGetCurrentThread
+#define LoadResource MacLoadResource
+#include <CoreServices/CoreServices.h>
+#undef GetCurrentThread
+#undef LoadResource
+#undef DPRINTF
+#endif
+
+#include "windef.h"
+#include "winbase.h"
+#ifndef __MINGW32__
+#define USE_WS_PREFIX
+#endif
+#include "winsock2.h"
+#include "ws2ipdef.h"
+#include "winhttp.h"
+#include "wincrypt.h"
+#include "winreg.h"
+#define COBJMACROS
+#include "ole2.h"
+#include "dispex.h"
+#include "activscp.h"
+
 #include "winhttp_private.h"
 
-#include <wincrypt.h>
-#include <winreg.h>
-#include <dispex.h>
-#include <activscp.h>
+WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
 
 #define DEFAULT_RESOLVE_TIMEOUT     0
 #define DEFAULT_CONNECT_TIMEOUT     20000
@@ -197,7 +225,7 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe
         return TRUE;
     default:
         FIXME("unimplemented option %u\n", option);
-        set_last_error( ERROR_INVALID_PARAMETER );
+        set_last_error( ERROR_WINHTTP_INVALID_OPTION );
         return FALSE;
     }
 }
@@ -589,8 +617,6 @@ static void request_destroy( object_header_t *hdr )
         heap_free( request->headers[i].value );
     }
     heap_free( request->headers );
-    for (i = 0; i < request->num_accept_types; i++) heap_free( request->accept_types[i] );
-    heap_free( request->accept_types );
     for (i = 0; i < TARGET_MAX; i++)
     {
         for (j = 0; j < SCHEME_MAX; j++)
@@ -1002,8 +1028,8 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe
         return TRUE;
     default:
         FIXME("unimplemented option %u\n", option);
-        set_last_error( ERROR_INVALID_PARAMETER );
-        return TRUE;
+        set_last_error( ERROR_WINHTTP_INVALID_OPTION );
+        return FALSE;
     }
 }
 
@@ -1016,32 +1042,14 @@ static const object_vtbl_t request_vtbl =
 
 static BOOL store_accept_types( request_t *request, const WCHAR **accept_types )
 {
+    static const WCHAR attr_accept[] = {'A','c','c','e','p','t',0};
+    static const DWORD flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA;
     const WCHAR **types = accept_types;
-    DWORD i;
 
     if (!types) return TRUE;
     while (*types)
     {
-        request->num_accept_types++;
-        types++;
-    }
-    if (!request->num_accept_types) return TRUE;
-    if (!(request->accept_types = heap_alloc( request->num_accept_types * sizeof(WCHAR *))))
-    {
-        request->num_accept_types = 0;
-        return FALSE;
-    }
-    types = accept_types;
-    for (i = 0; i < request->num_accept_types; i++)
-    {
-        if (!(request->accept_types[i] = strdupW( *types )))
-        {
-            for ( ; i > 0; --i) heap_free( request->accept_types[i - 1] );
-            heap_free( request->accept_types );
-            request->accept_types = NULL;
-            request->num_accept_types = 0;
-            return FALSE;
-        }
+        process_header( request, attr_accept, *types, flags, TRUE );
         types++;
     }
     return TRUE;
@@ -1575,29 +1583,21 @@ BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
     }
     if (!got_from_reg && (envproxy = getenv( "http_proxy" )))
     {
-        char *colon, *http_proxy;
+        char *colon, *http_proxy = NULL;
 
-        if ((colon = strchr( envproxy, ':' )))
+        if (!(colon = strchr( envproxy, ':' ))) http_proxy = envproxy;
+        else
         {
             if (*(colon + 1) == '/' && *(colon + 2) == '/')
             {
-                static const char http[] = "http://";
-
                 /* It's a scheme, check that it's http */
-                if (!strncmp( envproxy, http, strlen( http ) ))
-                    http_proxy = envproxy + strlen( http );
-                else
-                {
-                    WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
-                    http_proxy = NULL;
-                }
+                if (!strncmp( envproxy, "http://", 7 )) http_proxy = envproxy + 7;
+                else WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
             }
-            else
-                http_proxy = envproxy;
+            else http_proxy = envproxy;
         }
-        else
-            http_proxy = envproxy;
-        if (http_proxy)
+
+        if (http_proxy && http_proxy[0])
         {
             WCHAR *http_proxyW;
             int len;
@@ -1610,8 +1610,7 @@ BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
                 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
                 info->lpszProxy = http_proxyW;
                 info->lpszProxyBypass = NULL;
-                TRACE("http proxy (from environment) = %s\n",
-                    debugstr_w(info->lpszProxy));
+                TRACE("http proxy (from environment) = %s\n", debugstr_w(info->lpszProxy));
             }
         }
     }