libzypp  13.10.6
PatchesFileReader.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include "zypp/base/String.h"
15 #include "zypp/base/Logger.h"
16 
17 #include "zypp/Date.h"
18 #include "zypp/CheckSum.h"
19 #include "zypp/OnMediaLocation.h"
20 
21 #include "zypp/parser/xml/Reader.h"
23 
24 
25 using namespace std;
26 using namespace zypp::xml;
27 
28 namespace zypp
29 {
30  namespace parser
31  {
32  namespace yum
33  {
34 
35 
36  enum Tag
37  {
45  };
46 
47 
49  //
50  // CLASS NAME : PatchesFileReader::Impl
51  //
53  {
54  public:
58  Impl(const Pathname &patches_file, const ProcessResource & callback);
59 
63  bool consumeNode( Reader & reader_r );
64 
65  private:
68  std::string _id;
71  std::string _checksum_type;
73  };
75 
76 
77  PatchesFileReader::Impl::Impl(const Pathname & patches_file,
78  const ProcessResource & callback)
79  : _tag(tag_NONE), _callback(callback)
80  {
81  Reader reader( patches_file );
82  MIL << "Reading " << patches_file << endl;
83  reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
84  }
85 
86  // --------------------------------------------------------------------------
87 
89  {
90  //MIL << reader_r->name() << endl;
91  std::string data_type;
92  if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
93  {
94  if ( reader_r->name() == "patches" )
95  {
96  _tag = tag_Patches;
97  return true;
98  }
99  if ( reader_r->name() == "patch" )
100  {
101  _tag = tag_Patch;
102  _id = reader_r->getAttribute("id").asString();
103  return true;
104  }
105  if ( reader_r->name() == "location" )
106  {
107  _tag = tag_Location;
108  _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
109  return true;
110  }
111  if ( reader_r->name() == "checksum" )
112  {
113  _tag = tag_CheckSum;
114  string checksum_type = reader_r->getAttribute("type").asString() ;
115  string checksum_vaue = reader_r.nodeText().asString();
116  _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
117  return true;
118  }
119  if ( reader_r->name() == "timestamp" )
120  {
121  // ignore it
122  return true;
123  }
124  }
125  else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
126  {
127  //MIL << "end element" << endl;
128  if ( reader_r->name() == "patch" )
129  _callback( _location, _id );
130  return true;
131  }
132  return true;
133  }
134 
135 
137  //
138  // CLASS NAME : PatchesFileReader
139  //
141 
142  PatchesFileReader::PatchesFileReader(const Pathname & patches_file,
143  const ProcessResource & callback)
144  : _pimpl(new Impl(patches_file, callback))
145  {}
146 
148  {}
149 
150 
151  } // ns yum
152  } // ns parser
153 } // ns zypp
154 
155 // vim: set ts=2 sts=2 sw=2 et ai:
#define MIL
Definition: Logger.h:47
Describes a path on a certain media amongs as the information required to download it...
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Store and operate on date (time_t).
Definition: Date.h:31
bool consumeNode(Reader &reader_r)
Callback provided to the XML parser.
XmlString name() const
The qualified name of the node, equal to Prefix :LocalName.
Definition: Node.h:115
Interface of patches.xml file reader.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
std::string asString() const
Explicit conversion to std::string.
Definition: XmlString.h:77
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
Definition: Node.h:71
XmlString nodeText()
If the curent node is not empty, advances the reader to the next node, and returns the value...
Definition: Reader.cc:140
bool foreachNode(ProcessNode fnc_r)
Definition: Reader.h:144
PatchesFileReader(const Pathname &patches_file, const ProcessResource &callback)
CTOR.
function< bool(const OnMediaLocation &, const std::string &)> ProcessResource
Callback definition first parameter is a OnMediaLocation object with the resource second parameter is...
NodeType nodeType() const
Get the node type of the current node.
Definition: Node.h:123
xmlTextReader based interface to iterate xml streams.
Definition: Reader.h:95