fixup Fix to build with libxml 2.12.x (fixes #505)
[platform/upstream/libzypp.git] / zypp / ServiceInfo.cc
index f0c04e2..04bfcb2 100644 (file)
 #include <ostream>
 #include <iostream>
 
-#include "zypp/base/String.h"
-#include "zypp/parser/xml/XmlEscape.h"
+#include <zypp/base/String.h>
+#include <zypp/base/DefaultIntegral.h>
+#include <zypp/parser/xml/XmlEscape.h>
 
-#include "zypp/RepoInfo.h"
-#include "zypp/parser/RepoindexFileReader.h"
-#include "zypp/repo/RepoInfoBaseImpl.h"
+#include <zypp/RepoInfo.h>
+#include <zypp/ServiceInfo.h>
 
-#include "zypp/ServiceInfo.h"
-
-using namespace std;
+using std::endl;
 using zypp::xml::escape;
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -32,39 +30,38 @@ namespace zypp
   //
   //  CLASS NAME : ServiceInfo::Impl
   //
-  struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
+  struct ServiceInfo::Impl
   {
     typedef ServiceInfo::ReposToEnable  ReposToEnable;
     typedef ServiceInfo::ReposToDisable ReposToDisable;
 
   public:
-    Url url;
-    repo::ServiceType type;
-    ReposToEnable  reposToEnable;
-    ReposToDisable reposToDisable;
+    RepoVariablesReplacedUrl _url;
+    repo::ServiceType _type;
+    ReposToEnable _reposToEnable;
+    ReposToDisable _reposToDisable;
+    RepoStates _repoStates;
+    DefaultIntegral<Date::Duration,0> _ttl;
+    Date _lrf;
 
   public:
     Impl()
-      : repo::RepoInfoBase::Impl()
-      , type(repo::ServiceType::NONE_e)
     {}
 
-    Impl(const Url & url_)
-      : repo::RepoInfoBase::Impl()
-      , url(url_)
-      , type(repo::ServiceType::NONE_e)
+    Impl( const Url & url_r )
+    : _url( url_r )
     {}
 
     ~Impl()
     {}
 
-    void setProbedType( const repo::ServiceType & t ) const
+    void setProbedType( const repo::ServiceType & type_r ) const
     {
-      if ( type == repo::ServiceType::NONE
-           && t != repo::ServiceType::NONE )
+      if ( _type == repo::ServiceType::NONE
+           && type_r != repo::ServiceType::NONE )
       {
         // lazy init!
-        const_cast<Impl*>(this)->type = t;
+        const_cast<Impl*>(this)->_type = type_r;
       }
     }
 
@@ -88,84 +85,121 @@ namespace zypp
 
   ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
 
-  ServiceInfo::ServiceInfo(const string & alias)
+  ServiceInfo::ServiceInfo(const std::string & alias)
     : repo::RepoInfoBase(alias), _pimpl( new Impl() )
   {}
 
-  ServiceInfo::ServiceInfo(const string & alias, const Url & url)
+  ServiceInfo::ServiceInfo(const std::string & alias, const Url & url)
     : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
   {}
 
   ServiceInfo::~ServiceInfo()
   {}
 
-  Url ServiceInfo::url() const { return _pimpl->url; }
-  void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
+  Url ServiceInfo::url() const                 // Variables replaced
+  { return _pimpl->_url.transformed(); }
 
-  repo::ServiceType ServiceInfo::type() const
-  { return _pimpl->type; }
-  void ServiceInfo::setType( const repo::ServiceType & type )
-  { _pimpl->type = type; }
+  Url ServiceInfo::rawUrl() const              // Raw
+  { return _pimpl->_url.raw(); }
 
-  void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
-  { _pimpl->setProbedType( t ); }
+  void ServiceInfo::setUrl( const Url& url )   // Raw
+  { _pimpl->_url.raw() = url; }
 
-  bool ServiceInfo::reposToEnableEmpty() const
-  { return _pimpl->reposToEnable.empty(); }
+  repo::ServiceType ServiceInfo::type() const                          { return _pimpl->_type; }
+  void ServiceInfo::setType( const repo::ServiceType & type )          { _pimpl->_type = type; }
+  void ServiceInfo::setProbedType( const repo::ServiceType &t ) const  { _pimpl->setProbedType( t ); }
 
-  ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const
-  { return _pimpl->reposToEnable.size(); }
+  Date::Duration ServiceInfo::ttl() const                      { return _pimpl->_ttl; }
+  void ServiceInfo::setTtl( Date::Duration ttl_r )             { _pimpl->_ttl = ttl_r; }
+  void ServiceInfo::setProbedTtl( Date::Duration ttl_r ) const { const_cast<ServiceInfo*>(this)->setTtl( ttl_r ); }
 
-  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
-  { return _pimpl->reposToEnable.begin(); }
+  Date ServiceInfo::lrf() const                                        { return _pimpl->_lrf; }
+  void ServiceInfo::setLrf( Date lrf_r )                       { _pimpl->_lrf = lrf_r; }
 
-  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
-  { return _pimpl->reposToEnable.end(); }
+  bool ServiceInfo::reposToEnableEmpty() const                                         { return _pimpl->_reposToEnable.empty(); }
+  ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const         { return _pimpl->_reposToEnable.size(); }
+  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const   { return _pimpl->_reposToEnable.begin(); }
+  ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const     { return _pimpl->_reposToEnable.end(); }
 
   bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
-  { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
+  { return( _pimpl->_reposToEnable.find( alias_r ) != _pimpl->_reposToEnable.end() ); }
 
   void ServiceInfo::addRepoToEnable( const std::string & alias_r )
-  { _pimpl->reposToEnable.insert( alias_r ); }
+  {
+    _pimpl->_reposToEnable.insert( alias_r );
+    _pimpl->_reposToDisable.erase( alias_r );
+  }
 
   void ServiceInfo::delRepoToEnable( const std::string & alias_r )
-  { _pimpl->reposToEnable.erase( alias_r ); }
+  { _pimpl->_reposToEnable.erase( alias_r ); }
 
   void ServiceInfo::clearReposToEnable()
-  { _pimpl->reposToEnable.clear(); }
-
-
-  bool ServiceInfo::reposToDisableEmpty() const
-  { return _pimpl->reposToDisable.empty(); }
-
-  ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const
-  { return _pimpl->reposToDisable.size(); }
+  { _pimpl->_reposToEnable.clear(); }
 
-  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
-  { return _pimpl->reposToDisable.begin(); }
 
-  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
-  { return _pimpl->reposToDisable.end(); }
+  bool ServiceInfo::reposToDisableEmpty() const                                                { return _pimpl->_reposToDisable.empty(); }
+  ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const       { return _pimpl->_reposToDisable.size(); }
+  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const { return _pimpl->_reposToDisable.begin(); }
+  ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const   { return _pimpl->_reposToDisable.end(); }
 
   bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
-  { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
+  { return( _pimpl->_reposToDisable.find( alias_r ) != _pimpl->_reposToDisable.end() ); }
 
   void ServiceInfo::addRepoToDisable( const std::string & alias_r )
-  { _pimpl->reposToDisable.insert( alias_r ); }
+  {
+    _pimpl->_reposToDisable.insert( alias_r );
+    _pimpl->_reposToEnable.erase( alias_r );
+  }
 
   void ServiceInfo::delRepoToDisable( const std::string & alias_r )
-  { _pimpl->reposToDisable.erase( alias_r ); }
+  { _pimpl->_reposToDisable.erase( alias_r ); }
 
   void ServiceInfo::clearReposToDisable()
-  { _pimpl->reposToDisable.clear(); }
+  { _pimpl->_reposToDisable.clear(); }
+
 
+  const ServiceInfo::RepoStates & ServiceInfo::repoStates() const      { return _pimpl->_repoStates; }
+  void ServiceInfo::setRepoStates( RepoStates newStates_r )            { swap( _pimpl->_repoStates, newStates_r ); }
+
+
+  std::ostream & operator<<( std::ostream & str, const ServiceInfo::RepoState & obj )
+  {
+    return str
+       << "enabled=" << obj.enabled << " "
+       << "autorefresh=" << obj.autorefresh << " "
+       << "priority=" << obj.priority;
+  }
 
   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
   {
     RepoInfoBase::dumpAsIniOn(str)
-      << "url = " << url() << endl
+      << "url = " << rawUrl() << endl
       << "type = " << type() << endl;
 
+    if ( ttl() )
+      str << "ttl_sec = " << ttl() << endl;
+
+    if ( lrf() )
+      str << "lrf_dat = " << lrf().asSeconds() << endl;
+
+    if ( ! repoStates().empty() )
+    {
+      unsigned cnt = 0U;
+      for ( const auto & el : repoStates() )
+      {
+       std::string tag( "repo_" );
+       tag += str::numstring( ++cnt );
+       const RepoState & state( el.second );
+
+       str << tag << "=" << el.first << endl
+           << tag << "_enabled=" << state.enabled << endl
+           << tag << "_autorefresh=" << state.autorefresh << endl;
+       if ( state.priority != RepoInfo::defaultPriority() )
+         str
+           << tag << "_priority=" << state.priority << endl;
+      }
+    }
+
     if ( ! reposToEnableEmpty() )
       str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
     if ( ! reposToDisableEmpty() )
@@ -173,10 +207,7 @@ namespace zypp
     return str;
   }
 
-  std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
-  { return dumpAsXMLOn(str, ""); }
-
-  ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
+  std::ostream & ServiceInfo::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
   {
     str
       << "<service"
@@ -185,7 +216,8 @@ namespace zypp
       << " enabled=\"" << enabled() << "\""
       << " autorefresh=\"" << autorefresh() << "\""
       << " url=\"" << escape(url().asString()) << "\""
-      << " type=\"" << type().asString() << "\"";
+      << " type=\"" << type().asString() << "\""
+      << " ttl_sec=\"" << ttl() << "\"";
 
     if (content.empty())
       str << "/>" << endl;