apt-key del: Ignore case when checking if a keyid exists in a keyring.
[ntk/apt.git] / apt-pkg / acquire.h
index 1de6f5e..ef16d85 100644 (file)
@@ -30,7 +30,7 @@
    ##################################################################### */
                                                                        /*}}}*/
 
-/** \defgroup acquire Acquire system
+/** \defgroup acquire Acquire system                                   {{{
  *
  *  \brief The Acquire system is responsible for retrieving files from
  *  local or remote URIs and postprocessing them (for instance,
@@ -54,7 +54,7 @@
  *  once, but it is not clear what its behavior in this case is, and
  *  no subclass of pkgAcquire::Item seems to actually use this
  *  capability.
- */
+ */                                                                    /*}}}*/
 
 /** \addtogroup acquire
  *
 #ifndef PKGLIB_ACQUIRE_H
 #define PKGLIB_ACQUIRE_H
 
+#include <apt-pkg/macros.h>
+#include <apt-pkg/weakptr.h>
+
 #include <vector>
 #include <string>
 
-using std::vector;
-using std::string;
-
-
+#include <stddef.h>
 #include <sys/time.h>
+#include <sys/select.h>
+
+#ifndef APT_10_CLEANER_HEADERS
 #include <unistd.h>
+#endif
+
+#ifndef APT_8_CLEANER_HEADERS
+using std::vector;
+using std::string;
+#endif
 
 class pkgAcquireStatus;
 
-/** \brief The core download scheduler.
+/** \brief The core download scheduler.                                        {{{
  *
  *  This class represents an ongoing download.  It manages the lists
  *  of active and pending downloads and handles setting up and tearing
@@ -88,6 +97,12 @@ class pkgAcquireStatus;
  */
 class pkgAcquire
 {   
+   private:
+   /** \brief FD of the Lock file we acquire in Setup (if any) */
+   int LockFD;
+   /** \brief dpointer placeholder (for later in case we need it) */
+   void *d;
+
    public:
    
    class Item;
@@ -98,8 +113,8 @@ class pkgAcquire
    friend class Item;
    friend class Queue;
 
-   typedef vector<Item *>::iterator ItemIterator;
-   typedef vector<Item *>::const_iterator ItemCIterator;
+   typedef std::vector<Item *>::iterator ItemIterator;
+   typedef std::vector<Item *>::const_iterator ItemCIterator;
 
    protected:
    
@@ -108,7 +123,7 @@ class pkgAcquire
     *  This is built monotonically as items are created and only
     *  emptied when the download shuts down.
     */
-   vector<Item *> Items;
+   std::vector<Item *> Items;
    
    /** \brief The head of the list of active queues.
     *
@@ -139,12 +154,7 @@ class pkgAcquire
    /** \brief The progress indicator for this download. */
    pkgAcquireStatus *Log;
 
-   /** \brief The total size of the files which are to be fetched.
-    *
-    *  This is not necessarily the total number of bytes to download
-    *  when, e.g., download resumption and list updates via patches
-    *  are taken into account.
-    */
+   /** \brief The number of files which are to be fetched. */
    unsigned long ToFetch;
 
    // Configurable parameters for the scheduler
@@ -161,7 +171,7 @@ class pkgAcquire
      QueueAccess} QueueMode;
 
    /** \brief If \b true, debugging information will be dumped to std::clog. */
-   bool Debug;
+   bool const Debug;
    /** \brief If \b true, a download is currently in progress. */
    bool Running;
 
@@ -198,7 +208,7 @@ class pkgAcquire
     *  \return the string-name of the queue in which a fetch request
     *  for the given URI should be placed.
     */
-   string QueueName(string URI,MethodConfig const *&Config);
+   std::string QueueName(std::string URI,MethodConfig const *&Config);
 
    /** \brief Build up the set of file descriptors upon which select() should
     *  block.
@@ -244,7 +254,7 @@ class pkgAcquire
     *
     *  \return the method whose name is Access, or \b NULL if no such method exists.
     */
-   MethodConfig *GetConfig(string Access);
+   MethodConfig *GetConfig(std::string Access);
 
    /** \brief Provides information on how a download terminated. */
    enum RunResult {
@@ -277,18 +287,18 @@ class pkgAcquire
     */
    void Shutdown();
    
-   /** \brief Get the first #Worker object.
+   /** \brief Get the first Worker object.
     *
     *  \return the first active worker in this download process.
     */
    inline Worker *WorkersBegin() {return Workers;};
 
-   /** \brief Advance to the next #Worker object.
+   /** \brief Advance to the next Worker object.
     *
     *  \return the worker immediately following I, or \b NULL if none
     *  exists.
     */
-   Worker *WorkerStep(Worker *I);
+   Worker *WorkerStep(Worker *I) APT_PURE;
 
    /** \brief Get the head of the list of items. */
    inline ItemIterator ItemsBegin() {return Items.begin();};
@@ -315,32 +325,41 @@ class pkgAcquire
     *
     *  \return \b true if the directory exists and is readable.
     */
-   bool Clean(string Dir);
+   bool Clean(std::string Dir);
 
    /** \return the total size in bytes of all the items included in
     *  this download.
     */
-   double TotalNeeded();
+   unsigned long long TotalNeeded();
 
    /** \return the size in bytes of all non-local items included in
     *  this download.
     */
-   double FetchNeeded();
+   unsigned long long FetchNeeded();
 
    /** \return the amount of data to be fetched that is already
     *  present on the filesystem.
     */
-   double PartialPresent();
+   unsigned long long PartialPresent();
 
-   /** \brief Construct a new pkgAcquire.
+   /** \brief Delayed constructor
     *
-    *  \param Log The progress indicator associated with this
-    *  download, or \b NULL for none.  This object is not owned by the
+    *  \param Progress indicator associated with this download or
+    *  \b NULL for none.  This object is not owned by the
     *  download process and will not be deleted when the pkgAcquire
     *  object is destroyed.  Naturally, it should live for at least as
     *  long as the pkgAcquire object does.
+    *  \param Lock defines a lock file that should be acquired to ensure
+    *  only one Acquire class is in action at the time or an empty string
+    *  if no lock file should be used.
     */
-   pkgAcquire(pkgAcquireStatus *Log = 0);
+   bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = "");
+
+   void SetLog(pkgAcquireStatus *Progress) { Log = Progress; }
+
+   /** \brief Construct a new pkgAcquire. */
+   pkgAcquire(pkgAcquireStatus *Log) APT_DEPRECATED;
+   pkgAcquire();
 
    /** \brief Destroy this pkgAcquire object.
     *
@@ -348,6 +367,7 @@ class pkgAcquire
     *  this download.
     */
    virtual ~pkgAcquire();
+
 };
 
 /** \brief Represents a single download source from which an item
@@ -355,19 +375,19 @@ class pkgAcquire
  *
  *  An item may have several assocated ItemDescs over its lifetime.
  */
-struct pkgAcquire::ItemDesc
+struct pkgAcquire::ItemDesc : public WeakPointable
 {
    /** \brief The URI from which to download this item. */
-   string URI;
+   std::string URI;
    /** brief A description of this item. */
-   string Description;
+   std::string Description;
    /** brief A shorter description of this item. */
-   string ShortDesc;
+   std::string ShortDesc;
    /** brief The underlying item which is to be downloaded. */
    Item *Owner;
 };
-
-/** \brief A single download queue in a pkgAcquire object.
+                                                                       /*}}}*/
+/** \brief A single download queue in a pkgAcquire object.             {{{
  *
  *  \todo Why so many protected values?
  */
@@ -377,6 +397,9 @@ class pkgAcquire::Queue
    friend class pkgAcquire::UriIterator;
    friend class pkgAcquire::Worker;
 
+   /** \brief dpointer placeholder (for later in case we need it) */
+   void *d;
+
    /** \brief The next queue in the pkgAcquire object's list of queues. */
    Queue *Next;
    
@@ -403,7 +426,7 @@ class pkgAcquire::Queue
    };
    
    /** \brief The name of this queue. */
-   string Name;
+   std::string Name;
 
    /** \brief The head of the list of items contained in this queue.
     *
@@ -458,13 +481,13 @@ class pkgAcquire::Queue
     *  \return the first item in the queue whose URI is #URI and that
     *  is being downloaded by #Owner.
     */
-   QItem *FindItem(string URI,pkgAcquire::Worker *Owner);
+   QItem *FindItem(std::string URI,pkgAcquire::Worker *Owner) APT_PURE;
 
    /** Presumably this should start downloading an item?
     *
     *  \todo Unimplemented.  Implement it or remove?
     */
-   bool ItemStart(QItem *Itm,unsigned long Size);
+   bool ItemStart(QItem *Itm,unsigned long long Size);
 
    /** \brief Remove the given item from this queue and set its state
     *  to pkgAcquire::Item::StatDone.
@@ -521,17 +544,20 @@ class pkgAcquire::Queue
     *  \param Name The name of the new queue.
     *  \param Owner The download process that owns the new queue.
     */
-   Queue(string Name,pkgAcquire *Owner);
+   Queue(std::string Name,pkgAcquire *Owner);
 
    /** Shut down all the worker processes associated with this queue
     *  and empty the queue.
     */
-   ~Queue();
+   virtual ~Queue();
 };
-
-/** \brief Iterates over all the URIs being fetched by a pkgAcquire object. */
+                                                                       /*}}}*/
+/** \brief Iterates over all the URIs being fetched by a pkgAcquire object.    {{{*/
 class pkgAcquire::UriIterator
 {
+   /** \brief dpointer placeholder (for later in case we need it) */
+   void *d;
+
    /** The next queue to iterate over. */
    pkgAcquire::Queue *CurQ;
    /** The item that we currently point at. */
@@ -539,7 +565,7 @@ class pkgAcquire::UriIterator
    
    public:
    
-   inline void operator ++() {operator ++();};
+   inline void operator ++() {operator ++(0);};
 
    void operator ++(int)
    {
@@ -567,11 +593,15 @@ class pkgAcquire::UriIterator
         CurQ = CurQ->Next;
       }
    }   
+   virtual ~UriIterator() {};
 };
-
-/** \brief Information about the properties of a single acquire method. */
+                                                                       /*}}}*/
+/** \brief Information about the properties of a single acquire method.        {{{*/
 struct pkgAcquire::MethodConfig
 {
+   /** \brief dpointer placeholder (for later in case we need it) */
+   void *d;
+   
    /** \brief The next link on the acquire method list.
     *
     *  \todo Why not an STL container?
@@ -579,10 +609,10 @@ struct pkgAcquire::MethodConfig
    MethodConfig *Next;
    
    /** \brief The name of this acquire method (e.g., http). */
-   string Access;
+   std::string Access;
 
    /** \brief The implementation version of this acquire method. */
-   string Version;
+   std::string Version;
 
    /** \brief If \b true, only one download queue should be created for this
     *  method.
@@ -620,16 +650,20 @@ struct pkgAcquire::MethodConfig
     *  appropriate.
     */
    MethodConfig();
-};
 
-/** \brief A monitor object for downloads controlled by the pkgAcquire class.
+   /* \brief Destructor, empty currently */
+   virtual ~MethodConfig() {};
+};
+                                                                       /*}}}*/
+/** \brief A monitor object for downloads controlled by the pkgAcquire class.  {{{
  *
  *  \todo Why protected members?
- *
- *  \todo Should the double members be uint64_t?
  */
 class pkgAcquireStatus
 {
+   /** \brief dpointer placeholder (for later in case we need it) */
+   void *d;
+
    protected:
    
    /** \brief The last time at which this monitor object was updated. */
@@ -641,34 +675,34 @@ class pkgAcquireStatus
    /** \brief The number of bytes fetched as of the previous call to
     *  pkgAcquireStatus::Pulse, including local items.
     */
-   double LastBytes;
+   unsigned long long LastBytes;
 
    /** \brief The current rate of download as of the most recent call
     *  to pkgAcquireStatus::Pulse, in bytes per second.
     */
-   double CurrentCPS;
+   unsigned long long CurrentCPS;
 
    /** \brief The number of bytes fetched as of the most recent call
     *  to pkgAcquireStatus::Pulse, including local items.
     */
-   double CurrentBytes;
+   unsigned long long CurrentBytes;
 
    /** \brief The total number of bytes that need to be fetched.
     *
     *  \warning This member is inaccurate, as new items might be
     *  enqueued while the download is in progress!
     */
-   double TotalBytes;
+   unsigned long long TotalBytes;
 
    /** \brief The total number of bytes accounted for by items that
     *  were successfully fetched.
     */
-   double FetchedBytes;
+   unsigned long long FetchedBytes;
 
    /** \brief The amount of time that has elapsed since the download
     *   started.
     */
-   unsigned long ElapsedTime;
+   unsigned long long ElapsedTime;
 
    /** \brief The total number of items that need to be fetched.
     *
@@ -701,7 +735,7 @@ class pkgAcquireStatus
     *
     *  \param ResumePoint How much of the file was already fetched.
     */
-   virtual void Fetched(unsigned long Size,unsigned long ResumePoint);
+   virtual void Fetched(unsigned long long Size,unsigned long long ResumePoint);
    
    /** \brief Invoked when the user should be prompted to change the
     *         inserted removable media.
@@ -720,7 +754,7 @@ class pkgAcquireStatus
     *  \todo This is a horrible blocking monster; it should be CPSed
     *  with prejudice.
     */
-   virtual bool MediaChange(string Media,string Drive) = 0;
+   virtual bool MediaChange(std::string Media,std::string Drive) = 0;
    
    /** \brief Invoked when an item is confirmed to be up-to-date.
 
@@ -762,7 +796,7 @@ class pkgAcquireStatus
    pkgAcquireStatus();
    virtual ~pkgAcquireStatus() {};
 };
-
+                                                                       /*}}}*/
 /** @} */
 
 #endif