urlmon: Added IInternetPriority implementation for gopher protocol.
[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 PROTOCOL_THIS(iface) DEFINE_THIS(GopherProtocol, InternetProtocol, iface)
37
38 static HRESULT WINAPI GopherProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
39 {
40     GopherProtocol *This = PROTOCOL_THIS(iface);
41
42     *ppv = NULL;
43     if(IsEqualGUID(&IID_IUnknown, riid)) {
44         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
45         *ppv = PROTOCOL(This);
46     }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
47         TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
48         *ppv = PROTOCOL(This);
49     }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
50         TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
51         *ppv = PROTOCOL(This);
52     }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
53         TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
54         *ppv = PRIORITY(This);
55     }
56
57     if(*ppv) {
58         IInternetProtocol_AddRef(iface);
59         return S_OK;
60     }
61
62     WARN("not supported interface %s\n", debugstr_guid(riid));
63     return E_NOINTERFACE;
64 }
65
66 static ULONG WINAPI GopherProtocol_AddRef(IInternetProtocol *iface)
67 {
68     GopherProtocol *This = PROTOCOL_THIS(iface);
69     LONG ref = InterlockedIncrement(&This->ref);
70     TRACE("(%p) ref=%d\n", This, ref);
71     return ref;
72 }
73
74 static ULONG WINAPI GopherProtocol_Release(IInternetProtocol *iface)
75 {
76     GopherProtocol *This = PROTOCOL_THIS(iface);
77     LONG ref = InterlockedDecrement(&This->ref);
78
79     TRACE("(%p) ref=%d\n", This, ref);
80
81     if(!ref) {
82         heap_free(This);
83
84         URLMON_UnlockModule();
85     }
86
87     return ref;
88 }
89
90 static HRESULT WINAPI GopherProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
91         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
92         DWORD grfPI, DWORD dwReserved)
93 {
94     GopherProtocol *This = PROTOCOL_THIS(iface);
95     FIXME("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
96           pOIBindInfo, grfPI, dwReserved);
97     return E_NOTIMPL;
98 }
99
100 static HRESULT WINAPI GopherProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
101 {
102     GopherProtocol *This = PROTOCOL_THIS(iface);
103     FIXME("(%p)->(%p)\n", This, pProtocolData);
104     return E_NOTIMPL;
105 }
106
107 static HRESULT WINAPI GopherProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
108         DWORD dwOptions)
109 {
110     GopherProtocol *This = PROTOCOL_THIS(iface);
111     FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
112     return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI GopherProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
116 {
117     GopherProtocol *This = PROTOCOL_THIS(iface);
118     FIXME("(%p)->(%08x)\n", This, dwOptions);
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI GopherProtocol_Suspend(IInternetProtocol *iface)
123 {
124     GopherProtocol *This = PROTOCOL_THIS(iface);
125     FIXME("(%p)\n", This);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI GopherProtocol_Resume(IInternetProtocol *iface)
130 {
131     GopherProtocol *This = PROTOCOL_THIS(iface);
132     FIXME("(%p)\n", This);
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI GopherProtocol_Read(IInternetProtocol *iface, void *pv,
137         ULONG cb, ULONG *pcbRead)
138 {
139     GopherProtocol *This = PROTOCOL_THIS(iface);
140     FIXME("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
141     return E_NOTIMPL;
142 }
143
144 static HRESULT WINAPI GopherProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
145         DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
146 {
147     GopherProtocol *This = PROTOCOL_THIS(iface);
148     FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
149     return E_NOTIMPL;
150 }
151
152 static HRESULT WINAPI GopherProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
153 {
154     GopherProtocol *This = PROTOCOL_THIS(iface);
155     FIXME("(%p)->(%08x)\n", This, dwOptions);
156     return E_NOTIMPL;
157 }
158
159 static HRESULT WINAPI GopherProtocol_UnlockRequest(IInternetProtocol *iface)
160 {
161     GopherProtocol *This = PROTOCOL_THIS(iface);
162     FIXME("(%p)\n", This);
163     return E_NOTIMPL;
164 }
165
166 #undef PROTOCOL_THIS
167
168 static const IInternetProtocolVtbl GopherProtocolVtbl = {
169     GopherProtocol_QueryInterface,
170     GopherProtocol_AddRef,
171     GopherProtocol_Release,
172     GopherProtocol_Start,
173     GopherProtocol_Continue,
174     GopherProtocol_Abort,
175     GopherProtocol_Terminate,
176     GopherProtocol_Suspend,
177     GopherProtocol_Resume,
178     GopherProtocol_Read,
179     GopherProtocol_Seek,
180     GopherProtocol_LockRequest,
181     GopherProtocol_UnlockRequest
182 };
183
184 #define PRIORITY_THIS(iface) DEFINE_THIS(GopherProtocol, InternetPriority, iface)
185
186 static HRESULT WINAPI GopherPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
187 {
188     GopherProtocol *This = PRIORITY_THIS(iface);
189     return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
190 }
191
192 static ULONG WINAPI GopherPriority_AddRef(IInternetPriority *iface)
193 {
194     GopherProtocol *This = PRIORITY_THIS(iface);
195     return IInternetProtocol_AddRef(PROTOCOL(This));
196 }
197
198 static ULONG WINAPI GopherPriority_Release(IInternetPriority *iface)
199 {
200     GopherProtocol *This = PRIORITY_THIS(iface);
201     return IInternetProtocol_Release(PROTOCOL(This));
202 }
203
204 static HRESULT WINAPI GopherPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
205 {
206     GopherProtocol *This = PRIORITY_THIS(iface);
207
208     TRACE("(%p)->(%d)\n", This, nPriority);
209
210     This->base.priority = nPriority;
211     return S_OK;
212 }
213
214 static HRESULT WINAPI GopherPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
215 {
216     GopherProtocol *This = PRIORITY_THIS(iface);
217
218     TRACE("(%p)->(%p)\n", This, pnPriority);
219
220     *pnPriority = This->base.priority;
221     return S_OK;
222 }
223
224 #undef PRIORITY_THIS
225
226 static const IInternetPriorityVtbl GopherPriorityVtbl = {
227     GopherPriority_QueryInterface,
228     GopherPriority_AddRef,
229     GopherPriority_Release,
230     GopherPriority_SetPriority,
231     GopherPriority_GetPriority
232 };
233
234 HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
235 {
236     GopherProtocol *ret;
237
238     TRACE("(%p %p)\n", pUnkOuter, ppobj);
239
240     URLMON_LockModule();
241
242     ret = heap_alloc_zero(sizeof(GopherProtocol));
243
244     ret->lpInternetProtocolVtbl = &GopherProtocolVtbl;
245     ret->lpInternetPriorityVtbl = &GopherPriorityVtbl;
246     ret->ref = 1;
247
248     *ppobj = PROTOCOL(ret);
249
250     return S_OK;
251 }