libzypp  10.5.0
PatchesFileReader.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 
00014 #include "zypp/base/String.h"
00015 #include "zypp/base/Logger.h"
00016 
00017 #include "zypp/Date.h"
00018 #include "zypp/CheckSum.h"
00019 #include "zypp/OnMediaLocation.h"
00020 
00021 #include "zypp/parser/xml/Reader.h"
00022 #include "zypp/parser/yum/PatchesFileReader.h"
00023 
00024 
00025 using namespace std;
00026 using namespace zypp::xml;
00027 
00028 namespace zypp
00029 {
00030   namespace parser
00031   {
00032     namespace yum
00033     {
00034 
00035 
00036   enum Tag
00037   {
00038     tag_NONE,
00039     tag_Patches,
00040     tag_Patch,
00041     tag_Location,
00042     tag_CheckSum,
00043     tag_Timestamp,
00044     tag_OpenCheckSum
00045   };
00046 
00047 
00049   //
00050   //  CLASS NAME : PatchesFileReader::Impl
00051   //
00052   class PatchesFileReader::Impl : private base::NonCopyable
00053   {
00054   public:
00058     Impl(const Pathname &patches_file, const ProcessResource & callback);
00059 
00063     bool consumeNode( Reader & reader_r );
00064 
00065   private:
00066     OnMediaLocation _location;
00067     Tag _tag;
00068     std::string _id;
00069     ProcessResource _callback;
00070     CheckSum _checksum;
00071     std::string _checksum_type;
00072     Date _timestamp;
00073   };
00075 
00076 
00077   PatchesFileReader::Impl::Impl(const Pathname & patches_file,
00078                                 const ProcessResource & callback)
00079     : _tag(tag_NONE), _callback(callback)
00080   {
00081     Reader reader( patches_file );
00082     MIL << "Reading " << patches_file << endl;
00083     reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
00084   }
00085 
00086   // --------------------------------------------------------------------------
00087 
00088   bool PatchesFileReader::Impl::consumeNode( Reader & reader_r )
00089   {
00090     //MIL << reader_r->name() << endl;
00091     std::string data_type;
00092     if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
00093     {
00094       if ( reader_r->name() == "patches" )
00095       {
00096         _tag = tag_Patches;
00097         return true;
00098       }
00099       if ( reader_r->name() == "patch" )
00100       {
00101         _tag = tag_Patch;
00102         _id = reader_r->getAttribute("id").asString();
00103         return true;
00104       }
00105       if ( reader_r->name() == "location" )
00106       {
00107         _tag = tag_Location;
00108         _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
00109         return true;
00110       }
00111       if ( reader_r->name() == "checksum" )
00112       {
00113         _tag = tag_CheckSum;
00114         string checksum_type = reader_r->getAttribute("type").asString() ;
00115         string checksum_vaue = reader_r.nodeText().asString();
00116         _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
00117         return true;
00118       }
00119       if ( reader_r->name() == "timestamp" )
00120       {
00121         // ignore it
00122         return true;
00123       }
00124     }
00125     else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
00126     {
00127       //MIL << "end element" << endl;
00128       if ( reader_r->name() == "patch" )
00129         _callback( _location, _id );
00130       return true;
00131     }
00132     return true;
00133   }
00134 
00135 
00137   //
00138   //  CLASS NAME : PatchesFileReader
00139   //
00141 
00142   PatchesFileReader::PatchesFileReader(const Pathname & patches_file,
00143                                        const ProcessResource & callback)
00144     : _pimpl(new Impl(patches_file, callback))
00145   {}
00146 
00147   PatchesFileReader::~PatchesFileReader()
00148   {}
00149 
00150 
00151     } // ns yum
00152   } // ns parser
00153 } // ns zypp
00154 
00155 // vim: set ts=2 sts=2 sw=2 et ai: