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.

132 lines
3.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: bgihttp.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <windows.h>
  11. #include <tchar.h>
  12. #include <assert.h>
  13. #include <stdio.h>
  14. #include "httpext.h"
  15. #include "gttran.h"
  16. typedef struct _GPT {
  17. HINSTANCE hLib;
  18. PFNGTRecSend PfnRecSend;
  19. PFNGTFree PfnFree;
  20. } GPT;
  21. static GPT gpt;
  22. BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *pVer )
  23. {
  24. pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR,
  25. HSE_VERSION_MAJOR );
  26. lstrcpyn( pVer->lpszExtensionDesc,
  27. "This is a sample Web Server Application",
  28. HSE_MAX_EXT_DLL_NAME_LEN );
  29. return TRUE;
  30. }
  31. DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB) {
  32. DWORD cb = 0;
  33. BYTE * pb = NULL;
  34. TCHAR tszBuff[1024];
  35. DWORD cbBuff;
  36. DWORD dwEncodingType;
  37. TCHAR * tszContentType;
  38. // assume an error
  39. pECB->dwHttpStatusCode = 500;
  40. if(!_tcscmp(TEXT("application/x-octet-stream-asn"), pECB->lpszContentType))
  41. dwEncodingType = ASN_ENCODING;
  42. else if(!_tcscmp(TEXT("application/x-octet-stream-idl"), pECB->lpszContentType))
  43. dwEncodingType = IDL_ENCODING;
  44. else if(!_tcscmp(TEXT("application/x-octet-stream-tlv"), pECB->lpszContentType))
  45. dwEncodingType = TLV_ENCODING;
  46. else if(!_tcscmp(TEXT("application/octet-stream"), pECB->lpszContentType))
  47. dwEncodingType = OCTET_ENCODING;
  48. else
  49. dwEncodingType = ASCII_ENCODING;
  50. if(dwEncodingType == ASCII_ENCODING)
  51. tszContentType = TEXT("text/html");
  52. else
  53. tszContentType = pECB->lpszContentType;
  54. // only do it if we can.
  55. if(gpt.PfnRecSend == NULL || gpt.PfnFree == NULL)
  56. return(HSE_STATUS_ERROR);
  57. // call the user dlls with the data
  58. if( gpt.PfnRecSend(dwEncodingType, pECB->cbTotalBytes, pECB->lpbData, &cb, &pb) != ERROR_SUCCESS)
  59. return(HSE_STATUS_ERROR);
  60. // we are ok now
  61. pECB->dwHttpStatusCode = 200;
  62. // write any return data
  63. if( cb > 0 ) {
  64. assert( pb != NULL);
  65. // write headers
  66. // we assume the only type of content type we support
  67. _stprintf(tszBuff, TEXT("Content-Length: %d\r\nContent-Type: %s\r\n\r\n"), cb, tszContentType);
  68. cbBuff = _tcslen(tszBuff);
  69. pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, &cbBuff, (LPDWORD) tszBuff);
  70. // write users data
  71. pECB->WriteClient(pECB->ConnID, pb, &cb, 0);
  72. // free the users data
  73. gpt.PfnFree(pb);
  74. }
  75. // just write out the headers if no data returned
  76. else {
  77. // write headers
  78. pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, NULL, NULL);
  79. }
  80. return(HSE_STATUS_SUCCESS);
  81. }
  82. // SHOULD ONLY BE CALLED DURING PROCESS ATTACH
  83. DWORD __stdcall GTInitSrv(TCHAR * tszLibrary) {
  84. // this is only called on process attach
  85. // there is only one process attach
  86. assert(gpt.hLib == NULL);
  87. memset(&gpt, 0, sizeof(gpt));
  88. if( (gpt.hLib = LoadLibrary(tszLibrary)) == NULL )
  89. return(ERROR_DLL_NOT_FOUND);
  90. gpt.PfnRecSend = (PFNGTRecSend) GetProcAddress(gpt.hLib, TEXT("GTRecSend"));
  91. gpt.PfnFree = (PFNGTFree) GetProcAddress(gpt.hLib, TEXT("GTFree"));
  92. if( gpt.PfnRecSend == NULL || gpt.PfnFree == NULL ) {
  93. FreeLibrary(gpt.hLib);
  94. memset(&gpt, 0, sizeof(GPT));
  95. return(ERROR_PROC_NOT_FOUND);
  96. }
  97. return(ERROR_SUCCESS);
  98. }
  99. // SHOULD ONLY BE CALLED DURING PROCESS DETACH
  100. DWORD __stdcall GTUnInitSrv(void) {
  101. if(gpt.hLib != NULL)
  102. FreeLibrary(gpt.hLib);
  103. return(ERROR_SUCCESS);
  104. }