Commit 5e23b8a9 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

vbscript: Implement SID_GetCaller for QueryService.

parent c8f81cce
...@@ -2,6 +2,7 @@ TESTDLL = vbscript.dll ...@@ -2,6 +2,7 @@ TESTDLL = vbscript.dll
IMPORTS = oleaut32 ole32 advapi32 IMPORTS = oleaut32 ole32 advapi32
C_SRCS = \ C_SRCS = \
caller.c \
createobj.c \ createobj.c \
run.c \ run.c \
vbscript.c vbscript.c
......
...@@ -413,6 +413,8 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc ...@@ -413,6 +413,8 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
{ {
vbdisp_t *This = impl_from_IDispatchEx(iface); vbdisp_t *This = impl_from_IDispatchEx(iface);
IServiceProvider *prev_caller;
HRESULT hres;
TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller); TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
...@@ -422,7 +424,17 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc ...@@ -422,7 +424,17 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
if(pvarRes) if(pvarRes)
V_VT(pvarRes) = VT_EMPTY; V_VT(pvarRes) = VT_EMPTY;
return invoke_vbdisp(This, id, wFlags, TRUE, pdp, pvarRes); prev_caller = This->desc->ctx->vbcaller->caller;
This->desc->ctx->vbcaller->caller = pspCaller;
if(pspCaller)
IServiceProvider_AddRef(pspCaller);
hres = invoke_vbdisp(This, id, wFlags, TRUE, pdp, pvarRes);
This->desc->ctx->vbcaller->caller = prev_caller;
if(pspCaller)
IServiceProvider_Release(pspCaller);
return hres;
} }
static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex) static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
...@@ -1414,6 +1426,7 @@ static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc ...@@ -1414,6 +1426,7 @@ static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
{ {
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface); ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
IServiceProvider *prev_caller;
HRESULT hres; HRESULT hres;
TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller); TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
...@@ -1421,11 +1434,18 @@ static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc ...@@ -1421,11 +1434,18 @@ static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
if (!This->ctx) if (!This->ctx)
return E_UNEXPECTED; return E_UNEXPECTED;
prev_caller = This->ctx->vbcaller->caller;
This->ctx->vbcaller->caller = pspCaller;
if(pspCaller)
IServiceProvider_AddRef(pspCaller);
if (id & DISPID_FUNCTION_MASK) if (id & DISPID_FUNCTION_MASK)
{ {
id &= ~DISPID_FUNCTION_MASK; id &= ~DISPID_FUNCTION_MASK;
if (id > This->global_funcs_cnt) if (id > This->global_funcs_cnt) {
return DISP_E_MEMBERNOTFOUND; hres = DISP_E_MEMBERNOTFOUND;
goto done;
}
switch (wFlags) switch (wFlags)
{ {
...@@ -1438,19 +1458,28 @@ static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc ...@@ -1438,19 +1458,28 @@ static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
hres = E_NOTIMPL; hres = E_NOTIMPL;
} }
return hres; goto done;
} }
if (id > This->global_vars_cnt) if (id > This->global_vars_cnt) {
return DISP_E_MEMBERNOTFOUND; hres = DISP_E_MEMBERNOTFOUND;
goto done;
}
if (This->global_vars[id - 1]->is_const) if (This->global_vars[id - 1]->is_const)
{ {
FIXME("const not supported\n"); FIXME("const not supported\n");
return E_NOTIMPL; hres = E_NOTIMPL;
goto done;
} }
return invoke_variant_prop(This->ctx, &This->global_vars[id - 1]->v, wFlags, pdp, pvarRes); hres = invoke_variant_prop(This->ctx, &This->global_vars[id - 1]->v, wFlags, pdp, pvarRes);
done:
This->ctx->vbcaller->caller = prev_caller;
if(pspCaller)
IServiceProvider_Release(pspCaller);
return hres;
} }
static HRESULT WINAPI ScriptDisp_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex) static HRESULT WINAPI ScriptDisp_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
......
...@@ -96,6 +96,7 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res ...@@ -96,6 +96,7 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res
ScriptDisp *obj = ctx->script_obj; ScriptDisp *obj = ctx->script_obj;
function_t *func_iter, **new_funcs; function_t *func_iter, **new_funcs;
dynamic_var_t *var, **new_vars; dynamic_var_t *var, **new_vars;
IServiceProvider *prev_caller;
size_t cnt, i; size_t cnt, i;
HRESULT hres; HRESULT hres;
...@@ -185,7 +186,12 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res ...@@ -185,7 +186,12 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res
} }
code->pending_exec = FALSE; code->pending_exec = FALSE;
return exec_script(ctx, TRUE, &code->main_code, NULL, NULL, res);
prev_caller = ctx->vbcaller->caller;
ctx->vbcaller->caller = SP_CALLER_UNINITIALIZED;
hres = exec_script(ctx, TRUE, &code->main_code, NULL, NULL, res);
ctx->vbcaller->caller = prev_caller;
return hres;
} }
static void exec_queued_code(script_ctx_t *ctx) static void exec_queued_code(script_ctx_t *ctx)
...@@ -415,6 +421,14 @@ static HRESULT WINAPI vbcaller_QueryService(IServiceProvider *iface, REFGUID gui ...@@ -415,6 +421,14 @@ static HRESULT WINAPI vbcaller_QueryService(IServiceProvider *iface, REFGUID gui
{ {
struct vbcaller *This = vbcaller_from_IServiceProvider(iface); struct vbcaller *This = vbcaller_from_IServiceProvider(iface);
if(IsEqualGUID(guidService, &SID_GetCaller)) {
TRACE("(%p)->(SID_GetCaller)\n", This);
*ppv = NULL;
if(!This->caller)
return S_OK;
return (This->caller == SP_CALLER_UNINITIALIZED) ? E_NOINTERFACE : IServiceProvider_QueryInterface(This->caller, riid, ppv);
}
FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv); FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
*ppv = NULL; *ppv = NULL;
...@@ -436,6 +450,7 @@ static struct vbcaller *create_vbcaller(void) ...@@ -436,6 +450,7 @@ static struct vbcaller *create_vbcaller(void)
if(ret) { if(ret) {
ret->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl; ret->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
ret->ref = 1; ret->ref = 1;
ret->caller = SP_CALLER_UNINITIALIZED;
} }
return ret; return ret;
} }
......
...@@ -180,10 +180,14 @@ static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i) ...@@ -180,10 +180,14 @@ static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
return dp->rgvarg + dp->cArgs-i-1; return dp->rgvarg + dp->cArgs-i-1;
} }
#define SP_CALLER_UNINITIALIZED ((IServiceProvider*)IntToPtr(-1))
struct vbcaller { struct vbcaller {
IServiceProvider IServiceProvider_iface; IServiceProvider IServiceProvider_iface;
LONG ref; LONG ref;
IServiceProvider *caller;
}; };
struct _script_ctx_t { struct _script_ctx_t {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment