ReactOS  0.4.12-dev-375-g61fed54
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;
14  unsigned char Format[ TYPE_FORMAT_STRING_SIZE ];
16 
18  {
19  short Pad;
20  unsigned char Format[ PROC_FORMAT_STRING_SIZE ];
22 
23 extern const MIDL_STUB_DESC hello_StubDesc;
25 //extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;*/
26 
27 /*****************************************************************
28  * Modified from midl-generated stubs *
29  *****************************************************************/
30 
31 
32 void m_CtxOpen(
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  }
104  RpcFinally
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  }
257  RpcFinally
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  }
331  RpcFinally
332  {
333  NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );
334 
335  }
337 
338 }
339 
340 int interactive = 0;
341 void interact()
342 {
343  if(interactive)
344  {
345  printf("\nPress any key to continue...");
346  getch();
347  printf("\n\n");
348  }
349 }
350 
351 void 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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define RPC_X_SS_IN_NULL_CONTEXT
Definition: winerror.h:1083
static int test_value
Definition: signal.c:25
static int argc
Definition: ServiceArgs.c:12
const MIDL_STUB_DESC hello_StubDesc
Definition: ctx_c.c:236
#define RpcEndExcept
Definition: rpc.h:128
RPC_STATUS WINAPI RpcBindingFree(RPC_BINDING_HANDLE *Binding)
Definition: rpc_binding.c:784
int interactive
Definition: client.c:340
void __RPC_FAR *__RPC_USER midl_user_allocate(size_t len)
Definition: client.c:449
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
handle_t hBinding
Definition: ctx_c.c:54
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define free
Definition: debug_ros.c:5
void DECLSPEC_NORETURN WINAPI RpcRaiseException(RPC_STATUS exception)
Definition: rpcrt4_main.c:189
#define U(x)
Definition: wordpad.c:44
unsigned char * Buffer
Definition: rpcndr.h:203
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
GLuint buffer
Definition: glext.h:5915
void WINAPI NDRCContextMarshall(NDR_CCONTEXT CContext, void *pBuff)
PRPC_MESSAGE RpcMsg
Definition: rpcndr.h:202
CTXTYPE __RPC_FAR * PCTXTYPE
Definition: ctx.h:48
#define argv
Definition: mplay32.c:18
void WINAPI NdrConvert(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat)
void m_CtxOpen(PCTXTYPE __RPC_FAR *pphContext, long Value)
Definition: client.c:32
#define RpcFinally
Definition: rpc.h:130
#define RpcTryFinally
Definition: rpc.h:129
unsigned int BufferLength
Definition: rpcdcep.h:41
RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
long RPC_STATUS
Definition: rpc.h:52
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define RpcEndFinally
Definition: rpc.h:131
static PVOID ptr
Definition: dispmode.c:27
#define RpcTryExcept
Definition: rpc.h:126
smooth NULL
Definition: ftsmooth.c:416
#define __RPC_FAR
Definition: rpc.h:56
void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg, NDR_CCONTEXT ContextHandle, int fCheck)
#define PROC_FORMAT_STRING_SIZE
Definition: client.c:7
#define __RPC_USER
Definition: rpc.h:65
void interact()
Definition: client.c:341
const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString
Definition: ctx_c.c:264
struct _MIDL_TYPE_FORMAT_STRING MIDL_TYPE_FORMAT_STRING
_In_ HANDLE Handle
Definition: extypes.h:390
#define RpcExceptionCode()
Definition: rpc.h:132
void m_CtxClose(PCTXTYPE __RPC_FAR *pphContext)
Definition: client.c:267
const unsigned char * PFORMAT_STRING
Definition: rpcndr.h:176
unsigned char * BufferStart
Definition: rpcndr.h:204
void main(int argc, char **argv)
Definition: client.c:351
ULONG BufferLength
Definition: rpcndr.h:207
unsigned char * BufferEnd
Definition: rpcndr.h:205
GLenum GLsizei len
Definition: glext.h:6722
#define RpcStringFree
Definition: rpcdce.h:592
#define TYPE_FORMAT_STRING_SIZE
Definition: client.c:6
void CtxOpen(PCTXTYPE __RPC_FAR *pphContext, long Value)
Definition: ctx_c.c:76
void m_CtxHello(PCTXTYPE phContext)
Definition: client.c:206
#define NDR_LOCAL_DATA_REPRESENTATION
Definition: rpcndr.h:107
void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
_Check_return_ _CRTIMP int __cdecl getch(void)
unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
#define RpcStringBindingCompose
Definition: rpcdce.h:370
#define RpcBindingFromStringBinding
Definition: rpcdce.h:353
void __RPC_USER midl_user_free(void __RPC_FAR *ptr)
Definition: client.c:454
void m_CtxOpen2(PCTXTYPE __RPC_FAR *pphContext, long Value)
Definition: client.c:113
unsigned char *WINAPI NdrSendReceive(PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer)
void WINAPI NDRCContextUnmarshall(NDR_CCONTEXT *CContext, RPC_BINDING_HANDLE hBinding, void *pBuff, ULONG DataRepresentation)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
struct _MIDL_PROC_FORMAT_STRING MIDL_PROC_FORMAT_STRING
void WINAPI NdrClientInitializeNew(PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum)
#define malloc
Definition: debug_ros.c:4
void exit(int exitcode)
Definition: _exit.c:33
ULONG DataRepresentation
Definition: rpcdcep.h:39
void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, NDR_CCONTEXT *pContextHandle, RPC_BINDING_HANDLE BindHandle)
static SERVICE_STATUS status
Definition: service.c:31
unsigned char Format[PROC_FORMAT_STRING_SIZE]
Definition: client.c:20
#define RpcExcept(expr)
Definition: rpc.h:127
#define printf
Definition: config.h:203
Definition: ps.c:97