]>
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>
24 string
indexRecords::GetDist() const
29 bool indexRecords::CheckDist(const string MaybeDist
) const
31 return (this->Dist
== MaybeDist
32 || this->Suite
== MaybeDist
);
35 string
indexRecords::GetExpectedDist() const
37 return this->ExpectedDist
;
40 time_t indexRecords::GetValidUntil() const
42 return this->ValidUntil
;
45 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
47 std::map
<std::string
, indexRecords::checkSum
* >::const_iterator sum
= Entries
.find(MetaKey
);
48 if (sum
== Entries
.end())
53 bool indexRecords::Exists(string
const &MetaKey
) const
55 return Entries
.count(MetaKey
) == 1;
58 bool indexRecords::Load(const string Filename
) /*{{{*/
60 FileFd
Fd(Filename
, FileFd::ReadOnly
);
61 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
62 if (_error
->PendingError() == true)
64 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
68 pkgTagSection Section
;
69 const char *Start
, *End
;
70 // Skip over sections beginning with ----- as this is an idicator for clearsigns
72 if (TagFile
.Step(Section
) == false)
74 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
78 Section
.Get (Start
, End
, 0);
79 } while (End
- Start
> 5 && strncmp(Start
, "-----", 5) == 0);
81 Suite
= Section
.FindS("Suite");
82 Dist
= Section
.FindS("Codename");
85 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
87 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
92 unsigned long long Size
;
95 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
97 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
98 Sum
->MetaKeyFilename
= Name
;
99 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
106 if(HashString::SupportedHashes()[i
] == NULL
)
108 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
112 string Label
= Section
.FindS("Label");
113 string StrDate
= Section
.FindS("Date");
114 string StrValidUntil
= Section
.FindS("Valid-Until");
116 // if we have a Valid-Until header in the Release file, use it as default
117 if (StrValidUntil
.empty() == false)
119 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
121 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
125 // get the user settings for this archive and use what expires earlier
126 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
127 if (Label
.empty() == false)
128 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
129 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
130 if (Label
.empty() == false)
131 MinAge
= _config
->FindI(string("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
134 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
138 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
140 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
144 if (MinAge
!= 0 && ValidUntil
!= 0) {
145 time_t const min_date
= date
+ MinAge
;
146 if (ValidUntil
< min_date
)
147 ValidUntil
= min_date
;
150 time_t const max_date
= date
+ MaxAge
;
151 if (ValidUntil
== 0 || ValidUntil
> max_date
)
152 ValidUntil
= max_date
;
158 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
160 std::vector
<std::string
> keys
;
161 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
162 while(I
!= Entries
.end()) {
163 keys
.push_back((*I
).first
);
169 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
170 string
&Name
, string
&Hash
, unsigned long long &Size
)
175 /* Skip over the first blank */
176 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
182 /* Move EntryEnd to the end of the first entry (the hash) */
183 const char *EntryEnd
= Start
;
184 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
190 Hash
.append(Start
, EntryEnd
-Start
);
192 /* Skip over intermediate blanks */
194 while (*Start
== '\t' || *Start
== ' ')
200 /* Find the end of the second entry (the size) */
201 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
207 Size
= strtoull (Start
, NULL
, 10);
209 /* Skip over intermediate blanks */
211 while (*Start
== '\t' || *Start
== ' ')
217 /* Find the end of the third entry (the filename) */
218 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
219 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
223 Name
.append(Start
, EntryEnd
-Start
);
224 Start
= EntryEnd
; //prepare for the next round
228 indexRecords::indexRecords()
232 indexRecords::indexRecords(const string ExpectedDist
) :
233 ExpectedDist(ExpectedDist
), ValidUntil(0)