Skip to content

Commit

Permalink
Merge branch 'refs/heads/OMEMO' into OMEMO-NEW-OLD
Browse files Browse the repository at this point in the history
  • Loading branch information
Yagiza committed Aug 4, 2021
2 parents bbbb682 + d2c807d commit 75f7157
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/plugins/omemo/signalprotocol.cpp
@@ -1,5 +1,6 @@
#include "signalprotocol.h"

#include <utils/logger.h>
#include <QMutex>
#include <QDateTime>
extern "C" {
Expand Down Expand Up @@ -588,19 +589,19 @@ session_pre_key_bundle *SignalProtocol::createPreKeyBundle(uint32_t ARegistratio

int rc = curve_decode_point(&preKeyPublic, DATA_SIZE(APreKeyPublic), FGlobalContext);
if (rc != SG_SUCCESS) {
errMsg = "curve_decode_point() failed!";
errMsg = "curve_decode_point() failed! (public pre key)";
goto cleanup;
}

rc = curve_decode_point(&signedPreKeyPublic, DATA_SIZE(ASignedPreKeyPublic), FGlobalContext);
if (rc != SG_SUCCESS) {
errMsg = "curve_decode_point() failed!";
errMsg = "curve_decode_point() failed! (public signed pre key)";
goto cleanup;
}

rc = curve_decode_point(&identityKey, DATA_SIZE(AIdentityKey), FGlobalContext);
if (rc != SG_SUCCESS) {
errMsg = "curve_decode_point() failed!";
errMsg = "curve_decode_point() failed! (identity key)";
goto cleanup;
}

Expand Down Expand Up @@ -1351,6 +1352,26 @@ int SignalProtocol::decryptFunc(signal_buffer **AOutput, int ACipher, const uint
return rc;
}

void SignalProtocol::logFunc(int ALevel, const char *AMessage, size_t ALen, void *AUserData)
{
switch (ALevel)
{
case SG_LOG_ERROR:
qCritical("%s", AMessage);
break;
case SG_LOG_WARNING:
qWarning("%s", AMessage);
break;
case SG_LOG_NOTICE:
case SG_LOG_INFO:
qInfo("%s", AMessage);
break;
case SG_LOG_DEBUG:
qDebug("%s", AMessage);
break;
}
}

void SignalProtocol::recursiveMutexLock(void *AUserData)
{
reinterpret_cast<SignalProtocol *>(AUserData)->recursiveMutexLock();
Expand Down Expand Up @@ -1420,6 +1441,13 @@ SignalProtocol::SignalProtocol(const QString &AFileName, const QString &AConnect
goto cleanup;
}

// 3. set logging function
if (signal_context_set_log_function(FGlobalContext, logFunc)) {
errMsg = "failed to set logging function";
FError = -1;
goto cleanup;
}

// Init store context
if (signal_protocol_store_context_create(&FStoreContext, FGlobalContext)) {
errMsg = "failed to create store context";
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/omemo/signalprotocol.h
Expand Up @@ -338,6 +338,16 @@ class SignalProtocol
const uint8_t *ACiphertext, size_t ACiphertextLen,
void *AUserData);

/**
* Callback for Sighnal logging function.
*
* @param ALevel log level
* @param AMessagr log message
* @param ALen message length
* @param AUserData opaque user data
*/
static void logFunc(int ALevel, const char *AMessage, size_t ALen, void *AUserData);

static void recursiveMutexLock(void *AUserData);
static void recursiveMutexUnlock(void *AUserData);

Expand Down

0 comments on commit 75f7157

Please sign in to comment.