-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfParser.cpp
More file actions
122 lines (88 loc) · 3.74 KB
/
confParser.cpp
File metadata and controls
122 lines (88 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <fstream>
#include "Json.h"
#include "parser.h"
#include <stdlib.h>
extern "C" {
#include "pktheaders.h"
}
using namespace std;
Json::Value arrpkts(string fileName) {
ifstream ifs(fileName);
if (!ifs) { // If the file was not found, then file is 0, i.e. !file=1 or true.
cout << "could not find the file." << '\n';
exit(1); // The file was not found.
}
Json::Reader reader;
Json::Value obj;
reader.parse(ifs, obj); // reader can also read strings
Json::Value& pkts = obj["pkt"]; // array of characters
return pkts;
}
int GetfromDemand(int Dindex, int Pindex, Json::Value &pkts) {
return pkts[Pindex]["demands"]["details"][Dindex]["from"].asInt();
}
int getTimesFromConf(int index, Json::Value &pkts) {
return pkts[index]["times"].asUInt();
}
int GettoDemand(int Dindex, int Pindex, Json::Value &pkts) {
return pkts[Pindex]["demands"]["details"][Dindex]["to"].asInt();
}
int get_edianDemand(int Dindex, int Pindex, Json::Value &pkts) {
return pkts[Pindex]["demands"]["details"][Dindex]["format"].asInt();
}
struct packetC buildJsonArrDemand(int index, struct packetC(*fp)(int, int, char[200], int, int), Json::Value &pkts) {
char test[200];
if (pkts[index]["isCommented"].asUInt() && pkts[index]["ispcap"].asUInt()) {
cout << "file cannot be both hex stream and commented." << '\n';
exit(1); // The file was not found.
}
if (pkts[index]["isCommented"].asUInt()) {
strcpy(test, (pkts[index]["path"].asString()).c_str());
comments_killer(test);
memset(test, '\0', sizeof(test));
strncpy(test, "temp.txt", 8);
return fp(pkts[index]["size"].asUInt(), pkts[index]["isCommented"].asUInt(), test, pkts[index]["times"].asUInt(), pkts[index]["delays"].asUInt());
}
else if (pkts[index]["ispcap"].asUInt()) {
strcpy(test, (pkts[index]["path"].asString()).c_str());
hexstream2tool(test);
memset(test, '\0', sizeof(test));
strncpy(test, "temp.txt", 8);
return fp(pkts[index]["size"].asUInt(), pkts[index]["ispcap"].asUInt(), test, pkts[index]["times"].asUInt(), pkts[index]["delays"].asUInt());
}
strcpy(test, (pkts[index]["path"].asString()).c_str());
return fp(pkts[index]["size"].asUInt(), pkts[index]["isCommented"].asUInt(), test, pkts[index]["times"].asUInt(), pkts[index]["delays"].asUInt());
}
int get_sizeDemands(int index, Json::Value &pkts) {
return pkts[index]["conditions"]["size"].asInt();
}
/*
void getAllInCell(int index, Json::Value& pkts) {
for (int i = 0; i < pkts.size(); i++) {
number = pkts[i]["number"].asUInt();
path = pkts[i]["path"].asString();
isPcap = pkts[i]["ispcap"].asBool();
isCommented = pkts[i]["isCommented"].asBool();
times = pkts[i]["times"].asUInt();
delays = pkts[i]["delays"].asUInt();
pktSize = pkts[i]["size"].asUInt();
demandSize = pkts[i]["demands"]["size"].asUInt();
conditionSize = pkts[i]["conditions"]["size"].asUInt();
const Json::Value& demands = pkts[i]["demands"]["details"]; // array of characters
for (int j = 0; j < demandSize; j++) {
cout << " from: " << pkts[i]["demands"]["details"][j]["from"].asUInt();
cout << " to: " << pkts[i]["demands"]["details"][j]["to"].asUInt();
cout << " type: " << pkts[i]["demands"]["details"][j]["type"].asString();
cout << " in: " << pkts[i]["demands"]["details"][j]["in"].asUInt();
cout << " format: " << pkts[i]["demands"]["details"][j]["format"].asString();
}
const Json::Value& conditions = pkts[i]["conditions"]["details"]; // array of characters
for (int j = 0; j < conditionSize; j++) {
cout << " index: " << pkts[i]["conditions"]["details"][j]["index"].asUInt();
cout << " eq: " << pkts[i]["conditions"]["details"][j]["eq"].asString();
cout << " then: " << pkts[i]["conditions"]["details"][j]["then"].asUInt();
cout << " changesTo: " << pkts[i]["conditions"]["details"][j]["changesTo"].asString();
}
}
}
*/