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 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(GopherProtocol, base, iface)
37 static HRESULT GopherProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
38 HINTERNET internet_session, IInternetBindInfo *bind_info)
40 GopherProtocol *This = ASYNCPROTOCOL_THIS(prot);
44 hres = IUri_GetAbsoluteUri(uri, &url);
48 This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0,
49 request_flags, (DWORD_PTR)&This->base);
51 if (!This->base.request && GetLastError() != ERROR_IO_PENDING) {
52 WARN("InternetOpenUrl failed: %d\n", GetLastError());
53 return INET_E_RESOURCE_NOT_FOUND;
59 static HRESULT GopherProtocol_start_downloading(Protocol *prot)
64 static void GopherProtocol_close_connection(Protocol *prot)
68 #undef ASYNCPROTOCOL_THIS
70 static const ProtocolVtbl AsyncProtocolVtbl = {
71 GopherProtocol_open_request,
72 GopherProtocol_start_downloading,
73 GopherProtocol_close_connection
76 #define PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, IInternetProtocol, iface)
78 static HRESULT WINAPI GopherProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
80 GopherProtocol *This = PROTOCOL_THIS(iface);
83 if(IsEqualGUID(&IID_IUnknown, riid)) {
84 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
85 *ppv = PROTOCOL(This);
86 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
87 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
88 *ppv = PROTOCOL(This);
89 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
90 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
91 *ppv = PROTOCOL(This);
92 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
93 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
94 *ppv = PRIORITY(This);
98 IInternetProtocol_AddRef(iface);
102 WARN("not supported interface %s\n", debugstr_guid(riid));
103 return E_NOINTERFACE;
106 static ULONG WINAPI GopherProtocol_AddRef(IInternetProtocol *iface)
108 GopherProtocol *This = PROTOCOL_THIS(iface);
109 LONG ref = InterlockedIncrement(&This->ref);
110 TRACE("(%p) ref=%d\n", This, ref);
114 static ULONG WINAPI GopherProtocol_Release(IInternetProtocol *iface)
116 GopherProtocol *This = PROTOCOL_THIS(iface);
117 LONG ref = InterlockedDecrement(&This->ref);
119 TRACE("(%p) ref=%d\n", This, ref);
124 URLMON_UnlockModule();
130 static HRESULT WINAPI GopherProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
131 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
132 DWORD grfPI, HANDLE_PTR dwReserved)
134 GopherProtocol *This = PROTOCOL_THIS(iface);
138 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
139 pOIBindInfo, grfPI, dwReserved);
141 hres = CreateUri(szUrl, 0, 0, &uri);
145 hres = protocol_start(&This->base, PROTOCOL(This), uri, pOIProtSink, pOIBindInfo);
151 static HRESULT WINAPI GopherProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
153 GopherProtocol *This = PROTOCOL_THIS(iface);
155 TRACE("(%p)->(%p)\n", This, pProtocolData);
157 return protocol_continue(&This->base, pProtocolData);
160 static HRESULT WINAPI GopherProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
163 GopherProtocol *This = PROTOCOL_THIS(iface);
164 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
168 static HRESULT WINAPI GopherProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
170 GopherProtocol *This = PROTOCOL_THIS(iface);
172 TRACE("(%p)->(%08x)\n", This, dwOptions);
174 protocol_close_connection(&This->base);
178 static HRESULT WINAPI GopherProtocol_Suspend(IInternetProtocol *iface)
180 GopherProtocol *This = PROTOCOL_THIS(iface);
181 FIXME("(%p)\n", This);
185 static HRESULT WINAPI GopherProtocol_Resume(IInternetProtocol *iface)
187 GopherProtocol *This = PROTOCOL_THIS(iface);
188 FIXME("(%p)\n", This);
192 static HRESULT WINAPI GopherProtocol_Read(IInternetProtocol *iface, void *pv,
193 ULONG cb, ULONG *pcbRead)
195 GopherProtocol *This = PROTOCOL_THIS(iface);
197 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
199 return protocol_read(&This->base, pv, cb, pcbRead);
202 static HRESULT WINAPI GopherProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
203 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
205 GopherProtocol *This = PROTOCOL_THIS(iface);
206 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
210 static HRESULT WINAPI GopherProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
212 GopherProtocol *This = PROTOCOL_THIS(iface);
214 TRACE("(%p)->(%08x)\n", This, dwOptions);
216 return protocol_lock_request(&This->base);
219 static HRESULT WINAPI GopherProtocol_UnlockRequest(IInternetProtocol *iface)
221 GopherProtocol *This = PROTOCOL_THIS(iface);
223 TRACE("(%p)\n", This);
225 return protocol_unlock_request(&This->base);
230 static const IInternetProtocolVtbl GopherProtocolVtbl = {
231 GopherProtocol_QueryInterface,
232 GopherProtocol_AddRef,
233 GopherProtocol_Release,
234 GopherProtocol_Start,
235 GopherProtocol_Continue,
236 GopherProtocol_Abort,
237 GopherProtocol_Terminate,
238 GopherProtocol_Suspend,
239 GopherProtocol_Resume,
242 GopherProtocol_LockRequest,
243 GopherProtocol_UnlockRequest
246 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
248 static HRESULT WINAPI GopherPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
250 GopherProtocol *This = PRIORITY_THIS(iface);
251 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
254 static ULONG WINAPI GopherPriority_AddRef(IInternetPriority *iface)
256 GopherProtocol *This = PRIORITY_THIS(iface);
257 return IInternetProtocol_AddRef(PROTOCOL(This));
260 static ULONG WINAPI GopherPriority_Release(IInternetPriority *iface)
262 GopherProtocol *This = PRIORITY_THIS(iface);
263 return IInternetProtocol_Release(PROTOCOL(This));
266 static HRESULT WINAPI GopherPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
268 GopherProtocol *This = PRIORITY_THIS(iface);
270 TRACE("(%p)->(%d)\n", This, nPriority);
272 This->base.priority = nPriority;
276 static HRESULT WINAPI GopherPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
278 GopherProtocol *This = PRIORITY_THIS(iface);
280 TRACE("(%p)->(%p)\n", This, pnPriority);
282 *pnPriority = This->base.priority;
288 static const IInternetPriorityVtbl GopherPriorityVtbl = {
289 GopherPriority_QueryInterface,
290 GopherPriority_AddRef,
291 GopherPriority_Release,
292 GopherPriority_SetPriority,
293 GopherPriority_GetPriority
296 HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
300 TRACE("(%p %p)\n", pUnkOuter, ppobj);
304 ret = heap_alloc_zero(sizeof(GopherProtocol));
306 ret->base.vtbl = &AsyncProtocolVtbl;
307 ret->lpIInternetProtocolVtbl = &GopherProtocolVtbl;
308 ret->lpInternetPriorityVtbl = &GopherPriorityVtbl;
311 *ppobj = PROTOCOL(ret);