Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed May 23, 2024
1 parent f20a594 commit 42f29c5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 250 deletions.
8 changes: 0 additions & 8 deletions include/fastrtps/xmlparser/XMLParserCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,7 @@ extern const char* SEND_BUFFER_SIZE;
extern const char* TTL;
extern const char* NON_BLOCKING_SEND;
extern const char* WHITE_LIST;
<<<<<<< HEAD:include/fastrtps/xmlparser/XMLParserCommon.h
extern const char* INTERFACE;
=======
extern const char* NETWORK_INTERFACE;
extern const char* NETMASK_FILTER;
extern const char* NETWORK_INTERFACES;
extern const char* ALLOWLIST;
extern const char* BLOCKLIST;
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLParserCommon.h
extern const char* MAX_MESSAGE_SIZE;
extern const char* MAX_INITIAL_PEERS_RANGE;
extern const char* KEEP_ALIVE_FREQUENCY;
Expand Down
222 changes: 2 additions & 220 deletions src/cpp/rtps/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ using namespace eprosima::fastdds::xml::detail;
XMLP_ret XMLParser::loadDefaultXMLFile(
up_base_node_t& root)
{
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLParser.cpp
return loadXML(DEFAULT_FASTRTPS_PROFILES, root);
=======
// Use absolute path to ensure that the file is loaded only once
#ifdef _WIN32
char current_directory[MAX_PATH];
Expand All @@ -62,7 +59,7 @@ XMLP_ret XMLParser::loadDefaultXMLFile(
}
else
{
strcat_s(current_directory, MAX_PATH, DEFAULT_FASTDDS_PROFILES);
strcat_s(current_directory, MAX_PATH, DEFAULT_FASTRTPS_PROFILES);
return loadXML(current_directory, root, true);
}
#else
Expand All @@ -74,12 +71,11 @@ XMLP_ret XMLParser::loadDefaultXMLFile(
else
{
strcat(current_directory, "/");
strcat(current_directory, DEFAULT_FASTDDS_PROFILES);
strcat(current_directory, DEFAULT_FASTRTPS_PROFILES);
return loadXML(current_directory, root, true);
}
#endif // _WIN32
return XMLP_ret::XML_ERROR;
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLParser.cpp
}

XMLP_ret XMLParser::parseXML(
Expand Down Expand Up @@ -450,11 +446,6 @@ XMLP_ret XMLParser::validateXMLTransportElements(
strcmp(name, MAX_MESSAGE_SIZE) == 0 ||
strcmp(name, MAX_INITIAL_PEERS_RANGE) == 0 ||
strcmp(name, WHITE_LIST) == 0 ||
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLParser.cpp
=======
strcmp(name, NETMASK_FILTER) == 0 ||
strcmp(name, NETWORK_INTERFACES) == 0 ||
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLParser.cpp
strcmp(name, TTL) == 0 ||
strcmp(name, NON_BLOCKING_SEND) == 0 ||
strcmp(name, UDP_OUTPUT_PORT) == 0 ||
Expand Down Expand Up @@ -652,211 +643,6 @@ XMLP_ret XMLParser::parseXMLSocketTransportData(
}
}
}
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLParser.cpp
=======
else if (strcmp(name, NETMASK_FILTER) == 0)
{
std::string netmask_filter_str;
if (XMLP_ret::XML_OK != getXMLString(p_aux0, &netmask_filter_str, 0))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found into 'netmask_filter'.");
return XMLP_ret::XML_ERROR;
}

try
{
p_transport->netmask_filter = fastdds::rtps::network::netmask_filter::string_to_netmask_filter_kind(
netmask_filter_str);
}
catch (const std::invalid_argument& e)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found into 'netmask_filter' : " << e.what());
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, NETWORK_INTERFACES) == 0)
{
if (XMLP_ret::XML_OK != parseXMLInterfaces(p_aux0, p_transport))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Failed to parse 'interfaces' element.");
return XMLP_ret::XML_ERROR;
}
}
}
return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::parseXMLInterfaces(
tinyxml2::XMLElement* p_root,
std::shared_ptr<fastdds::rtps::SocketTransportDescriptor> p_transport)
{
/*
<xs:complexType name="interfacesType">
<xs:all>
<xs:element name="allowlist" type="allowlistType" minOccurs="0" maxOccurs="1"/>
<xs:element name="blocklist" type="blocklistType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
*/
tinyxml2::XMLElement* p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, ALLOWLIST) == 0)
{
if (XMLP_ret::XML_OK != parseXMLAllowlist(p_aux0, p_transport))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Failed to parse 'allowlist'.");
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(name, BLOCKLIST) == 0)
{
if (XMLP_ret::XML_OK != parseXMLBlocklist(p_aux0, p_transport))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Failed to parse 'blocklist'.");
return XMLP_ret::XML_ERROR;
}
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found in 'interfaces'. Name: " << name);
return XMLP_ret::XML_ERROR;
}
}
return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::parseXMLAllowlist(
tinyxml2::XMLElement* p_root,
std::shared_ptr<fastdds::rtps::SocketTransportDescriptor> p_transport)
{
/*
<xs:complexType name="allowlistType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="interface" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="string" use="required"/>
<xs:attribute name="netmask_filter" type="netmaskFilterType" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
*/
static const char* INTERFACE_NAME = "interface";
static const char* NAME_ATTR_NAME = "name";
static const char* NETMASK_FILTER_ATTR_NAME = "netmask_filter";

const tinyxml2::XMLElement* p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, INTERFACE_NAME) == 0)
{
// Parse interface name (device/ip)
std::string iface_name;
auto iface_name_attr = p_aux0->FindAttribute(NAME_ATTR_NAME);
if (nullptr != iface_name_attr)
{
iface_name = iface_name_attr->Value();
if (iface_name.empty())
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Failed to parse 'allowlist' element. Attribute 'name' cannot be empty.");
return XMLP_ret::XML_ERROR;
}
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Failed to parse 'allowlist' element. Required attribute 'name' not found.");
return XMLP_ret::XML_ERROR;
}

// Parse netmask filter
fastdds::rtps::NetmaskFilterKind netmask_filter{fastdds::rtps::NetmaskFilterKind::AUTO};
auto netmask_filter_attr = p_aux0->FindAttribute(NETMASK_FILTER_ATTR_NAME);
if (nullptr != netmask_filter_attr)
{
try
{
netmask_filter = fastdds::rtps::network::netmask_filter::string_to_netmask_filter_kind(
netmask_filter_attr->Value());
}
catch (const std::invalid_argument& e)
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Failed to parse 'allowlist' element. Invalid value found in 'netmask_filter' : " <<
e.what());
return XMLP_ret::XML_ERROR;
}
}
// Add valid item to allowlist
p_transport->interface_allowlist.emplace_back(iface_name, netmask_filter);
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found in 'allowlist'. Name: " << name);
return XMLP_ret::XML_ERROR;
}
}
return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::parseXMLBlocklist(
tinyxml2::XMLElement* p_root,
std::shared_ptr<fastdds::rtps::SocketTransportDescriptor> p_transport)
{
/*
<xs:complexType name="blocklistType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="interface" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
*/
static const char* INTERFACE_NAME = "interface";
static const char* NAME_ATTR_NAME = "name";

const tinyxml2::XMLElement* p_aux0 = nullptr;
const char* name = nullptr;
for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
if (strcmp(name, INTERFACE_NAME) == 0)
{
// Parse interface name (device/ip)
auto iface = p_aux0->FindAttribute(NAME_ATTR_NAME);
if (nullptr != iface)
{
std::string iface_name = iface->Value();
if (iface_name.empty())
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Failed to parse 'blocklist' element. Attribute 'name' cannot be empty.");
return XMLP_ret::XML_ERROR;
}
// Add valid item to blocklist
p_transport->interface_blocklist.emplace_back(iface_name);
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Failed to parse 'blocklist' element. Required attribute 'name' not found.");
return XMLP_ret::XML_ERROR;
}
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found in 'blocklist'. Name: " << name);
return XMLP_ret::XML_ERROR;
}
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLParser.cpp
}
return XMLP_ret::XML_OK;
}
Expand Down Expand Up @@ -2101,11 +1887,7 @@ XMLP_ret XMLParser::loadXML(
tinyxml2::XMLDocument xmlDoc;
if (tinyxml2::XMLError::XML_SUCCESS != xmlDoc.LoadFile(filename.c_str()))
{
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLParser.cpp
if (filename != std::string(DEFAULT_FASTRTPS_PROFILES))
=======
if (!is_default)
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLParser.cpp
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Error opening '" << filename << "'");
}
Expand Down
8 changes: 0 additions & 8 deletions src/cpp/rtps/xmlparser/XMLParserCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ const char* SEND_BUFFER_SIZE = "sendBufferSize";
const char* TTL = "TTL";
const char* NON_BLOCKING_SEND = "non_blocking_send";
const char* WHITE_LIST = "interfaceWhiteList";
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLParserCommon.cpp
const char* INTERFACE = "interface";
=======
const char* NETWORK_INTERFACE = "interface";
const char* NETMASK_FILTER = "netmask_filter";
const char* NETWORK_INTERFACES = "interfaces";
const char* ALLOWLIST = "allowlist";
const char* BLOCKLIST = "blocklist";
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLParserCommon.cpp
const char* MAX_MESSAGE_SIZE = "maxMessageSize";
const char* MAX_INITIAL_PEERS_RANGE = "maxInitialPeersRange";
const char* KEEP_ALIVE_FREQUENCY = "keep_alive_frequency_ms";
Expand Down
16 changes: 2 additions & 14 deletions src/cpp/rtps/xmlparser/XMLProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ void XMLProfileManager::loadDefaultXMLFile()
// Try to load the default XML file if variable does not exist or is not set to '1'
if (!(getenv_s(&size, skip_xml, size, SKIP_DEFAULT_XML_FILE) == 0 && skip_xml[0] == '1'))
{
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLProfileManager.cpp
loadXMLFile(DEFAULT_FASTRTPS_PROFILES);
=======
// Try to load the default XML file.
if (GetCurrentDirectory(MAX_PATH, current_directory) == 0)
{
Expand All @@ -233,10 +230,9 @@ void XMLProfileManager::loadDefaultXMLFile()
else
{
strcat_s(current_directory, MAX_PATH, "\\");
strcat_s(current_directory, MAX_PATH, DEFAULT_FASTDDS_PROFILES);
strcat_s(current_directory, MAX_PATH, DEFAULT_FASTRTPS_PROFILES);
loadXMLFile(current_directory, true);
}
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLProfileManager.cpp
}
#else
char absolute_path[PATH_MAX];
Expand All @@ -259,20 +255,16 @@ void XMLProfileManager::loadDefaultXMLFile()
// Try to load the default XML file if variable does not exist or is not set to '1'
if (!(skip_xml != nullptr && skip_xml[0] == '1'))
{
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLProfileManager.cpp
loadXMLFile(DEFAULT_FASTRTPS_PROFILES);
=======
if (getcwd(absolute_path, PATH_MAX) == NULL)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "getcwd failed " << std::strerror(errno));
}
else
{
strcat(absolute_path, "/");
strcat(absolute_path, DEFAULT_FASTDDS_PROFILES);
strcat(absolute_path, DEFAULT_FASTRTPS_PROFILES);
loadXMLFile(absolute_path, true);
}
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLProfileManager.cpp
}

#endif // ifdef _WIN32
Expand Down Expand Up @@ -383,11 +375,7 @@ XMLP_ret XMLProfileManager::loadXMLFile(
XMLP_ret loaded_ret = XMLParser::loadXML(filename, root_node, is_default);
if (!root_node || loaded_ret != XMLP_ret::XML_OK)
{
<<<<<<< HEAD:src/cpp/rtps/xmlparser/XMLProfileManager.cpp
if (filename != std::string(DEFAULT_FASTRTPS_PROFILES))
=======
if (!is_default)
>>>>>>> 0919ff294 (Use absolute paths when loading XML files (#4751)):src/cpp/xmlparser/XMLProfileManager.cpp
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Error parsing '" << filename << "'");
}
Expand Down

0 comments on commit 42f29c5

Please sign in to comment.