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