hiding impl of PatchesFileReader
[platform/upstream/libzypp.git] / zypp / parser / yum / PatchesFileReader.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/yum/PatchesFileReader.cc
10  * Implementation of patches.xml file reader.
11  */
12 #include "zypp/base/String.h"
13 #include "zypp/base/Logger.h"
14
15 #include "zypp/Date.h"
16 #include "zypp/CheckSum.h"
17 #include "zypp/OnMediaLocation.h"
18
19 #include "zypp/parser/xml/Reader.h"
20 #include "zypp/parser/yum/PatchesFileReader.h"
21
22
23 using namespace std;
24 using namespace zypp::xml;
25
26 namespace zypp
27 {
28   namespace parser
29   {
30     namespace yum
31     {
32
33
34   enum Tag
35   {
36     tag_NONE,
37     tag_Patches,
38     tag_Patch,
39     tag_Location,
40     tag_CheckSum,
41     tag_Timestamp,
42     tag_OpenCheckSum
43   };
44
45
46   ///////////////////////////////////////////////////////////////////////
47   //
48   //  CLASS NAME : PatchesFileReader::Impl
49   //
50   class PatchesFileReader::Impl : private base::NonCopyable
51   {
52   public:
53    /**
54     * CTOR
55     */
56     Impl(const Pathname &patches_file, const ProcessResource & callback);
57
58     /**
59     * Callback provided to the XML parser. Don't use it.
60     */
61     bool consumeNode( Reader & reader_r );
62     
63   private:
64     OnMediaLocation _location;
65     Tag _tag;
66     std::string _id;
67     ProcessResource _callback;
68     CheckSum _checksum;
69     std::string _checksum_type;
70     Date _timestamp;
71   };
72   ///////////////////////////////////////////////////////////////////////
73
74
75   PatchesFileReader::Impl::Impl(const Pathname & patches_file,
76                                 const ProcessResource & callback)
77     : _tag(tag_NONE), _callback(callback)
78   {
79     Reader reader( patches_file );
80     MIL << "Reading " << patches_file << endl;
81     reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
82   }
83
84   // --------------------------------------------------------------------------
85
86   bool PatchesFileReader::Impl::consumeNode( Reader & reader_r )
87   {
88     //MIL << reader_r->name() << endl;
89     std::string data_type;
90     if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
91     {
92       if ( reader_r->name() == "patches" )
93       {
94         _tag = tag_Patches;
95         return true;
96       }
97       if ( reader_r->name() == "patch" )
98       {
99         _tag = tag_Patch;
100         _id = reader_r->getAttribute("id").asString();
101         return true;
102       }
103       if ( reader_r->name() == "location" )
104       {
105         _tag = tag_Location;
106         _location.filename( reader_r->getAttribute("href").asString() );
107         return true;
108       }
109       if ( reader_r->name() == "checksum" )
110       {
111         _tag = tag_CheckSum;
112         string checksum_type = reader_r->getAttribute("type").asString() ;
113         string checksum_vaue = reader_r.nodeText().asString();
114         _location.checksum( CheckSum( checksum_type, checksum_vaue ) );
115         return true;
116       }
117       if ( reader_r->name() == "timestamp" )
118       {
119         // ignore it
120         return true;
121       }
122     }
123     else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
124     {
125       //MIL << "end element" << endl;
126       if ( reader_r->name() == "patch" )
127         _callback( _location, _id );
128       return true;
129     }
130     return true;
131   }
132
133
134   ///////////////////////////////////////////////////////////////////
135   //
136   //  CLASS NAME : PatchesFileReader
137   //
138   ///////////////////////////////////////////////////////////////////
139
140   PatchesFileReader::PatchesFileReader(const Pathname & patches_file,
141                                        const ProcessResource & callback)
142     : _pimpl(new Impl(patches_file, callback))
143   {}
144   
145   PatchesFileReader::~PatchesFileReader()
146   {}
147
148
149     } // ns yum
150   } // ns parser
151 } // ns zypp
152
153 // vim: set ts=2 sts=2 sw=2 et ai: