s3: Do not free a string where we should not
[Samba/gebeck_regimport.git] / testprogs / win32 / midltests / midltests_marshall.c
blobf0fc78a71ddbf924648c1bdeb7df3070e4a1e860
1 /*
2 MIDLTESTS client.
4 Copyright (C) Stefan Metzmacher 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include "midltests.h"
25 #define MIN(a,b) ((a)<(b)?(a):(b))
26 static void print_asc(const unsigned char *buf,int len)
28 int i;
29 for (i=0;i<len;i++)
30 printf("%c", isprint(buf[i])?buf[i]:'.');
33 void dump_data(const unsigned char *buf1,int len)
35 const unsigned char *buf = (const unsigned char *)buf1;
36 int i=0;
37 if (len<=0) return;
39 printf("[%03X] ",i);
40 for (i=0;i<len;) {
41 printf("%02X ",(int)buf[i]);
42 i++;
43 if (i%8 == 0) printf(" ");
44 if (i%16 == 0) {
45 print_asc(&buf[i-16],8); printf(" ");
46 print_asc(&buf[i-8],8); printf("\n");
47 if (i<len) printf("[%03X] ",i);
50 if (i%16) {
51 int n;
52 n = 16 - (i%16);
53 printf(" ");
54 if (n>8) printf(" ");
55 while (n--) printf(" ");
56 n = MIN(8,i%16);
57 print_asc(&buf[i-(i%16)],n); printf( " " );
58 n = (i%16) - n;
59 if (n>0) print_asc(&buf[i-n],n);
60 printf("\n");
64 #if _WIN32_WINNT < 0x600
66 void NdrGetBufferMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned long len, RPC_BINDING_HANDLE hnd)
68 stubmsg->RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, len);
69 memset(stubmsg->RpcMsg->Buffer, 0xef, len);
70 stubmsg->RpcMsg->BufferLength = len;
71 stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
72 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
73 stubmsg->fBufferValid = TRUE;
76 void __RPC_STUB midltests_midltests_fn(PRPC_MESSAGE _pRpcMessage);
78 void NdrSendReceiveMarshall(PMIDL_STUB_MESSAGE StubMsg, unsigned char *buffer)
80 unsigned long DataRepresentation;
82 StubMsg->RpcMsg->BufferLength = buffer - (unsigned char *)StubMsg->RpcMsg->Buffer;
84 printf("[in] Buffer[%d/%d]\n",
85 StubMsg->RpcMsg->BufferLength, StubMsg->BufferLength);
86 dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength);
88 DataRepresentation = StubMsg->RpcMsg->DataRepresentation;
89 StubMsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
90 midltests_midltests_fn(StubMsg->RpcMsg);
91 StubMsg->RpcMsg->DataRepresentation = DataRepresentation;
93 StubMsg->BufferLength = StubMsg->RpcMsg->BufferLength;
94 StubMsg->BufferStart = StubMsg->RpcMsg->Buffer;
95 StubMsg->BufferEnd = StubMsg->BufferStart + StubMsg->BufferLength;
96 StubMsg->Buffer = StubMsg->BufferStart;
98 printf("[out] Buffer[%d]\n",
99 StubMsg->RpcMsg->BufferLength);
100 dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength);
103 void NdrServerInitializeNewMarshall(PRPC_MESSAGE pRpcMsg,
104 PMIDL_STUB_MESSAGE pStubMsg,
105 PMIDL_STUB_DESC pStubDesc)
107 memset(pStubMsg, 0, sizeof(*pStubMsg));
108 pStubMsg->RpcMsg = pRpcMsg;
109 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
110 pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
111 pStubMsg->BufferLength = pRpcMsg->BufferLength;
112 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
113 pStubMsg->pfnFree = pStubDesc->pfnFree;
114 pStubMsg->StubDesc = pStubDesc;
115 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
118 RPC_STATUS WINAPI I_RpcGetBufferMarshall(PRPC_MESSAGE RpcMsg)
120 RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, RpcMsg->BufferLength);
121 memset(RpcMsg->Buffer, 0xcd, RpcMsg->BufferLength);
122 return 0;
125 #endif /* _WIN32_WINNT < 0x600 */