[WINHTTP] Sync with Wine Staging 3.9. CORE-14656
[reactos.git] / dll / win32 / winhttp / winhttp_private.h
index e1ca4a7..d5ec9ca 100644 (file)
 #ifndef _WINE_WINHTTP_PRIVATE_H_
 #define _WINE_WINHTTP_PRIVATE_H_
 
-#include <wine/config.h>
-
-#include <stdarg.h>
-
-#define WIN32_NO_STATUS
-#define _INC_WINDOWS
-#define COM_NO_WINDOWS_H
-
-#define COBJMACROS
-#define NONAMELESSUNION
-
-#include <windef.h>
-#include <winbase.h>
-#include <objbase.h>
-#include <oleauto.h>
-#include <winsock2.h>
-#include <winhttp.h>
+#ifndef __WINE_CONFIG_H
+# error You must include config.h to use this header
+#endif
 
-#include <wine/list.h>
-#include <wine/unicode.h>
+#include "wine/heap.h"
+#include "wine/list.h"
+#include "wine/unicode.h"
 
+#include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
 #endif
 # define ioctlsocket ioctl
 #endif
 
-#include <sspi.h>
-
-#include <wine/debug.h>
-WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
+#include "ole2.h"
+#include "sspi.h"
 
 static const WCHAR getW[]    = {'G','E','T',0};
 static const WCHAR postW[]   = {'P','O','S','T',0};
@@ -111,6 +97,15 @@ typedef struct
     WCHAR *path;
 } cookie_t;
 
+typedef struct {
+    struct list entry;
+    LONG ref;
+    WCHAR *hostname;
+    INTERNET_PORT port;
+    BOOL secure;
+    struct list connections;
+} hostdata_t;
+
 typedef struct
 {
     object_header_t hdr;
@@ -125,6 +120,10 @@ typedef struct
     LPWSTR proxy_username;
     LPWSTR proxy_password;
     struct list cookie_cache;
+    HANDLE unload_event;
+    CredHandle cred_handle;
+    BOOL cred_handle_initialized;
+    DWORD secure_protocols;
 } session_t;
 
 typedef struct
@@ -143,8 +142,12 @@ typedef struct
 
 typedef struct
 {
+    struct list entry;
     int socket;
+    struct sockaddr_storage sockaddr;
     BOOL secure; /* SSL active on connection? */
+    hostdata_t *host;
+    ULONGLONG keep_until;
     CtxtHandle ssl_ctx;
     SecPkgContext_StreamSizes ssl_sizes;
     char *ssl_buf;
@@ -153,7 +156,6 @@ typedef struct
     char *peek_msg;
     char *peek_msg_mem;
     size_t peek_len;
-    DWORD security_flags;
 } netconn_t;
 
 typedef struct
@@ -163,6 +165,14 @@ typedef struct
     BOOL is_request; /* part of request headers? */
 } header_t;
 
+enum auth_target
+{
+    TARGET_INVALID = -1,
+    TARGET_SERVER,
+    TARGET_PROXY,
+    TARGET_MAX
+};
+
 enum auth_scheme
 {
     SCHEME_INVALID = -1,
@@ -170,7 +180,8 @@ enum auth_scheme
     SCHEME_NTLM,
     SCHEME_PASSPORT,
     SCHEME_DIGEST,
-    SCHEME_NEGOTIATE
+    SCHEME_NEGOTIATE,
+    SCHEME_MAX
 };
 
 struct authinfo
@@ -196,30 +207,42 @@ typedef struct
     LPWSTR raw_headers;
     void *optional;
     DWORD optional_len;
-    netconn_t netconn;
+    netconn_t *netconn;
+    DWORD security_flags;
     int resolve_timeout;
     int connect_timeout;
     int send_timeout;
     int recv_timeout;
     LPWSTR status_text;
-    DWORD content_length; /* total number of bytes to be read (per chunk) */
+    DWORD content_length; /* total number of bytes to be read */
     DWORD content_read;   /* bytes read so far */
     BOOL  read_chunked;   /* are we reading in chunked mode? */
+    BOOL  read_chunked_eof;  /* end of stream in chunked mode */
+    BOOL  read_chunked_size; /* chunk size remaining */
     DWORD read_pos;       /* current read position in read_buf */
     DWORD read_size;      /* valid data size in read_buf */
-    char  read_buf[4096]; /* buffer for already read but not returned data */
+    char  read_buf[8192]; /* buffer for already read but not returned data */
     header_t *headers;
     DWORD num_headers;
-    WCHAR **accept_types;
-    DWORD num_accept_types;
     struct authinfo *authinfo;
     struct authinfo *proxy_authinfo;
+    HANDLE task_wait;
+    HANDLE task_cancel;
+    HANDLE task_thread;
+    struct list task_queue;
+    CRITICAL_SECTION task_cs;
+    struct
+    {
+        WCHAR *username;
+        WCHAR *password;
+    } creds[TARGET_MAX][SCHEME_MAX];
 } request_t;
 
 typedef struct _task_header_t task_header_t;
 
 struct _task_header_t
 {
+    struct list entry;
     request_t *request;
     void (*proc)( task_header_t * );
 };
@@ -274,17 +297,15 @@ void send_callback( object_header_t *, DWORD, LPVOID, DWORD ) DECLSPEC_HIDDEN;
 void close_connection( request_t * ) DECLSPEC_HIDDEN;
 
 BOOL netconn_close( netconn_t * ) DECLSPEC_HIDDEN;
-BOOL netconn_connect( netconn_t *, const struct sockaddr *, unsigned int, int ) DECLSPEC_HIDDEN;
-BOOL netconn_connected( netconn_t * ) DECLSPEC_HIDDEN;
-BOOL netconn_create( netconn_t *, int, int, int ) DECLSPEC_HIDDEN;
-BOOL netconn_init( netconn_t * ) DECLSPEC_HIDDEN;
+netconn_t *netconn_create( hostdata_t *, const struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
 void netconn_unload( void ) DECLSPEC_HIDDEN;
-BOOL netconn_query_data_available( netconn_t *, DWORD * ) DECLSPEC_HIDDEN;
+ULONG netconn_query_data_available( netconn_t * ) DECLSPEC_HIDDEN;
 BOOL netconn_recv( netconn_t *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
-BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr *, socklen_t *, int ) DECLSPEC_HIDDEN;
-BOOL netconn_secure_connect( netconn_t *, WCHAR * ) DECLSPEC_HIDDEN;
+BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
+BOOL netconn_secure_connect( netconn_t *, WCHAR *, DWORD, CredHandle * ) DECLSPEC_HIDDEN;
 BOOL netconn_send( netconn_t *, const void *, size_t, int * ) DECLSPEC_HIDDEN;
 DWORD netconn_set_timeout( netconn_t *, BOOL, int ) DECLSPEC_HIDDEN;
+BOOL netconn_is_alive( netconn_t * ) DECLSPEC_HIDDEN;
 const void *netconn_get_certificate( netconn_t * ) DECLSPEC_HIDDEN;
 int netconn_get_cipher_strength( netconn_t * ) DECLSPEC_HIDDEN;
 
@@ -295,64 +316,18 @@ void delete_domain( domain_t * ) DECLSPEC_HIDDEN;
 BOOL set_server_for_hostname( connect_t *, LPCWSTR, INTERNET_PORT ) DECLSPEC_HIDDEN;
 void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN;
 
-extern HRESULT WinHttpRequest_create( IUnknown *, void ** ) DECLSPEC_HIDDEN;
-
-static inline const char *debugstr_variant( const VARIANT *v )
-{
-    if (!v) return "(null)";
-    switch (V_VT(v))
-    {
-    case VT_EMPTY:
-        return "{VT_EMPTY}";
-    case VT_NULL:
-        return "{VT_NULL}";
-    case VT_I4:
-        return wine_dbg_sprintf( "{VT_I4: %d}", V_I4(v) );
-    case VT_R8:
-        return wine_dbg_sprintf( "{VT_R8: %lf}", V_R8(v) );
-    case VT_BSTR:
-        return wine_dbg_sprintf( "{VT_BSTR: %s}", debugstr_w(V_BSTR(v)) );
-    case VT_DISPATCH:
-        return wine_dbg_sprintf( "{VT_DISPATCH: %p}", V_DISPATCH(v) );
-    case VT_BOOL:
-        return wine_dbg_sprintf( "{VT_BOOL: %x}", V_BOOL(v) );
-    case VT_UNKNOWN:
-        return wine_dbg_sprintf( "{VT_UNKNOWN: %p}", V_UNKNOWN(v) );
-    case VT_UINT:
-        return wine_dbg_sprintf( "{VT_UINT: %u}", V_UINT(v) );
-    case VT_BSTR|VT_BYREF:
-        return wine_dbg_sprintf( "{VT_BSTR|VT_BYREF: ptr %p, data %s}",
-            V_BSTRREF(v), V_BSTRREF(v) ? debugstr_w( *V_BSTRREF(v) ) : NULL );
-    default:
-        return wine_dbg_sprintf( "{vt %d}", V_VT(v) );
-    }
-}
-
-static inline void *heap_alloc( SIZE_T size )
-{
-    return HeapAlloc( GetProcessHeap(), 0, size );
-}
+void release_host( hostdata_t *host ) DECLSPEC_HIDDEN;
 
-static inline void *heap_alloc_zero( SIZE_T size )
-{
-    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
-}
+BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD flags, BOOL request_only ) DECLSPEC_HIDDEN;
 
-static inline void *heap_realloc( LPVOID mem, SIZE_T size )
-{
-    return HeapReAlloc( GetProcessHeap(), 0, mem, size );
-}
+extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
+void release_typelib( void ) DECLSPEC_HIDDEN;
 
-static inline void *heap_realloc_zero( LPVOID mem, SIZE_T size )
+static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero( LPVOID mem, SIZE_T size )
 {
     return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
 }
 
-static inline BOOL heap_free( LPVOID mem )
-{
-    return HeapFree( GetProcessHeap(), 0, mem );
-}
-
 static inline WCHAR *strdupW( const WCHAR *src )
 {
     WCHAR *dst;
@@ -387,4 +362,21 @@ static inline char *strdupWA( const WCHAR *src )
     return dst;
 }
 
+static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
+{
+    char *dst = NULL;
+    if (src)
+    {
+        int len = WideCharToMultiByte( CP_ACP, 0, src, size, NULL, 0, NULL, NULL ) + 1;
+        if ((dst = heap_alloc( len )))
+        {
+            WideCharToMultiByte( CP_ACP, 0, src, len, dst, size, NULL, NULL );
+            dst[len - 1] = 0;
+        }
+    }
+    return dst;
+}
+
+extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;
+
 #endif /* _WINE_WINHTTP_PRIVATE_H_ */