1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/* apt-sourceslist.h - access the sources.list file
*
* Copyright (c) 1999 Patrick Cole <z@amused.net>
* (c) 2002 Synaptic development team
* (c) 2018-2025 Matthias Klumpp <matthias@tenstral.net>
*
* Author: Patrick Cole <z@amused.net>
* Michael Vogt <mvo@debian.org>
* Gustavo Niemeyer <niemeyer@conectiva.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef APT_SOURCESLIST_H
#define APT_SOURCESLIST_H
#include <apt-pkg/fileutl.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/metaindex.h>
#include <string>
#include <list>
using namespace std;
class SourcesList
{
public:
enum RecType {
Deb = 1 << 0,
DebSrc = 1 << 1,
Disabled = 1 << 2,
Comment = 1 << 3,
};
struct SourceRecord {
unsigned int Type;
string VendorID;
string PrimaryURI;
std::vector<std::string> URIs;
string Dist;
string *Sections;
unsigned short NumSections;
string Comment;
string SourceFile;
uint Deb822StanzaIdx;
string joinedSections(const std::string &separator = " ");
string niceName();
string repoId();
bool hasSection(const char *component);
bool SetType(string);
string GetType();
bool SetURI(string);
bool SetURIs(const std::vector<std::string> &newURIs);
SourceRecord()
: Type(0),
Sections(0),
NumSections(0),
Deb822StanzaIdx(0)
{
}
~SourceRecord()
{
if (Sections) {
delete[] Sections;
}
}
SourceRecord &operator=(const SourceRecord &);
};
struct VendorRecord {
string VendorID;
string FingerPrint;
string Description;
};
list<SourceRecord *> SourceRecords;
list<VendorRecord *> VendorRecords;
private:
SourceRecord *AddSourceNode(SourceRecord &);
VendorRecord *AddVendorNode(VendorRecord &);
bool OpenConfigurationFileFd(std::string const &File, FileFd &Fd);
bool ParseDeb822Stanza(const char *Type, pkgTagSection &Tags, unsigned int const stanzaIdx, FileFd &Fd);
bool UpdateSourceLegacy(const std::string &filename);
bool UpdateSourceDeb822(const std::string &filename);
public:
SourceRecord *AddSource(
RecType Type,
string VendorID,
string URI,
string Dist,
string *Sections,
unsigned short count,
string SourceFile);
SourceRecord *AddEmptySource();
void RemoveSource(SourceRecord *&);
void SwapSources(SourceRecord *&, SourceRecord *&);
bool ReadSourceDeb822(string listpath);
bool ReadSourceLegacy(string listpath);
bool ReadSourcePart(string listpath);
bool ReadSourceDir(string Dir);
bool ReadSources();
bool UpdateSources();
VendorRecord *AddVendor(string VendorID, string FingerPrint, string Description);
void RemoveVendor(VendorRecord *&);
bool ReadVendors();
bool UpdateVendors();
SourcesList() {}
~SourcesList();
};
typedef list<SourcesList::SourceRecord *>::iterator SourcesListIter;
ostream &operator<<(ostream &, const SourcesList::SourceRecord &);
ostream &operator<<(ostream &os, const SourcesList::VendorRecord &rec);
#endif
|