X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/7db98ffceda347f0bc457c6bdc4ff33d60e26b18..0c6aa02ecfbb1b1ecac519527467befae36b7c40:/apt-pkg/indexrecords.cc diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index c4b8a8235..eb9a36866 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -3,16 +3,16 @@ // $Id: indexrecords.cc,v 1.1.2.4 2003/12/30 02:11:43 mdz Exp $ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/indexrecords.h" -#endif #include #include #include #include +#include #include #include +#include + /*}}}*/ string indexRecords::GetDist() const { return this->Dist; @@ -29,61 +29,119 @@ string indexRecords::GetExpectedDist() const return this->ExpectedDist; } +time_t indexRecords::GetValidUntil() const +{ + return this->ValidUntil; +} + const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) { return Entries[MetaKey]; } -bool indexRecords::Load(const string Filename) +bool indexRecords::Exists(string const &MetaKey) const +{ + return Entries.count(MetaKey) == 1; +} + +bool indexRecords::Load(const string Filename) /*{{{*/ { FileFd Fd(Filename, FileFd::ReadOnly); pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX if (_error->PendingError() == true) { - ErrorText = _(("Unable to parse Release file " + Filename).c_str()); + strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str()); return false; } pkgTagSection Section; if (TagFile.Step(Section) == false) { - ErrorText = _(("No sections in Release file " + Filename).c_str()); + strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str()); return false; } const char *Start, *End; Section.Get (Start, End, 0); + Suite = Section.FindS("Suite"); Dist = Section.FindS("Codename"); -// if (Dist.empty()) -// { -// ErrorText = _(("No Codename entry in Release file " + Filename).c_str()); -// return false; -// } - if (!Section.Find("MD5Sum", Start, End)) + + int i; + for (i=0;HashString::SupportedHashes()[i] != NULL; i++) + { + if (!Section.Find(HashString::SupportedHashes()[i], Start, End)) + continue; + + string Name; + string Hash; + size_t Size; + while (Start < End) + { + if (!parseSumData(Start, End, Name, Hash, Size)) + return false; + indexRecords::checkSum *Sum = new indexRecords::checkSum; + Sum->MetaKeyFilename = Name; + Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash); + Sum->Size = Size; + Entries[Name] = Sum; + } + break; + } + + if(HashString::SupportedHashes()[i] == NULL) { - ErrorText = _(("No MD5Sum entry in Release file " + Filename).c_str()); + strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); return false; } - string Name; - string MD5Hash; - size_t Size; - while (Start < End) + + string Label = Section.FindS("Label"); + string StrDate = Section.FindS("Date"); + string StrValidUntil = Section.FindS("Valid-Until"); + + // if we have a Valid-Until header in the Release file, use it as default + if (StrValidUntil.empty() == false) { - if (!parseSumData(Start, End, Name, MD5Hash, Size)) + if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) + { + strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); return false; - indexRecords::checkSum *Sum = new indexRecords::checkSum; - Sum->MetaKeyFilename = Name; - Sum->MD5Hash = MD5Hash; - Sum->Size = Size; - Entries[Name] = Sum; + } } - - string Strdate = Section.FindS("Date"); // FIXME: verify this somehow? + // get the user settings for this archive and use what expires earlier + int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); + if (Label.empty() == true) + MaxAge = _config->FindI(string("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); + + if(MaxAge == 0) // No user settings, use the one from the Release file + return true; + + time_t date; + if (RFC1123StrToTime(StrDate.c_str(), date) == false) + { + strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + return false; + } + date += 24*60*60*MaxAge; + + if (ValidUntil == 0 || ValidUntil > date) + ValidUntil = date; + return true; } - -bool indexRecords::parseSumData(const char *&Start, const char *End, + /*}}}*/ +vector indexRecords::MetaKeys() /*{{{*/ +{ + std::vector keys; + std::map::iterator I = Entries.begin(); + while(I != Entries.end()) { + keys.push_back((*I).first); + ++I; + } + return keys; +} + /*}}}*/ +bool indexRecords::parseSumData(const char *&Start, const char *End, /*{{{*/ string &Name, string &Hash, size_t &Size) { Name = ""; @@ -140,12 +198,12 @@ bool indexRecords::parseSumData(const char *&Start, const char *End, Start = EntryEnd; //prepare for the next round return true; } - + /*}}}*/ indexRecords::indexRecords() { } indexRecords::indexRecords(const string ExpectedDist) : - ExpectedDist(ExpectedDist) + ExpectedDist(ExpectedDist), ValidUntil(0) { }