]> git.saurik.com Git - apt-legacy.git/blame - apt-pkg/deb/debrecords.cc
Fix compilation of http when embedding into Cydia.
[apt-legacy.git] / apt-pkg / deb / debrecords.cc
CommitLineData
da6ee469
JF
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
4/* ######################################################################
5
6 Debian Package Records - Parser for debian package records
7
8 ##################################################################### */
9 /*}}}*/
10// Include Files /*{{{*/
da6ee469 11#include <apt-pkg/debrecords.h>
00ec24d0 12#include <apt-pkg/strutl.h>
da6ee469 13#include <apt-pkg/error.h>
00ec24d0 14#include <langinfo.h>
da6ee469
JF
15 /*}}}*/
16
17// RecordParser::debRecordParser - Constructor /*{{{*/
18// ---------------------------------------------------------------------
19/* */
20debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
21 File(FileName,FileFd::ReadOnly),
22 Tags(&File,Cache.Head().MaxVerFileSize + 200)
23{
24}
25 /*}}}*/
26// RecordParser::Jump - Jump to a specific record /*{{{*/
27// ---------------------------------------------------------------------
28/* */
29bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
30{
31 return Tags.Jump(Section,Ver->Offset);
00ec24d0
JF
32}
33bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
34{
35 return Tags.Jump(Section,Desc->Offset);
da6ee469
JF
36}
37 /*}}}*/
38// RecordParser::FileName - Return the archive filename on the site /*{{{*/
39// ---------------------------------------------------------------------
40/* */
41string debRecordParser::FileName()
42{
43 return Section.FindS("Filename");
44}
45 /*}}}*/
46// RecordParser::Name - Return the package name /*{{{*/
47// ---------------------------------------------------------------------
48/* */
49string debRecordParser::Name()
50{
51 return Section.FindS("Package");
52}
53 /*}}}*/
acdafb44
JF
54// RecordParser::Display - Return the package display name /*{{{*/
55// ---------------------------------------------------------------------
56/* */
57string debRecordParser::Display()
58{
59 string display(Section.FindS("Name"));
60 if (display.empty())
61 display = Section.FindS("Maemo-Display-Name");
62 return display;
63}
64 /*}}}*/
00ec24d0
JF
65// RecordParser::Homepage - Return the package homepage /*{{{*/
66// ---------------------------------------------------------------------
67/* */
68string debRecordParser::Homepage()
69{
70 return Section.FindS("Homepage");
71}
72 /*}}}*/
da6ee469
JF
73// RecordParser::MD5Hash - Return the archive hash /*{{{*/
74// ---------------------------------------------------------------------
75/* */
76string debRecordParser::MD5Hash()
77{
78 return Section.FindS("MD5Sum");
79}
80 /*}}}*/
81// RecordParser::SHA1Hash - Return the archive hash /*{{{*/
82// ---------------------------------------------------------------------
83/* */
84string debRecordParser::SHA1Hash()
85{
00ec24d0
JF
86 return Section.FindS("SHA1");
87}
88 /*}}}*/
89// RecordParser::SHA1Hash - Return the archive hash /*{{{*/
90// ---------------------------------------------------------------------
91/* */
92string debRecordParser::SHA256Hash()
93{
94 return Section.FindS("SHA256");
da6ee469
JF
95}
96 /*}}}*/
97// RecordParser::Maintainer - Return the maintainer email /*{{{*/
98// ---------------------------------------------------------------------
99/* */
100string debRecordParser::Maintainer()
101{
102 return Section.FindS("Maintainer");
103}
104 /*}}}*/
105// RecordParser::ShortDesc - Return a 1 line description /*{{{*/
106// ---------------------------------------------------------------------
107/* */
108string debRecordParser::ShortDesc()
109{
00ec24d0 110 string Res = LongDesc();
da6ee469
JF
111 string::size_type Pos = Res.find('\n');
112 if (Pos == string::npos)
113 return Res;
114 return string(Res,0,Pos);
115}
116 /*}}}*/
117// RecordParser::LongDesc - Return a longer description /*{{{*/
118// ---------------------------------------------------------------------
119/* */
120string debRecordParser::LongDesc()
121{
00ec24d0
JF
122 string orig, dest;
123 char *codeset = nl_langinfo(CODESET);
124
acdafb44
JF
125 orig = Section.FindS("Description");
126 if (orig.empty())
127 orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str());
00ec24d0
JF
128
129 if (strcmp(codeset,"UTF-8") != 0) {
130 UTF8ToCodeset(codeset, orig, &dest);
131 orig = dest;
132 }
133
134 return orig;
da6ee469
JF
135}
136 /*}}}*/
acdafb44
JF
137// RecordParser::ShortDesc - Return a 1 line description /*{{{*/
138// ---------------------------------------------------------------------
139/* */
140bool debRecordParser::ShortDesc(const char *&Start,const char *&End)
141{
142 if (!LongDesc(Start,End))
143 return false;
144 const char *Line = (const char *) memchr(Start, '\n', End - Start);
145 if (Line != NULL)
146 End = Line;
147 return true;
148}
149 /*}}}*/
150// RecordParser::LongDesc - Return a longer description /*{{{*/
151// ---------------------------------------------------------------------
152/* */
153bool debRecordParser::LongDesc(const char *&Start,const char *&End)
154{
155 if (!Section.Find("Description",Start,End))
156 return Section.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(),Start,End);
157 return true;
158}
159 /*}}}*/
00ec24d0
JF
160
161static const char *SourceVerSeparators = " ()";
162
da6ee469
JF
163// RecordParser::SourcePkg - Return the source package name if any /*{{{*/
164// ---------------------------------------------------------------------
165/* */
166string debRecordParser::SourcePkg()
167{
168 string Res = Section.FindS("Source");
00ec24d0 169 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
da6ee469
JF
170 if (Pos == string::npos)
171 return Res;
172 return string(Res,0,Pos);
173}
174 /*}}}*/
00ec24d0
JF
175// RecordParser::SourceVer - Return the source version number if present /*{{{*/
176// ---------------------------------------------------------------------
177/* */
178string debRecordParser::SourceVer()
179{
180 string Pkg = Section.FindS("Source");
181 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
182 if (Pos == string::npos)
183 return "";
184
185 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
186 if(VerStart == string::npos)
187 return "";
188
189 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
190 if(VerEnd == string::npos)
191 // Corresponds to the case of, e.g., "foo (1.2" without a closing
192 // paren. Be liberal and guess what it means.
193 return string(Pkg, VerStart);
194 else
195 return string(Pkg, VerStart, VerEnd - VerStart);
196}
197 /*}}}*/
da6ee469
JF
198// RecordParser::GetRec - Return the whole record /*{{{*/
199// ---------------------------------------------------------------------
200/* */
201void debRecordParser::GetRec(const char *&Start,const char *&Stop)
202{
203 Section.GetSection(Start,Stop);
204}
205 /*}}}*/
acdafb44
JF
206// RecordParser::Find - Locate a tag /*{{{*/
207// ---------------------------------------------------------------------
208/* */
209bool debRecordParser::Find(const char *Tag,const char *&Start, const char *&End)
210{
211 return Section.Find(Tag,Start,End);
212}
213 /*}}}*/