Line data Source code
1 : /* 2 : * Distributed under the OpenDDS License. 3 : * See: http://www.OpenDDS.org/license.html 4 : */ 5 : 6 : #ifndef OPENDDS_DCPS_SECURITY_ACCESS_CONTROL_XML_UTILS_H 7 : #define OPENDDS_DCPS_SECURITY_ACCESS_CONTROL_XML_UTILS_H 8 : 9 : #include "DomainIdSet.h" 10 : 11 : #include <dds/Versioned_Namespace.h> 12 : #include <dds/DCPS/SafetyProfileStreams.h> 13 : #include <dds/DCPS/unique_ptr.h> 14 : #include <dds/DCPS/security/OpenDDS_Security_Export.h> 15 : 16 : #include <ace/XML_Utils/XercesString.h> 17 : 18 : #include <xercesc/dom/DOM.hpp> 19 : #include <xercesc/util/XMLDateTime.hpp> 20 : #include <xercesc/parsers/XercesDOMParser.hpp> 21 : #include <xercesc/sax/SAXParseException.hpp> 22 : 23 : #include <string> 24 : #include <ctime> 25 : 26 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 27 : 28 : namespace OpenDDS { 29 : namespace Security { 30 : namespace XmlUtils { 31 : 32 : typedef DCPS::unique_ptr<xercesc::XercesDOMParser> ParserPtr; 33 : 34 : OpenDDS_Security_Export 35 : bool get_parser(ParserPtr& parser, const std::string& filename, const std::string& xml); 36 : 37 : OpenDDS_Security_Export 38 : std::string to_string(const XMLCh* in); 39 : 40 : OpenDDS_Security_Export 41 : bool parse_bool(const XMLCh* in, bool& value); 42 : 43 : OpenDDS_Security_Export 44 : bool parse_time(const XMLCh* in, time_t& value); 45 : 46 : OpenDDS_Security_Export 47 : std::string to_string(const xercesc::SAXParseException& ex); 48 : 49 0 : inline std::string to_string(const xercesc::XMLException& ex) 50 : { 51 0 : return to_string(ex.getMessage()); 52 : } 53 : 54 0 : inline std::string to_string(const xercesc::DOMException& ex) 55 : { 56 0 : return to_string(ex.getMessage()); 57 : } 58 : 59 319 : inline std::string to_string(const xercesc::DOMNode* node) 60 : { 61 319 : return to_string(node->getTextContent()); 62 : } 63 : 64 188 : inline bool parse_bool(const xercesc::DOMNode* node, bool& value) 65 : { 66 188 : return parse_bool(node->getTextContent(), value); 67 : } 68 : 69 : inline bool parse_time(const xercesc::DOMNode* node, time_t& value) 70 : { 71 : return parse_time(node->getTextContent(), value); 72 : } 73 : 74 : /** 75 : * Convert a node that's a DomainIdSet in the permissions and governance XML 76 : * Schema in the security spec to a std::set of domain ids. 77 : */ 78 : OpenDDS_Security_Export 79 : bool parse_domain_id_set(const xercesc::DOMNode* node, Security::DomainIdSet& domain_id_set); 80 : 81 150 : inline bool is_element(const xercesc::DOMNode* node) 82 : { 83 150 : return node->getNodeType() == xercesc::DOMNode::ELEMENT_NODE; 84 : } 85 : 86 : } // namespace XMLUtils 87 : } // namespace Security 88 : } // namespace OpenDDS 89 : 90 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 91 : 92 : #endif