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.

221 lines
5.3 KiB

  1. //
  2. // Microsoft Corporation - Copyright 1997
  3. //
  4. //
  5. // DLLMAIN.CPP - DLL entry points
  6. //
  7. #include "pch.h"
  8. // Globals
  9. HANDLE g_hInst;
  10. //
  11. // What: DllMain
  12. //
  13. // Desc: Dll initialization entry point.
  14. //
  15. BOOL WINAPI DllMain (
  16. HANDLE hInst,
  17. ULONG ulReason,
  18. LPVOID lpReserved )
  19. {
  20. TraceMsg( TF_FUNC | TF_DLL, "DllMain( )" );
  21. #if 0
  22. DebugBreak( ); // stop so we can get a chance to enable break points
  23. #endif
  24. switch( ulReason )
  25. {
  26. case DLL_PROCESS_ATTACH:
  27. g_hInst = hInst;
  28. break;
  29. case DLL_PROCESS_DETACH:
  30. break;
  31. }
  32. return TRUE;
  33. } // DllMain( )
  34. //
  35. // What: DllRegisterServer
  36. //
  37. // Desc: Register our ISAPI with IIS
  38. //
  39. STDAPI DllRegisterServer( void )
  40. {
  41. HRESULT hr = S_OK;
  42. TraceMsg( TF_FUNC | TF_DLL, "DllRegisterServer( )" );
  43. TraceMsgResult( TF_DLL, &HRtoStr, hr, "DllRegisterServer( ) Exit" );
  44. return hr;
  45. } // DllRegisterServer( )
  46. //
  47. // What: GetExtensionVersion
  48. //
  49. // Desc: ISAPI entry point
  50. //
  51. BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *pVer )
  52. {
  53. TraceMsg( TF_FUNC | TF_DLL, "GetExtensionVersion( pVer )" );
  54. pVer->dwExtensionVersion = MAKELONG( FILEUPLD_VERSION_MINOR,
  55. FILEUPLD_VERSION_MAJOR );
  56. StrCpyN( pVer->lpszExtensionDesc,
  57. FILEUPLD_DESCRIPTION,
  58. HSE_MAX_EXT_DLL_NAME_LEN );
  59. TraceMsg( TF_FUNC | TF_DLL, "GetExtensionVersion( pVer ) Exit BOOL=TRUE" );
  60. return TRUE;
  61. } // GetExtensionVersion( )
  62. //
  63. // What: HttpExtensionProc
  64. //
  65. // Desc: ISAPI entry point
  66. //
  67. DWORD HttpExtensionProc( LPEXTENSION_CONTROL_BLOCK lpEcb )
  68. {
  69. DWORD dwResult = HSE_STATUS_SUCCESS; // return status
  70. BOOL fReturn; // status flag
  71. BOOL fMultipart; // multipart/form-data submit?
  72. BOOL fTextPlain; // text/plain submit?
  73. BOOL fDebug; // show debug spew?
  74. LPSTR lpszOut = NULL; // server log output
  75. LPSTR lpszDebug = NULL; // debug output
  76. LPBYTE lpbData; // pointer to body data
  77. DWORD dwParsed; // number of bytes parsed
  78. DUMPTABLE DT[ MAX_DT ]; // Hex Dump table info.
  79. QUERYMETHOD eMethod = METHOD_UNKNOWN; // method of query
  80. CMultipartParse *lpMPParser = NULL;
  81. CTextPlainParse *lpTPParser = NULL;
  82. TraceMsg( TF_FUNC | TF_DLL, "HttpExtensionProc( lpEcb )" );
  83. #if 0
  84. fReturn = SendEcho( lpEcb );
  85. #endif
  86. // Make sure that we have all the data
  87. fReturn = CompleteDownload( lpEcb, &lpbData );
  88. // Check content-type for multipart
  89. if ( fReturn )
  90. {
  91. fReturn = CheckForMultiPartFormSubmit( lpEcb, &fMultipart );
  92. }
  93. if ( fReturn )
  94. {
  95. fReturn = CheckForTextPlainSubmit( lpEcb, &fTextPlain );
  96. }
  97. if ( fReturn )
  98. {
  99. fReturn = CheckForDebug( lpEcb, &fDebug );
  100. }
  101. // Parse
  102. if ( fReturn )
  103. {
  104. if ( fMultipart )
  105. {
  106. if ( fDebug )
  107. {
  108. lpMPParser = new CMultipartParse( lpEcb, &lpszOut, &lpszDebug, DT );
  109. }
  110. else
  111. {
  112. lpMPParser = new CMultipartParse( lpEcb, &lpszOut, NULL, DT );
  113. lpszDebug = NULL;
  114. }
  115. fReturn = lpMPParser->PreParse( lpbData, &dwParsed );
  116. eMethod= METHOD_POSTMULTIPART;
  117. }
  118. else if ( fTextPlain )
  119. {
  120. if ( ! fDebug )
  121. {
  122. lpTPParser = new CTextPlainParse( lpEcb, &lpszOut, &lpszDebug, DT );
  123. }
  124. else
  125. {
  126. lpTPParser = new CTextPlainParse( lpEcb, &lpszOut, NULL, DT );
  127. lpszDebug = NULL;
  128. }
  129. fReturn = lpTPParser->Parse( lpbData, &dwParsed );
  130. eMethod= METHOD_POSTTEXTPLAIN;
  131. }
  132. else
  133. {
  134. if ( !StrCmpI( lpEcb->lpszMethod, "POST" ) )
  135. {
  136. eMethod= METHOD_POST;
  137. }
  138. else if ( !StrCmpI( lpEcb->lpszMethod, "GET" ) )
  139. {
  140. eMethod= METHOD_GET;
  141. }
  142. }
  143. }
  144. // Display results
  145. if ( fReturn )
  146. {
  147. fReturn = SendSuccess( eMethod, lpEcb, lpszOut, lpszDebug, lpbData, dwParsed, DT );
  148. }
  149. else
  150. {
  151. fReturn = SendFailure( eMethod, lpEcb, lpszOut, lpszDebug, lpbData, dwParsed, DT );
  152. }
  153. // Check to see if everything went OK
  154. if ( !fReturn )
  155. {
  156. dwResult = HSE_STATUS_ERROR;
  157. }
  158. // Free if we created the buffer
  159. if ( lpEcb->lpbData != lpbData )
  160. {
  161. GlobalFree( lpbData );
  162. }
  163. delete lpMPParser;
  164. delete lpTPParser;
  165. TraceMsgResult( TF_FUNC | TF_DLL, &HSEtoStr, dwResult, "HttpExtensionProc( lpEcb ) " );
  166. lpEcb->dwHttpStatusCode = dwResult;
  167. return dwResult;
  168. } // HttpExtensionProc( )
  169. //
  170. // Support functions
  171. //
  172. void * __cdecl operator new( unsigned int nSize )
  173. {
  174. return ((LPVOID) LocalAlloc( LMEM_FIXED, nSize ));
  175. }
  176. void __cdecl operator delete( void *pv )
  177. {
  178. LocalFree( pv );
  179. }
  180. extern "C" int __cdecl _purecall( void ) { return 0; }