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