2 * Copyright 2020 AT&T Intellectual Property
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 // Created by adi ENZEL on 4/5/20.
27 #include "pugixml/src/pugixml.hpp"
34 * Copied from pugixml samples
36 struct xml_string_writer : pugi::xml_writer {
39 virtual void write(const void *data, size_t size) {
40 result.append(static_cast<const char *>(data), size);
45 struct xml_memory_writer : pugi::xml_writer {
50 xml_memory_writer() : buffer(0), capacity(0), result(0) {
53 xml_memory_writer(char *buffer, size_t capacity) : buffer(buffer), capacity(capacity), result(0) {
56 size_t written_size() const {
57 return result < capacity ? result : capacity;
60 virtual void write(const void *data, size_t size) {
61 if (result < capacity) {
62 size_t chunk = (capacity - result < size) ? capacity - result : size;
64 memcpy(buffer + result, data, chunk);
70 std::string node_to_string(pugi::xml_node node) {
71 xml_string_writer writer;
78 void buildXmlData(const string &messageName, const string &ieName, vector<string> &repValues, unsigned char *buffer) {
79 pugi::xml_document doc;
81 pugi::xml_parse_result result = doc.load_string((const char *)buffer);
83 unsigned int index = 0;
84 for (auto tool : doc.child("E2AP-PDU")
85 .child("initiatingMessage")
87 .child(messageName.c_str())
89 .children(ieName.c_str())) {
90 for (auto n : tool.child("value").child("RANfunctions-List").child(
91 "ProtocolIE-SingleContainer").children()) {
92 //ProtocolIE-SingleContainer
93 //cout << "\t1 " << n.name() << endl;
94 if (strcmp(n.name(), "value") == 0) {
95 for (auto l : tool.child("value").children()) {
96 //cout << "\t\t2 " << l.name() << endl;
97 for (auto f : l.children()) {
98 //cout << "\t\t\t3 " << f.name() << endl;
99 for (auto g : f.child("value").children()) {
100 //cout << "\t\t\t\t4 " << g.name() << endl;
101 for (auto a : g.children()) {
102 if (strcmp(a.name(), "ranFunctionDefinition") == 0) {
103 if (repValues.size() > index) {
105 string val = repValues.at(index++);
106 // here we get vector with counter
107 a.append_child(pugi::node_pcdata).set_value(val.c_str());
111 //cout << "\t\t\t\t\t5 " << a.name() << " " << a.child_value() << endl;
120 auto res = node_to_string(doc);
121 memcpy(buffer, res.c_str(), res.length());
123 // streambuf *oldCout = cout.rdbuf();
124 // ostringstream memCout;
126 // cout.rdbuf(memCout.rdbuf());
127 // doc.save(std::cout);
128 ////return to the normal cout
129 // cout.rdbuf(oldCout);
130 // memcpy(buffer, memCout.str().c_str(), memCout.str().length());
134 #endif //E2_BUILDXML_H