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_end_request(Protocol
*prot
)
64 static HRESULT
GopherProtocol_start_downloading(Protocol
*prot
)
69 static void GopherProtocol_close_connection(Protocol
*prot
)
73 #undef ASYNCPROTOCOL_THIS
75 static const ProtocolVtbl AsyncProtocolVtbl
= {
76 GopherProtocol_open_request
,
77 GopherProtocol_end_request
,
78 GopherProtocol_start_downloading
,
79 GopherProtocol_close_connection
82 #define PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, IInternetProtocol, iface)
84 static HRESULT WINAPI
GopherProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
86 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
89 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
90 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
91 *ppv
= PROTOCOL(This
);
92 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
93 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
94 *ppv
= PROTOCOL(This
);
95 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
96 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
97 *ppv
= PROTOCOL(This
);
98 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
99 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
100 *ppv
= PRIORITY(This
);
104 IInternetProtocol_AddRef(iface
);
108 WARN("not supported interface %s\n", debugstr_guid(riid
));
109 return E_NOINTERFACE
;
112 static ULONG WINAPI
GopherProtocol_AddRef(IInternetProtocol
*iface
)
114 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
115 LONG ref
= InterlockedIncrement(&This
->ref
);
116 TRACE("(%p) ref=%d\n", This
, ref
);
120 static ULONG WINAPI
GopherProtocol_Release(IInternetProtocol
*iface
)
122 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
123 LONG ref
= InterlockedDecrement(&This
->ref
);
125 TRACE("(%p) ref=%d\n", This
, ref
);
130 URLMON_UnlockModule();
136 static HRESULT WINAPI
GopherProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
137 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
138 DWORD grfPI
, HANDLE_PTR dwReserved
)
140 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
144 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
145 pOIBindInfo
, grfPI
, dwReserved
);
147 hres
= CreateUri(szUrl
, 0, 0, &uri
);
151 hres
= protocol_start(&This
->base
, PROTOCOL(This
), uri
, pOIProtSink
, pOIBindInfo
);
157 static HRESULT WINAPI
GopherProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
159 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
161 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
163 return protocol_continue(&This
->base
, pProtocolData
);
166 static HRESULT WINAPI
GopherProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
169 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
171 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
173 return protocol_abort(&This
->base
, hrReason
);
176 static HRESULT WINAPI
GopherProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
178 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
180 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
182 protocol_close_connection(&This
->base
);
186 static HRESULT WINAPI
GopherProtocol_Suspend(IInternetProtocol
*iface
)
188 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
189 FIXME("(%p)\n", This
);
193 static HRESULT WINAPI
GopherProtocol_Resume(IInternetProtocol
*iface
)
195 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
196 FIXME("(%p)\n", This
);
200 static HRESULT WINAPI
GopherProtocol_Read(IInternetProtocol
*iface
, void *pv
,
201 ULONG cb
, ULONG
*pcbRead
)
203 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
205 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
207 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
210 static HRESULT WINAPI
GopherProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
211 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
213 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
214 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
218 static HRESULT WINAPI
GopherProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
220 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
222 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
224 return protocol_lock_request(&This
->base
);
227 static HRESULT WINAPI
GopherProtocol_UnlockRequest(IInternetProtocol
*iface
)
229 GopherProtocol
*This
= PROTOCOL_THIS(iface
);
231 TRACE("(%p)\n", This
);
233 return protocol_unlock_request(&This
->base
);
238 static const IInternetProtocolVtbl GopherProtocolVtbl
= {
239 GopherProtocol_QueryInterface
,
240 GopherProtocol_AddRef
,
241 GopherProtocol_Release
,
242 GopherProtocol_Start
,
243 GopherProtocol_Continue
,
244 GopherProtocol_Abort
,
245 GopherProtocol_Terminate
,
246 GopherProtocol_Suspend
,
247 GopherProtocol_Resume
,
250 GopherProtocol_LockRequest
,
251 GopherProtocol_UnlockRequest
254 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
256 static HRESULT WINAPI
GopherPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
258 GopherProtocol
*This
= PRIORITY_THIS(iface
);
259 return IInternetProtocol_QueryInterface(PROTOCOL(This
), riid
, ppv
);
262 static ULONG WINAPI
GopherPriority_AddRef(IInternetPriority
*iface
)
264 GopherProtocol
*This
= PRIORITY_THIS(iface
);
265 return IInternetProtocol_AddRef(PROTOCOL(This
));
268 static ULONG WINAPI
GopherPriority_Release(IInternetPriority
*iface
)
270 GopherProtocol
*This
= PRIORITY_THIS(iface
);
271 return IInternetProtocol_Release(PROTOCOL(This
));
274 static HRESULT WINAPI
GopherPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
276 GopherProtocol
*This
= PRIORITY_THIS(iface
);
278 TRACE("(%p)->(%d)\n", This
, nPriority
);
280 This
->base
.priority
= nPriority
;
284 static HRESULT WINAPI
GopherPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
286 GopherProtocol
*This
= PRIORITY_THIS(iface
);
288 TRACE("(%p)->(%p)\n", This
, pnPriority
);
290 *pnPriority
= This
->base
.priority
;
296 static const IInternetPriorityVtbl GopherPriorityVtbl
= {
297 GopherPriority_QueryInterface
,
298 GopherPriority_AddRef
,
299 GopherPriority_Release
,
300 GopherPriority_SetPriority
,
301 GopherPriority_GetPriority
304 HRESULT
GopherProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
308 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
312 ret
= heap_alloc_zero(sizeof(GopherProtocol
));
314 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
315 ret
->lpIInternetProtocolVtbl
= &GopherProtocolVtbl
;
316 ret
->lpInternetPriorityVtbl
= &GopherPriorityVtbl
;
319 *ppobj
= PROTOCOL(ret
);