]> git.saurik.com Git - apt.git/blame - apt-pkg/indexrecords.cc
* test/versions.lst:
[apt.git] / apt-pkg / indexrecords.cc
CommitLineData
7db98ffc
MZ
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: indexrecords.cc,v 1.1.2.4 2003/12/30 02:11:43 mdz Exp $
4 /*}}}*/
5// Include Files /*{{{*/
7db98ffc
MZ
6#include <apt-pkg/indexrecords.h>
7#include <apt-pkg/tagfile.h>
8#include <apt-pkg/error.h>
9#include <apt-pkg/strutl.h>
1ddb8596 10#include <apt-pkg/configuration.h>
7db98ffc
MZ
11#include <apti18n.h>
12#include <sys/stat.h>
1ddb8596
DK
13#include <clocale>
14
92fcbfc1 15 /*}}}*/
7db98ffc
MZ
16string indexRecords::GetDist() const
17{
18 return this->Dist;
19}
20
21bool indexRecords::CheckDist(const string MaybeDist) const
22{
23 return (this->Dist == MaybeDist
24 || this->Suite == MaybeDist);
25}
26
27string indexRecords::GetExpectedDist() const
28{
29 return this->ExpectedDist;
30}
31
1ddb8596
DK
32time_t indexRecords::GetValidUntil() const
33{
34 return this->ValidUntil;
35}
36
7db98ffc
MZ
37const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
38{
39 return Entries[MetaKey];
40}
41
e1430400
DK
42bool indexRecords::Exists(string const &MetaKey) const
43{
44 return Entries.count(MetaKey) == 1;
45}
46
92fcbfc1 47bool indexRecords::Load(const string Filename) /*{{{*/
7db98ffc
MZ
48{
49 FileFd Fd(Filename, FileFd::ReadOnly);
50 pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX
51 if (_error->PendingError() == true)
52 {
d4cd303e 53 strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
7db98ffc
MZ
54 return false;
55 }
56
57 pkgTagSection Section;
7db98ffc 58 const char *Start, *End;
fe0f7911
DK
59 // Skip over sections beginning with ----- as this is an idicator for clearsigns
60 do {
61 if (TagFile.Step(Section) == false)
62 {
63 strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str());
64 return false;
65 }
66
67 Section.Get (Start, End, 0);
68 } while (End - Start > 5 && strncmp(Start, "-----", 5) == 0);
495e5cb2 69
7db98ffc
MZ
70 Suite = Section.FindS("Suite");
71 Dist = Section.FindS("Codename");
495e5cb2
MV
72
73 int i;
74 for (i=0;HashString::SupportedHashes()[i] != NULL; i++)
7db98ffc 75 {
495e5cb2
MV
76 if (!Section.Find(HashString::SupportedHashes()[i], Start, End))
77 continue;
78
79 string Name;
80 string Hash;
81 size_t Size;
82 while (Start < End)
83 {
84 if (!parseSumData(Start, End, Name, Hash, Size))
85 return false;
86 indexRecords::checkSum *Sum = new indexRecords::checkSum;
87 Sum->MetaKeyFilename = Name;
88 Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);
89 Sum->Size = Size;
90 Entries[Name] = Sum;
91 }
92 break;
7db98ffc 93 }
495e5cb2
MV
94
95 if(HashString::SupportedHashes()[i] == NULL)
7db98ffc 96 {
d4cd303e 97 strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
495e5cb2 98 return false;
bbde96a6 99 }
495e5cb2 100
1ddb8596 101 string Label = Section.FindS("Label");
0323317c 102 string StrDate = Section.FindS("Date");
1ddb8596
DK
103 string StrValidUntil = Section.FindS("Valid-Until");
104
bbde96a6 105 // if we have a Valid-Until header in the Release file, use it as default
0323317c 106 if (StrValidUntil.empty() == false)
1ddb8596 107 {
0323317c 108 if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
1ddb8596 109 {
0323317c 110 strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str());
1ddb8596
DK
111 return false;
112 }
bbde96a6
DK
113 }
114 // get the user settings for this archive and use what expires earlier
b02fffa6 115 int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
bbde96a6 116 if (Label.empty() == true)
b02fffa6 117 MaxAge = _config->FindI(string("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
0323317c 118
bbde96a6
DK
119 if(MaxAge == 0) // No user settings, use the one from the Release file
120 return true;
121
122 time_t date;
123 if (RFC1123StrToTime(StrDate.c_str(), date) == false)
124 {
125 strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
126 return false;
1ddb8596 127 }
bbde96a6
DK
128 date += 24*60*60*MaxAge;
129
130 if (ValidUntil == 0 || ValidUntil > date)
131 ValidUntil = date;
495e5cb2 132
7db98ffc
MZ
133 return true;
134}
92fcbfc1
DK
135 /*}}}*/
136vector<string> indexRecords::MetaKeys() /*{{{*/
a75c6a6e
MZ
137{
138 std::vector<std::string> keys;
139 std::map<string,checkSum *>::iterator I = Entries.begin();
140 while(I != Entries.end()) {
141 keys.push_back((*I).first);
142 ++I;
143 }
144 return keys;
145}
92fcbfc1
DK
146 /*}}}*/
147bool indexRecords::parseSumData(const char *&Start, const char *End, /*{{{*/
7db98ffc
MZ
148 string &Name, string &Hash, size_t &Size)
149{
150 Name = "";
151 Hash = "";
152 Size = 0;
153 /* Skip over the first blank */
154 while ((*Start == '\t' || *Start == ' ' || *Start == '\n')
155 && Start < End)
156 Start++;
157 if (Start >= End)
158 return false;
159
160 /* Move EntryEnd to the end of the first entry (the hash) */
161 const char *EntryEnd = Start;
162 while ((*EntryEnd != '\t' && *EntryEnd != ' ')
163 && EntryEnd < End)
164 EntryEnd++;
165 if (EntryEnd == End)
166 return false;
167
168 Hash.append(Start, EntryEnd-Start);
169
170 /* Skip over intermediate blanks */
171 Start = EntryEnd;
172 while (*Start == '\t' || *Start == ' ')
173 Start++;
174 if (Start >= End)
175 return false;
176
177 EntryEnd = Start;
178 /* Find the end of the second entry (the size) */
179 while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
180 && EntryEnd < End)
181 EntryEnd++;
182 if (EntryEnd == End)
183 return false;
184
185 Size = strtol (Start, NULL, 10);
186
187 /* Skip over intermediate blanks */
188 Start = EntryEnd;
189 while (*Start == '\t' || *Start == ' ')
190 Start++;
191 if (Start >= End)
192 return false;
193
194 EntryEnd = Start;
195 /* Find the end of the third entry (the filename) */
196 while ((*EntryEnd != '\t' && *EntryEnd != ' ' && *EntryEnd != '\n')
197 && EntryEnd < End)
198 EntryEnd++;
199
200 Name.append(Start, EntryEnd-Start);
201 Start = EntryEnd; //prepare for the next round
202 return true;
203}
92fcbfc1 204 /*}}}*/
7db98ffc
MZ
205indexRecords::indexRecords()
206{
207}
208
209indexRecords::indexRecords(const string ExpectedDist) :
1ddb8596 210 ExpectedDist(ExpectedDist), ValidUntil(0)
7db98ffc
MZ
211{
212}