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
*lpInternetProtocolVtbl
;
28 const IInternetPriorityVtbl
*lpInternetPriorityVtbl
;
33 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
34 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
36 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(GopherProtocol, base, iface)
38 static HRESULT
GopherProtocol_open_request(Protocol
*prot
, LPCWSTR url
, DWORD request_flags
,
39 IInternetBindInfo
*bind_info
)
41 GopherProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
43 This
->base
.request
= InternetOpenUrlW(This
->base
.internet
, url
, NULL
, 0,
44 request_flags
, (DWORD_PTR
)&This
->base
);
45 if (!This
->base
.request
&& GetLastError() != ERROR_IO_PENDING
) {
46 WARN("InternetOpenUrl failed: %d\n", GetLastError());
47 return INET_E_RESOURCE_NOT_FOUND
;
53 static HRESULT
GopherProtocol_start_downloading(Protocol
*prot
)
58 static void GopherProtocol_close_connection(Protocol
*prot
)
62 #undef ASYNCPROTOCOL_THIS
64 static const ProtocolVtbl AsyncProtocolVtbl
= {
65 GopherProtocol_open_request
,
66 GopherProtocol_start_downloading
,
67 GopherProtocol_close_connection
70 #define PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, InternetProtocol, iface)
72 static HRESULT WINAPI
GopherProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
74 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
77 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
78 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
79 *ppv
= PROTOCOL(This
);
80 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
81 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
82 *ppv
= PROTOCOL(This
);
83 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
84 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
85 *ppv
= PROTOCOL(This
);
86 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
87 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
88 *ppv
= PRIORITY(This
);
92 IInternetProtocol_AddRef(iface
);
96 WARN("not supported interface %s\n", debugstr_guid(riid
));
100 static ULONG WINAPI
GopherProtocol_AddRef(IInternetProtocol
*iface
)
102 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
103 LONG ref
= InterlockedIncrement(&This
->ref
);
104 TRACE("(%p) ref=%d\n", This
, ref
);
108 static ULONG WINAPI
GopherProtocol_Release(IInternetProtocol
*iface
)
110 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
111 LONG ref
= InterlockedDecrement(&This
->ref
);
113 TRACE("(%p) ref=%d\n", This
, ref
);
118 URLMON_UnlockModule();
124 static HRESULT WINAPI
GopherProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
125 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
126 DWORD grfPI
, DWORD dwReserved
)
128 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
130 TRACE("(%p)->(%s %p %p %08x %d)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
131 pOIBindInfo
, grfPI
, dwReserved
);
133 return protocol_start(&This
->base
, PROTOCOL(This
), szUrl
, pOIProtSink
, pOIBindInfo
);
136 static HRESULT WINAPI
GopherProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
138 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
140 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
142 return protocol_continue(&This
->base
, pProtocolData
);
145 static HRESULT WINAPI
GopherProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
148 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
149 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
153 static HRESULT WINAPI
GopherProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
155 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
157 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
159 protocol_close_connection(&This
->base
);
163 static HRESULT WINAPI
GopherProtocol_Suspend(IInternetProtocol
*iface
)
165 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
166 FIXME("(%p)\n", This
);
170 static HRESULT WINAPI
GopherProtocol_Resume(IInternetProtocol
*iface
)
172 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
173 FIXME("(%p)\n", This
);
177 static HRESULT WINAPI
GopherProtocol_Read(IInternetProtocol
*iface
, void *pv
,
178 ULONG cb
, ULONG
*pcbRead
)
180 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
182 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
184 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
187 static HRESULT WINAPI
GopherProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
188 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
190 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
191 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
195 static HRESULT WINAPI
GopherProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
197 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
199 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
201 return protocol_lock_request(&This
->base
);
204 static HRESULT WINAPI
GopherProtocol_UnlockRequest(IInternetProtocol
*iface
)
206 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
208 TRACE("(%p)\n", This
);
210 return protocol_unlock_request(&This
->base
);
215 static const IInternetProtocolVtbl GopherProtocolVtbl
= {
216 GopherProtocol_QueryInterface
,
217 GopherProtocol_AddRef
,
218 GopherProtocol_Release
,
219 GopherProtocol_Start
,
220 GopherProtocol_Continue
,
221 GopherProtocol_Abort
,
222 GopherProtocol_Terminate
,
223 GopherProtocol_Suspend
,
224 GopherProtocol_Resume
,
227 GopherProtocol_LockRequest
,
228 GopherProtocol_UnlockRequest
231 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
233 static HRESULT WINAPI
GopherPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
235 GopherProtocol
*This
= PRIORITY_THIS(iface
);
236 return IInternetProtocol_QueryInterface(PROTOCOL(This
), riid
, ppv
);
239 static ULONG WINAPI
GopherPriority_AddRef(IInternetPriority
*iface
)
241 GopherProtocol
*This
= PRIORITY_THIS(iface
);
242 return IInternetProtocol_AddRef(PROTOCOL(This
));
245 static ULONG WINAPI
GopherPriority_Release(IInternetPriority
*iface
)
247 GopherProtocol
*This
= PRIORITY_THIS(iface
);
248 return IInternetProtocol_Release(PROTOCOL(This
));
251 static HRESULT WINAPI
GopherPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
253 GopherProtocol
*This
= PRIORITY_THIS(iface
);
255 TRACE("(%p)->(%d)\n", This
, nPriority
);
257 This
->base
.priority
= nPriority
;
261 static HRESULT WINAPI
GopherPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
263 GopherProtocol
*This
= PRIORITY_THIS(iface
);
265 TRACE("(%p)->(%p)\n", This
, pnPriority
);
267 *pnPriority
= This
->base
.priority
;
273 static const IInternetPriorityVtbl GopherPriorityVtbl
= {
274 GopherPriority_QueryInterface
,
275 GopherPriority_AddRef
,
276 GopherPriority_Release
,
277 GopherPriority_SetPriority
,
278 GopherPriority_GetPriority
281 HRESULT
GopherProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
285 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
289 ret
= heap_alloc_zero(sizeof(GopherProtocol
));
291 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
292 ret
->lpInternetProtocolVtbl
= &GopherProtocolVtbl
;
293 ret
->lpInternetPriorityVtbl
= &GopherPriorityVtbl
;
296 *ppobj
= PROTOCOL(ret
);