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.

430 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. wbisapi.cxx
  5. Abstract:
  6. Implements a fast WebBench ISAPI
  7. Author:
  8. Bilal Alam (balam) Sept 3, 2002
  9. --*/
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <httpext.h>
  15. #include <string.hxx>
  16. CHAR * g_pszStaticHeader;
  17. DWORD g_cbStaticHeader;
  18. DWORD
  19. WINAPI
  20. HttpExtensionProc(
  21. EXTENSION_CONTROL_BLOCK * pecb
  22. )
  23. /*++
  24. Routine Description:
  25. Main entry point for ISAPI
  26. Arguments:
  27. pecb - EXTENSION_CONTROL_BLOCK *
  28. Return Value:
  29. HSE_STATUS_*
  30. --*/
  31. {
  32. CHAR achDynamic[ 4096 ];
  33. STRA strDynamic( achDynamic, sizeof( achDynamic ) );
  34. HRESULT hr;
  35. BOOL fRet;
  36. CHAR achBuffer[ 512 ];
  37. DWORD cbBuffer;
  38. HSE_RESPONSE_VECTOR responseVector;
  39. HSE_VECTOR_ELEMENT vectorElement[ 2 ];
  40. //
  41. // Generate dynamic portion
  42. //
  43. hr = strDynamic.Append( "SERVER_NAME = <B>" );
  44. if ( FAILED( hr ) )
  45. {
  46. goto Failure;
  47. }
  48. cbBuffer = sizeof( achBuffer );
  49. fRet = pecb->GetServerVariable( pecb->ConnID,
  50. "SERVER_NAME",
  51. achBuffer,
  52. &cbBuffer );
  53. if ( !fRet )
  54. {
  55. hr = HRESULT_FROM_WIN32( GetLastError() );
  56. goto Failure;
  57. }
  58. hr = strDynamic.Append( achBuffer );
  59. if ( FAILED( hr ) )
  60. {
  61. goto Failure;
  62. }
  63. hr = strDynamic.Append( "</B>\nGATEWAY_INTERFACE = <B>CGI/1.1</B>\nSERVER_PROTOCOL = <B>" );
  64. if ( FAILED( hr ) )
  65. {
  66. goto Failure;
  67. }
  68. cbBuffer = sizeof( achBuffer );
  69. fRet = pecb->GetServerVariable( pecb->ConnID,
  70. "SERVER_PROTOCOL",
  71. achBuffer,
  72. &cbBuffer );
  73. if ( !fRet )
  74. {
  75. hr = HRESULT_FROM_WIN32( GetLastError() );
  76. goto Failure;
  77. }
  78. hr = strDynamic.Append( achBuffer );
  79. if ( FAILED( hr ) )
  80. {
  81. goto Failure;
  82. }
  83. hr = strDynamic.Append( "</B>\nSERVER_PORT = <B>80</B>\nREQUEST_METHOD = <B>" );
  84. if ( FAILED( hr ) )
  85. {
  86. goto Failure;
  87. }
  88. hr = strDynamic.Append( pecb->lpszMethod );
  89. if ( FAILED( hr ) )
  90. {
  91. goto Failure;
  92. }
  93. hr = strDynamic.Append( "</B>\nHTTP_ACCEPT = <B>" );
  94. if ( FAILED( hr ) )
  95. {
  96. goto Failure;
  97. }
  98. cbBuffer = sizeof( achBuffer );
  99. fRet = pecb->GetServerVariable( pecb->ConnID,
  100. "HTTP_ACCEPT",
  101. achBuffer,
  102. &cbBuffer );
  103. if ( !fRet )
  104. {
  105. achBuffer[ 0 ] = '\0';
  106. }
  107. hr = strDynamic.Append( achBuffer );
  108. if ( FAILED( hr ) )
  109. {
  110. goto Failure;
  111. }
  112. hr = strDynamic.Append( "</B>\nHTTP_USER_AGENT = <B>" );
  113. if ( FAILED( hr ) )
  114. {
  115. goto Failure;
  116. }
  117. cbBuffer = sizeof( achBuffer );
  118. fRet = pecb->GetServerVariable( pecb->ConnID,
  119. "HTTP_USER_AGENT",
  120. achBuffer,
  121. &cbBuffer );
  122. if ( !fRet )
  123. {
  124. achBuffer[ 0 ] = '\0';
  125. }
  126. hr = strDynamic.Append( achBuffer );
  127. if ( FAILED( hr ) )
  128. {
  129. goto Failure;
  130. }
  131. hr = strDynamic.Append( "</B>\nHTTP_REFERER = <B>" );
  132. if ( FAILED( hr ) )
  133. {
  134. goto Failure;
  135. }
  136. cbBuffer = sizeof( achBuffer );
  137. fRet = pecb->GetServerVariable( pecb->ConnID,
  138. "HTTP_REFERER",
  139. achBuffer,
  140. &cbBuffer );
  141. if ( !fRet )
  142. {
  143. achBuffer[ 0 ] = '\0';
  144. }
  145. hr = strDynamic.Append( achBuffer );
  146. if ( FAILED( hr ) )
  147. {
  148. goto Failure;
  149. }
  150. hr = strDynamic.Append( "</B>\nPATH_INFO = <B>" );
  151. if ( FAILED( hr ) )
  152. {
  153. goto Failure;
  154. }
  155. hr = strDynamic.Append( pecb->lpszPathInfo );
  156. if ( FAILED( hr ) )
  157. {
  158. goto Failure;
  159. }
  160. hr = strDynamic.Append( "</B>\nPATH_TRANSLATED = <B>" );
  161. if ( FAILED( hr ) )
  162. {
  163. goto Failure;
  164. }
  165. hr = strDynamic.Append( pecb->lpszPathTranslated );
  166. if ( FAILED( hr ) )
  167. {
  168. goto Failure;
  169. }
  170. hr = strDynamic.Append( "</B>\nSCRIPT_NAME = <B>" );
  171. if ( FAILED( hr ) )
  172. {
  173. goto Failure;
  174. }
  175. cbBuffer = sizeof( achBuffer );
  176. fRet = pecb->GetServerVariable( pecb->ConnID,
  177. "SCRIPT_NAME",
  178. achBuffer,
  179. &cbBuffer );
  180. if ( !fRet )
  181. {
  182. hr = HRESULT_FROM_WIN32( GetLastError() );
  183. goto Failure;
  184. }
  185. hr = strDynamic.Append( achBuffer );
  186. if ( FAILED( hr ) )
  187. {
  188. goto Failure;
  189. }
  190. hr = strDynamic.Append( "</B>\nQUERY_STRING = <B>" );
  191. if ( FAILED( hr ) )
  192. {
  193. goto Failure;
  194. }
  195. hr = strDynamic.Append( pecb->lpszQueryString );
  196. if ( FAILED( hr ) )
  197. {
  198. goto Failure;
  199. }
  200. hr = strDynamic.Append( "</B>\nREMOTE_HOST = <B>" );
  201. if ( FAILED( hr ) )
  202. {
  203. goto Failure;
  204. }
  205. cbBuffer = sizeof( achBuffer );
  206. fRet = pecb->GetServerVariable( pecb->ConnID,
  207. "REMOTE_HOST",
  208. achBuffer,
  209. &cbBuffer );
  210. if ( !fRet )
  211. {
  212. hr = HRESULT_FROM_WIN32( GetLastError() );
  213. goto Failure;
  214. }
  215. hr = strDynamic.Append( achBuffer );
  216. if ( FAILED( hr ) )
  217. {
  218. goto Failure;
  219. }
  220. hr = strDynamic.Append( "</B>\nREMOTE_ADDR = <B>" );
  221. if ( FAILED( hr ) )
  222. {
  223. goto Failure;
  224. }
  225. hr = strDynamic.Append( achBuffer );
  226. if ( FAILED( hr ) )
  227. {
  228. goto Failure;
  229. }
  230. hr = strDynamic.Append( "</B>\nREMOTE_USER = <B></B>\nAUTH_TYPE = <B></B>\nCONTENT_TYPE = <B>" );
  231. if ( FAILED( hr ) )
  232. {
  233. goto Failure;
  234. }
  235. hr = strDynamic.Append( pecb->lpszContentType );
  236. if ( FAILED( hr ) )
  237. {
  238. goto Failure;
  239. }
  240. hr = strDynamic.Append( "</B>\nCONTENT_LENGTH = <B>" );
  241. if ( FAILED( hr ) )
  242. {
  243. goto Failure;
  244. }
  245. cbBuffer = sizeof( achBuffer );
  246. fRet = pecb->GetServerVariable( pecb->ConnID,
  247. "CONTENT_LENGTH",
  248. achBuffer,
  249. &cbBuffer );
  250. if ( !fRet )
  251. {
  252. hr = HRESULT_FROM_WIN32( GetLastError() );
  253. goto Failure;
  254. }
  255. hr = strDynamic.Append( achBuffer );
  256. if ( FAILED( hr ) )
  257. {
  258. goto Failure;
  259. }
  260. hr = strDynamic.Append( "</B>\nANNOTATION_SERVER = <B></B>\n\n</pre></BODY></HTML>" );
  261. if ( FAILED( hr ) )
  262. {
  263. goto Failure;
  264. }
  265. //
  266. // Phew. Now that dynamic portion is done, send out response
  267. //
  268. vectorElement[ 0 ].ElementType = HSE_VECTOR_ELEMENT_TYPE_MEMORY_BUFFER;
  269. vectorElement[ 0 ].pvContext = g_pszStaticHeader;
  270. vectorElement[ 0 ].cbSize = g_cbStaticHeader;
  271. vectorElement[ 1 ].ElementType = HSE_VECTOR_ELEMENT_TYPE_MEMORY_BUFFER;
  272. vectorElement[ 1 ].pvContext = strDynamic.QueryStr();
  273. vectorElement[ 1 ].cbSize = strDynamic.QueryCB();
  274. responseVector.lpElementArray = vectorElement;
  275. responseVector.nElementCount = 2;
  276. responseVector.dwFlags = HSE_IO_FINAL_SEND | HSE_IO_SYNC | HSE_IO_DISCONNECT_AFTER_SEND;
  277. responseVector.pszStatus = NULL;
  278. responseVector.pszHeaders = NULL;
  279. //
  280. // Let'r rip
  281. //
  282. fRet = pecb->ServerSupportFunction( pecb->ConnID,
  283. HSE_REQ_VECTOR_SEND,
  284. &responseVector,
  285. NULL,
  286. NULL );
  287. if ( !fRet )
  288. {
  289. return HSE_STATUS_ERROR;
  290. }
  291. else
  292. {
  293. return HSE_STATUS_SUCCESS;
  294. }
  295. Failure:
  296. SetLastError( hr );
  297. return HSE_STATUS_ERROR;
  298. }
  299. BOOL
  300. WINAPI
  301. GetExtensionVersion(
  302. HSE_VERSION_INFO * pver
  303. )
  304. /*++
  305. Routine Description:
  306. Initialization routine for ISAPI
  307. Arguments:
  308. pver - Version information
  309. Return Value:
  310. TRUE if successful, else FALSE
  311. --*/
  312. {
  313. //
  314. // Do ISAPI interface init crap
  315. //
  316. pver->dwExtensionVersion = MAKELONG( 0, 1 );
  317. strcpy( pver->lpszExtensionDesc,
  318. "WebBench ISAPI" );
  319. //
  320. // Setup static header
  321. //
  322. g_pszStaticHeader = "HTTP/1.1 200 OK\r\n" \
  323. "Content-type: text/html\r\n\r\n" \
  324. "<HTML><HEAD><TITLE>WebBench 2.0 HTTP API Application</TITLE></HEAD><BODY>\n" \
  325. "<pre>SERVER_SOFTWARE = <B>Microsoft-IIS/6.0</B>\n";
  326. g_cbStaticHeader = (DWORD) strlen( g_pszStaticHeader );
  327. return TRUE;
  328. }
  329. BOOL
  330. WINAPI
  331. TerminateExtension(
  332. DWORD
  333. )
  334. /*++
  335. Routine Description:
  336. Cleanup ISAPI extension
  337. Arguments:
  338. None
  339. Return Value:
  340. TRUE if successful, else FALSE
  341. --*/
  342. {
  343. return TRUE;
  344. }