diff --git a/libssu/libssu.pro b/libssu/libssu.pro index f7bb76b..3ba46f8 100644 --- a/libssu/libssu.pro +++ b/libssu/libssu.pro @@ -4,10 +4,11 @@ HEADERS = ssu.h \ SOURCES = ssu.cpp TEMPLATE = lib TARGET = ssu -CONFIG += dll mobility +CONFIG += dll mobility link_pkgconfig QT -= gui QT += network xml MOBILITY += systeminfo +PKGCONFIG += libsystemd-journal headers.files = ssu.h headers.path = /usr/include diff --git a/libssu/ssu.cpp b/libssu/ssu.cpp index 882dcb8..4939b00 100644 --- a/libssu/ssu.cpp +++ b/libssu/ssu.cpp @@ -8,13 +8,15 @@ #include #include + #include "ssu.h" #include "../constants.h" QTM_USE_NAMESPACE -Ssu::Ssu(): QObject(){ +Ssu::Ssu(QString fallbackLog): QObject(){ errorFlag = false; + fallbackLogPath = fallbackLog; #ifdef SSUCONFHACK // dirty hack to make sure we can write to the configuration @@ -289,6 +291,21 @@ QString Ssu::lastError(){ return errorString; } +void Ssu::printJournal(int priority, QString message){ + QByteArray ba = message.toUtf8(); + const char *ca = ba.constData(); + + if (sd_journal_print(LOG_INFO, "ssu: %s", ca) < 0 && fallbackLogPath != ""){ + QFile logfile; + QTextStream logstream; + logfile.setFileName(fallbackLogPath); + logfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); + logstream.setDevice(&logfile); + logstream << message << "\n"; + logstream.flush(); + } +} + bool Ssu::registerDevice(QDomDocument *response){ QString certificateString = response->elementsByTagName("certificate").at(0).toElement().text(); QSslCertificate certificate(certificateString.toAscii()); diff --git a/libssu/ssu.h b/libssu/ssu.h index a5b5bdc..6f959f6 100644 --- a/libssu/ssu.h +++ b/libssu/ssu.h @@ -16,11 +16,13 @@ #include +#include + class Ssu: public QObject { Q_OBJECT public: - Ssu(); + Ssu(QString fallbackLog=""); /** * Find a username/password pair for the given scope * @return a QPair with username and password, or an empty QPair if scope is invalid @@ -86,6 +88,10 @@ class Ssu: public QObject { * successful. */ Q_INVOKABLE QString lastError(); + /** + * Print a message to systemds journal, or to a text log file, if a fallback is defined + */ + void printJournal(int priority, QString message); /** * Return the release version string for either a release, or a RnD snapshot */ @@ -122,7 +128,7 @@ class Ssu: public QObject { Q_INVOKABLE bool useSslVerify(); private: - QString errorString; + QString errorString, fallbackLogPath; QString cachedModel, cachedFamily; bool errorFlag; QNetworkAccessManager *manager;