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