00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00013 #include <zypp/parser/yum/YUMPatchesParser.h> 00014 #include <zypp/parser/yum/YUMPrimaryParser.h> 00015 #include <istream> 00016 #include <string> 00017 #include "zypp/parser/xml_parser_assert.h" 00018 #include <libxml/xmlreader.h> 00019 #include <libxml/tree.h> 00020 #include <zypp/parser/LibXMLHelper.h> 00021 #include <zypp/base/Logger.h> 00022 #include <zypp/parser/yum/schemanames.h> 00023 00024 using namespace std; 00025 namespace zypp { 00026 namespace parser { 00027 namespace yum { 00028 00029 YUMPatchesParser::~YUMPatchesParser() 00030 { } 00031 00032 YUMPatchesParser::YUMPatchesParser(istream &is, const string& baseUrl) 00033 : XMLNodeIterator<YUMPatchesData_Ptr>(is, baseUrl,PATCHESSCHEMA) 00034 { 00035 fetchNext(); 00036 } 00037 00038 YUMPatchesParser::YUMPatchesParser() 00039 { } 00040 00041 YUMPatchesParser::YUMPatchesParser(YUMPatchesData_Ptr& entry) 00042 : XMLNodeIterator<YUMPatchesData_Ptr>(entry) 00043 { } 00044 00045 00046 // select for which elements process() will be called 00047 bool 00048 YUMPatchesParser::isInterested(const xmlNodePtr nodePtr) 00049 { 00050 return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "patch"; 00051 } 00052 00053 // do the actual processing 00054 YUMPatchesData_Ptr 00055 YUMPatchesParser::process(const xmlTextReaderPtr reader) 00056 { 00057 xml_assert(reader); 00058 YUMPatchesData_Ptr patchPtr = new YUMPatchesData; 00059 xmlNodePtr dataNode = xmlTextReaderExpand(reader); 00060 xml_assert(dataNode); 00061 00062 patchPtr->id = _helper.attribute(dataNode,"id"); 00063 00064 for (xmlNodePtr child = dataNode->children; 00065 child && child != dataNode; 00066 child = child->next) { 00067 if (_helper.isElement(child)) { 00068 string name = _helper.name(child); 00069 if (name == "location") { 00070 patchPtr->location = _helper.attribute(child,"href"); 00071 } 00072 else if (name == "checksum") { 00073 patchPtr->checksumType = _helper.attribute(child,"type"); 00074 patchPtr->checksum = _helper.content(child); 00075 } 00076 else { 00077 WAR << "YUM <data> contains the unknown element <" << name << "> " 00078 << _helper.positionInfo(child) << ", skipping" << endl; 00079 } 00080 } 00081 } 00082 return patchPtr; 00083 } /* end process */ 00084 00085 00086 } // namespace yum 00087 } // namespace parser 00088 } // namespace zypp