summaryrefslogtreecommitdiff
path: root/Network
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2024-09-30 22:36:11 +0200
committerChristoph Berg <myon@debian.org>2024-09-30 22:36:11 +0200
commit4320ce238aae1fe87fc9f379cdd816e9317885fa (patch)
treeb9d97364486fc8b7f79e8e877d5d491bb061740f /Network
parentfbaeaa72f63f22bf0b53d634f6809cbdfbb46c9f (diff)
New upstream version 2.7.0~rc7+repackupstream/2.7.0_rc7+repack
Diffstat (limited to 'Network')
-rwxr-xr-xNetwork/FoxVerifier.cpp125
-rwxr-xr-xNetwork/FoxVerifier.hpp63
-rwxr-xr-xNetwork/MessageClient.cpp17
-rwxr-xr-xNetwork/MessageClient.hpp5
-rwxr-xr-xNetwork/Network.pri21
-rwxr-xr-xNetwork/NetworkMessage.hpp37
6 files changed, 265 insertions, 3 deletions
diff --git a/Network/FoxVerifier.cpp b/Network/FoxVerifier.cpp
new file mode 100755
index 00000000..2882f34a
--- /dev/null
+++ b/Network/FoxVerifier.cpp
@@ -0,0 +1,125 @@
+#include "FoxVerifier.hpp"
+#include "Logger.hpp"
+
+FoxVerifier::FoxVerifier(QString user_agent, QNetworkAccessManager *manager,QString base_url, QString callsign, QDateTime timestamp, QString code, unsigned int hz=750) : QObject(nullptr)
+{
+ manager_ = manager;
+ finished_ = false;
+ errored_ = false;
+ callsign_ = callsign;
+ code_ = code;
+ ts_ = timestamp;
+ hz_ = hz;
+
+ // make sure we URLencode the callsign, for things like E51D/MM
+ QString encodedCall = QString::fromUtf8(QUrl::toPercentEncoding(callsign));
+ QString url = QString("%1/check/").arg(base_url) + encodedCall + QString("/%1/%2.text").arg(timestamp.toString(Qt::ISODate)).arg(code);
+ LOG_INFO(QString("FoxVerifier: url %1").arg(url).toStdString());
+ q_url_ = QUrl(url);
+ if (manager_ == nullptr) {
+ LOG_INFO("FoxVerifier: manager is null, creating new one");
+ manager_ = new QNetworkAccessManager(this);
+ manager_->deleteLater();
+ }
+ if (q_url_.isValid()) {
+ request_ = QNetworkRequest(q_url_);
+ request_.setRawHeader( "User-Agent" , user_agent.toUtf8());
+ request_.setRawHeader( "Accept" , "*/*" );
+ request_.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ request_.setTransferTimeout(FOXVERIFIER_DEFAULT_TIMEOUT_MSEC);
+#endif
+
+ reply_ = manager_->get(request_);
+ connect(reply_, &QNetworkReply::finished, this, &FoxVerifier::httpFinished);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ connect(reply_, &QNetworkReply::errorOccurred, this, &FoxVerifier::errorOccurred);
+#endif
+ connect(reply_, &QNetworkReply::redirected, this, &FoxVerifier::httpRedirected);
+ connect(reply_, &QNetworkReply::encrypted, this, &FoxVerifier::httpEncrypted);
+#if QT_CONFIG(ssl)
+ connect(reply_, &QNetworkReply::sslErrors, this, &FoxVerifier::sslErrors);
+#else
+ LOG_INFO("FoxVerifier: ssl not supported");
+#endif
+
+ } else {
+ LOG_INFO(QString("FoxVerifier: url invalid ! %1").arg(url).toStdString());
+ }
+}
+
+FoxVerifier::~FoxVerifier() {
+}
+
+bool FoxVerifier::finished() {
+ return finished_;
+}
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+void FoxVerifier::errorOccurred(QNetworkReply::NetworkError code)
+{
+ int status = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QString reason = reply_->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
+ errored_ = true;
+ error_reason_ = reply_->errorString();
+ if (reply_->error() != QNetworkReply::NoError) {
+
+ LOG_INFO(QString("FoxVerifier: errorOccurred status %1 error [%2][%3] isFinished %4 isrunning %5 code %6").arg(status).arg(
+ reason).arg(error_reason_).arg(reply_->isFinished()).arg(reply_->isRunning()).arg(code).toStdString());
+ return;
+ }
+ // TODO emit
+}
+#endif
+
+void FoxVerifier::httpFinished()
+{
+ int status = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QString reason = reply_->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
+ if (reply_->error() != QNetworkReply::NoError) {
+ LOG_INFO(QString("FoxVerifier: httpFinished error:[%1 - %2] msg:[%3]").arg(status).arg(reason).arg(reply_->errorString()).toStdString());
+ reply_->abort();
+ emit verifyError(status, ts_, callsign_, code_, hz_, reply_->errorString());
+ }
+ return_value = reply_->read(1024); // limit amount we get
+ LOG_INFO(QString("FoxVerifier: httpFinished status:[%1 - %2] body:[%3] ").arg(status).arg(reason).arg(return_value).toStdString());
+ finished_ = true;
+ reply_->deleteLater();
+ if (status >= 200 && status <= 299) {
+ emit verifyComplete(status, ts_, callsign_, code_, hz_, return_value);
+ }
+}
+
+void FoxVerifier::sslErrors(const QList<QSslError> &)
+{
+ LOG_INFO(QString("FoxVerifier: sslErrors").toStdString());
+ reply_->ignoreSslErrors();
+}
+
+void FoxVerifier::httpRedirected(const QUrl &url) {
+ LOG_INFO(QString("FoxVerifier: redirected to %1").arg(url.toString()).toStdString());
+}
+
+void FoxVerifier::httpEncrypted() {
+ LOG_INFO("FoxVerifier: httpEncrypted");
+}
+
+QString FoxVerifier::formatDecodeMessage(QDateTime ts, QString callsign, unsigned int hz_, QString const& verify_message) {
+ //"172100 -00 0.0 750 ~ K8R VERIFIED"
+ QTime rx_time = ts.time();
+ QString hz=QString("%1").arg(hz_, 4, 10 ); // insert Hz
+ if (verify_message.endsWith(" VERIFIED")) {
+ return QString("%1 0 0.0 %2 ~ %3 verified").arg(rx_time.toString("hhmmss")).arg(hz).arg(callsign);
+ } else
+ if (verify_message.endsWith(" INVALID"))
+ {
+ return QString("%1 0 0.0 %2 ~ %3 invalid").arg(rx_time.toString("hhmmss")).arg(hz).arg(callsign);
+ }
+ else
+ return QString{};
+}
+
+QString FoxVerifier::default_url() {
+ return QString(FOXVERIFIER_DEFAULT_BASE_URL);
+}
diff --git a/Network/FoxVerifier.hpp b/Network/FoxVerifier.hpp
new file mode 100755
index 00000000..0a645189
--- /dev/null
+++ b/Network/FoxVerifier.hpp
@@ -0,0 +1,63 @@
+
+#ifndef WSJTX2_FOXVERIFIER_HPP
+#define WSJTX2_FOXVERIFIER_HPP
+
+#include <QObject>
+#include <QString>
+#include <QPointer>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QMutex>
+
+#define FOXVERIFIER_DEFAULT_TIMEOUT_MSEC 5000
+#define FOXVERIFIER_DEFAULT_BASE_URL "https://www.9dx.cc"
+
+class FoxVerifier : public QObject {
+ Q_OBJECT
+ QMutex mutex_;
+
+public:
+ explicit FoxVerifier(QString user_agent, QNetworkAccessManager *manager, QString base_url, QString callsign, QDateTime timestamp, QString code, unsigned int);
+ ~FoxVerifier();
+
+ QString return_value;
+ bool finished();
+ static QString formatDecodeMessage(QDateTime ts, QString callsign, unsigned int hz, QString const& verify_message);
+ static QString default_url();
+
+private:
+ QNetworkAccessManager* manager_;
+ QNetworkReply* reply_;
+ QNetworkRequest request_;
+ QUrl q_url_;
+ bool finished_;
+ bool errored_;
+ unsigned int hz_;
+ QString error_reason_;
+ QDateTime ts_;
+ QString callsign_;
+ QString code_;
+
+private slots:
+ void httpFinished();
+ void httpRedirected(const QUrl &url);
+ void httpEncrypted();
+#ifndef QT_NO_SSL
+ void sslErrors(const QList<QSslError> &);
+#endif
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ void errorOccurred(QNetworkReply::NetworkError code);
+#endif
+//signals:
+ //void results(QString verify_response);
+ //void error(QString const& reason) const;
+
+public slots:
+signals:
+ void verifyComplete(int status, QDateTime ts, QString callsign, QString code, unsigned int hz, QString const& response);
+ void verifyError(int status, QDateTime ts, QString callsign, QString code, unsigned int hz, QString const& response);
+
+};
+
+
+#endif //WSJTX2_FOXVERIFIER_HPP
diff --git a/Network/MessageClient.cpp b/Network/MessageClient.cpp
index aa26fa1f..a34a5a00 100755
--- a/Network/MessageClient.cpp
+++ b/Network/MessageClient.cpp
@@ -392,7 +392,22 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
}
break;
- default:
+ case NetworkMessage::AnnotationInfo: {
+ QByteArray dx_call;
+ bool sort_order_provided{false};
+ quint32 sort_order{std::numeric_limits<quint32>::max()};
+ in >> dx_call >> sort_order_provided >> sort_order;
+ TRACE_UDP ("External Callsign Info:" << dx_call << "sort_order_provided:" << sort_order_provided
+ << "sort_order:" << sort_order);
+ if (sort_order > 50000) sort_order = 50000;
+ if (check_status(in) != Fail) {
+ Q_EMIT
+ self_->annotation_info(QString::fromUtf8(dx_call), sort_order_provided, sort_order);
+ }
+ }
+ break;
+
+ default:
// Ignore
//
// Note that although server heartbeat messages are not
diff --git a/Network/MessageClient.hpp b/Network/MessageClient.hpp
index 05348f27..66a3f56e 100755
--- a/Network/MessageClient.hpp
+++ b/Network/MessageClient.hpp
@@ -123,7 +123,10 @@ public:
, bool fast_mode, quint32 tr_period, quint32 rx_df, QString const& dx_call
, QString const& dx_grid, bool generate_messages);
- // this signal is emitted when network errors occur or if a host
+ // this signal is emitted if the server has sent information about a callsign
+ Q_SIGNAL void annotation_info (QString const& dx_call, bool sort_order_provided, quint32 sort_order);
+
+ // this signal is emitted when network errors occur or if a host
// lookup fails
Q_SIGNAL void error (QString const&) const;
diff --git a/Network/Network.pri b/Network/Network.pri
new file mode 100755
index 00000000..ac590793
--- /dev/null
+++ b/Network/Network.pri
@@ -0,0 +1,21 @@
+SOURCES += \
+Network/FileDownload.cpp \
+Network/FoxVerifier.cpp \
+Network/LotWUsers.cpp \
+Network/MessageClient.cpp \
+Network/NetworkAccessManager.cpp \
+Network/NetworkMessage.cpp \
+Network/NetworkServerLookup.cpp \
+Network/PSKReporter.cpp \
+Network/wsprnet.cpp
+
+HEADERS += \
+Network/FileDownload.hpp \
+Network/FoxVerifier.hpp \
+Network/LotWUsers.hpp \
+Network/MessageClient.hpp \
+Network/NetworkAccessManager.hpp \
+Network/NetworkMessage.hpp \
+Network/NetworkServerLookup.hpp \
+Network/PSKReporter.hpp \
+Network/wsprnet.h
diff --git a/Network/NetworkMessage.hpp b/Network/NetworkMessage.hpp
index 728e71e4..c046c3db 100755
--- a/Network/NetworkMessage.hpp
+++ b/Network/NetworkMessage.hpp
@@ -463,6 +463,14 @@
* limit the number of active highlighting requests to no more
* than 100.
*
+ * Using a callsign of "CLEARALL!" and anything for the
+ * color values will clear the internal highlighting data. It will
+ * NOT remove the highlighting on the screen, however. The exclamation
+ * symbol is used to avoid accidental clearing of all highlighting
+ * data via a decoded callsign, since an exclamation symbol is not
+ * a valid character in a callsign.
+
+ *
* The "Highlight last" field allows the sender to request that
* all instances of "Callsign" in the last period only, instead
* of all instances in all periods, be highlighted.
@@ -494,7 +502,33 @@
* fields an empty value implies no change, for the quint32 Rx DF
* and Frequency Tolerance fields the maximum quint32 value
* implies no change. Invalid or unrecognized values will be
- * silently ignored.
+ * silently ignored. NOTE that if a mode/submode change occurs and
+ * the current frequency is NOT in the frequency table for that
+ * mode, a frequency change (to the default frequency for that band
+ * and mode) may occur.
+ *
+ * AnnotationInfo In 16 quint32
+ * Id (unique key) utf8
+ * DX Call utf8
+ * Sort Order Provided bool
+ * Sort Order quint32
+ *
+ * The server may send this message at any time. Sort orders can be used
+ * for sorting hound callers when in Fox mode. A typical usage is to
+ * "score" callsigns based on number of bands and/or modes worked using
+ * an external logging program during a DXpedition, to be able to give
+ * preference to calls that have not been worked before on any other
+ * band or mode. An external program can watch decodes from wsjt-x,
+ * then use this message to annotate the calls with a sort order. The
+ * hound queue can be displayed by that sort order. *
+ *
+ * If 'sort order provided' is true, the message also specifies a numeric
+ * sort order for the DX call.
+ *
+ * Invalid or unrecognized values will be silently ignored. A sort-order of
+ * ffffffff will remove the sort-order value from the internal table.
+ * Callsigns without a sort order will be valued at zero for sorting purposes
+ * in the hound display.
*/
#include <QDataStream>
@@ -526,6 +560,7 @@ namespace NetworkMessage
HighlightCallsign,
SwitchConfiguration,
Configure,
+ AnnotationInfo,
maximum_message_type_ // ONLY add new message types
// immediately before here
};