1 | /*
|
---|
2 | MIDLTESTS client.
|
---|
3 |
|
---|
4 | Copyright (C) Stefan Metzmacher 2008
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include <stdio.h>
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <ctype.h>
|
---|
23 | #include "midltests.h"
|
---|
24 |
|
---|
25 | #define MIN(a,b) ((a)<(b)?(a):(b))
|
---|
26 | static void print_asc(const unsigned char *buf,int len)
|
---|
27 | {
|
---|
28 | int i;
|
---|
29 | for (i=0;i<len;i++)
|
---|
30 | printf("%c", isprint(buf[i])?buf[i]:'.');
|
---|
31 | }
|
---|
32 |
|
---|
33 | static void dump_data(const unsigned char *buf1,int len)
|
---|
34 | {
|
---|
35 | const unsigned char *buf = (const unsigned char *)buf1;
|
---|
36 | int i=0;
|
---|
37 | if (len<=0) return;
|
---|
38 |
|
---|
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);
|
---|
48 | }
|
---|
49 | }
|
---|
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");
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | void NdrGetBufferMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned long len, RPC_BINDING_HANDLE hnd)
|
---|
65 | {
|
---|
66 | stubmsg->RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, len);
|
---|
67 | memset(stubmsg->RpcMsg->Buffer, 0xef, len);
|
---|
68 | stubmsg->RpcMsg->BufferLength = len;
|
---|
69 | stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
|
---|
70 | stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
|
---|
71 | stubmsg->fBufferValid = TRUE;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void __RPC_STUB midltests_midltests_fn(PRPC_MESSAGE _pRpcMessage);
|
---|
75 |
|
---|
76 | void NdrSendReceiveMarshall(PMIDL_STUB_MESSAGE StubMsg, unsigned char *buffer)
|
---|
77 | {
|
---|
78 | unsigned long DataRepresentation;
|
---|
79 |
|
---|
80 | StubMsg->RpcMsg->BufferLength = buffer - (unsigned char *)StubMsg->RpcMsg->Buffer;
|
---|
81 |
|
---|
82 | printf("[in] Buffer[%d/%d]\n",
|
---|
83 | StubMsg->RpcMsg->BufferLength, StubMsg->BufferLength);
|
---|
84 | dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength);
|
---|
85 |
|
---|
86 | DataRepresentation = StubMsg->RpcMsg->DataRepresentation;
|
---|
87 | StubMsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
|
---|
88 | midltests_midltests_fn(StubMsg->RpcMsg);
|
---|
89 | StubMsg->RpcMsg->DataRepresentation = DataRepresentation;
|
---|
90 |
|
---|
91 | StubMsg->BufferLength = StubMsg->RpcMsg->BufferLength;
|
---|
92 | StubMsg->BufferStart = StubMsg->RpcMsg->Buffer;
|
---|
93 | StubMsg->BufferEnd = StubMsg->BufferStart + StubMsg->BufferLength;
|
---|
94 | StubMsg->Buffer = StubMsg->BufferStart;
|
---|
95 |
|
---|
96 | printf("[out] Buffer[%d]\n",
|
---|
97 | StubMsg->RpcMsg->BufferLength);
|
---|
98 | dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength);
|
---|
99 | }
|
---|
100 |
|
---|
101 | void NdrServerInitializeNewMarshall(PRPC_MESSAGE pRpcMsg,
|
---|
102 | PMIDL_STUB_MESSAGE pStubMsg,
|
---|
103 | PMIDL_STUB_DESC pStubDesc)
|
---|
104 | {
|
---|
105 | memset(pStubMsg, 0, sizeof(*pStubMsg));
|
---|
106 | pStubMsg->RpcMsg = pRpcMsg;
|
---|
107 | pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
|
---|
108 | pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
|
---|
109 | pStubMsg->BufferLength = pRpcMsg->BufferLength;
|
---|
110 | pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
|
---|
111 | pStubMsg->pfnFree = pStubDesc->pfnFree;
|
---|
112 | pStubMsg->StubDesc = pStubDesc;
|
---|
113 | pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | RPC_STATUS WINAPI I_RpcGetBufferMarshall(PRPC_MESSAGE RpcMsg)
|
---|
117 | {
|
---|
118 | RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, RpcMsg->BufferLength);
|
---|
119 | memset(RpcMsg->Buffer, 0xcd, RpcMsg->BufferLength);
|
---|
120 | return 0;
|
---|
121 | }
|
---|