]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debrecords.cc
ef6a7ca9d6ac547b8eef67693c792a06b0fe9953
[apt.git] / apt-pkg / deb / debrecords.cc
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 /*{{{*/
11 #include <config.h>
12
13 #include <apt-pkg/debrecords.h>
14 #include <apt-pkg/strutl.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/aptconfiguration.h>
17 #include <langinfo.h>
18 /*}}}*/
19
20 using std::string;
21
22 // RecordParser::debRecordParser - Constructor /*{{{*/
23 // ---------------------------------------------------------------------
24 /* */
25 debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
26 File(FileName,FileFd::ReadOnlyGzip),
27 Tags(&File, std::max(Cache.Head().MaxVerFileSize,
28 Cache.Head().MaxDescFileSize) + 200)
29 {
30 }
31 /*}}}*/
32 // RecordParser::Jump - Jump to a specific record /*{{{*/
33 // ---------------------------------------------------------------------
34 /* */
35 bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
36 {
37 return Tags.Jump(Section,Ver->Offset);
38 }
39 bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
40 {
41 return Tags.Jump(Section,Desc->Offset);
42 }
43 /*}}}*/
44 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
45 // ---------------------------------------------------------------------
46 /* */
47 string debRecordParser::FileName()
48 {
49 return Section.FindS("Filename");
50 }
51 /*}}}*/
52 // RecordParser::Name - Return the package name /*{{{*/
53 // ---------------------------------------------------------------------
54 /* */
55 string debRecordParser::Name()
56 {
57 return Section.FindS("Package");
58 }
59 /*}}}*/
60 // RecordParser::Homepage - Return the package homepage /*{{{*/
61 // ---------------------------------------------------------------------
62 /* */
63 string debRecordParser::Homepage()
64 {
65 return Section.FindS("Homepage");
66 }
67 /*}}}*/
68 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
69 // ---------------------------------------------------------------------
70 /* */
71 string debRecordParser::MD5Hash()
72 {
73 return Section.FindS("MD5Sum");
74 }
75 /*}}}*/
76 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
77 // ---------------------------------------------------------------------
78 /* */
79 string debRecordParser::SHA1Hash()
80 {
81 return Section.FindS("SHA1");
82 }
83 /*}}}*/
84 // RecordParser::SHA256Hash - Return the archive hash /*{{{*/
85 // ---------------------------------------------------------------------
86 /* */
87 string debRecordParser::SHA256Hash()
88 {
89 return Section.FindS("SHA256");
90 }
91 /*}}}*/
92 // RecordParser::SHA512Hash - Return the archive hash /*{{{*/
93 // ---------------------------------------------------------------------
94 /* */
95 string debRecordParser::SHA512Hash()
96 {
97 return Section.FindS("SHA512");
98 }
99 /*}}}*/
100 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
101 // ---------------------------------------------------------------------
102 /* */
103 string debRecordParser::Maintainer()
104 {
105 return Section.FindS("Maintainer");
106 }
107 /*}}}*/
108 // RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
109 // ---------------------------------------------------------------------
110 /* */
111 string debRecordParser::RecordField(const char *fieldName)
112 {
113 return Section.FindS(fieldName);
114 }
115
116 /*}}}*/
117 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
118 // ---------------------------------------------------------------------
119 /* */
120 string debRecordParser::ShortDesc()
121 {
122 string Res = LongDesc();
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 /* */
132 string debRecordParser::LongDesc()
133 {
134 string orig, dest;
135
136 if (!Section.FindS("Description").empty())
137 orig = Section.FindS("Description").c_str();
138 else
139 {
140 std::vector<string> const lang = APT::Configuration::getLanguages();
141 for (std::vector<string>::const_iterator l = lang.begin();
142 orig.empty() && l != lang.end(); ++l)
143 orig = Section.FindS(string("Description-").append(*l).c_str());
144 }
145
146 char const * const codeset = nl_langinfo(CODESET);
147 if (strcmp(codeset,"UTF-8") != 0) {
148 UTF8ToCodeset(codeset, orig, &dest);
149 orig = dest;
150 }
151
152 return orig;
153 }
154 /*}}}*/
155
156 static const char *SourceVerSeparators = " ()";
157
158 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
159 // ---------------------------------------------------------------------
160 /* */
161 string debRecordParser::SourcePkg()
162 {
163 string Res = Section.FindS("Source");
164 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
165 if (Pos == string::npos)
166 return Res;
167 return string(Res,0,Pos);
168 }
169 /*}}}*/
170 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
171 // ---------------------------------------------------------------------
172 /* */
173 string 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 /*}}}*/
193 // RecordParser::GetRec - Return the whole record /*{{{*/
194 // ---------------------------------------------------------------------
195 /* */
196 void debRecordParser::GetRec(const char *&Start,const char *&Stop)
197 {
198 Section.GetSection(Start,Stop);
199 }
200 /*}}}*/