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