d3dxof: Do not expect a separator when there is no element.
[wine/multimedia.git] / dlls / urlmon / gopher.c
blob18e397285df5786b3dd5382f0b3b8d1bb5d160ca
1 /*
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);
24 typedef struct {
25 Protocol base;
27 const IInternetProtocolVtbl *lpIInternetProtocolVtbl;
28 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
30 LONG ref;
31 } GopherProtocol;
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, LPCWSTR url, DWORD request_flags,
38 HINTERNET internet_session, IInternetBindInfo *bind_info)
40 GopherProtocol *This = ASYNCPROTOCOL_THIS(prot);
42 This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0,
43 request_flags, (DWORD_PTR)&This->base);
44 if (!This->base.request && GetLastError() != ERROR_IO_PENDING) {
45 WARN("InternetOpenUrl failed: %d\n", GetLastError());
46 return INET_E_RESOURCE_NOT_FOUND;
49 return S_OK;
52 static HRESULT GopherProtocol_start_downloading(Protocol *prot)
54 return S_OK;
57 static void GopherProtocol_close_connection(Protocol *prot)
61 #undef ASYNCPROTOCOL_THIS
63 static const ProtocolVtbl AsyncProtocolVtbl = {
64 GopherProtocol_open_request,
65 GopherProtocol_start_downloading,
66 GopherProtocol_close_connection
69 #define PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, IInternetProtocol, iface)
71 static HRESULT WINAPI GopherProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
73 GopherProtocol *This = PROTOCOL_THIS(iface);
75 *ppv = NULL;
76 if(IsEqualGUID(&IID_IUnknown, riid)) {
77 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
78 *ppv = PROTOCOL(This);
79 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
80 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
81 *ppv = PROTOCOL(This);
82 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
83 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
84 *ppv = PROTOCOL(This);
85 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
86 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
87 *ppv = PRIORITY(This);
90 if(*ppv) {
91 IInternetProtocol_AddRef(iface);
92 return S_OK;
95 WARN("not supported interface %s\n", debugstr_guid(riid));
96 return E_NOINTERFACE;
99 static ULONG WINAPI GopherProtocol_AddRef(IInternetProtocol *iface)
101 GopherProtocol *This = PROTOCOL_THIS(iface);
102 LONG ref = InterlockedIncrement(&This->ref);
103 TRACE("(%p) ref=%d\n", This, ref);
104 return ref;
107 static ULONG WINAPI GopherProtocol_Release(IInternetProtocol *iface)
109 GopherProtocol *This = PROTOCOL_THIS(iface);
110 LONG ref = InterlockedDecrement(&This->ref);
112 TRACE("(%p) ref=%d\n", This, ref);
114 if(!ref) {
115 heap_free(This);
117 URLMON_UnlockModule();
120 return ref;
123 static HRESULT WINAPI GopherProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
124 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
125 DWORD grfPI, HANDLE_PTR dwReserved)
127 GopherProtocol *This = PROTOCOL_THIS(iface);
129 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
130 pOIBindInfo, grfPI, dwReserved);
132 return protocol_start(&This->base, PROTOCOL(This), szUrl, pOIProtSink, pOIBindInfo);
135 static HRESULT WINAPI GopherProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
137 GopherProtocol *This = PROTOCOL_THIS(iface);
139 TRACE("(%p)->(%p)\n", This, pProtocolData);
141 return protocol_continue(&This->base, pProtocolData);
144 static HRESULT WINAPI GopherProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
145 DWORD dwOptions)
147 GopherProtocol *This = PROTOCOL_THIS(iface);
148 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
149 return E_NOTIMPL;
152 static HRESULT WINAPI GopherProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
154 GopherProtocol *This = PROTOCOL_THIS(iface);
156 TRACE("(%p)->(%08x)\n", This, dwOptions);
158 protocol_close_connection(&This->base);
159 return S_OK;
162 static HRESULT WINAPI GopherProtocol_Suspend(IInternetProtocol *iface)
164 GopherProtocol *This = PROTOCOL_THIS(iface);
165 FIXME("(%p)\n", This);
166 return E_NOTIMPL;
169 static HRESULT WINAPI GopherProtocol_Resume(IInternetProtocol *iface)
171 GopherProtocol *This = PROTOCOL_THIS(iface);
172 FIXME("(%p)\n", This);
173 return E_NOTIMPL;
176 static HRESULT WINAPI GopherProtocol_Read(IInternetProtocol *iface, void *pv,
177 ULONG cb, ULONG *pcbRead)
179 GopherProtocol *This = PROTOCOL_THIS(iface);
181 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
183 return protocol_read(&This->base, pv, cb, pcbRead);
186 static HRESULT WINAPI GopherProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
187 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
189 GopherProtocol *This = PROTOCOL_THIS(iface);
190 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
191 return E_NOTIMPL;
194 static HRESULT WINAPI GopherProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
196 GopherProtocol *This = PROTOCOL_THIS(iface);
198 TRACE("(%p)->(%08x)\n", This, dwOptions);
200 return protocol_lock_request(&This->base);
203 static HRESULT WINAPI GopherProtocol_UnlockRequest(IInternetProtocol *iface)
205 GopherProtocol *This = PROTOCOL_THIS(iface);
207 TRACE("(%p)\n", This);
209 return protocol_unlock_request(&This->base);
212 #undef PROTOCOL_THIS
214 static const IInternetProtocolVtbl GopherProtocolVtbl = {
215 GopherProtocol_QueryInterface,
216 GopherProtocol_AddRef,
217 GopherProtocol_Release,
218 GopherProtocol_Start,
219 GopherProtocol_Continue,
220 GopherProtocol_Abort,
221 GopherProtocol_Terminate,
222 GopherProtocol_Suspend,
223 GopherProtocol_Resume,
224 GopherProtocol_Read,
225 GopherProtocol_Seek,
226 GopherProtocol_LockRequest,
227 GopherProtocol_UnlockRequest
230 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
232 static HRESULT WINAPI GopherPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
234 GopherProtocol *This = PRIORITY_THIS(iface);
235 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
238 static ULONG WINAPI GopherPriority_AddRef(IInternetPriority *iface)
240 GopherProtocol *This = PRIORITY_THIS(iface);
241 return IInternetProtocol_AddRef(PROTOCOL(This));
244 static ULONG WINAPI GopherPriority_Release(IInternetPriority *iface)
246 GopherProtocol *This = PRIORITY_THIS(iface);
247 return IInternetProtocol_Release(PROTOCOL(This));
250 static HRESULT WINAPI GopherPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
252 GopherProtocol *This = PRIORITY_THIS(iface);
254 TRACE("(%p)->(%d)\n", This, nPriority);
256 This->base.priority = nPriority;
257 return S_OK;
260 static HRESULT WINAPI GopherPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
262 GopherProtocol *This = PRIORITY_THIS(iface);
264 TRACE("(%p)->(%p)\n", This, pnPriority);
266 *pnPriority = This->base.priority;
267 return S_OK;
270 #undef PRIORITY_THIS
272 static const IInternetPriorityVtbl GopherPriorityVtbl = {
273 GopherPriority_QueryInterface,
274 GopherPriority_AddRef,
275 GopherPriority_Release,
276 GopherPriority_SetPriority,
277 GopherPriority_GetPriority
280 HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
282 GopherProtocol *ret;
284 TRACE("(%p %p)\n", pUnkOuter, ppobj);
286 URLMON_LockModule();
288 ret = heap_alloc_zero(sizeof(GopherProtocol));
290 ret->base.vtbl = &AsyncProtocolVtbl;
291 ret->lpIInternetProtocolVtbl = &GopherProtocolVtbl;
292 ret->lpInternetPriorityVtbl = &GopherPriorityVtbl;
293 ret->ref = 1;
295 *ppobj = PROTOCOL(ret);
297 return S_OK;