wined3d: Properly check if input/output varyings are used.
[wine] / dlls / urlmon / gopher.c
1 /*
2  * Copyright 2009 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
23
24 typedef struct {
25     Protocol base;
26
27     const IInternetProtocolVtbl  *lpInternetProtocolVtbl;
28     const IInternetPriorityVtbl  *lpInternetPriorityVtbl;
29
30     LONG ref;
31 } GopherProtocol;
32
33 #define PROTOCOL(x)  ((IInternetProtocol*)  &(x)->lpInternetProtocolVtbl)
34 #define PRIORITY(x)  ((IInternetPriority*)  &(x)->lpInternetPriorityVtbl)
35
36 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(GopherProtocol, base, iface)
37
38 static HRESULT GopherProtocol_open_request(Protocol *prot, LPCWSTR url, DWORD request_flags,
39                                         IInternetBindInfo *bind_info)
40 {
41     GopherProtocol *This = ASYNCPROTOCOL_THIS(prot);
42
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;
48     }
49
50     return S_OK;
51 }
52
53 static HRESULT GopherProtocol_start_downloading(Protocol *prot)
54 {
55     return S_OK;
56 }
57
58 static void GopherProtocol_close_connection(Protocol *prot)
59 {
60 }
61
62 #undef ASYNCPROTOCOL_THIS
63
64 static const ProtocolVtbl AsyncProtocolVtbl = {
65     GopherProtocol_open_request,
66     GopherProtocol_start_downloading,
67     GopherProtocol_close_connection
68 };
69
70 #define PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, InternetProtocol, iface)
71
72 static HRESULT WINAPI GopherProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
73 {
74     GopherProtocol *This = PROTOCOL_THIS(iface);
75
76     *ppv = NULL;
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);
89     }
90
91     if(*ppv) {
92         IInternetProtocol_AddRef(iface);
93         return S_OK;
94     }
95
96     WARN("not supported interface %s\n", debugstr_guid(riid));
97     return E_NOINTERFACE;
98 }
99
100 static ULONG WINAPI GopherProtocol_AddRef(IInternetProtocol *iface)
101 {
102     GopherProtocol *This = PROTOCOL_THIS(iface);
103     LONG ref = InterlockedIncrement(&This->ref);
104     TRACE("(%p) ref=%d\n", This, ref);
105     return ref;
106 }
107
108 static ULONG WINAPI GopherProtocol_Release(IInternetProtocol *iface)
109 {
110     GopherProtocol *This = PROTOCOL_THIS(iface);
111     LONG ref = InterlockedDecrement(&This->ref);
112
113     TRACE("(%p) ref=%d\n", This, ref);
114
115     if(!ref) {
116         heap_free(This);
117
118         URLMON_UnlockModule();
119     }
120
121     return ref;
122 }
123
124 static HRESULT WINAPI GopherProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
125         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
126         DWORD grfPI, HANDLE_PTR dwReserved)
127 {
128     GopherProtocol *This = PROTOCOL_THIS(iface);
129
130     TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
131           pOIBindInfo, grfPI, dwReserved);
132
133     return protocol_start(&This->base, PROTOCOL(This), szUrl, pOIProtSink, pOIBindInfo);
134 }
135
136 static HRESULT WINAPI GopherProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
137 {
138     GopherProtocol *This = PROTOCOL_THIS(iface);
139
140     TRACE("(%p)->(%p)\n", This, pProtocolData);
141
142     return protocol_continue(&This->base, pProtocolData);
143 }
144
145 static HRESULT WINAPI GopherProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
146         DWORD dwOptions)
147 {
148     GopherProtocol *This = PROTOCOL_THIS(iface);
149     FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI GopherProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
154 {
155     GopherProtocol *This = PROTOCOL_THIS(iface);
156
157     TRACE("(%p)->(%08x)\n", This, dwOptions);
158
159     protocol_close_connection(&This->base);
160     return S_OK;
161 }
162
163 static HRESULT WINAPI GopherProtocol_Suspend(IInternetProtocol *iface)
164 {
165     GopherProtocol *This = PROTOCOL_THIS(iface);
166     FIXME("(%p)\n", This);
167     return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI GopherProtocol_Resume(IInternetProtocol *iface)
171 {
172     GopherProtocol *This = PROTOCOL_THIS(iface);
173     FIXME("(%p)\n", This);
174     return E_NOTIMPL;
175 }
176
177 static HRESULT WINAPI GopherProtocol_Read(IInternetProtocol *iface, void *pv,
178         ULONG cb, ULONG *pcbRead)
179 {
180     GopherProtocol *This = PROTOCOL_THIS(iface);
181
182     TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
183
184     return protocol_read(&This->base, pv, cb, pcbRead);
185 }
186
187 static HRESULT WINAPI GopherProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
188         DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
189 {
190     GopherProtocol *This = PROTOCOL_THIS(iface);
191     FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
192     return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI GopherProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
196 {
197     GopherProtocol *This = PROTOCOL_THIS(iface);
198
199     TRACE("(%p)->(%08x)\n", This, dwOptions);
200
201     return protocol_lock_request(&This->base);
202 }
203
204 static HRESULT WINAPI GopherProtocol_UnlockRequest(IInternetProtocol *iface)
205 {
206     GopherProtocol *This = PROTOCOL_THIS(iface);
207
208     TRACE("(%p)\n", This);
209
210     return protocol_unlock_request(&This->base);
211 }
212
213 #undef PROTOCOL_THIS
214
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,
225     GopherProtocol_Read,
226     GopherProtocol_Seek,
227     GopherProtocol_LockRequest,
228     GopherProtocol_UnlockRequest
229 };
230
231 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
232
233 static HRESULT WINAPI GopherPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
234 {
235     GopherProtocol *This = PRIORITY_THIS(iface);
236     return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
237 }
238
239 static ULONG WINAPI GopherPriority_AddRef(IInternetPriority *iface)
240 {
241     GopherProtocol *This = PRIORITY_THIS(iface);
242     return IInternetProtocol_AddRef(PROTOCOL(This));
243 }
244
245 static ULONG WINAPI GopherPriority_Release(IInternetPriority *iface)
246 {
247     GopherProtocol *This = PRIORITY_THIS(iface);
248     return IInternetProtocol_Release(PROTOCOL(This));
249 }
250
251 static HRESULT WINAPI GopherPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
252 {
253     GopherProtocol *This = PRIORITY_THIS(iface);
254
255     TRACE("(%p)->(%d)\n", This, nPriority);
256
257     This->base.priority = nPriority;
258     return S_OK;
259 }
260
261 static HRESULT WINAPI GopherPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
262 {
263     GopherProtocol *This = PRIORITY_THIS(iface);
264
265     TRACE("(%p)->(%p)\n", This, pnPriority);
266
267     *pnPriority = This->base.priority;
268     return S_OK;
269 }
270
271 #undef PRIORITY_THIS
272
273 static const IInternetPriorityVtbl GopherPriorityVtbl = {
274     GopherPriority_QueryInterface,
275     GopherPriority_AddRef,
276     GopherPriority_Release,
277     GopherPriority_SetPriority,
278     GopherPriority_GetPriority
279 };
280
281 HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
282 {
283     GopherProtocol *ret;
284
285     TRACE("(%p %p)\n", pUnkOuter, ppobj);
286
287     URLMON_LockModule();
288
289     ret = heap_alloc_zero(sizeof(GopherProtocol));
290
291     ret->base.vtbl = &AsyncProtocolVtbl;
292     ret->lpInternetProtocolVtbl = &GopherProtocolVtbl;
293     ret->lpInternetPriorityVtbl = &GopherPriorityVtbl;
294     ret->ref = 1;
295
296     *ppobj = PROTOCOL(ret);
297
298     return S_OK;
299 }