This commit is contained in:
Kilian Hofmann 2022-09-07 03:04:26 +02:00
parent 910afad3b5
commit 25c4d8474d
4 changed files with 37 additions and 45 deletions

View File

@ -20,10 +20,10 @@ namespace germanairlinesva_simdata
void makeAirport( void makeAirport(
const std::string &kind, const std::string &kind,
std::ifstream *infile, std::ifstream &infile,
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>> std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
*airports, &airports,
std::ofstream *logfile); std::ofstream &logfile);
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields); void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields);
void makeRunway(std::vector<Runway> *runways, void makeRunway(std::vector<Runway> *runways,
std::vector<std::string> fields); std::vector<std::string> fields);

View File

@ -27,7 +27,7 @@ namespace germanairlinesva_simdata
// Default // Default
logfile << "<FILE> " << defaultFile << std::endl; logfile << "<FILE> " << defaultFile << std::endl;
makeAirport("DEFAULT", &base, &airports, &logfile); makeAirport("DEFAULT", base, airports, logfile);
base.close(); base.close();
std::string line; std::string line;
@ -47,7 +47,7 @@ namespace germanairlinesva_simdata
std::ifstream pack(path); std::ifstream pack(path);
if (pack.good()) { if (pack.good()) {
logfile << "<FILE> " << path << std::endl; logfile << "<FILE> " << path << std::endl;
makeAirport("CUSTOM", &pack, &airports, &logfile); makeAirport("CUSTOM", pack, airports, logfile);
pack.close(); pack.close();
} else { } else {
pack.close(); pack.close();
@ -66,10 +66,10 @@ namespace germanairlinesva_simdata
void makeAirport( void makeAirport(
const std::string &kind, const std::string &kind,
std::ifstream *infile, std::ifstream &infile,
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>> std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
*airports, &airports,
std::ofstream *logfile) std::ofstream &logfile)
{ {
std::string line; std::string line;
std::string *currentIcao = nullptr; std::string *currentIcao = nullptr;
@ -79,7 +79,7 @@ namespace germanairlinesva_simdata
int apCount = 0; int apCount = 0;
int validCount = 0; int validCount = 0;
while (std::getline(*infile, line)) { while (std::getline(infile, line)) {
std::vector<std::string> fields = germanairlinesva_util::split(line, ' '); std::vector<std::string> fields = germanairlinesva_util::split(line, ' ');
fields = germanairlinesva_util::select_T<std::string>( fields = germanairlinesva_util::select_T<std::string>(
fields, fields,
@ -91,54 +91,52 @@ namespace germanairlinesva_simdata
// Write to file if ICAO is valid, and we have gates and runways // Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() && if (currentIcao != nullptr && !tmpRunways.empty() &&
!tmpGates.empty()) { !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways}; airports[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1; validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
<< std::endl;
} else if (currentIcao != nullptr) { } else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
<< " had no gates or runways" << std::endl; << std::endl;
} }
tmpGates = std::vector<Gate>(); tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>(); tmpRunways = std::vector<Runway>();
currentIcao = new std::string(fields[4]); currentIcao = new std::string(fields[4]);
apCount += 1; apCount += 1;
*logfile << "\t<" << kind << "> " << line << std::endl; logfile << "\t<" << kind << "> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "15") { } else if (currentIcao != nullptr && fields[0] == "15") {
makeGate15(&tmpGates, fields); makeGate15(&tmpGates, fields);
*logfile << "\t\t<GATE OLD> " << line << std::endl; logfile << "\t\t<GATE OLD> " << line << std::endl;
} else if (fields[0] == "16" || fields[0] == "17") { } else if (fields[0] == "16" || fields[0] == "17") {
// Write to file if ICAO is valid, and we have gates and runways // Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() && if (currentIcao != nullptr && !tmpRunways.empty() &&
!tmpGates.empty()) { !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways}; airports[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1; validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
<< std::endl;
} else if (currentIcao != nullptr) { } else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
<< " had no gates or runways" << std::endl; << std::endl;
} }
tmpGates = std::vector<Gate>(); tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>(); tmpRunways = std::vector<Runway>();
currentIcao = nullptr; currentIcao = nullptr;
*logfile << "\t<" << kind << " SKIPPED> " << line << std::endl; logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "100") { } else if (currentIcao != nullptr && fields[0] == "100") {
makeRunway(&tmpRunways, fields); makeRunway(&tmpRunways, fields);
*logfile << "\t\t<RUNWAY> " << line << std::endl; logfile << "\t\t<RUNWAY> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "1300") { } else if (currentIcao != nullptr && fields[0] == "1300") {
makeGate1300(&tmpGates, fields); makeGate1300(&tmpGates, fields);
*logfile << "\t\t<GATE> " << line << std::endl; logfile << "\t\t<GATE> " << line << std::endl;
} }
} }
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) { if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways}; airports[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1; validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl; logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
} }
*logfile << "<STATUS> " << apCount << " airports found, of which " logfile << "<STATUS> " << apCount << " airports found, of which "
<< validCount << " are valid" << std::endl; << validCount << " are valid" << std::endl;
} }
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields) void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields)

View File

@ -105,18 +105,16 @@ namespace germanairlinesva_util
nullptr, nullptr,
PROV_RSA_FULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT)) { CRYPT_VERIFYCONTEXT)) {
std::stringstream debug_msg; toLog("CryptAcquireContext returned with error " +
debug_msg << "CryptAcquireContext returned with error " << GetLastError(); std::to_string(GetLastError()));
toLog(debug_msg.str());
CloseHandle(hFile); CloseHandle(hFile);
return 1; return 1;
} }
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) { if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
std::stringstream debug_msg; toLog("CryptCreateHash returned with error " +
debug_msg << "CryptCreateHash returned with error " << GetLastError(); std::to_string(GetLastError()));
toLog(debug_msg.str());
CloseHandle(hFile); CloseHandle(hFile);
CryptReleaseContext(hProv, 0); CryptReleaseContext(hProv, 0);
@ -129,9 +127,8 @@ namespace germanairlinesva_util
} }
if (!CryptHashData(hHash, rgbFile, cbRead, 0)) { if (!CryptHashData(hHash, rgbFile, cbRead, 0)) {
std::stringstream debug_msg; toLog("CryptHashData returned with error " +
debug_msg << "CryptHashData returned with error " << GetLastError(); std::to_string(GetLastError()));
toLog(debug_msg.str());
CryptReleaseContext(hProv, 0); CryptReleaseContext(hProv, 0);
CryptDestroyHash(hHash); CryptDestroyHash(hHash);
@ -141,9 +138,7 @@ namespace germanairlinesva_util
} }
if (!bResult) { if (!bResult) {
std::stringstream debug_msg; toLog("ReadFile returned with error " + std::to_string(GetLastError()));
debug_msg << "ReadFile returned with error " << GetLastError();
toLog(debug_msg.str());
CryptReleaseContext(hProv, 0); CryptReleaseContext(hProv, 0);
CryptDestroyHash(hHash); CryptDestroyHash(hHash);
@ -155,9 +150,8 @@ namespace germanairlinesva_util
if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) { if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) {
to_hex((char *)rgbHash, lastHash); to_hex((char *)rgbHash, lastHash);
} else { } else {
std::stringstream debug_msg; toLog("CryptGetHashParam returned with error " +
debug_msg << "CryptGetHashParam returned with error " << GetLastError(); std::to_string(GetLastError()));
toLog(debug_msg.str());
} }
CryptDestroyHash(hHash); CryptDestroyHash(hHash);

View File

@ -33,8 +33,8 @@ namespace germanairlinesva_websocket
public: public:
Websocket(std::string host, Websocket(std::string host,
std::string user, std::string user,
std::function<void(const std::string)> toLog); std::function<void(const std::string)> toLog);
~Websocket(); ~Websocket();
void onClientMessageCallback(const ix::WebSocketMessagePtr &msg); void onClientMessageCallback(const ix::WebSocketMessagePtr &msg);
void sendData(data &d); void sendData(data &d);