File : admin_says_hello.adb


------------------------------------------------------------------------------
--
--  procedure Admin_Says_Hello (body)
--
--  A simple webserver, which asks the user running the server to type in the
--  results to the individual queries.
--
--  The program is a slight extension of the Ada Web Server "Hello World" demo
--  program by Dmitriy Anisimov and Pascal Obry.
--
--  The program is distributed under the GNU General Public License.
--
------------------------------------------------------------------------------
--  Update information:
--
--  2001.10.15 (Jacob Sparre Andersen and Christian I. Mikkelsen)
--    Written based on the Ada Web Server "Hello World" demo program by
--      Dmitriy Anisimov and Pascal Obry.
--
--  2001.10.16 (Jacob Sparre Andersen)
--    Changed the port number to 4321.
--    Added a beep, when a request comes in.
--
--  2001.10.18 (Jacob Sparre Andersen)
--    Using a selective abort statement to guarantee an answer within
--      30 seconds.
--
--  2002.03.28 (Jacob Sparre Andersen)
--    Updated to use the AWS 1.1 specifications.
--
--  (Insert additional update information above this line.)
------------------------------------------------------------------------------
--  Standard packages:

with Ada.Characters.Latin_1;
with Ada.Text_IO;

------------------------------------------------------------------------------
--  Ada Web Server packages:

with AWS.Response;
with AWS.Server;
with AWS.Status;

------------------------------------------------------------------------------
--  Other packages:

with UStrings;

------------------------------------------------------------------------------

procedure Admin_Says_Hello is

   WS : AWS.Server.HTTP;

   function HW_CB (Request : in AWS.Status.Data)
     return AWS.Response.Data is

      use Ada.Text_IO;
      use AWS.Status;
      use UStrings;

      Greeting : UString;

   begin
      select
         delay 30.0;
         Greeting := U ("Admin seems to be sleeping. The " &
                        """Admin_Says_Hello"" HTTP server sends apologies " &
                        "on behalf of him/her.");
         Put_Line (Item => Greeting);
      then abort
         Put (Item => Ada.Characters.Latin_1.BEL & "You have a guest from (" &
                      Peername (Request) & "): ");
         Get_Line (Greeting);
      end select;

      return AWS.Response.Build
        ("text/html; charset=ISO-8859-1",
         "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">" &
         "<html><head><title>Admin says hello</title></head>" &
         "<body><p>" & S (Greeting) & "</p></body></html>");
   end HW_CB;

begin
   Ada.Text_IO.Put_Line ("AWS " & AWS.Version & " running on port 4321.");
   Ada.Text_IO.Put_Line ("Kill me when you want me to stop...");

   AWS.Server.Start (Web_Server     => WS,
                     Name           => "Admin says hello",
                     Port           => 4321,
--                   Session        => False,
                     Max_Connection => 1,
                     Callback       => HW_CB'Unrestricted_Access);

Wait_Forever:
   loop
      delay 3600.0;
   end loop Wait_Forever;

   AWS.Server.Shutdown (Web_Server => WS);
end Admin_Says_Hello;