ReactOS 0.4.15-dev-8102-g108db8f
loadopts.c
Go to the documentation of this file.
1/*
2 * Copyright 2006 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 "mshtml_private.h"
20
21typedef struct load_opt {
25
26 struct load_opt *next;
28
29typedef struct {
31
33
36
38{
39 return CONTAINING_RECORD(iface, HTMLLoadOptions, IHtmlLoadOptions_iface);
40}
41
43 REFIID riid, void **ppv)
44{
46
47 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
48
50 *ppv = &This->IHtmlLoadOptions_iface;
51 }else if(IsEqualGUID(&IID_IOptionArray, riid)) {
52 *ppv = &This->IHtmlLoadOptions_iface;
53 }else if(IsEqualGUID(&IID_IHtmlLoadOptions, riid)) {
54 *ppv = &This->IHtmlLoadOptions_iface;
55 }else {
56 *ppv = NULL;
57 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
58 return E_NOINTERFACE;
59 }
60
61 IUnknown_AddRef((IUnknown*)*ppv);
62 return S_OK;
63}
64
66{
69
70 TRACE("(%p) ref=%d\n", This, ref);
71
72 return ref;
73}
74
76{
79
80 TRACE("(%p) ref=%d\n", This, ref);
81
82 if(!ref) {
83 load_opt *iter = This->opts, *last;
84
85 while(iter) {
86 last = iter;
87 iter = iter->next;
88
89 heap_free(last->buffer);
91 }
92
94 }
95
96 return ref;
97}
98
100 LPVOID pBuffer, ULONG *pcbBuf)
101{
103 load_opt *iter;
104
105 TRACE("(%p)->(%d %p %p)\n", This, dwOption, pBuffer, pcbBuf);
106
107 for(iter = This->opts; iter; iter = iter->next) {
108 if(iter->option == dwOption)
109 break;
110 }
111
112 if(!iter) {
113 *pcbBuf = 0;
114 return S_OK;
115 }
116
117 if(*pcbBuf < iter->size) {
118 *pcbBuf = iter->size;
119 return E_FAIL;
120 }
121
122 memcpy(pBuffer, iter->buffer, iter->size);
123 *pcbBuf = iter->size;
124
125 return S_OK;
126}
127
129 LPVOID pBuffer, ULONG cbBuf)
130{
132 load_opt *iter = NULL;
133
134 TRACE("(%p)->(%d %p %d)\n", This, dwOption, pBuffer, cbBuf);
135
136 for(iter = This->opts; iter; iter = iter->next) {
137 if(iter->option == dwOption)
138 break;
139 }
140
141 if(!iter) {
142 iter = heap_alloc(sizeof(load_opt));
143 iter->next = This->opts;
144 This->opts = iter;
145
146 iter->option = dwOption;
147 }else {
148 heap_free(iter->buffer);
149 }
150
151 if(!cbBuf) {
152 iter->buffer = NULL;
153 iter->size = 0;
154
155 return S_OK;
156 }
157
158 iter->size = cbBuf;
159 iter->buffer = heap_alloc(cbBuf);
160 memcpy(iter->buffer, pBuffer, iter->size);
161
162 return S_OK;
163}
164
165static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl = {
171};
172
174{
177
178 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_mshtml_guid(riid), ppv);
179
180 ret = heap_alloc(sizeof(HTMLLoadOptions));
181 if(!ret)
182 return E_OUTOFMEMORY;
183
184 ret->IHtmlLoadOptions_iface.lpVtbl = &HtmlLoadOptionsVtbl;
185 ret->ref = 1;
186 ret->opts = NULL;
187
188 hres = IHtmlLoadOptions_QueryInterface(&ret->IHtmlLoadOptions_iface, riid, ppv);
189 IHtmlLoadOptions_Release(&ret->IHtmlLoadOptions_iface);
190 return hres;
191}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
const GUID IID_IUnknown
#define WARN(fmt,...)
Definition: debug.h:115
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
const char * debugstr_mshtml_guid(const GUID *iid)
Definition: main.c:542
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
static ULONG WINAPI HtmlLoadOptions_Release(IHtmlLoadOptions *iface)
Definition: loadopts.c:75
HRESULT HTMLLoadOptions_Create(IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: loadopts.c:173
static HTMLLoadOptions * impl_from_IHtmlLoadOptions(IHtmlLoadOptions *iface)
Definition: loadopts.c:37
static ULONG WINAPI HtmlLoadOptions_AddRef(IHtmlLoadOptions *iface)
Definition: loadopts.c:65
static HRESULT WINAPI HtmlLoadOptions_SetOption(IHtmlLoadOptions *iface, DWORD dwOption, LPVOID pBuffer, ULONG cbBuf)
Definition: loadopts.c:128
static HRESULT WINAPI HtmlLoadOptions_QueryInterface(IHtmlLoadOptions *iface, REFIID riid, void **ppv)
Definition: loadopts.c:42
static HRESULT WINAPI HtmlLoadOptions_QueryOption(IHtmlLoadOptions *iface, DWORD dwOption, LPVOID pBuffer, ULONG *pcbBuf)
Definition: loadopts.c:99
static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl
Definition: loadopts.c:165
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static UINT UINT last
Definition: font.c:45
HRESULT hres
Definition: protocol.c:465
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
PVOID pBuffer
#define TRACE(s)
Definition: solgame.cpp:4
load_opt * opts
Definition: loadopts.c:34
IHtmlLoadOptions IHtmlLoadOptions_iface
Definition: loadopts.c:30
DWORD size
Definition: loadopts.c:24
DWORD option
Definition: loadopts.c:22
struct load_opt * next
Definition: loadopts.c:26
PVOID buffer
Definition: loadopts.c:23
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364