]> git.saurik.com Git - apt.git/blame - apt-pkg/vendorlist.cc
extent the mmap to be able to handle currently not implemented
[apt.git] / apt-pkg / vendorlist.cc
CommitLineData
b3d44315
MV
1#include <apt-pkg/vendorlist.h>
2#include <apt-pkg/fileutl.h>
3#include <apt-pkg/error.h>
4#include <apti18n.h>
5
6pkgVendorList::~pkgVendorList()
7{
8 for (vector<const Vendor *>::const_iterator I = VendorList.begin();
9 I != VendorList.end(); I++)
10 delete *I;
11}
12
92fcbfc1 13// pkgVendorList::ReadMainList - Read list of known package vendors /*{{{*/
b3d44315
MV
14// ---------------------------------------------------------------------
15/* This also scans a directory of vendor files similar to apt.conf.d
16 which can contain the usual suspects of distribution provided data.
17 The APT config mechanism allows the user to override these in their
18 configuration file. */
19bool pkgVendorList::ReadMainList()
20{
21 Configuration Cnf;
22
23 string CnfFile = _config->FindDir("Dir::Etc::vendorparts");
24 if (FileExists(CnfFile) == true)
25 if (ReadConfigDir(Cnf,CnfFile,true) == false)
26 return false;
27 CnfFile = _config->FindFile("Dir::Etc::vendorlist");
28 if (FileExists(CnfFile) == true)
29 if (ReadConfigFile(Cnf,CnfFile,true) == false)
30 return false;
31
32 return CreateList(Cnf);
33}
92fcbfc1
DK
34 /*}}}*/
35bool pkgVendorList::Read(string File) /*{{{*/
b3d44315
MV
36{
37 Configuration Cnf;
38 if (ReadConfigFile(Cnf,File,true) == false)
39 return false;
40
41 return CreateList(Cnf);
42}
92fcbfc1
DK
43 /*}}}*/
44bool pkgVendorList::CreateList(Configuration& Cnf) /*{{{*/
b3d44315
MV
45{
46 for (vector<const Vendor *>::const_iterator I = VendorList.begin();
47 I != VendorList.end(); I++)
48 delete *I;
49 VendorList.erase(VendorList.begin(),VendorList.end());
50
51 const Configuration::Item *Top = Cnf.Tree("Vendor");
52 for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
53 {
54 Configuration Block(Top);
55 string VendorID = Top->Tag;
56 vector <struct Vendor::Fingerprint *> *Fingerprints = new vector<Vendor::Fingerprint *>;
57 struct Vendor::Fingerprint *Fingerprint = new struct Vendor::Fingerprint;
58 string Origin = Block.Find("Origin");
59
60 Fingerprint->Print = Block.Find("Fingerprint");
61 Fingerprint->Description = Block.Find("Name");
62 Fingerprints->push_back(Fingerprint);
63
64 if (Fingerprint->Print.empty() || Fingerprint->Description.empty())
65 {
66 _error->Error(_("Vendor block %s contains no fingerprint"), VendorID.c_str());
67 delete Fingerprints;
68 continue;
69 }
70 if (_config->FindB("Debug::sourceList", false))
71 std::cerr << "Adding vendor with ID: " << VendorID
72 << " Fingerprint: " << Fingerprint->Print << std::endl;
73
74 VendorList.push_back(new Vendor(VendorID, Origin, Fingerprints));
75 }
76
77 /* Process 'group-key' type sections */
78 Top = Cnf.Tree("group-key");
79 for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
80 {
81// Configuration Block(Top);
82// vector<Vendor::Fingerprint *> Fingerprints;
83// string VendorID = Top->Tag;
84
85// while (Block->Next)
86// {
87// struct Vendor::Fingerprint Fingerprint = new struct Vendor::Fingerprint;
88// Fingerprint->Print = Block.Find("Fingerprint");
89// Fingerprint->Description = Block.Find("Name");
90// if (Fingerprint->print.empty() || Fingerprint->Description.empty())
91// {
92// _error->Error(_("Vendor block %s is invalid"),
93// Vendor->VendorID.c_str());
94// delete Fingerprint;
95// break;
96// }
97// Block = Block->Next->Next;
98// }
99// if (_error->PendingError())
100// {
101// for (vector <struct Vendor::Fingerprint *>::iterator I = Fingerprints.begin();
102// I != Fingerprints.end(); I++)
103// delete *I;
104// delete Fingerprints;
105// continue;
106// }
107
108// VendorList.push_back(new Vendor(VendorID, Fingerprints));
109 }
110
111 return !_error->PendingError();
112}
92fcbfc1
DK
113 /*}}}*/
114const Vendor* pkgVendorList::LookupFingerprint(string Fingerprint) /*{{{*/
b3d44315 115{
61ec2779 116 for (const_iterator I = VendorList.begin(); I != VendorList.end(); ++I)
b3d44315
MV
117 {
118 if ((*I)->LookupFingerprint(Fingerprint) != "")
119 return *I;
120 }
121
122 return NULL;
123}
92fcbfc1
DK
124 /*}}}*/
125const Vendor* pkgVendorList::FindVendor(const std::vector<string> GPGVOutput) /*{{{*/
b3d44315
MV
126{
127 for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); I++)
128 {
129 string::size_type pos = (*I).find("VALIDSIG ");
130 if (_config->FindB("Debug::Vendor", false))
131 std::cerr << "Looking for VALIDSIG in \"" << (*I) << "\": pos " << pos << std::endl;
132 if (pos != std::string::npos)
133 {
134 string Fingerprint = (*I).substr(pos+sizeof("VALIDSIG"));
135 if (_config->FindB("Debug::Vendor", false))
136 std::cerr << "Looking for \"" << Fingerprint << "\" in vendor..." << std::endl;
137 const Vendor* vendor = this->LookupFingerprint(Fingerprint);
138 if (vendor != NULL)
139 return vendor;
140 }
141 }
142
143 return NULL;
144}
92fcbfc1 145 /*}}}*/