srcrecords.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Source Package Records - Allows access to source package records
  5. Parses and allows access to the list of source records and searching by
  6. source name on that list.
  7. ##################################################################### */
  8. /*}}}*/
  9. #ifndef PKGLIB_SRCRECORDS_H
  10. #define PKGLIB_SRCRECORDS_H
  11. #include <apt-pkg/macros.h>
  12. #include <apt-pkg/hashes.h>
  13. #include <string>
  14. #include <vector>
  15. #ifndef APT_8_CLEANER_HEADERS
  16. using std::string;
  17. using std::vector;
  18. #endif
  19. class pkgSourceList;
  20. class pkgIndexFile;
  21. class pkgSrcRecords
  22. {
  23. public:
  24. APT_IGNORE_DEPRECATED_PUSH
  25. // Describes a single file
  26. struct File
  27. {
  28. APT_DEPRECATED_MSG("Use Hashes member instead of hardcoded hash algorithm") std::string MD5Hash;
  29. APT_DEPRECATED_MSG("Use FileSize member instead") unsigned long Size;
  30. std::string Path;
  31. std::string Type;
  32. };
  33. struct File2 : public File
  34. {
  35. unsigned long long FileSize;
  36. HashStringList Hashes;
  37. };
  38. APT_IGNORE_DEPRECATED_POP
  39. // Abstract parser for each source record
  40. class Parser
  41. {
  42. void * const d;
  43. protected:
  44. const pkgIndexFile *iIndex;
  45. public:
  46. enum BuildDep {BuildDepend=0x0,BuildDependIndep=0x1,
  47. BuildConflict=0x2,BuildConflictIndep=0x3,
  48. BuildDependArch=0x4,BuildConflictArch=0x5};
  49. struct BuildDepRec
  50. {
  51. std::string Package;
  52. std::string Version;
  53. unsigned int Op;
  54. unsigned char Type;
  55. };
  56. inline const pkgIndexFile &Index() const {return *iIndex;};
  57. virtual bool Restart() = 0;
  58. virtual bool Step() = 0;
  59. virtual bool Jump(unsigned long const &Off) = 0;
  60. virtual unsigned long Offset() = 0;
  61. virtual std::string AsStr() = 0;
  62. virtual std::string Package() const = 0;
  63. virtual std::string Version() const = 0;
  64. virtual std::string Maintainer() const = 0;
  65. virtual std::string Section() const = 0;
  66. virtual const char **Binaries() = 0; // Ownership does not transfer
  67. //FIXME: Add a parameter to specify which architecture to use for [wildcard] matching
  68. virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0;
  69. static const char *BuildDepType(unsigned char const &Type) APT_PURE;
  70. virtual bool Files(std::vector<pkgSrcRecords::File> &F) = 0;
  71. bool Files2(std::vector<pkgSrcRecords::File2> &F);
  72. explicit Parser(const pkgIndexFile *Index);
  73. virtual ~Parser();
  74. };
  75. private:
  76. /** \brief dpointer placeholder (for later in case we need it) */
  77. void * const d;
  78. // The list of files and the current parser pointer
  79. std::vector<Parser*> Files;
  80. std::vector<Parser *>::iterator Current;
  81. public:
  82. // Reset the search
  83. bool Restart();
  84. // Step to the next SourcePackage and return pointer to the
  85. // next SourceRecord. The pointer is owned by libapt.
  86. const Parser* Step();
  87. // Locate a package by name and return pointer to the Parser.
  88. // The pointer is owned by libapt.
  89. Parser* Find(const char *Package,bool const &SrcOnly = false);
  90. explicit pkgSrcRecords(pkgSourceList &List);
  91. virtual ~pkgSrcRecords();
  92. };
  93. #endif