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