------------------------------------------------------------------------------ -- Ada Web Server -- -- -- -- Copyright (C) 2008-2012, AdaCore -- -- -- -- This is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 3, or (at your option) any -- -- later version. This software is distributed in the hope that it will -- -- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -- -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public License -- -- distributed with this software; see file COPYING3. If not, go -- -- to http://www.gnu.org/licenses for a complete copy of the license. -- ------------------------------------------------------------------------------ with Ada.Command_Line; with Ada.Exceptions; with Ada.Tags; with Ada.Text_IO; with Ada.Strings.Fixed; with Ada.Unchecked_Deallocation; with AWS.Containers; with AWS.Jabber.Client; with AWS.Net.Acceptors; with AWS.Net.Buffered; with AWS.Net.SSL; with AWS.Net.Std; with AWS.Utils; procedure Test_Jabber is use type Ada.Tags.Tag; use Ada; use AWS; use AWS.Net; use Ada.Exceptions; use AWS.Jabber.Client; package Acceptors is new AWS.Net.Acceptors (Utils.Null_Record, (others => <>)); Verbose : constant Boolean := False; Acceptor : Acceptors.Acceptor_Type; task type Server_Task is entry Started; entry Can_Stop; entry Shutdown; entry Stopped; end Server_Task; ----------------- -- Server_Task -- ----------------- task body Server_Task is use AWS.Containers; Sock : Socket_Access; First : Boolean := True; procedure Buffered_Put_Line (Socket : Socket_Type'Class; Item : String); -- Print Text message and then call Buffered.Put_Line ----------------------- -- Buffered_Put_Line -- ----------------------- procedure Buffered_Put_Line (Socket : Socket_Type'Class; Item : String) is begin if Verbose then Text_IO.New_Line; Text_IO.Put_Line ("Server :: " & Item); end if; Buffered.Put_Line (Socket, Item); end Buffered_Put_Line; begin Acceptors.Listen (Acceptor, "", 0, 11); accept Started; Acceptors.Get (Acceptor, Sock); Set_Timeout (Sock.all, 4.0); -- Client initialize the connection declare Got_Message : constant String := Buffered.Get_Line (Sock.all); begin if Verbose then Text_IO.New_Line; Text_IO.Put_Line ("Client :: [" & Got_Message & "]"); end if; end; -- Return new stream.id Buffered_Put_Line (Sock.all, ""); Buffered.Flush (Sock.all); -- Advertize mechanisms Buffered_Put_Line (Sock.all, "" & "" & "DIGEST-MD5PLAIN" & "" & "" & ""); Buffered.Flush (Sock.all); loop declare Got_Message : constant String := Buffered.Get_Line (Sock.all); begin if Verbose then Text_IO.New_Line; Text_IO.Put_Line ("############# Client :: [" & Got_Message & "]"); end if; if Strings.Fixed.Index (Got_Message, "PLAIN") /= 0 then -- Client authentication (in PLAIN mode) -- Return success Buffered_Put_Line (Sock.all, ""); Buffered.Flush (Sock.all); elsif Strings.Fixed.Index (Got_Message, "" & "" & "" & "" & ""); Buffered.Flush (Sock.all); elsif Strings.Fixed.Index (Got_Message, "" & "" & "user@192.168.1.4/Resource"); Buffered.Flush (Sock.all); elsif Strings.Fixed.Index (Got_Message, "" & ""); Buffered.Flush (Sock.all); elsif Strings.Fixed.Index (Got_Message, " Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E)); Jabber_Server.Shutdown; Jabber_Server.Stopped; end Test_Jabber;