From c6a6fa184125f94a0891b613daffb44d93d0e803 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 6 Feb 2008 16:34:36 +0100 Subject: win32-tests: add a very usefull w32 programm to explore midl features You have to define idl, call the client function and add a server implementation. Then you need to compile midltests.exe and run it, it will dump the generated NDR on the screen. metze (This used to be commit dc15c8833599a1cb8f51c2b5390925410cbf4e12) --- testprogs/win32/midltests/midltests.acf | 6 ++ testprogs/win32/midltests/midltests.c | 42 +++++++++ testprogs/win32/midltests/midltests.idl | 27 ++++++ testprogs/win32/midltests/midltests_c_m.c | 2 + testprogs/win32/midltests/midltests_marshall.c | 121 +++++++++++++++++++++++++ testprogs/win32/midltests/midltests_marshall.h | 16 ++++ testprogs/win32/midltests/midltests_s_m.c | 2 + testprogs/win32/midltests/utils.c | 32 +++++++ 8 files changed, 248 insertions(+) create mode 100644 testprogs/win32/midltests/midltests.acf create mode 100644 testprogs/win32/midltests/midltests.c create mode 100644 testprogs/win32/midltests/midltests.idl create mode 100644 testprogs/win32/midltests/midltests_c_m.c create mode 100644 testprogs/win32/midltests/midltests_marshall.c create mode 100644 testprogs/win32/midltests/midltests_marshall.h create mode 100644 testprogs/win32/midltests/midltests_s_m.c create mode 100644 testprogs/win32/midltests/utils.c (limited to 'testprogs/win32') diff --git a/testprogs/win32/midltests/midltests.acf b/testprogs/win32/midltests/midltests.acf new file mode 100644 index 0000000000..a04bb5dcd9 --- /dev/null +++ b/testprogs/win32/midltests/midltests.acf @@ -0,0 +1,6 @@ +[ + implicit_handle (handle_t midltests_IfHandle) +] +interface midltests +{ +} diff --git a/testprogs/win32/midltests/midltests.c b/testprogs/win32/midltests/midltests.c new file mode 100644 index 0000000000..61d4ce0812 --- /dev/null +++ b/testprogs/win32/midltests/midltests.c @@ -0,0 +1,42 @@ +/* + MIDLTESTS client. + + Copyright (C) Stefan Metzmacher 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include "midltests.h" + +#define MIDLTESTS_C_CODE 1 +#include "midltests.idl" + +int main(int argc, char **argv) +{ + int ret; + + midltests_IfHandle = NULL; + + RpcTryExcept { + midltests(); + } RpcExcept(1) { + ret = RpcExceptionCode(); + printf("Runtime error 0x%x\n", ret); + } RpcEndExcept + + return ret; +} diff --git a/testprogs/win32/midltests/midltests.idl b/testprogs/win32/midltests/midltests.idl new file mode 100644 index 0000000000..1932549c56 --- /dev/null +++ b/testprogs/win32/midltests/midltests.idl @@ -0,0 +1,27 @@ +#ifndef MIDLTESTS_C_CODE + +[ + uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"), + pointer_default(unique) +] +interface midltests +{ + long midltests_fn( + ); +} + +#elif MIDLTESTS_C_CODE + +static void midltests(void) +{ + cli_midltests_fn(); +} + +long srv_midltests_fn(void) +{ + printf("srv_midltests_fn: Start\n"); + printf("srv_midltests_fn: End\n"); + return 0x65757254; +} + +#endif \ No newline at end of file diff --git a/testprogs/win32/midltests/midltests_c_m.c b/testprogs/win32/midltests/midltests_c_m.c new file mode 100644 index 0000000000..facf735304 --- /dev/null +++ b/testprogs/win32/midltests/midltests_c_m.c @@ -0,0 +1,2 @@ +#include "midltests_marshall.h" +#include "midltests_c.c" diff --git a/testprogs/win32/midltests/midltests_marshall.c b/testprogs/win32/midltests/midltests_marshall.c new file mode 100644 index 0000000000..e772afd03d --- /dev/null +++ b/testprogs/win32/midltests/midltests_marshall.c @@ -0,0 +1,121 @@ +/* + MIDLTESTS client. + + Copyright (C) Stefan Metzmacher 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include "midltests.h" + +#define MIN(a,b) ((a)<(b)?(a):(b)) +static void print_asc(const unsigned char *buf,int len) +{ + int i; + for (i=0;i8) printf(" "); + while (n--) printf(" "); + n = MIN(8,i%16); + print_asc(&buf[i-(i%16)],n); printf( " " ); + n = (i%16) - n; + if (n>0) print_asc(&buf[i-n],n); + printf("\n"); + } +} + +void NdrGetBufferMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned long len, RPC_BINDING_HANDLE hnd) +{ + stubmsg->RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, len); + memset(stubmsg->RpcMsg->Buffer, 0xef, len); + stubmsg->RpcMsg->BufferLength = len; + stubmsg->Buffer = stubmsg->RpcMsg->Buffer; + stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength; + stubmsg->fBufferValid = TRUE; +} + +void __RPC_STUB midltests_midltests_fn(PRPC_MESSAGE _pRpcMessage); + +void NdrSendReceiveMarshall(PMIDL_STUB_MESSAGE StubMsg, unsigned char *buffer) +{ + unsigned long DataRepresentation; + + StubMsg->RpcMsg->BufferLength = buffer - (unsigned char *)StubMsg->RpcMsg->Buffer; + + printf("[in] Buffer[%d/%d]\n", + StubMsg->RpcMsg->BufferLength, StubMsg->BufferLength); + dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength); + + DataRepresentation = StubMsg->RpcMsg->DataRepresentation; + StubMsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION; + midltests_midltests_fn(StubMsg->RpcMsg); + StubMsg->RpcMsg->DataRepresentation = DataRepresentation; + + StubMsg->BufferLength = StubMsg->RpcMsg->BufferLength; + StubMsg->BufferStart = StubMsg->RpcMsg->Buffer; + StubMsg->BufferEnd = StubMsg->BufferStart + StubMsg->BufferLength; + StubMsg->Buffer = StubMsg->BufferStart; + + printf("[out] Buffer[%d]\n", + StubMsg->RpcMsg->BufferLength); + dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength); +} + +void NdrServerInitializeNewMarshall(PRPC_MESSAGE pRpcMsg, + PMIDL_STUB_MESSAGE pStubMsg, + PMIDL_STUB_DESC pStubDesc) +{ + memset(pStubMsg, 0, sizeof(*pStubMsg)); + pStubMsg->RpcMsg = pRpcMsg; + pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer; + pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength; + pStubMsg->BufferLength = pRpcMsg->BufferLength; + pStubMsg->pfnAllocate = pStubDesc->pfnAllocate; + pStubMsg->pfnFree = pStubDesc->pfnFree; + pStubMsg->StubDesc = pStubDesc; + pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE; +} + +RPC_STATUS WINAPI I_RpcGetBufferMarshall(PRPC_MESSAGE RpcMsg) +{ + RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, RpcMsg->BufferLength); + memset(RpcMsg->Buffer, 0xcd, RpcMsg->BufferLength); + return 0; +} diff --git a/testprogs/win32/midltests/midltests_marshall.h b/testprogs/win32/midltests/midltests_marshall.h new file mode 100644 index 0000000000..0c6aed2721 --- /dev/null +++ b/testprogs/win32/midltests/midltests_marshall.h @@ -0,0 +1,16 @@ +#include "rpc.h" +#include "rpcndr.h" +#define NdrSendReceive NdrSendReceiveMarshall +void NdrSendReceiveMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer); +#define NdrGetBuffer NdrGetBufferMarshall +void NdrGetBufferMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned long len, RPC_BINDING_HANDLE hnd); +#define NdrServerInitializeNew NdrServerInitializeNewMarshall +void NdrServerInitializeNewMarshall(PRPC_MESSAGE pRpcMsg, + PMIDL_STUB_MESSAGE pStubMsg, + PMIDL_STUB_DESC pStubDesc); +#define I_RpcGetBuffer I_RpcGetBufferMarshall +RPC_STATUS WINAPI I_RpcGetBufferMarshall(PRPC_MESSAGE pMsg); + + + + diff --git a/testprogs/win32/midltests/midltests_s_m.c b/testprogs/win32/midltests/midltests_s_m.c new file mode 100644 index 0000000000..7e0862dc69 --- /dev/null +++ b/testprogs/win32/midltests/midltests_s_m.c @@ -0,0 +1,2 @@ +#include "midltests_marshall.h" +#include "midltests_s.c" diff --git a/testprogs/win32/midltests/utils.c b/testprogs/win32/midltests/utils.c new file mode 100644 index 0000000000..8c4833ddb4 --- /dev/null +++ b/testprogs/win32/midltests/utils.c @@ -0,0 +1,32 @@ +/* + MIDLTESTS utility functions. + + Copyright (C) Tim Potter 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "midltests.h" + +/* MIDL allocate and free functions */ + +void __RPC_FAR *__RPC_USER midl_user_allocate(size_t len) +{ + return(malloc(len)); +} + +void __RPC_USER midl_user_free(void __RPC_FAR *ptr) +{ + free(ptr); +} -- cgit