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.

212 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. testwp.cxx
  5. Abstract:
  6. Main module for the Rogue Worker Process. Takes the place of w3wp.exe/w3core.dll
  7. and calls directly into w3dt.dll, which will have been overwritten by tw3dt.dll.
  8. Author:
  9. Michael Brown ( MiBrown ) 4-Mar-2002
  10. Environment:
  11. Win32 - User Mode
  12. --*/
  13. /************************************************************
  14. * Include Headers
  15. ************************************************************/
  16. #include "precomp.hxx"
  17. HTTP_DATA_CHUNK g_DataChunk;
  18. HTTP_RESPONSE g_HttpResponse;
  19. VOID
  20. OnNewRequest(
  21. ULATQ_CONTEXT ulatqContext
  22. )
  23. {
  24. HRESULT hr;
  25. //
  26. // Set a context to receive on completions
  27. //
  28. UlAtqSetContextProperty( ulatqContext,
  29. ULATQ_PROPERTY_COMPLETION_CONTEXT,
  30. (PVOID) ulatqContext );
  31. //
  32. // Just send the response
  33. //
  34. DWORD cbSent;
  35. hr = UlAtqSendHttpResponse( ulatqContext,
  36. TRUE, // async
  37. 0, // no special flags
  38. &g_HttpResponse,
  39. NULL, // no UL cache
  40. &cbSent, // bytes sent
  41. NULL ); // no log
  42. if ( FAILED( hr ) )
  43. {
  44. UlAtqFreeContext( ulatqContext );
  45. }
  46. }
  47. VOID
  48. OnIoCompletion(
  49. VOID * pContext,
  50. DWORD cbWritten,
  51. DWORD dwCompletionStatus,
  52. OVERLAPPED * lpo
  53. )
  54. {
  55. //
  56. // Ignore the completion. Just cleanup the request
  57. //
  58. UlAtqFreeContext( (ULATQ_CONTEXT) pContext );
  59. }
  60. VOID
  61. OnUlDisconnect(
  62. VOID * pvContext
  63. )
  64. {
  65. return;
  66. }
  67. VOID
  68. OnShutdown(
  69. BOOL fDoImmediate
  70. )
  71. {
  72. return;
  73. }
  74. HRESULT FakeCollectCounters(PBYTE *ppCounterData,
  75. DWORD *pdwCounterData)
  76. {
  77. return E_FAIL;
  78. }
  79. extern "C" INT
  80. __cdecl
  81. wmain(
  82. INT argc,
  83. PWSTR argv[]
  84. )
  85. {
  86. HRESULT hr;
  87. ULATQ_CONFIG ulatqConfig;
  88. //
  89. // One time initialization of generic response
  90. //
  91. g_DataChunk.DataChunkType = HttpDataChunkFromMemory;
  92. g_DataChunk.FromMemory.pBuffer = "Hello From The IIS Rogue Worker Process!";
  93. g_DataChunk.FromMemory.BufferLength = strlen ((const char *) g_DataChunk.FromMemory.pBuffer);
  94. g_HttpResponse.Flags = 0;
  95. g_HttpResponse.StatusCode = 200;
  96. g_HttpResponse.pReason = "OK";
  97. g_HttpResponse.ReasonLength = (USHORT) strlen(g_HttpResponse.pReason);
  98. g_HttpResponse.Headers.UnknownHeaderCount = 1;
  99. g_HttpResponse.EntityChunkCount = 1;
  100. g_HttpResponse.pEntityChunks = &g_DataChunk;
  101. //
  102. // set the known headers
  103. //
  104. //g_HttpResponse.Headers.KnownHeaders[HttpHeaderContentLength].pRawValue = "0";
  105. // g_HttpResponse.Headers.KnownHeaders[HttpHeaderContentLength].RawValueLength = sizeof (CHAR);
  106. //
  107. // set the unknown headers
  108. //
  109. HTTP_UNKNOWN_HEADER UnknownHeader;
  110. memset(&UnknownHeader, 0, sizeof(HTTP_UNKNOWN_HEADER));
  111. g_HttpResponse.Headers.UnknownHeaderCount = 1;
  112. g_HttpResponse.Headers.pUnknownHeaders = &UnknownHeader;
  113. //
  114. // Set Header PID
  115. //
  116. PHTTP_UNKNOWN_HEADER pHeaderPid = g_HttpResponse.Headers.pUnknownHeaders;
  117. pHeaderPid->pName = "PID";
  118. pHeaderPid->NameLength = (USHORT) strlen (pHeaderPid->pName);
  119. CHAR Pid[256];
  120. pHeaderPid->pRawValue = _itoa (GetCurrentProcessId(), Pid, 10);
  121. pHeaderPid->RawValueLength = (USHORT) strlen (pHeaderPid->pRawValue);
  122. /*
  123. //
  124. // Set Header Application-Pool
  125. //
  126. PHTTP_UNKNOWN_HEADER pHeaderAppPool = (pResponse->Headers.pUnknownHeaders + 1);
  127. pHeaderAppPool->pName = "Application-Pool";
  128. pHeaderAppPool->NameLength = strlen (pHeaderAppPool->pName);
  129. WP_CONFIG* wpConfig = g_pwpContext->QueryConfig ();
  130. CHAR AppPoolName[256];
  131. wcstombs (AppPoolName, wpConfig->QueryAppPoolName(), wcslen(wpConfig->QueryAppPoolName()));
  132. pHeaderAppPool->pRawValue = AppPoolName;
  133. pHeaderAppPool->RawValueLength = strlen(pHeaderAppPool->pRawValue);
  134. */
  135. //
  136. // Initialize ULATQ
  137. //
  138. ulatqConfig.pfnNewRequest = OnNewRequest;
  139. ulatqConfig.pfnIoCompletion = OnIoCompletion;
  140. ulatqConfig.pfnOnShutdown = OnShutdown;
  141. ulatqConfig.pfnDisconnect = OnUlDisconnect;
  142. ulatqConfig.pfnCollectCounters = FakeCollectCounters;
  143. hr = UlAtqInitialize( argc, argv, &ulatqConfig );
  144. if ( FAILED( hr ) )
  145. {
  146. return -1;
  147. }
  148. //
  149. // Start listening
  150. //
  151. UlAtqStartListen();
  152. //
  153. // Cleanup
  154. //
  155. UlAtqTerminate(S_OK);
  156. return 0;
  157. }
  158. /************************ End of File ***********************/