Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
4.0 KiB

  1. #include <windows.h>
  2. #include <assert.h>
  3. #include <wmimsg.h>
  4. #include <rcvtest.h>
  5. #include <rcvtest_i.c>
  6. #include <stdio.h>
  7. BOOL g_bVerbose = FALSE;
  8. ULONG g_ulNumMsgs = 1;
  9. LPCWSTR g_wszTarget = NULL;
  10. LPCWSTR g_wszPrincipal = NULL;
  11. DWORD g_dwFlags = 0;
  12. BOOL g_bKill = FALSE;
  13. BOOL ParseArg( LPWSTR wszArg )
  14. {
  15. WCHAR* pCurr = wszArg;
  16. if ( *pCurr != '/' && *pCurr != '-' )
  17. {
  18. g_wszTarget = pCurr;
  19. return TRUE;
  20. }
  21. pCurr++; // remove the / or -
  22. if ( wbem_wcsicmp( pCurr, L"txn" ) == 0 )
  23. {
  24. g_dwFlags &= ~WMIMSG_MASK_QOS;
  25. g_dwFlags |= WMIMSG_FLAG_QOS_XACT;
  26. }
  27. else if ( wbem_wcsicmp( pCurr, L"express" ) == 0 )
  28. {
  29. g_dwFlags &= ~WMIMSG_MASK_QOS;
  30. g_dwFlags |= WMIMSG_FLAG_QOS_EXPRESS;
  31. }
  32. else if ( wbem_wcsicmp( pCurr, L"guaranteed" ) == 0 )
  33. {
  34. g_dwFlags &= ~WMIMSG_MASK_QOS;
  35. g_dwFlags |= WMIMSG_FLAG_QOS_GUARANTEED;
  36. }
  37. else if ( wbem_wcsicmp( pCurr, L"sync" ) == 0 )
  38. {
  39. g_dwFlags &= ~WMIMSG_MASK_QOS;
  40. g_dwFlags |= WMIMSG_FLAG_QOS_SYNCHRONOUS;
  41. }
  42. else if ( wbem_wcsicmp( pCurr, L"ack" ) == 0 )
  43. {
  44. g_dwFlags |= WMIMSG_FLAG_RCVR_ACK;
  45. }
  46. else if ( wbem_wcsicmp( pCurr, L"verify" ) == 0 )
  47. {
  48. g_dwFlags |= WMIMSG_FLAG_RCVR_PRIV_VERIFY;
  49. }
  50. else if ( wbem_wcsicmp( pCurr, L"secure" ) == 0 )
  51. {
  52. g_dwFlags |= WMIMSG_FLAG_RCVR_SECURE_ONLY;
  53. }
  54. else if ( wbem_wcsnicmp( pCurr, L"nummsgs", 7 ) == 0 )
  55. {
  56. pCurr += 7;
  57. if ( *pCurr++ != ':' )
  58. {
  59. return FALSE;
  60. }
  61. g_ulNumMsgs = _wtol( pCurr );
  62. }
  63. else if ( wbem_wcsnicmp( pCurr, L"svrprinc", 8 ) == 0 )
  64. {
  65. pCurr += 8;
  66. if ( *pCurr++ != ':' )
  67. {
  68. return FALSE;
  69. }
  70. g_wszPrincipal = pCurr;
  71. }
  72. else if ( wbem_wcsicmp( pCurr, L"verbose" ) == 0 )
  73. {
  74. g_bVerbose = TRUE;
  75. }
  76. else if ( wbem_wcsicmp( pCurr, L"kill" ) == 0 )
  77. {
  78. g_bKill = TRUE;
  79. }
  80. else
  81. {
  82. return FALSE;
  83. }
  84. return TRUE;
  85. }
  86. BOOL ParseArgs( int nArgs, LPWSTR* awszArgs )
  87. {
  88. if ( nArgs < 2 )
  89. {
  90. return FALSE;
  91. }
  92. for( int i=1; i < nArgs; i++ )
  93. {
  94. if ( !ParseArg( awszArgs[i] ) )
  95. {
  96. return FALSE;
  97. }
  98. }
  99. return TRUE;
  100. }
  101. extern "C" int __cdecl wmain( int argc, wchar_t* argv[] )
  102. {
  103. if ( !ParseArgs( argc, argv ) )
  104. {
  105. wprintf( L"Usage: msgrcv [-sync|-express|-guaranteed|-txn] \n"
  106. L" [-nummsgs:#] [-ack] [-verify] \n"
  107. L" [-verbose] [-svrprinc:principal] endpoint\n" );
  108. return 1;
  109. }
  110. HRESULT hr;
  111. CoInitialize( NULL );
  112. IReceiveTest* pRcvTest;
  113. hr = CoCreateInstance( CLSID_ReceiveTest,
  114. NULL,
  115. CLSCTX_LOCAL_SERVER,
  116. IID_IReceiveTest,
  117. (void**)&pRcvTest );
  118. if ( FAILED(hr) )
  119. {
  120. printf( "Could not CoCI MsgSvr obj. HR = 0x%x\n", hr );
  121. return 1;
  122. }
  123. if ( g_bKill )
  124. {
  125. hr = pRcvTest->Kill();
  126. if ( FAILED(hr) )
  127. {
  128. printf("Failed to Kill MsgSvr. HR = 0x%x\n", hr );
  129. return 1;
  130. }
  131. printf("Killed MsgSvr\n");
  132. return 0;
  133. }
  134. ULONG ulElapsed;
  135. hr = pRcvTest->RunTest( g_wszTarget,
  136. g_dwFlags,
  137. g_wszPrincipal,
  138. g_ulNumMsgs,
  139. &ulElapsed );
  140. pRcvTest->Release();
  141. if ( FAILED(hr) )
  142. {
  143. printf( "Test Failed. HR = 0x%x\n", hr );
  144. return 1;
  145. }
  146. printf( "Test Succeeded in %d msec.\n", ulElapsed );
  147. printf( "Rate is %f msg/sec\n", g_ulNumMsgs * 1000.0 / ulElapsed );
  148. CoUninitialize();
  149. return 0;
  150. }