]>
git.saurik.com Git - apt.git/blob - apt-pkg/sourcelist.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: sourcelist.cc,v 1.24 2002/07/08 04:18:07 jgg Exp $
4 /* ######################################################################
8 ##################################################################### */
10 // Include Files /*{{{*/
12 #pragma implementation "apt-pkg/sourcelist.h"
15 #include <apt-pkg/sourcelist.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/fileutl.h>
18 #include <apt-pkg/configuration.h>
19 #include <apt-pkg/strutl.h>
28 // Global list of Items supported
29 static pkgSourceList::Type
*ItmList
[10];
30 pkgSourceList::Type
**pkgSourceList::Type::GlobalList
= ItmList
;
31 unsigned long pkgSourceList::Type::GlobalListLen
= 0;
33 // Type::Type - Constructor /*{{{*/
34 // ---------------------------------------------------------------------
35 /* Link this to the global list of items*/
36 pkgSourceList::Type::Type()
38 ItmList
[GlobalListLen
] = this;
42 // Type::GetType - Get a specific meta for a given type /*{{{*/
43 // ---------------------------------------------------------------------
45 pkgSourceList::Type
*pkgSourceList::Type::GetType(const char *Type
)
47 for (unsigned I
= 0; I
!= GlobalListLen
; I
++)
48 if (strcmp(GlobalList
[I
]->Name
,Type
) == 0)
53 // Type::FixupURI - Normalize the URI and check it.. /*{{{*/
54 // ---------------------------------------------------------------------
56 bool pkgSourceList::Type::FixupURI(string
&URI
) const
58 if (URI
.empty() == true)
61 if (URI
.find(':') == string::npos
)
64 URI
= SubstVar(URI
,"$(ARCH)",_config
->Find("APT::Architecture"));
66 // Make sure that the URI is / postfixed
67 if (URI
[URI
.size() - 1] != '/')
73 // Type::ParseLine - Parse a single line /*{{{*/
74 // ---------------------------------------------------------------------
75 /* This is a generic one that is the 'usual' format for sources.list
76 Weird types may override this. */
77 bool pkgSourceList::Type::ParseLine(vector
<pkgIndexFile
*> &List
,
80 unsigned long CurLine
,
87 if (ParseQuoteWord(Buffer
,URI
) == false)
88 return _error
->Error(_("Malformed line %lu in source list %s (URI)"),CurLine
,File
.c_str());
89 if (ParseQuoteWord(Buffer
,Dist
) == false)
90 return _error
->Error(_("Malformed line %lu in source list %s (dist)"),CurLine
,File
.c_str());
92 if (FixupURI(URI
) == false)
93 return _error
->Error(_("Malformed line %lu in source list %s (URI parse)"),CurLine
,File
.c_str());
95 // Check for an absolute dists specification.
96 if (Dist
.empty() == false && Dist
[Dist
.size() - 1] == '/')
98 if (ParseQuoteWord(Buffer
,Section
) == true)
99 return _error
->Error(_("Malformed line %lu in source list %s (Absolute dist)"),CurLine
,File
.c_str());
100 Dist
= SubstVar(Dist
,"$(ARCH)",_config
->Find("APT::Architecture"));
101 return CreateItem(List
,URI
,Dist
,Section
,Vendor
);
104 // Grab the rest of the dists
105 if (ParseQuoteWord(Buffer
,Section
) == false)
106 return _error
->Error(_("Malformed line %lu in source list %s (dist parse)"),CurLine
,File
.c_str());
110 if (CreateItem(List
,URI
,Dist
,Section
,Vendor
) == false)
113 while (ParseQuoteWord(Buffer
,Section
) == true);
119 // SourceList::pkgSourceList - Constructors /*{{{*/
120 // ---------------------------------------------------------------------
122 pkgSourceList::pkgSourceList()
126 pkgSourceList::pkgSourceList(string File
)
131 // SourceList::~pkgSourceList - Destructor /*{{{*/
132 // ---------------------------------------------------------------------
134 pkgSourceList::~pkgSourceList()
136 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
138 for (vector
<Vendor
const *>::const_iterator I
= VendorList
.begin();
139 I
!= VendorList
.end(); I
++)
143 // SourceList::ReadVendors - Read list of known package vendors /*{{{*/
144 // ---------------------------------------------------------------------
145 /* This also scans a directory of vendor files similar to apt.conf.d
146 which can contain the usual suspects of distribution provided data.
147 The APT config mechanism allows the user to override these in their
148 configuration file. */
149 bool pkgSourceList::ReadVendors()
153 string CnfFile
= _config
->FindDir("Dir::Etc::vendorparts");
154 if (FileExists(CnfFile
) == true)
155 if (ReadConfigDir(Cnf
,CnfFile
,true) == false)
157 CnfFile
= _config
->FindFile("Dir::Etc::vendorlist");
158 if (FileExists(CnfFile
) == true)
159 if (ReadConfigFile(Cnf
,CnfFile
,true) == false)
162 for (vector
<Vendor
const *>::const_iterator I
= VendorList
.begin();
163 I
!= VendorList
.end(); I
++)
165 VendorList
.erase(VendorList
.begin(),VendorList
.end());
167 // Process 'simple-key' type sections
168 const Configuration::Item
*Top
= Cnf
.Tree("simple-key");
169 for (Top
= (Top
== 0?0:Top
->Child
); Top
!= 0; Top
= Top
->Next
)
171 Configuration
Block(Top
);
174 Vendor
= new pkgSourceList::Vendor
;
176 Vendor
->VendorID
= Top
->Tag
;
177 Vendor
->FingerPrint
= Block
.Find("Fingerprint");
178 Vendor
->Description
= Block
.Find("Name");
180 if (Vendor
->FingerPrint
.empty() == true ||
181 Vendor
->Description
.empty() == true)
183 _error
->Error(_("Vendor block %s is invalid"), Vendor
->VendorID
.c_str());
188 VendorList
.push_back(Vendor
);
191 /* XXX Process 'group-key' type sections
192 This is currently faked out so that the vendors file format is
193 parsed but nothing is done with it except check for validity */
194 Top
= Cnf
.Tree("group-key");
195 for (Top
= (Top
== 0?0:Top
->Child
); Top
!= 0; Top
= Top
->Next
)
197 Configuration
Block(Top
);
200 Vendor
= new pkgSourceList::Vendor
;
202 Vendor
->VendorID
= Top
->Tag
;
203 Vendor
->Description
= Block
.Find("Name");
205 if (Vendor
->Description
.empty() == true)
207 _error
->Error(_("Vendor block %s is invalid"),
208 Vendor
->VendorID
.c_str());
213 VendorList
.push_back(Vendor
);
216 return !_error
->PendingError();
219 // SourceList::ReadMainList - Read the main source list from etc /*{{{*/
220 // ---------------------------------------------------------------------
222 bool pkgSourceList::ReadMainList()
224 return ReadVendors() && Read(_config
->FindFile("Dir::Etc::sourcelist"));
227 // SourceList::Read - Parse the sourcelist file /*{{{*/
228 // ---------------------------------------------------------------------
230 bool pkgSourceList::Read(string File
)
232 // Open the stream for reading
233 ifstream
F(File
.c_str(),ios::in
/*| ios::nocreate*/);
235 return _error
->Errno("ifstream::ifstream",_("Opening %s"),File
.c_str());
237 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
239 SrcList
.erase(SrcList
.begin(),SrcList
.end());
243 while (F
.eof() == false)
245 F
.getline(Buffer
,sizeof(Buffer
));
247 _strtabexpand(Buffer
,sizeof(Buffer
));
248 if (F
.fail() && !F
.eof())
249 return _error
->Error(_("Line %u too long in source list %s."),
250 CurLine
,File
.c_str());
254 for (I
= Buffer
; *I
!= 0 && *I
!= '#'; I
++);
257 const char *C
= _strstrip(Buffer
);
260 if (C
[0] == '#' || C
[0] == 0)
265 if (ParseQuoteWord(C
,LineType
) == false)
266 return _error
->Error(_("Malformed line %u in source list %s (type)"),CurLine
,File
.c_str());
268 Type
*Parse
= Type::GetType(LineType
.c_str());
270 return _error
->Error(_("Type '%s' is not known in on line %u in source list %s"),LineType
.c_str(),CurLine
,File
.c_str());
272 // Authenticated repository
273 Vendor
const *Vndr
= 0;
278 if (ParseQuoteWord(C
,VendorID
) == false)
279 return _error
->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine
,File
.c_str());
281 if (VendorID
.length() < 2 || VendorID
.end()[-1] != ']')
282 return _error
->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine
,File
.c_str());
283 VendorID
= string(VendorID
,1,VendorID
.size()-2);
285 for (vector
<Vendor
const *>::const_iterator iter
= VendorList
.begin();
286 iter
!= VendorList
.end(); iter
++)
288 if ((*iter
)->VendorID
== VendorID
)
296 return _error
->Error(_("Unknown vendor ID '%s' in line %u of source list %s"),
297 VendorID
.c_str(),CurLine
,File
.c_str());
300 if (Parse
->ParseLine(SrcList
,Vndr
,C
,CurLine
,File
) == false)
306 // SourceList::FindIndex - Get the index associated with a file /*{{{*/
307 // ---------------------------------------------------------------------
309 bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File
,
310 pkgIndexFile
*&Found
) const
312 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
314 if ((*I
)->FindInCache(*File
.Cache()) == File
)
324 // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/
325 // ---------------------------------------------------------------------
327 bool pkgSourceList::GetIndexes(pkgAcquire
*Owner
) const
329 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
330 if ((*I
)->GetIndexes(Owner
) == false)