]>
git.saurik.com Git - apt.git/blob - apt-pkg/sourcelist.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: sourcelist.cc,v 1.19 2001/03/13 06:51:46 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>
26 // Global list of Item supported
27 static pkgSourceList::Type
*ItmList
[10];
28 pkgSourceList::Type
**pkgSourceList::Type::GlobalList
= ItmList
;
29 unsigned long pkgSourceList::Type::GlobalListLen
= 0;
31 // Type::Type - Constructor /*{{{*/
32 // ---------------------------------------------------------------------
33 /* Link this to the global list of items*/
34 pkgSourceList::Type::Type()
36 ItmList
[GlobalListLen
] = this;
40 // Type::GetType - Get a specific meta for a given type /*{{{*/
41 // ---------------------------------------------------------------------
43 pkgSourceList::Type
*pkgSourceList::Type::GetType(const char *Type
)
45 for (unsigned I
= 0; I
!= GlobalListLen
; I
++)
46 if (strcmp(GlobalList
[I
]->Name
,Type
) == 0)
51 // Type::FixupURI - Normalize the URI and check it.. /*{{{*/
52 // ---------------------------------------------------------------------
54 bool pkgSourceList::Type::FixupURI(string
&URI
) const
56 if (URI
.empty() == true)
59 if (URI
.find(':') == string::npos
)
62 URI
= SubstVar(URI
,"$(ARCH)",_config
->Find("APT::Architecture"));
64 // Make sure that the URI is / postfixed
65 if (URI
[URI
.size() - 1] != '/')
71 // Type::ParseLine - Parse a single line /*{{{*/
72 // ---------------------------------------------------------------------
73 /* This is a generic one that is the 'usual' format for sources.list
74 Weird types may override this. */
75 bool pkgSourceList::Type::ParseLine(vector
<pkgIndexFile
*> &List
,
78 unsigned long CurLine
,
85 if (ParseQuoteWord(Buffer
,URI
) == false)
86 return _error
->Error(_("Malformed line %lu in source list %s (URI)"),CurLine
,File
.c_str());
87 if (ParseQuoteWord(Buffer
,Dist
) == false)
88 return _error
->Error(_("Malformed line %lu in source list %s (dist)"),CurLine
,File
.c_str());
90 if (FixupURI(URI
) == false)
91 return _error
->Error(_("Malformed line %lu in source list %s (URI parse)"),CurLine
,File
.c_str());
93 // Check for an absolute dists specification.
94 if (Dist
.empty() == false && Dist
[Dist
.size() - 1] == '/')
96 if (ParseQuoteWord(Buffer
,Section
) == true)
97 return _error
->Error(_("Malformed line %lu in source list %s (Absolute dist)"),CurLine
,File
.c_str());
98 Dist
= SubstVar(Dist
,"$(ARCH)",_config
->Find("APT::Architecture"));
99 return CreateItem(List
,URI
,Dist
,Section
,Vendor
);
102 // Grab the rest of the dists
103 if (ParseQuoteWord(Buffer
,Section
) == false)
104 return _error
->Error(_("Malformed line %lu in source list %s (dist parse)"),CurLine
,File
.c_str());
108 if (CreateItem(List
,URI
,Dist
,Section
,Vendor
) == false)
111 while (ParseQuoteWord(Buffer
,Section
) == true);
117 // SourceList::pkgSourceList - Constructors /*{{{*/
118 // ---------------------------------------------------------------------
120 pkgSourceList::pkgSourceList()
124 pkgSourceList::pkgSourceList(string File
)
129 // SourceList::ReadVendors - Read list of known package vendors /*{{{*/
130 // ---------------------------------------------------------------------
131 /* This also scans a directory of vendor files similar to apt.conf.d
132 which can contain the usual suspects of distribution provided data.
133 The APT config mechanism allows the user to override these in their
134 configuration file. */
135 bool pkgSourceList::ReadVendors()
139 string CnfFile
= _config
->FindDir("Dir::Etc::vendorparts");
140 if (FileExists(CnfFile
) == true)
141 if (ReadConfigDir(Cnf
,CnfFile
,true) == false)
143 CnfFile
= _config
->FindFile("Dir::Etc::vendorlist");
144 if (FileExists(CnfFile
) == true)
145 if (ReadConfigFile(Cnf
,CnfFile
,true) == false)
148 // Process 'simple-key' type sections
149 const Configuration::Item
*Top
= Cnf
.Tree("simple-key");
150 for (Top
= (Top
== 0?0:Top
->Child
); Top
!= 0; Top
= Top
->Next
)
152 Configuration
Block(Top
);
155 Vendor
= new pkgSourceList::Vendor
;
157 Vendor
->VendorID
= Top
->Tag
;
158 Vendor
->FingerPrint
= Block
.Find("Fingerprint");
159 Vendor
->Description
= Block
.Find("Name");
161 if (Vendor
->FingerPrint
.empty() == true ||
162 Vendor
->Description
.empty() == true)
164 _error
->Error(_("Vendor block %s is invalid"), Vendor
->VendorID
.c_str());
169 VendorList
.push_back(Vendor
);
172 return !_error
->PendingError();
175 // SourceList::ReadMainList - Read the main source list from etc /*{{{*/
176 // ---------------------------------------------------------------------
178 bool pkgSourceList::ReadMainList()
180 return ReadVendors() && Read(_config
->FindFile("Dir::Etc::sourcelist"));
183 // SourceList::Read - Parse the sourcelist file /*{{{*/
184 // ---------------------------------------------------------------------
186 bool pkgSourceList::Read(string File
)
188 // Open the stream for reading
189 ifstream
F(File
.c_str(),ios::in
| ios::nocreate
);
191 return _error
->Errno("ifstream::ifstream",_("Opening %s"),File
.c_str());
193 SrcList
.erase(SrcList
.begin(),SrcList
.end());
197 while (F
.eof() == false)
199 F
.getline(Buffer
,sizeof(Buffer
));
201 _strtabexpand(Buffer
,sizeof(Buffer
));
205 for (I
= Buffer
; *I
!= 0 && *I
!= '#'; I
++);
208 const char *C
= _strstrip(Buffer
);
211 if (C
[0] == '#' || C
[0] == 0)
216 if (ParseQuoteWord(C
,LineType
) == false)
217 return _error
->Error(_("Malformed line %u in source list %s (type)"),CurLine
,File
.c_str());
219 Type
*Parse
= Type::GetType(LineType
.c_str());
221 return _error
->Error(_("Type '%s' is not known in on line %u in source list %s"),LineType
.c_str(),CurLine
,File
.c_str());
223 // Authenticated repository
224 Vendor
const *Vndr
= 0;
229 if (ParseQuoteWord(C
,VendorID
) == false)
230 return _error
->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine
,File
.c_str());
232 if (VendorID
.length() < 2 || VendorID
.end()[-1] != ']')
233 return _error
->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine
,File
.c_str());
234 VendorID
= string(VendorID
,1,VendorID
.size()-2);
236 for (vector
<Vendor
const *>::const_iterator iter
= VendorList
.begin();
237 iter
!= VendorList
.end(); iter
++)
239 if ((*iter
)->VendorID
== VendorID
)
247 return _error
->Error(_("Unknown vendor ID '%s' in line %u of source list %s"),
248 VendorID
.c_str(),CurLine
,File
.c_str());
251 if (Parse
->ParseLine(SrcList
,Vndr
,C
,CurLine
,File
) == false)
257 // SourceList::FindIndex - Get the index associated with a file /*{{{*/
258 // ---------------------------------------------------------------------
260 bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File
,
261 pkgIndexFile
*&Found
) const
263 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
265 if ((*I
)->FindInCache(*File
.Cache()) == File
)
275 // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/
276 // ---------------------------------------------------------------------
278 bool pkgSourceList::GetIndexes(pkgAcquire
*Owner
) const
280 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
281 if ((*I
)->GetIndexes(Owner
) == false)