1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 Package Cache Generator - Generator for the cache structure.
7 This builds the cache structure from the abstract package list parser.
8 Each archive source has it's own list parser that is instantiated by
9 the caller to provide data for the generator.
11 Parts of the cache are created by this generator class while other
12 parts are created by the list parser. The list parser is responsible
13 for creating version, depends and provides structures, and some of
16 ##################################################################### */
18 #ifndef PKGLIB_PKGCACHEGEN_H
19 #define PKGLIB_PKGCACHEGEN_H
21 #include <apt-pkg/md5.h>
22 #include <apt-pkg/mmap.h>
23 #include <apt-pkg/pkgcache.h>
24 #include <apt-pkg/cacheiterators.h>
25 #include <apt-pkg/macros.h>
35 class pkgCacheListParser
;
37 class APT_HIDDEN pkgCacheGenerator
/*{{{*/
39 APT_HIDDEN map_stringitem_t
WriteStringInMap(std::string
const &String
) { return WriteStringInMap(String
.c_str()); };
40 APT_HIDDEN map_stringitem_t
WriteStringInMap(const char *String
);
41 APT_HIDDEN map_stringitem_t
WriteStringInMap(const char *String
, const unsigned long &Len
);
42 APT_HIDDEN map_pointer_t
AllocateInMap(const unsigned long &size
);
44 std::map
<std::string
,map_stringitem_t
> strMixed
;
45 std::map
<std::string
,map_stringitem_t
> strSections
;
46 std::map
<std::string
,map_stringitem_t
> strPkgNames
;
47 std::map
<std::string
,map_stringitem_t
> strVersions
;
49 friend class pkgCacheListParser
;
50 typedef pkgCacheListParser ListParser
;
54 template<typename Iter
> class Dynamic
{
56 static std::vector
<Iter
*> toReMap
;
57 explicit Dynamic(Iter
&I
) {
58 toReMap
.push_back(&I
);
72 std::string RlsFileName
;
73 pkgCache::ReleaseFile
*CurrentRlsFile
;
74 std::string PkgFileName
;
75 pkgCache::PackageFile
*CurrentFile
;
77 bool NewGroup(pkgCache::GrpIterator
&Grp
,const std::string
&Name
);
78 bool NewPackage(pkgCache::PkgIterator
&Pkg
,const std::string
&Name
, const std::string
&Arch
);
79 bool NewFileVer(pkgCache::VerIterator
&Ver
,ListParser
&List
);
80 bool NewFileDesc(pkgCache::DescIterator
&Desc
,ListParser
&List
);
81 bool NewDepends(pkgCache::PkgIterator
&Pkg
, pkgCache::VerIterator
&Ver
,
82 map_pointer_t
const Version
, uint8_t const Op
,
83 uint8_t const Type
, map_pointer_t
* &OldDepLast
);
84 map_pointer_t
NewVersion(pkgCache::VerIterator
&Ver
,const std::string
&VerStr
,map_pointer_t
const Next
) APT_DEPRECATED
85 { return NewVersion(Ver
, VerStr
, 0, 0, Next
); }
86 map_pointer_t
NewVersion(pkgCache::VerIterator
&Ver
,const std::string
&VerStr
,
87 map_pointer_t
const ParentPkg
, unsigned short const Hash
,
88 map_pointer_t
const Next
);
89 map_pointer_t
NewDescription(pkgCache::DescIterator
&Desc
,const std::string
&Lang
,const MD5SumValue
&md5sum
,map_stringitem_t
const idxmd5str
);
90 bool NewProvides(pkgCache::VerIterator
&Ver
, pkgCache::PkgIterator
&Pkg
,
91 map_stringitem_t
const ProvidesVersion
, uint8_t const Flags
);
95 enum StringType
{ MIXED
, PKGNAME
, VERSIONNUMBER
, SECTION
};
96 map_stringitem_t
StoreString(StringType
const type
, const char * S
, unsigned int const Size
);
97 inline map_stringitem_t
StoreString(enum StringType
const type
, const std::string
&S
) {return StoreString(type
, S
.c_str(),S
.length());};
99 void DropProgress() {Progress
= 0;};
100 bool SelectFile(const std::string
&File
,pkgIndexFile
const &Index
, std::string
const &Architecture
, std::string
const &Component
, unsigned long Flags
= 0);
101 bool SelectReleaseFile(const std::string
&File
, const std::string
&Site
, unsigned long Flags
= 0);
102 bool MergeList(ListParser
&List
,pkgCache::VerIterator
*Ver
= 0);
103 inline pkgCache
&GetCache() {return Cache
;};
104 inline pkgCache::PkgFileIterator
GetCurFile()
105 {return pkgCache::PkgFileIterator(Cache
,CurrentFile
);};
106 inline pkgCache::RlsFileIterator
GetCurRlsFile()
107 {return pkgCache::RlsFileIterator(Cache
,CurrentRlsFile
);};
109 APT_PUBLIC
static bool MakeStatusCache(pkgSourceList
&List
,OpProgress
*Progress
,
110 MMap
**OutMap
= 0,bool AllowMem
= false);
111 APT_PUBLIC
static bool MakeOnlyStatusCache(OpProgress
*Progress
,DynamicMMap
**OutMap
);
113 void ReMap(void const * const oldMap
, void const * const newMap
);
115 pkgCacheGenerator(DynamicMMap
*Map
,OpProgress
*Progress
);
116 virtual ~pkgCacheGenerator();
120 APT_HIDDEN
bool MergeListGroup(ListParser
&List
, std::string
const &GrpName
);
121 APT_HIDDEN
bool MergeListPackage(ListParser
&List
, pkgCache::PkgIterator
&Pkg
);
122 APT_HIDDEN
bool MergeListVersion(ListParser
&List
, pkgCache::PkgIterator
&Pkg
,
123 std::string
const &Version
, pkgCache::VerIterator
* &OutVer
);
125 APT_HIDDEN
bool AddImplicitDepends(pkgCache::GrpIterator
&G
, pkgCache::PkgIterator
&P
,
126 pkgCache::VerIterator
&V
);
127 APT_HIDDEN
bool AddImplicitDepends(pkgCache::VerIterator
&V
, pkgCache::PkgIterator
&D
);
129 APT_HIDDEN
bool AddNewDescription(ListParser
&List
, pkgCache::VerIterator
&Ver
,
130 std::string
const &lang
, MD5SumValue
const &CurMd5
, map_stringitem_t
&md5idx
);
133 // This is the abstract package list parser class. /*{{{*/
134 class APT_HIDDEN pkgCacheListParser
136 pkgCacheGenerator
*Owner
;
137 friend class pkgCacheGenerator
;
138 template<class T
> using Dynamic
= pkgCacheGenerator::Dynamic
<T
>;
141 pkgCache::VerIterator OldDepVer
;
142 map_pointer_t
*OldDepLast
;
148 inline map_stringitem_t
StoreString(pkgCacheGenerator::StringType
const type
, std::string
const &S
) {return Owner
->StoreString(type
, S
);};
149 inline map_stringitem_t
StoreString(pkgCacheGenerator::StringType
const type
, const char *S
,unsigned int Size
) {return Owner
->StoreString(type
, S
, Size
);};
151 inline map_stringitem_t
WriteString(const std::string
&S
) {return Owner
->WriteStringInMap(S
);};
152 inline map_stringitem_t
WriteString(const char *S
,unsigned int Size
) {return Owner
->WriteStringInMap(S
,Size
);};
153 bool NewDepends(pkgCache::VerIterator
&Ver
,const std::string
&Package
, const std::string
&Arch
,
154 const std::string
&Version
,uint8_t const Op
,
156 bool NewProvides(pkgCache::VerIterator
&Ver
,const std::string
&PkgName
,
157 const std::string
&PkgArch
, const std::string
&Version
,
158 uint8_t const Flags
);
159 bool NewProvidesAllArch(pkgCache::VerIterator
&Ver
, std::string
const &Package
,
160 std::string
const &Version
, uint8_t const Flags
);
164 // These all operate against the current section
165 virtual std::string
Package() = 0;
166 virtual std::string
Architecture() = 0;
167 virtual bool ArchitectureAll() = 0;
168 virtual std::string
Version() = 0;
169 virtual bool NewVersion(pkgCache::VerIterator
&Ver
) = 0;
170 virtual std::string
Description(std::string
const &lang
) = 0;
171 virtual std::vector
<std::string
> AvailableDescriptionLanguages() = 0;
172 virtual MD5SumValue
Description_md5() = 0;
173 virtual unsigned short VersionHash() = 0;
174 /** compare currently parsed version with given version
176 * \param Hash of the currently parsed version
177 * \param Ver to compare with
179 virtual bool SameVersion(unsigned short const Hash
, pkgCache::VerIterator
const &Ver
);
180 virtual bool UsePackage(pkgCache::PkgIterator
&Pkg
,
181 pkgCache::VerIterator
&Ver
) = 0;
182 virtual map_filesize_t
Offset() = 0;
183 virtual map_filesize_t
Size() = 0;
185 virtual bool Step() = 0;
187 virtual bool CollectFileProvides(pkgCache
&/*Cache*/,
188 pkgCache::VerIterator
&/*Ver*/) {return true;};
190 pkgCacheListParser();
191 virtual ~pkgCacheListParser();
195 bool pkgMakeStatusCache(pkgSourceList
&List
,OpProgress
&Progress
,
196 MMap
**OutMap
= 0,bool AllowMem
= false);
197 bool pkgMakeOnlyStatusCache(OpProgress
&Progress
,DynamicMMap
**OutMap
);