version 4.0.7
[ric-plt/e2.git] / RIC-E2-TERMINATION / BuildXml.h
1 /*
2  * Copyright 2020 AT&T Intellectual Property
3  * Copyright 2020 Nokia
4  *
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 //
19 // Created by adi ENZEL on 4/5/20.
20 //
21
22 #ifndef E2_BUILDXML_H
23 #define E2_BUILDXML_H
24 #include <iostream>
25 #include <iosfwd>
26 #include <vector>
27 #include "pugixml/src/pugixml.hpp"
28 #include <string.h>
29 #include <sstream>
30
31
32 using namespace std;
33
34 void buildXmlData(vector<string> &repValues, unsigned char *buffer) {
35     pugi::xml_document doc;
36
37     pugi::xml_parse_result result = doc.load_string((const char *) buffer);
38     if (result) {
39         unsigned int index = 0;
40         for (auto tool : doc.child("E2AP-PDU")
41                 .child("initiatingMessage")
42                 .child("value")
43                 .child("E2setupRequest")
44                 .child("protocolIEs")
45                 .children("E2setupRequestIEs")) {
46             for (auto n : tool.child("value").child("RANfunctions-List").child(
47                     "ProtocolIE-SingleContainer").children()) {
48 //ProtocolIE-SingleContainer
49 //cout << "\t1 " << n.name() << endl;
50                 if (strcmp(n.name(), "value") == 0) {
51                     for (auto l : tool.child("value").children()) {
52 //cout << "\t\t2 " << l.name() << endl;
53                         for (auto f : l.children()) {
54 //cout << "\t\t\t3 " << f.name() << endl;
55                             for (auto g : f.child("value").children()) {
56 //cout << "\t\t\t\t4 " << g.name() << endl;
57                                 for (auto a : g.children()) {
58                                     if (strcmp(a.name(), "ranFunctionDefinition") == 0) {
59                                         if (repValues.size() > index) {
60                                             a.remove_children();
61                                             string val = repValues.at(index++);
62 // here we get vector with counter
63                                             a.append_child(pugi::node_pcdata).set_value(val.c_str());
64
65                                         }
66                                     }
67 //cout << "\t\t\t\t\t5 " << a.name() << " " << a.child_value() << endl;
68                                 }
69                             }
70                         }
71                     }
72                 }
73             }
74         }
75
76         streambuf *oldCout = cout.rdbuf();
77         ostringstream memCout;
78 // create new cout
79         cout.rdbuf(memCout.rdbuf());
80         doc.save(std::cout);
81 //return to the normal cout
82         cout.rdbuf(oldCout);
83         memcpy(buffer, memCout.str().c_str(), memCout.str().length());
84     }
85 }
86
87 #endif //E2_BUILDXML_H