]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
00f520c4f1b20ca80fc32923b5c2820c78ac7b1a
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>
18 string
indexRecords::GetDist() const
23 bool indexRecords::CheckDist(const string MaybeDist
) const
25 return (this->Dist
== MaybeDist
26 || this->Suite
== MaybeDist
);
29 string
indexRecords::GetExpectedDist() const
31 return this->ExpectedDist
;
34 time_t indexRecords::GetValidUntil() const
36 return this->ValidUntil
;
39 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
41 return Entries
[MetaKey
];
44 bool indexRecords::Exists(string
const &MetaKey
) const
46 return Entries
.count(MetaKey
) == 1;
49 bool indexRecords::Load(const string Filename
) /*{{{*/
51 FileFd
Fd(Filename
, FileFd::ReadOnly
);
52 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
53 if (_error
->PendingError() == true)
55 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
59 pkgTagSection Section
;
60 const char *Start
, *End
;
61 // Skip over sections beginning with ----- as this is an idicator for clearsigns
63 if (TagFile
.Step(Section
) == false)
65 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
69 Section
.Get (Start
, End
, 0);
70 } while (End
- Start
> 5 && strncmp(Start
, "-----", 5) == 0);
72 Suite
= Section
.FindS("Suite");
73 Dist
= Section
.FindS("Codename");
76 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
78 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
86 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
88 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
89 Sum
->MetaKeyFilename
= Name
;
90 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
97 if(HashString::SupportedHashes()[i
] == NULL
)
99 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
103 string Label
= Section
.FindS("Label");
104 string StrDate
= Section
.FindS("Date");
105 string StrValidUntil
= Section
.FindS("Valid-Until");
107 // if we have a Valid-Until header in the Release file, use it as default
108 if (StrValidUntil
.empty() == false)
110 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
112 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
116 // get the user settings for this archive and use what expires earlier
117 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
118 if (Label
.empty() == true)
119 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
121 if(MaxAge
== 0) // No user settings, use the one from the Release file
125 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
127 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
130 date
+= 24*60*60*MaxAge
;
132 if (ValidUntil
== 0 || ValidUntil
> date
)
138 vector
<string
> indexRecords::MetaKeys() /*{{{*/
140 std::vector
<std::string
> keys
;
141 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
142 while(I
!= Entries
.end()) {
143 keys
.push_back((*I
).first
);
149 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
150 string
&Name
, string
&Hash
, size_t &Size
)
155 /* Skip over the first blank */
156 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
162 /* Move EntryEnd to the end of the first entry (the hash) */
163 const char *EntryEnd
= Start
;
164 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
170 Hash
.append(Start
, EntryEnd
-Start
);
172 /* Skip over intermediate blanks */
174 while (*Start
== '\t' || *Start
== ' ')
180 /* Find the end of the second entry (the size) */
181 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
187 Size
= strtol (Start
, NULL
, 10);
189 /* Skip over intermediate blanks */
191 while (*Start
== '\t' || *Start
== ' ')
197 /* Find the end of the third entry (the filename) */
198 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
202 Name
.append(Start
, EntryEnd
-Start
);
203 Start
= EntryEnd
; //prepare for the next round
207 indexRecords::indexRecords()
211 indexRecords::indexRecords(const string ExpectedDist
) :
212 ExpectedDist(ExpectedDist
), ValidUntil(0)