zypp/capability/Makefile \
zypp/parser/Makefile \
zypp/parser/yum/Makefile \
+ zypp/parser/yum2/Makefile \
zypp/parser/yum/schema/Makefile \
zypp/parser/tagfile/Makefile \
zypp/parser/xmlstore/Makefile \
#include "zypp/PublicKey.h"
#include "zypp/MediaSetAccess.h"
+#include "zypp/source/yum/YUMSourceCacher.h"
using namespace zypp::detail;
int main()
{
- MediaSetAccess ma( Url("cd:///"), Pathname("/"));
- MIL << "done 1" << srd::endl;
- Pathname local = ma.provideFile("content", 1);
- MIL << local << std::endl;
-
+ //MediaSetAccess ma( Url("cd:///"), Pathname("/"));
+ //MIL << "done 1" << std::endl;
+ //ChecksumFileChecker checker(CheckSum("sha1", "fa0abb22f703a3a41f7a39f0844b24daf572fd4c"));
+ //Pathname local = ma.provideFile("content", 1, checker);
+ //MIL << local << std::endl;
+ try
+ {
+ zypp::source::yum::YUMSourceCacher cacher(Pathname("/"));
+ cacher.cache( Url("http://ftp-1.gwdg.de/pub/opensuse/distribution/SL-OSS-factory/inst-source/suse"), Pathname("/"));
+ }
+ catch ( const Exception &e )
+ {
+ MIL << "Sorry, bye" << endl;
+ }
}
#include <zypp/TranslatedText.h>
///////////////////////////////////////////////////////////////////
-#include <zypp/parser/yum/YUMParser.h>
-#include <zypp/base/Logger.h>
-#include <zypp/source/yum/YUMScriptImpl.h>
-#include <zypp/source/yum/YUMMessageImpl.h>
-#include <zypp/source/yum/YUMPackageImpl.h>
-#include <zypp/source/yum/YUMSourceImpl.h>
-#include <map>
-#include <set>
-#include <zypp/CapFactory.h>
-#include <libxml/parser.h>
-
-using namespace zypp::detail;
-
-using namespace std;
-using namespace zypp;
-using namespace zypp::parser::yum;
-using namespace zypp::source::yum;
-
-xmlSAXHandler emptySAXHandlerStruct = {
- NULL, /* internalSubset */
- NULL, /* isStandalone */
- NULL, /* hasInternalSubset */
- NULL, /* hasExternalSubset */
- NULL, /* resolveEntity */
- NULL, /* getEntity */
- NULL, /* entityDecl */
- NULL, /* notationDecl */
- NULL, /* attributeDecl */
- NULL, /* elementDecl */
- NULL, /* unparsedEntityDecl */
- NULL, /* setDocumentLocator */
- NULL, /* startDocument */
- NULL, /* endDocument */
- NULL, /* startElement */
- NULL, /* endElement */
- NULL, /* reference */
- NULL, /* characters */
- NULL, /* ignorableWhitespace */
- NULL, /* processingInstruction */
- NULL, /* comment */
- NULL, /* xmlParserWarning */
- NULL, /* xmlParserError */
- NULL, /* xmlParserError */
- NULL, /* getParameterEntity */
- NULL, /* cdataBlock; */
- NULL, /* externalSubset; */
- 1
-};
-
-xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
-extern xmlSAXHandlerPtr debugSAXHandler;
-
-/**
- * startElementDebug:
- * @ctxt: An XML parser context
- * @name: The element name
- *
- * called when an opening tag has been processed.
- */
-static void
-startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
-{
- int i;
-
- fprintf(stdout, "SAX.startElement(%s", (char *) name);
- if (atts != NULL) {
- for (i = 0;(atts[i] != NULL);i++) {
- fprintf(stdout, ", %s='", atts[i++]);
- if (atts[i] != NULL)
- fprintf(stdout, "%s'", atts[i]);
- }
- }
- fprintf(stdout, ")\n");
-}
-
-static xmlEntityPtr
-my_getEntity(void *user_data, const xmlChar *name)
-{
- return xmlGetPredefinedEntity(name);
-}
-
-
-/**
- * endElementDebug:
- * @ctxt: An XML parser context
- * @name: The element name
- *
- * called when the end of an element has been detected.
- */
-static void
-endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
-{
- fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
-}
-
-static void
-primaryStartElement(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
-{
-}
+#include <zypp/parser/SAXParser.h>
-static void
-primaryEndElement(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
+struct myParser : public zypp::parser::SAXParser
{
-}
-
-struct SAXParserBase
-{
- static void
- startElement_receiver(void *ctx, const xmlChar *name, const xmlChar **atts)
- {
- SAXParserBase *rcv = (SAXParserBase *) ctx;
- rcv->startElement(std::string( (const char*) name), atts);
- }
-
- static void
- endElement_receiver(void *ctx, const xmlChar *name)
- {
- SAXParserBase *rcv = (SAXParserBase *) ctx;
- rcv->endElement(std::string( (const char*) name));
- }
-
- virtual void startElement(const std::string name, const xmlChar **atts)
- {
- MIL << name << std::endl;
- }
-
- virtual void endElement(const std::string name)
- {
- MIL << name << std::endl;
- }
-
- private:
- xmlSAXHandler _saxHandler;
-
- public:
-
- void parseFile( const Pathname &p)
- {
- FILE *f = fopen(p.asString().c_str(), "r");
- if (f != NULL)
- {
- int res = xmlSAXUserParseFile(&_saxHandler, (void *) this, p.asString().c_str());
- if (res != 0)
- {
- fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
- }
- fclose(f);
- }
- else
- {
- fprintf(stdout, "UPS\n");
- }
- }
-
-// void parseFileByChunk( const Pathname &p)
-// {
-// FILE *f = fopen(p.asString().c_str(), "r");
-// if (f != NULL)
-// {
-// int ret;
-// char chars[10];
-// xmlParserCtxtPtr ctxt;
-//
-// ret = fread(chars, 1, 4, f);
-// if (ret > 0)
-// {
-// ctxt = xmlCreatePushParserCtxt(&_saxHandler, NULL,
-// chars, ret, p.asString().c_str());
-// while ((ret = fread(chars, 1, 3, f)) > 0)
-// {
-// xmlParseChunk(ctxt, chars, ret, 0);
-// }
-// ret = xmlParseChunk(ctxt, chars, 0, 1);
-// xmlFreeParserCtxt(ctxt);
-// if (ret != 0)
-// {
-// fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", ret);
-// }
-// }
-// fclose(f);
-// }
-// else
-// {
-// fprintf(stdout, "UPS\n");
-// }
-// }
-
- SAXParserBase()
- {
- _saxHandler.internalSubset = NULL;
- _saxHandler.isStandalone = NULL;
- _saxHandler.hasInternalSubset = NULL;
- _saxHandler.hasExternalSubset = NULL;
- _saxHandler.resolveEntity = NULL;
- _saxHandler.getEntity = NULL;
- _saxHandler.entityDecl = NULL;
- _saxHandler.notationDecl = NULL;
- _saxHandler.attributeDecl = NULL;
- _saxHandler.elementDecl = NULL;
- _saxHandler.unparsedEntityDecl = NULL;
- _saxHandler.setDocumentLocator = NULL;
- _saxHandler.startDocument = NULL;
- _saxHandler.endDocument = NULL;
- _saxHandler.startElement = NULL;
- _saxHandler.endElement = NULL;
- _saxHandler.reference = NULL;
- _saxHandler.characters = NULL;
- _saxHandler.ignorableWhitespace = NULL;
- _saxHandler.processingInstruction = NULL;
- _saxHandler.comment = NULL;
-
- //_saxHandler.xmlParserWarning = NULL;
- //_saxHandler.xmlParserError = NULL;
- //_saxHandler.xmlParserError = NULL;
-
- _saxHandler.getParameterEntity = NULL;
- _saxHandler.cdataBlock = NULL;
- _saxHandler.externalSubset = NULL;
-
- _saxHandler = emptySAXHandlerStruct;
- //_saxHandler.startDocument = startElement_receiver;
- _saxHandler.startElement = startElement_receiver;
- _saxHandler.endElement = endElement_receiver;
- }
-
- virtual ~SAXParserBase()
- {
- }
+
};
-
-struct myParser : public SAXParserBase
-{
-
-};
-
-
int main()
{
myParser parser;
/** Creates a source cache */
SourceCache( const Pathname &root_r, const std::string alias );
~SourceCache();
+
void cachePattern( const data::Pattern pattern );
void cachePackage( const data::Package package );
protected:
parserincludedir = $(pkgincludedir)/data
parserinclude_HEADERS = \
- ResolvableData.h
+ ResolvableData.h \
+ ResolvableDataConsumer.h
noinst_LTLIBRARIES = lib@PACKAGE@_data.la
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPP_ResolvableDataConsumer_H
+#define ZYPP_ResolvableDataConsumer_H
+
+
+
+#include "zypp/data/ResolvableData.h"
+
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+namespace data
+{ /////////////////////////////////////////////////////////////////
+
+ class ResolvableDataConsumer
+ {
+ public:
+
+ ResolvableDataConsumer();
+ virtual ~ResolvableDataConsumer();
+
+ virtual void consumePackage( const data::Package &package) = 0;
+
+ };
+
+} // namespace parser
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_ResolvableDataConsumer_H
## Process this file with automake to produce Makefile.in
## ##################################################
-SUBDIRS = yum tagfile xmlstore
+SUBDIRS = yum2 yum tagfile xmlstore
INCLUDES = -I$(oldincludedir)/libxml2 \
-DZYPP_BASE_LOGGER_LOGGROUP=\"parser\"
SAXParser.cc
lib@PACKAGE@_parser_la_LIBADD = yum/lib@PACKAGE@_parser_yum.la \
+ yum2/lib@PACKAGE@_parser_yum2.la \
-lxml2 \
-lz \
tagfile/lib@PACKAGE@_parser_tagfile.la \
--- /dev/null
+## Process this file with automake to produce Makefile.in
+## ##################################################
+
+SUBDIRS =
+
+INCLUDES = -I$(oldincludedir)/libxml2 -I.. \
+ -DZYPP_BASE_LOGGER_LOGGROUP=\"parser-yum2\"
+
+## ##################################################
+
+parseryum2includedir = $(pkgincludedir)/parser/yum2
+
+parseryum2include_HEADERS = \
+ YUMPrimaryParser.h
+
+noinst_LTLIBRARIES = lib@PACKAGE@_parser_yum2.la
+
+## ##################################################
+
+lib@PACKAGE@_parser_yum2_la_SOURCES = \
+ YUMPrimaryParser.cc
+
+## ##################################################
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+
+#include "zypp/parser/yum2/YUMPrimaryParser.h"
+#include "zypp/data/ResolvableData.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+namespace parser
+{ /////////////////////////////////////////////////////////////////
+namespace yum2
+{ /////////////////////////////////////////////////////////////////
+
+ YUMPrimaryParser::YUMPrimaryParser( zypp::data::ResolvableDataConsumer &consumer )
+ {
+ _consumer.reset(&consumer);
+ }
+
+ void YUMPrimaryParser::startElement(const std::string name, const xmlChar **atts)
+ {
+ if ( name == "package" )
+ _package.reset(new zypp::data::Package());
+ }
+
+ void YUMPrimaryParser::characters(const xmlChar *ch, int len)
+ {
+ //MIL << "append buffer :" << len << " [" << ( (len < 20) ? string((const char *)(ch), len) : "" ) << "]" << std::endl;
+ _buffer.append( (const char *)ch, len);
+ }
+
+ void YUMPrimaryParser::endElement(const std::string name)
+ {
+ if ( name == "name" )
+ _package->name = _buffer;
+ if ( name == "arch" )
+ _package->arch = Arch(_buffer);
+
+ if ( name == "package" )
+ {
+ _consumer->consumePackage(*_package);
+ }
+
+ _buffer.clear();
+ }
+
+
+} // namespace yum2
+} // namespace parser
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPP_YUMPrimaryParser_H
+#define ZYPP_YUMPrimaryParser_H
+
+#include "zypp/parser/SAXParser.h"
+#include "zypp/data/ResolvableDataConsumer.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+namespace parser
+{ /////////////////////////////////////////////////////////////////
+namespace yum2
+{ /////////////////////////////////////////////////////////////////
+
+ class YUMPrimaryParser : public parser::SAXParser
+ {
+ public:
+
+ YUMPrimaryParser( zypp::data::ResolvableDataConsumer &consumer );
+ virtual void startElement(const std::string name, const xmlChar **atts);
+ virtual void characters(const xmlChar *ch, int len);
+ virtual void endElement(const std::string name);
+
+ private:
+ shared_ptr<zypp::data::Package> _package;
+ shared_ptr<zypp::data::ResolvableDataConsumer> _consumer;
+ std::string _buffer;
+ };
+
+
+} // namespace yum2
+} // namespace parser
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_YUMPrimaryParser_H
#include "zypp/parser/yum/YUMParser.h"
#include "zypp/parser/SAXParser.h"
+#include "zypp/parser/yum/YUMParser.h"
+#include "zypp/parser/yum2/YUMPrimaryParser.h"
#include "zypp/source/yum/YUMSourceCacher.h"
using namespace std;
-using namespace zypp::parser::yum;
//////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
-class YUMPrimaryReader : public parser::SAXParser
-{
- public:
- YUMPrimaryReader( YUMSourceCacher &cacher )
- {
- _cacher.reset(&cacher);
- }
-
- virtual void startElement(const std::string name, const xmlChar **atts)
- {
- if ( name == "package" )
- _package.reset(new zypp::data::Package());
- }
-
- virtual void characters(const xmlChar *ch, int len)
- {
- _buffer.append( (const char *)ch, len);
- }
-
- virtual void endElement(const std::string name)
- {
- if ( name == "name" )
- _package->name = popBuffer();
- if ( name == "arch" )
- _package->arch = Arch(popBuffer());
-
- if ( name == "package" )
- {
- _cacher->packageParsed(*_package);
- }
- }
-
- std::string popBuffer()
- {
- std::string rt = _buffer;
- _buffer.clear();
- return rt;
- }
-
- private:
- shared_ptr<zypp::data::Package> _package;
- shared_ptr<YUMSourceCacher> _cacher;
- std::string _buffer;
-};
-
YUMSourceCacher::YUMSourceCacher( const Pathname &root_r ) : zypp::cache::SourceCacher(root_r)
{
{
}
-void YUMSourceCacher::packageParsed( const data::Package &package)
+void YUMSourceCacher::consumePackage( const data::Package &package)
{
- MIL << "caching " << package << std::endl;
+ MIL << "caching " << package.name << " " << package.arch << std::endl;
}
void YUMSourceCacher::cache( const Url &url, const Pathname &path )
{
filesystem::TmpDir tmpdir = downloadMetadata(url, path);
- YUMPrimaryReader reader(*this);
+ parser::yum2::YUMPrimaryParser reader(*this);
reader.parseFile( tmpdir.path() + "/repodata/primary.xml.gz");
}
DBG << "Reading file " << remote_repomd << endl;
ifstream repo_st(remote_repomd.asString().c_str());
- YUMRepomdParser repomd(repo_st, "");
+ parser::yum::YUMRepomdParser repomd(repo_st, "");
for(; ! repomd.atEnd(); ++repomd)
{
Pathname patches_list = local_dir + (*repomd)->location;
MIL << "Reading patches file " << patches_list << std::endl;
ifgzstream st ( patches_list.asString().c_str() );
- YUMPatchesParser patch(st, "");
+ parser::yum::YUMPatchesParser patch(st, "");
for (; !patch.atEnd(); ++patch)
{
#include "zypp/cache/SourceCacher.h"
#include "zypp/data/ResolvableData.h"
+#include "zypp/data/ResolvableDataConsumer.h"
#include "zypp/Pathname.h"
#include "zypp/TmpPath.h"
//
// CLASS NAME : SourceCacher
//
- class YUMSourceCacher : public cache::SourceCacher
+ class YUMSourceCacher : public cache::SourceCacher, public data::ResolvableDataConsumer
{
friend std::ostream & operator<<( std::ostream & str, const YUMSourceCacher & obj );
~YUMSourceCacher();
void cache( const Url &url, const Pathname &path );
- void packageParsed( const data::Package &package);
+ void consumePackage( const data::Package &package);
protected:
filesystem::TmpDir downloadMetadata(const Url &url, const Pathname &path);