]>
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 /*{{{*/
6 #include <apt-pkg/indexrecords.h>
7 #include <apt-pkg/tagfile.h>
8 #include <apt-pkg/error.h>
9 #include <apt-pkg/strutl.h>
10 #include <apt-pkg/configuration.h>
16 string
indexRecords::GetDist() const
21 bool indexRecords::CheckDist(const string MaybeDist
) const
23 return (this->Dist
== MaybeDist
24 || this->Suite
== MaybeDist
);
27 string
indexRecords::GetExpectedDist() const
29 return this->ExpectedDist
;
32 time_t indexRecords::GetValidUntil() const
34 return this->ValidUntil
;
37 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
39 return Entries
[MetaKey
];
42 bool indexRecords::Exists(string
const &MetaKey
) const
44 return Entries
.count(MetaKey
) == 1;
47 bool indexRecords::Load(const string Filename
) /*{{{*/
49 FileFd
Fd(Filename
, FileFd::ReadOnly
);
50 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
51 if (_error
->PendingError() == true)
53 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
57 pkgTagSection Section
;
58 if (TagFile
.Step(Section
) == false)
60 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
64 const char *Start
, *End
;
65 Section
.Get (Start
, End
, 0);
67 Suite
= Section
.FindS("Suite");
68 Dist
= Section
.FindS("Codename");
71 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
73 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
81 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
83 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
84 Sum
->MetaKeyFilename
= Name
;
85 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
92 if(HashString::SupportedHashes()[i
] == NULL
)
94 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
98 string Label
= Section
.FindS("Label");
99 string StrDate
= Section
.FindS("Date");
100 string StrValidUntil
= Section
.FindS("Valid-Until");
102 // if we have a Valid-Until header in the Release file, use it as default
103 if (StrValidUntil
.empty() == false)
105 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
107 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
111 // get the user settings for this archive and use what expires earlier
112 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
113 if (Label
.empty() == true)
114 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
116 if(MaxAge
== 0) // No user settings, use the one from the Release file
120 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
122 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
125 date
+= 24*60*60*MaxAge
;
127 if (ValidUntil
== 0 || ValidUntil
> date
)
133 vector
<string
> indexRecords::MetaKeys() /*{{{*/
135 std::vector
<std::string
> keys
;
136 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
137 while(I
!= Entries
.end()) {
138 keys
.push_back((*I
).first
);
144 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
145 string
&Name
, string
&Hash
, size_t &Size
)
150 /* Skip over the first blank */
151 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
157 /* Move EntryEnd to the end of the first entry (the hash) */
158 const char *EntryEnd
= Start
;
159 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
165 Hash
.append(Start
, EntryEnd
-Start
);
167 /* Skip over intermediate blanks */
169 while (*Start
== '\t' || *Start
== ' ')
175 /* Find the end of the second entry (the size) */
176 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
182 Size
= strtol (Start
, NULL
, 10);
184 /* Skip over intermediate blanks */
186 while (*Start
== '\t' || *Start
== ' ')
192 /* Find the end of the third entry (the filename) */
193 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
197 Name
.append(Start
, EntryEnd
-Start
);
198 Start
= EntryEnd
; //prepare for the next round
202 indexRecords::indexRecords()
206 indexRecords::indexRecords(const string ExpectedDist
) :
207 ExpectedDist(ExpectedDist
), ValidUntil(0)