home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / ISAPIEXT.PAK / SIMPLEEX.CPP < prev   
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.3 KB  |  103 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1997 by Borland International, All Rights Reserved
  4. // written by Michael Sawczyn
  5. //----------------------------------------------------------------------------
  6. #include "IsapiExt.h"
  7. #include <classlib\time.h>
  8.  
  9. class TSimpleExtension : public TIsapiExtension
  10. {
  11. protected:
  12. public:
  13.    TSimpleExtension(const char* modulename = "Simple Extension");
  14.    virtual DWORD Run();
  15. };
  16.  
  17. TSimpleExtension::TSimpleExtension(const char* modulename)
  18.    : TIsapiExtension(modulename)
  19. {
  20.  
  21. }
  22.  
  23. DWORD TSimpleExtension::Run()
  24. {
  25.    // this extension creates two possible pages: one is a textual output
  26.    // that creates some verbage and displays a simple form. The second,
  27.    // called from the form that the first creates, demonstrates how form
  28.    // variables can be trapped.
  29.  
  30.    if (!GetVariable("MyForm").length())
  31.    {
  32.       // this wasn't called from our form, so output the first page
  33.       browser << HEAD(TITLE("Simple Extension Test Page"));
  34.       browser << BEGINBODY;
  35.       browser << H1("Simple Test Page");
  36.  
  37.       // no problem mixing embedded html with macros
  38.       string p;
  39.       browser << "<PRE>Your current information:<BR>";
  40.       p=GetVariable("AUTH_TYPE");
  41.       browser << "Authentication type: " << (p.length()?p.c_str():"Unavailable") << "<BR>";
  42.       p=GetVariable("REMOTE_ADDR");
  43.       browser << "IP Address         : " << (p.length()?p.c_str():"Unavailable") << "<BR>";
  44.       p=GetVariable("REMOTE_HOST");
  45.       browser << "Your Host Name     : " << (p.length()?p.c_str():"Unavailable") << "</PRE>";
  46.  
  47.       browser << P("Here's a form for you to fill in:");
  48.  
  49.       browser << "<form method=\"GET\">";
  50.       browser << "<input type=\"hidden\" name=\"MyForm\" value=\"1\">";
  51.       browser << P("My name: <input type=\"text\" size=\"45\" name=\"NameField\">");
  52.       browser << P("My favorite color: <input type=\"text\" size=\"20\" name=\"ColorField\">");
  53.       browser << P("<input type=\"checkbox\" name=\"GoToBorland\" value=\"ON\">Forget all this ... just take me to Borland's website");
  54.       browser << P("<input type=\"submit\" name=\"SubmitButton\" value=\"Submit this information\">");
  55.       browser << "</form>";
  56.       browser << ENDBODY;
  57.    }
  58.    else
  59.    {
  60.       char NameField[46];
  61.       char ColorField[21];
  62.       char GoToBorland[3];
  63.  
  64.       GetVariable("NameField",NameField,46);
  65.       GetVariable("ColorField",ColorField,21);
  66.       GetVariable("GoToBorland",GoToBorland,3);
  67.  
  68.       if (!strcmp(GoToBorland,"ON"))
  69.          RedirectToURL("http://www.borland.com");
  70.       else
  71.       {
  72.          browser << HEAD(TITLE("Form Results"));
  73.          browser << BEGINBODY;
  74.          browser << H2("Hello " << NameField << "!");
  75.          browser << P("The current time at the server is " << TTime().AsString());
  76.          browser << P("I see your favorite color is " << ColorField);
  77.          browser << ENDBODY;
  78.       }
  79.    }
  80.  
  81.    return Success;
  82. }
  83.  
  84. BOOL WINAPI __export DllEntryPoint( HINSTANCE, DWORD fdwReason, LPVOID )
  85. {
  86.    static TSimpleExtension* module = NULL;
  87.  
  88.    switch (fdwReason)
  89.    {
  90.       case DLL_PROCESS_ATTACH:
  91.          module = new TSimpleExtension;
  92.          break;
  93.  
  94.       case DLL_PROCESS_DETACH:
  95.          delete module;
  96.          break;
  97.    }
  98.  
  99.    return TRUE;
  100. }
  101.  
  102.  
  103.