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