home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 October / PCWorld_2000-10_cd1.bin / Komunik / sambar / _setup.1 / testisa.c < prev    next >
C/C++ Source or Header  |  2000-06-26  |  3KB  |  149 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. #ifdef    WIN32
  19. #include <windows.h>
  20. #else
  21. #define    MAX_PATH    1024
  22. #define TRUE        1
  23. #define lstrcpyn    strncpy
  24. #define lstrlen        strlen
  25. #define stricmp        strcasecmp
  26. #define wsprintf    sprintf
  27. #endif    /* WIN32 */
  28.  
  29. #include <httpext.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32. #include <stdarg.h>
  33. #include <time.h>
  34.  
  35.  
  36. /*
  37. ** Globals
  38. */
  39. #define    NO_DATA_FOUND        "<P>No Data Provided."
  40.  
  41. /*
  42. ** DLL Entry point.
  43. */
  44. #ifdef    WIN32
  45. BOOL APIENTRY
  46. DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  47. {
  48.     switch(ul_reason_for_call) 
  49.     {
  50.     case DLL_PROCESS_ATTACH: 
  51.         break;
  52.     case DLL_PROCESS_DETACH:
  53.         break;
  54.     default:
  55.         break;
  56.     }
  57.  
  58.     return TRUE;
  59. }
  60.  
  61. #endif    /* WIN32 */
  62.  
  63. /*
  64. **    GetExtensionVersion
  65. **
  66. **    ISAPI/Win32 API method to ensure compatibility with the Server.
  67. */
  68. BOOL WINAPI
  69. GetExtensionVersion(HSE_VERSION_INFO *pVer)
  70. {
  71.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  72.  
  73.     lstrcpyn(pVer->lpszExtensionDesc, "Sambar Server ISAPI Test extension.",
  74.             HSE_MAX_EXT_DLL_NAME_LEN);
  75.  
  76.     return TRUE;
  77.  
  78. /*
  79. **    HttpExtensionProc
  80. **
  81. **     Called in response to the client request.
  82. */
  83. DWORD WINAPI
  84. HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
  85. {
  86.     DWORD    buflen;
  87.     DWORD    datalen;
  88.     CHAR    buffer[8192];
  89.  
  90.     /* Prepare the response header                                        */
  91.     wsprintf(buffer,
  92.              "Content-Type: text/html\r\n"
  93.              "\r\n"
  94.              "<head><title>Sambar ISAPI TEST</title></head>\n"
  95.              "<body><h1>Sambar ISAPI TEST</h1>\n"
  96.              "<hr>\n");
  97.  
  98.     buflen = lstrlen(buffer);
  99.  
  100.     /* Get the GET/POST data                                            */
  101.     if (!stricmp(pECB->lpszMethod, "GET")) 
  102.     {
  103.         /* Append the QUERY_STRING data                                    */
  104.         datalen = lstrlen(pECB->lpszQueryString);
  105.         if (datalen > 8000)
  106.             datalen = 8000;
  107.         if (datalen > 0)
  108.         {
  109.             strncpy(&buffer[buflen], pECB->lpszQueryString, datalen);
  110.             buflen += datalen;
  111.         }
  112.     }
  113.     else     /* POST */
  114.     {
  115.         /* Note: cbTotalBytes = cbAvailable    in the Sambar Server        */ 
  116.         if(pECB->cbTotalBytes > 0) 
  117.         {
  118.             datalen = pECB->cbAvailable;
  119.             if (datalen > 8000)
  120.                 datalen = 8000;
  121.  
  122.             strncpy(&buffer[buflen], pECB->lpbData, datalen);
  123.             buflen += datalen;
  124.         }
  125.     }
  126.  
  127.     if (datalen == 0)
  128.     {
  129.         datalen = lstrlen(NO_DATA_FOUND);
  130.         strncpy(&buffer[buflen], NO_DATA_FOUND, datalen);
  131.         buflen += datalen;
  132.     }
  133.  
  134.     strncpy(&buffer[buflen], "</BODY></HTML>", 14);
  135.     buflen += 14;
  136.  
  137.     if (!pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER,
  138.         "200 OK", &buflen, (LPDWORD)buffer)) 
  139.     {
  140.         pECB->dwHttpStatusCode = 500;
  141.         return HSE_STATUS_ERROR;
  142.     }
  143.  
  144.     pECB->dwHttpStatusCode = 200;
  145.  
  146.     return HSE_STATUS_SUCCESS;
  147.