winhttp: Implement WinHttpGetIEProxyConfigForCurrentUser.
[wine] / dlls / 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 COBJMACROS
20 #include "config.h"
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "rpcproxy.h"
27 #include "httprequest.h"
28 #include "winhttp.h"
29
30 #include "wine/debug.h"
31 #include "winhttp_private.h"
32
33 static HINSTANCE instance;
34
35 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
36
37 /******************************************************************
38  *              DllMain (winhttp.@)
39  */
40 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
41 {
42     switch(fdwReason)
43     {
44     case DLL_PROCESS_ATTACH:
45         instance = hInstDLL;
46         DisableThreadLibraryCalls(hInstDLL);
47         break;
48     case DLL_PROCESS_DETACH:
49         netconn_unload();
50         break;
51     }
52     return TRUE;
53 }
54
55 typedef HRESULT (*fnCreateInstance)( IUnknown *outer, void **obj );
56
57 struct winhttp_cf
58 {
59     IClassFactory IClassFactory_iface;
60     fnCreateInstance pfnCreateInstance;
61 };
62
63 static inline struct winhttp_cf *impl_from_IClassFactory( IClassFactory *iface )
64 {
65     return CONTAINING_RECORD( iface, struct winhttp_cf, IClassFactory_iface );
66 }
67
68 static HRESULT WINAPI requestcf_QueryInterface(
69     IClassFactory *iface,
70     REFIID riid,
71     void **obj )
72 {
73     if (IsEqualGUID( riid, &IID_IUnknown ) ||
74         IsEqualGUID( riid, &IID_IClassFactory ))
75     {
76         IClassFactory_AddRef( iface );
77         *obj = iface;
78         return S_OK;
79     }
80     FIXME("interface %s not implemented\n", debugstr_guid(riid));
81     return E_NOINTERFACE;
82 }
83
84 static ULONG WINAPI requestcf_AddRef(
85     IClassFactory *iface )
86 {
87     return 2;
88 }
89
90 static ULONG WINAPI requestcf_Release(
91     IClassFactory *iface )
92 {
93     return 1;
94 }
95
96 static HRESULT WINAPI requestcf_CreateInstance(
97     IClassFactory *iface,
98     LPUNKNOWN outer,
99     REFIID riid,
100     void **obj )
101 {
102     struct winhttp_cf *cf = impl_from_IClassFactory( iface );
103     IUnknown *unknown;
104     HRESULT hr;
105
106     TRACE("%p, %s, %p\n", outer, debugstr_guid(riid), obj);
107
108     *obj = NULL;
109     if (outer)
110         return CLASS_E_NOAGGREGATION;
111
112     hr = cf->pfnCreateInstance( outer, (void **)&unknown );
113     if (FAILED(hr))
114         return hr;
115
116     hr = IUnknown_QueryInterface( unknown, riid, obj );
117     if (FAILED(hr))
118         return hr;
119
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( instance );
174 }
175
176 /***********************************************************************
177  *          DllUnregisterServer (winhttp.@)
178  */
179 HRESULT WINAPI DllUnregisterServer(void)
180 {
181     return __wine_unregister_resources( instance );
182 }