13 #include <xercesc/framework/MemBufInputSource.hpp> 14 #include <xercesc/sax/ErrorHandler.hpp> 15 #include <xercesc/util/XMLDateTime.hpp> 16 #include <xercesc/util/PlatformUtils.hpp> 17 #include <xercesc/util/XercesVersion.hpp> 30 std::string
to_string(
const xercesc::SAXParseException& ex)
40 class ErrorHandler :
public xercesc::ErrorHandler {
42 void warning(
const xercesc::SAXParseException& ex)
46 "XmlUtils::ErrorHandler: %C\n",
51 void error(
const xercesc::SAXParseException& ex)
55 "XmlUtils::ErrorHandler: %C\n",
60 void fatalError(
const xercesc::SAXParseException& ex)
76 }
catch (
const xercesc::XMLException& ex) {
79 "XMLPlatformUtils::Initialize XMLException: %C\n",
86 parser.
reset(
new xercesc::XercesDOMParser());
88 parser->setDoNamespaces(
true);
89 parser->setIncludeIgnorableWhitespace(
false);
90 parser->setCreateCommentNodes(
false);
92 ErrorHandler error_handler;
93 parser->setErrorHandler(&error_handler);
95 xercesc::MemBufInputSource contentbuf(
96 reinterpret_cast<const XMLByte*>(xml.c_str()), xml.size(), filename.c_str());
99 parser->parse(contentbuf);
101 }
catch (
const xercesc::XMLException& ex) {
104 "XMLException while parsing \"%C\": %C\n",
105 filename.c_str(),
to_string(ex).c_str()));
110 }
catch (
const xercesc::DOMException& ex) {
113 "DOMException while parsing \"%C\": %C\n",
114 filename.c_str(),
to_string(ex).c_str()));
122 "Unexpected exception while parsing \"%C\"",
129 if (!parser->getDocument()->getDocumentElement()) {
132 "XML document \"%C\" is empty\n",
144 char* c = xercesc::XMLString::transcode(in);
145 const std::string s(c);
146 xercesc::XMLString::release(&c);
168 #if _XERCES_VERSION >= 30200 169 # define XMLDATETIME_HAS_GETEPOCH 1 171 # define XMLDATETIME_HAS_GETEPOCH 0 173 bool parse_time_string(
174 const std::string& whole,
size_t& pos, std::string&
value,
size_t width = std::string::npos)
176 const bool to_end = width == std::string::npos;
177 const size_t size = whole.size();
178 if (pos >= size || (!to_end && pos + width > size)) {
181 value = whole.substr(pos, width);
182 pos = to_end ? size : pos + width;
186 bool parse_time_field(
187 const std::string& whole,
size_t& pos,
int& value,
size_t width = 2)
190 if (parse_time_string(whole, pos,
string, width)) {
197 "failed to get field at pos %B in \"%C\"\n",
198 pos, whole.c_str()));
203 bool parse_time_char_or_end(
204 const std::string& whole,
size_t& pos,
const std::string& choices,
char& c,
bool& end)
207 if (parse_time_string(whole, pos,
string, 1)) {
210 if (choices.find(c) != std::string::npos) {
215 "failed to find one of \"%C\" at pos %B in \"%C\"\n",
216 choices.c_str(), pos, whole.c_str()));
224 bool parse_time_char(
225 const std::string& whole,
size_t& pos,
const std::string& choices)
229 if (!parse_time_char_or_end(whole, pos, choices, c, end)) {
235 "failed to find one of \"%C\" at end of \"%C\"\n",
236 choices.c_str(), whole.c_str()));
243 #endif // XMLDATETIME_HAS_GETEPOCH 247 xercesc::XMLDateTime xdt(in);
250 }
catch (
const xercesc::XMLException& ex) {
253 "failed to parse date/time \"%C\": %C\n",
259 #if XMLDATETIME_HAS_GETEPOCH 260 value = xdt.getEpoch();
288 "date/time can't be negative: \"%C\"\n",
305 if (!parse_time_field(str, pos, dttm.tm_year, 4)) {
308 dttm.tm_year -= 1900;
309 if (!parse_time_char(str, pos,
"-")) {
313 if (!parse_time_field(str, pos, dttm.tm_mon)) {
317 if (!parse_time_char(str, pos,
"-")) {
321 if (!parse_time_field(str, pos, dttm.tm_mday)) {
324 if (!parse_time_char(str, pos,
"T")) {
328 if (!parse_time_field(str, pos, dttm.tm_hour)) {
331 if (!parse_time_char(str, pos,
":")) {
335 if (!parse_time_field(str, pos, dttm.tm_min)) {
338 if (!parse_time_char(str, pos,
":")) {
342 if (!parse_time_field(str, pos, dttm.tm_sec)) {
347 if (str[pos] ==
'.') {
349 for (; str[pos] >=
'0' && str[pos] <=
'9'; ++pos) {
354 time_t timezone_offset = 0;
357 if (!parse_time_char_or_end(str, pos,
"+-Z", tz_char, end)) {
360 if (!end && tz_char !=
'Z') {
362 if (!parse_time_field(str, pos, tz_hour)) {
366 if (!parse_time_char(str, pos,
":")) {
371 if (!parse_time_field(str, pos, tz_min)) {
379 const int timezone_offset_sign = tz_char ==
'+' ? -1 : 1;
388 timezone_offset = timezone_offset_sign * (tz_hour * 60 * 60 + tz_min * 60);
391 std::string leftover;
392 if (parse_time_string(str, pos, leftover)) {
395 "leftover characters in \"%C\": \"%C\"\n",
396 str.c_str(), leftover.c_str()));
402 value = std::mktime(&dttm);
403 if (value == time_t(-1)) {
406 "failed to convert to time_t \"%C\"\n",
414 const time_t local_timezone =
static_cast<time_t
>(
ace_timezone());
415 if (local_timezone == 0 && errno ==
ENOTSUP) {
418 "ace_timezone not supported\n"));
422 value -= local_timezone;
425 value += timezone_offset;
426 #endif // XMLDATETIME_HAS_GETEPOCH 436 const bool success = xercesc::XMLString::textToBin(node->getTextContent(), i) &&
447 const xercesc::DOMNodeList*
const domainIdNodes = node->getChildNodes();
448 for (XMLSize_t did = 0, did_len = domainIdNodes->getLength(); did < did_len; ++did) {
449 const xercesc::DOMNode*
const domainIdNode = domainIdNodes->item(did);
453 const std::string domainIdNodeName =
to_string(domainIdNode->getNodeName());
454 if (domainIdNodeName ==
"id") {
456 if (!parse_domain_id(domainIdNode, domain_id)) {
459 "Invalid domain ID \"%C\" in id\n",
464 domain_id_set.
add(domain_id);
466 }
else if (domainIdNodeName ==
"id_range") {
467 const xercesc::DOMNodeList*
const domRangeIdNodes = domainIdNode->getChildNodes();
469 bool has_min =
false;
471 bool has_max =
false;
472 const XMLSize_t drid_len = domRangeIdNodes->getLength();
473 for (XMLSize_t drid = 0; drid < drid_len; ++drid) {
474 const xercesc::DOMNode*
const domRangeIdNode = domRangeIdNodes->item(drid);
478 const std::string domRangeIdNodeName =
to_string(domRangeIdNode->getNodeName());
479 if (
"min" == domRangeIdNodeName && !has_min) {
480 if (!parse_domain_id(domRangeIdNode, min_value)) {
483 "Invalid domain ID \"%C\" in min_value\n",
490 }
else if (
"max" == domRangeIdNodeName && !has_max) {
491 if (!parse_domain_id(domRangeIdNode, max_value)) {
494 "Invalid domain ID \"%C\" in max_value\n",
499 if (min_value > max_value) {
502 "Permission XML Domain Range invalid.\n"));
511 "Invalid tag \"%C\" in id_range\n",
512 domRangeIdNodeName.c_str()));
518 domain_id_set.
add(min_value, max_value);
523 "Invalid tag \"%C\" in domain ID set\n",
524 domainIdNodeName.c_str()));
530 if (domain_id_set.
empty()) {
533 "empty domain ID set\n"));
bool parse_domain_id_set(const xercesc::DOMNode *node, Security::DomainIdSet &domain_id_set)
const LogLevel::Value value
String to_dds_string(unsigned short to_convert)
DDS::DomainId_t DomainId_t
const DDS::Security::DomainId_t domain_id_max
void add(T lower, T upper)
const DDS::Security::DomainId_t domain_id_min
bool is_element(const xercesc::DOMNode *node)
bool access_error
Permissions and Governance.
DOMAINID_TYPE_NATIVE DomainId_t
void Initialize(const CONFIGURATION_RESOURCE configuration_file, RETURN_CODE_TYPE &return_code)
int strcasecmp(const char *s, const char *t)
bool parse_bool(const XMLCh *in, bool &value)
bool get_parser(ParserPtr &parser, const std::string &filename, const std::string &xml)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
bool parse_time(const XMLCh *in, time_t &value)
std::string to_string(const xercesc::SAXParseException &ex)
The Internal API and Implementation of OpenDDS.
OpenDDS_Dcps_Export SecurityDebug security_debug
bool convertToInteger(const String &s, T &value)