X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=RIC-E2-TERMINATION%2FBuildXml.h;h=e71fa4dc21c718c2b17236c889607894b18a7674;hb=6cf28617aec735a578731b2a7e0d184223f18cda;hp=beca88ba9b733eca2c4d6c4f50283273cfd7969b;hpb=f051a87fb2df97b49fd2ffe503f1453f2513a885;p=ric-plt%2Fe2.git diff --git a/RIC-E2-TERMINATION/BuildXml.h b/RIC-E2-TERMINATION/BuildXml.h index beca88b..e71fa4d 100644 --- a/RIC-E2-TERMINATION/BuildXml.h +++ b/RIC-E2-TERMINATION/BuildXml.h @@ -21,6 +21,7 @@ #ifndef E2_BUILDXML_H #define E2_BUILDXML_H + #include #include #include @@ -42,32 +43,6 @@ struct xml_string_writer : pugi::xml_writer { result.append(static_cast(data), size); } }; -// end::code[] - -//struct xml_memory_writer : pugi::xml_writer { -// char *buffer; -// size_t capacity; -// size_t result; -// -// xml_memory_writer() : buffer(nullptr), capacity(0), result(0) { -// } -// -// xml_memory_writer(char *buffer, size_t capacity) : buffer(buffer), capacity(capacity), result(0) { -// } -// -// [[nodiscard]] size_t written_size() const { -// return result < capacity ? result : capacity; -// } -// -// void write(const void *data, size_t size) override { -// if (result < capacity) { -// size_t chunk = (capacity - result < size) ? capacity - result : size; -// -// memcpy(buffer + result, data, chunk); -// } -// result += size; -// } -//}; std::string node_to_string(pugi::xml_node node) { xml_string_writer writer; @@ -76,15 +51,24 @@ std::string node_to_string(pugi::xml_node node) { return writer.result; } +string buildXmlData(const string &messageName, + const string &ieName, + vector &RANfunctionsAdded, + vector &RANfunctionsModified, + unsigned char *buffer, + size_t size) { + pugi::xml_document *doc = new pugi::xml_document(); -int buildXmlData(const string &messageName, const string &ieName, vector &RANfunctionsAdded, unsigned char *buffer, size_t size) { - pugi::xml_document doc; + char RANfunctionsAddedID[8]; + snprintf(RANfunctionsAddedID, 8, "%d", (int) ProtocolIE_ID_id_RANfunctionsAdded); + char RANfunctionsModifiedID[8]; + snprintf(RANfunctionsModifiedID, 8, "%d", (int) ProtocolIE_ID_id_RANfunctionsModified); + char GlobalE2nodeID[8]; + snprintf(GlobalE2nodeID, 8, "%d", (int) ProtocolIE_ID_id_GlobalE2node_ID); - doc.reset(); - pugi::xml_parse_result result = doc.load_buffer((const char *)buffer, size); + pugi::xml_parse_result result = doc->load_buffer((const char *) buffer, size); if (result) { - unsigned int index = 0; - for (auto tool : doc.child("E2AP-PDU") + for (auto tool : doc->child("E2AP-PDU") .child("initiatingMessage") .child("value") .child(messageName.c_str()) @@ -94,14 +78,14 @@ int buildXmlData(const string &messageName, const string &ieName, vector auto node = tool.child("id"); // get the id to identify the type of the contained message if (node.empty()) { mdclog_write(MDCLOG_ERR, "Failed to find ID node in the XML. File %s, line %d", - __FILE__, __LINE__); + __FILE__, __LINE__); continue; } - if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), "10") == 0) { + if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), RANfunctionsAddedID) == 0) { auto nodea = tool.child("value"). child("RANfunctions-List"). children("ProtocolIE-SingleContainer"); - + unsigned int index = 0; for (auto n1 : nodea) { auto n2 = n1.child("value").child("RANfunction-Item").child("ranFunctionDefinition"); n2.remove_children(); @@ -112,22 +96,41 @@ int buildXmlData(const string &messageName, const string &ieName, vector mdclog_write(MDCLOG_DEBUG, "entry %s Replaced with : %s", n2.name(), n2.child_value()); } } + } else if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), RANfunctionsModifiedID) == 0) { + auto nodea = tool.child("value"). + child("RANfunctions-List"). + children("ProtocolIE-SingleContainer"); + unsigned int index = 0; + for (auto n1 : nodea) { + auto n2 = n1.child("value").child("RANfunction-Item").child("ranFunctionDefinition"); + n2.remove_children(); + string val = RANfunctionsModified.at(index++); + // here we get vector with counter + n2.append_child(pugi::node_pcdata).set_value(val.c_str()); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "entry %s Replaced with : %s", n2.name(), n2.child_value()); + } + } + } else if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), GlobalE2nodeID) == 0) { + continue; } else { if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Entry %s = value %s skipped", node.name(), node.child_value()); + mdclog_write(MDCLOG_DEBUG, "Entry name :%s with entry of %s skipped", node.name(), node.child_value()); } continue; } } - - auto res = node_to_string(doc); - memcpy(buffer, res.c_str(), res.length()); - doc.reset(); } else { - mdclog_write(MDCLOG_ERR, "Error loading xml string"); - return -1; + mdclog_write(MDCLOG_ERR, + "Error loading xml string"); + delete doc; + return string(""); } - return 0; + auto res = node_to_string(*doc); + res.erase(std::remove(res.begin(), res.end(), '\n'), res.end()); + res.erase(std::remove(res.begin(), res.end(), '\t'), res.end()); + delete doc; + return res; }