Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[19315] Allow participant profiles with no rtps tag (backport #3771) #3780

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions src/cpp/rtps/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1771,39 +1771,64 @@ XMLP_ret XMLParser::fillDataNode(
addAllAttributes(p_profile, participant_node);

uint8_t ident = 1;
tinyxml2::XMLElement* p_element = p_profile->FirstChildElement(DOMAIN_ID);
if (nullptr != p_element)
tinyxml2::XMLElement* p_element;
tinyxml2::XMLElement* p_aux0 = nullptr;
const char* name = nullptr;
std::set<std::string> tags_present;

/*
* The only allowed elements are <domainId> and <rtps>
* - The min occurrences of <domainId> are 0, and its max is 1; look for it.
* - The min occurrences of <rtps> are 0, and its max is 1; look for it.
*/
for (p_element = p_profile->FirstChildElement(); p_element != nullptr; p_element = p_element->NextSiblingElement())
{
// domainId - uint32Type
if (XMLP_ret::XML_OK != getXMLUint(p_element, &participant_node.get()->domainId, ident))
name = p_element->Name();
if (tags_present.count(name) != 0)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Duplicated element found in 'participant'. Tag: " << name);
return XMLP_ret::XML_ERROR;
}
tags_present.emplace(name);

if (strcmp(p_element->Name(), DOMAIN_ID) == 0)
{
// domainId - uint32Type
if (XMLP_ret::XML_OK != getXMLUint(p_element, &participant_node.get()->domainId, ident))
{
return XMLP_ret::XML_ERROR;
}
}
else if (strcmp(p_element->Name(), RTPS) == 0)
{
p_aux0 = p_element;
}
else
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Found incorrect tag '" << p_element->Name() << "'");
return XMLP_ret::XML_ERROR;
}
}
tags_present.clear();

p_element = p_profile->FirstChildElement(RTPS);
if (nullptr == p_element)
// <rtps> is not present, but that's OK
if (nullptr == p_aux0)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "Not found '" << RTPS << "' tag");
return XMLP_ret::XML_ERROR;
return XMLP_ret::XML_OK;
}

tinyxml2::XMLElement* p_aux0 = nullptr;
const char* name = nullptr;

std::unordered_map<std::string, bool> tags_present;

for (p_aux0 = p_element->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
// Check contents of <rtps>
for (p_aux0 = p_aux0->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();

if (tags_present[name])
if (tags_present.count(name) != 0)
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Duplicated element found in 'rtpsParticipantAttributesType'. Name: " << name);
"Duplicated element found in 'rtpsParticipantAttributesType'. Tag: " << name);
return XMLP_ret::XML_ERROR;
}
tags_present[name] = true;
tags_present.emplace(name);

if (strcmp(name, ALLOCATION) == 0)
{
Expand Down
17 changes: 6 additions & 11 deletions test/unittest/xmlparser/XMLParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ TEST_F(XMLParserTests, regressions)
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/14456_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/15344_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/18395_profile_bin.xml", root));
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/simple_participant_profiles_nok.xml", root));
EXPECT_EQ(XMLP_ret::XML_OK, XMLParser::loadXML("regressions/simple_participant_profiles_ok.xml", root));
}

TEST_F(XMLParserTests, NoFile)
Expand Down Expand Up @@ -1603,10 +1605,9 @@ TEST_F(XMLParserTests, parseLogConfig)
/*
* This test checks the return of the negative cases of the fillDataNode given a ParticipantAttributes DataNode
* 1. Check passing a nullptr as if the XMLElement was wrongly parsed above
* 2. Check missing required rtps tag
* 3. Check missing DomainId value in tag
* 4. Check bad values for all attributes
* 5. Check a non existant attribute tag
* 2. Check missing DomainId value in tag
* 3. Check bad values for all attributes
* 4. Check a non existant attribute tag
*/
TEST_F(XMLParserTests, fillDataNodeParticipantNegativeClauses)
{
Expand All @@ -1628,12 +1629,6 @@ TEST_F(XMLParserTests, fillDataNodeParticipantNegativeClauses)
";
char xml[500];

// Misssing rtps tag
sprintf(xml, xml_p, "<domainId>0</domainId>");
ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml));
titleElement = xml_doc.RootElement();
EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::fillDataNode_wrapper(titleElement, *participant_node));

// Misssing DomainId Value
sprintf(xml, xml_p, "<domainId></domainId><rtps></rtps>");
ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml));
Expand Down Expand Up @@ -1751,6 +1746,7 @@ TEST_F(XMLParserTests, parseXMLProfilesRoot)
// <topic>, <requester>, <replier>, <types>, and <log> are read as xml child elements of the <profiles>
// root element.
std::vector<std::string> elements_ok {
"participant",
"publisher",
"data_writer",
"subscriber",
Expand All @@ -1768,7 +1764,6 @@ TEST_F(XMLParserTests, parseXMLProfilesRoot)

std::vector<std::string> elements_error {
"library_settings",
"participant",
"requester",
"replier"
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dds xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<profiles>
<participant profile_name="duplicated_domainid_participant">
<domainId>1</domainId>
<domainId>2</domainId>
</participant>

<participant profile_name="duplicated_rtps_participant">
<rtps></rtps>
<rtps></rtps>
</participant>
</profiles>
</dds>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dds xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<profiles>
<participant profile_name="empty_participant">
</participant>

<participant profile_name="only_rtps_participant">
<rtps></rtps>
</participant>

<participant profile_name="only_rtps_participant">
<rtps/>
</participant>

<participant profile_name="only_domainid_participant">
<domainId>1</domainId>
</participant>

<participant profile_name="complete_participant">
<domainId>1</domainId>
<rtps></rtps>
</participant>
</profiles>
</dds>