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