[WINHTTP] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / reactos / 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 #include "winhttp_private.h"
20
21 #include <rpcproxy.h>
22 #include <httprequest.h>
23
24 static HINSTANCE instance;
25
26 /******************************************************************
27 * DllMain (winhttp.@)
28 */
29 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
30 {
31 switch(fdwReason)
32 {
33 case DLL_PROCESS_ATTACH:
34 instance = hInstDLL;
35 DisableThreadLibraryCalls(hInstDLL);
36 break;
37 case DLL_PROCESS_DETACH:
38 if (lpv) break;
39 netconn_unload();
40 release_typelib();
41 break;
42 }
43 return TRUE;
44 }
45
46 typedef HRESULT (*fnCreateInstance)( void **obj );
47
48 struct winhttp_cf
49 {
50 IClassFactory IClassFactory_iface;
51 fnCreateInstance pfnCreateInstance;
52 };
53
54 static inline struct winhttp_cf *impl_from_IClassFactory( IClassFactory *iface )
55 {
56 return CONTAINING_RECORD( iface, struct winhttp_cf, IClassFactory_iface );
57 }
58
59 static HRESULT WINAPI requestcf_QueryInterface(
60 IClassFactory *iface,
61 REFIID riid,
62 void **obj )
63 {
64 if (IsEqualGUID( riid, &IID_IUnknown ) ||
65 IsEqualGUID( riid, &IID_IClassFactory ))
66 {
67 IClassFactory_AddRef( iface );
68 *obj = iface;
69 return S_OK;
70 }
71 FIXME("interface %s not implemented\n", debugstr_guid(riid));
72 return E_NOINTERFACE;
73 }
74
75 static ULONG WINAPI requestcf_AddRef(
76 IClassFactory *iface )
77 {
78 return 2;
79 }
80
81 static ULONG WINAPI requestcf_Release(
82 IClassFactory *iface )
83 {
84 return 1;
85 }
86
87 static HRESULT WINAPI requestcf_CreateInstance(
88 IClassFactory *iface,
89 LPUNKNOWN outer,
90 REFIID riid,
91 void **obj )
92 {
93 struct winhttp_cf *cf = impl_from_IClassFactory( iface );
94 IUnknown *unknown;
95 HRESULT hr;
96
97 TRACE("%p, %s, %p\n", outer, debugstr_guid(riid), obj);
98
99 *obj = NULL;
100 if (outer)
101 return CLASS_E_NOAGGREGATION;
102
103 hr = cf->pfnCreateInstance( (void **)&unknown );
104 if (FAILED(hr))
105 return hr;
106
107 hr = IUnknown_QueryInterface( unknown, riid, obj );
108 IUnknown_Release( unknown );
109 return hr;
110 }
111
112 static HRESULT WINAPI requestcf_LockServer(
113 IClassFactory *iface,
114 BOOL dolock )
115 {
116 FIXME("%p, %d\n", iface, dolock);
117 return S_OK;
118 }
119
120 static const struct IClassFactoryVtbl winhttp_cf_vtbl =
121 {
122 requestcf_QueryInterface,
123 requestcf_AddRef,
124 requestcf_Release,
125 requestcf_CreateInstance,
126 requestcf_LockServer
127 };
128
129 static struct winhttp_cf request_cf = { { &winhttp_cf_vtbl }, WinHttpRequest_create };
130
131 /******************************************************************
132 * DllGetClassObject (winhttp.@)
133 */
134 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
135 {
136 IClassFactory *cf = NULL;
137
138 TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
139
140 if (IsEqualGUID( rclsid, &CLSID_WinHttpRequest ))
141 {
142 cf = &request_cf.IClassFactory_iface;
143 }
144 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
145 return IClassFactory_QueryInterface( cf, riid, ppv );
146 }
147
148 /******************************************************************
149 * DllCanUnloadNow (winhttp.@)
150 */
151 HRESULT WINAPI DllCanUnloadNow(void)
152 {
153 return S_FALSE;
154 }
155
156 /***********************************************************************
157 * DllRegisterServer (winhttp.@)
158 */
159 HRESULT WINAPI DllRegisterServer(void)
160 {
161 return __wine_register_resources( instance );
162 }
163
164 /***********************************************************************
165 * DllUnregisterServer (winhttp.@)
166 */
167 HRESULT WINAPI DllUnregisterServer(void)
168 {
169 return __wine_unregister_resources( instance );
170 }