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