]>
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 bool indexRecords::CheckDist(const string MaybeDist
) const
32 return (this->Dist
== MaybeDist
33 || this->Suite
== MaybeDist
);
36 string
indexRecords::GetExpectedDist() const
38 return this->ExpectedDist
;
41 time_t indexRecords::GetValidUntil() const
43 return this->ValidUntil
;
46 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
48 std::map
<std::string
, indexRecords::checkSum
* >::const_iterator sum
= Entries
.find(MetaKey
);
49 if (sum
== Entries
.end())
54 bool indexRecords::Exists(string
const &MetaKey
) const
56 return Entries
.count(MetaKey
) == 1;
59 bool indexRecords::Load(const string Filename
) /*{{{*/
62 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
65 pkgTagFile
TagFile(&Fd
);
66 if (_error
->PendingError() == true)
68 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
72 pkgTagSection Section
;
73 const char *Start
, *End
;
74 if (TagFile
.Step(Section
) == false)
76 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
80 Suite
= Section
.FindS("Suite");
81 Dist
= Section
.FindS("Codename");
84 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
86 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
91 unsigned long long Size
;
94 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
96 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
97 Sum
->MetaKeyFilename
= Name
;
98 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
105 if(HashString::SupportedHashes()[i
] == NULL
)
107 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
111 string Label
= Section
.FindS("Label");
112 string StrDate
= Section
.FindS("Date");
113 string StrValidUntil
= Section
.FindS("Valid-Until");
115 // if we have a Valid-Until header in the Release file, use it as default
116 if (StrValidUntil
.empty() == false)
118 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
120 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
124 // get the user settings for this archive and use what expires earlier
125 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
126 if (Label
.empty() == false)
127 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
128 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
129 if (Label
.empty() == false)
130 MinAge
= _config
->FindI(string("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
133 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
137 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
139 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
143 if (MinAge
!= 0 && ValidUntil
!= 0) {
144 time_t const min_date
= date
+ MinAge
;
145 if (ValidUntil
< min_date
)
146 ValidUntil
= min_date
;
149 time_t const max_date
= date
+ MaxAge
;
150 if (ValidUntil
== 0 || ValidUntil
> max_date
)
151 ValidUntil
= max_date
;
157 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
159 std::vector
<std::string
> keys
;
160 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
161 while(I
!= Entries
.end()) {
162 keys
.push_back((*I
).first
);
168 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
169 string
&Name
, string
&Hash
, unsigned long long &Size
)
174 /* Skip over the first blank */
175 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
181 /* Move EntryEnd to the end of the first entry (the hash) */
182 const char *EntryEnd
= Start
;
183 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
189 Hash
.append(Start
, EntryEnd
-Start
);
191 /* Skip over intermediate blanks */
193 while (*Start
== '\t' || *Start
== ' ')
199 /* Find the end of the second entry (the size) */
200 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
206 Size
= strtoull (Start
, NULL
, 10);
208 /* Skip over intermediate blanks */
210 while (*Start
== '\t' || *Start
== ' ')
216 /* Find the end of the third entry (the filename) */
217 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
218 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
222 Name
.append(Start
, EntryEnd
-Start
);
223 Start
= EntryEnd
; //prepare for the next round
227 indexRecords::indexRecords()
231 indexRecords::indexRecords(const string ExpectedDist
) :
232 ExpectedDist(ExpectedDist
), ValidUntil(0)