]> git.saurik.com Git - apt.git/blame - apt-pkg/indexrecords.cc
use the Valid-Until header from the Release file but if the user
[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
92fcbfc1 42bool indexRecords::Load(const string Filename) /*{{{*/
7db98ffc
MZ
43{
44 FileFd Fd(Filename, FileFd::ReadOnly);
45 pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX
46 if (_error->PendingError() == true)
47 {
d4cd303e 48 strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
7db98ffc
MZ
49 return false;
50 }
51
52 pkgTagSection Section;
53 if (TagFile.Step(Section) == false)
54 {
d4cd303e 55 strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str());
7db98ffc
MZ
56 return false;
57 }
58
59 const char *Start, *End;
60 Section.Get (Start, End, 0);
495e5cb2 61
7db98ffc
MZ
62 Suite = Section.FindS("Suite");
63 Dist = Section.FindS("Codename");
495e5cb2
MV
64
65 int i;
66 for (i=0;HashString::SupportedHashes()[i] != NULL; i++)
7db98ffc 67 {
495e5cb2
MV
68 if (!Section.Find(HashString::SupportedHashes()[i], Start, End))
69 continue;
70
71 string Name;
72 string Hash;
73 size_t Size;
74 while (Start < End)
75 {
76 if (!parseSumData(Start, End, Name, Hash, Size))
77 return false;
78 indexRecords::checkSum *Sum = new indexRecords::checkSum;
79 Sum->MetaKeyFilename = Name;
80 Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);
81 Sum->Size = Size;
82 Entries[Name] = Sum;
83 }
84 break;
7db98ffc 85 }
495e5cb2
MV
86
87 if(HashString::SupportedHashes()[i] == NULL)
7db98ffc 88 {
d4cd303e 89 strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
495e5cb2 90 return false;
bbde96a6 91 }
495e5cb2 92
1ddb8596 93 string Label = Section.FindS("Label");
0323317c 94 string StrDate = Section.FindS("Date");
1ddb8596
DK
95 string StrValidUntil = Section.FindS("Valid-Until");
96
bbde96a6 97 // if we have a Valid-Until header in the Release file, use it as default
0323317c 98 if (StrValidUntil.empty() == false)
1ddb8596 99 {
0323317c 100 if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
1ddb8596 101 {
0323317c 102 strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str());
1ddb8596
DK
103 return false;
104 }
bbde96a6
DK
105 }
106 // get the user settings for this archive and use what expires earlier
107 int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0);
108 if (Label.empty() == true)
109 MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::" + Label).c_str(), MaxAge);
0323317c 110
bbde96a6
DK
111 if(MaxAge == 0) // No user settings, use the one from the Release file
112 return true;
113
114 time_t date;
115 if (RFC1123StrToTime(StrDate.c_str(), date) == false)
116 {
117 strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
118 return false;
1ddb8596 119 }
bbde96a6
DK
120 date += 24*60*60*MaxAge;
121
122 if (ValidUntil == 0 || ValidUntil > date)
123 ValidUntil = date;
1ddb8596 124
7db98ffc
MZ
125 return true;
126}
92fcbfc1
DK
127 /*}}}*/
128vector<string> indexRecords::MetaKeys() /*{{{*/
a75c6a6e
MZ
129{
130 std::vector<std::string> keys;
131 std::map<string,checkSum *>::iterator I = Entries.begin();
132 while(I != Entries.end()) {
133 keys.push_back((*I).first);
134 ++I;
135 }
136 return keys;
137}
92fcbfc1
DK
138 /*}}}*/
139bool indexRecords::parseSumData(const char *&Start, const char *End, /*{{{*/
7db98ffc
MZ
140 string &Name, string &Hash, size_t &Size)
141{
142 Name = "";
143 Hash = "";
144 Size = 0;
145 /* Skip over the first blank */
146 while ((*Start == '\t' || *Start == ' ' || *Start == '\n')
147 && Start < End)
148 Start++;
149 if (Start >= End)
150 return false;
151
152 /* Move EntryEnd to the end of the first entry (the hash) */
153 const char *EntryEnd = Start;
154 while ((*EntryEnd != '\t' && *EntryEnd != ' ')
155 && EntryEnd < End)
156 EntryEnd++;
157 if (EntryEnd == End)
158 return false;
159
160 Hash.append(Start, EntryEnd-Start);
161
162 /* Skip over intermediate blanks */
163 Start = EntryEnd;
164 while (*Start == '\t' || *Start == ' ')
165 Start++;
166 if (Start >= End)
167 return false;
168
169 EntryEnd = Start;
170 /* Find the end of the second entry (the size) */
171 while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
172 && EntryEnd < End)
173 EntryEnd++;
174 if (EntryEnd == End)
175 return false;
176
177 Size = strtol (Start, NULL, 10);
178
179 /* Skip over intermediate blanks */
180 Start = EntryEnd;
181 while (*Start == '\t' || *Start == ' ')
182 Start++;
183 if (Start >= End)
184 return false;
185
186 EntryEnd = Start;
187 /* Find the end of the third entry (the filename) */
188 while ((*EntryEnd != '\t' && *EntryEnd != ' ' && *EntryEnd != '\n')
189 && EntryEnd < End)
190 EntryEnd++;
191
192 Name.append(Start, EntryEnd-Start);
193 Start = EntryEnd; //prepare for the next round
194 return true;
195}
92fcbfc1 196 /*}}}*/
7db98ffc
MZ
197indexRecords::indexRecords()
198{
199}
200
201indexRecords::indexRecords(const string ExpectedDist) :
1ddb8596 202 ExpectedDist(ExpectedDist), ValidUntil(0)
7db98ffc
MZ
203{
204}