Imported Upstream version 15.21.5
[platform/upstream/libzypp.git] / zypp / Patch.cc
index f2a776c..b15f14d 100644 (file)
@@ -12,6 +12,7 @@
 #include <iostream>
 
 #include "zypp/base/LogTools.h"
+#include "zypp/base/String.h"
 #include "zypp/Patch.h"
 #include "zypp/sat/WhatProvides.h"
 
@@ -41,43 +42,169 @@ namespace zypp
   {}
 
   ///////////////////////////////////////////////////////////////////
-  //
-  //   Patch interface forwarded to implementation
-  //
-  ///////////////////////////////////////////////////////////////////
+
+  std::string Patch::category() const
+  { return str::toLower(lookupStrAttribute( sat::SolvAttr::patchcategory )); }
 
   Patch::Category Patch::categoryEnum() const
+  { return categoryEnum( category() ); }
+
+  bool Patch::isCategory( const std::string & category_r ) const
+  { return( str::compareCI( category_r, category() ) == 0 ); }
+
+  bool Patch::isCategory( Categories category_r ) const
+  { return category_r.testFlag( categoryEnum() ); }
+
+  Patch::Category Patch::categoryEnum( const std::string & category_r )
   {
-    static const IdString cat_yast             ( "yast" );
-    static const IdString cat_security         ( "security" );
-    static const IdString cat_recommended      ( "recommended" );
-    static const IdString cat_bugfix           ( "bugfix" );           // rhn
-    static const IdString cat_optional         ( "optional" );
-    static const IdString cat_enhancement      ( "enhancement" );      // rnh
-    static const IdString cat_document         ( "document" );
-
-    // patch category is not poolized in the solv file (i.e. an IdString) ;(
-    IdString cat( sat::LookupAttr( sat::SolvAttr::patchcategory, satSolvable() ).begin().c_str() );
-
-    if ( cat == cat_yast )
-      return CAT_YAST;
-    if ( cat == cat_security )
-      return CAT_SECURITY;
-    if ( cat == cat_recommended || cat == cat_bugfix )
-      return CAT_RECOMMENDED;
-    if ( cat == cat_optional || cat == cat_enhancement )
-      return CAT_OPTIONAL;
-    if ( cat == cat_document )
-      return CAT_DOCUMENT;
+    switch ( category_r[0] )
+    {
+      //       CAT_YAST
+      case 'y':
+      case 'Y':
+       if ( str::compareCI( category_r, "yast" ) == 0 )
+         return CAT_YAST;
+       break;
 
+      //       CAT_SECURITY
+      case 's':
+      case 'S':
+       if ( str::compareCI( category_r, "security" ) == 0 )
+         return CAT_SECURITY;
+       break;
+
+      //       CAT_RECOMMENDED
+      case 'r':
+      case 'R':
+       if ( str::compareCI( category_r, "recommended" ) == 0 )
+         return CAT_RECOMMENDED;
+       break;
+      case 'b':
+      case 'B':
+       if ( str::compareCI( category_r, "bugfix" ) == 0 )      // rhn
+         return CAT_RECOMMENDED;
+       break;
+
+      //       CAT_OPTIONAL
+      case 'o':
+      case 'O':
+       if ( str::compareCI( category_r, "optional" ) == 0 )
+         return CAT_OPTIONAL;
+       break;
+      case 'f':
+      case 'F':
+       if ( str::compareCI( category_r, "feature" ) == 0 )
+         return CAT_OPTIONAL;
+       break;
+      case 'e':
+      case 'E':
+       if ( str::compareCI( category_r, "enhancement" ) == 0 ) // rhn
+         return CAT_OPTIONAL;
+       break;
+
+      //       CAT_DOCUMENT
+      case 'd':
+      case 'D':
+       if ( str::compareCI( category_r, "document" ) == 0 )
+         return CAT_DOCUMENT;
+       break;
+    }
+    // default:
+    INT << "Unrecognized Patch::Category string '" << category_r << "'" << endl;
     return CAT_OTHER;
   }
 
-  std::string Patch::message( const Locale & lang_r ) const
-  { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
+  std::string asString( const Patch::Category & obj )
+  {
+    switch ( obj )
+    {
+      case Patch::CAT_OTHER:           return std::string( "other" );          break;
+      case Patch::CAT_YAST:            return std::string( "yast" );           break;
+      case Patch::CAT_SECURITY:                return std::string( "security" );       break;
+      case Patch::CAT_RECOMMENDED:     return std::string( "recommended" );    break;
+      case Patch::CAT_OPTIONAL:                return std::string( "optional" );       break;
+      case Patch::CAT_DOCUMENT:                return std::string( "document" );       break;
+    }
+    // make gcc happy:
+    return std::string( "other" );
+  }
 
-  std::string Patch::category() const
-  { return lookupStrAttribute( sat::SolvAttr::patchcategory ); }
+  ///////////////////////////////////////////////////////////////////
+
+  std::string Patch::severity() const
+  { return str::toLower(lookupStrAttribute( sat::SolvAttr::severity )); }
+
+  Patch::SeverityFlag Patch::severityFlag() const
+  { return severityFlag( severity() ); }
+
+  bool Patch::isSeverity( const std::string & severity_r ) const
+  { return( str::compareCI( severity_r, severity() ) == 0 ); }
+
+  bool Patch::isSeverity( SeverityFlags severity_r ) const
+  { return severity_r.testFlag( severityFlag() ); }
+
+  Patch::SeverityFlag Patch::severityFlag( const std::string & severity_r )
+  {
+    switch ( severity_r[0] )
+    {
+      case 'l':
+      case 'L':
+       if ( str::compareCI( severity_r, "low" ) == 0 )
+         return SEV_LOW;
+       break;
+
+      case 'm':
+      case 'M':
+       if ( str::compareCI( severity_r, "moderate" ) == 0 )
+         return SEV_MODERATE;
+       break;
+
+      case 'i':
+      case 'I':
+       if ( str::compareCI( severity_r, "important" ) == 0 )
+         return SEV_IMPORTANT;
+       break;
+
+      case 'c':
+      case 'C':
+       if ( str::compareCI( severity_r, "critical" ) == 0 )
+         return SEV_CRITICAL;
+       break;
+
+      case 'u':
+      case 'U':
+       if ( str::compareCI( severity_r, "unspecified" ) == 0 )
+         return SEV_NONE;
+       break;
+
+      case '\0':
+       return SEV_NONE;
+       break;
+    }
+    // default:
+    INT << "Unrecognized Patch::Severity string '" << severity_r << "'" << endl;
+    return SEV_OTHER;
+  }
+
+  std::string asString( const Patch::SeverityFlag & obj )
+  {
+    switch ( obj )
+    {
+      case Patch::SEV_OTHER:   return std::string( "unknown" );        break;
+      case Patch::SEV_NONE:    return std::string( "unspecified" );    break;
+      case Patch::SEV_LOW:     return std::string( "low" );            break;
+      case Patch::SEV_MODERATE:        return std::string( "moderate" );       break;
+      case Patch::SEV_IMPORTANT:return std::string( "important" );     break;
+      case Patch::SEV_CRITICAL:        return std::string( "critical" );       break;
+    }
+    // make gcc happy:
+    return std::string( "unknown" );
+  }
+
+  ///////////////////////////////////////////////////////////////////
+  //
+std::string Patch::message( const Locale & lang_r ) const
+  { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
 
   bool Patch::rebootSuggested() const
   { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); }
@@ -88,26 +215,57 @@ namespace zypp
   bool Patch::reloginSuggested() const
   { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); }
 
-
-  bool Patch::interactive() const
+  Patch::InteractiveFlags Patch::interactiveFlags() const
   {
-    if ( rebootSuggested()
-         || ! message().empty()
-         || ! licenseToConfirm().empty() )
-    {
-      return true;
-    }
+    InteractiveFlags patchFlags (NoFlags);
+    if ( rebootSuggested() )
+      patchFlags |= Reboot;
+
+    if ( ! message().empty() )
+      patchFlags |= Message;
+
+    if ( ! licenseToConfirm().empty() )
+      patchFlags |= License;
 
     Patch::Contents c( contents() );
     for_( it, c.begin(), c.end() )
     {
-      if ( ! licenseToConfirm().empty() )
+      if ( ! makeResObject(*it)->licenseToConfirm().empty() )
       {
-        return true;
+        patchFlags |= License;
+        break;
       }
     }
+    return patchFlags;
+  }
+
+  bool Patch::interactiveWhenIgnoring( InteractiveFlags flags_r ) const
+  {
+    if ( interactiveFlags() & ( ~flags_r ) )
+    {
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+
+  bool Patch::interactive() const
+  {
+    return interactiveWhenIgnoring();
+  }
 
-    return false;
+  std::string asString( const Patch::InteractiveFlag & obj )
+  {
+    switch ( obj )
+    {
+      case Patch::NoFlags:     return "";              break;
+      case Patch::Reboot:      return "reboot";        break;
+      case Patch::Message:     return "message";       break;
+      case Patch::License:     return "license";       break;
+    }
+    return str::hexstring(obj);
   }
 
   Patch::Contents Patch::contents() const
@@ -144,7 +302,6 @@ namespace zypp
         continue;
       }
 
-#warning definition of patch contents is poor - needs review
       /* find exact providers first (this matches the _real_ 'collection content' of the patch */
       providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) );
       if ( providers.empty() )