apt  @VERSION@
sourcelist.h
00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: sourcelist.h,v 1.12.2.1 2003/12/24 23:09:17 mdz Exp $
00004 /* ######################################################################
00005 
00006    SourceList - Manage a list of sources
00007    
00008    The Source List class provides access to a list of sources. It 
00009    can read them from a file and generate a list of all the distinct
00010    sources.
00011    
00012    All sources have a type associated with them that defines the layout
00013    of the archive. The exact format of the file is documented in
00014    files.sgml.
00015 
00016    The types are mapped through a list of type definitions which handle
00017    the actual construction of the back end type. After loading a source 
00018    list all you have is a list of package index files that have the ability
00019    to be Acquired.
00020    
00021    The vendor machanism is similar, except the vendor types are hard 
00022    wired. Before loading the source list the vendor list is loaded.
00023    This doesn't load key data, just the checks to perform.
00024    
00025    ##################################################################### */
00026                                                                         /*}}}*/
00027 #ifndef PKGLIB_SOURCELIST_H
00028 #define PKGLIB_SOURCELIST_H
00029 
00030 #include <string>
00031 #include <vector>
00032 #include <map>
00033 #include <apt-pkg/pkgcache.h>
00034 
00035 #ifndef APT_8_CLEANER_HEADERS
00036 #include <apt-pkg/metaindex.h>
00037 using std::string;
00038 using std::vector;
00039 #endif
00040 
00041 class pkgAcquire;
00042 class pkgIndexFile;
00043 class metaIndex;
00044 
00045 class pkgSourceList
00046 {
00047    public:
00048    
00049    // List of supported source list types
00050    class Type
00051    {
00052       public:
00053       
00054       // Global list of Items supported
00055       static Type **GlobalList;
00056       static unsigned long GlobalListLen;
00057       static Type *GetType(const char *Type);
00058 
00059       const char *Name;
00060       const char *Label;
00061 
00062       bool FixupURI(std::string &URI) const;
00063       virtual bool ParseLine(std::vector<metaIndex *> &List,
00064                              const char *Buffer,
00065                              unsigned long const &CurLine,std::string const &File) const;
00066       virtual bool CreateItem(std::vector<metaIndex *> &List,std::string const &URI,
00067                               std::string const &Dist,std::string const &Section,
00068                               std::map<std::string, std::string> const &Options) const = 0;
00069       Type();
00070       virtual ~Type() {};
00071    };
00072    
00073    typedef std::vector<metaIndex *>::const_iterator const_iterator;
00074    
00075    protected:
00076 
00077    std::vector<metaIndex *> SrcList;
00078    
00079    public:
00080 
00081    bool ReadMainList();
00082    bool Read(std::string File);
00083 
00084    // CNC:2003-03-03
00085    void Reset();
00086    bool ReadAppend(std::string File);
00087    bool ReadSourceDir(std::string Dir);
00088    
00089    // List accessors
00090    inline const_iterator begin() const {return SrcList.begin();};
00091    inline const_iterator end() const {return SrcList.end();};
00092    inline unsigned int size() const {return SrcList.size();};
00093    inline bool empty() const {return SrcList.empty();};
00094 
00095    bool FindIndex(pkgCache::PkgFileIterator File,
00096                   pkgIndexFile *&Found) const;
00097    bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
00098    
00099    // query last-modified time
00100    time_t GetLastModifiedTime();
00101 
00102    pkgSourceList();
00103    pkgSourceList(std::string File);
00104    ~pkgSourceList();      
00105 };
00106 
00107 #endif