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"
24 IInternetProtocol IInternetProtocol_iface
;
25 IInternetPriority IInternetPriority_iface
;
30 static inline GopherProtocol
*impl_from_Protocol(Protocol
*prot
)
32 return CONTAINING_RECORD(prot
, GopherProtocol
, base
);
35 static HRESULT
GopherProtocol_open_request(Protocol
*prot
, IUri
*uri
, DWORD request_flags
,
36 HINTERNET internet_session
, IInternetBindInfo
*bind_info
)
38 GopherProtocol
*This
= impl_from_Protocol(prot
);
42 hres
= IUri_GetAbsoluteUri(uri
, &url
);
46 This
->base
.request
= InternetOpenUrlW(internet_session
, url
, NULL
, 0,
47 request_flags
, (DWORD_PTR
)&This
->base
);
49 if (!This
->base
.request
&& GetLastError() != ERROR_IO_PENDING
) {
50 WARN("InternetOpenUrl failed: %d\n", GetLastError());
51 return INET_E_RESOURCE_NOT_FOUND
;
57 static HRESULT
GopherProtocol_end_request(Protocol
*prot
)
62 static HRESULT
GopherProtocol_start_downloading(Protocol
*prot
)
67 static void GopherProtocol_close_connection(Protocol
*prot
)
71 static void GopherProtocol_on_error(Protocol
*prot
, DWORD error
)
73 FIXME("(%p) %d - stub\n", prot
, error
);
76 static const ProtocolVtbl AsyncProtocolVtbl
= {
77 GopherProtocol_open_request
,
78 GopherProtocol_end_request
,
79 GopherProtocol_start_downloading
,
80 GopherProtocol_close_connection
,
81 GopherProtocol_on_error
84 static inline GopherProtocol
*impl_from_IInternetProtocol(IInternetProtocol
*iface
)
86 return CONTAINING_RECORD(iface
, GopherProtocol
, IInternetProtocol_iface
);
89 static HRESULT WINAPI
GopherProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
91 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
94 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
95 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
96 *ppv
= &This
->IInternetProtocol_iface
;
97 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
98 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
99 *ppv
= &This
->IInternetProtocol_iface
;
100 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
101 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
102 *ppv
= &This
->IInternetProtocol_iface
;
103 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
104 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
105 *ppv
= &This
->IInternetPriority_iface
;
109 IInternetProtocol_AddRef(iface
);
113 WARN("not supported interface %s\n", debugstr_guid(riid
));
114 return E_NOINTERFACE
;
117 static ULONG WINAPI
GopherProtocol_AddRef(IInternetProtocol
*iface
)
119 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
120 LONG ref
= InterlockedIncrement(&This
->ref
);
121 TRACE("(%p) ref=%d\n", This
, ref
);
125 static ULONG WINAPI
GopherProtocol_Release(IInternetProtocol
*iface
)
127 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
128 LONG ref
= InterlockedDecrement(&This
->ref
);
130 TRACE("(%p) ref=%d\n", This
, ref
);
135 URLMON_UnlockModule();
141 static HRESULT WINAPI
GopherProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
142 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
143 DWORD grfPI
, HANDLE_PTR dwReserved
)
145 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
149 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
150 pOIBindInfo
, grfPI
, dwReserved
);
152 hres
= CreateUri(szUrl
, 0, 0, &uri
);
156 hres
= protocol_start(&This
->base
, &This
->IInternetProtocol_iface
, uri
, pOIProtSink
,
163 static HRESULT WINAPI
GopherProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
165 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
167 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
169 return protocol_continue(&This
->base
, pProtocolData
);
172 static HRESULT WINAPI
GopherProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
175 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
177 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
179 return protocol_abort(&This
->base
, hrReason
);
182 static HRESULT WINAPI
GopherProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
184 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
186 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
188 protocol_close_connection(&This
->base
);
192 static HRESULT WINAPI
GopherProtocol_Suspend(IInternetProtocol
*iface
)
194 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
195 FIXME("(%p)\n", This
);
199 static HRESULT WINAPI
GopherProtocol_Resume(IInternetProtocol
*iface
)
201 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
202 FIXME("(%p)\n", This
);
206 static HRESULT WINAPI
GopherProtocol_Read(IInternetProtocol
*iface
, void *pv
,
207 ULONG cb
, ULONG
*pcbRead
)
209 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
211 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
213 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
216 static HRESULT WINAPI
GopherProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
217 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
219 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
220 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
224 static HRESULT WINAPI
GopherProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
226 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
228 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
230 return protocol_lock_request(&This
->base
);
233 static HRESULT WINAPI
GopherProtocol_UnlockRequest(IInternetProtocol
*iface
)
235 GopherProtocol
*This
= impl_from_IInternetProtocol(iface
);
237 TRACE("(%p)\n", This
);
239 return protocol_unlock_request(&This
->base
);
242 static const IInternetProtocolVtbl GopherProtocolVtbl
= {
243 GopherProtocol_QueryInterface
,
244 GopherProtocol_AddRef
,
245 GopherProtocol_Release
,
246 GopherProtocol_Start
,
247 GopherProtocol_Continue
,
248 GopherProtocol_Abort
,
249 GopherProtocol_Terminate
,
250 GopherProtocol_Suspend
,
251 GopherProtocol_Resume
,
254 GopherProtocol_LockRequest
,
255 GopherProtocol_UnlockRequest
258 static inline GopherProtocol
*impl_from_IInternetPriority(IInternetPriority
*iface
)
260 return CONTAINING_RECORD(iface
, GopherProtocol
, IInternetPriority_iface
);
263 static HRESULT WINAPI
GopherPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
265 GopherProtocol
*This
= impl_from_IInternetPriority(iface
);
266 return IInternetProtocol_QueryInterface(&This
->IInternetProtocol_iface
, riid
, ppv
);
269 static ULONG WINAPI
GopherPriority_AddRef(IInternetPriority
*iface
)
271 GopherProtocol
*This
= impl_from_IInternetPriority(iface
);
272 return IInternetProtocol_AddRef(&This
->IInternetProtocol_iface
);
275 static ULONG WINAPI
GopherPriority_Release(IInternetPriority
*iface
)
277 GopherProtocol
*This
= impl_from_IInternetPriority(iface
);
278 return IInternetProtocol_Release(&This
->IInternetProtocol_iface
);
281 static HRESULT WINAPI
GopherPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
283 GopherProtocol
*This
= impl_from_IInternetPriority(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
= impl_from_IInternetPriority(iface
);
295 TRACE("(%p)->(%p)\n", This
, pnPriority
);
297 *pnPriority
= This
->base
.priority
;
301 static const IInternetPriorityVtbl GopherPriorityVtbl
= {
302 GopherPriority_QueryInterface
,
303 GopherPriority_AddRef
,
304 GopherPriority_Release
,
305 GopherPriority_SetPriority
,
306 GopherPriority_GetPriority
309 HRESULT
GopherProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
313 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
317 ret
= heap_alloc_zero(sizeof(GopherProtocol
));
319 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
320 ret
->IInternetProtocol_iface
.lpVtbl
= &GopherProtocolVtbl
;
321 ret
->IInternetPriority_iface
.lpVtbl
= &GopherPriorityVtbl
;
324 *ppobj
= &ret
->IInternetProtocol_iface
;