Commit d440ca4a authored by Mike Hearn's avatar Mike Hearn Committed by Alexandre Julliard

Fix typelib marshaller relaying, add a comment describing what it is,

don't print the ugly L"" parts of Unicode strings in the relay trace.
parent de9af241
......@@ -3,6 +3,9 @@
*
* Copyright 2002 Marcus Meissner
*
* The olerelay debug channel allows you to see calls marshalled by
* the typelib marshaller. It is not a generic COM relaying system.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
......@@ -59,6 +62,14 @@ typedef struct _marshal_state {
IID iid; /* HACK: for VT_VOID */
} marshal_state;
/* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
static char *relaystr(WCHAR *in) {
char *tmp = (char *)debugstr_w(in);
tmp += 2;
tmp[strlen(tmp)-1] = '\0';
return tmp;
}
static HRESULT
xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
while (buf->size - buf->curoff < size) {
......@@ -429,7 +440,7 @@ serialize_param(
case VT_UI2:
case VT_UI1:
hres = S_OK;
if (debugout) MESSAGE("%lx",*arg);
if (debugout) TRACE_(olerelay)("%lx",*arg);
if (writeit)
hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
return hres;
......@@ -438,7 +449,7 @@ serialize_param(
VARIANT *vt = (VARIANT*)arg;
DWORD vttype = V_VT(vt);
if (debugout) MESSAGE("Vt(%ld)(",vttype);
if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
tdesc2.vt = vttype;
if (writeit) {
hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
......@@ -446,15 +457,15 @@ serialize_param(
}
/* need to recurse since we need to free the stuff */
hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
if (debugout) MESSAGE(")");
if (debugout) TRACE_(olerelay)(")");
return hres;
}
case VT_BSTR: {
if (debugout) {
if (arg)
MESSAGE("%s",debugstr_w((BSTR)*arg));
TRACE_(olerelay)("%s",relaystr((BSTR)*arg));
else
MESSAGE("<bstr NULL>");
TRACE_(olerelay)("<bstr NULL>");
}
if (writeit) {
if (!*arg) {
......@@ -478,7 +489,7 @@ serialize_param(
case VT_PTR: {
DWORD cookie;
if (debugout) MESSAGE("*");
if (debugout) TRACE_(olerelay)("*");
if (writeit) {
cookie = *arg ? 0x42424242 : 0;
hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
......@@ -486,7 +497,7 @@ serialize_param(
return hres;
}
if (!*arg) {
if (debugout) MESSAGE("NULL");
if (debugout) TRACE_(olerelay)("NULL");
return S_OK;
}
hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
......@@ -494,17 +505,17 @@ serialize_param(
return hres;
}
case VT_UNKNOWN:
if (debugout) MESSAGE("unk(0x%lx)",*arg);
if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
if (writeit)
hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
return hres;
case VT_DISPATCH:
if (debugout) MESSAGE("idisp(0x%lx)",*arg);
if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
if (writeit)
hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
return hres;
case VT_VOID:
if (debugout) MESSAGE("<void>");
if (debugout) TRACE_(olerelay)("<void>");
return S_OK;
case VT_USERDEFINED: {
ITypeInfo *tinfo2;
......@@ -524,7 +535,7 @@ serialize_param(
break;
case TKIND_RECORD: {
int i;
if (debugout) MESSAGE("{");
if (debugout) TRACE_(olerelay)("{");
for (i=0;i<tattr->cVars;i++) {
VARDESC *vdesc;
ELEMDESC *elem2;
......@@ -543,7 +554,7 @@ serialize_param(
ERR("Need more names!\n");
}
if (!hres && debugout)
MESSAGE("%s=",debugstr_w(names[0]));
TRACE_(olerelay)("%s=",relaystr(names[0]));
*/
elem2 = &vdesc->elemdescVar;
tdesc2 = &elem2->tdesc;
......@@ -559,11 +570,11 @@ serialize_param(
if (hres!=S_OK)
return hres;
if (debugout && (i<(tattr->cVars-1)))
MESSAGE(",");
TRACE_(olerelay)(",");
}
if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
memcpy(&(buf->iid),arg,sizeof(buf->iid));
if (debugout) MESSAGE("}");
if (debugout) TRACE_(olerelay)("}");
break;
}
default:
......@@ -578,19 +589,19 @@ serialize_param(
ARRAYDESC *adesc = tdesc->u.lpadesc;
int i, arrsize = 1;
if (debugout) MESSAGE("carr");
if (debugout) TRACE_(olerelay)("carr");
for (i=0;i<adesc->cDims;i++) {
if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
arrsize *= adesc->rgbounds[i].cElements;
}
if (debugout) MESSAGE("[");
if (debugout) TRACE_(olerelay)("[");
for (i=0;i<arrsize;i++) {
hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
if (hres)
return hres;
if (debugout && (i<arrsize-1)) MESSAGE(",");
if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
}
if (debugout) MESSAGE("]");
if (debugout) TRACE_(olerelay)("]");
return S_OK;
}
default:
......@@ -626,11 +637,11 @@ serialize_LPVOID_ptr(
return hres;
}
if (!*arg) {
if (debugout) MESSAGE("<lpvoid NULL>");
if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
return S_OK;
}
if (debugout)
MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
if (writeit) {
hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
if (hres)
......@@ -668,7 +679,7 @@ serialize_DISPPARAM_ptr(
return hres;
}
if (!*arg) {
if (debugout) MESSAGE("<DISPPARAMS NULL>");
if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
return S_OK;
}
disp = (DISPPARAMS*)*arg;
......@@ -677,7 +688,7 @@ serialize_DISPPARAM_ptr(
if (hres)
return hres;
}
if (debugout) MESSAGE("D{");
if (debugout) TRACE_(olerelay)("D{");
for (i=0;i<disp->cArgs;i++) {
TYPEDESC vtdesc;
......@@ -692,7 +703,7 @@ serialize_DISPPARAM_ptr(
buf
);
if (debugout && (i<disp->cArgs-1))
MESSAGE(",");
TRACE_(olerelay)(",");
}
if (dealloc)
HeapFree(GetProcessHeap(),0,disp->rgvarg);
......@@ -701,7 +712,7 @@ serialize_DISPPARAM_ptr(
if (hres)
return hres;
}
if (debugout) MESSAGE("}{");
if (debugout) TRACE_(olerelay)("}{");
for (i=0;i<disp->cNamedArgs;i++) {
TYPEDESC vtdesc;
......@@ -716,9 +727,9 @@ serialize_DISPPARAM_ptr(
buf
);
if (debugout && (i<disp->cNamedArgs-1))
MESSAGE(",");
TRACE_(olerelay)(",");
}
if (debugout) MESSAGE("}");
if (debugout) TRACE_(olerelay)("}");
if (dealloc) {
HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
HeapFree(GetProcessHeap(),0,disp);
......@@ -743,10 +754,10 @@ deserialize_param(
while (1) {
switch (tdesc->vt) {
case VT_EMPTY:
if (debugout) MESSAGE("<empty>");
if (debugout) TRACE_(olerelay)("<empty>");
return S_OK;
case VT_NULL:
if (debugout) MESSAGE("<null>");
if (debugout) TRACE_(olerelay)("<null>");
return S_OK;
case VT_VARIANT: {
VARIANT *vt = (VARIANT*)arg;
......@@ -762,9 +773,9 @@ deserialize_param(
memset(&tdesc2,0,sizeof(tdesc2));
tdesc2.vt = vttype;
V_VT(vt) = vttype;
if (debugout) MESSAGE("Vt(%ld)(",vttype);
if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
MESSAGE(")");
TRACE_(olerelay)(")");
return hres;
} else {
VariantInit(vt);
......@@ -779,7 +790,7 @@ deserialize_param(
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
if (hres) FIXME("Failed to read integer 4 byte\n");
}
if (debugout) MESSAGE("%lx",*arg);
if (debugout) TRACE_(olerelay)("%lx",*arg);
return hres;
case VT_BSTR: {
WCHAR *str;
......@@ -793,7 +804,7 @@ deserialize_param(
}
if (len == -1) {
*arg = 0;
if (debugout) MESSAGE("<bstr NULL>");
if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len);
......@@ -802,7 +813,7 @@ deserialize_param(
return hres;
}
*arg = (DWORD)SysAllocStringLen(str,len);
if (debugout) MESSAGE("%s",debugstr_w(str));
if (debugout) TRACE_(olerelay)("%s",relaystr(str));
HeapFree(GetProcessHeap(),0,str);
}
} else {
......@@ -823,11 +834,11 @@ deserialize_param(
return hres;
}
if (cookie != 0x42424242) {
if (debugout) MESSAGE("NULL");
if (debugout) TRACE_(olerelay)("NULL");
*arg = 0;
return S_OK;
}
if (debugout) MESSAGE("*");
if (debugout) TRACE_(olerelay)("*");
}
if (alloc) {
if (derefhere)
......@@ -846,17 +857,17 @@ deserialize_param(
if (readit)
hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
if (debugout)
MESSAGE("unk(%p)",arg);
TRACE_(olerelay)("unk(%p)",arg);
return hres;
case VT_DISPATCH:
hres = S_OK;
if (readit)
hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
if (debugout)
MESSAGE("idisp(%p)",arg);
TRACE_(olerelay)("idisp(%p)",arg);
return hres;
case VT_VOID:
if (debugout) MESSAGE("<void>");
if (debugout) TRACE_(olerelay)("<void>");
return S_OK;
case VT_USERDEFINED: {
ITypeInfo *tinfo2;
......@@ -882,7 +893,7 @@ deserialize_param(
case TKIND_RECORD: {
int i;
if (debugout) MESSAGE("{");
if (debugout) TRACE_(olerelay)("{");
for (i=0;i<tattr->cVars;i++) {
VARDESC *vdesc;
......@@ -900,11 +911,11 @@ deserialize_param(
(DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
buf
);
if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
}
if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
if (debugout) MESSAGE("}");
if (debugout) TRACE_(olerelay)("}");
break;
}
default:
......@@ -973,7 +984,7 @@ deserialize_LPVOID_ptr(
return hres;
if (cookie != 0x42424242) {
*(DWORD*)*arg = 0;
if (debugout) MESSAGE("<lpvoid NULL>");
if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
return S_OK;
}
}
......@@ -982,7 +993,7 @@ deserialize_LPVOID_ptr(
if (hres)
return hres;
}
if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
return S_OK;
}
......@@ -1011,7 +1022,7 @@ deserialize_DISPPARAM_ptr(
return hres;
if (cookie == 0) {
*arg = 0;
if (debugout) MESSAGE("<DISPPARAMS NULL>");
if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
return S_OK;
}
}
......@@ -1025,7 +1036,7 @@ deserialize_DISPPARAM_ptr(
return hres;
if (alloc)
disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
if (debugout) MESSAGE("D{");
if (debugout) TRACE_(olerelay)("D{");
for (i=0; i< disps->cArgs; i++) {
TYPEDESC vdesc;
......@@ -1040,7 +1051,7 @@ deserialize_DISPPARAM_ptr(
buf
);
}
if (debugout) MESSAGE("}{");
if (debugout) TRACE_(olerelay)("}{");
hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
if (hres)
return hres;
......@@ -1060,10 +1071,10 @@ deserialize_DISPPARAM_ptr(
(DWORD*)(disps->rgdispidNamedArgs+i),
buf
);
if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
}
}
if (debugout) MESSAGE("}");
if (debugout) TRACE_(olerelay)("}");
return S_OK;
}
......@@ -1139,16 +1150,15 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
return 0;
}
/*dump_FUNCDESC(fdesc);*/
if (relaydeb) {
TRACE_(olerelay)("->");
TRACE_(olerelay)("\n->");
if (iname)
MESSAGE("%s:",debugstr_w(iname));
TRACE_(olerelay)("%s:",relaystr(iname));
if (fname)
MESSAGE("%s(%d)",debugstr_w(fname),method);
TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
else
MESSAGE("%d",method);
MESSAGE("(");
TRACE_(olerelay)("%d",method);
TRACE_(olerelay)("(");
if (iname) SysFreeString(iname);
if (fname) SysFreeString(fname);
}
......@@ -1163,21 +1173,21 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
buf.iid = IID_IUnknown;
if (method == 0) {
xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
if (relaydeb) TRACE_(olerelay)("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
} else {
xargs = args;
for (i=0;i<fdesc->cParams;i++) {
ELEMDESC *elem = fdesc->lprgelemdescParam+i;
BOOL isserialized = FALSE;
if (relaydeb) {
if (i) MESSAGE(",");
if (i) TRACE_(olerelay)(",");
if (i+1<nrofnames && names[i+1])
MESSAGE("%s=",debugstr_w(names[i+1]));
TRACE_(olerelay)("%s=",relaystr(names[i+1]));
}
/* No need to marshal other data than FIN */
if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
xargs+=_argsize(elem->tdesc.vt);
if (relaydeb) MESSAGE("[out]");
if (relaydeb) TRACE_(olerelay)("[out]");
continue;
}
if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
......@@ -1231,7 +1241,7 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
xargs+=_argsize(elem->tdesc.vt);
}
}
if (relaydeb) MESSAGE(")");
if (relaydeb) TRACE_(olerelay)(")");
memset(&msg,0,sizeof(msg));
msg.cbBuffer = buf.curoff;
msg.iMethod = method;
......@@ -1241,14 +1251,14 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
return hres;
}
memcpy(msg.Buffer,buf.base,buf.curoff);
if (relaydeb) MESSAGE("\n");
if (relaydeb) TRACE_(olerelay)("\n");
hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
if (hres) {
FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
return hres;
}
relaydeb = TRACE_ON(olerelay);
if (relaydeb) MESSAGE(" = %08lx (",status);
if (relaydeb) TRACE_(olerelay)(" = %08lx (",status);
if (buf.base)
buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
else
......@@ -1258,7 +1268,7 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
buf.curoff = 0;
if (method == 0) {
_unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
} else {
xargs = args;
for (i=0;i<fdesc->cParams;i++) {
......@@ -1266,13 +1276,13 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
BOOL isdeserialized = FALSE;
if (relaydeb) {
if (i) MESSAGE(",");
if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
if (i) TRACE_(olerelay)(",");
if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
}
/* No need to marshal other data than FOUT I think */
if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
xargs += _argsize(elem->tdesc.vt);
if (relaydeb) MESSAGE("[in]");
if (relaydeb) TRACE_(olerelay)("[in]");
continue;
}
if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
......@@ -1329,7 +1339,7 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
xargs += _argsize(elem->tdesc.vt);
}
}
if (relaydeb) MESSAGE(")\n\n");
if (relaydeb) TRACE_(olerelay)(")\n\n");
HeapFree(GetProcessHeap(),0,buf.base);
return status;
}
......@@ -1580,7 +1590,7 @@ TMStubImpl_Invoke(
);
xargs += _argsize(elem->tdesc.vt);
if (hres) {
FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
FIXME("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
break;
}
}
......
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