]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: indexrecords.cc,v 1.1.2.4 2003/12/30 02:11:43 mdz Exp $
5 // Include Files /*{{{*/
8 #include <apt-pkg/indexrecords.h>
9 #include <apt-pkg/tagfile.h>
10 #include <apt-pkg/error.h>
11 #include <apt-pkg/strutl.h>
12 #include <apt-pkg/configuration.h>
13 #include <apt-pkg/fileutl.h>
14 #include <apt-pkg/hashes.h>
15 #include <apt-pkg/gpgv.h>
30 APT_PURE string
indexRecords::GetDist() const
35 APT_PURE string
indexRecords::GetSuite() const
40 APT_PURE
bool indexRecords::GetSupportsAcquireByHash() const
42 return this->SupportsAcquireByHash
;
45 APT_PURE
bool indexRecords::CheckDist(string
const &MaybeDist
) const
47 return (this->Dist
== MaybeDist
48 || this->Suite
== MaybeDist
);
51 APT_PURE string
indexRecords::GetExpectedDist() const
53 return this->ExpectedDist
;
56 APT_PURE
time_t indexRecords::GetValidUntil() const
58 return this->ValidUntil
;
61 APT_PURE
time_t indexRecords::GetDate() const
66 APT_PURE
indexRecords::checkSum
*indexRecords::Lookup(string
const &MetaKey
)
68 std::map
<std::string
, indexRecords::checkSum
* >::const_iterator sum
= Entries
.find(MetaKey
);
69 if (sum
== Entries
.end())
74 APT_PURE
bool indexRecords::Exists(string
const &MetaKey
) const
76 return Entries
.find(MetaKey
) != Entries
.end();
79 bool indexRecords::Load(string
const &Filename
) /*{{{*/
82 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
85 pkgTagFile
TagFile(&Fd
, Fd
.Size());
86 if (_error
->PendingError() == true)
88 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
92 pkgTagSection Section
;
93 const char *Start
, *End
;
94 if (TagFile
.Step(Section
) == false)
96 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
99 // FIXME: find better tag name
100 SupportsAcquireByHash
= Section
.FindB("Acquire-By-Hash", false);
102 Suite
= Section
.FindS("Suite");
103 Dist
= Section
.FindS("Codename");
105 bool FoundHashSum
= false;
106 for (int i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
108 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
113 unsigned long long Size
;
116 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
119 if (Entries
.find(Name
) == Entries
.end())
121 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
122 Sum
->MetaKeyFilename
= Name
;
124 Sum
->Hashes
.FileSize(Size
);
125 APT_IGNORE_DEPRECATED(Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);)
128 Entries
[Name
]->Hashes
.push_back(HashString(HashString::SupportedHashes()[i
],Hash
));
133 if(FoundHashSum
== false)
135 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
139 string
const StrDate
= Section
.FindS("Date");
140 if (RFC1123StrToTime(StrDate
.c_str(), Date
) == false)
142 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
146 string
const Label
= Section
.FindS("Label");
147 string
const StrValidUntil
= Section
.FindS("Valid-Until");
149 // if we have a Valid-Until header in the Release file, use it as default
150 if (StrValidUntil
.empty() == false)
152 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
154 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
158 // get the user settings for this archive and use what expires earlier
159 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
160 if (Label
.empty() == false)
161 MaxAge
= _config
->FindI(("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
162 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
163 if (Label
.empty() == false)
164 MinAge
= _config
->FindI(("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
167 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
170 if (MinAge
!= 0 && ValidUntil
!= 0) {
171 time_t const min_date
= Date
+ MinAge
;
172 if (ValidUntil
< min_date
)
173 ValidUntil
= min_date
;
176 time_t const max_date
= Date
+ MaxAge
;
177 if (ValidUntil
== 0 || ValidUntil
> max_date
)
178 ValidUntil
= max_date
;
184 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
186 std::vector
<std::string
> keys
;
187 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
188 while(I
!= Entries
.end()) {
189 keys
.push_back((*I
).first
);
195 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
196 string
&Name
, string
&Hash
, unsigned long long &Size
)
201 /* Skip over the first blank */
202 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
208 /* Move EntryEnd to the end of the first entry (the hash) */
209 const char *EntryEnd
= Start
;
210 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
216 Hash
.append(Start
, EntryEnd
-Start
);
218 /* Skip over intermediate blanks */
220 while (*Start
== '\t' || *Start
== ' ')
226 /* Find the end of the second entry (the size) */
227 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
233 Size
= strtoull (Start
, NULL
, 10);
235 /* Skip over intermediate blanks */
237 while (*Start
== '\t' || *Start
== ' ')
243 /* Find the end of the third entry (the filename) */
244 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
245 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
249 Name
.append(Start
, EntryEnd
-Start
);
250 Start
= EntryEnd
; //prepare for the next round
255 APT_PURE
bool indexRecords::IsAlwaysTrusted() const
257 if (Trusted
== ALWAYS_TRUSTED
)
261 APT_PURE
bool indexRecords::IsNeverTrusted() const
263 if (Trusted
== NEVER_TRUSTED
)
267 void indexRecords::SetTrusted(bool const Trusted
)
270 this->Trusted
= ALWAYS_TRUSTED
;
272 this->Trusted
= NEVER_TRUSTED
;
275 indexRecords::indexRecords(const string
&ExpectedDist
) :
276 Trusted(CHECK_TRUST
), d(NULL
), ExpectedDist(ExpectedDist
), ValidUntil(0),
277 SupportsAcquireByHash(false)
281 indexRecords::~indexRecords() {}