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; }
};
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 )
{}
};
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 )
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 )
{
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);
_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;
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;
}
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;
}
return true;
}
- virtual void problemPatchDownload( std::string description )
+ virtual void problemPatchDownload( const std::string &description )
{
std::cout << description << std::endl;
}
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 )
{}
};
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);
#include <sstream>
#include <streambuf>
+#include <boost/program_options.hpp>
+
#include <zypp/base/LogControl.h>
#include <zypp/base/Logger.h>
#include <zypp/base/String.h>
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;
//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");
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
{
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;
virtual bool progressDeltaDownload( int value )
{ return true; }
- virtual void problemDeltaDownload( std::string description )
+ virtual void problemDeltaDownload( const std::string &description )
{}
virtual void finishDeltaDownload()
virtual void progressDeltaApply( int value )
{}
- virtual void problemDeltaApply( std::string description )
+ virtual void problemDeltaApply( const std::string &description )
{}
virtual void finishDeltaApply()
virtual bool progressPatchDownload( int value )
{ return true; }
- virtual void problemPatchDownload( std::string description )
+ virtual void problemPatchDownload( const std::string &description )
{}
virtual void finishPatchDownload()
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
) {}
};
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
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
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 )
{}
};
const Source_Ref source
, unsigned mediumNr
, Error error
- , std::string description
+ , const std::string &description
) { return ABORT; }
};
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
) {}
};
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
) {}
};
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
) {}
};
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
) {}
};
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
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
) {}
};
*
*/
+#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>
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,
#include <ostream>
#include <sstream>
#include "zypp/parser/xml_parser_assert.h"
+#include "zypp/Pathname.h"
#include "zypp/parser/ParserProgress.h"
#include <iterator>
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 ...
* 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.
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.
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() )
{ }
{
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();
// 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;
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