]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
7b48d659ec5e04364c010b800cbfe782480ca9ed
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>
21 string
indexRecords::GetDist() const
26 bool indexRecords::CheckDist(const string MaybeDist
) const
28 return (this->Dist
== MaybeDist
29 || this->Suite
== MaybeDist
);
32 string
indexRecords::GetExpectedDist() const
34 return this->ExpectedDist
;
37 time_t indexRecords::GetValidUntil() const
39 return this->ValidUntil
;
42 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
44 return Entries
[MetaKey
];
47 bool indexRecords::Exists(string
const &MetaKey
) const
49 return Entries
.count(MetaKey
) == 1;
52 bool indexRecords::Load(const string Filename
) /*{{{*/
54 FileFd
Fd(Filename
, FileFd::ReadOnly
);
55 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
56 if (_error
->PendingError() == true)
58 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
62 pkgTagSection Section
;
63 const char *Start
, *End
;
64 // Skip over sections beginning with ----- as this is an idicator for clearsigns
66 if (TagFile
.Step(Section
) == false)
68 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
72 Section
.Get (Start
, End
, 0);
73 } while (End
- Start
> 5 && strncmp(Start
, "-----", 5) == 0);
75 Suite
= Section
.FindS("Suite");
76 Dist
= Section
.FindS("Codename");
79 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
81 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
86 unsigned long long Size
;
89 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
91 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
92 Sum
->MetaKeyFilename
= Name
;
93 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
100 if(HashString::SupportedHashes()[i
] == NULL
)
102 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
106 string Label
= Section
.FindS("Label");
107 string StrDate
= Section
.FindS("Date");
108 string StrValidUntil
= Section
.FindS("Valid-Until");
110 // if we have a Valid-Until header in the Release file, use it as default
111 if (StrValidUntil
.empty() == false)
113 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
115 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
119 // get the user settings for this archive and use what expires earlier
120 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
121 if (Label
.empty() == false)
122 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
123 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
124 if (Label
.empty() == false)
125 MinAge
= _config
->FindI(string("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
128 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
132 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
134 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
138 if (MinAge
!= 0 && ValidUntil
!= 0) {
139 time_t const min_date
= date
+ MinAge
;
140 if (ValidUntil
< min_date
)
141 ValidUntil
= min_date
;
144 time_t const max_date
= date
+ MaxAge
;
145 if (ValidUntil
== 0 || ValidUntil
> max_date
)
146 ValidUntil
= max_date
;
152 std::vector
<string
> indexRecords::MetaKeys() /*{{{*/
154 std::vector
<std::string
> keys
;
155 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
156 while(I
!= Entries
.end()) {
157 keys
.push_back((*I
).first
);
163 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
164 string
&Name
, string
&Hash
, unsigned long long &Size
)
169 /* Skip over the first blank */
170 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
176 /* Move EntryEnd to the end of the first entry (the hash) */
177 const char *EntryEnd
= Start
;
178 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
184 Hash
.append(Start
, EntryEnd
-Start
);
186 /* Skip over intermediate blanks */
188 while (*Start
== '\t' || *Start
== ' ')
194 /* Find the end of the second entry (the size) */
195 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
201 Size
= strtoull (Start
, NULL
, 10);
203 /* Skip over intermediate blanks */
205 while (*Start
== '\t' || *Start
== ' ')
211 /* Find the end of the third entry (the filename) */
212 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
216 Name
.append(Start
, EntryEnd
-Start
);
217 Start
= EntryEnd
; //prepare for the next round
221 indexRecords::indexRecords()
225 indexRecords::indexRecords(const string ExpectedDist
) :
226 ExpectedDist(ExpectedDist
), ValidUntil(0)