pkgrecords.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. ~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 std::string MD5Hash() const { return GetHashFromHashes("MD5Sum"); };
  58. APT_DEPRECATED std::string SHA1Hash() const { return GetHashFromHashes("SHA1"); };
  59. APT_DEPRECATED std::string SHA256Hash() const { return GetHashFromHashes("SHA256"); };
  60. APT_DEPRECATED 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. virtual std::string ShortDesc() {return std::string();};
  64. virtual std::string LongDesc() {return std::string();};
  65. virtual std::string Name() {return std::string();};
  66. virtual std::string Homepage() {return std::string();}
  67. // An arbitrary custom field
  68. virtual std::string RecordField(const char * /*fieldName*/) { return std::string();};
  69. // The record in binary form
  70. virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};
  71. virtual ~Parser() {};
  72. private:
  73. APT_HIDDEN std::string GetHashFromHashes(char const * const type) const
  74. {
  75. HashStringList const hashes = Hashes();
  76. HashString const * const hs = hashes.find(type);
  77. return hs != NULL ? hs->HashValue() : "";
  78. };
  79. };
  80. /*}}}*/
  81. #endif