Compare commits

..

No commits in common. "ef9cc2309367d733de3ee3ef5575b1ec3df56cba" and "b270a9f30e3c76a94ff443d07923020d6a8c3651" have entirely different histories.

6 changed files with 25 additions and 138 deletions

View File

@ -112,23 +112,19 @@ void IsmasClient::printErrorMessage(int port,
}
std::optional<QString>
IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool verbose) {
IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
if (verbose) {
qInfo() << "REQUEST" << request;
}
qInfo() << "REQUEST" << request;
int sockfd;
int r;
errno = 0;
// socket create and verification
if ((sockfd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
if (verbose) {
qCritical().noquote()
<< "\n"
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
<< "SOCKET CREATION FAILED (" << strerror(errno) << ")";
}
qCritical().noquote()
<< "\n"
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
<< "SOCKET CREATION FAILED (" << strerror(errno) << ")";
return std::nullopt;
}
@ -141,12 +137,10 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool v
servAddr.sin_port = htons(port);
// connect the client socket to server socket
if ((r = ::connect(sockfd, (struct sockaddr *)(&servAddr), sizeof(servAddr))) != 0) {
if (verbose) {
qCritical().noquote()
<< "\n"
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
<< "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")";
}
qCritical().noquote()
<< "\n"
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
<< "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")";
::close(sockfd);
return std::nullopt;
}
@ -161,9 +155,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool v
inet_ntop(AF_INET, &clientAddr.sin_addr, clientIP, sizeof(clientIP));
unsigned int clientPort = ntohs(clientAddr.sin_port);
if (verbose) {
printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER"));
}
printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER"));
struct timeval tv;
tv.tv_sec = 10; /* 10 secs timeout for read and write */
@ -252,9 +244,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool v
// QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")");
// }
if (verbose) {
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
}
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
loop = 0;
bzero(buf, sizeof(buf));
@ -335,9 +325,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool v
response = response.mid(0, idx);
} else
if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED
if (verbose) {
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
}
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
::close(sockfd);
return std::nullopt;
}
@ -346,10 +334,8 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool v
QJsonDocument document(QJsonDocument::fromJson(response.toUtf8(), &parseError));
if (parseError.error == QJsonParseError::NoError) {
if (document.isObject()) { // done: received valid APISM response
if (verbose) {
printInfoMessage(port, clientIP, clientPort,
QString("VALID APISM RESPONSE .. \n") + response);
}
printInfoMessage(port, clientIP, clientPort,
QString("VALID APISM RESPONSE .. \n") + response);
::close(sockfd);
return response;
} else {

View File

@ -37,7 +37,7 @@ public:
static char const *reason[REASON::ENTRIES];
static std::optional<QString>
sendRequestReceiveResponse(int port, QString const &request, bool verbose=false);
sendRequestReceiveResponse(int port, QString const &request);
private:
static void printDebugMessage(int port, QString const &clientIP, int clientPort,

View File

@ -9,18 +9,8 @@
#include <QDir>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QRegularExpression>
#include <QFile>
#include <QTextStream>
#include <optional>
#include "commandline_parser.h"
#include "message_handler.h"
#include "ismas_client.h"
int main(int argc, char **argv) {
QByteArray const value = qgetenv("LC_ALL");
@ -28,6 +18,9 @@ int main(int argc, char **argv) {
qputenv("LC_ALL", "C");
}
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
openlog("ATB-UPDATE_CHECK", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
QCoreApplication a(argc, argv);
@ -43,106 +36,15 @@ int main(int argc, char **argv) {
QCommandLineParser parser;
QCommandLineOption ismasConnectOption("ismas-connected");
QCommandLineOption updateRequestedOption("update-requested");
QCommandLineOption verboseOption("verbose");
parser.addOption(ismasConnectOption);
parser.addOption(updateRequestedOption);
parser.addOption(verboseOption);
parser.process(a);
QString connectionStatus{"not connected"};
QString updateRequestStatus{"not requested"};
if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT,
"#M=APISM#C=REQ_SELF#J={}")) {
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
for (QString const &k : d.object().keys()) {
if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
QJsonObject o = d.object()[k].toObject();
QJsonObject::const_iterator it = o.find("Broker");
if (it != o.constEnd()) {
// value for "Broker"
QString const &v = it->toString();
if (v.contains("connected", Qt::CaseInsensitive)) {
connectionStatus = "connected";
} else
if (v.contains("not connected", Qt::CaseInsensitive)) {
connectionStatus = "not connected";
} else
if (v.contains("disconnected", Qt::CaseInsensitive)) {
connectionStatus = "not connected";
} else
if (v.contains("connecting", Qt::CaseInsensitive)) {
connectionStatus = "not connected";
} else
if (v.contains("disconnecting", Qt::CaseInsensitive)) {
connectionStatus = "not connected";
}
break;
}
}
}
}
if (parser.isSet(updateRequestedOption)) {
if (connectionStatus == "connected") {
if (std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT,
"#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
for (QString const &k : d.object().keys()) {
if (k.contains("REQ_ISMASPARAMETER")) {
QJsonObject o = d.object()[k].toObject();
QJsonObject::const_iterator it = o.find("Aknoledge");
if (it == o.constEnd()) continue;
QString const &v = it->toString();
if (v != "OK") break;
for (QString const &k : d.object().keys()) { // request ack
if (!k.contains("FileUpload", Qt::CaseInsensitive)) continue;
QJsonObject o = d.object()[k].toObject();
QJsonObject::const_iterator it = o.find("TRG");
if (it == o.constEnd()) break;
QString const &v = it->toString();
if (v == "WAIT") {
updateRequestStatus = "requested";
} else
if (v.isEmpty()) {
QFile f("/mnt/system_data/cust_nr");
if (!f.exists()) break;
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) break;
QTextStream in(&f);
in.setCodec("UTF-8");
if(!in.atEnd()) {
unsigned custNr = in.readLine().toInt();
if (custNr > 0) {
QString custRepo = QString("/opt/app/tools/atbupdate/customer_%1").arg(custNr);
if (!QDir(custRepo).exists()) {
updateRequestStatus = "not necessary";
}
}
}
}
break;
}
break;
}
}
}
}
qCritical() << updateRequestStatus;
}
if (parser.isSet(ismasConnectOption)) {
qCritical() << connectionStatus;
qCritical() << parser.isSet(ismasConnectOption);
} else
if (parser.isSet(updateRequestedOption)) {
qCritical() << parser.isSet(updateRequestedOption);
}
return 0;

View File

View File

View File

@ -197,8 +197,7 @@ Worker::Worker(int customerNr,
// check ISMAS connectivity
m_workList.push_back(
std::make_unique<CheckIsmasConnectivityCommand>(
//QString("echo CheckIsmasConnectivityCommand")
QString("/opt/app/tools/atbupdate/ATBUpdateCheck --ismas-connected")
QString("echo CheckIsmasConnectivityCommand")
, this));
// check if update activated in ISMAS