Sync with trunk r63174.
[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)( 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( (void **)&unknown );
103 if (FAILED(hr))
104 return hr;
105
106 hr = IUnknown_QueryInterface( unknown, riid, obj );
107 IUnknown_Release( unknown );
108 return hr;
109 }
110
111 static HRESULT WINAPI requestcf_LockServer(
112 IClassFactory *iface,
113 BOOL dolock )
114 {
115 FIXME("%p, %d\n", iface, dolock);
116 return S_OK;
117 }
118
119 static const struct IClassFactoryVtbl winhttp_cf_vtbl =
120 {
121 requestcf_QueryInterface,
122 requestcf_AddRef,
123 requestcf_Release,
124 requestcf_CreateInstance,
125 requestcf_LockServer
126 };
127
128 static struct winhttp_cf request_cf = { { &winhttp_cf_vtbl }, WinHttpRequest_create };
129
130 /******************************************************************
131 * DllGetClassObject (winhttp.@)
132 */
133 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
134 {
135 IClassFactory *cf = NULL;
136
137 TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
138
139 if (IsEqualGUID( rclsid, &CLSID_WinHttpRequest ))
140 {
141 cf = &request_cf.IClassFactory_iface;
142 }
143 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
144 return IClassFactory_QueryInterface( cf, riid, ppv );
145 }
146
147 /******************************************************************
148 * DllCanUnloadNow (winhttp.@)
149 */
150 HRESULT WINAPI DllCanUnloadNow(void)
151 {
152 return S_FALSE;
153 }
154
155 /***********************************************************************
156 * DllRegisterServer (winhttp.@)
157 */
158 HRESULT WINAPI DllRegisterServer(void)
159 {
160 return __wine_register_resources( instance );
161 }
162
163 /***********************************************************************
164 * DllUnregisterServer (winhttp.@)
165 */
166 HRESULT WINAPI DllUnregisterServer(void)
167 {
168 return __wine_unregister_resources( instance );
169 }