ReactOS  0.4.13-dev-242-g611e6d7
vbscript.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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 <assert.h>
21 
22 #include "vbscript.h"
23 #include "objsafe.h"
24 
25 #include "wine/debug.h"
26 
28 
29 #ifdef _WIN64
30 
31 #define CTXARG_T DWORDLONG
32 #define IActiveScriptDebugVtbl IActiveScriptDebug64Vtbl
33 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
34 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
35 
36 #else
37 
38 #define CTXARG_T DWORD
39 #define IActiveScriptDebugVtbl IActiveScriptDebug32Vtbl
40 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
41 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
42 
43 #endif
44 
45 struct VBScript {
47  IActiveScriptDebug IActiveScriptDebug_iface;
48  IActiveScriptParse IActiveScriptParse_iface;
49  IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface;
51 
53 
60 };
61 
63 {
64  if(This->state == state)
65  return;
66 
67  This->state = state;
68  if(This->site)
69  IActiveScriptSite_OnStateChange(This->site, state);
70 }
71 
72 static inline BOOL is_started(VBScript *This)
73 {
74  return This->state == SCRIPTSTATE_STARTED
75  || This->state == SCRIPTSTATE_CONNECTED
76  || This->state == SCRIPTSTATE_DISCONNECTED;
77 }
78 
80 {
81  HRESULT hres;
82 
83  code->pending_exec = FALSE;
84 
85  IActiveScriptSite_OnEnterScript(ctx->site);
86  hres = exec_script(ctx, &code->main_code, NULL, NULL, NULL);
87  IActiveScriptSite_OnLeaveScript(ctx->site);
88 
89  return hres;
90 }
91 
92 static void exec_queued_code(script_ctx_t *ctx)
93 {
94  vbscode_t *iter;
95 
97  if(iter->pending_exec)
98  exec_global_code(ctx, iter);
99  }
100 }
101 
103 {
105  HRESULT hres;
106 
108  if((item->flags & flags) == flags && !strcmpiW(item->name, name)) {
109  if(!item->disp) {
110  IUnknown *unk;
111 
112  hres = IActiveScriptSite_GetItemInfo(ctx->site, item->name,
113  SCRIPTINFO_IUNKNOWN, &unk, NULL);
114  if(FAILED(hres)) {
115  WARN("GetItemInfo failed: %08x\n", hres);
116  continue;
117  }
118 
119  hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
120  IUnknown_Release(unk);
121  if(FAILED(hres)) {
122  WARN("object does not implement IDispatch\n");
123  continue;
124  }
125  }
126 
127  return item->disp;
128  }
129  }
130 
131  return NULL;
132 }
133 
135 {
136  HRESULT hres;
137 
138  This->ctx->lcid = This->lcid;
139 
140  hres = init_global(This->ctx);
141  if(FAILED(hres))
142  return hres;
143 
144  IActiveScriptSite_AddRef(This->site);
145  This->ctx->site = This->site;
146 
148  return S_OK;
149 }
150 
151 static void release_script(script_ctx_t *ctx)
152 {
153  class_desc_t *class_desc;
154 
155  collect_objects(ctx);
156 
158  ctx->global_vars = NULL;
159 
160  while(!list_empty(&ctx->named_items)) {
162 
163  list_remove(&iter->entry);
164  if(iter->disp)
165  IDispatch_Release(iter->disp);
166  heap_free(iter->name);
167  heap_free(iter);
168  }
169 
170  while(ctx->procs) {
171  class_desc = ctx->procs;
172  ctx->procs = class_desc->next;
173 
174  heap_free(class_desc);
175  }
176 
177  if(ctx->host_global) {
178  IDispatch_Release(ctx->host_global);
179  ctx->host_global = NULL;
180  }
181 
182  if(ctx->secmgr) {
183  IInternetHostSecurityManager_Release(ctx->secmgr);
184  ctx->secmgr = NULL;
185  }
186 
187  if(ctx->site) {
188  IActiveScriptSite_Release(ctx->site);
189  ctx->site = NULL;
190  }
191 
192  if(ctx->err_obj) {
193  IDispatchEx_Release(&ctx->err_obj->IDispatchEx_iface);
194  ctx->err_obj = NULL;
195  }
196 
197  if(ctx->global_obj) {
198  IDispatchEx_Release(&ctx->global_obj->IDispatchEx_iface);
199  ctx->global_obj = NULL;
200  }
201 
202  if(ctx->script_obj) {
203  ScriptDisp *script_obj = ctx->script_obj;
204 
205  ctx->script_obj = NULL;
206  script_obj->ctx = NULL;
207  IDispatchEx_Release(&script_obj->IDispatchEx_iface);
208  }
209 
210  heap_pool_free(&ctx->heap);
211  heap_pool_init(&ctx->heap);
212 }
213 
214 static void destroy_script(script_ctx_t *ctx)
215 {
216  while(!list_empty(&ctx->code_list))
218 
219  release_script(ctx);
220  heap_free(ctx);
221 }
222 
224 {
225  switch(This->state) {
229  return;
230  /* FALLTHROUGH */
231  case SCRIPTSTATE_STARTED:
233  if(This->state == SCRIPTSTATE_DISCONNECTED)
236  break;
237  /* FALLTHROUGH */
241 
242  if(This->site) {
243  IActiveScriptSite_Release(This->site);
244  This->site = NULL;
245  }
246 
247  if(This->ctx)
248  release_script(This->ctx);
249 
250  This->thread_id = 0;
251  break;
252  case SCRIPTSTATE_CLOSED:
253  break;
255  }
256 }
257 
259 {
260  return CONTAINING_RECORD(iface, VBScript, IActiveScript_iface);
261 }
262 
264 {
266 
267  if(IsEqualGUID(riid, &IID_IUnknown)) {
268  TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
269  *ppv = &This->IActiveScript_iface;
270  }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
271  TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
272  *ppv = &This->IActiveScript_iface;
273  }else if(IsEqualGUID(riid, &IID_IActiveScriptDebug)) {
274  TRACE("(%p)->(IID_IActiveScriptDebug %p)\n", This, ppv);
275  *ppv = &This->IActiveScriptDebug_iface;
276  }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
277  TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
278  *ppv = &This->IActiveScriptParse_iface;
279  }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
280  TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
281  *ppv = &This->IActiveScriptParseProcedure2_iface;
282  }else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
283  TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
284  *ppv = &This->IObjectSafety_iface;
285  }else {
286  FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
287  *ppv = NULL;
288  return E_NOINTERFACE;
289  }
290 
291  IUnknown_AddRef((IUnknown*)*ppv);
292  return S_OK;
293 }
294 
296 {
299 
300  TRACE("(%p) ref=%d\n", This, ref);
301 
302  return ref;
303 }
304 
306 {
309 
310  TRACE("(%p) ref=%d\n", iface, ref);
311 
312  if(!ref) {
313  if(This->ctx) {
315  destroy_script(This->ctx);
316  This->ctx = NULL;
317  }
318  if(This->site)
319  IActiveScriptSite_Release(This->site);
320  heap_free(This);
321  }
322 
323  return ref;
324 }
325 
327 {
329  LCID lcid;
330  HRESULT hres;
331 
332  TRACE("(%p)->(%p)\n", This, pass);
333 
334  if(!pass)
335  return E_POINTER;
336 
337  if(This->site)
338  return E_UNEXPECTED;
339 
340  if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
341  return E_UNEXPECTED;
342 
343  This->site = pass;
344  IActiveScriptSite_AddRef(This->site);
345 
346  hres = IActiveScriptSite_GetLCID(This->site, &lcid);
347  if(hres == S_OK)
348  This->lcid = lcid;
349 
350  return This->ctx ? set_ctx_site(This) : S_OK;
351 }
352 
354  void **ppvObject)
355 {
357  FIXME("(%p)->()\n", This);
358  return E_NOTIMPL;
359 }
360 
362 {
364 
365  TRACE("(%p)->(%d)\n", This, ss);
366 
367  if(This->thread_id && GetCurrentThreadId() != This->thread_id)
368  return E_UNEXPECTED;
369 
371  if(This->state == SCRIPTSTATE_CLOSED)
372  return E_UNEXPECTED;
373 
375  return S_OK;
376  }
377 
378  if(!This->ctx)
379  return E_UNEXPECTED;
380 
381  switch(ss) {
382  case SCRIPTSTATE_STARTED:
383  case SCRIPTSTATE_CONNECTED: /* FIXME */
384  if(This->state == SCRIPTSTATE_CLOSED)
385  return E_UNEXPECTED;
386 
387  exec_queued_code(This->ctx);
388  break;
390  FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
391  return S_OK;
393  FIXME("unimplemented SCRIPTSTATE_DISCONNECTED\n");
394  return S_OK;
395  default:
396  FIXME("unimplemented state %d\n", ss);
397  return E_NOTIMPL;
398  }
399 
400  change_state(This, ss);
401  return S_OK;
402 }
403 
405 {
407 
408  TRACE("(%p)->(%p)\n", This, pssState);
409 
410  if(!pssState)
411  return E_POINTER;
412 
413  if(This->thread_id && This->thread_id != GetCurrentThreadId())
414  return E_UNEXPECTED;
415 
416  *pssState = This->state;
417  return S_OK;
418 }
419 
421 {
423 
424  TRACE("(%p)->()\n", This);
425 
426  if(This->thread_id && This->thread_id != GetCurrentThreadId())
427  return E_UNEXPECTED;
428 
430  return S_OK;
431 }
432 
433 static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
434 {
437  IDispatch *disp = NULL;
438  HRESULT hres;
439 
440  TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
441 
442  if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->state == SCRIPTSTATE_CLOSED)
443  return E_UNEXPECTED;
444 
445  if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
446  IUnknown *unk;
447 
448  hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
449  if(FAILED(hres)) {
450  WARN("GetItemInfo failed: %08x\n", hres);
451  return hres;
452  }
453 
454  hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
455  IUnknown_Release(unk);
456  if(FAILED(hres)) {
457  WARN("object does not implement IDispatch\n");
458  return hres;
459  }
460 
461  if(This->ctx->host_global)
462  IDispatch_Release(This->ctx->host_global);
463  IDispatch_AddRef(disp);
464  This->ctx->host_global = disp;
465  }
466 
467  item = heap_alloc(sizeof(*item));
468  if(!item) {
469  if(disp)
470  IDispatch_Release(disp);
471  return E_OUTOFMEMORY;
472  }
473 
474  item->disp = disp;
475  item->flags = dwFlags;
476  item->name = heap_strdupW(pstrName);
477  if(!item->name) {
478  if(disp)
479  IDispatch_Release(disp);
480  heap_free(item);
481  return E_OUTOFMEMORY;
482  }
483 
484  list_add_tail(&This->ctx->named_items, &item->entry);
485  return S_OK;
486 }
487 
489  DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
490 {
492  FIXME("(%p)->()\n", This);
493  return E_NOTIMPL;
494 }
495 
496 static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName, IDispatch **ppdisp)
497 {
499 
500  TRACE("(%p)->(%p)\n", This, ppdisp);
501 
502  if(!ppdisp)
503  return E_POINTER;
504 
505  if(This->thread_id != GetCurrentThreadId() || !This->ctx || !This->ctx->script_obj) {
506  *ppdisp = NULL;
507  return E_UNEXPECTED;
508  }
509 
510  *ppdisp = (IDispatch*)&This->ctx->script_obj->IDispatchEx_iface;
511  IDispatch_AddRef(*ppdisp);
512  return S_OK;
513 }
514 
516  SCRIPTTHREADID *pstridThread)
517 {
519  FIXME("(%p)->()\n", This);
520  return E_NOTIMPL;
521 }
522 
524  DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
525 {
527  FIXME("(%p)->()\n", This);
528  return E_NOTIMPL;
529 }
530 
532  SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
533 {
535  FIXME("(%p)->()\n", This);
536  return E_NOTIMPL;
537 }
538 
540  SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
541 {
543  FIXME("(%p)->()\n", This);
544  return E_NOTIMPL;
545 }
546 
548 {
550  FIXME("(%p)->()\n", This);
551  return E_NOTIMPL;
552 }
553 
554 static const IActiveScriptVtbl VBScriptVtbl = {
571 };
572 
573 static inline VBScript *impl_from_IActiveScriptDebug(IActiveScriptDebug *iface)
574 {
575  return CONTAINING_RECORD(iface, VBScript, IActiveScriptDebug_iface);
576 }
577 
578 static HRESULT WINAPI VBScriptDebug_QueryInterface(IActiveScriptDebug *iface, REFIID riid, void **ppv)
579 {
581  return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
582 }
583 
584 static ULONG WINAPI VBScriptDebug_AddRef(IActiveScriptDebug *iface)
585 {
587  return IActiveScript_AddRef(&This->IActiveScript_iface);
588 }
589 
590 static ULONG WINAPI VBScriptDebug_Release(IActiveScriptDebug *iface)
591 {
593  return IActiveScript_Release(&This->IActiveScript_iface);
594 }
595 
596 static HRESULT WINAPI VBScriptDebug_GetScriptTextAttributes(IActiveScriptDebug *iface,
597  LPCOLESTR code, ULONG len, LPCOLESTR delimiter, DWORD flags, SOURCE_TEXT_ATTR *attr)
598 {
600  FIXME("(%p)->(%s %u %s %#x %p)\n", This, debugstr_w(code), len,
602  return E_NOTIMPL;
603 }
604 
605 static HRESULT WINAPI VBScriptDebug_GetScriptletTextAttributes(IActiveScriptDebug *iface,
606  LPCOLESTR code, ULONG len, LPCOLESTR delimiter, DWORD flags, SOURCE_TEXT_ATTR *attr)
607 {
609  FIXME("(%p)->(%s %u %s %#x %p)\n", This, debugstr_w(code), len,
611  return E_NOTIMPL;
612 }
613 
614 static HRESULT WINAPI VBScriptDebug_EnumCodeContextsOfPosition(IActiveScriptDebug *iface,
616 {
618  FIXME("(%p)->(%s %u %u %p)\n", This, wine_dbgstr_longlong(source), offset, len, ret);
619  return E_NOTIMPL;
620 }
621 
629 };
630 
631 static inline VBScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
632 {
633  return CONTAINING_RECORD(iface, VBScript, IActiveScriptParse_iface);
634 }
635 
636 static HRESULT WINAPI VBScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
637 {
639  return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
640 }
641 
642 static ULONG WINAPI VBScriptParse_AddRef(IActiveScriptParse *iface)
643 {
645  return IActiveScript_AddRef(&This->IActiveScript_iface);
646 }
647 
648 static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
649 {
651  return IActiveScript_Release(&This->IActiveScript_iface);
652 }
653 
654 static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
655 {
657  script_ctx_t *ctx, *old_ctx;
658 
659  TRACE("(%p)\n", This);
660 
661  if(This->ctx)
662  return E_UNEXPECTED;
663 
664  ctx = heap_alloc_zero(sizeof(script_ctx_t));
665  if(!ctx)
666  return E_OUTOFMEMORY;
667 
668  ctx->safeopt = This->safeopt;
669  heap_pool_init(&ctx->heap);
670  list_init(&ctx->objects);
671  list_init(&ctx->code_list);
672  list_init(&ctx->named_items);
673 
674  old_ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
675  if(old_ctx) {
676  destroy_script(ctx);
677  return E_UNEXPECTED;
678  }
679 
680  return This->site ? set_ctx_site(This) : S_OK;
681 }
682 
683 static HRESULT WINAPI VBScriptParse_AddScriptlet(IActiveScriptParse *iface,
684  LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
685  LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
686  CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
687  BSTR *pbstrName, EXCEPINFO *pexcepinfo)
688 {
690  FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
691  debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
692  debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
693  ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
694  return E_NOTIMPL;
695 }
696 
697 static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
698  LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
699  LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
700  DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
701 {
704  vbscode_t *code;
705  HRESULT hres;
706 
707  TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
708  debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
709  wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
710 
711  if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
712  return E_UNEXPECTED;
713 
714  if(pstrItemName) {
715  context = lookup_named_item(This->ctx, pstrItemName, 0);
716  if(!context) {
717  WARN("Inknown context %s\n", debugstr_w(pstrItemName));
718  return E_INVALIDARG;
719  }
720  }
721 
722  hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
723  if(FAILED(hres))
724  return hres;
725 
726  if(context)
727  IDispatch_AddRef(code->context = context);
728 
729  if(!is_started(This)) {
730  code->pending_exec = TRUE;
731  return S_OK;
732  }
733 
734  return exec_global_code(This->ctx, code);
735 }
736 
744 };
745 
746 static inline VBScript *impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 *iface)
747 {
748  return CONTAINING_RECORD(iface, VBScript, IActiveScriptParseProcedure2_iface);
749 }
750 
751 static HRESULT WINAPI VBScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
752 {
754  return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
755 }
756 
757 static ULONG WINAPI VBScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
758 {
760  return IActiveScript_AddRef(&This->IActiveScript_iface);
761 }
762 
763 static ULONG WINAPI VBScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
764 {
766  return IActiveScript_Release(&This->IActiveScript_iface);
767 }
768 
769 static HRESULT WINAPI VBScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
770  LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
771  LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
772  CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
773 {
775  vbscode_t *code;
776  HRESULT hres;
777 
778  TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
779  debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
780  wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
781 
782  if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
783  return E_UNEXPECTED;
784 
785  hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
786  if(FAILED(hres))
787  return hres;
788 
789  return create_procedure_disp(This->ctx, code, ppdisp);
790 }
791 
797 };
798 
800 {
801  return CONTAINING_RECORD(iface, VBScript, IObjectSafety_iface);
802 }
803 
805 {
807  return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
808 }
809 
811 {
813  return IActiveScript_AddRef(&This->IActiveScript_iface);
814 }
815 
817 {
819  return IActiveScript_Release(&This->IActiveScript_iface);
820 }
821 
822 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
823 
825  DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
826 {
828 
829  TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
830 
831  if(!pdwSupportedOptions || !pdwEnabledOptions)
832  return E_POINTER;
833 
834  *pdwSupportedOptions = SUPPORTED_OPTIONS;
835  *pdwEnabledOptions = This->safeopt;
836  return S_OK;
837 }
838 
840  DWORD dwOptionSetMask, DWORD dwEnabledOptions)
841 {
843 
844  TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
845 
846  if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
847  return E_FAIL;
848 
849  This->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
850  return S_OK;
851 }
852 
853 static const IObjectSafetyVtbl VBScriptSafetyVtbl = {
859 };
860 
862 {
863  VBScript *ret;
864  HRESULT hres;
865 
866  TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
867 
868  ret = heap_alloc_zero(sizeof(*ret));
869  if(!ret)
870  return E_OUTOFMEMORY;
871 
872  ret->IActiveScript_iface.lpVtbl = &VBScriptVtbl;
873  ret->IActiveScriptDebug_iface.lpVtbl = &VBScriptDebugVtbl;
874  ret->IActiveScriptParse_iface.lpVtbl = &VBScriptParseVtbl;
875  ret->IActiveScriptParseProcedure2_iface.lpVtbl = &VBScriptParseProcedureVtbl;
876  ret->IObjectSafety_iface.lpVtbl = &VBScriptSafetyVtbl;
877 
878  ret->ref = 1;
880  ret->safeopt = INTERFACE_USES_DISPEX;
881 
882  hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
883  IActiveScript_Release(&ret->IActiveScript_iface);
884  return hres;
885 }
886 
887 typedef struct {
888  IServiceProvider IServiceProvider_iface;
889 
890  LONG ref;
891 
893 } AXSite;
894 
896 {
897  return CONTAINING_RECORD(iface, AXSite, IServiceProvider_iface);
898 }
899 
901 {
903 
904  if(IsEqualGUID(&IID_IUnknown, riid)) {
905  TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
906  *ppv = &This->IServiceProvider_iface;
907  }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
908  TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
909  *ppv = &This->IServiceProvider_iface;
910  }else {
911  TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
912  *ppv = NULL;
913  return E_NOINTERFACE;
914  }
915 
916  IUnknown_AddRef((IUnknown*)*ppv);
917  return S_OK;
918 }
919 
921 {
924 
925  TRACE("(%p) ref=%d\n", This, ref);
926 
927  return ref;
928 }
929 
931 {
934 
935  TRACE("(%p) ref=%d\n", This, ref);
936 
937  if(!ref)
938  heap_free(This);
939 
940  return ref;
941 }
942 
944  REFGUID guidService, REFIID riid, void **ppv)
945 {
947 
948  TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
949 
950  return IServiceProvider_QueryService(This->sp, guidService, riid, ppv);
951 }
952 
953 static IServiceProviderVtbl AXSiteVtbl = {
958 };
959 
961 {
963  AXSite *ret;
964  HRESULT hres;
965 
966  hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
967  if(FAILED(hres)) {
968  ERR("Could not get IServiceProvider iface: %08x\n", hres);
969  return NULL;
970  }
971 
972  ret = heap_alloc(sizeof(*ret));
973  if(!ret) {
974  IServiceProvider_Release(sp);
975  return NULL;
976  }
977 
978  ret->IServiceProvider_iface.lpVtbl = &AXSiteVtbl;
979  ret->ref = 1;
980  ret->sp = sp;
981 
982  return (IUnknown*)&ret->IServiceProvider_iface;
983 }
DWORD safeopt
Definition: vbscript.c:54
script_ctx_t * ctx
Definition: vbscript.c:57
static void release_script(script_ctx_t *ctx)
Definition: vbscript.c:151
static BOOL is_started(VBScript *This)
Definition: vbscript.c:72
#define DEFAULT_UNREACHABLE
static AXSite * impl_from_IServiceProvider(IServiceProvider *iface)
Definition: vbscript.c:895
disp
Definition: i386-dis.c:3181
static HRESULT WINAPI VBScriptDebug_GetScriptTextAttributes(IActiveScriptDebug *iface, LPCOLESTR code, ULONG len, LPCOLESTR delimiter, DWORD flags, SOURCE_TEXT_ATTR *attr)
Definition: vbscript.c:596
heap_pool_t heap
Definition: vbscript.h:207
static ULONG WINAPI VBScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
Definition: vbscript.c:757
static BOOL CALLBACK collect_objects(LPCDIDEVICEOBJECTINSTANCEW lpddo, LPVOID pvRef)
Definition: config.c:50
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
static void exec_queued_code(script_ctx_t *ctx)
Definition: vbscript.c:92
#define E_NOINTERFACE
Definition: winerror.h:2364
ScriptDisp * script_obj
Definition: vbscript.h:192
static const IObjectSafetyVtbl VBScriptSafetyVtbl
Definition: vbscript.c:853
HRESULT create_procedure_disp(script_ctx_t *ctx, vbscode_t *code, IDispatch **ret)
Definition: vbdisp.c:639
static HRESULT WINAPI VBScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
Definition: vbscript.c:547
Definition: scsiwmi.h:51
void release_vbscode(vbscode_t *code)
Definition: compile.c:1740
Definition: http.c:6587
LCID lcid
Definition: vbscript.c:59
static ULONG WINAPI VBScriptParse_AddRef(IActiveScriptParse *iface)
Definition: vbscript.c:642
REFIID riid
Definition: precomp.h:44
static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
Definition: vbscript.c:326
static const IActiveScriptParseProcedure2Vtbl VBScriptParseProcedureVtbl
Definition: vbscript.c:792
script_ctx_t * ctx
Definition: vbscript.h:151
struct list objects
Definition: vbscript.h:209
#define WARN(fmt,...)
Definition: debug.h:111
dynamic_var_t * global_vars
Definition: vbscript.h:202
GLintptr offset
Definition: glext.h:5920
static HRESULT WINAPI VBScriptDebug_GetScriptletTextAttributes(IActiveScriptDebug *iface, LPCOLESTR code, ULONG len, LPCOLESTR delimiter, DWORD flags, SOURCE_TEXT_ATTR *attr)
Definition: vbscript.c:605
REFIID LPVOID * ppv
Definition: atlbase.h:39
IObjectSafety IObjectSafety_iface
Definition: vbscript.c:50
IUnknown * create_ax_site(script_ctx_t *ctx)
Definition: vbscript.c:960
static HRESULT WINAPI VBScript_GetCurrentScriptThreadID(IActiveScript *iface, SCRIPTTHREADID *pstridThread)
Definition: vbscript.c:515
#define InterlockedCompareExchange
Definition: interlocked.h:104
SCRIPTSTATE state
Definition: vbscript.c:55
DWORD SCRIPTTHREADID
Definition: activscp.idl:74
DWORD LCID
Definition: nls.h:13
void release_dynamic_vars(dynamic_var_t *var)
Definition: interp.c:2022
static void decrease_state(VBScript *This, SCRIPTSTATE state)
Definition: vbscript.c:223
OLECHAR * BSTR
Definition: compat.h:1934
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbscript.c:861
LONG thread_id
Definition: vbscript.c:58
static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
Definition: vbscript.c:361
#define E_FAIL
Definition: ddrawi.h:102
static ULONG WINAPI VBScriptSafety_AddRef(IObjectSafety *iface)
Definition: vbscript.c:810
Definition: send.c:47
IDispatch * host_global
Definition: jscript.h:424
IActiveScriptParse IActiveScriptParse_iface
Definition: vbscript.c:48
static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
Definition: vbscript.c:654
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static const IActiveScriptVtbl VBScriptVtbl
Definition: vbscript.c:554
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
#define CTXARG_T
Definition: vbscript.c:38
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
pass
Definition: typegen.h:24
static HRESULT WINAPI VBScript_InterruptScriptThread(IActiveScript *iface, SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
Definition: vbscript.c:539
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
static HRESULT WINAPI VBScriptDebug_EnumCodeContextsOfPosition(IActiveScriptDebug *iface, CTXARG_T source, ULONG offset, ULONG len, IEnumDebugCodeContexts **ret)
Definition: vbscript.c:614
GLenum GLint ref
Definition: glext.h:6028
LONG ref
Definition: vbscript.c:52
#define FIXME(fmt,...)
Definition: debug.h:110
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
static ULONG WINAPI VBScript_AddRef(IActiveScript *iface)
Definition: vbscript.c:295
static VBScript * impl_from_IActiveScriptParse(IActiveScriptParse *iface)
Definition: vbscript.c:631
static ULONG WINAPI VBScriptSafety_Release(IObjectSafety *iface)
Definition: vbscript.c:816
#define E_INVALIDARG
Definition: ddrawi.h:101
static ULONG WINAPI VBScript_Release(IActiveScript *iface)
Definition: vbscript.c:305
smooth NULL
Definition: ftsmooth.c:416
const char * delimiter
Definition: string.c:1523
static ULONG WINAPI VBScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
Definition: vbscript.c:763
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, bytecode_t **ret)
Definition: compile.c:2458
vbdisp_t * err_obj
Definition: vbscript.h:198
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:420
static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface, LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine, DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
Definition: vbscript.c:697
static HRESULT WINAPI 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)
Definition: vbscript.c:683
static ULONG WINAPI AXSite_AddRef(IServiceProvider *iface)
Definition: vbscript.c:920
IActiveScript IActiveScript_iface
Definition: vbscript.c:46
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
static HRESULT WINAPI VBScriptDebug_QueryInterface(IActiveScriptDebug *iface, REFIID riid, void **ppv)
Definition: vbscript.c:578
WORD SOURCE_TEXT_ATTR
Definition: activdbg.idl:83
static VBScript * impl_from_IActiveScriptDebug(IActiveScriptDebug *iface)
Definition: vbscript.c:573
#define TRACE(s)
Definition: solgame.cpp:4
static HRESULT WINAPI VBScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
Definition: vbscript.c:804
HRESULT hres
Definition: protocol.c:465
static HRESULT set_ctx_site(VBScript *This)
Definition: vbscript.c:134
class_desc_t * procs
Definition: vbscript.h:205
DWORD safeopt
Definition: jscript.h:414
static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName, IDispatch **ppdisp)
Definition: vbscript.c:496
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IActiveScriptDebugVtbl
Definition: vbscript.c:39
static HRESULT WINAPI AXSite_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
Definition: vbscript.c:900
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
enum tagSCRIPTTHREADSTATE SCRIPTTHREADSTATE
static HRESULT WINAPI VBScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
Definition: vbscript.c:636
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT init_global(script_ctx_t *ctx)
Definition: global.c:1105
struct _class_desc_t * next
Definition: vbscript.h:126
static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
Definition: vbscript.c:433
Definition: cookie.c:170
static HRESULT WINAPI VBScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
Definition: vbscript.c:751
GLbitfield flags
Definition: glext.h:7161
static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code)
Definition: vbscript.c:79
IDispatchEx IDispatchEx_iface
Definition: vbscript.h:130
const GUID IID_IDispatch
static HRESULT WINAPI 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)
Definition: vbscript.c:769
int ret
static ULONG WINAPI VBScriptDebug_AddRef(IActiveScriptDebug *iface)
Definition: vbscript.c:584
#define InterlockedDecrement
Definition: armddk.h:52
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
static int state
Definition: maze.c:121
static HRESULT WINAPI VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
Definition: vbscript.c:824
uint32_t entry
Definition: isohybrid.c:63
GLenum GLsizei len
Definition: glext.h:6722
REFIID LPVOID * ppvObject
Definition: precomp.h:44
static void change_state(VBScript *This, SCRIPTSTATE state)
Definition: vbscript.c:62
int code
Definition: i386-dis.c:3591
void heap_pool_init(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:69
static HRESULT WINAPI VBScript_Close(IActiveScript *iface)
Definition: vbscript.c:420
static VBScript * impl_from_IActiveScript(IActiveScript *iface)
Definition: vbscript.c:258
static HRESULT WINAPI VBScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
Definition: vbscript.c:263
#define strcmpiW(s1, s2)
Definition: unicode.h:39
BOOL pending_exec
Definition: vbscript.h:349
struct list entry
Definition: vbscript.h:67
#define ERR(fmt,...)
Definition: debug.h:109
static HRESULT WINAPI VBScript_GetScriptThreadState(IActiveScript *iface, SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
Definition: vbscript.c:531
struct stdole::EXCEPINFO EXCEPINFO
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
#define S_OK
Definition: intsafe.h:59
HRESULT exec_script(HTMLInnerWindow *, const WCHAR *, const WCHAR *, VARIANT *) DECLSPEC_HIDDEN
Definition: script.c:1245
static VBScript * impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 *iface)
Definition: vbscript.c:746
#define InterlockedIncrement
Definition: armddk.h:53
static ATOM item
Definition: dde.c:856
static ULONG WINAPI VBScriptDebug_Release(IActiveScriptDebug *iface)
Definition: vbscript.c:590
LPWSTR name
Definition: jscript.h:360
WINE_DEFAULT_DEBUG_CHANNEL(vbscript)
#define E_NOTIMPL
Definition: ddrawi.h:99
IActiveScriptSite * site
Definition: jscript.h:412
struct list code_list
Definition: vbscript.h:210
IDispatch * lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flags)
Definition: vbscript.c:102
SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION enum tagSCRIPTSTATE SCRIPTSTATE
IDispatch * disp
Definition: jscript.h:358
IInternetHostSecurityManager * secmgr
Definition: jscript.h:413
static const IActiveScriptDebugVtbl VBScriptDebugVtbl
Definition: vbscript.c:622
#define IActiveScriptParseProcedure2Vtbl
Definition: vbscript.c:41
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
IDispatchEx IDispatchEx_iface
Definition: vbscript.h:144
#define SUPPORTED_OPTIONS
Definition: vbscript.c:822
#define E_UNEXPECTED
Definition: winerror.h:2456
IActiveScriptSite * site
Definition: vbscript.c:56
void heap_pool_free(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:167
Definition: name.c:36
static VBScript * impl_from_IObjectSafety(IObjectSafety *iface)
Definition: vbscript.c:799
static HRESULT WINAPI VBScript_GetScriptThreadID(IActiveScript *iface, DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
Definition: vbscript.c:523
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
static HRESULT WINAPI AXSite_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
Definition: vbscript.c:943
IActiveScriptDebug IActiveScriptDebug_iface
Definition: vbscript.c:47
unsigned int ULONG
Definition: retypes.h:1
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
static const WCHAR sp[]
Definition: suminfo.c:288
named_item_t * named_items
Definition: jscript.h:411
static HRESULT WINAPI VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
Definition: vbscript.c:839
static const IActiveScriptParseVtbl VBScriptParseVtbl
Definition: vbscript.c:737
static ULONG WINAPI AXSite_Release(IServiceProvider *iface)
Definition: vbscript.c:930
#define LIST_ENTRY(type)
Definition: queue.h:175
#define ss
Definition: i386-dis.c:432
#define E_POINTER
Definition: winerror.h:2365
static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
Definition: vbscript.c:648
static void destroy_script(script_ctx_t *ctx)
Definition: vbscript.c:214
IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface
Definition: vbscript.c:49
static HRESULT WINAPI VBScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib, DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
Definition: vbscript.c:488
vbdisp_t * global_obj
Definition: vbscript.h:195
static IServiceProviderVtbl AXSiteVtbl
Definition: vbscript.c:953
static HRESULT WINAPI VBScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
Definition: vbscript.c:404
#define IActiveScriptParseVtbl
Definition: vbscript.c:40
static HRESULT WINAPI VBScript_GetScriptSite(IActiveScript *iface, REFIID riid, void **ppvObject)
Definition: vbscript.c:353
static BOOL heap_free(void *mem)
Definition: appwiz.h:75