do not pollute namespace in the headers with using (Closes: #500198)
[ntk/apt.git] / apt-pkg / deb / debrecords.cc
CommitLineData
f55ece0e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
a7c835af 3// $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
f55ece0e
AL
4/* ######################################################################
5
6 Debian Package Records - Parser for debian package records
7
8 ##################################################################### */
9 /*}}}*/
10// Include Files /*{{{*/
ea542140
DK
11#include <config.h>
12
f55ece0e 13#include <apt-pkg/debrecords.h>
a52f938b 14#include <apt-pkg/strutl.h>
f55ece0e 15#include <apt-pkg/error.h>
45df0ad2 16#include <apt-pkg/aptconfiguration.h>
a52f938b 17#include <langinfo.h>
f55ece0e
AL
18 /*}}}*/
19
8f3ba4e8
DK
20using std::string;
21
f55ece0e
AL
22// RecordParser::debRecordParser - Constructor /*{{{*/
23// ---------------------------------------------------------------------
24/* */
b2e465d6 25debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
c4fc2fd7 26 File(FileName,FileFd::ReadOnlyGzip),
63b528a4
MV
27 Tags(&File, std::max(Cache.Head().MaxVerFileSize,
28 Cache.Head().MaxDescFileSize) + 200)
f55ece0e
AL
29{
30}
31 /*}}}*/
32// RecordParser::Jump - Jump to a specific record /*{{{*/
33// ---------------------------------------------------------------------
34/* */
03e39e59 35bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
f55ece0e
AL
36{
37 return Tags.Jump(Section,Ver->Offset);
a52f938b
OS
38}
39bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
40{
41 return Tags.Jump(Section,Desc->Offset);
f55ece0e
AL
42}
43 /*}}}*/
7e798dd7
AL
44// RecordParser::FileName - Return the archive filename on the site /*{{{*/
45// ---------------------------------------------------------------------
46/* */
47string debRecordParser::FileName()
48{
7974b907 49 return Section.FindS("Filename");
7e798dd7
AL
50}
51 /*}}}*/
b2e465d6
AL
52// RecordParser::Name - Return the package name /*{{{*/
53// ---------------------------------------------------------------------
54/* */
55string debRecordParser::Name()
56{
57 return Section.FindS("Package");
58}
59 /*}}}*/
f27b4a70
OS
60// RecordParser::Homepage - Return the package homepage /*{{{*/
61// ---------------------------------------------------------------------
62/* */
63string debRecordParser::Homepage()
64{
65 return Section.FindS("Homepage");
66}
67 /*}}}*/
7e798dd7
AL
68// RecordParser::MD5Hash - Return the archive hash /*{{{*/
69// ---------------------------------------------------------------------
70/* */
71string debRecordParser::MD5Hash()
72{
a7c835af
AL
73 return Section.FindS("MD5Sum");
74}
75 /*}}}*/
76// RecordParser::SHA1Hash - Return the archive hash /*{{{*/
77// ---------------------------------------------------------------------
78/* */
79string debRecordParser::SHA1Hash()
80{
59b46c41 81 return Section.FindS("SHA1");
7e798dd7
AL
82}
83 /*}}}*/
d9b9e9e2 84// RecordParser::SHA256Hash - Return the archive hash /*{{{*/
495e5cb2
MV
85// ---------------------------------------------------------------------
86/* */
87string debRecordParser::SHA256Hash()
88{
89 return Section.FindS("SHA256");
90}
91 /*}}}*/
d9b9e9e2
MV
92// RecordParser::SHA512Hash - Return the archive hash /*{{{*/
93// ---------------------------------------------------------------------
94/* */
95string debRecordParser::SHA512Hash()
96{
97 return Section.FindS("SHA512");
98}
99 /*}}}*/
7e798dd7
AL
100// RecordParser::Maintainer - Return the maintainer email /*{{{*/
101// ---------------------------------------------------------------------
102/* */
103string debRecordParser::Maintainer()
104{
7974b907 105 return Section.FindS("Maintainer");
7e798dd7
AL
106}
107 /*}}}*/
75bda619
MV
108// RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
109// ---------------------------------------------------------------------
110/* */
111string debRecordParser::RecordField(const char *fieldName)
112{
113 return Section.FindS(fieldName);
114}
115
116 /*}}}*/
7e798dd7
AL
117// RecordParser::ShortDesc - Return a 1 line description /*{{{*/
118// ---------------------------------------------------------------------
119/* */
120string debRecordParser::ShortDesc()
121{
a52f938b 122 string Res = LongDesc();
7e798dd7
AL
123 string::size_type Pos = Res.find('\n');
124 if (Pos == string::npos)
125 return Res;
126 return string(Res,0,Pos);
127}
128 /*}}}*/
129// RecordParser::LongDesc - Return a longer description /*{{{*/
130// ---------------------------------------------------------------------
131/* */
132string debRecordParser::LongDesc()
133{
a52f938b 134 string orig, dest;
a52f938b
OS
135
136 if (!Section.FindS("Description").empty())
137 orig = Section.FindS("Description").c_str();
45df0ad2
DK
138 else
139 {
8f3ba4e8
DK
140 std::vector<string> const lang = APT::Configuration::getLanguages();
141 for (std::vector<string>::const_iterator l = lang.begin();
f7f0d6c7 142 orig.empty() && l != lang.end(); ++l)
45df0ad2
DK
143 orig = Section.FindS(string("Description-").append(*l).c_str());
144 }
a52f938b 145
45df0ad2 146 char const * const codeset = nl_langinfo(CODESET);
a52f938b
OS
147 if (strcmp(codeset,"UTF-8") != 0) {
148 UTF8ToCodeset(codeset, orig, &dest);
149 orig = dest;
150 }
151
152 return orig;
7e798dd7
AL
153}
154 /*}}}*/
c2f2b862
MV
155
156static const char *SourceVerSeparators = " ()";
157
04f232fc 158// RecordParser::SourcePkg - Return the source package name if any /*{{{*/
36375005
AL
159// ---------------------------------------------------------------------
160/* */
161string debRecordParser::SourcePkg()
162{
04f232fc 163 string Res = Section.FindS("Source");
c2f2b862 164 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
04f232fc
AL
165 if (Pos == string::npos)
166 return Res;
167 return string(Res,0,Pos);
36375005
AL
168}
169 /*}}}*/
c2f2b862
MV
170// RecordParser::SourceVer - Return the source version number if present /*{{{*/
171// ---------------------------------------------------------------------
172/* */
173string debRecordParser::SourceVer()
174{
175 string Pkg = Section.FindS("Source");
176 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
177 if (Pos == string::npos)
178 return "";
179
180 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
181 if(VerStart == string::npos)
182 return "";
183
184 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
185 if(VerEnd == string::npos)
186 // Corresponds to the case of, e.g., "foo (1.2" without a closing
187 // paren. Be liberal and guess what it means.
188 return string(Pkg, VerStart);
189 else
190 return string(Pkg, VerStart, VerEnd - VerStart);
191}
192 /*}}}*/
b2e465d6
AL
193// RecordParser::GetRec - Return the whole record /*{{{*/
194// ---------------------------------------------------------------------
195/* */
196void debRecordParser::GetRec(const char *&Start,const char *&Stop)
197{
198 Section.GetSection(Start,Stop);
199}
200 /*}}}*/