2 * Copyright 2009 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
27 const IInternetProtocolVtbl *lpIInternetProtocolVtbl;
28 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
33 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
35 static inline GopherProtocol *impl_from_Protocol(Protocol *prot)
37 return CONTAINING_RECORD(prot, GopherProtocol, base);
40 static HRESULT GopherProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
41 HINTERNET internet_session, IInternetBindInfo *bind_info)
43 GopherProtocol *This = impl_from_Protocol(prot);
47 hres = IUri_GetAbsoluteUri(uri, &url);
51 This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0,
52 request_flags, (DWORD_PTR)&This->base);
54 if (!This->base.request && GetLastError() != ERROR_IO_PENDING) {
55 WARN("InternetOpenUrl failed: %d\n", GetLastError());
56 return INET_E_RESOURCE_NOT_FOUND;
62 static HRESULT GopherProtocol_end_request(Protocol *prot)
67 static HRESULT GopherProtocol_start_downloading(Protocol *prot)
72 static void GopherProtocol_close_connection(Protocol *prot)
76 static void GopherProtocol_on_error(Protocol *prot, DWORD error)
78 FIXME("(%p) %d - stub\n", prot, error);
81 static const ProtocolVtbl AsyncProtocolVtbl = {
82 GopherProtocol_open_request,
83 GopherProtocol_end_request,
84 GopherProtocol_start_downloading,
85 GopherProtocol_close_connection,
86 GopherProtocol_on_error
89 #define PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, IInternetProtocol, iface)
91 static HRESULT WINAPI GopherProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
93 GopherProtocol *This = PROTOCOL_THIS(iface);
96 if(IsEqualGUID(&IID_IUnknown, riid)) {
97 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
98 *ppv = PROTOCOL(This);
99 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
100 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
101 *ppv = PROTOCOL(This);
102 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
103 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
104 *ppv = PROTOCOL(This);
105 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
106 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
107 *ppv = PRIORITY(This);
111 IInternetProtocol_AddRef(iface);
115 WARN("not supported interface %s\n", debugstr_guid(riid));
116 return E_NOINTERFACE;
119 static ULONG WINAPI GopherProtocol_AddRef(IInternetProtocol *iface)
121 GopherProtocol *This = PROTOCOL_THIS(iface);
122 LONG ref = InterlockedIncrement(&This->ref);
123 TRACE("(%p) ref=%d\n", This, ref);
127 static ULONG WINAPI GopherProtocol_Release(IInternetProtocol *iface)
129 GopherProtocol *This = PROTOCOL_THIS(iface);
130 LONG ref = InterlockedDecrement(&This->ref);
132 TRACE("(%p) ref=%d\n", This, ref);
137 URLMON_UnlockModule();
143 static HRESULT WINAPI GopherProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
144 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
145 DWORD grfPI, HANDLE_PTR dwReserved)
147 GopherProtocol *This = PROTOCOL_THIS(iface);
151 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
152 pOIBindInfo, grfPI, dwReserved);
154 hres = CreateUri(szUrl, 0, 0, &uri);
158 hres = protocol_start(&This->base, PROTOCOL(This), uri, pOIProtSink, pOIBindInfo);
164 static HRESULT WINAPI GopherProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
166 GopherProtocol *This = PROTOCOL_THIS(iface);
168 TRACE("(%p)->(%p)\n", This, pProtocolData);
170 return protocol_continue(&This->base, pProtocolData);
173 static HRESULT WINAPI GopherProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
176 GopherProtocol *This = PROTOCOL_THIS(iface);
178 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
180 return protocol_abort(&This->base, hrReason);
183 static HRESULT WINAPI GopherProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
185 GopherProtocol *This = PROTOCOL_THIS(iface);
187 TRACE("(%p)->(%08x)\n", This, dwOptions);
189 protocol_close_connection(&This->base);
193 static HRESULT WINAPI GopherProtocol_Suspend(IInternetProtocol *iface)
195 GopherProtocol *This = PROTOCOL_THIS(iface);
196 FIXME("(%p)\n", This);
200 static HRESULT WINAPI GopherProtocol_Resume(IInternetProtocol *iface)
202 GopherProtocol *This = PROTOCOL_THIS(iface);
203 FIXME("(%p)\n", This);
207 static HRESULT WINAPI GopherProtocol_Read(IInternetProtocol *iface, void *pv,
208 ULONG cb, ULONG *pcbRead)
210 GopherProtocol *This = PROTOCOL_THIS(iface);
212 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
214 return protocol_read(&This->base, pv, cb, pcbRead);
217 static HRESULT WINAPI GopherProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
218 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
220 GopherProtocol *This = PROTOCOL_THIS(iface);
221 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
225 static HRESULT WINAPI GopherProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
227 GopherProtocol *This = PROTOCOL_THIS(iface);
229 TRACE("(%p)->(%08x)\n", This, dwOptions);
231 return protocol_lock_request(&This->base);
234 static HRESULT WINAPI GopherProtocol_UnlockRequest(IInternetProtocol *iface)
236 GopherProtocol *This = PROTOCOL_THIS(iface);
238 TRACE("(%p)\n", This);
240 return protocol_unlock_request(&This->base);
245 static const IInternetProtocolVtbl GopherProtocolVtbl = {
246 GopherProtocol_QueryInterface,
247 GopherProtocol_AddRef,
248 GopherProtocol_Release,
249 GopherProtocol_Start,
250 GopherProtocol_Continue,
251 GopherProtocol_Abort,
252 GopherProtocol_Terminate,
253 GopherProtocol_Suspend,
254 GopherProtocol_Resume,
257 GopherProtocol_LockRequest,
258 GopherProtocol_UnlockRequest
261 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
263 static HRESULT WINAPI GopherPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
265 GopherProtocol *This = PRIORITY_THIS(iface);
266 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
269 static ULONG WINAPI GopherPriority_AddRef(IInternetPriority *iface)
271 GopherProtocol *This = PRIORITY_THIS(iface);
272 return IInternetProtocol_AddRef(PROTOCOL(This));
275 static ULONG WINAPI GopherPriority_Release(IInternetPriority *iface)
277 GopherProtocol *This = PRIORITY_THIS(iface);
278 return IInternetProtocol_Release(PROTOCOL(This));
281 static HRESULT WINAPI GopherPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
283 GopherProtocol *This = PRIORITY_THIS(iface);
285 TRACE("(%p)->(%d)\n", This, nPriority);
287 This->base.priority = nPriority;
291 static HRESULT WINAPI GopherPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
293 GopherProtocol *This = PRIORITY_THIS(iface);
295 TRACE("(%p)->(%p)\n", This, pnPriority);
297 *pnPriority = This->base.priority;
303 static const IInternetPriorityVtbl GopherPriorityVtbl = {
304 GopherPriority_QueryInterface,
305 GopherPriority_AddRef,
306 GopherPriority_Release,
307 GopherPriority_SetPriority,
308 GopherPriority_GetPriority
311 HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
315 TRACE("(%p %p)\n", pUnkOuter, ppobj);
319 ret = heap_alloc_zero(sizeof(GopherProtocol));
321 ret->base.vtbl = &AsyncProtocolVtbl;
322 ret->lpIInternetProtocolVtbl = &GopherProtocolVtbl;
323 ret->lpInternetPriorityVtbl = &GopherPriorityVtbl;
326 *ppobj = PROTOCOL(ret);