pkgrecords.h 4.3 KB

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