Skip to content

Commit

Permalink
Merge branch 'dev' into tobias/cross-signing
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Sep 11, 2023
2 parents fa1b247 + 14247af commit 8fa6664
Show file tree
Hide file tree
Showing 43 changed files with 1,105 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ PenaltyBreakComment: 45
#PenaltyBreakOpenParenthesis: 0 # ClangFormat 14
PenaltyBreakString: 200
#PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 40
PenaltyExcessCharacter: 30
PenaltyReturnTypeOnItsOwnLine: 200
#PenaltyIndentedWhitespace: 0
#PointerAlignment: Left
Expand Down
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ CheckOptions:
# value: 'false'
# - key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
# value: 'false'
# - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
# value: 'false'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 'true'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '1'
- key: google-readability-namespace-comments.ShortNamespaceLines
Expand Down
32 changes: 13 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_policy(SET CMP0092 NEW)
endif()

set(API_VERSION "0.8")
project(Quotient VERSION "${API_VERSION}.0" LANGUAGES CXX)
project(Quotient VERSION "${API_VERSION}.1.1" LANGUAGES CXX)

message(STATUS)
message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION} ==>")
Expand Down Expand Up @@ -51,6 +51,18 @@ else()
add_compile_options(-fno-exceptions)
endif()

add_compile_definitions(
QT_NO_JAVA_STYLE_ITERATORS QT_NO_URL_CAST_FROM_STRING QT_NO_CAST_TO_ASCII
QT_NO_CAST_FROM_ASCII QT_STRICT_ITERATORS QT_NO_CAST_FROM_BYTEARRAY
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_FOREACH)

set_directory_properties(PROPERTIES
CXX_STANDARD 20
CXX_EXTENSIONS OFF
VISIBILITY_INLINES_HIDDEN ON
CXX_VISIBILITY_PRESET hidden
)

option(BUILD_WITH_QT6 "Build Quotient with Qt 6 (EXPERIMENTAL)" OFF)
if (BUILD_WITH_QT6)
set(QUOTIENT_LIB_NAME ${PROJECT_NAME}Qt6)
Expand Down Expand Up @@ -244,7 +256,6 @@ if (API_GENERATION_ENABLED)
${ABS_GTAD_PATH} --config ../gtad/gtad.yaml --out ${CSAPI_DIR}
${FULL_CSAPI_SRC_DIR}
old_sync.yaml- room_initial_sync.yaml- # deprecated
key_backup.yaml- # immature and buggy in terms of API definition
sync.yaml- # we have a better handcrafted implementation
${GTAD_ARGS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/Quotient
Expand All @@ -270,37 +281,20 @@ add_feature_info(EnableApiCodeGeneration "${API_GENERATION_ENABLED}"
file(GLOB_RECURSE api_ALL_SRCS CONFIGURE_DEPENDS
${FULL_CSAPI_DIR}/*.* Quotient/${ASAPI_DEF_DIR}/*.* Quotient/${ISAPI_DEF_DIR}/*.*)

add_compile_options(
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
-DQT_NO_FOREACH
)

add_library(${QUOTIENT_LIB_NAME} ${lib_SRCS} ${api_ALL_SRCS})
# Set BUILDING_SHARED_QUOTIENT if building as a shared library
target_compile_definitions(${QUOTIENT_LIB_NAME} PRIVATE
$<$<STREQUAL:$<TARGET_PROPERTY:${QUOTIENT_LIB_NAME},TYPE>,SHARED_LIBRARY>:BUILDING_SHARED_QUOTIENT>)
# Set QUOTIENT_STATIC in a static library setting
target_compile_definitions(${QUOTIENT_LIB_NAME} PUBLIC
$<$<STREQUAL:$<TARGET_PROPERTY:${QUOTIENT_LIB_NAME},TYPE>,STATIC_LIBRARY>:QUOTIENT_STATIC>)
target_compile_definitions(${QUOTIENT_LIB_NAME} PRIVATE
QT_NO_JAVA_STYLE_ITERATORS QT_NO_URL_CAST_FROM_STRING QT_NO_CAST_TO_ASCII
QT_STRICT_ITERATORS QT_NO_CAST_FROM_BYTEARRAY)

target_compile_definitions(${QUOTIENT_LIB_NAME} PUBLIC ${PROJECT_NAME}_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
${PROJECT_NAME}_VERSION_MINOR=${PROJECT_VERSION_MINOR} ${PROJECT_NAME}_VERSION_PATCH=${PROJECT_VERSION_PATCH}
${PROJECT_NAME}_VERSION_STRING=\"${PROJECT_VERSION}\")
if (${PROJECT_NAME}_ENABLE_E2EE)
target_compile_definitions(${QUOTIENT_LIB_NAME} PUBLIC ${PROJECT_NAME}_E2EE_ENABLED)
endif()
set_target_properties(${QUOTIENT_LIB_NAME} PROPERTIES
CXX_STANDARD 20
CXX_EXTENSIONS OFF
VISIBILITY_INLINES_HIDDEN ON
CXX_VISIBILITY_PRESET hidden
VERSION "${PROJECT_VERSION}"
SOVERSION ${API_VERSION}
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${API_VERSION}
Expand Down
3 changes: 1 addition & 2 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "user.h"

// NB: since Qt 6, moc_connection.cpp needs Room and User fully defined
#include "moc_connection.cpp"
#include "moc_connection.cpp" // NOLINT(bugprone-suspicious-include)
#include "util.h"

#include "csapi/account-data.h"
Expand All @@ -34,7 +34,6 @@
#include "jobs/downloadfilejob.h"
#include "jobs/mediathumbnailjob.h"
#include "jobs/syncjob.h"
#include <variant>

#ifdef Quotient_E2EE_ENABLED
# include "connectionencryptiondata_p.h"
Expand Down
14 changes: 9 additions & 5 deletions Quotient/connectionencryptiondata_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void ConnectionEncryptionData::consumeToDeviceEvents(Events&& toDeviceEvents)
if (!toDeviceEvents.empty()) {
qCDebug(E2EE) << "Consuming" << toDeviceEvents.size()
<< "to-device events";
for (auto&& tdEvt : toDeviceEvents) {
for (auto&& tdEvt : std::move(toDeviceEvents)) {
if (processIfVerificationEvent(*tdEvt, false))
continue;
if (auto&& event = eventCast<EncryptedEvent>(std::move(tdEvt))) {
Expand Down Expand Up @@ -334,10 +334,14 @@ bool ConnectionEncryptionData::processIfVerificationEvent(const Event& evt,
reqEvt, q, encrypted);
return true;
},
[](const KeyVerificationDoneEvent&) { return true; },
[](const KeyVerificationDoneEvent&) {
qCDebug(E2EE) << "Ignoring m.key.verification.done";
return true;
},
[this](const KeyVerificationEvent& kvEvt) {
if (auto* const session =
verificationSessions.value(kvEvt.transactionId())) {
qCDebug(E2EE) << "Handling" << kvEvt.matrixType();
session->handleEvent(kvEvt);
emit q->keyVerificationStateChanged(session, session->state());
}
Expand All @@ -351,7 +355,8 @@ void ConnectionEncryptionData::handleEncryptedToDeviceEvent(
{
const auto [decryptedEvent, olmSessionId] = sessionDecryptMessage(event);
if (!decryptedEvent) {
qCWarning(E2EE) << "Failed to decrypt event" << event.id();
qCWarning(E2EE) << "Failed to decrypt to-device event from device"
<< event.deviceId();
return;
}

Expand Down Expand Up @@ -737,8 +742,7 @@ std::pair<QByteArray, QByteArray> ConnectionEncryptionData::sessionDecryptMessag
auto newSessionResult =
olmAccount.createInboundSessionFrom(senderKey, message);
if (!newSessionResult) {
qCWarning(E2EE) << "Failed to create inbound session for" << senderKey
<< "with error" << newSessionResult.error();
qCWarning(E2EE) << "Failed to create inbound session for" << senderKey;
return {};
}
auto&& newSession = std::move(*newSessionResult);
Expand Down
2 changes: 2 additions & 0 deletions Quotient/connectionencryptiondata_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "connection.h"
#include "database.h"
#include "logging_categories_p.h"

#include "e2ee/qolmaccount.h"
#include "e2ee/qolmsession.h"
Expand Down Expand Up @@ -84,6 +85,7 @@ namespace _impl {
{
auto session =
new KeyVerificationSession(std::forward<ArgTs>(sessionArgs)...);
qCDebug(E2EE) << "Incoming key verification session from" << session->remoteDeviceId();
verificationSessions.insert(session->transactionId(), session);
QObject::connect(session, &QObject::destroyed, q,
[this, txnId = session->transactionId()] {
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/administrative_contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Quotient/csapi/definitions/request_email_validation.h>
#include <Quotient/csapi/definitions/request_msisdn_validation.h>
#include <Quotient/csapi/definitions/request_token_response.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
4 changes: 2 additions & 2 deletions Quotient/csapi/content-repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#pragma once

#include <Quotient/jobs/basejob.h>

#include <QtCore/QIODevice>
#include <QtNetwork/QNetworkReply>

#include <Quotient/jobs/basejob.h>

namespace Quotient {

/*! \brief Upload some content to the content repository.
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/cross_signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <Quotient/csapi/definitions/auth_data.h>
#include <Quotient/csapi/definitions/cross_signing_key.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
49 changes: 49 additions & 0 deletions Quotient/csapi/definitions/key_backup_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/******************************************************************************
* THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
*/

#pragma once

#include <Quotient/converters.h>

namespace Quotient {
/// The key data
struct KeyBackupData {
/// The index of the first message in the session that the key can decrypt.
int firstMessageIndex;

/// The number of times this key has been forwarded via key-sharing between
/// devices.
int forwardedCount;

/// Whether the device backing up the key verified the device that the key
/// is from.
bool isVerified;

/// Algorithm-dependent data. See the documentation for the backup
/// algorithms in [Server-side key
/// backups](/client-server-api/#server-side-key-backups) for more
/// information on the expected format of the data.
QJsonObject sessionData;
};

template <>
struct JsonObjectConverter<KeyBackupData> {
static void dumpTo(QJsonObject& jo, const KeyBackupData& pod)
{
addParam<>(jo, QStringLiteral("first_message_index"),
pod.firstMessageIndex);
addParam<>(jo, QStringLiteral("forwarded_count"), pod.forwardedCount);
addParam<>(jo, QStringLiteral("is_verified"), pod.isVerified);
addParam<>(jo, QStringLiteral("session_data"), pod.sessionData);
}
static void fillFrom(const QJsonObject& jo, KeyBackupData& pod)
{
fillFromJson(jo.value("first_message_index"_ls), pod.firstMessageIndex);
fillFromJson(jo.value("forwarded_count"_ls), pod.forwardedCount);
fillFromJson(jo.value("is_verified"_ls), pod.isVerified);
fillFromJson(jo.value("session_data"_ls), pod.sessionData);
}
};

} // namespace Quotient
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/push_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/push_condition.h>

#include <Quotient/converters.h>

namespace Quotient {

struct PushRule {
Expand Down
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/push_ruleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/push_rule.h>

#include <Quotient/converters.h>

namespace Quotient {

struct PushRuleset {
Expand Down
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/room_event_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/event_filter.h>

#include <Quotient/converters.h>

namespace Quotient {

struct RoomEventFilter : EventFilter {
Expand Down
30 changes: 30 additions & 0 deletions Quotient/csapi/definitions/room_key_backup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/******************************************************************************
* THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
*/

#pragma once

#include <Quotient/csapi/definitions/key_backup_data.h>

#include <Quotient/converters.h>

namespace Quotient {
/// The backed up keys for a room.
struct RoomKeyBackup {
/// A map of session IDs to key data.
QHash<QString, KeyBackupData> sessions;
};

template <>
struct JsonObjectConverter<RoomKeyBackup> {
static void dumpTo(QJsonObject& jo, const RoomKeyBackup& pod)
{
addParam<>(jo, QStringLiteral("sessions"), pod.sessions);
}
static void fillFrom(const QJsonObject& jo, RoomKeyBackup& pod)
{
fillFromJson(jo.value("sessions"_ls), pod.sessions);
}
};

} // namespace Quotient
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/sync_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/event_filter.h>
#include <Quotient/csapi/definitions/room_event_filter.h>

#include <Quotient/converters.h>

namespace Quotient {
/// Filters to be applied to room data.
struct RoomFilter {
Expand Down
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/wellknown/full.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/wellknown/homeserver.h>
#include <Quotient/csapi/definitions/wellknown/identity_server.h>

#include <Quotient/converters.h>

namespace Quotient {
/// Used by clients to determine the homeserver, identity server, and other
/// optional components they should be interacting with.
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/device_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <Quotient/csapi/definitions/auth_data.h>
#include <Quotient/csapi/definitions/client_device.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <Quotient/csapi/definitions/sync_filter.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/joining.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <Quotient/csapi/definitions/third_party_signed.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
Loading

0 comments on commit 8fa6664

Please sign in to comment.