wined3d: Support the full amount of constants in GLSL.
[wine/hacks.git] / dlls / urlmon / mk.c
blob934eeda8ef709e020351ba5d6247832d0652a0bb
1 /*
2 * Copyright 2007 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 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
27 LONG ref;
29 IStream *stream;
30 } MkProtocol;
32 #define PROTOCOL_THIS(iface) DEFINE_THIS(MkProtocol, InternetProtocol, iface)
34 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
36 static HRESULT WINAPI MkProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
38 MkProtocol *This = PROTOCOL_THIS(iface);
40 *ppv = NULL;
41 if(IsEqualGUID(&IID_IUnknown, riid)) {
42 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
43 *ppv = PROTOCOL(This);
44 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
45 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
46 *ppv = PROTOCOL(This);
47 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
48 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
49 *ppv = PROTOCOL(This);
52 if(*ppv) {
53 IInternetProtocol_AddRef(iface);
54 return S_OK;
57 WARN("not supported interface %s\n", debugstr_guid(riid));
58 return E_NOINTERFACE;
61 static ULONG WINAPI MkProtocol_AddRef(IInternetProtocol *iface)
63 MkProtocol *This = PROTOCOL_THIS(iface);
64 LONG ref = InterlockedIncrement(&This->ref);
65 TRACE("(%p) ref=%d\n", This, ref);
66 return ref;
69 static ULONG WINAPI MkProtocol_Release(IInternetProtocol *iface)
71 MkProtocol *This = PROTOCOL_THIS(iface);
72 LONG ref = InterlockedDecrement(&This->ref);
74 TRACE("(%p) ref=%d\n", This, ref);
76 if(!ref) {
77 if(This->stream)
78 IStream_Release(This->stream);
80 heap_free(This);
82 URLMON_UnlockModule();
85 return ref;
88 static HRESULT report_result(IInternetProtocolSink *sink, HRESULT hres, DWORD dwError)
90 IInternetProtocolSink_ReportResult(sink, hres, dwError, NULL);
91 return hres;
94 static HRESULT WINAPI MkProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
95 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
96 DWORD grfPI, HANDLE_PTR dwReserved)
98 MkProtocol *This = PROTOCOL_THIS(iface);
99 IParseDisplayName *pdn;
100 IMoniker *mon;
101 LPWSTR mime, progid, display_name;
102 LPCWSTR ptr, ptr2;
103 BINDINFO bindinfo;
104 STATSTG statstg;
105 DWORD bindf=0, eaten=0, len;
106 CLSID clsid;
107 HRESULT hres;
109 static const WCHAR wszMK[] = {'m','k',':','@'};
111 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
112 pOIBindInfo, grfPI, dwReserved);
114 if(strncmpiW(szUrl, wszMK, sizeof(wszMK)/sizeof(WCHAR)))
115 return INET_E_INVALID_URL;
117 memset(&bindinfo, 0, sizeof(bindinfo));
118 bindinfo.cbSize = sizeof(BINDINFO);
119 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
120 if(FAILED(hres)) {
121 WARN("GetBindInfo failed: %08x\n", hres);
122 return hres;
125 ReleaseBindInfo(&bindinfo);
127 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, NULL);
129 hres = FindMimeFromData(NULL, szUrl, NULL, 0, NULL, 0, &mime, 0);
130 if(SUCCEEDED(hres)) {
131 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
132 CoTaskMemFree(mime);
135 ptr2 = szUrl + sizeof(wszMK)/sizeof(WCHAR);
136 ptr = strchrW(ptr2, ':');
137 if(!ptr)
138 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
140 progid = heap_alloc((ptr-ptr2+1)*sizeof(WCHAR));
141 memcpy(progid, ptr2, (ptr-ptr2)*sizeof(WCHAR));
142 progid[ptr-ptr2] = 0;
143 hres = CLSIDFromProgID(progid, &clsid);
144 heap_free(progid);
145 if(FAILED(hres))
146 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
148 hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
149 &IID_IParseDisplayName, (void**)&pdn);
150 if(FAILED(hres)) {
151 WARN("Could not create object %s\n", debugstr_guid(&clsid));
152 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
155 len = strlenW(--ptr2);
156 display_name = heap_alloc((len+1)*sizeof(WCHAR));
157 memcpy(display_name, ptr2, (len+1)*sizeof(WCHAR));
158 hres = IParseDisplayName_ParseDisplayName(pdn, NULL /* FIXME */, display_name, &eaten, &mon);
159 heap_free(display_name);
160 IParseDisplayName_Release(pdn);
161 if(FAILED(hres)) {
162 WARN("ParseDisplayName failed: %08x\n", hres);
163 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
166 if(This->stream) {
167 IStream_Release(This->stream);
168 This->stream = NULL;
171 hres = IMoniker_BindToStorage(mon, NULL /* FIXME */, NULL, &IID_IStream, (void**)&This->stream);
172 IMoniker_Release(mon);
173 if(FAILED(hres)) {
174 WARN("BindToStorage failed: %08x\n", hres);
175 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
178 hres = IStream_Stat(This->stream, &statstg, STATFLAG_NONAME);
179 if(FAILED(hres)) {
180 WARN("Stat failed: %08x\n", hres);
181 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
184 IInternetProtocolSink_ReportData(pOIProtSink,
185 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION,
186 statstg.cbSize.u.LowPart, statstg.cbSize.u.LowPart);
188 return report_result(pOIProtSink, S_OK, ERROR_SUCCESS);
191 static HRESULT WINAPI MkProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
193 MkProtocol *This = PROTOCOL_THIS(iface);
194 FIXME("(%p)->(%p)\n", This, pProtocolData);
195 return E_NOTIMPL;
198 static HRESULT WINAPI MkProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
199 DWORD dwOptions)
201 MkProtocol *This = PROTOCOL_THIS(iface);
202 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
203 return E_NOTIMPL;
206 static HRESULT WINAPI MkProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
208 MkProtocol *This = PROTOCOL_THIS(iface);
210 TRACE("(%p)->(%08x)\n", This, dwOptions);
212 return S_OK;
215 static HRESULT WINAPI MkProtocol_Suspend(IInternetProtocol *iface)
217 MkProtocol *This = PROTOCOL_THIS(iface);
218 FIXME("(%p)\n", This);
219 return E_NOTIMPL;
222 static HRESULT WINAPI MkProtocol_Resume(IInternetProtocol *iface)
224 MkProtocol *This = PROTOCOL_THIS(iface);
225 FIXME("(%p)\n", This);
226 return E_NOTIMPL;
229 static HRESULT WINAPI MkProtocol_Read(IInternetProtocol *iface, void *pv,
230 ULONG cb, ULONG *pcbRead)
232 MkProtocol *This = PROTOCOL_THIS(iface);
234 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
236 if(!This->stream)
237 return E_FAIL;
239 return IStream_Read(This->stream, pv, cb, pcbRead);
242 static HRESULT WINAPI MkProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
243 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
245 MkProtocol *This = PROTOCOL_THIS(iface);
246 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
247 return E_NOTIMPL;
250 static HRESULT WINAPI MkProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
252 MkProtocol *This = PROTOCOL_THIS(iface);
254 TRACE("(%p)->(%08x)\n", This, dwOptions);
256 return S_OK;
259 static HRESULT WINAPI MkProtocol_UnlockRequest(IInternetProtocol *iface)
261 MkProtocol *This = PROTOCOL_THIS(iface);
263 TRACE("(%p)\n", This);
265 return S_OK;
268 #undef PROTOCOL_THIS
270 static const IInternetProtocolVtbl MkProtocolVtbl = {
271 MkProtocol_QueryInterface,
272 MkProtocol_AddRef,
273 MkProtocol_Release,
274 MkProtocol_Start,
275 MkProtocol_Continue,
276 MkProtocol_Abort,
277 MkProtocol_Terminate,
278 MkProtocol_Suspend,
279 MkProtocol_Resume,
280 MkProtocol_Read,
281 MkProtocol_Seek,
282 MkProtocol_LockRequest,
283 MkProtocol_UnlockRequest
286 HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
288 MkProtocol *ret;
290 TRACE("(%p %p)\n", pUnkOuter, ppobj);
292 URLMON_LockModule();
294 ret = heap_alloc(sizeof(MkProtocol));
296 ret->lpInternetProtocolVtbl = &MkProtocolVtbl;
297 ret->ref = 1;
298 ret->stream = NULL;
300 /* NOTE:
301 * Native returns NULL ppobj and S_OK in CreateInstance if called with IID_IUnknown riid.
303 *ppobj = PROTOCOL(ret);
305 return S_OK;