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