callbacks: fix const & in string params
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 8 Sep 2006 12:08:09 +0000 (12:08 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 8 Sep 2006 12:08:09 +0000 (12:08 +0000)
zmart: 1st package installed!

tools/zmart/zmart-media-callbacks.h
tools/zmart/zmart-rpm-callbacks.h
tools/zmart/zmart-source-callbacks.h
tools/zmart/zypp-checkpatches.cc
zypp/ZYppCallbacks.h
zypp/parser/XMLNodeIterator.cc
zypp/parser/XMLNodeIterator.h
zypp/parser/yum/YUMPrimaryParser.cc
zypp/parser/yum/YUMPrimaryParser.h
zypp/source/yum/YUMSourceImpl.cc

index c67d351..4b6d8df 100644 (file)
@@ -32,7 +32,7 @@ namespace ZmartRecipients
 
   struct MediaChangeReportReceiver : public zypp::callback::ReceiveReport<MediaChangeReport>
   {
-    virtual MediaChangeReport::Action requestMedia( const zypp::Source_Ref source, unsigned mediumNr, MediaChangeReport::Error error, std::string description )
+    virtual MediaChangeReport::Action requestMedia( const zypp::Source_Ref source, unsigned mediumNr, MediaChangeReport::Error error, const std::string &description )
     { return MediaChangeReport::ABORT; }
   };
 
@@ -45,10 +45,10 @@ namespace ZmartRecipients
     virtual bool progress(int value, const zypp::Url &file)
     { return true; }
 
-    virtual DownloadProgressReport::Action problem( const zypp::Url &file, DownloadProgressReport::Error error, std::string description )
+    virtual DownloadProgressReport::Action problem( const zypp::Url &file, DownloadProgressReport::Error error, const std::string &description )
     { return DownloadProgressReport::ABORT; }
 
-    virtual void finish( const zypp::Url &file, Error error, std::string reason )
+    virtual void finish( const zypp::Url &file, Error error, const std::string &konreason )
     {}
   };
   
index 074e28c..f437d1f 100644 (file)
@@ -132,6 +132,7 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
   virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
   {
     display_step( resolvable, value );
+    return true;
   }
 
   virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, std::string description, RpmLevel level )
index f50114c..d25cf0a 100644 (file)
@@ -45,7 +45,7 @@ namespace ZmartRecipients
         cout << url << " is type " << type << endl;
       }
       
-      virtual void finish(const zypp::Url &url, Error error, std::string reason )
+      virtual void finish(const zypp::Url &url, Error error, const std::string &reason )
       {
         if ( error == INVALID )
         {
@@ -57,7 +57,7 @@ namespace ZmartRecipients
       virtual bool progress(const zypp::Url &url, int value)
       { return true; }
 
-      virtual Action problem( const zypp::Url &url, Error error, std::string description )
+      virtual Action problem( const zypp::Url &url, Error error, const std::string &description )
       {
         cout << error << endl;
         exit(-1);
@@ -83,7 +83,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     _url = url;
   }
    
-  void display_step( std::string what, int value )
+  void display_step( const std::string &what, int value )
   {
     cout << "\x1B 2K\r" << _cursor << " " <<  what << " [" << value << " %]  ";
     ++_cursor;
@@ -104,7 +104,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     display_step( "Downloading delta " + _delta.asString(), value );
   }
   
-  virtual void problemDeltaDownload( std::string description )
+  virtual void problemDeltaDownload( const std::string &description )
   {
     std::cout << description << std::endl;
   }
@@ -127,7 +127,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     display_step( "Applying delta " + _delta.asString(), value );
   }
   
-  virtual void problemDeltaApply( std::string description )
+  virtual void problemDeltaApply( const std::string &description )
   {
     std::cout << description << std::endl;
   }
@@ -151,7 +151,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     return true;
   }
   
-  virtual void problemPatchDownload( std::string description )
+  virtual void problemPatchDownload( const std::string &description )
   {
     std::cout << description << std::endl;
   }
@@ -167,13 +167,13 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     return true;
   }
   
-  virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error error, std::string description )
+  virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error error, const std::string &description )
   {
     std::cout << resolvable_ptr << " " << description << std::endl;
     return ABORT;
   }
   
-  virtual void finish( zypp::Resolvable::constPtr resolvable_ptr, Error error, std::string reason )
+  virtual void finish( zypp::Resolvable::constPtr resolvable_ptr, Error error, const std::string &reason )
   {}
 };
 
@@ -202,10 +202,10 @@ struct SourceReportReceiver  : public zypp::callback::ReceiveReport<zypp::source
     return true;
   }
   
-  virtual Action problem( zypp::Source_Ref source, Error error, std::string description )
+  virtual Action problem( zypp::Source_Ref source, Error error, const std::string &description )
   { return ABORT; }
 
-  virtual void finish( zypp::Source_Ref source, const std::string task, Error error, std::string reason )
+  virtual void finish( zypp::Source_Ref source, Error error, const std::string &reason )
   {
     if ( error == SourceReportReceiver::NO_ERROR )
       display_step(100);
index 326e56d..25a492c 100644 (file)
@@ -3,6 +3,8 @@
 #include <sstream>
 #include <streambuf>
 
+#include <boost/program_options.hpp>
+
 #include <zypp/base/LogControl.h>
 #include <zypp/base/Logger.h>
 #include <zypp/base/String.h>
@@ -28,7 +30,9 @@ using namespace zypp::detail;
 
 using namespace std;
 using namespace zypp;
+using namespace boost;
 
+namespace po = boost::program_options;
 #define ZYPP_CHECKPATCHES_LOG "/var/log/zypp-checkpatches.log"
 
 ZYpp::Ptr God;
@@ -37,6 +41,36 @@ Settings gSettings;
 
 //using namespace DbXml;
 
+void render_xml( const zypp::ResPool &pool )
+{
+  int count = 0;
+  int security_count = 0;
+  
+  cout << "<?xml>" << std::endl;
+  cout << "<update-status>" << std::endl;
+  cout << " <update-list>" << std::endl;
+  for ( ResPool::byKind_iterator it = pool.byKindBegin<Patch>(); it != pool.byKindEnd<Patch>(); ++it )
+  {
+    Resolvable::constPtr res = it->resolvable();
+    Patch::constPtr patch = asKind<Patch>(res);
+    MIL << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << ( it->status().isNeeded() ? " [needed]" : " [unneeded]" )<< std::endl;
+    if ( it->status().isNeeded() )
+    {
+      cout << " <update category=\"" << patch ->category() << "\">" << std::endl;
+      cout << "  <name>" << patch->name() << "</name>" <<endl;
+      cout << "  <edition>" << patch->edition() << "</edition>" <<endl;
+      
+      
+      count++;
+      if (patch->category() == "security")
+        security_count++;
+    }
+  }
+  cout << " </update-list>" << std::endl;
+  cout << " <update-summary total=\"" << count << "\" security=\"" << security_count << "\"/>" << std::endl;
+  cout << "</update-status>" << std::endl;
+}
+
 int main(int argc, char **argv)
 {
   const char *logfile = getenv("ZYPP_LOGFILE");
@@ -45,20 +79,61 @@ int main(int argc, char **argv)
   else
     zypp::base::LogControl::instance().logfile( ZYPP_CHECKPATCHES_LOG );
   
-  std::string previous_token;
-  int previous_code = -1;
+  po::positional_options_description pos_options;
+  pos_options.add("command", -1);
   
-  if (argc != 3)
-  {
-    cerr << "usage: " << argv[0] << " [<previous token>] [previous result]" << endl;
-    exit(-1);
+  po::options_description general_options("General options");
+  general_options.add_options()
+      ("help,h", "produce a help message")
+      ("version,v", "output the version number")
+      ;
+
+  po::options_description check_options("Check options");
+  check_options.add_options()
+      ("previous-token,t", po::value< string >(), "The token got from last run.")
+      ("previous-result,r", po::value< int >(), "Previous result. If repositories are the same as last run, this will be shown.")
+      ;
+  
+  //po::options_description source_options("Source options");
+  //source_options.add_options()
+  //    ("disable-system-sources,D", "Don't read the system sources.")
+  //    ("sources,S", po::value< vector<string> >(), "Read from additional sources")
+  //    ;
+  
+  // Declare an options description instance which will include
+  // all the options
+  po::options_description all_options("Allowed options");
+  all_options.add(general_options).add(check_options);
+
+  // Declare an options description instance which will be shown
+  // to the user
+  po::options_description visible_options("Allowed options");
+  visible_options.add(general_options).add(check_options);
+
+  po::variables_map vm;
+  //po::store(po::parse_command_line(argc, argv, visible_options), vm);
+  po::store(po::command_line_parser(argc, argv).options(visible_options).positional(pos_options).run(), vm);
+  po::notify(vm);
+  if (vm.count("help")) {
+    cout << visible_options << "\n";
+    return 1;
   }
   
-  MIL << argv[0] << " started with arguments " << argv[1] << " " << argv[2] << std::endl;
+  std::string previous_token;
+  if (vm.count("previous-token"))
+  {
+    previous_token = vm["previous-token"].as< string >();
+  }
   
-  previous_token = std::string(argv[1]);
-  previous_code = str::strtonum<int>(argv[2]);
+  int previous_code = -1;
+  if (vm.count("previous-result"))
+  {
+    previous_code = vm["previous-result"].as< int >();
+  }
   
+  MIL << argv[0] << " started with arguments " << previous_token << " " << previous_code << std::endl;
+   
   ZYpp::Ptr God = NULL;
   try
   {
@@ -132,22 +207,11 @@ int main(int argc, char **argv)
   int count = 0;
   int security_count = 0;
   MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
-  for ( ResPool::byKind_iterator it = God->pool().byKindBegin<Patch>(); it != God->pool().byKindEnd<Patch>(); ++it )
-  {
-    Resolvable::constPtr res = it->resolvable();
-    Patch::constPtr patch = asKind<Patch>(res);
-    MIL << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << ( it->status().isNeeded() ? " [needed]" : " [unneeded]" )<< std::endl;
-    if ( it->status().isNeeded() )
-    {
-      count++;
-      if (patch->category() == "security")
-        security_count++;
-      
-      cerr << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << std::endl;
-    }
-  }
   
-  MIL << "Patches " << security_count << " " << count << std::endl;
+  
+  render_xml(God->pool());
+  
+  //MIL << "Patches " << security_count << " " << count << std::endl;
   
   if ( security_count > 0 )
     return 2;
index a5c5d74..7eb3b13 100644 (file)
@@ -57,7 +57,7 @@ namespace zypp
       virtual bool progressDeltaDownload( int value )
       { return true; }
 
-      virtual void problemDeltaDownload( std::string description )
+      virtual void problemDeltaDownload( const std::string &description )
       {}
 
       virtual void finishDeltaDownload()
@@ -73,7 +73,7 @@ namespace zypp
       virtual void progressDeltaApply( int value )
       {}
 
-      virtual void problemDeltaApply( std::string description )
+      virtual void problemDeltaApply( const std::string &description )
       {}
 
       virtual void finishDeltaApply()
@@ -89,7 +89,7 @@ namespace zypp
       virtual bool progressPatchDownload( int value )
       { return true; }
 
-      virtual void problemPatchDownload( std::string description )
+      virtual void problemPatchDownload( const std::string &description )
       {}
 
       virtual void finishPatchDownload()
@@ -103,12 +103,12 @@ namespace zypp
       virtual Action problem(
         Resolvable::constPtr resolvable_ptr
           , Error error
-          , std::string description
+          , const std::string &description
       ) { return ABORT; }
 
       virtual void finish(Resolvable::constPtr resolvable_ptr
         , Error error
-        , std::string reason
+        , const std::string &reason
       ) {}
     };
 
@@ -131,12 +131,12 @@ namespace zypp
       virtual void start(const Url &url) {}
       virtual void failedProbe( const Url &url, const std::string &type ) {}
       virtual void successProbe( const Url &url, const std::string &type ) {}
-      virtual void finish(const Url &url, Error error, std::string reason ) {}
+      virtual void finish(const Url &url, Error error, const std::string &reason ) {}
 
       virtual bool progress(const Url &url, int value)
       { return true; }
 
-      virtual Action problem( const Url &url, Error error, std::string description ) { return ABORT; }
+      virtual Action problem( const Url &url, Error error, const std::string &description ) { return ABORT; }
     };
     
     struct SourceCreateReport : public callback::ReportBase
@@ -163,14 +163,14 @@ namespace zypp
       virtual Action problem(
           const zypp::Url &url
           , Error error
-          , std::string description )
+          , const std::string &description )
       { return ABORT; }
 
       virtual void finish(
           const zypp::Url &url
-          , Error error
-          , std::string reason )
-      {}
+          , Error error            
+          , const std::string &reason )
+      {}                 
     };
     
     struct SourceReport : public callback::ReportBase
@@ -195,14 +195,14 @@ namespace zypp
       virtual Action problem(
           Source_Ref source
           , Error error
-          , std::string description )
+          , const std::string &description )
       { return ABORT; }
 
       virtual void finish(
           Source_Ref source
-          , const std::string task
+          , const std::string &task
           , Error error
-          , std::string reason )
+          , const std::string &reason )
       {}
     };
     
@@ -238,7 +238,7 @@ namespace zypp
         const Source_Ref source
         , unsigned mediumNr
         , Error error
-        , std::string description
+        , const std::string &description
       ) { return ABORT; }
     };
 
@@ -265,13 +265,13 @@ namespace zypp
         virtual Action problem(
           const Url &file
          , Error error
-         , std::string description
+         , const std::string &description
         ) { return ABORT; }
 
         virtual void finish(
           const Url &file
           , Error error
-         , std::string reason
+         , const std::string &reason
         ) {}
     };
 
@@ -328,14 +328,14 @@ namespace zypp
         virtual Action problem(
           Resolvable::constPtr resolvable
          , Error error
-         , std::string description
+         , const std::string &description
          , RpmLevel level
         ) { return ABORT; }
 
         virtual void finish(
           Resolvable::constPtr resolvable
           , Error error
-         , std::string reason
+         , const std::string &reason
          , RpmLevel level
         ) {}
       };
@@ -366,13 +366,13 @@ namespace zypp
         virtual Action problem(
           Resolvable::constPtr resolvable
          , Error error
-         , std::string description
+         , const std::string &description
         ) { return ABORT; }
 
         virtual void finish(
           Resolvable::constPtr resolvable
           , Error error
-         , std::string reason
+         , const std::string &reason
         ) {}
       };
 
@@ -398,13 +398,13 @@ namespace zypp
         virtual Action problem(
          Pathname path
         , Error error
-        , std::string description
+        , const std::string &description
         ) { return ABORT; }
 
         virtual void finish(
          Pathname path
           , Error error
-         , std::string reason
+         , const std::string &reason
         ) {}
       };
 
@@ -432,14 +432,14 @@ namespace zypp
         virtual Action problem(
          Pathname path
          , Error error
-        , std::string description
+        , const std::string &description
         ) { return ABORT; }
 
         virtual void finish(
          Pathname path
           , Error error
-         , std::string reason
-        ) {}
+          , const std::string &reason
+        ) {}           
       };
 
        // progress for scanning the database
@@ -464,12 +464,12 @@ namespace zypp
 
         virtual Action problem(
          Error error
-        , std::string description
+        , const std::string &description
         ) { return ABORT; }
 
         virtual void finish(
           Error error
-         , std::string reason
+         , const std::string &reason
         ) {}
       };
 
index 9b7ff5c..3968264 100644 (file)
  *
 */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include <zypp/parser/XMLNodeIterator.h>
 #include <zypp/base/Logger.h>
 #include <libxml2/libxml/xmlreader.h>
@@ -118,6 +126,32 @@ namespace zypp {
       return out;
     }
 
+    XMLNodeIteratorBase::XMLNodeIteratorBase( const Pathname xml_file_path,
+                                             const std::string &baseUrl,
+                                             const char *validationPath, parser::ParserProgress::Ptr progress)
+      : _error(0), _file(0), _baseUrl(baseUrl), _progress(progress), _stream_size(0), _bytes_consumed(0)
+    {
+     
+      int fd = open( xml_file_path.asString().c_str(), O_RDONLY );
+      if ( fd < 0 )
+        ZYPP_THROW(Exception("Cant't open " + xml_file_path.asString()));
+      
+      _reader = xmlReaderForFd( fd, baseUrl.c_str(), "utf-8", XML_PARSE_PEDANTIC)
+          ;
+      xmlTextReaderSetErrorHandler(_reader, (xmlTextReaderErrorFunc) errorHandler, this);
+      if (_reader )
+      {
+        if ( validationPath )
+        {
+          if (xmlTextReaderRelaxNGValidate(_reader,validationPath)==-1)
+            WAR << "Could not enable validation of document using " << validationPath << std::endl;
+        }
+        // otherwise validation is disabled.
+      }
+        /* Derived classes must call fetchNext() in their constructors themselves,
+      XMLNodeIterator has no access to their virtual functions during
+      construction */
+    }
 
     XMLNodeIteratorBase::XMLNodeIteratorBase(std::istream &input,
                                              const std::string &baseUrl,
index 7dc8f25..aebfb00 100644 (file)
@@ -18,6 +18,7 @@
 #include <ostream>
 #include <sstream>
 #include "zypp/parser/xml_parser_assert.h"
+#include "zypp/Pathname.h"
 #include "zypp/parser/ParserProgress.h"
 #include <iterator>
 
@@ -144,6 +145,17 @@ namespace zypp {
                           const char *validationPath, parser::ParserProgress::Ptr progress );
 
       /**
+       * Constructor. Derived classes must call fetchNext() here.
+       * @param xml_file_path is the xml file
+       * @param baseUrl is the base URL of the xml document
+       * FIXME: use XMLParserError::operator<< instead of doing it on my own.
+       */
+      
+      XMLNodeIteratorBase( const Pathname xml_file_path,
+          const std::string &baseUrl,
+          const char *validationPath, parser::ParserProgress::Ptr progress);
+      
+      /**
        * Constructor for an empty iterator.
        * An empty iterator is already at its end.
        * This is what end() returns ...
@@ -278,6 +290,13 @@ namespace zypp {
        * Can be 0 if at end or if the current element is the only element left.
        **/
       std::istream* _input;
+      
+      /**
+       * contains the file to read the xml file from.
+       * Can be 0 if at end or if the current element is the only element left.
+       **/
+      FILE* _file;
+      
 
       /**
        * contains the xmlTextReader used to parse the xml file.
@@ -329,7 +348,18 @@ namespace zypp {
            construction */
       }
 
-
+      /**
+       * Constructor. Derived classes must call fetchNext() here.
+       * @param xml_file_path is  the xml file
+       * @param baseUrl is the base URL of the xml document
+       * FIXME: use XMLParserError::operator<< instead of doing it on my own.
+       */
+      XMLNodeIterator( const Pathname xml_file_path, const std::string &baseUrl
+                      , const char *validationPath, parser::ParserProgress::Ptr progress)
+          : XMLNodeIteratorBase( xml_file_path, baseUrl, validationPath, progress), _current(0)
+      {
+      }
+      
       /**
        * Constructor for a trivial iterator.
        * A trivial iterator contains only one element.
index d3f5d3f..4f9db17 100644 (file)
@@ -38,6 +38,13 @@ namespace zypp {
         fetchNext();
       }
       
+      YUMPrimaryParser::YUMPrimaryParser(const Pathname &filename, const std::string &baseUrl, parser::ParserProgress::Ptr progress )
+        : XMLNodeIterator<YUMPrimaryData_Ptr>(filename, baseUrl,PRIMARYSCHEMA, progress)
+          , _zypp_architecture( getZYpp()->architecture() )
+      {
+        fetchNext();
+      }    
+          
       YUMPrimaryParser::YUMPrimaryParser()
        : _zypp_architecture( getZYpp()->architecture() )
       { }
index bedc42a..8e24cff 100644 (file)
@@ -49,6 +49,7 @@ namespace zypp {
       {
       public:
         YUMPrimaryParser(std::istream &is, const std::string &baseUrl, parser::ParserProgress::Ptr progress = parser::ParserProgress::Ptr() );
+        YUMPrimaryParser(const Pathname &filename, const std::string &baseUrl, parser::ParserProgress::Ptr progress = parser::ParserProgress::Ptr() );
         YUMPrimaryParser();
         YUMPrimaryParser(YUMPrimaryData_Ptr& entry);
         virtual ~YUMPrimaryParser();
index 177d8f8..7dfe24a 100644 (file)
@@ -240,7 +240,7 @@ namespace zypp
         // check signature
         MIL << "Checking [" << (local_dir + "/repodata/repomd.xml") << "] signature"  << endl;
         if (! getZYpp()->keyRing()->verifyFileSignatureWorkflow(local_dir + "/repodata/repomd.xml", (_path + "/repodata/repomd.xml").asString()+ " (" + url().asString() + ")", local_dir + "/repodata/repomd.xml.asc"))
-          ZYPP_THROW(Exception(N_("Signed repomd.xml file fails signature check")));
+          ZYPP_THROW(SourceMetadataException(N_("Signed repomd.xml file fails signature check")));
 
         // ok, now we have a consistent repo in the tmpdir.
         return tmpdir;
@@ -559,6 +559,7 @@ namespace zypp
             ifgzstream st ( filename.asString().c_str() );
             
             YUMPrimaryParser prim(st, "", progress);
+            //YUMPrimaryParser prim(filename.asString(), "", progress);
             for (; !prim.atEnd(); ++prim)
             {
               if (*prim == NULL) continue;      // incompatible arch detected during parsing