home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 September / PCWorld_2000-09_cd.bin / Komunik / sambar / _setup.1 / testisa.c < prev    next >
C/C++ Source or Header  |  1998-03-08  |  3KB  |  142 lines

  1. /*
  2. ** TESTISA
  3. **
  4. **      This is a simple ISAPI test DLL that takes the input and displays
  5. **        it to the user.
  6. **
  7. **        Confidential Property of Tod Sambar
  8. **        (c) Copyright Tod Sambar 1998
  9. **        All rights reserved.
  10. **
  11. **
  12. ** History:
  13. ** Chg#    Date    Description                                                Resp
  14. ** ----    -------    -------------------------------------------------------    ----
  15. **        5FEB98     Created                                                    sambar
  16. */
  17.  
  18. #include <windows.h>
  19. #include <httpext.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. #include <time.h>
  24.  
  25. /*
  26. ** Globals
  27. */
  28. #define    NO_DATA_FOUND        "<P>No Data Provided."
  29.  
  30. /*
  31. ** Use a critical section to protect global data.
  32. */
  33. CRITICAL_SECTION     gCS;
  34.  
  35. /*
  36. ** DLL Entry point.
  37. */
  38. BOOL APIENTRY
  39. DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  40. {
  41.     switch(ul_reason_for_call) 
  42.     {
  43.     case DLL_PROCESS_ATTACH: 
  44.         InitializeCriticalSection(&gCS);
  45.         break;
  46.     case DLL_PROCESS_DETACH:
  47.         DeleteCriticalSection(&gCS);
  48.         break;
  49.     default:
  50.         break;
  51.     }
  52.  
  53.     return TRUE;
  54. }
  55.  
  56. /*
  57. **    GetExtensionVersion
  58. **
  59. **    ISAPI/Win32 API method to ensure compatibility with the Server.
  60. */
  61. BOOL WINAPI
  62. GetExtensionVersion(HSE_VERSION_INFO *pVer)
  63. {
  64.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  65.  
  66.     lstrcpyn(pVer->lpszExtensionDesc, "Sambar Server ISAPI Test extension.",
  67.             HSE_MAX_EXT_DLL_NAME_LEN);
  68.  
  69.     return TRUE;
  70.  
  71. /*
  72. **    HttpExtensionProc
  73. **
  74. **     Called in response to the client request.
  75. */
  76. DWORD WINAPI
  77. HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
  78. {
  79.     DWORD    buflen;
  80.     DWORD    datalen;
  81.     CHAR    buffer[8192];
  82.  
  83.     /* Prepare the response header                                        */
  84.     wsprintf(buffer,
  85.              "Content-Type: text/html\r\n"
  86.              "\r\n"
  87.              "<head><title>Sambar ISAPI TEST</title></head>\n"
  88.              "<body><h1>Sambar ISAPI TEST</h1>\n"
  89.              "<hr>\n");
  90.  
  91.     buflen = lstrlen(buffer);
  92.  
  93.     /* Get the GET/POST data                                            */
  94.     if (!stricmp(pECB->lpszMethod, "GET")) 
  95.     {
  96.         /* Append the QUERY_STRING data                                    */
  97.         datalen = lstrlen(pECB->lpszQueryString);
  98.         if (datalen > 8000)
  99.             datalen = 8000;
  100.         if (datalen > 0)
  101.         {
  102.             strncpy(&buffer[buflen], pECB->lpszQueryString, datalen);
  103.             buflen += datalen;
  104.         }
  105.     }
  106.     else     /* POST */
  107.     {
  108.         /* Note: cbTotalBytes = cbAvailable    in the Sambar Server        */ 
  109.         if(pECB->cbTotalBytes > 0) 
  110.         {
  111.             datalen = pECB->cbAvailable;
  112.             if (datalen > 8000)
  113.                 datalen = 8000;
  114.  
  115.             strncpy(&buffer[buflen], pECB->lpbData, datalen);
  116.             buflen += datalen;
  117.         }
  118.     }
  119.  
  120.     if (datalen == 0)
  121.     {
  122.         datalen = lstrlen(NO_DATA_FOUND);
  123.         strncpy(&buffer[buflen], NO_DATA_FOUND, datalen);
  124.         buflen += datalen;
  125.     }
  126.  
  127.     strncpy(&buffer[buflen], "</BODY></HTML>", 14);
  128.     buflen += 14;
  129.  
  130.     if (!pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER,
  131.         "200 OK", &buflen, (LPDWORD)buffer)) 
  132.     {
  133.         pECB->dwHttpStatusCode = 500;
  134.         return HSE_STATUS_ERROR;
  135.     }
  136.  
  137.     pECB->dwHttpStatusCode = 200;
  138.  
  139.     return HSE_STATUS_SUCCESS;
  140.