122194e94adfc7f8a7673344405f5424bf58cd83
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::CheckDist(const string MaybeDist
) const
42 return (this->Dist
== MaybeDist
43 || this->Suite
== MaybeDist
);
46 APT_PURE string
indexRecords::GetExpectedDist() const
48 return this->ExpectedDist
;
51 APT_PURE
time_t indexRecords::GetValidUntil() const
53 return this->ValidUntil
;
56 APT_PURE
indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
58 std::map
<std::string
, indexRecords::checkSum
* >::const_iterator sum
= Entries
.find(MetaKey
);
59 if (sum
== Entries
.end())
64 APT_PURE
bool indexRecords::Exists(string
const &MetaKey
) const
66 return Entries
.count(MetaKey
) == 1;
69 bool indexRecords::Load(const string Filename
) /*{{{*/
72 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
75 pkgTagFile
TagFile(&Fd
, Fd
.Size());
76 if (_error
->PendingError() == true)
78 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
82 pkgTagSection Section
;
83 const char *Start
, *End
;
84 if (TagFile
.Step(Section
) == false)
86 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
90 Suite
= Section
.FindS("Suite");
91 Dist
= Section
.FindS("Codename");
93 bool FoundHashSum
= false;
94 for (int i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
96 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
101 unsigned long long Size
;
104 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
107 if (Entries
.find(Name
) == Entries
.end())
109 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
110 Sum
->MetaKeyFilename
= Name
;
114 Entries
[Name
]->Hashes
.push_back(HashString(HashString::SupportedHashes()[i
],Hash
));
119 if(FoundHashSum
== false)
121 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
125 string Label
= Section
.FindS("Label");
126 string StrDate
= Section
.FindS("Date");
127 string StrValidUntil
= Section
.FindS("Valid-Until");
129 // if we have a Valid-Until header in the Release file, use it as default
130 if (StrValidUntil
.empty() == false)
132 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
134 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
138 // get the user settings for this archive and use what expires earlier
139 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
140 if (Label
.empty() == false)
141 MaxAge
= _config
->FindI(("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
142 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
143 if (Label
.empty() == false)
144 MinAge
= _config
->FindI(("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
147 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
151 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
153 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
157 if (MinAge
!= 0 && ValidUntil
!= 0) {
158 time_t const min_date
= date
+ MinAge
;
159 if (ValidUntil
< min_date
)
160 ValidUntil
= min_date
;
163 time_t const max_date
= date
+ MaxAge
;
164 if (ValidUntil
== 0 || ValidUntil
> max_date
)
165 ValidUntil
= max_date
;
171 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
173 std::vector
<std::string
> keys
;
174 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
175 while(I
!= Entries
.end()) {
176 keys
.push_back((*I
).first
);
182 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
183 string
&Name
, string
&Hash
, unsigned long long &Size
)
188 /* Skip over the first blank */
189 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
195 /* Move EntryEnd to the end of the first entry (the hash) */
196 const char *EntryEnd
= Start
;
197 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
203 Hash
.append(Start
, EntryEnd
-Start
);
205 /* Skip over intermediate blanks */
207 while (*Start
== '\t' || *Start
== ' ')
213 /* Find the end of the second entry (the size) */
214 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
220 Size
= strtoull (Start
, NULL
, 10);
222 /* Skip over intermediate blanks */
224 while (*Start
== '\t' || *Start
== ' ')
230 /* Find the end of the third entry (the filename) */
231 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
232 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
236 Name
.append(Start
, EntryEnd
-Start
);
237 Start
= EntryEnd
; //prepare for the next round
241 indexRecords::indexRecords()
245 indexRecords::indexRecords(const string ExpectedDist
) :
246 ExpectedDist(ExpectedDist
), ValidUntil(0)