]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cachefilter.cc
use 'best' hash for source authentication
[apt.git] / apt-pkg / cachefilter.cc
index 210a9a9ab8f2eac5047500daabe5c31aedc55bf8..e388f2450cfa0f665ea44b34a3dd9b6f9e06d86d 100644 (file)
@@ -9,16 +9,20 @@
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
-
-#include <apti18n.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/macros.h>
 
 #include <string>
-
+#include <string.h>
 #include <regex.h>
+#include <fnmatch.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 namespace APT {
 namespace CacheFilter {
-PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {/*{{{*/
+PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) : d(NULL) {/*{{{*/
        pattern = new regex_t;
        int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
        if (Res == 0)
@@ -52,5 +56,58 @@ PackageNameMatchesRegEx::~PackageNameMatchesRegEx() {                        /*{{{*/
        delete pattern;
 }
                                                                        /*}}}*/
+
+// Fnmatch support                                     /*{{{*/
+//----------------------------------------------------------------------
+bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
+   return fnmatch(Pattern.c_str(), Pkg.Name(), FNM_CASEFOLD) == 0;
+}
+                                                                       /*}}}*/
+bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/
+   return fnmatch(Pattern.c_str(), Grp.Name(), FNM_CASEFOLD) == 0;
+}
+                                                                       /*}}}*/
+
+// CompleteArch to <kernel>-<cpu> tuple                                        /*{{{*/
+//----------------------------------------------------------------------
+/* The complete architecture, consisting of <kernel>-<cpu>. */
+static std::string CompleteArch(std::string const &arch) {
+       if (arch.find('-') != std::string::npos) {
+               // ensure that only -any- is replaced and not something like company-
+               std::string complete = std::string("-").append(arch).append("-");
+               complete = SubstVar(complete, "-any-", "-*-");
+               complete = complete.substr(1, complete.size()-2);
+               return complete;
+       }
+       else if (arch == "any")                 return "*-*";
+       else                                    return "linux-" + arch;
+}
+                                                                       /*}}}*/
+PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/
+                                       literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern), d(NULL) {
+}
+                                                                       /*}}}*/
+bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/
+       if (strcmp(literal.c_str(), arch) == 0 ||
+           strcmp(complete.c_str(), arch) == 0)
+               return true;
+       std::string const pkgarch = CompleteArch(arch);
+       if (isPattern == true)
+               return fnmatch(complete.c_str(), pkgarch.c_str(), 0) == 0;
+       return fnmatch(pkgarch.c_str(), complete.c_str(), 0) == 0;
+}
+                                                                       /*}}}*/
+bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
+       return (*this)(Pkg.Arch());
+}
+                                                                       /*}}}*/
+bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator const &Ver) {/*{{{*/
+       return (*this)(Ver.ParentPkg());
+}
+                                                                       /*}}}*/
+PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() {  /*{{{*/
+}
+                                                                       /*}}}*/
+
 }
 }