1c2c66affSColin Finck /*
2c2c66affSColin Finck * Copyright 2011 Jacek Caban for CodeWeavers
3c2c66affSColin Finck *
4c2c66affSColin Finck * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck * License as published by the Free Software Foundation; either
7c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck *
9c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c2c66affSColin Finck * Lesser General Public License for more details.
13c2c66affSColin Finck *
14c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck */
18c2c66affSColin Finck
19c2c66affSColin Finck
209f8faabaSAmine Khaldi #include <assert.h>
219f8faabaSAmine Khaldi
229f8faabaSAmine Khaldi #include "vbscript.h"
239f8faabaSAmine Khaldi #include "objsafe.h"
249f8faabaSAmine Khaldi
259f8faabaSAmine Khaldi #include "wine/debug.h"
269f8faabaSAmine Khaldi
279f8faabaSAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
28c2c66affSColin Finck
29c2c66affSColin Finck #ifdef _WIN64
30c2c66affSColin Finck
31c2c66affSColin Finck #define CTXARG_T DWORDLONG
32bcea8c65SAmine Khaldi #define IActiveScriptDebugVtbl IActiveScriptDebug64Vtbl
33c2c66affSColin Finck #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
34c2c66affSColin Finck #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
35c2c66affSColin Finck
36c2c66affSColin Finck #else
37c2c66affSColin Finck
38c2c66affSColin Finck #define CTXARG_T DWORD
39bcea8c65SAmine Khaldi #define IActiveScriptDebugVtbl IActiveScriptDebug32Vtbl
40c2c66affSColin Finck #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
41c2c66affSColin Finck #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
42c2c66affSColin Finck
43c2c66affSColin Finck #endif
44c2c66affSColin Finck
45c2c66affSColin Finck struct VBScript {
46c2c66affSColin Finck IActiveScript IActiveScript_iface;
47bcea8c65SAmine Khaldi IActiveScriptDebug IActiveScriptDebug_iface;
48c2c66affSColin Finck IActiveScriptParse IActiveScriptParse_iface;
49c2c66affSColin Finck IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface;
50c2c66affSColin Finck IObjectSafety IObjectSafety_iface;
51c2c66affSColin Finck
52c2c66affSColin Finck LONG ref;
53c2c66affSColin Finck
54c2c66affSColin Finck SCRIPTSTATE state;
55c2c66affSColin Finck script_ctx_t *ctx;
56c2c66affSColin Finck LONG thread_id;
57*9a0ddc13SAmine Khaldi BOOL is_initialized;
58c2c66affSColin Finck };
59c2c66affSColin Finck
60*9a0ddc13SAmine Khaldi typedef struct {
61*9a0ddc13SAmine Khaldi IActiveScriptError IActiveScriptError_iface;
62*9a0ddc13SAmine Khaldi LONG ref;
63*9a0ddc13SAmine Khaldi EXCEPINFO ei;
64*9a0ddc13SAmine Khaldi } VBScriptError;
65*9a0ddc13SAmine Khaldi
change_state(VBScript * This,SCRIPTSTATE state)66c2c66affSColin Finck static void change_state(VBScript *This, SCRIPTSTATE state)
67c2c66affSColin Finck {
68c2c66affSColin Finck if(This->state == state)
69c2c66affSColin Finck return;
70c2c66affSColin Finck
71c2c66affSColin Finck This->state = state;
72*9a0ddc13SAmine Khaldi if(This->ctx->site)
73*9a0ddc13SAmine Khaldi IActiveScriptSite_OnStateChange(This->ctx->site, state);
74c2c66affSColin Finck }
75c2c66affSColin Finck
is_started(VBScript * This)76c2c66affSColin Finck static inline BOOL is_started(VBScript *This)
77c2c66affSColin Finck {
78c2c66affSColin Finck return This->state == SCRIPTSTATE_STARTED
79c2c66affSColin Finck || This->state == SCRIPTSTATE_CONNECTED
80c2c66affSColin Finck || This->state == SCRIPTSTATE_DISCONNECTED;
81c2c66affSColin Finck }
82c2c66affSColin Finck
exec_global_code(script_ctx_t * ctx,vbscode_t * code,VARIANT * res)83*9a0ddc13SAmine Khaldi static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res)
84c2c66affSColin Finck {
85c2c66affSColin Finck code->pending_exec = FALSE;
86*9a0ddc13SAmine Khaldi return exec_script(ctx, TRUE, &code->main_code, NULL, NULL, res);
87c2c66affSColin Finck }
88c2c66affSColin Finck
exec_queued_code(script_ctx_t * ctx)89c2c66affSColin Finck static void exec_queued_code(script_ctx_t *ctx)
90c2c66affSColin Finck {
91c2c66affSColin Finck vbscode_t *iter;
92c2c66affSColin Finck
93c2c66affSColin Finck LIST_FOR_EACH_ENTRY(iter, &ctx->code_list, vbscode_t, entry) {
94c2c66affSColin Finck if(iter->pending_exec)
95*9a0ddc13SAmine Khaldi exec_global_code(ctx, iter, NULL);
96c2c66affSColin Finck }
97c2c66affSColin Finck }
98c2c66affSColin Finck
lookup_named_item(script_ctx_t * ctx,const WCHAR * name,unsigned flags)99bcea8c65SAmine Khaldi IDispatch *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flags)
100bcea8c65SAmine Khaldi {
101bcea8c65SAmine Khaldi named_item_t *item;
102bcea8c65SAmine Khaldi HRESULT hres;
103bcea8c65SAmine Khaldi
104bcea8c65SAmine Khaldi LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
105*9a0ddc13SAmine Khaldi if((item->flags & flags) == flags && !wcsicmp(item->name, name)) {
106bcea8c65SAmine Khaldi if(!item->disp) {
107bcea8c65SAmine Khaldi IUnknown *unk;
108bcea8c65SAmine Khaldi
109bcea8c65SAmine Khaldi hres = IActiveScriptSite_GetItemInfo(ctx->site, item->name,
110bcea8c65SAmine Khaldi SCRIPTINFO_IUNKNOWN, &unk, NULL);
111bcea8c65SAmine Khaldi if(FAILED(hres)) {
112bcea8c65SAmine Khaldi WARN("GetItemInfo failed: %08x\n", hres);
113bcea8c65SAmine Khaldi continue;
114bcea8c65SAmine Khaldi }
115bcea8c65SAmine Khaldi
116bcea8c65SAmine Khaldi hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
117bcea8c65SAmine Khaldi IUnknown_Release(unk);
118bcea8c65SAmine Khaldi if(FAILED(hres)) {
119bcea8c65SAmine Khaldi WARN("object does not implement IDispatch\n");
120bcea8c65SAmine Khaldi continue;
121bcea8c65SAmine Khaldi }
122bcea8c65SAmine Khaldi }
123bcea8c65SAmine Khaldi
124bcea8c65SAmine Khaldi return item->disp;
125bcea8c65SAmine Khaldi }
126bcea8c65SAmine Khaldi }
127bcea8c65SAmine Khaldi
128bcea8c65SAmine Khaldi return NULL;
129bcea8c65SAmine Khaldi }
130bcea8c65SAmine Khaldi
release_script(script_ctx_t * ctx)131c2c66affSColin Finck static void release_script(script_ctx_t *ctx)
132c2c66affSColin Finck {
133c2c66affSColin Finck class_desc_t *class_desc;
134c2c66affSColin Finck
135c2c66affSColin Finck collect_objects(ctx);
136*9a0ddc13SAmine Khaldi clear_ei(&ctx->ei);
137c2c66affSColin Finck
138c2c66affSColin Finck release_dynamic_vars(ctx->global_vars);
139c2c66affSColin Finck ctx->global_vars = NULL;
140c2c66affSColin Finck
141c2c66affSColin Finck while(!list_empty(&ctx->named_items)) {
142c2c66affSColin Finck named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry);
143c2c66affSColin Finck
144c2c66affSColin Finck list_remove(&iter->entry);
145c2c66affSColin Finck if(iter->disp)
146c2c66affSColin Finck IDispatch_Release(iter->disp);
147c2c66affSColin Finck heap_free(iter->name);
148c2c66affSColin Finck heap_free(iter);
149c2c66affSColin Finck }
150c2c66affSColin Finck
151c2c66affSColin Finck while(ctx->procs) {
152c2c66affSColin Finck class_desc = ctx->procs;
153c2c66affSColin Finck ctx->procs = class_desc->next;
154c2c66affSColin Finck
155c2c66affSColin Finck heap_free(class_desc);
156c2c66affSColin Finck }
157c2c66affSColin Finck
158c2c66affSColin Finck if(ctx->host_global) {
159c2c66affSColin Finck IDispatch_Release(ctx->host_global);
160c2c66affSColin Finck ctx->host_global = NULL;
161c2c66affSColin Finck }
162c2c66affSColin Finck
163c2c66affSColin Finck if(ctx->secmgr) {
164c2c66affSColin Finck IInternetHostSecurityManager_Release(ctx->secmgr);
165c2c66affSColin Finck ctx->secmgr = NULL;
166c2c66affSColin Finck }
167c2c66affSColin Finck
168c2c66affSColin Finck if(ctx->site) {
169c2c66affSColin Finck IActiveScriptSite_Release(ctx->site);
170c2c66affSColin Finck ctx->site = NULL;
171c2c66affSColin Finck }
172c2c66affSColin Finck
173c2c66affSColin Finck if(ctx->script_obj) {
174c2c66affSColin Finck ScriptDisp *script_obj = ctx->script_obj;
175c2c66affSColin Finck
176c2c66affSColin Finck ctx->script_obj = NULL;
177c2c66affSColin Finck script_obj->ctx = NULL;
178c2c66affSColin Finck IDispatchEx_Release(&script_obj->IDispatchEx_iface);
179c2c66affSColin Finck }
180c2c66affSColin Finck
181*9a0ddc13SAmine Khaldi detach_global_objects(ctx);
182c2c66affSColin Finck heap_pool_free(&ctx->heap);
183c2c66affSColin Finck heap_pool_init(&ctx->heap);
184c2c66affSColin Finck }
185c2c66affSColin Finck
destroy_script(script_ctx_t * ctx)186c2c66affSColin Finck static void destroy_script(script_ctx_t *ctx)
187c2c66affSColin Finck {
188c2c66affSColin Finck while(!list_empty(&ctx->code_list))
189c2c66affSColin Finck release_vbscode(LIST_ENTRY(list_head(&ctx->code_list), vbscode_t, entry));
190c2c66affSColin Finck
191c2c66affSColin Finck release_script(ctx);
192c2c66affSColin Finck heap_free(ctx);
193c2c66affSColin Finck }
194c2c66affSColin Finck
decrease_state(VBScript * This,SCRIPTSTATE state)195c2c66affSColin Finck static void decrease_state(VBScript *This, SCRIPTSTATE state)
196c2c66affSColin Finck {
197c2c66affSColin Finck switch(This->state) {
198c2c66affSColin Finck case SCRIPTSTATE_CONNECTED:
199c2c66affSColin Finck change_state(This, SCRIPTSTATE_DISCONNECTED);
200c2c66affSColin Finck if(state == SCRIPTSTATE_DISCONNECTED)
201c2c66affSColin Finck return;
202c2c66affSColin Finck /* FALLTHROUGH */
203c2c66affSColin Finck case SCRIPTSTATE_STARTED:
204c2c66affSColin Finck case SCRIPTSTATE_DISCONNECTED:
205c2c66affSColin Finck if(This->state == SCRIPTSTATE_DISCONNECTED)
206c2c66affSColin Finck change_state(This, SCRIPTSTATE_INITIALIZED);
207c2c66affSColin Finck if(state == SCRIPTSTATE_INITIALIZED)
208c2c66affSColin Finck break;
209c2c66affSColin Finck /* FALLTHROUGH */
210c2c66affSColin Finck case SCRIPTSTATE_INITIALIZED:
211c2c66affSColin Finck case SCRIPTSTATE_UNINITIALIZED:
212c2c66affSColin Finck change_state(This, state);
213c2c66affSColin Finck release_script(This->ctx);
214c2c66affSColin Finck This->thread_id = 0;
215c2c66affSColin Finck break;
216c2c66affSColin Finck case SCRIPTSTATE_CLOSED:
217c2c66affSColin Finck break;
218c2c66affSColin Finck DEFAULT_UNREACHABLE;
219c2c66affSColin Finck }
220c2c66affSColin Finck }
221c2c66affSColin Finck
impl_from_IActiveScriptError(IActiveScriptError * iface)222*9a0ddc13SAmine Khaldi static inline VBScriptError *impl_from_IActiveScriptError(IActiveScriptError *iface)
223*9a0ddc13SAmine Khaldi {
224*9a0ddc13SAmine Khaldi return CONTAINING_RECORD(iface, VBScriptError, IActiveScriptError_iface);
225*9a0ddc13SAmine Khaldi }
226*9a0ddc13SAmine Khaldi
VBScriptError_QueryInterface(IActiveScriptError * iface,REFIID riid,void ** ppv)227*9a0ddc13SAmine Khaldi static HRESULT WINAPI VBScriptError_QueryInterface(IActiveScriptError *iface, REFIID riid, void **ppv)
228*9a0ddc13SAmine Khaldi {
229*9a0ddc13SAmine Khaldi VBScriptError *This = impl_from_IActiveScriptError(iface);
230*9a0ddc13SAmine Khaldi
231*9a0ddc13SAmine Khaldi if(IsEqualGUID(riid, &IID_IUnknown)) {
232*9a0ddc13SAmine Khaldi TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
233*9a0ddc13SAmine Khaldi *ppv = &This->IActiveScriptError_iface;
234*9a0ddc13SAmine Khaldi }else if(IsEqualGUID(riid, &IID_IActiveScriptError)) {
235*9a0ddc13SAmine Khaldi TRACE("(%p)->(IID_IActiveScriptError %p)\n", This, ppv);
236*9a0ddc13SAmine Khaldi *ppv = &This->IActiveScriptError_iface;
237*9a0ddc13SAmine Khaldi }else {
238*9a0ddc13SAmine Khaldi FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
239*9a0ddc13SAmine Khaldi *ppv = NULL;
240*9a0ddc13SAmine Khaldi return E_NOINTERFACE;
241*9a0ddc13SAmine Khaldi }
242*9a0ddc13SAmine Khaldi
243*9a0ddc13SAmine Khaldi IUnknown_AddRef((IUnknown*)*ppv);
244*9a0ddc13SAmine Khaldi return S_OK;
245*9a0ddc13SAmine Khaldi }
246*9a0ddc13SAmine Khaldi
VBScriptError_AddRef(IActiveScriptError * iface)247*9a0ddc13SAmine Khaldi static ULONG WINAPI VBScriptError_AddRef(IActiveScriptError *iface)
248*9a0ddc13SAmine Khaldi {
249*9a0ddc13SAmine Khaldi VBScriptError *This = impl_from_IActiveScriptError(iface);
250*9a0ddc13SAmine Khaldi LONG ref = InterlockedIncrement(&This->ref);
251*9a0ddc13SAmine Khaldi
252*9a0ddc13SAmine Khaldi TRACE("(%p) ref=%d\n", This, ref);
253*9a0ddc13SAmine Khaldi
254*9a0ddc13SAmine Khaldi return ref;
255*9a0ddc13SAmine Khaldi }
256*9a0ddc13SAmine Khaldi
VBScriptError_Release(IActiveScriptError * iface)257*9a0ddc13SAmine Khaldi static ULONG WINAPI VBScriptError_Release(IActiveScriptError *iface)
258*9a0ddc13SAmine Khaldi {
259*9a0ddc13SAmine Khaldi VBScriptError *This = impl_from_IActiveScriptError(iface);
260*9a0ddc13SAmine Khaldi LONG ref = InterlockedDecrement(&This->ref);
261*9a0ddc13SAmine Khaldi
262*9a0ddc13SAmine Khaldi TRACE("(%p) ref=%d\n", This, ref);
263*9a0ddc13SAmine Khaldi
264*9a0ddc13SAmine Khaldi if(!ref) {
265*9a0ddc13SAmine Khaldi heap_free(This);
266*9a0ddc13SAmine Khaldi }
267*9a0ddc13SAmine Khaldi
268*9a0ddc13SAmine Khaldi return ref;
269*9a0ddc13SAmine Khaldi }
270*9a0ddc13SAmine Khaldi
VBScriptError_GetExceptionInfo(IActiveScriptError * iface,EXCEPINFO * excepinfo)271*9a0ddc13SAmine Khaldi static HRESULT WINAPI VBScriptError_GetExceptionInfo(IActiveScriptError *iface, EXCEPINFO *excepinfo)
272*9a0ddc13SAmine Khaldi {
273*9a0ddc13SAmine Khaldi VBScriptError *This = impl_from_IActiveScriptError(iface);
274*9a0ddc13SAmine Khaldi
275*9a0ddc13SAmine Khaldi TRACE("(%p)->(%p)\n", This, excepinfo);
276*9a0ddc13SAmine Khaldi
277*9a0ddc13SAmine Khaldi *excepinfo = This->ei;
278*9a0ddc13SAmine Khaldi excepinfo->bstrSource = SysAllocString(This->ei.bstrSource);
279*9a0ddc13SAmine Khaldi excepinfo->bstrDescription = SysAllocString(This->ei.bstrDescription);
280*9a0ddc13SAmine Khaldi excepinfo->bstrHelpFile = SysAllocString(This->ei.bstrHelpFile);
281*9a0ddc13SAmine Khaldi return S_OK;
282*9a0ddc13SAmine Khaldi }
283*9a0ddc13SAmine Khaldi
VBScriptError_GetSourcePosition(IActiveScriptError * iface,DWORD * source_context,ULONG * line,LONG * character)284*9a0ddc13SAmine Khaldi static HRESULT WINAPI VBScriptError_GetSourcePosition(IActiveScriptError *iface, DWORD *source_context, ULONG *line, LONG *character)
285*9a0ddc13SAmine Khaldi {
286*9a0ddc13SAmine Khaldi VBScriptError *This = impl_from_IActiveScriptError(iface);
287*9a0ddc13SAmine Khaldi
288*9a0ddc13SAmine Khaldi FIXME("(%p)->(%p %p %p)\n", This, source_context, line, character);
289*9a0ddc13SAmine Khaldi
290*9a0ddc13SAmine Khaldi if(source_context)
291*9a0ddc13SAmine Khaldi *source_context = 0;
292*9a0ddc13SAmine Khaldi if(line)
293*9a0ddc13SAmine Khaldi *line = 0;
294*9a0ddc13SAmine Khaldi if(character)
295*9a0ddc13SAmine Khaldi *character = 0;
296*9a0ddc13SAmine Khaldi return S_OK;
297*9a0ddc13SAmine Khaldi }
298*9a0ddc13SAmine Khaldi
VBScriptError_GetSourceLineText(IActiveScriptError * iface,BSTR * source)299*9a0ddc13SAmine Khaldi static HRESULT WINAPI VBScriptError_GetSourceLineText(IActiveScriptError *iface, BSTR *source)
300*9a0ddc13SAmine Khaldi {
301*9a0ddc13SAmine Khaldi VBScriptError *This = impl_from_IActiveScriptError(iface);
302*9a0ddc13SAmine Khaldi FIXME("(%p)->(%p)\n", This, source);
303*9a0ddc13SAmine Khaldi return E_NOTIMPL;
304*9a0ddc13SAmine Khaldi }
305*9a0ddc13SAmine Khaldi
306*9a0ddc13SAmine Khaldi static const IActiveScriptErrorVtbl VBScriptErrorVtbl = {
307*9a0ddc13SAmine Khaldi VBScriptError_QueryInterface,
308*9a0ddc13SAmine Khaldi VBScriptError_AddRef,
309*9a0ddc13SAmine Khaldi VBScriptError_Release,
310*9a0ddc13SAmine Khaldi VBScriptError_GetExceptionInfo,
311*9a0ddc13SAmine Khaldi VBScriptError_GetSourcePosition,
312*9a0ddc13SAmine Khaldi VBScriptError_GetSourceLineText
313*9a0ddc13SAmine Khaldi };
314*9a0ddc13SAmine Khaldi
report_script_error(script_ctx_t * ctx)315*9a0ddc13SAmine Khaldi HRESULT report_script_error(script_ctx_t *ctx)
316*9a0ddc13SAmine Khaldi {
317*9a0ddc13SAmine Khaldi VBScriptError *error;
318*9a0ddc13SAmine Khaldi HRESULT hres, result;
319*9a0ddc13SAmine Khaldi
320*9a0ddc13SAmine Khaldi if(!(error = heap_alloc(sizeof(*error))))
321*9a0ddc13SAmine Khaldi return E_OUTOFMEMORY;
322*9a0ddc13SAmine Khaldi error->IActiveScriptError_iface.lpVtbl = &VBScriptErrorVtbl;
323*9a0ddc13SAmine Khaldi
324*9a0ddc13SAmine Khaldi error->ref = 1;
325*9a0ddc13SAmine Khaldi error->ei = ctx->ei;
326*9a0ddc13SAmine Khaldi memset(&ctx->ei, 0, sizeof(ctx->ei));
327*9a0ddc13SAmine Khaldi result = error->ei.scode;
328*9a0ddc13SAmine Khaldi
329*9a0ddc13SAmine Khaldi hres = IActiveScriptSite_OnScriptError(ctx->site, &error->IActiveScriptError_iface);
330*9a0ddc13SAmine Khaldi IActiveScriptError_Release(&error->IActiveScriptError_iface);
331*9a0ddc13SAmine Khaldi return hres == S_OK ? SCRIPT_E_REPORTED : result;
332*9a0ddc13SAmine Khaldi }
333*9a0ddc13SAmine Khaldi
impl_from_IActiveScript(IActiveScript * iface)334c2c66affSColin Finck static inline VBScript *impl_from_IActiveScript(IActiveScript *iface)
335c2c66affSColin Finck {
336c2c66affSColin Finck return CONTAINING_RECORD(iface, VBScript, IActiveScript_iface);
337c2c66affSColin Finck }
338c2c66affSColin Finck
VBScript_QueryInterface(IActiveScript * iface,REFIID riid,void ** ppv)339c2c66affSColin Finck static HRESULT WINAPI VBScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
340c2c66affSColin Finck {
341c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
342c2c66affSColin Finck
343c2c66affSColin Finck if(IsEqualGUID(riid, &IID_IUnknown)) {
344c2c66affSColin Finck TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
345c2c66affSColin Finck *ppv = &This->IActiveScript_iface;
346c2c66affSColin Finck }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
347c2c66affSColin Finck TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
348c2c66affSColin Finck *ppv = &This->IActiveScript_iface;
349bcea8c65SAmine Khaldi }else if(IsEqualGUID(riid, &IID_IActiveScriptDebug)) {
350bcea8c65SAmine Khaldi TRACE("(%p)->(IID_IActiveScriptDebug %p)\n", This, ppv);
351bcea8c65SAmine Khaldi *ppv = &This->IActiveScriptDebug_iface;
352c2c66affSColin Finck }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
353c2c66affSColin Finck TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
354c2c66affSColin Finck *ppv = &This->IActiveScriptParse_iface;
355c2c66affSColin Finck }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
356c2c66affSColin Finck TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
357c2c66affSColin Finck *ppv = &This->IActiveScriptParseProcedure2_iface;
358c2c66affSColin Finck }else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
359c2c66affSColin Finck TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
360c2c66affSColin Finck *ppv = &This->IObjectSafety_iface;
361c2c66affSColin Finck }else {
362c2c66affSColin Finck FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
363c2c66affSColin Finck *ppv = NULL;
364c2c66affSColin Finck return E_NOINTERFACE;
365c2c66affSColin Finck }
366c2c66affSColin Finck
367c2c66affSColin Finck IUnknown_AddRef((IUnknown*)*ppv);
368c2c66affSColin Finck return S_OK;
369c2c66affSColin Finck }
370c2c66affSColin Finck
VBScript_AddRef(IActiveScript * iface)371c2c66affSColin Finck static ULONG WINAPI VBScript_AddRef(IActiveScript *iface)
372c2c66affSColin Finck {
373c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
374c2c66affSColin Finck LONG ref = InterlockedIncrement(&This->ref);
375c2c66affSColin Finck
376c2c66affSColin Finck TRACE("(%p) ref=%d\n", This, ref);
377c2c66affSColin Finck
378c2c66affSColin Finck return ref;
379c2c66affSColin Finck }
380c2c66affSColin Finck
VBScript_Release(IActiveScript * iface)381c2c66affSColin Finck static ULONG WINAPI VBScript_Release(IActiveScript *iface)
382c2c66affSColin Finck {
383c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
384c2c66affSColin Finck LONG ref = InterlockedDecrement(&This->ref);
385c2c66affSColin Finck
386c2c66affSColin Finck TRACE("(%p) ref=%d\n", iface, ref);
387c2c66affSColin Finck
388c2c66affSColin Finck if(!ref) {
389c2c66affSColin Finck decrease_state(This, SCRIPTSTATE_CLOSED);
390c2c66affSColin Finck destroy_script(This->ctx);
391c2c66affSColin Finck heap_free(This);
392c2c66affSColin Finck }
393c2c66affSColin Finck
394c2c66affSColin Finck return ref;
395c2c66affSColin Finck }
396c2c66affSColin Finck
VBScript_SetScriptSite(IActiveScript * iface,IActiveScriptSite * pass)397c2c66affSColin Finck static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
398c2c66affSColin Finck {
399c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
400c2c66affSColin Finck LCID lcid;
401c2c66affSColin Finck HRESULT hres;
402c2c66affSColin Finck
403c2c66affSColin Finck TRACE("(%p)->(%p)\n", This, pass);
404c2c66affSColin Finck
405c2c66affSColin Finck if(!pass)
406c2c66affSColin Finck return E_POINTER;
407c2c66affSColin Finck
408*9a0ddc13SAmine Khaldi if(This->ctx->site)
409c2c66affSColin Finck return E_UNEXPECTED;
410c2c66affSColin Finck
411c2c66affSColin Finck if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
412c2c66affSColin Finck return E_UNEXPECTED;
413c2c66affSColin Finck
414*9a0ddc13SAmine Khaldi hres = create_script_disp(This->ctx, &This->ctx->script_obj);
415*9a0ddc13SAmine Khaldi if(FAILED(hres))
416*9a0ddc13SAmine Khaldi return hres;
417c2c66affSColin Finck
418*9a0ddc13SAmine Khaldi This->ctx->site = pass;
419*9a0ddc13SAmine Khaldi IActiveScriptSite_AddRef(This->ctx->site);
420*9a0ddc13SAmine Khaldi
421*9a0ddc13SAmine Khaldi hres = IActiveScriptSite_GetLCID(This->ctx->site, &lcid);
422c2c66affSColin Finck if(hres == S_OK)
423*9a0ddc13SAmine Khaldi This->ctx->lcid = lcid;
424c2c66affSColin Finck
425*9a0ddc13SAmine Khaldi if(This->is_initialized)
426*9a0ddc13SAmine Khaldi change_state(This, SCRIPTSTATE_INITIALIZED);
427*9a0ddc13SAmine Khaldi return S_OK;
428c2c66affSColin Finck }
429c2c66affSColin Finck
VBScript_GetScriptSite(IActiveScript * iface,REFIID riid,void ** ppvObject)430c2c66affSColin Finck static HRESULT WINAPI VBScript_GetScriptSite(IActiveScript *iface, REFIID riid,
431c2c66affSColin Finck void **ppvObject)
432c2c66affSColin Finck {
433c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
434c2c66affSColin Finck FIXME("(%p)->()\n", This);
435c2c66affSColin Finck return E_NOTIMPL;
436c2c66affSColin Finck }
437c2c66affSColin Finck
VBScript_SetScriptState(IActiveScript * iface,SCRIPTSTATE ss)438c2c66affSColin Finck static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
439c2c66affSColin Finck {
440c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
441c2c66affSColin Finck
442c2c66affSColin Finck TRACE("(%p)->(%d)\n", This, ss);
443c2c66affSColin Finck
444c2c66affSColin Finck if(This->thread_id && GetCurrentThreadId() != This->thread_id)
445c2c66affSColin Finck return E_UNEXPECTED;
446c2c66affSColin Finck
447c2c66affSColin Finck if(ss == SCRIPTSTATE_UNINITIALIZED) {
448c2c66affSColin Finck if(This->state == SCRIPTSTATE_CLOSED)
449c2c66affSColin Finck return E_UNEXPECTED;
450c2c66affSColin Finck
451c2c66affSColin Finck decrease_state(This, SCRIPTSTATE_UNINITIALIZED);
452c2c66affSColin Finck return S_OK;
453c2c66affSColin Finck }
454c2c66affSColin Finck
455*9a0ddc13SAmine Khaldi if(!This->is_initialized)
456c2c66affSColin Finck return E_UNEXPECTED;
457c2c66affSColin Finck
458c2c66affSColin Finck switch(ss) {
459c2c66affSColin Finck case SCRIPTSTATE_STARTED:
460c2c66affSColin Finck case SCRIPTSTATE_CONNECTED: /* FIXME */
461c2c66affSColin Finck if(This->state == SCRIPTSTATE_CLOSED)
462c2c66affSColin Finck return E_UNEXPECTED;
463c2c66affSColin Finck
464c2c66affSColin Finck exec_queued_code(This->ctx);
465c2c66affSColin Finck break;
466c2c66affSColin Finck case SCRIPTSTATE_INITIALIZED:
467c2c66affSColin Finck FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
468c2c66affSColin Finck return S_OK;
469e0b80a09SAmine Khaldi case SCRIPTSTATE_DISCONNECTED:
470e0b80a09SAmine Khaldi FIXME("unimplemented SCRIPTSTATE_DISCONNECTED\n");
471e0b80a09SAmine Khaldi return S_OK;
472c2c66affSColin Finck default:
473c2c66affSColin Finck FIXME("unimplemented state %d\n", ss);
474c2c66affSColin Finck return E_NOTIMPL;
475c2c66affSColin Finck }
476c2c66affSColin Finck
477c2c66affSColin Finck change_state(This, ss);
478c2c66affSColin Finck return S_OK;
479c2c66affSColin Finck }
480c2c66affSColin Finck
VBScript_GetScriptState(IActiveScript * iface,SCRIPTSTATE * pssState)481c2c66affSColin Finck static HRESULT WINAPI VBScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
482c2c66affSColin Finck {
483c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
484c2c66affSColin Finck
485c2c66affSColin Finck TRACE("(%p)->(%p)\n", This, pssState);
486c2c66affSColin Finck
487c2c66affSColin Finck if(!pssState)
488c2c66affSColin Finck return E_POINTER;
489c2c66affSColin Finck
490c2c66affSColin Finck if(This->thread_id && This->thread_id != GetCurrentThreadId())
491c2c66affSColin Finck return E_UNEXPECTED;
492c2c66affSColin Finck
493c2c66affSColin Finck *pssState = This->state;
494c2c66affSColin Finck return S_OK;
495c2c66affSColin Finck }
496c2c66affSColin Finck
VBScript_Close(IActiveScript * iface)497c2c66affSColin Finck static HRESULT WINAPI VBScript_Close(IActiveScript *iface)
498c2c66affSColin Finck {
499c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
500c2c66affSColin Finck
501c2c66affSColin Finck TRACE("(%p)->()\n", This);
502c2c66affSColin Finck
503c2c66affSColin Finck if(This->thread_id && This->thread_id != GetCurrentThreadId())
504c2c66affSColin Finck return E_UNEXPECTED;
505c2c66affSColin Finck
506c2c66affSColin Finck decrease_state(This, SCRIPTSTATE_CLOSED);
507c2c66affSColin Finck return S_OK;
508c2c66affSColin Finck }
509c2c66affSColin Finck
VBScript_AddNamedItem(IActiveScript * iface,LPCOLESTR pstrName,DWORD dwFlags)510c2c66affSColin Finck static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
511c2c66affSColin Finck {
512c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
513c2c66affSColin Finck named_item_t *item;
514c2c66affSColin Finck IDispatch *disp = NULL;
515c2c66affSColin Finck HRESULT hres;
516c2c66affSColin Finck
517c2c66affSColin Finck TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
518c2c66affSColin Finck
519*9a0ddc13SAmine Khaldi if(This->thread_id != GetCurrentThreadId() || !This->ctx->site)
520c2c66affSColin Finck return E_UNEXPECTED;
521c2c66affSColin Finck
522c2c66affSColin Finck if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
523c2c66affSColin Finck IUnknown *unk;
524c2c66affSColin Finck
525*9a0ddc13SAmine Khaldi hres = IActiveScriptSite_GetItemInfo(This->ctx->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
526c2c66affSColin Finck if(FAILED(hres)) {
527c2c66affSColin Finck WARN("GetItemInfo failed: %08x\n", hres);
528c2c66affSColin Finck return hres;
529c2c66affSColin Finck }
530c2c66affSColin Finck
531c2c66affSColin Finck hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
532c2c66affSColin Finck IUnknown_Release(unk);
533c2c66affSColin Finck if(FAILED(hres)) {
534c2c66affSColin Finck WARN("object does not implement IDispatch\n");
535c2c66affSColin Finck return hres;
536c2c66affSColin Finck }
537c2c66affSColin Finck
538c2c66affSColin Finck if(This->ctx->host_global)
539c2c66affSColin Finck IDispatch_Release(This->ctx->host_global);
540c2c66affSColin Finck IDispatch_AddRef(disp);
541c2c66affSColin Finck This->ctx->host_global = disp;
542c2c66affSColin Finck }
543c2c66affSColin Finck
544c2c66affSColin Finck item = heap_alloc(sizeof(*item));
545c2c66affSColin Finck if(!item) {
546c2c66affSColin Finck if(disp)
547c2c66affSColin Finck IDispatch_Release(disp);
548c2c66affSColin Finck return E_OUTOFMEMORY;
549c2c66affSColin Finck }
550c2c66affSColin Finck
551c2c66affSColin Finck item->disp = disp;
552c2c66affSColin Finck item->flags = dwFlags;
553c2c66affSColin Finck item->name = heap_strdupW(pstrName);
554c2c66affSColin Finck if(!item->name) {
555c2c66affSColin Finck if(disp)
556c2c66affSColin Finck IDispatch_Release(disp);
557c2c66affSColin Finck heap_free(item);
558c2c66affSColin Finck return E_OUTOFMEMORY;
559c2c66affSColin Finck }
560c2c66affSColin Finck
561c2c66affSColin Finck list_add_tail(&This->ctx->named_items, &item->entry);
562c2c66affSColin Finck return S_OK;
563c2c66affSColin Finck }
564c2c66affSColin Finck
VBScript_AddTypeLib(IActiveScript * iface,REFGUID rguidTypeLib,DWORD dwMajor,DWORD dwMinor,DWORD dwFlags)565c2c66affSColin Finck static HRESULT WINAPI VBScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
566c2c66affSColin Finck DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
567c2c66affSColin Finck {
568c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
569c2c66affSColin Finck FIXME("(%p)->()\n", This);
570c2c66affSColin Finck return E_NOTIMPL;
571c2c66affSColin Finck }
572c2c66affSColin Finck
VBScript_GetScriptDispatch(IActiveScript * iface,LPCOLESTR pstrItemName,IDispatch ** ppdisp)573c2c66affSColin Finck static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName, IDispatch **ppdisp)
574c2c66affSColin Finck {
575c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
576c2c66affSColin Finck
577c2c66affSColin Finck TRACE("(%p)->(%p)\n", This, ppdisp);
578c2c66affSColin Finck
579c2c66affSColin Finck if(!ppdisp)
580c2c66affSColin Finck return E_POINTER;
581c2c66affSColin Finck
582*9a0ddc13SAmine Khaldi if(This->thread_id != GetCurrentThreadId() || !This->ctx->script_obj) {
583c2c66affSColin Finck *ppdisp = NULL;
584c2c66affSColin Finck return E_UNEXPECTED;
585c2c66affSColin Finck }
586c2c66affSColin Finck
587c2c66affSColin Finck *ppdisp = (IDispatch*)&This->ctx->script_obj->IDispatchEx_iface;
588c2c66affSColin Finck IDispatch_AddRef(*ppdisp);
589c2c66affSColin Finck return S_OK;
590c2c66affSColin Finck }
591c2c66affSColin Finck
VBScript_GetCurrentScriptThreadID(IActiveScript * iface,SCRIPTTHREADID * pstridThread)592c2c66affSColin Finck static HRESULT WINAPI VBScript_GetCurrentScriptThreadID(IActiveScript *iface,
593c2c66affSColin Finck SCRIPTTHREADID *pstridThread)
594c2c66affSColin Finck {
595c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
596c2c66affSColin Finck FIXME("(%p)->()\n", This);
597c2c66affSColin Finck return E_NOTIMPL;
598c2c66affSColin Finck }
599c2c66affSColin Finck
VBScript_GetScriptThreadID(IActiveScript * iface,DWORD dwWin32ThreadId,SCRIPTTHREADID * pstidThread)600c2c66affSColin Finck static HRESULT WINAPI VBScript_GetScriptThreadID(IActiveScript *iface,
601c2c66affSColin Finck DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
602c2c66affSColin Finck {
603c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
604c2c66affSColin Finck FIXME("(%p)->()\n", This);
605c2c66affSColin Finck return E_NOTIMPL;
606c2c66affSColin Finck }
607c2c66affSColin Finck
VBScript_GetScriptThreadState(IActiveScript * iface,SCRIPTTHREADID stidThread,SCRIPTTHREADSTATE * pstsState)608c2c66affSColin Finck static HRESULT WINAPI VBScript_GetScriptThreadState(IActiveScript *iface,
609c2c66affSColin Finck SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
610c2c66affSColin Finck {
611c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
612c2c66affSColin Finck FIXME("(%p)->()\n", This);
613c2c66affSColin Finck return E_NOTIMPL;
614c2c66affSColin Finck }
615c2c66affSColin Finck
VBScript_InterruptScriptThread(IActiveScript * iface,SCRIPTTHREADID stidThread,const EXCEPINFO * pexcepinfo,DWORD dwFlags)616c2c66affSColin Finck static HRESULT WINAPI VBScript_InterruptScriptThread(IActiveScript *iface,
617c2c66affSColin Finck SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
618c2c66affSColin Finck {
619c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
620c2c66affSColin Finck FIXME("(%p)->()\n", This);
621c2c66affSColin Finck return E_NOTIMPL;
622c2c66affSColin Finck }
623c2c66affSColin Finck
VBScript_Clone(IActiveScript * iface,IActiveScript ** ppscript)624c2c66affSColin Finck static HRESULT WINAPI VBScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
625c2c66affSColin Finck {
626c2c66affSColin Finck VBScript *This = impl_from_IActiveScript(iface);
627c2c66affSColin Finck FIXME("(%p)->()\n", This);
628c2c66affSColin Finck return E_NOTIMPL;
629c2c66affSColin Finck }
630c2c66affSColin Finck
631c2c66affSColin Finck static const IActiveScriptVtbl VBScriptVtbl = {
632c2c66affSColin Finck VBScript_QueryInterface,
633c2c66affSColin Finck VBScript_AddRef,
634c2c66affSColin Finck VBScript_Release,
635c2c66affSColin Finck VBScript_SetScriptSite,
636c2c66affSColin Finck VBScript_GetScriptSite,
637c2c66affSColin Finck VBScript_SetScriptState,
638c2c66affSColin Finck VBScript_GetScriptState,
639c2c66affSColin Finck VBScript_Close,
640c2c66affSColin Finck VBScript_AddNamedItem,
641c2c66affSColin Finck VBScript_AddTypeLib,
642c2c66affSColin Finck VBScript_GetScriptDispatch,
643c2c66affSColin Finck VBScript_GetCurrentScriptThreadID,
644c2c66affSColin Finck VBScript_GetScriptThreadID,
645c2c66affSColin Finck VBScript_GetScriptThreadState,
646c2c66affSColin Finck VBScript_InterruptScriptThread,
647c2c66affSColin Finck VBScript_Clone
648c2c66affSColin Finck };
649c2c66affSColin Finck
impl_from_IActiveScriptDebug(IActiveScriptDebug * iface)650bcea8c65SAmine Khaldi static inline VBScript *impl_from_IActiveScriptDebug(IActiveScriptDebug *iface)
651bcea8c65SAmine Khaldi {
652bcea8c65SAmine Khaldi return CONTAINING_RECORD(iface, VBScript, IActiveScriptDebug_iface);
653bcea8c65SAmine Khaldi }
654bcea8c65SAmine Khaldi
VBScriptDebug_QueryInterface(IActiveScriptDebug * iface,REFIID riid,void ** ppv)655bcea8c65SAmine Khaldi static HRESULT WINAPI VBScriptDebug_QueryInterface(IActiveScriptDebug *iface, REFIID riid, void **ppv)
656bcea8c65SAmine Khaldi {
657bcea8c65SAmine Khaldi VBScript *This = impl_from_IActiveScriptDebug(iface);
658bcea8c65SAmine Khaldi return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
659bcea8c65SAmine Khaldi }
660bcea8c65SAmine Khaldi
VBScriptDebug_AddRef(IActiveScriptDebug * iface)661bcea8c65SAmine Khaldi static ULONG WINAPI VBScriptDebug_AddRef(IActiveScriptDebug *iface)
662bcea8c65SAmine Khaldi {
663bcea8c65SAmine Khaldi VBScript *This = impl_from_IActiveScriptDebug(iface);
664bcea8c65SAmine Khaldi return IActiveScript_AddRef(&This->IActiveScript_iface);
665bcea8c65SAmine Khaldi }
666bcea8c65SAmine Khaldi
VBScriptDebug_Release(IActiveScriptDebug * iface)667bcea8c65SAmine Khaldi static ULONG WINAPI VBScriptDebug_Release(IActiveScriptDebug *iface)
668bcea8c65SAmine Khaldi {
669bcea8c65SAmine Khaldi VBScript *This = impl_from_IActiveScriptDebug(iface);
670bcea8c65SAmine Khaldi return IActiveScript_Release(&This->IActiveScript_iface);
671bcea8c65SAmine Khaldi }
672bcea8c65SAmine Khaldi
VBScriptDebug_GetScriptTextAttributes(IActiveScriptDebug * iface,LPCOLESTR code,ULONG len,LPCOLESTR delimiter,DWORD flags,SOURCE_TEXT_ATTR * attr)673bcea8c65SAmine Khaldi static HRESULT WINAPI VBScriptDebug_GetScriptTextAttributes(IActiveScriptDebug *iface,
674bcea8c65SAmine Khaldi LPCOLESTR code, ULONG len, LPCOLESTR delimiter, DWORD flags, SOURCE_TEXT_ATTR *attr)
675bcea8c65SAmine Khaldi {
676bcea8c65SAmine Khaldi VBScript *This = impl_from_IActiveScriptDebug(iface);
677bcea8c65SAmine Khaldi FIXME("(%p)->(%s %u %s %#x %p)\n", This, debugstr_w(code), len,
678bcea8c65SAmine Khaldi debugstr_w(delimiter), flags, attr);
679bcea8c65SAmine Khaldi return E_NOTIMPL;
680bcea8c65SAmine Khaldi }
681bcea8c65SAmine Khaldi
VBScriptDebug_GetScriptletTextAttributes(IActiveScriptDebug * iface,LPCOLESTR code,ULONG len,LPCOLESTR delimiter,DWORD flags,SOURCE_TEXT_ATTR * attr)682bcea8c65SAmine Khaldi static HRESULT WINAPI VBScriptDebug_GetScriptletTextAttributes(IActiveScriptDebug *iface,
683bcea8c65SAmine Khaldi LPCOLESTR code, ULONG len, LPCOLESTR delimiter, DWORD flags, SOURCE_TEXT_ATTR *attr)
684bcea8c65SAmine Khaldi {
685bcea8c65SAmine Khaldi VBScript *This = impl_from_IActiveScriptDebug(iface);
686bcea8c65SAmine Khaldi FIXME("(%p)->(%s %u %s %#x %p)\n", This, debugstr_w(code), len,
687bcea8c65SAmine Khaldi debugstr_w(delimiter), flags, attr);
688bcea8c65SAmine Khaldi return E_NOTIMPL;
689bcea8c65SAmine Khaldi }
690bcea8c65SAmine Khaldi
VBScriptDebug_EnumCodeContextsOfPosition(IActiveScriptDebug * iface,CTXARG_T source,ULONG offset,ULONG len,IEnumDebugCodeContexts ** ret)691bcea8c65SAmine Khaldi static HRESULT WINAPI VBScriptDebug_EnumCodeContextsOfPosition(IActiveScriptDebug *iface,
692bcea8c65SAmine Khaldi CTXARG_T source, ULONG offset, ULONG len, IEnumDebugCodeContexts **ret)
693bcea8c65SAmine Khaldi {
694bcea8c65SAmine Khaldi VBScript *This = impl_from_IActiveScriptDebug(iface);
695bcea8c65SAmine Khaldi FIXME("(%p)->(%s %u %u %p)\n", This, wine_dbgstr_longlong(source), offset, len, ret);
696bcea8c65SAmine Khaldi return E_NOTIMPL;
697bcea8c65SAmine Khaldi }
698bcea8c65SAmine Khaldi
699bcea8c65SAmine Khaldi static const IActiveScriptDebugVtbl VBScriptDebugVtbl = {
700bcea8c65SAmine Khaldi VBScriptDebug_QueryInterface,
701bcea8c65SAmine Khaldi VBScriptDebug_AddRef,
702bcea8c65SAmine Khaldi VBScriptDebug_Release,
703bcea8c65SAmine Khaldi VBScriptDebug_GetScriptTextAttributes,
704bcea8c65SAmine Khaldi VBScriptDebug_GetScriptletTextAttributes,
705bcea8c65SAmine Khaldi VBScriptDebug_EnumCodeContextsOfPosition,
706bcea8c65SAmine Khaldi };
707bcea8c65SAmine Khaldi
impl_from_IActiveScriptParse(IActiveScriptParse * iface)708c2c66affSColin Finck static inline VBScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
709c2c66affSColin Finck {
710c2c66affSColin Finck return CONTAINING_RECORD(iface, VBScript, IActiveScriptParse_iface);
711c2c66affSColin Finck }
712c2c66affSColin Finck
VBScriptParse_QueryInterface(IActiveScriptParse * iface,REFIID riid,void ** ppv)713c2c66affSColin Finck static HRESULT WINAPI VBScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
714c2c66affSColin Finck {
715c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParse(iface);
716c2c66affSColin Finck return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
717c2c66affSColin Finck }
718c2c66affSColin Finck
VBScriptParse_AddRef(IActiveScriptParse * iface)719c2c66affSColin Finck static ULONG WINAPI VBScriptParse_AddRef(IActiveScriptParse *iface)
720c2c66affSColin Finck {
721c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParse(iface);
722c2c66affSColin Finck return IActiveScript_AddRef(&This->IActiveScript_iface);
723c2c66affSColin Finck }
724c2c66affSColin Finck
VBScriptParse_Release(IActiveScriptParse * iface)725c2c66affSColin Finck static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
726c2c66affSColin Finck {
727c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParse(iface);
728c2c66affSColin Finck return IActiveScript_Release(&This->IActiveScript_iface);
729c2c66affSColin Finck }
730c2c66affSColin Finck
VBScriptParse_InitNew(IActiveScriptParse * iface)731c2c66affSColin Finck static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
732c2c66affSColin Finck {
733c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParse(iface);
734c2c66affSColin Finck
735c2c66affSColin Finck TRACE("(%p)\n", This);
736c2c66affSColin Finck
737*9a0ddc13SAmine Khaldi if(This->is_initialized)
738c2c66affSColin Finck return E_UNEXPECTED;
739*9a0ddc13SAmine Khaldi This->is_initialized = TRUE;
740c2c66affSColin Finck
741*9a0ddc13SAmine Khaldi if(This->ctx->site)
742*9a0ddc13SAmine Khaldi change_state(This, SCRIPTSTATE_INITIALIZED);
743*9a0ddc13SAmine Khaldi return S_OK;
744c2c66affSColin Finck }
745c2c66affSColin Finck
VBScriptParse_AddScriptlet(IActiveScriptParse * iface,LPCOLESTR pstrDefaultName,LPCOLESTR pstrCode,LPCOLESTR pstrItemName,LPCOLESTR pstrSubItemName,LPCOLESTR pstrEventName,LPCOLESTR pstrDelimiter,CTXARG_T dwSourceContextCookie,ULONG ulStartingLineNumber,DWORD dwFlags,BSTR * pbstrName,EXCEPINFO * pexcepinfo)746c2c66affSColin Finck static HRESULT WINAPI VBScriptParse_AddScriptlet(IActiveScriptParse *iface,
747c2c66affSColin Finck LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
748c2c66affSColin Finck LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
749c2c66affSColin Finck CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
750c2c66affSColin Finck BSTR *pbstrName, EXCEPINFO *pexcepinfo)
751c2c66affSColin Finck {
752c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParse(iface);
753c2c66affSColin Finck FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
754c2c66affSColin Finck debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
755c2c66affSColin Finck debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
756c2c66affSColin Finck ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
757c2c66affSColin Finck return E_NOTIMPL;
758c2c66affSColin Finck }
759c2c66affSColin Finck
VBScriptParse_ParseScriptText(IActiveScriptParse * iface,LPCOLESTR pstrCode,LPCOLESTR pstrItemName,IUnknown * punkContext,LPCOLESTR pstrDelimiter,CTXARG_T dwSourceContextCookie,ULONG ulStartingLine,DWORD dwFlags,VARIANT * pvarResult,EXCEPINFO * pexcepinfo)760c2c66affSColin Finck static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
761c2c66affSColin Finck LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
762c2c66affSColin Finck LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
763c2c66affSColin Finck DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
764c2c66affSColin Finck {
765c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParse(iface);
766bcea8c65SAmine Khaldi IDispatch *context = NULL;
767c2c66affSColin Finck vbscode_t *code;
768c2c66affSColin Finck HRESULT hres;
769c2c66affSColin Finck
770c2c66affSColin Finck TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
771c2c66affSColin Finck debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
772c2c66affSColin Finck wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
773c2c66affSColin Finck
774c2c66affSColin Finck if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
775c2c66affSColin Finck return E_UNEXPECTED;
776c2c66affSColin Finck
777bcea8c65SAmine Khaldi if(pstrItemName) {
778bcea8c65SAmine Khaldi context = lookup_named_item(This->ctx, pstrItemName, 0);
779bcea8c65SAmine Khaldi if(!context) {
780bcea8c65SAmine Khaldi WARN("Inknown context %s\n", debugstr_w(pstrItemName));
781bcea8c65SAmine Khaldi return E_INVALIDARG;
782bcea8c65SAmine Khaldi }
783bcea8c65SAmine Khaldi }
784bcea8c65SAmine Khaldi
785*9a0ddc13SAmine Khaldi hres = compile_script(This->ctx, pstrCode, pstrDelimiter, dwFlags, &code);
786c2c66affSColin Finck if(FAILED(hres))
787c2c66affSColin Finck return hres;
788c2c66affSColin Finck
789bcea8c65SAmine Khaldi if(context)
790bcea8c65SAmine Khaldi IDispatch_AddRef(code->context = context);
791bcea8c65SAmine Khaldi
792*9a0ddc13SAmine Khaldi if(!(dwFlags & SCRIPTTEXT_ISEXPRESSION) && !is_started(This)) {
793c2c66affSColin Finck code->pending_exec = TRUE;
794c2c66affSColin Finck return S_OK;
795c2c66affSColin Finck }
796c2c66affSColin Finck
797*9a0ddc13SAmine Khaldi return exec_global_code(This->ctx, code, pvarResult);
798c2c66affSColin Finck }
799c2c66affSColin Finck
800c2c66affSColin Finck static const IActiveScriptParseVtbl VBScriptParseVtbl = {
801c2c66affSColin Finck VBScriptParse_QueryInterface,
802c2c66affSColin Finck VBScriptParse_AddRef,
803c2c66affSColin Finck VBScriptParse_Release,
804c2c66affSColin Finck VBScriptParse_InitNew,
805c2c66affSColin Finck VBScriptParse_AddScriptlet,
806c2c66affSColin Finck VBScriptParse_ParseScriptText
807c2c66affSColin Finck };
808c2c66affSColin Finck
impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 * iface)809c2c66affSColin Finck static inline VBScript *impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 *iface)
810c2c66affSColin Finck {
811c2c66affSColin Finck return CONTAINING_RECORD(iface, VBScript, IActiveScriptParseProcedure2_iface);
812c2c66affSColin Finck }
813c2c66affSColin Finck
VBScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 * iface,REFIID riid,void ** ppv)814c2c66affSColin Finck static HRESULT WINAPI VBScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
815c2c66affSColin Finck {
816c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
817c2c66affSColin Finck return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
818c2c66affSColin Finck }
819c2c66affSColin Finck
VBScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 * iface)820c2c66affSColin Finck static ULONG WINAPI VBScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
821c2c66affSColin Finck {
822c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
823c2c66affSColin Finck return IActiveScript_AddRef(&This->IActiveScript_iface);
824c2c66affSColin Finck }
825c2c66affSColin Finck
VBScriptParseProcedure_Release(IActiveScriptParseProcedure2 * iface)826c2c66affSColin Finck static ULONG WINAPI VBScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
827c2c66affSColin Finck {
828c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
829c2c66affSColin Finck return IActiveScript_Release(&This->IActiveScript_iface);
830c2c66affSColin Finck }
831c2c66affSColin Finck
VBScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 * iface,LPCOLESTR pstrCode,LPCOLESTR pstrFormalParams,LPCOLESTR pstrProcedureName,LPCOLESTR pstrItemName,IUnknown * punkContext,LPCOLESTR pstrDelimiter,CTXARG_T dwSourceContextCookie,ULONG ulStartingLineNumber,DWORD dwFlags,IDispatch ** ppdisp)832c2c66affSColin Finck static HRESULT WINAPI VBScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
833c2c66affSColin Finck LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
834c2c66affSColin Finck LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
835c2c66affSColin Finck CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
836c2c66affSColin Finck {
837c2c66affSColin Finck VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
838*9a0ddc13SAmine Khaldi class_desc_t *desc;
839*9a0ddc13SAmine Khaldi vbdisp_t *vbdisp;
840c2c66affSColin Finck HRESULT hres;
841c2c66affSColin Finck
842c2c66affSColin Finck TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
843c2c66affSColin Finck debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
844c2c66affSColin Finck wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
845c2c66affSColin Finck
846c2c66affSColin Finck if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
847c2c66affSColin Finck return E_UNEXPECTED;
848c2c66affSColin Finck
849*9a0ddc13SAmine Khaldi hres = compile_procedure(This->ctx, pstrCode, pstrDelimiter, dwFlags, &desc);
850c2c66affSColin Finck if(FAILED(hres))
851c2c66affSColin Finck return hres;
852c2c66affSColin Finck
853*9a0ddc13SAmine Khaldi hres = create_vbdisp(desc, &vbdisp);
854*9a0ddc13SAmine Khaldi if(FAILED(hres))
855*9a0ddc13SAmine Khaldi return hres;
856*9a0ddc13SAmine Khaldi
857*9a0ddc13SAmine Khaldi *ppdisp = (IDispatch*)&vbdisp->IDispatchEx_iface;
858*9a0ddc13SAmine Khaldi return S_OK;
859c2c66affSColin Finck }
860c2c66affSColin Finck
861c2c66affSColin Finck static const IActiveScriptParseProcedure2Vtbl VBScriptParseProcedureVtbl = {
862c2c66affSColin Finck VBScriptParseProcedure_QueryInterface,
863c2c66affSColin Finck VBScriptParseProcedure_AddRef,
864c2c66affSColin Finck VBScriptParseProcedure_Release,
865c2c66affSColin Finck VBScriptParseProcedure_ParseProcedureText,
866c2c66affSColin Finck };
867c2c66affSColin Finck
impl_from_IObjectSafety(IObjectSafety * iface)868c2c66affSColin Finck static inline VBScript *impl_from_IObjectSafety(IObjectSafety *iface)
869c2c66affSColin Finck {
870c2c66affSColin Finck return CONTAINING_RECORD(iface, VBScript, IObjectSafety_iface);
871c2c66affSColin Finck }
872c2c66affSColin Finck
VBScriptSafety_QueryInterface(IObjectSafety * iface,REFIID riid,void ** ppv)873c2c66affSColin Finck static HRESULT WINAPI VBScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
874c2c66affSColin Finck {
875c2c66affSColin Finck VBScript *This = impl_from_IObjectSafety(iface);
876c2c66affSColin Finck return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
877c2c66affSColin Finck }
878c2c66affSColin Finck
VBScriptSafety_AddRef(IObjectSafety * iface)879c2c66affSColin Finck static ULONG WINAPI VBScriptSafety_AddRef(IObjectSafety *iface)
880c2c66affSColin Finck {
881c2c66affSColin Finck VBScript *This = impl_from_IObjectSafety(iface);
882c2c66affSColin Finck return IActiveScript_AddRef(&This->IActiveScript_iface);
883c2c66affSColin Finck }
884c2c66affSColin Finck
VBScriptSafety_Release(IObjectSafety * iface)885c2c66affSColin Finck static ULONG WINAPI VBScriptSafety_Release(IObjectSafety *iface)
886c2c66affSColin Finck {
887c2c66affSColin Finck VBScript *This = impl_from_IObjectSafety(iface);
888c2c66affSColin Finck return IActiveScript_Release(&This->IActiveScript_iface);
889c2c66affSColin Finck }
890c2c66affSColin Finck
891c2c66affSColin Finck #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
892c2c66affSColin Finck
VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety * iface,REFIID riid,DWORD * pdwSupportedOptions,DWORD * pdwEnabledOptions)893c2c66affSColin Finck static HRESULT WINAPI VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
894c2c66affSColin Finck DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
895c2c66affSColin Finck {
896c2c66affSColin Finck VBScript *This = impl_from_IObjectSafety(iface);
897c2c66affSColin Finck
898c2c66affSColin Finck TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
899c2c66affSColin Finck
900c2c66affSColin Finck if(!pdwSupportedOptions || !pdwEnabledOptions)
901c2c66affSColin Finck return E_POINTER;
902c2c66affSColin Finck
903c2c66affSColin Finck *pdwSupportedOptions = SUPPORTED_OPTIONS;
904*9a0ddc13SAmine Khaldi *pdwEnabledOptions = This->ctx->safeopt;
905c2c66affSColin Finck return S_OK;
906c2c66affSColin Finck }
907c2c66affSColin Finck
VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety * iface,REFIID riid,DWORD dwOptionSetMask,DWORD dwEnabledOptions)908c2c66affSColin Finck static HRESULT WINAPI VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
909c2c66affSColin Finck DWORD dwOptionSetMask, DWORD dwEnabledOptions)
910c2c66affSColin Finck {
911c2c66affSColin Finck VBScript *This = impl_from_IObjectSafety(iface);
912c2c66affSColin Finck
913c2c66affSColin Finck TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
914c2c66affSColin Finck
915c2c66affSColin Finck if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
916c2c66affSColin Finck return E_FAIL;
917c2c66affSColin Finck
918*9a0ddc13SAmine Khaldi This->ctx->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->ctx->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
919c2c66affSColin Finck return S_OK;
920c2c66affSColin Finck }
921c2c66affSColin Finck
922c2c66affSColin Finck static const IObjectSafetyVtbl VBScriptSafetyVtbl = {
923c2c66affSColin Finck VBScriptSafety_QueryInterface,
924c2c66affSColin Finck VBScriptSafety_AddRef,
925c2c66affSColin Finck VBScriptSafety_Release,
926c2c66affSColin Finck VBScriptSafety_GetInterfaceSafetyOptions,
927c2c66affSColin Finck VBScriptSafety_SetInterfaceSafetyOptions
928c2c66affSColin Finck };
929c2c66affSColin Finck
VBScriptFactory_CreateInstance(IClassFactory * iface,IUnknown * pUnkOuter,REFIID riid,void ** ppv)930c2c66affSColin Finck HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
931c2c66affSColin Finck {
932*9a0ddc13SAmine Khaldi script_ctx_t *ctx;
933c2c66affSColin Finck VBScript *ret;
934c2c66affSColin Finck HRESULT hres;
935c2c66affSColin Finck
936c2c66affSColin Finck TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
937c2c66affSColin Finck
938c2c66affSColin Finck ret = heap_alloc_zero(sizeof(*ret));
939c2c66affSColin Finck if(!ret)
940c2c66affSColin Finck return E_OUTOFMEMORY;
941c2c66affSColin Finck
942c2c66affSColin Finck ret->IActiveScript_iface.lpVtbl = &VBScriptVtbl;
943bcea8c65SAmine Khaldi ret->IActiveScriptDebug_iface.lpVtbl = &VBScriptDebugVtbl;
944c2c66affSColin Finck ret->IActiveScriptParse_iface.lpVtbl = &VBScriptParseVtbl;
945c2c66affSColin Finck ret->IActiveScriptParseProcedure2_iface.lpVtbl = &VBScriptParseProcedureVtbl;
946c2c66affSColin Finck ret->IObjectSafety_iface.lpVtbl = &VBScriptSafetyVtbl;
947c2c66affSColin Finck
948c2c66affSColin Finck ret->ref = 1;
949c2c66affSColin Finck ret->state = SCRIPTSTATE_UNINITIALIZED;
950*9a0ddc13SAmine Khaldi
951*9a0ddc13SAmine Khaldi ctx = ret->ctx = heap_alloc_zero(sizeof(*ctx));
952*9a0ddc13SAmine Khaldi if(!ctx) {
953*9a0ddc13SAmine Khaldi heap_free(ret);
954*9a0ddc13SAmine Khaldi return E_OUTOFMEMORY;
955*9a0ddc13SAmine Khaldi }
956*9a0ddc13SAmine Khaldi
957*9a0ddc13SAmine Khaldi ctx->safeopt = INTERFACE_USES_DISPEX;
958*9a0ddc13SAmine Khaldi heap_pool_init(&ctx->heap);
959*9a0ddc13SAmine Khaldi list_init(&ctx->objects);
960*9a0ddc13SAmine Khaldi list_init(&ctx->code_list);
961*9a0ddc13SAmine Khaldi list_init(&ctx->named_items);
962*9a0ddc13SAmine Khaldi
963*9a0ddc13SAmine Khaldi hres = init_global(ctx);
964*9a0ddc13SAmine Khaldi if(FAILED(hres)) {
965*9a0ddc13SAmine Khaldi IActiveScript_Release(&ret->IActiveScript_iface);
966*9a0ddc13SAmine Khaldi return hres;
967*9a0ddc13SAmine Khaldi }
968c2c66affSColin Finck
969c2c66affSColin Finck hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
970c2c66affSColin Finck IActiveScript_Release(&ret->IActiveScript_iface);
971c2c66affSColin Finck return hres;
972c2c66affSColin Finck }
973c2c66affSColin Finck
974c2c66affSColin Finck typedef struct {
975c2c66affSColin Finck IServiceProvider IServiceProvider_iface;
976c2c66affSColin Finck
977c2c66affSColin Finck LONG ref;
978c2c66affSColin Finck
979c2c66affSColin Finck IServiceProvider *sp;
980c2c66affSColin Finck } AXSite;
981c2c66affSColin Finck
impl_from_IServiceProvider(IServiceProvider * iface)982c2c66affSColin Finck static inline AXSite *impl_from_IServiceProvider(IServiceProvider *iface)
983c2c66affSColin Finck {
984c2c66affSColin Finck return CONTAINING_RECORD(iface, AXSite, IServiceProvider_iface);
985c2c66affSColin Finck }
986c2c66affSColin Finck
AXSite_QueryInterface(IServiceProvider * iface,REFIID riid,void ** ppv)987c2c66affSColin Finck static HRESULT WINAPI AXSite_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
988c2c66affSColin Finck {
989c2c66affSColin Finck AXSite *This = impl_from_IServiceProvider(iface);
990c2c66affSColin Finck
991c2c66affSColin Finck if(IsEqualGUID(&IID_IUnknown, riid)) {
992c2c66affSColin Finck TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
993c2c66affSColin Finck *ppv = &This->IServiceProvider_iface;
994c2c66affSColin Finck }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
995c2c66affSColin Finck TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
996c2c66affSColin Finck *ppv = &This->IServiceProvider_iface;
997c2c66affSColin Finck }else {
998c2c66affSColin Finck TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
999c2c66affSColin Finck *ppv = NULL;
1000c2c66affSColin Finck return E_NOINTERFACE;
1001c2c66affSColin Finck }
1002c2c66affSColin Finck
1003c2c66affSColin Finck IUnknown_AddRef((IUnknown*)*ppv);
1004c2c66affSColin Finck return S_OK;
1005c2c66affSColin Finck }
1006c2c66affSColin Finck
AXSite_AddRef(IServiceProvider * iface)1007c2c66affSColin Finck static ULONG WINAPI AXSite_AddRef(IServiceProvider *iface)
1008c2c66affSColin Finck {
1009c2c66affSColin Finck AXSite *This = impl_from_IServiceProvider(iface);
1010c2c66affSColin Finck LONG ref = InterlockedIncrement(&This->ref);
1011c2c66affSColin Finck
1012c2c66affSColin Finck TRACE("(%p) ref=%d\n", This, ref);
1013c2c66affSColin Finck
1014c2c66affSColin Finck return ref;
1015c2c66affSColin Finck }
1016c2c66affSColin Finck
AXSite_Release(IServiceProvider * iface)1017c2c66affSColin Finck static ULONG WINAPI AXSite_Release(IServiceProvider *iface)
1018c2c66affSColin Finck {
1019c2c66affSColin Finck AXSite *This = impl_from_IServiceProvider(iface);
1020c2c66affSColin Finck LONG ref = InterlockedDecrement(&This->ref);
1021c2c66affSColin Finck
1022c2c66affSColin Finck TRACE("(%p) ref=%d\n", This, ref);
1023c2c66affSColin Finck
1024c2c66affSColin Finck if(!ref)
1025c2c66affSColin Finck heap_free(This);
1026c2c66affSColin Finck
1027c2c66affSColin Finck return ref;
1028c2c66affSColin Finck }
1029c2c66affSColin Finck
AXSite_QueryService(IServiceProvider * iface,REFGUID guidService,REFIID riid,void ** ppv)1030c2c66affSColin Finck static HRESULT WINAPI AXSite_QueryService(IServiceProvider *iface,
1031c2c66affSColin Finck REFGUID guidService, REFIID riid, void **ppv)
1032c2c66affSColin Finck {
1033c2c66affSColin Finck AXSite *This = impl_from_IServiceProvider(iface);
1034c2c66affSColin Finck
1035c2c66affSColin Finck TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1036c2c66affSColin Finck
1037c2c66affSColin Finck return IServiceProvider_QueryService(This->sp, guidService, riid, ppv);
1038c2c66affSColin Finck }
1039c2c66affSColin Finck
1040c2c66affSColin Finck static IServiceProviderVtbl AXSiteVtbl = {
1041c2c66affSColin Finck AXSite_QueryInterface,
1042c2c66affSColin Finck AXSite_AddRef,
1043c2c66affSColin Finck AXSite_Release,
1044c2c66affSColin Finck AXSite_QueryService
1045c2c66affSColin Finck };
1046c2c66affSColin Finck
create_ax_site(script_ctx_t * ctx)1047c2c66affSColin Finck IUnknown *create_ax_site(script_ctx_t *ctx)
1048c2c66affSColin Finck {
1049c2c66affSColin Finck IServiceProvider *sp;
1050c2c66affSColin Finck AXSite *ret;
1051c2c66affSColin Finck HRESULT hres;
1052c2c66affSColin Finck
1053c2c66affSColin Finck hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
1054c2c66affSColin Finck if(FAILED(hres)) {
1055c2c66affSColin Finck ERR("Could not get IServiceProvider iface: %08x\n", hres);
1056c2c66affSColin Finck return NULL;
1057c2c66affSColin Finck }
1058c2c66affSColin Finck
1059c2c66affSColin Finck ret = heap_alloc(sizeof(*ret));
1060c2c66affSColin Finck if(!ret) {
1061c2c66affSColin Finck IServiceProvider_Release(sp);
1062c2c66affSColin Finck return NULL;
1063c2c66affSColin Finck }
1064c2c66affSColin Finck
1065c2c66affSColin Finck ret->IServiceProvider_iface.lpVtbl = &AXSiteVtbl;
1066c2c66affSColin Finck ret->ref = 1;
1067c2c66affSColin Finck ret->sp = sp;
1068c2c66affSColin Finck
1069c2c66affSColin Finck return (IUnknown*)&ret->IServiceProvider_iface;
1070c2c66affSColin Finck }
1071