]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgrecords.h
restore ABI of pkgTagSection
[apt.git] / apt-pkg / pkgrecords.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgrecords.h,v 1.6 2001/03/13 06:51:46 jgg Exp $
4 /* ######################################################################
5
6 Package Records - Allows access to complete package description records
7 directly from the file.
8
9 The package record system abstracts the actual parsing of the
10 package files. This is different than the generators parser in that
11 it is used to access information not generate information. No
12 information touched by the generator should be parable from here as
13 it can always be retreived directly from the cache.
14
15 ##################################################################### */
16 /*}}}*/
17 #ifndef PKGLIB_PKGRECORDS_H
18 #define PKGLIB_PKGRECORDS_H
19
20 #include <apt-pkg/pkgcache.h>
21 #include <apt-pkg/hashes.h>
22 #include <apt-pkg/macros.h>
23
24 #include <string>
25 #include <vector>
26
27 class pkgRecords /*{{{*/
28 {
29 public:
30 class Parser;
31
32 private:
33 /** \brief dpointer placeholder (for later in case we need it) */
34 void *d;
35
36 pkgCache &Cache;
37 std::vector<Parser *>Files;
38
39 public:
40 // Lookup function
41 Parser &Lookup(pkgCache::VerFileIterator const &Ver);
42 Parser &Lookup(pkgCache::DescFileIterator const &Desc);
43
44 // Construct destruct
45 pkgRecords(pkgCache &Cache);
46 ~pkgRecords();
47 };
48 /*}}}*/
49 class pkgRecords::Parser /*{{{*/
50 {
51 protected:
52
53 virtual bool Jump(pkgCache::VerFileIterator const &Ver) = 0;
54 virtual bool Jump(pkgCache::DescFileIterator const &Desc) = 0;
55
56 public:
57 friend class pkgRecords;
58
59 // These refer to the archive file for the Version
60 virtual std::string FileName() {return std::string();};
61 virtual std::string SourcePkg() {return std::string();};
62 virtual std::string SourceVer() {return std::string();};
63
64 /** return all known hashes in this record.
65 *
66 * For authentication proposes packages come with hashsums which
67 * this method is supposed to parse and return so that clients can
68 * choose the hash to be used.
69 */
70 virtual HashStringList Hashes() const { return HashStringList(); };
71 #if APT_PKG_ABI >= 413
72 APT_DEPRECATED std::string MD5Hash() const { return GetHashFromHashes("MD5Sum"); };
73 APT_DEPRECATED std::string SHA1Hash() const { return GetHashFromHashes("SHA1"); };
74 APT_DEPRECATED std::string SHA256Hash() const { return GetHashFromHashes("SHA256"); };
75 APT_DEPRECATED std::string SHA512Hash() const { return GetHashFromHashes("SHA512"); };
76 #else
77 APT_DEPRECATED std::string MD5Hash() { return GetHashFromHashes("MD5Sum"); };
78 APT_DEPRECATED std::string SHA1Hash() { return GetHashFromHashes("SHA1"); };
79 APT_DEPRECATED std::string SHA256Hash() { return GetHashFromHashes("SHA256"); };
80 APT_DEPRECATED std::string SHA512Hash() { return GetHashFromHashes("SHA512"); };
81 #endif
82
83 // These are some general stats about the package
84 virtual std::string Maintainer() {return std::string();};
85 /** return short description in language from record.
86 *
87 * @see #LongDesc
88 */
89 virtual std::string ShortDesc(std::string const &/*lang*/) {return std::string();};
90 /** return long description in language from record.
91 *
92 * If \b lang is empty the "best" available language will be
93 * returned as determined by the APT::Languages configuration.
94 * If a (requested) language can't be found in this record an empty
95 * string will be returned.
96 */
97 virtual std::string LongDesc(std::string const &/*lang*/) {return std::string();};
98 std::string ShortDesc() {return ShortDesc("");};
99 std::string LongDesc() {return LongDesc("");};
100
101 virtual std::string Name() {return std::string();};
102 virtual std::string Homepage() {return std::string();}
103
104 // An arbitrary custom field
105 virtual std::string RecordField(const char * /*fieldName*/) { return std::string();};
106
107 // The record in binary form
108 virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};
109
110 virtual ~Parser() {};
111
112 private:
113 APT_HIDDEN std::string GetHashFromHashes(char const * const type) const
114 {
115 HashStringList const hashes = Hashes();
116 HashString const * const hs = hashes.find(type);
117 return hs != NULL ? hs->HashValue() : "";
118 };
119 };
120 /*}}}*/
121 #endif