Sync with trunk r63174.
[reactos.git] / dll / win32 / urlmon / urlmon_main.h
index ea33f15..e93c80b 100644 (file)
 
 #include <stdarg.h>
 
+#define WIN32_NO_STATUS
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+
 #define COBJMACROS
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
 
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "ole2.h"
-#include "urlmon.h"
-#include "wininet.h"
+#include <windef.h>
+#include <winbase.h>
+#include <winreg.h>
+#include <objbase.h>
+#include <oleauto.h>
+#include <urlmon.h>
+#include <wininet.h>
+#include <advpub.h>
+#define NO_SHLWAPI_REG
+#include <shlwapi.h>
+
+#include <wine/debug.h>
+#include <wine/list.h>
+#include <wine/unicode.h>
 
-#include "wine/unicode.h"
-#include "wine/list.h"
+WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
 
 extern HINSTANCE hProxyDll DECLSPEC_HIDDEN;
-extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT StdURLMoniker_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
-extern HRESULT MimeFilter_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
+extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT StdURLMoniker_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT MimeFilter_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
+extern HRESULT Uri_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
 
 extern BOOL WINAPI URLMON_DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) DECLSPEC_HIDDEN;
 extern HRESULT WINAPI URLMON_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) DECLSPEC_HIDDEN;
@@ -54,34 +66,35 @@ extern HRESULT WINAPI URLMON_DllRegisterServer(void) DECLSPEC_HIDDEN;
 extern HRESULT WINAPI URLMON_DllUnregisterServer(void) DECLSPEC_HIDDEN;
 
 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
+extern GUID const CLSID_CUri DECLSPEC_HIDDEN;
 
 /**********************************************************************
  * Dll lifetime tracking declaration for urlmon.dll
  */
-extern LONG URLMON_refCount;
+extern LONG URLMON_refCount DECLSPEC_HIDDEN;
 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
 
-#define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
-#define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
+extern HINSTANCE urlmon_instance;
 
-IInternetProtocolInfo *get_protocol_info(LPCWSTR);
-HRESULT get_protocol_handler(IUri*,CLSID*,BOOL*,IClassFactory**);
-IInternetProtocol *get_mime_filter(LPCWSTR);
-BOOL is_registered_protocol(LPCWSTR);
-void register_urlmon_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL);
-HINTERNET get_internet_session(IInternetBindInfo*);
-LPWSTR get_useragent(void);
-void free_session(void);
+IInternetProtocolInfo *get_protocol_info(LPCWSTR) DECLSPEC_HIDDEN;
+HRESULT get_protocol_handler(IUri*,CLSID*,BOOL*,IClassFactory**) DECLSPEC_HIDDEN;
+IInternetProtocol *get_mime_filter(LPCWSTR) DECLSPEC_HIDDEN;
+BOOL is_registered_protocol(LPCWSTR) DECLSPEC_HIDDEN;
+HRESULT register_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL) DECLSPEC_HIDDEN;
+HINTERNET get_internet_session(IInternetBindInfo*) DECLSPEC_HIDDEN;
+LPWSTR get_useragent(void) DECLSPEC_HIDDEN;
+void free_session(void) DECLSPEC_HIDDEN;
 
-HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**);
-HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv);
+HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**) DECLSPEC_HIDDEN;
+HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv) DECLSPEC_HIDDEN;
 
-HRESULT create_binding_protocol(BOOL,IInternetProtocolEx**);
-void set_binding_sink(IInternetProtocolEx*,IInternetProtocolSink*,IInternetBindInfo*);
-IWinInetInfo *get_wininet_info(IInternetProtocolEx*);
-HRESULT create_default_callback(IBindStatusCallback**);
-HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**);
+HRESULT create_default_callback(IBindStatusCallback**) DECLSPEC_HIDDEN;
+HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**) DECLSPEC_HIDDEN;
+IBindStatusCallback *bsc_from_bctx(IBindCtx*) DECLSPEC_HIDDEN;
+
+typedef HRESULT (*stop_cache_binding_proc_t)(void*,const WCHAR*,HRESULT,const WCHAR*);
+HRESULT download_to_cache(IUri*,stop_cache_binding_proc_t,void*,IBindStatusCallback*) DECLSPEC_HIDDEN;
 
 typedef struct ProtocolVtbl ProtocolVtbl;
 
@@ -102,6 +115,7 @@ typedef struct {
     ULONG current_position;
     ULONG content_length;
     ULONG available_bytes;
+    ULONG query_available;
 
     IStream *post_stream;
 
@@ -113,30 +127,105 @@ struct ProtocolVtbl {
     HRESULT (*end_request)(Protocol*);
     HRESULT (*start_downloading)(Protocol*);
     void (*close_connection)(Protocol*);
+    void (*on_error)(Protocol*,DWORD);
 };
 
-HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*);
-HRESULT protocol_continue(Protocol*,PROTOCOLDATA*);
-HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*);
-HRESULT protocol_lock_request(Protocol*);
-HRESULT protocol_unlock_request(Protocol*);
-HRESULT protocol_abort(Protocol*,HRESULT);
-void protocol_close_connection(Protocol*);
+/* Flags are needed for, among other things, return HRESULTs from the Read function
+ * to conform to native. For example, Read returns:
+ *
+ * 1. E_PENDING if called before the request has completed,
+ *        (flags = 0)
+ * 2. S_FALSE after all data has been read and S_OK has been reported,
+ *        (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
+ * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
+ *    this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
+ *        (flags = FLAG_REQUEST_COMPLETE)
+ *    but upon subsequent calls to Read no reporting will take place, yet
+ *    InternetQueryDataAvailable will still be called, and, on failure,
+ *    INET_E_DATA_NOT_AVAILABLE will still be returned.
+ *        (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
+ *
+ * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
+ * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
+ * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
+ * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
+ * if OnResponse does not return S_OK, Continue will not report data, and Read
+ * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
+ * data has been read.
+ */
+#define FLAG_REQUEST_COMPLETE         0x0001
+#define FLAG_FIRST_CONTINUE_COMPLETE  0x0002
+#define FLAG_FIRST_DATA_REPORTED      0x0004
+#define FLAG_ALL_DATA_READ            0x0008
+#define FLAG_LAST_DATA_REPORTED       0x0010
+#define FLAG_RESULT_REPORTED          0x0020
+#define FLAG_ERROR                    0x0040
+#define FLAG_SYNC_READ                0x0080
+
+HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
+HRESULT protocol_continue(Protocol*,PROTOCOLDATA*) DECLSPEC_HIDDEN;
+HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*) DECLSPEC_HIDDEN;
+HRESULT protocol_lock_request(Protocol*) DECLSPEC_HIDDEN;
+HRESULT protocol_unlock_request(Protocol*) DECLSPEC_HIDDEN;
+HRESULT protocol_abort(Protocol*,HRESULT) DECLSPEC_HIDDEN;
+HRESULT protocol_syncbinding(Protocol*) DECLSPEC_HIDDEN;
+void protocol_close_connection(Protocol*) DECLSPEC_HIDDEN;
+
+void find_domain_name(const WCHAR*,DWORD,INT*) DECLSPEC_HIDDEN;
+
+typedef struct _task_header_t task_header_t;
 
 typedef struct {
-    const IInternetProtocolVtbl      *lpIInternetProtocolVtbl;
-    const IInternetProtocolSinkVtbl  *lpIInternetProtocolSinkVtbl;
+    IInternetProtocolEx   IInternetProtocolEx_iface;
+    IInternetBindInfo     IInternetBindInfo_iface;
+    IInternetPriority     IInternetPriority_iface;
+    IServiceProvider      IServiceProvider_iface;
+    IInternetProtocolSink IInternetProtocolSink_iface;
+    IWinInetHttpInfo      IWinInetHttpInfo_iface;
 
     LONG ref;
 
-    IInternetProtocolSink *protocol_sink;
     IInternetProtocol *protocol;
-} ProtocolProxy;
+    IInternetBindInfo *bind_info;
+    IInternetProtocolSink *protocol_sink;
+    IServiceProvider *service_provider;
+    IWinInetInfo *wininet_info;
+    IWinInetHttpInfo *wininet_http_info;
+
+    struct {
+        IInternetProtocol IInternetProtocol_iface;
+        IInternetProtocolSink IInternetProtocolSink_iface;
+    } default_protocol_handler;
+    IInternetProtocol *protocol_handler;
+    IInternetProtocolSink *protocol_sink_handler;
+
+    LONG priority;
+
+    BOOL reported_result;
+    BOOL reported_mime;
+    BOOL from_urlmon;
+    DWORD pi;
+
+    DWORD bscf;
+    ULONG progress;
+    ULONG progress_max;
 
-#define PROTOCOL(x)  ((IInternetProtocol*)       &(x)->lpIInternetProtocolVtbl)
-#define PROTSINK(x)  ((IInternetProtocolSink*)   &(x)->lpIInternetProtocolSinkVtbl)
+    DWORD apartment_thread;
+    HWND notif_hwnd;
+    DWORD continue_call;
+
+    CRITICAL_SECTION section;
+    task_header_t *task_queue_head, *task_queue_tail;
 
-HRESULT create_protocol_proxy(IInternetProtocol*,IInternetProtocolSink*,ProtocolProxy**);
+    BYTE *buf;
+    DWORD buf_size;
+    LPWSTR mime;
+    IUri *uri;
+    BSTR display_uri;
+}  BindProtocol;
+
+HRESULT create_binding_protocol(BOOL,BindProtocol**) DECLSPEC_HIDDEN;
+void set_binding_sink(BindProtocol*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
 
 typedef struct {
     HWND notif_hwnd;
@@ -145,10 +234,12 @@ typedef struct {
     struct list entry;
 } tls_data_t;
 
-tls_data_t *get_tls_data(void);
+tls_data_t *get_tls_data(void) DECLSPEC_HIDDEN;
+
+HWND get_notif_hwnd(void) DECLSPEC_HIDDEN;
+void release_notif_hwnd(HWND) DECLSPEC_HIDDEN;
 
-HWND get_notif_hwnd(void);
-void release_notif_hwnd(HWND);
+const char *debugstr_bindstatus(ULONG) DECLSPEC_HIDDEN;
 
 static inline void *heap_alloc(size_t len)
 {
@@ -184,7 +275,8 @@ static inline LPWSTR heap_strdupW(LPCWSTR str)
 
         size = (strlenW(str)+1)*sizeof(WCHAR);
         ret = heap_alloc(size);
-        memcpy(ret, str, size);
+        if(ret)
+            memcpy(ret, str, size);
     }
 
     return ret;
@@ -212,7 +304,22 @@ static inline LPWSTR heap_strdupAtoW(const char *str)
     if(str) {
         DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
         ret = heap_alloc(len*sizeof(WCHAR));
-        MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+        if(ret)
+            MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+    }
+
+    return ret;
+}
+
+static inline char *heap_strdupWtoA(const WCHAR *str)
+{
+    char *ret = NULL;
+
+    if(str) {
+        size_t size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
+        ret = heap_alloc(size);
+        if(ret)
+            WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
     }
 
     return ret;