crypt32: NULL ptr could leak into function (Coverity).
[wine] / dlls / mshtml / htmlcomment.c
1 /*
2  * Copyright 2008 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
20 #include <stdarg.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28
29 #include "mshtml_private.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 struct HTMLCommentElement {
36     HTMLElement element;
37     const IHTMLCommentElementVtbl   *lpIHTMLCommentElementVtbl;
38 };
39
40 #define HTMLCOMMENT(x)  (&(x)->lpIHTMLCommentElementVtbl)
41
42 #define HTMLCOMMENT_THIS(iface) DEFINE_THIS(HTMLCommentElement, IHTMLCommentElement, iface)
43
44 static HRESULT WINAPI HTMLCommentElement_QueryInterface(IHTMLCommentElement *iface,
45         REFIID riid, void **ppv)
46 {
47     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
48
49     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
50 }
51
52 static ULONG WINAPI HTMLCommentElement_AddRef(IHTMLCommentElement *iface)
53 {
54     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
55
56     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
57 }
58
59 static ULONG WINAPI HTMLCommentElement_Release(IHTMLCommentElement *iface)
60 {
61     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
62
63     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
64 }
65
66 static HRESULT WINAPI HTMLCommentElement_GetTypeInfoCount(IHTMLCommentElement *iface, UINT *pctinfo)
67 {
68     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
69     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
70 }
71
72 static HRESULT WINAPI HTMLCommentElement_GetTypeInfo(IHTMLCommentElement *iface, UINT iTInfo,
73         LCID lcid, ITypeInfo **ppTInfo)
74 {
75     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
76     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
77             ppTInfo);
78 }
79
80 static HRESULT WINAPI HTMLCommentElement_GetIDsOfNames(IHTMLCommentElement *iface, REFIID riid,
81                                                 LPOLESTR *rgszNames, UINT cNames,
82                                                 LCID lcid, DISPID *rgDispId)
83 {
84     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
85     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
86             cNames, lcid, rgDispId);
87 }
88
89 static HRESULT WINAPI HTMLCommentElement_Invoke(IHTMLCommentElement *iface, DISPID dispIdMember,
90                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
91                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
92 {
93     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
94     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
95             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
96 }
97
98 static HRESULT WINAPI HTMLCommentElement_put_text(IHTMLCommentElement *iface, BSTR v)
99 {
100     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
101     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
102     return E_NOTIMPL;
103 }
104
105 static HRESULT WINAPI HTMLCommentElement_get_text(IHTMLCommentElement *iface, BSTR *p)
106 {
107     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
108
109     TRACE("(%p)->(%p)\n", This, p);
110
111     return IHTMLElement_get_outerHTML(&This->element.IHTMLElement_iface, p);
112 }
113
114 static HRESULT WINAPI HTMLCommentElement_put_atomic(IHTMLCommentElement *iface, LONG v)
115 {
116     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
117     FIXME("(%p)->(%d)\n", This, v);
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI HTMLCommentElement_get_atomic(IHTMLCommentElement *iface, LONG *p)
122 {
123     HTMLCommentElement *This = HTMLCOMMENT_THIS(iface);
124     FIXME("(%p)->(%p)\n", This, p);
125     return E_NOTIMPL;
126 }
127
128 #undef HTMLCOMMENT_THIS
129
130 static const IHTMLCommentElementVtbl HTMLCommentElementVtbl = {
131     HTMLCommentElement_QueryInterface,
132     HTMLCommentElement_AddRef,
133     HTMLCommentElement_Release,
134     HTMLCommentElement_GetTypeInfoCount,
135     HTMLCommentElement_GetTypeInfo,
136     HTMLCommentElement_GetIDsOfNames,
137     HTMLCommentElement_Invoke,
138     HTMLCommentElement_put_text,
139     HTMLCommentElement_get_text,
140     HTMLCommentElement_put_atomic,
141     HTMLCommentElement_get_atomic
142 };
143
144 static inline HTMLCommentElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
145 {
146     return CONTAINING_RECORD(iface, HTMLCommentElement, element.node);
147 }
148
149 static HRESULT HTMLCommentElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
150 {
151     HTMLCommentElement *This = impl_from_HTMLDOMNode(iface);
152
153     *ppv =  NULL;
154
155     if(IsEqualGUID(&IID_IHTMLCommentElement, riid)) {
156         TRACE("(%p)->(IID_IHTMLCommentElement %p)\n", This, ppv);
157         *ppv = HTMLCOMMENT(This);
158     }else {
159         return HTMLElement_QI(&This->element.node, riid, ppv);
160     }
161
162     IUnknown_AddRef((IUnknown*)*ppv);
163     return S_OK;
164 }
165
166 static void HTMLCommentElement_destructor(HTMLDOMNode *iface)
167 {
168     HTMLCommentElement *This = impl_from_HTMLDOMNode(iface);
169
170     HTMLElement_destructor(&This->element.node);
171 }
172
173 static const NodeImplVtbl HTMLCommentElementImplVtbl = {
174     HTMLCommentElement_QI,
175     HTMLCommentElement_destructor,
176     HTMLElement_clone
177 };
178
179 static const tid_t HTMLCommentElement_iface_tids[] = {
180     HTMLELEMENT_TIDS,
181     IHTMLCommentElement_tid,
182     0
183 };
184 static dispex_static_data_t HTMLCommentElement_dispex = {
185     NULL,
186     DispHTMLCommentElement_tid,
187     NULL,
188     HTMLCommentElement_iface_tids
189 };
190
191 HRESULT HTMLCommentElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLElement **elem)
192 {
193     HTMLCommentElement *ret;
194
195     ret = heap_alloc_zero(sizeof(*ret));
196     if(!ret)
197         return E_OUTOFMEMORY;
198
199     ret->element.node.vtbl = &HTMLCommentElementImplVtbl;
200     ret->lpIHTMLCommentElementVtbl = &HTMLCommentElementVtbl;
201
202     HTMLElement_Init(&ret->element, doc, NULL, &HTMLCommentElement_dispex);
203
204     nsIDOMNode_AddRef(nsnode);
205     ret->element.node.nsnode = nsnode;
206
207     *elem = &ret->element;
208     return S_OK;
209 }