pkgrecords.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 *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. 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. #if APT_PKG_ABI >= 413
  58. APT_DEPRECATED std::string MD5Hash() const { return GetHashFromHashes("MD5Sum"); };
  59. APT_DEPRECATED std::string SHA1Hash() const { return GetHashFromHashes("SHA1"); };
  60. APT_DEPRECATED std::string SHA256Hash() const { return GetHashFromHashes("SHA256"); };
  61. APT_DEPRECATED std::string SHA512Hash() const { return GetHashFromHashes("SHA512"); };
  62. #else
  63. APT_DEPRECATED std::string MD5Hash() { return GetHashFromHashes("MD5Sum"); };
  64. APT_DEPRECATED std::string SHA1Hash() { return GetHashFromHashes("SHA1"); };
  65. APT_DEPRECATED std::string SHA256Hash() { return GetHashFromHashes("SHA256"); };
  66. APT_DEPRECATED std::string SHA512Hash() { return GetHashFromHashes("SHA512"); };
  67. #endif
  68. // These are some general stats about the package
  69. virtual std::string Maintainer() {return std::string();};
  70. /** return short description in language from record.
  71. *
  72. * @see #LongDesc
  73. */
  74. virtual std::string ShortDesc(std::string const &/*lang*/) {return std::string();};
  75. /** return long description in language from record.
  76. *
  77. * If \b lang is empty the "best" available language will be
  78. * returned as determined by the APT::Languages configuration.
  79. * If a (requested) language can't be found in this record an empty
  80. * string will be returned.
  81. */
  82. virtual std::string LongDesc(std::string const &/*lang*/) {return std::string();};
  83. std::string ShortDesc() {return ShortDesc("");};
  84. std::string LongDesc() {return LongDesc("");};
  85. virtual std::string Name() {return std::string();};
  86. virtual std::string Homepage() {return std::string();}
  87. // An arbitrary custom field
  88. virtual std::string RecordField(const char * /*fieldName*/) { return std::string();};
  89. // The record in binary form
  90. virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};
  91. Parser();
  92. virtual ~Parser();
  93. private:
  94. void *d;
  95. APT_HIDDEN std::string GetHashFromHashes(char const * const type) const
  96. {
  97. HashStringList const hashes = Hashes();
  98. HashString const * const hs = hashes.find(type);
  99. return hs != NULL ? hs->HashValue() : "";
  100. };
  101. };
  102. /*}}}*/
  103. #endif