File : adagio-searches-hit_family.ads


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

--                         ADAGIO - ADALID - AENEA.                         --

--                                                                          --

--                            Copyright (C) 2003                            --

--                                 A. Mosteo.                               --

--                                                                          --

--  Authors: A. Mosteo. (adagio@mosteo.com)                                 --

--                                                                          --

--  If you have any questions in regard to this software, please address    --

--  them to the above email.                                                --

--                                                                          --

--  This program is free software; you can redistribute it and/or modify    --

--  it under the terms of the GNU General Public License as published by    --

--  the Free Software Foundation; either version 2 of the License, or (at   --

--  your option) any later version.                                         --

--                                                                          --

--  This program 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       --

--  along with this library; if not, write to the Free Software Foundation, --

--  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.          --

--                                                                          --

--  You are not allowed to use any part of this code to develop a program   --

--  whose output would be used to harass or prosecute other users of the    --

--  networks Adagio connects with. All data collected with Adagio or a tool --

--  containing Adagio code about other network users must remain            --

--  confidential and cannot be made public by any mean, nor be used to      --

--  harass or legally prosecute these users.                                --

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

--  $Id: adagio-upload.ads,v 1.4 2004/01/21 21:05:51 Jano Exp $


--  Root package for all search packages


with Adagio.Hash_Dictionary;
with Adagio.Searches.Hit;

with Agpl.Http.Server.Sort_Handler;
use  Agpl.Http.Server.Sort_Handler;

with Charles.Hash_String;
with Charles.Maps.Hashed.Strings.Unbounded;

with Ada.Finalization;
use  Ada;

private package Adagio.Searches.Hit_Family is

   No_Such_Hash : exception; 

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

   -- Object                                                             --

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

   type Object is limited private;
   type Object_Access is access all Object;
   type Object_Access_Array is array (Positive range <>) of Object_Access;

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

   -- Add_Hit                                                            --

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

   -- Adds a hit. It must be compatible

   procedure Add_Hit (This : in out Object; H : in Hit.Object'Class);

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

   -- Contains                                                           --

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

   function Contains (This : in Object; H : in Hit.Object'Class) return Boolean;

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

   -- Create                                                             --

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

   -- A seed hit is needed

   procedure Create (This : out object; From : in Hit.Object'Class);  

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

   -- Equal                                                              --

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

   function Equal (L, R : in Object) return Boolean;

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

   -- Free                                                               --

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

   procedure Free (This : in out Object_Access);

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

   -- Get_Id                                                             --

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

   -- Get an unique id for the family (meaningless, for indexing)

   function Get_Id (This : in Object) return String;

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

   -- Get_Link                                                           --

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

   -- Will provide a link for the hit

   -- Will try to get a Sha1 magnet and if not, a ed2k link

   -- May raise No_Such_Hash if no hash available

   function Get_Link (This : in Object) return String;

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

   -- Get_Magnet                                                         --

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

   -- Will try to get a magnet link for sha1 hashes

   -- Raise No_Such_Hash if unable to obtain it

   function Get_Magnet (This : in Object) return String;

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

   -- Has_New_Hits                                                       --

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

   function Has_New_Hits (This : in Object) return Boolean;

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

   -- Is_Compatible                                                      --

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

   -- Says if a hit is compatible with this family

   function Is_Compatible (This : in Object; H : in Hit.Object'Class) return Boolean;

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

   -- Num_Firewalled_Hits                                                --

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

   function Num_Firewalled_Hits (This : in Object) return Natural;

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

   -- Num_Hits                                                           --

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

   function Num_Hits (This : in Object) return Natural;

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

   -- Num_New_Hits                                                       --

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

   function Num_New_Hits (This : in Object) return Natural;
   
   ------------------------------------------------------------------------

   -- Set_Expanded                                                       --

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

   procedure Set_Expanded (This : in out Object; Expanded : in Boolean := true);

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

   -- Http_Report                                                        --

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

   procedure Http_Report (This : in out Object; Data : in out Data_Set);

private

   type Family_Id is mod 2 ** 32;

   -- Index is the unique id of the hit

   package Hit_Map is new Charles.Maps.Hashed.Strings.Unbounded (
      Searches.Hit.Object_Access, Charles.Hash_String, "=", Searches.Hit.Equal);

   type Object is new Finalization.Limited_Controlled with record
      Id       : Family_Id;  -- Unique ID

      Name     : Ustring;  -- The most used name between all hits belonging to this family.

      Size     : File_Size; -- Most seen size (should be only one if no buggy clients!)

      Hashes   : Hash_Dictionary.Object;
      Hits     : Hit_Map.Container_Type;
      Expanded : Boolean := false; -- Just for the GUI

   end record;

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

   -- Finalize                                                           --

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

   procedure Finalize (This : in out Object);

end Adagio.Searches.Hit_Family;