Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __XML_BASE_H__ 6 : #define __XML_BASE_H__ 7 : 8 : #include "base/util.h" 9 : 10 : class XmlBase { 11 : 12 : public: 13 : // Set new xml doc. Null string means reset to new doc. 14 : // Resets previous doc 15 : virtual int LoadDoc(const std::string &doc) = 0; 16 : 17 : // returns bytes encoded. -1 for error. 18 : virtual int WriteDoc(uint8_t *buf)= 0; 19 : virtual int WriteRawDoc(uint8_t *buf) = 0; 20 : 21 : // prints the xml doc to ostream 22 : virtual void PrintDoc(std::ostream& os) const = 0; 23 : 24 : // Create child node and move node context to new node 25 : virtual int AddChildNode(const std::string &key, const std::string &value) = 0; 26 : 27 : // Create child node after node-name and move node context to new node 28 : virtual int AddChildNodeAfter(const std::string &node_name, 29 : const std::string &key, const std::string &value) = 0; 30 : 31 : // Create new node as sibling of node in context. Set context to new node 32 : virtual int AddNode(const std::string &key, const std::string &value) = 0; 33 : 34 : // Delete node 35 : virtual int DeleteNode(const std::string &key) = 0; 36 : 37 : // Find child node by key and set its value. Set context to new node. 38 : virtual int ModifyNode(const std::string &key, const std::string &value) = 0; 39 : 40 : // Add attriburte to current node context. Sets context to new attrib. 41 : virtual int AddAttribute(const std::string &key, const std::string &value) = 0; 42 : 43 : // Modify attriburte to current node context. Sets context to new attrib. 44 : virtual int ModifyAttribute(const std::string &key, const std::string &value) = 0; 45 : 46 : // Delete attribute, if exist, at current node context. Sets context to 47 : // next available attrib. 48 : virtual int DeleteAttribute(const std::string &key) = 0; 49 : 50 : // Return 'value' of given node 'name'. Set context to given node. 51 : virtual const char *ReadNode(const std::string &name) = 0; 52 : 53 : // Return 'value' of given node 'name'. Set context to given node. 54 : virtual const char *ReadNodeName(const std::string &name) = 0; 55 : 56 : // Return 'value' of given node. 57 : virtual const char *ReadNodeValue() = 0; 58 : 59 : // Moves node context to first child node. 60 : virtual const char *ReadChildNode() = 0; 61 : 62 : // Moves node context to first child node. 63 : virtual const char *ReadChildNodeName() = 0; 64 : 65 : // Get next sibling. Moves node context to next sibling 66 : virtual const char *ReadNextNode() = 0; 67 : 68 : // Get next sibling. Moves node context to next sibling 69 : virtual const char *ReadNextNodeName() = 0; 70 : 71 : // Moves node context to immediate parent 72 : virtual void RewindNode() = 0; 73 : 74 : virtual const char *ReadAttrib(const std::string &str) = 0; 75 : virtual const char *ReadFirstAttrib() = 0; 76 : virtual const char *ReadNextAttrib() = 0; 77 : virtual void RewindAttrib() = 0; 78 : 79 : // Get Parent node. Move node context to parent 80 : virtual const char *ReadParentName() = 0; 81 : 82 : virtual void RewindDoc() = 0; 83 : virtual void AppendDoc(const std::string &str, XmlBase *a_doc) = 0; 84 : 85 4255812 : virtual ~XmlBase() { } 86 4255793 : XmlBase() {} 87 : }; 88 : 89 : struct XmppXmlImplFactory { 90 : public: 91 : 92 : XmlBase *GetXmlImpl() ; 93 : void ReleaseXmlImpl(XmlBase *tmp); 94 : 95 : static XmppXmlImplFactory *Instance(); 96 : 97 : private: 98 : //singleton 99 362 : XmppXmlImplFactory() { } 100 : static XmppXmlImplFactory *Inst_; 101 : 102 : DISALLOW_COPY_AND_ASSIGN(XmppXmlImplFactory); 103 : }; 104 : 105 : #endif // __XML_BASE_H__