PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/synaptic-0.57.2/common/rpackagefilter.h

#
C Header | 295 lines | 185 code | 86 blank | 24 comment | 0 complexity | c0b9a3bbb99c493aba3c95b3a105cbdb MD5 | raw file
Possible License(s): GPL-2.0
  1. /* rpackagefilter.h - filters for package listing
  2. *
  3. * Copyright (c) 2000, 2001 Conectiva S/A
  4. * 2002 Michael Vogt <mvo@debian.org>
  5. *
  6. * Author: Alfredo K. Kojima <kojima@conectiva.com.br>
  7. * Michael Vogt <mvo@debian.org>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. * USA
  23. */
  24. #ifndef _RPACKAGEFILTER_H_
  25. #define _RPACKAGEFILTER_H_
  26. #include <set>
  27. #include <vector>
  28. #include <string>
  29. #include <fstream>
  30. #include <iostream>
  31. #include <apt-pkg/tagfile.h>
  32. #include <regex.h>
  33. #include "rpackagelister.h"
  34. using namespace std;
  35. class RPackage;
  36. class RPackageLister;
  37. class Configuration;
  38. class RPackageFilter {
  39. public:
  40. virtual const char *type() = 0;
  41. virtual bool filter(RPackage *pkg) = 0;
  42. virtual void reset() = 0;
  43. virtual bool read(Configuration &conf, string key) = 0;
  44. virtual bool write(ofstream &out, string pad) = 0;
  45. RPackageFilter() {};
  46. virtual ~RPackageFilter() {};
  47. };
  48. extern const char *RPFSection;
  49. class RSectionPackageFilter : public RPackageFilter {
  50. protected:
  51. vector<string> _groups;
  52. bool _inclusive; // include or exclude the packages
  53. public:
  54. RSectionPackageFilter() : _inclusive(false) {};
  55. virtual ~RSectionPackageFilter() {};
  56. inline virtual void reset() {
  57. clear();
  58. _inclusive = false;
  59. };
  60. inline virtual const char *type() { return RPFSection; };
  61. void setInclusive(bool flag) { _inclusive = flag; };
  62. bool inclusive();
  63. inline void addSection(string group) { _groups.push_back(group); };
  64. int count();
  65. string section(int index);
  66. void clear();
  67. virtual bool filter(RPackage *pkg);
  68. virtual bool read(Configuration &conf, string key);
  69. virtual bool write(ofstream &out, string pad);
  70. };
  71. extern const char *RPFPattern;
  72. class RPatternPackageFilter : public RPackageFilter {
  73. public:
  74. typedef enum {
  75. Name,
  76. Description,
  77. Maintainer,
  78. Version,
  79. Depends,
  80. Provides,
  81. Conflicts,
  82. Replaces, // (or obsoletes)
  83. Recommends,
  84. Suggests,
  85. RDepends, // reverse depends
  86. Origin // package origin (like security.debian.org)
  87. } DepType;
  88. protected:
  89. struct Pattern {
  90. DepType where;
  91. string pattern;
  92. bool exclusive;
  93. vector<regex_t *> regexps;
  94. };
  95. vector<Pattern> _patterns;
  96. bool and_mode; // patterns are applied in "AND" mode if true, "OR" if false
  97. inline bool filterName(Pattern pat, RPackage *pkg);
  98. inline bool filterVersion(Pattern pat, RPackage *pkg);
  99. inline bool filterDescription(Pattern pat, RPackage *pkg);
  100. inline bool filterMaintainer(Pattern pat, RPackage *pkg);
  101. inline bool filterDepends(Pattern pat, RPackage *pkg,
  102. pkgCache::Dep::DepType filterType);
  103. inline bool filterProvides(Pattern pat, RPackage *pkg);
  104. inline bool filterRDepends(Pattern pat, RPackage *pkg);
  105. inline bool filterOrigin(Pattern pat, RPackage *pkg);
  106. public:
  107. static const char *TypeName[];
  108. RPatternPackageFilter() : and_mode(true) {};
  109. RPatternPackageFilter(RPatternPackageFilter &f);
  110. virtual ~RPatternPackageFilter();
  111. inline virtual void reset() { clear(); };
  112. inline virtual const char *type() { return RPFPattern; };
  113. void addPattern(DepType type, string pattern, bool exclusive);
  114. inline int count() { return _patterns.size(); };
  115. inline void getPattern(int index, DepType &type, string &pattern,
  116. bool &exclusive) {
  117. type = _patterns[index].where;
  118. pattern = _patterns[index].pattern;
  119. exclusive = _patterns[index].exclusive;
  120. };
  121. void clear();
  122. bool getAndMode() { return and_mode; };
  123. void setAndMode(bool b) { and_mode=b; };
  124. virtual bool filter(RPackage *pkg);
  125. virtual bool read(Configuration &conf, string key);
  126. virtual bool write(ofstream &out, string pad);
  127. };
  128. extern const char *RPFStatus;
  129. class RStatusPackageFilter : public RPackageFilter {
  130. protected:
  131. int _status;
  132. public:
  133. enum Types {
  134. Installed = 1 << 0,
  135. Upgradable = 1 << 1, // installed but upgradable
  136. Broken = 1 << 2, // installed but dependencies are broken
  137. NotInstalled = 1 << 3,
  138. MarkInstall = 1 << 4,
  139. MarkRemove = 1 << 5,
  140. MarkKeep = 1 << 6,
  141. NewPackage = 1 << 7, // new Package (after update)
  142. PinnedPackage = 1 << 8, // pinned Package (never upgrade)
  143. OrphanedPackage = 1 << 9, // orphaned (identfied with deborphan)
  144. ResidualConfig = 1 << 10, // not installed but has config left
  145. NotInstallable = 1 << 11, // the package is not aviailable in repository
  146. UpstreamUpgradable = 1 << 12 // new upstream version
  147. };
  148. RStatusPackageFilter() : _status(~0)
  149. {};
  150. inline virtual void reset() { _status = ~0; };
  151. inline virtual const char *type() { return RPFStatus; };
  152. inline void setStatus(int status) { _status = status; };
  153. inline int status() { return _status; };
  154. virtual bool filter(RPackage *pkg);
  155. virtual bool read(Configuration &conf, string key);
  156. virtual bool write(ofstream &out, string pad);
  157. };
  158. extern const char *RPFPriority;
  159. class RPriorityPackageFilter:public RPackageFilter {
  160. public:
  161. RPriorityPackageFilter() {};
  162. inline virtual void reset() {};
  163. inline virtual const char *type() { return RPFPriority; };
  164. virtual bool filter(RPackage *pkg);
  165. virtual bool read(Configuration &conf, string key);
  166. virtual bool write(ofstream &out, string pad);
  167. };
  168. extern const char *RPFReducedView;
  169. class RReducedViewPackageFilter : public RPackageFilter {
  170. protected:
  171. bool _enabled;
  172. set<string> _hide;
  173. vector<string> _hide_wildcard;
  174. vector<regex_t *> _hide_regex;
  175. void addFile(string FileName);
  176. public:
  177. RReducedViewPackageFilter() : _enabled(false) {};
  178. ~RReducedViewPackageFilter();
  179. inline virtual void reset() { _hide.clear(); };
  180. inline virtual const char *type() { return RPFReducedView; };
  181. virtual bool filter(RPackage *pkg);
  182. virtual bool read(Configuration &conf, string key);
  183. virtual bool write(ofstream &out, string pad);
  184. void enable() { _enabled = true; };
  185. void disable() { _enabled = false; };
  186. };
  187. struct RFilter {
  188. public:
  189. RFilter()
  190. : section(), pattern(), status(),
  191. priority(), reducedview(), preset()
  192. {};
  193. void setName(string name);
  194. string getName();
  195. bool read(Configuration &conf, string key);
  196. bool write(ofstream &out);
  197. bool apply(RPackage *package);
  198. void reset();
  199. RSectionPackageFilter section;
  200. RPatternPackageFilter pattern;
  201. RStatusPackageFilter status;
  202. RPriorityPackageFilter priority;
  203. RReducedViewPackageFilter reducedview;
  204. bool preset;
  205. protected:
  206. string name;
  207. };
  208. #endif
  209. // vim:ts=3:sw=3:et