qcap: Implement a stubbed SmartTee filter.
[wine/multimedia.git] / dlls / mshtml / loadopts.c
blobe38be94374a3a1aa51643b21fe248a8a9fffcb02
1 /*
2 * Copyright 2006 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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "optary.h"
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 typedef struct load_opt {
39 DWORD option;
40 PVOID buffer;
41 DWORD size;
43 struct load_opt *next;
44 } load_opt;
46 typedef struct {
47 IHtmlLoadOptions IHtmlLoadOptions_iface;
49 LONG ref;
51 load_opt *opts;
52 } HTMLLoadOptions;
54 static inline HTMLLoadOptions *impl_from_IHtmlLoadOptions(IHtmlLoadOptions *iface)
56 return CONTAINING_RECORD(iface, HTMLLoadOptions, IHtmlLoadOptions_iface);
59 static HRESULT WINAPI HtmlLoadOptions_QueryInterface(IHtmlLoadOptions *iface,
60 REFIID riid, void **ppv)
62 HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
64 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
66 if(IsEqualGUID(&IID_IUnknown, riid)) {
67 *ppv = &This->IHtmlLoadOptions_iface;
68 }else if(IsEqualGUID(&IID_IOptionArray, riid)) {
69 *ppv = &This->IHtmlLoadOptions_iface;
70 }else if(IsEqualGUID(&IID_IHtmlLoadOptions, riid)) {
71 *ppv = &This->IHtmlLoadOptions_iface;
72 }else {
73 *ppv = NULL;
74 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
75 return E_NOINTERFACE;
78 IUnknown_AddRef((IUnknown*)*ppv);
79 return S_OK;
82 static ULONG WINAPI HtmlLoadOptions_AddRef(IHtmlLoadOptions *iface)
84 HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
85 LONG ref = InterlockedIncrement(&This->ref);
87 TRACE("(%p) ref=%d\n", This, ref);
89 return ref;
92 static ULONG WINAPI HtmlLoadOptions_Release(IHtmlLoadOptions *iface)
94 HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
95 LONG ref = InterlockedDecrement(&This->ref);
97 TRACE("(%p) ref=%d\n", This, ref);
99 if(!ref) {
100 load_opt *iter = This->opts, *last;
102 while(iter) {
103 last = iter;
104 iter = iter->next;
106 heap_free(last->buffer);
107 heap_free(last);
110 heap_free(This);
113 return ref;
116 static HRESULT WINAPI HtmlLoadOptions_QueryOption(IHtmlLoadOptions *iface, DWORD dwOption,
117 LPVOID pBuffer, ULONG *pcbBuf)
119 HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
120 load_opt *iter;
122 TRACE("(%p)->(%d %p %p)\n", This, dwOption, pBuffer, pcbBuf);
124 for(iter = This->opts; iter; iter = iter->next) {
125 if(iter->option == dwOption)
126 break;
129 if(!iter) {
130 *pcbBuf = 0;
131 return S_OK;
134 if(*pcbBuf < iter->size) {
135 *pcbBuf = iter->size;
136 return E_FAIL;
139 memcpy(pBuffer, iter->buffer, iter->size);
140 *pcbBuf = iter->size;
142 return S_OK;
145 static HRESULT WINAPI HtmlLoadOptions_SetOption(IHtmlLoadOptions *iface, DWORD dwOption,
146 LPVOID pBuffer, ULONG cbBuf)
148 HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
149 load_opt *iter = NULL;
151 TRACE("(%p)->(%d %p %d)\n", This, dwOption, pBuffer, cbBuf);
153 for(iter = This->opts; iter; iter = iter->next) {
154 if(iter->option == dwOption)
155 break;
158 if(!iter) {
159 iter = heap_alloc(sizeof(load_opt));
160 iter->next = This->opts;
161 This->opts = iter;
163 iter->option = dwOption;
164 }else {
165 heap_free(iter->buffer);
168 if(!cbBuf) {
169 iter->buffer = NULL;
170 iter->size = 0;
172 return S_OK;
175 iter->size = cbBuf;
176 iter->buffer = heap_alloc(cbBuf);
177 memcpy(iter->buffer, pBuffer, iter->size);
179 return S_OK;
182 static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl = {
183 HtmlLoadOptions_QueryInterface,
184 HtmlLoadOptions_AddRef,
185 HtmlLoadOptions_Release,
186 HtmlLoadOptions_QueryOption,
187 HtmlLoadOptions_SetOption
190 HRESULT HTMLLoadOptions_Create(IUnknown *pUnkOuter, REFIID riid, void** ppv)
192 HTMLLoadOptions *ret;
193 HRESULT hres;
195 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_mshtml_guid(riid), ppv);
197 ret = heap_alloc(sizeof(HTMLLoadOptions));
198 if(!ret)
199 return E_OUTOFMEMORY;
201 ret->IHtmlLoadOptions_iface.lpVtbl = &HtmlLoadOptionsVtbl;
202 ret->ref = 1;
203 ret->opts = NULL;
205 hres = IHtmlLoadOptions_QueryInterface(&ret->IHtmlLoadOptions_iface, riid, ppv);
206 IHtmlLoadOptions_Release(&ret->IHtmlLoadOptions_iface);
207 return hres;