YUMFileListParser.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00015 #include <zypp/parser/yum/YUMFileListParser.h>
00016 #include <istream>
00017 #include <string>
00018 #include "zypp/parser/xml_parser_assert.h"
00019 #include <libxml/xmlstring.h>
00020 #include <libxml/xmlreader.h>
00021 #include <libxml/tree.h>
00022 #include <zypp/parser/LibXMLHelper.h>
00023 #include <zypp/parser/yum/schemanames.h>
00024 #include <iostream>
00025 #include <zypp/base/Logger.h>
00026 #include <zypp/ZYppFactory.h>
00027 
00028 
00029 using namespace std;
00030 namespace zypp {
00031   namespace parser {
00032     namespace yum {
00033 
00034 
00035       YUMFileListParser::YUMFileListParser(istream &is, const string& baseUrl)
00036       : XMLNodeIterator<YUMFileListData_Ptr>(is, baseUrl,FILELISTSCHEMA)
00037         , _zypp_architecture( getZYpp()->architecture() )
00038       {
00039         fetchNext();
00040       }
00041 
00042       YUMFileListParser::YUMFileListParser()
00043         : _zypp_architecture( getZYpp()->architecture() )
00044       { }
00045 
00046       YUMFileListParser::YUMFileListParser(YUMFileListData_Ptr& entry)
00047       : XMLNodeIterator<YUMFileListData_Ptr>(entry)
00048         , _zypp_architecture( getZYpp()->architecture() )
00049       { }
00050 
00051 
00052 
00053       YUMFileListParser::~YUMFileListParser()
00054       {
00055       }
00056 
00057 
00058 
00059 
00060       // select for which elements process() will be called
00061       bool
00062       YUMFileListParser::isInterested(const xmlNodePtr nodePtr)
00063       {
00064         bool result = (_helper.isElement(nodePtr)
00065                        && _helper.name(nodePtr) == "package");
00066         return result;
00067       }
00068 
00069 
00070       // do the actual processing
00071       YUMFileListData_Ptr
00072       YUMFileListParser::process(const xmlTextReaderPtr reader)
00073       {
00074         xml_assert(reader);
00075         YUMFileListData_Ptr dataPtr = new YUMFileListData;
00076         xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00077         xml_assert(dataNode);
00078 
00079         dataPtr->pkgId = _helper.attribute(dataNode,"pkgid");
00080         dataPtr->name = _helper.attribute(dataNode,"name");
00081         dataPtr->arch = _helper.attribute(dataNode,"arch");
00082         try {
00083             if (!Arch(dataPtr->arch).compatibleWith( _zypp_architecture )) {
00084                 dataPtr = NULL;                 // skip <package>, incompatible architecture
00085                 return dataPtr;
00086             }
00087         }
00088         catch( const Exception & excpt_r ) {
00089             ZYPP_CAUGHT( excpt_r );
00090             DBG << "Skipping malformed " << dataPtr->arch << endl;
00091             dataPtr = NULL;
00092             return dataPtr;
00093         }
00094 
00095         for (xmlNodePtr child = dataNode->children;
00096             child != 0;
00097             child = child->next)
00098         {
00099             if (_helper.isElement(child)) {
00100                 string name = _helper.name(child);
00101                 if (name == "version") {
00102                     dataPtr->epoch = _helper.attribute(child,"epoch");
00103                     dataPtr->ver = _helper.attribute(child,"ver");
00104                     dataPtr->rel = _helper.attribute(child,"rel");
00105                 }
00106                 else if (name == "file") {
00107                     string filename = _helper.content( child );
00108                     if (filename.find("/bin/") != string::npos
00109                         || filename.find("/sbin/") != string::npos
00110                         || filename.find("/lib/") != string::npos
00111                         || filename.find("/lib64/") != string::npos
00112                         || filename.find("/etc/") != string::npos
00113                         || filename.find("/usr/games/") != string::npos
00114                         || filename.find("/usr/share/dict/words") != string::npos
00115                         || filename.find("/usr/share/magic.mime") != string::npos
00116                         || filename.find("/opt/gnome/games") != string::npos)
00117                     {
00118                         dataPtr->files.push_back( FileData( filename, _helper.attribute( child, "type" ) ) );
00119                     }
00120                 }
00121                 else {
00122                    WAR << "YUM <filelists> contains the unknown element <" << name << "> "
00123                      << _helper.positionInfo(child) << ", skipping" << endl;
00124                 }
00125             }
00126         }
00127         return dataPtr;
00128       }
00129 
00130 
00131     } // namespace yum
00132   } // namespace parser
00133 } // namespace zypp

Generated on Thu Jul 6 00:07:21 2006 for zypp by  doxygen 1.4.6