deblistparser.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: deblistparser.h,v 1.9 2001/02/20 07:03:17 jgg Exp $
  4. /* ######################################################################
  5. Debian Package List Parser - This implements the abstract parser
  6. interface for Debian package files
  7. ##################################################################### */
  8. /*}}}*/
  9. #ifndef PKGLIB_DEBLISTPARSER_H
  10. #define PKGLIB_DEBLISTPARSER_H
  11. #include <apt-pkg/pkgcachegen.h>
  12. #include <apt-pkg/tagfile.h>
  13. #include <apt-pkg/md5.h>
  14. #include <apt-pkg/pkgcache.h>
  15. #include <apt-pkg/macros.h>
  16. #include <string>
  17. #include <vector>
  18. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  19. #include <apt-pkg/string_view.h>
  20. #endif
  21. #ifndef APT_8_CLEANER_HEADERS
  22. #include <apt-pkg/indexfile.h>
  23. #endif
  24. class FileFd;
  25. class APT_HIDDEN debListParser : public pkgCacheListParser
  26. {
  27. public:
  28. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  29. // Parser Helper
  30. struct WordList
  31. {
  32. APT::StringView Str;
  33. unsigned char Val;
  34. };
  35. #endif
  36. private:
  37. std::vector<std::string> forceEssential;
  38. std::vector<std::string> forceImportant;
  39. std::string MD5Buffer;
  40. protected:
  41. pkgTagFile Tags;
  42. pkgTagSection Section;
  43. map_filesize_t iOffset;
  44. std::string Arch;
  45. virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
  46. bool ParseDepends(pkgCache::VerIterator &Ver, pkgTagSection::Key Key,
  47. unsigned int Type);
  48. bool ParseProvides(pkgCache::VerIterator &Ver);
  49. bool ParseTag(pkgCache::VerIterator &Ver);
  50. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  51. APT_HIDDEN static bool GrabWord(APT::StringView Word,const WordList *List,unsigned char &Out);
  52. #endif
  53. APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors);
  54. public:
  55. APT_PUBLIC static unsigned char GetPrio(std::string Str);
  56. // These all operate against the current section
  57. virtual std::string Package() APT_OVERRIDE;
  58. virtual bool ArchitectureAll() APT_OVERRIDE;
  59. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  60. virtual APT::StringView Architecture() APT_OVERRIDE;
  61. virtual APT::StringView Version() APT_OVERRIDE;
  62. #endif
  63. virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE;
  64. virtual std::vector<std::string> AvailableDescriptionLanguages() APT_OVERRIDE;
  65. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  66. virtual APT::StringView Description_md5() APT_OVERRIDE;
  67. #endif
  68. virtual unsigned short VersionHash() APT_OVERRIDE;
  69. virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver) APT_OVERRIDE;
  70. virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
  71. pkgCache::VerIterator &Ver) APT_OVERRIDE;
  72. virtual map_filesize_t Offset() APT_OVERRIDE {return iOffset;};
  73. virtual map_filesize_t Size() APT_OVERRIDE {return Section.size();};
  74. virtual bool Step() APT_OVERRIDE;
  75. bool LoadReleaseInfo(pkgCache::RlsFileIterator &FileI,FileFd &File,
  76. std::string const &section);
  77. APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
  78. std::string &Package,std::string &Ver,unsigned int &Op);
  79. APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
  80. std::string &Package,std::string &Ver,unsigned int &Op,
  81. bool const &ParseArchFlags);
  82. APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
  83. std::string &Package,std::string &Ver,unsigned int &Op,
  84. bool const &ParseArchFlags, bool const &StripMultiArch);
  85. APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
  86. std::string &Package,std::string &Ver,unsigned int &Op,
  87. bool const &ParseArchFlags, bool const &StripMultiArch,
  88. bool const &ParseRestrictionsList);
  89. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  90. APT_HIDDEN static const char *ParseDepends(const char *Start,const char *Stop,
  91. APT::StringView &Package,
  92. APT::StringView &Ver,unsigned int &Op,
  93. bool const ParseArchFlags = false, bool StripMultiArch = true,
  94. bool const ParseRestrictionsList = false);
  95. #endif
  96. APT_PUBLIC static const char *ConvertRelation(const char *I,unsigned int &Op);
  97. debListParser(FileFd *File);
  98. virtual ~debListParser();
  99. };
  100. class APT_HIDDEN debDebFileParser : public debListParser
  101. {
  102. private:
  103. std::string DebFile;
  104. public:
  105. debDebFileParser(FileFd *File, std::string const &DebFile);
  106. virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
  107. pkgCache::VerIterator &Ver) APT_OVERRIDE;
  108. };
  109. class APT_HIDDEN debTranslationsParser : public debListParser
  110. {
  111. public:
  112. #ifdef APT_PKG_EXPOSE_STRING_VIEW
  113. // a translation can never be a real package
  114. virtual APT::StringView Architecture() APT_OVERRIDE { return ""; }
  115. virtual APT::StringView Version() APT_OVERRIDE { return ""; }
  116. #endif
  117. debTranslationsParser(FileFd *File)
  118. : debListParser(File) {};
  119. };
  120. class APT_HIDDEN debStatusListParser : public debListParser
  121. {
  122. public:
  123. virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
  124. debStatusListParser(FileFd *File)
  125. : debListParser(File) {};
  126. };
  127. #endif