]>
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>
25 string
indexRecords::GetDist() const
30 string
indexRecords::GetSuite() const
35 bool indexRecords::CheckDist(const string MaybeDist
) const
37 return (this->Dist
== MaybeDist
38 || this->Suite
== MaybeDist
);
41 string
indexRecords::GetExpectedDist() const
43 return this->ExpectedDist
;
46 time_t indexRecords::GetValidUntil() const
48 return this->ValidUntil
;
51 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
53 std::map
<std::string
, indexRecords::checkSum
* >::const_iterator sum
= Entries
.find(MetaKey
);
54 if (sum
== Entries
.end())
59 bool indexRecords::Exists(string
const &MetaKey
) const
61 return Entries
.count(MetaKey
) == 1;
64 bool indexRecords::Load(const string Filename
) /*{{{*/
67 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
70 pkgTagFile
TagFile(&Fd
, Fd
.Size());
71 if (_error
->PendingError() == true)
73 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
77 pkgTagSection Section
;
78 const char *Start
, *End
;
79 if (TagFile
.Step(Section
) == false)
81 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
85 Suite
= Section
.FindS("Suite");
86 Dist
= Section
.FindS("Codename");
89 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
91 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
96 unsigned long long Size
;
99 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
101 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
102 Sum
->MetaKeyFilename
= Name
;
103 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
110 if(HashString::SupportedHashes()[i
] == NULL
)
112 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
116 string Label
= Section
.FindS("Label");
117 string StrDate
= Section
.FindS("Date");
118 string StrValidUntil
= Section
.FindS("Valid-Until");
120 // if we have a Valid-Until header in the Release file, use it as default
121 if (StrValidUntil
.empty() == false)
123 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
125 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
129 // get the user settings for this archive and use what expires earlier
130 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
131 if (Label
.empty() == false)
132 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
133 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
134 if (Label
.empty() == false)
135 MinAge
= _config
->FindI(string("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
138 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
142 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
144 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
148 if (MinAge
!= 0 && ValidUntil
!= 0) {
149 time_t const min_date
= date
+ MinAge
;
150 if (ValidUntil
< min_date
)
151 ValidUntil
= min_date
;
154 time_t const max_date
= date
+ MaxAge
;
155 if (ValidUntil
== 0 || ValidUntil
> max_date
)
156 ValidUntil
= max_date
;
162 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
164 std::vector
<std::string
> keys
;
165 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
166 while(I
!= Entries
.end()) {
167 keys
.push_back((*I
).first
);
173 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
174 string
&Name
, string
&Hash
, unsigned long long &Size
)
179 /* Skip over the first blank */
180 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
186 /* Move EntryEnd to the end of the first entry (the hash) */
187 const char *EntryEnd
= Start
;
188 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
194 Hash
.append(Start
, EntryEnd
-Start
);
196 /* Skip over intermediate blanks */
198 while (*Start
== '\t' || *Start
== ' ')
204 /* Find the end of the second entry (the size) */
205 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
211 Size
= strtoull (Start
, NULL
, 10);
213 /* Skip over intermediate blanks */
215 while (*Start
== '\t' || *Start
== ' ')
221 /* Find the end of the third entry (the filename) */
222 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
223 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
227 Name
.append(Start
, EntryEnd
-Start
);
228 Start
= EntryEnd
; //prepare for the next round
232 indexRecords::indexRecords()
236 indexRecords::indexRecords(const string ExpectedDist
) :
237 ExpectedDist(ExpectedDist
), ValidUntil(0)