[WINHTTP] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / winhttp / main.c
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define COBJMACROS
20 #include "config.h"
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "rpcproxy.h"
27 #include "httprequest.h"
28 #include "winhttp.h"
29
30 #include "wine/debug.h"
31 #include "winhttp_private.h"
32
33 HINSTANCE winhttp_instance;
34
35 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
36
37 /******************************************************************
38 * DllMain (winhttp.@)
39 */
40 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
41 {
42 switch(fdwReason)
43 {
44 case DLL_PROCESS_ATTACH:
45 winhttp_instance = hInstDLL;
46 DisableThreadLibraryCalls(hInstDLL);
47 break;
48 case DLL_PROCESS_DETACH:
49 if (lpv) break;
50 netconn_unload();
51 release_typelib();
52 break;
53 }
54 return TRUE;
55 }
56
57 typedef HRESULT (*fnCreateInstance)( void **obj );
58
59 struct winhttp_cf
60 {
61 IClassFactory IClassFactory_iface;
62 fnCreateInstance pfnCreateInstance;
63 };
64
65 static inline struct winhttp_cf *impl_from_IClassFactory( IClassFactory *iface )
66 {
67 return CONTAINING_RECORD( iface, struct winhttp_cf, IClassFactory_iface );
68 }
69
70 static HRESULT WINAPI requestcf_QueryInterface(
71 IClassFactory *iface,
72 REFIID riid,
73 void **obj )
74 {
75 if (IsEqualGUID( riid, &IID_IUnknown ) ||
76 IsEqualGUID( riid, &IID_IClassFactory ))
77 {
78 IClassFactory_AddRef( iface );
79 *obj = iface;
80 return S_OK;
81 }
82 FIXME("interface %s not implemented\n", debugstr_guid(riid));
83 return E_NOINTERFACE;
84 }
85
86 static ULONG WINAPI requestcf_AddRef(
87 IClassFactory *iface )
88 {
89 return 2;
90 }
91
92 static ULONG WINAPI requestcf_Release(
93 IClassFactory *iface )
94 {
95 return 1;
96 }
97
98 static HRESULT WINAPI requestcf_CreateInstance(
99 IClassFactory *iface,
100 LPUNKNOWN outer,
101 REFIID riid,
102 void **obj )
103 {
104 struct winhttp_cf *cf = impl_from_IClassFactory( iface );
105 IUnknown *unknown;
106 HRESULT hr;
107
108 TRACE("%p, %s, %p\n", outer, debugstr_guid(riid), obj);
109
110 *obj = NULL;
111 if (outer)
112 return CLASS_E_NOAGGREGATION;
113
114 hr = cf->pfnCreateInstance( (void **)&unknown );
115 if (FAILED(hr))
116 return hr;
117
118 hr = IUnknown_QueryInterface( unknown, riid, obj );
119 IUnknown_Release( unknown );
120 return hr;
121 }
122
123 static HRESULT WINAPI requestcf_LockServer(
124 IClassFactory *iface,
125 BOOL dolock )
126 {
127 FIXME("%p, %d\n", iface, dolock);
128 return S_OK;
129 }
130
131 static const struct IClassFactoryVtbl winhttp_cf_vtbl =
132 {
133 requestcf_QueryInterface,
134 requestcf_AddRef,
135 requestcf_Release,
136 requestcf_CreateInstance,
137 requestcf_LockServer
138 };
139
140 static struct winhttp_cf request_cf = { { &winhttp_cf_vtbl }, WinHttpRequest_create };
141
142 /******************************************************************
143 * DllGetClassObject (winhttp.@)
144 */
145 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
146 {
147 IClassFactory *cf = NULL;
148
149 TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
150
151 if (IsEqualGUID( rclsid, &CLSID_WinHttpRequest ))
152 {
153 cf = &request_cf.IClassFactory_iface;
154 }
155 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
156 return IClassFactory_QueryInterface( cf, riid, ppv );
157 }
158
159 /******************************************************************
160 * DllCanUnloadNow (winhttp.@)
161 */
162 HRESULT WINAPI DllCanUnloadNow(void)
163 {
164 return S_FALSE;
165 }
166
167 /***********************************************************************
168 * DllRegisterServer (winhttp.@)
169 */
170 HRESULT WINAPI DllRegisterServer(void)
171 {
172 return __wine_register_resources( winhttp_instance );
173 }
174
175 /***********************************************************************
176 * DllUnregisterServer (winhttp.@)
177 */
178 HRESULT WINAPI DllUnregisterServer(void)
179 {
180 return __wine_unregister_resources( winhttp_instance );
181 }