]>
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(const string 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
indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
63 std::map
<std::string
, indexRecords::checkSum
* >::const_iterator sum
= Entries
.find(MetaKey
);
64 if (sum
== Entries
.end())
69 APT_PURE
bool indexRecords::Exists(string
const &MetaKey
) const
71 return Entries
.count(MetaKey
) == 1;
74 bool indexRecords::Load(const string Filename
) /*{{{*/
77 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
80 pkgTagFile
TagFile(&Fd
, Fd
.Size());
81 if (_error
->PendingError() == true)
83 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
87 pkgTagSection Section
;
88 const char *Start
, *End
;
89 if (TagFile
.Step(Section
) == false)
91 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
94 // FIXME: find better tag name
95 SupportsAcquireByHash
= Section
.FindB("Acquire-By-Hash", false);
97 Suite
= Section
.FindS("Suite");
98 Dist
= Section
.FindS("Codename");
100 bool FoundHashSum
= false;
101 for (int i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
103 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
108 unsigned long long Size
;
111 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
114 if (Entries
.find(Name
) == Entries
.end())
116 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
117 Sum
->MetaKeyFilename
= Name
;
120 strprintf(SizeStr
, "%llu", Size
);
121 Sum
->Hashes
.push_back(HashString("Checksum-FileSize", SizeStr
));
122 APT_IGNORE_DEPRECATED(Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);)
125 Entries
[Name
]->Hashes
.push_back(HashString(HashString::SupportedHashes()[i
],Hash
));
130 if(FoundHashSum
== false)
132 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
136 string Label
= Section
.FindS("Label");
137 string StrDate
= Section
.FindS("Date");
138 string StrValidUntil
= Section
.FindS("Valid-Until");
140 // if we have a Valid-Until header in the Release file, use it as default
141 if (StrValidUntil
.empty() == false)
143 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
145 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
149 // get the user settings for this archive and use what expires earlier
150 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
151 if (Label
.empty() == false)
152 MaxAge
= _config
->FindI(("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
153 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
154 if (Label
.empty() == false)
155 MinAge
= _config
->FindI(("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
158 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
162 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
164 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
168 if (MinAge
!= 0 && ValidUntil
!= 0) {
169 time_t const min_date
= date
+ MinAge
;
170 if (ValidUntil
< min_date
)
171 ValidUntil
= min_date
;
174 time_t const max_date
= date
+ MaxAge
;
175 if (ValidUntil
== 0 || ValidUntil
> max_date
)
176 ValidUntil
= max_date
;
182 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
184 std::vector
<std::string
> keys
;
185 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
186 while(I
!= Entries
.end()) {
187 keys
.push_back((*I
).first
);
193 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
194 string
&Name
, string
&Hash
, unsigned long long &Size
)
199 /* Skip over the first blank */
200 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
206 /* Move EntryEnd to the end of the first entry (the hash) */
207 const char *EntryEnd
= Start
;
208 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
214 Hash
.append(Start
, EntryEnd
-Start
);
216 /* Skip over intermediate blanks */
218 while (*Start
== '\t' || *Start
== ' ')
224 /* Find the end of the second entry (the size) */
225 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
231 Size
= strtoull (Start
, NULL
, 10);
233 /* Skip over intermediate blanks */
235 while (*Start
== '\t' || *Start
== ' ')
241 /* Find the end of the third entry (the filename) */
242 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
243 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
247 Name
.append(Start
, EntryEnd
-Start
);
248 Start
= EntryEnd
; //prepare for the next round
253 APT_PURE
bool indexRecords::IsAlwaysTrusted() const
255 if (Trusted
== ALWAYS_TRUSTED
)
259 APT_PURE
bool indexRecords::IsNeverTrusted() const
261 if (Trusted
== NEVER_TRUSTED
)
265 void indexRecords::SetTrusted(bool const Trusted
)
268 this->Trusted
= ALWAYS_TRUSTED
;
270 this->Trusted
= NEVER_TRUSTED
;
273 indexRecords::indexRecords(const string
&ExpectedDist
) :
274 Trusted(CHECK_TRUST
), d(NULL
), ExpectedDist(ExpectedDist
), ValidUntil(0),
275 SupportsAcquireByHash(false)
279 indexRecords::~indexRecords() {}