rpcrt4: Move the writing and sizing of variances and conformances to common functions.

This commit is contained in:
Robert Shearman 2006-05-10 13:13:15 +01:00 committed by Alexandre Julliard
parent 4b4192f3a5
commit 265045d251
1 changed files with 53 additions and 35 deletions

View File

@ -340,6 +340,34 @@ done:
return pFormat+4; return pFormat+4;
} }
/* writes the conformance value to the buffer */
static inline void WriteConformance(MIDL_STUB_MESSAGE *pStubMsg)
{
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
pStubMsg->Buffer += 4;
}
/* writes the variance values to the buffer */
static inline void WriteVariance(MIDL_STUB_MESSAGE *pStubMsg)
{
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
pStubMsg->Buffer += 4;
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
pStubMsg->Buffer += 4;
}
/* requests buffer space for the conformance value */
static inline void SizeConformance(MIDL_STUB_MESSAGE *pStubMsg)
{
pStubMsg->BufferLength += 4;
}
/* requests buffer space for the variance values */
static inline void SizeVariance(MIDL_STUB_MESSAGE *pStubMsg)
{
pStubMsg->BufferLength += 8;
}
PFORMAT_STRING ComputeConformanceOrVariance( PFORMAT_STRING ComputeConformanceOrVariance(
MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory, MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount) PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
@ -483,7 +511,6 @@ unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
unsigned char *pszMessage, PFORMAT_STRING pFormat) unsigned char *pszMessage, PFORMAT_STRING pFormat)
{ {
unsigned long len, esize; unsigned long len, esize;
unsigned char *c;
TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat); TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
@ -510,15 +537,13 @@ unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
assert( (pStubMsg->BufferLength >= (len*esize + 13)) && (pStubMsg->Buffer != NULL) ); assert( (pStubMsg->BufferLength >= (len*esize + 13)) && (pStubMsg->Buffer != NULL) );
c = pStubMsg->Buffer; pStubMsg->MaxCount = pStubMsg->ActualCount = len;
memset(c, 0, 12); pStubMsg->Offset = 0;
NDR_LOCAL_UINT32_WRITE(c, len); /* max length: strlen + 1 (for '\0') */ WriteConformance(pStubMsg);
c += 8; /* offset: 0 */ WriteVariance(pStubMsg);
NDR_LOCAL_UINT32_WRITE(c, len); /* actual length: (same) */
c += 4; memcpy(pStubMsg->Buffer, pszMessage, len*esize); /* the string itself */
memcpy(c, pszMessage, len*esize); /* the string itself */ pStubMsg->Buffer += len*esize;
c += len*esize;
pStubMsg->Buffer = c;
STD_OVERFLOW_CHECK(pStubMsg); STD_OVERFLOW_CHECK(pStubMsg);
@ -534,16 +559,19 @@ void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
{ {
TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat); TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
SizeConformance(pStubMsg);
SizeVariance(pStubMsg);
assert(pFormat); assert(pFormat);
if (*pFormat == RPC_FC_C_CSTRING) { if (*pFormat == RPC_FC_C_CSTRING) {
/* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */ /* we need + 1 octet for '\0' */
TRACE("string=%s\n", debugstr_a((char*)pMemory)); TRACE("string=%s\n", debugstr_a((char*)pMemory));
pStubMsg->BufferLength += strlen((char*)pMemory) + 13 + BUFFER_PARANOIA; pStubMsg->BufferLength += strlen((char*)pMemory) + 1 + BUFFER_PARANOIA;
} }
else if (*pFormat == RPC_FC_C_WSTRING) { else if (*pFormat == RPC_FC_C_WSTRING) {
/* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */ /* we need + 2 octets for L'\0' */
TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory)); TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 14 + BUFFER_PARANOIA; pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 2 + BUFFER_PARANOIA;
} }
else { else {
ERR("Unhandled string type: %#x\n", *pFormat); ERR("Unhandled string type: %#x\n", *pFormat);
@ -1914,8 +1942,7 @@ unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0); pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
size = pStubMsg->MaxCount; size = pStubMsg->MaxCount;
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size); WriteConformance(pStubMsg);
pStubMsg->Buffer += 4;
ALIGN_POINTER(pStubMsg->Buffer, alignment); ALIGN_POINTER(pStubMsg->Buffer, alignment);
@ -1977,7 +2004,8 @@ void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0); pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
size = pStubMsg->MaxCount; size = pStubMsg->MaxCount;
pStubMsg->BufferLength += 4;
SizeVariance(pStubMsg);
ALIGN_LENGTH(pStubMsg->BufferLength, alignment); ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
@ -2043,12 +2071,8 @@ unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStu
pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0); pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0); pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount); WriteConformance(pStubMsg);
pStubMsg->Buffer += 4; WriteVariance(pStubMsg);
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
pStubMsg->Buffer += 4;
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
pStubMsg->Buffer += 4;
ALIGN_POINTER(pStubMsg->Buffer, alignment); ALIGN_POINTER(pStubMsg->Buffer, alignment);
@ -2146,8 +2170,8 @@ void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
/* compute length */ /* compute length */
pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0); pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
/* conformance + offset + variance */ SizeConformance(pStubMsg);
pStubMsg->BufferLength += 3 * sizeof(DWORD); SizeVariance(pStubMsg);
ALIGN_LENGTH(pStubMsg->BufferLength, alignment); ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
@ -2200,15 +2224,9 @@ unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount); pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
TRACE("variance = %ld\n", pStubMsg->ActualCount); TRACE("variance = %ld\n", pStubMsg->ActualCount);
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount); WriteConformance(pStubMsg);
pStubMsg->Buffer += 4;
if (variance_present) if (variance_present)
{ WriteVariance(pStubMsg);
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
pStubMsg->Buffer += 4;
NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
pStubMsg->Buffer += 4;
}
ALIGN_POINTER(pStubMsg->Buffer, alignment); ALIGN_POINTER(pStubMsg->Buffer, alignment);
@ -2292,14 +2310,14 @@ void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def); pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
TRACE("conformance = %ld\n", pStubMsg->MaxCount); TRACE("conformance = %ld\n", pStubMsg->MaxCount);
pStubMsg->BufferLength += sizeof(ULONG); SizeConformance(pStubMsg);
variance_present = IsConformanceOrVariancePresent(pFormat); variance_present = IsConformanceOrVariancePresent(pFormat);
pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount); pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
TRACE("variance = %ld\n", pStubMsg->ActualCount); TRACE("variance = %ld\n", pStubMsg->ActualCount);
if (variance_present) if (variance_present)
pStubMsg->BufferLength += 2*sizeof(ULONG); SizeVariance(pStubMsg);
ALIGN_LENGTH(pStubMsg->BufferLength, alignment); ALIGN_LENGTH(pStubMsg->BufferLength, alignment);