ReactOS 0.4.15-dev-7968-g24a56f8
client.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <stdio.h>
3#include <ctype.h>
4#include "ctx.h"
5
6#define TYPE_FORMAT_STRING_SIZE 23
7#define PROC_FORMAT_STRING_SIZE 21
8#define TRANSMIT_AS_TABLE_SIZE 0
9#define WIRE_MARSHAL_TABLE_SIZE 0
10
12 {
13 short Pad;
16
18 {
19 short Pad;
22
25//extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;*/
26
27/*****************************************************************
28 * Modified from midl-generated stubs *
29 *****************************************************************/
30
31
33 /* [out] */ PCTXTYPE __RPC_FAR *pphContext,
34 /* [in] */ long Value)
35{
36 RPC_BINDING_HANDLE _Handle = 0;
37
38 RPC_MESSAGE _RpcMessage;
39
40 MIDL_STUB_MESSAGE _StubMsg;
41
42 char *ctx, *buf;
43 int i;
44
45 printf("\n*******************************************************************\n");
46 printf("**** CtxOpen() ***\n");
47 printf("*******************************************************************\n\n");
48
49 if(!pphContext)
50 {
52 }
54 {
56 ( PRPC_MESSAGE )&_RpcMessage,
57 ( PMIDL_STUB_MESSAGE )&_StubMsg,
59 0);
60
61
62 _Handle = hBinding;
63
64
65 _StubMsg.BufferLength = 4U;
66 NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );
67
68 *(( long __RPC_FAR * )_StubMsg.Buffer)++ = Value;
69
70 NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );
71
72 if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
74
75
76 printf("Before NdrClientContextUnmarshall: Buflen=%d\nBuffer: ", _StubMsg.RpcMsg->BufferLength);
77 for(buf = _StubMsg.Buffer, i = 0; i < _StubMsg.RpcMsg->BufferLength; i++)
78 printf("0x%x, ", buf[i] & 0x0FF);
79 printf("\n\n");
80
81 *pphContext = (void *)0;
83 ( PMIDL_STUB_MESSAGE )&_StubMsg,
84 ( NDR_CCONTEXT __RPC_FAR * )pphContext,
85 _Handle);
86
87 ctx = (char*)*pphContext;
88 printf("\nNdrClientContextUnmarshall returned: handle=0x%p\n", ctx);
89 printf("00: 0x%x <- obviously pointer to binding handle copyed from _Handle\n", *((int*)ctx));
90 ctx+=4;
91 printf("04: 0x%x <- unknown field\n", *((int*)ctx));
92 printf("08: ");
93
94 for(ctx+=4, i = 0; i < 20; i++)
95 printf("0x%x,", *(ctx+i) & 0x0FF); printf(" <- ndr 20 bytes\n\n");
96
97 printf("Buflen=%d, Buffer: ", _StubMsg.BufferLength);
98 for(buf = _StubMsg.BufferStart; buf < _StubMsg.BufferEnd; buf++)
99 printf("0x%x,", *buf & 0x0FF);
100 printf("\n");
101
102
103 }
105 {
106 NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );
107
108 }
110
111}
112
114 /* [out] */ PCTXTYPE __RPC_FAR *pphContext,
115 /* [in] */ long Value)
116{
117
118 RPC_BINDING_HANDLE _Handle = 0;
119
120 RPC_MESSAGE _RpcMessage;
121
122 MIDL_STUB_MESSAGE _StubMsg;
123
124 char buf[255];
125
127 ( PRPC_MESSAGE )&_RpcMessage,
128 ( PMIDL_STUB_MESSAGE )&_StubMsg,
130 0);
131
132
133 _Handle = hBinding;
134
135
136 _StubMsg.BufferLength = 4U;
137 NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );
138
139 *(( long __RPC_FAR * )_StubMsg.Buffer)++ = Value;
140
141 NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );
142
143 if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
145
146 *pphContext = (void *)0;
147
149 {
151 ( PMIDL_STUB_MESSAGE )&_StubMsg,
152 NULL,
153 _Handle);
154 }
155 RpcExcept(1)
156 {
157 printf("NdrClientContextUnmarshall reported exception = %d\n", RpcExceptionCode());
158 }
160
161
162
164 {
166 ( PMIDL_STUB_MESSAGE )&_StubMsg,
167 (NDR_CCONTEXT __RPC_FAR * )pphContext,
168 NULL);
169 }
170 RpcExcept(1)
171 {
172 printf("NdrClientContextUnmarshall reported exception = %d\n", RpcExceptionCode());
173 }
175
176
178 {
180 ( PMIDL_STUB_MESSAGE )&_StubMsg,
181 NULL,
182 1);
183 }
184 RpcExcept(1)
185 {
186 printf("NdrClientContextMarshall reported exception = %d\n", RpcExceptionCode());
187 }
189
191 {
192 NDRCContextUnmarshall( NULL, _Handle, buf, _RpcMessage.DataRepresentation );
193 }
194 RpcExcept(1)
195 {
196 printf("NDRCContextUnmarshall reported exception = %d\n", RpcExceptionCode());
197 }
199
200
201 NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );
202
203
204}
205
207 /* [in] */ PCTXTYPE phContext)
208{
209
210 RPC_BINDING_HANDLE _Handle = 0;
211
212 RPC_MESSAGE _RpcMessage;
213
214 MIDL_STUB_MESSAGE _StubMsg;
215
216 char *buf;
217 int i;
218
219 printf("\n*******************************************************************\n");
220 printf("**** CtxHello() ***\n");
221 printf("*******************************************************************\n\n");
222
224 {
226 ( PRPC_MESSAGE )&_RpcMessage,
227 ( PMIDL_STUB_MESSAGE )&_StubMsg,
229 1);
230
231
232 if(phContext != 0)
233 {
234 _Handle = NDRCContextBinding(( NDR_CCONTEXT )phContext);;
235
236 }
237 else
238 {
240 }
241
242 _StubMsg.BufferLength = 20U;
243 NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );
244
246 ( PMIDL_STUB_MESSAGE )&_StubMsg,
247 ( NDR_CCONTEXT )phContext,
248 1);
249 printf("After NdrClientContextMarshall: Buflen=%d\nBuffer: ", _StubMsg.BufferLength );
250 for(buf = _StubMsg.Buffer, i = 0; i < _StubMsg.BufferLength; i++)
251 printf("0x%x, ", buf[i] & 0x0FF);
252 printf("\n\n");
253
254 NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );
255
256 }
258 {
259 NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );
260
261 }
263
264}
265
266
268 /* [out][in] */ PCTXTYPE __RPC_FAR *pphContext)
269{
270
271 RPC_BINDING_HANDLE _Handle = 0;
272
273 RPC_MESSAGE _RpcMessage;
274
275 MIDL_STUB_MESSAGE _StubMsg;
276 char *buf;
277 int i;
278
279 printf("\n*******************************************************************\n");
280 printf("**** CtxClose() ***\n");
281 printf("*******************************************************************\n\n");
282
283 if(!pphContext)
284 {
286 }
288 {
290 ( PRPC_MESSAGE )&_RpcMessage,
291 ( PMIDL_STUB_MESSAGE )&_StubMsg,
293 2);
294
295
296 if(*pphContext != 0)
297 {
298 _Handle = NDRCContextBinding(( NDR_CCONTEXT )*pphContext);;
299
300 }
301
302 _StubMsg.BufferLength = 20U;
303 NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );
304
306 ( PMIDL_STUB_MESSAGE )&_StubMsg,
307 ( NDR_CCONTEXT )*pphContext,
308 0);
309
310 NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );
311
312 if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
314
315
316 printf("Before NdrClientContextUnmarshall: Buflen=%d\nBuffer: ", _StubMsg.BufferLength );
317 for(buf = _StubMsg.Buffer, i = 0; i < _StubMsg.BufferLength; i++)
318 printf("0x%x, ", buf[i] & 0x0FF);
319 printf("\n\n");
320
322 ( PMIDL_STUB_MESSAGE )&_StubMsg,
323 ( NDR_CCONTEXT __RPC_FAR * )pphContext,
324 _Handle);
325
326
327 printf("\nNdrClientContextUnmarshall returned: handle=0x%p\n", *pphContext);
328
329
330 }
332 {
333 NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );
334
335 }
337
338}
339
342{
343 if(interactive)
344 {
345 printf("\nPress any key to continue...");
346 getch();
347 printf("\n\n");
348 }
349}
350
351void main(int argc, char **argv)
352{
354 unsigned long ulCode;
355 PCTXTYPE hContext;
356 char *pszStringBinding = NULL;
358 char buffer[255];
359
360 int test_num = 0;
361 int test_value = 31337;
362
363 if(argc<2)
364 {
365 printf("USAGE: client.exe <test_number> [test_value] [interactive]\n"
366 "Available tests:\n"
367 "0. General test\n"
368 "1. NULL pointer test\n"
369 "2. Context rundown routine");
370 return;
371 }
372
373 test_num = atoi(argv[1]);
374 if(argc>2) test_value = atoi(argv[2]);
375 if(argc>3) interactive = 1;
376
378 "ncacn_np",
379 NULL,
380 "\\pipe\\hello",
381 NULL,
382 &pszStringBinding);
383
384 if (status)
385 {
386 printf("RpcStringBindingCompose %x\n", status);
387 exit(status);
388 }
389
390 status = RpcBindingFromStringBinding(pszStringBinding, &hBinding);
391
392 if (status)
393 {
394 printf("RpcBindingFromStringBinding %x\n", status);
395 exit(status);
396 }
397
398 RpcStringFree(&pszStringBinding);
399
400 switch(test_num)
401 {
402 case 0:
403 m_CtxOpen(&hContext, test_value);
405 m_CtxHello(hContext);
406 interact();
407 m_CtxClose(&hContext);
408 break;
409 case 1:
412 {
414 printf("NDRCContextBinding(NULL) returned %p\n", Handle);
415 }
416 RpcExcept(1)
417 {
418 printf("NDRCContextBinding(NULL) reported exception = %d\n", RpcExceptionCode());
419 }
421
422 m_CtxOpen2(&hContext, test_value);
423
426 {
428 printf("NDRCContextMarshall(NULL) returned %p\n", Handle);
429 }
430 RpcExcept(1)
431 {
432 printf("NDRCContextMarshall(NULL) reported exception = %d\n", RpcExceptionCode());
433 }
436 break;
437 case 2:
438 CtxOpen(&hContext, test_value);
439 interact();
440 ExitProcess(0);
441 break;
442 default:
443 printf("Unknown test %d\n", test_num);
444 }
445
446}
447
448
450{
451 return(malloc(len));
452}
453
455{
456 free(ptr);
457}
static int argc
Definition: ServiceArgs.c:12
void CtxOpen(PCTXTYPE __RPC_FAR *pphContext, long Value)
Definition: ctx_c.c:76
handle_t hBinding
Definition: ctx_c.c:54
CTXTYPE __RPC_FAR * PCTXTYPE
Definition: ctx.h:48
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg, NDR_CCONTEXT ContextHandle, int fCheck)
void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, NDR_CCONTEXT *pContextHandle, RPC_BINDING_HANDLE BindHandle)
void WINAPI NdrConvert(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat)
int main()
Definition: test.c:6
#define printf
Definition: freeldr.h:97
ULONG Handle
Definition: gdb_input.c:15
GLuint buffer
Definition: glext.h:5915
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
static PVOID ptr
Definition: dispmode.c:27
void m_CtxHello(PCTXTYPE phContext)
Definition: client.c:206
void m_CtxOpen2(PCTXTYPE __RPC_FAR *pphContext, long Value)
Definition: client.c:113
void m_CtxClose(PCTXTYPE __RPC_FAR *pphContext)
Definition: client.c:267
const MIDL_STUB_DESC hello_StubDesc
Definition: ctx_c.c:236
#define PROC_FORMAT_STRING_SIZE
Definition: client.c:7
struct _MIDL_PROC_FORMAT_STRING MIDL_PROC_FORMAT_STRING
const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString
Definition: ctx_c.c:264
void m_CtxOpen(PCTXTYPE __RPC_FAR *pphContext, long Value)
Definition: client.c:32
void interact()
Definition: client.c:341
#define TYPE_FORMAT_STRING_SIZE
Definition: client.c:6
int interactive
Definition: client.c:340
struct _MIDL_TYPE_FORMAT_STRING MIDL_TYPE_FORMAT_STRING
static int test_value
Definition: signal.c:25
#define argv
Definition: mplay32.c:18
void WINAPI NdrClientInitializeNew(PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum)
void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
unsigned char *WINAPI NdrSendReceive(PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer)
RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
void WINAPI NDRCContextUnmarshall(NDR_CCONTEXT *CContext, RPC_BINDING_HANDLE hBinding, void *pBuff, ULONG DataRepresentation)
void WINAPI NDRCContextMarshall(NDR_CCONTEXT CContext, void *pBuff)
RPC_STATUS WINAPI RpcBindingFree(RPC_BINDING_HANDLE *Binding)
Definition: rpc_binding.c:787
#define RpcStringBindingCompose
Definition: rpcdce.h:370
#define RpcBindingFromStringBinding
Definition: rpcdce.h:353
#define RpcStringFree
Definition: rpcdce.h:592
#define NDR_LOCAL_DATA_REPRESENTATION
Definition: rpcndr.h:107
const unsigned char * PFORMAT_STRING
Definition: rpcndr.h:176
void DECLSPEC_NORETURN WINAPI RpcRaiseException(RPC_STATUS exception)
Definition: rpcrt4_main.c:188
_Check_return_ _CRTIMP int __cdecl getch(void)
#define RpcEndFinally
Definition: rpc.h:131
#define RpcTryFinally
Definition: rpc.h:129
#define RpcEndExcept
Definition: rpc.h:128
#define midl_user_free
Definition: rpc.h:45
#define __RPC_FAR
Definition: rpc.h:56
#define RpcTryExcept
Definition: rpc.h:126
#define RpcFinally
Definition: rpc.h:130
#define RpcExcept(expr)
Definition: rpc.h:127
long RPC_STATUS
Definition: rpc.h:52
#define __RPC_USER
Definition: rpc.h:65
#define RpcExceptionCode()
Definition: rpc.h:132
#define midl_user_allocate
Definition: rpc.h:44
#define exit(n)
Definition: config.h:202
unsigned char Format[PROC_FORMAT_STRING_SIZE]
Definition: client.c:20
unsigned char * Buffer
Definition: rpcndr.h:203
ULONG BufferLength
Definition: rpcndr.h:207
unsigned char * BufferEnd
Definition: rpcndr.h:205
PRPC_MESSAGE RpcMsg
Definition: rpcndr.h:202
unsigned char * BufferStart
Definition: rpcndr.h:204
unsigned int BufferLength
Definition: rpcdcep.h:41
ULONG DataRepresentation
Definition: rpcdcep.h:39
Definition: ps.c:97
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define RPC_X_SS_IN_NULL_CONTEXT
Definition: winerror.h:1083
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087