From 9eaa420b7bf51cc81c50e7f4ca0f256498a07c86 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 13 Oct 2023 15:57:15 +0200 Subject: [PATCH] HTTP layer for ESP32, make static specifier in matrix.c optional by defining it as a macro --- Todo.md | 4 +- esp32/esp_project/CMakeLists.txt | 3 + .../esp_project/components/olm/CMakeLists.txt | 16 +- esp32/esp_project/main/CMakeLists.txt | 2 +- esp32/esp_project/main/main.c | 63 ------ esp32/esp_project/main/wifi.c | 23 ++- esp32/esp_project/sdkconfig | 48 ++--- examples/Send.c | 16 +- examples/SendEncrypted.c | 2 +- src/matrix.c | 195 +++++++++++------- src/matrix.h | 106 ++++++---- 11 files changed, 243 insertions(+), 235 deletions(-) delete mode 100644 esp32/esp_project/main/main.c diff --git a/Todo.md b/Todo.md index b8e62c5..bbf754d 100644 --- a/Todo.md +++ b/Todo.md @@ -12,8 +12,8 @@ + incoming + outgoing + store keys/sessions -- respond to events - - room_key_request ++ respond to events + + room_key_request + add client saving/loading - overhaul client saving/loading + esp compatibility diff --git a/esp32/esp_project/CMakeLists.txt b/esp32/esp_project/CMakeLists.txt index 1d08676..897cd8e 100644 --- a/esp32/esp_project/CMakeLists.txt +++ b/esp32/esp_project/CMakeLists.txt @@ -4,3 +4,6 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(esp_project) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") +SET(CMAKE_CXX_COMPILER "C:/Espressif/tools/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc.exe") \ No newline at end of file diff --git a/esp32/esp_project/components/olm/CMakeLists.txt b/esp32/esp_project/components/olm/CMakeLists.txt index 352ab9c..e17b8ad 100644 --- a/esp32/esp_project/components/olm/CMakeLists.txt +++ b/esp32/esp_project/components/olm/CMakeLists.txt @@ -1,6 +1,6 @@ idf_component_register(SRCS "../../../../ext/olm/src/account.cpp" - #"../../../../ext/olm/lib/crypto-algorithms/aes.c" + "../../../../ext/olm/lib/crypto-algorithms/aes.c" "../../../../ext/olm/src/base64.cpp" "../../../../ext/olm/src/cipher.cpp" "../../../../ext/olm/src/crypto.cpp" @@ -16,29 +16,23 @@ idf_component_register(SRCS "../../../../ext/olm/src/pickle.cpp" "../../../../ext/olm/src/pickle_encoding.c" "../../../../ext/olm/src/pk.cpp" + "../../../../ext/olm/src/ratchet.cpp" "../../../../ext/olm/src/sas.c" "../../../../ext/olm/src/session.cpp" "../../../../ext/olm/lib/crypto-algorithms/sha256.c" "../../../../ext/olm/src/utility.cpp" - "../../../../src/matrix.c" - "../../../../src/matrix_http_mongoose.c" - "../../../../ext/mongoose/mongoose.c" - "../../../../ext/mjson/src/mjson.c" INCLUDE_DIRS "../../../../ext/olm/include" "../../../../ext/olm/lib" - "../../../../ext/mongoose" - "../../../../ext/mjson/src" "../../../../src" REQUIRES - esp_timer - mbedtls) + esp_timer) add_definitions(-DOLM_STATIC_DEFINE) add_definitions(-DOLMLIB_VERSION_MAJOR=3) add_definitions(-DOLMLIB_VERSION_MINOR=2) add_definitions(-DOLMLIB_VERSION_PATCH=15) -add_definitions(-DMG_ENABLE_MBEDTLS=1) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -Wl,--allow-multiple-definition") +SET(CMAKE_CXX_COMPILER "C:/Espressif/tools/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc.exe") diff --git a/esp32/esp_project/main/CMakeLists.txt b/esp32/esp_project/main/CMakeLists.txt index d0c6abb..ddba2b1 100644 --- a/esp32/esp_project/main/CMakeLists.txt +++ b/esp32/esp_project/main/CMakeLists.txt @@ -1,2 +1,2 @@ -idf_component_register(SRCS "main.c" "wifi.c" +idf_component_register(SRCS "wifi.c" "Verify.c" INCLUDE_DIRS "") \ No newline at end of file diff --git a/esp32/esp_project/main/main.c b/esp32/esp_project/main/main.c deleted file mode 100644 index b090849..0000000 --- a/esp32/esp_project/main/main.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: CC0-1.0 - */ - -#define OLMLIB_VERSION_MAJOR 3 -#define OLMLIB_VERSION_MINOR 2 -#define OLMLIB_VERSION_PATCH 15 - -#define OLM_STATIC_DEFINE - -#include -#include -#include - -#include - -#define SERVER "https://matrix.org" -#define USER_ID "@pscho:matrix.org" -#define ROOM_ID "!XKFUjAsGrSSrpDFIxB:matrix.org" - -void -app_main(void) -{ - MatrixClient client; - MatrixClientInit(&client, - SERVER); - - MatrixHttpInit(&client); - - MatrixClientSetUserId(&client, USER_ID); - - MatrixClientLoginPassword(&client, - "pscho", - "Wc23EbmB9G3faMq", - "Test1"); - - MatrixClientUploadDeviceKey(&client); - MatrixClientGenerateOnetimeKeys(&client, 10); - MatrixClientUploadOnetimeKeys(&client); - - // create megolmsession - MatrixMegolmOutSession * megolmOutSession; - MatrixClientGetMegolmOutSession(&client, - ROOM_ID, - &megolmOutSession); - printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key); - - MatrixClientShareMegolmOutSession(&client, - USER_ID, - "ULZZOKJBYN", - megolmOutSession); - - MatrixClientSendEventEncrypted(&client, - ROOM_ID, - "m.room.message", - "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"); - - MatrixClientDeleteDevice(&client); - - MatrixHttpDeinit(&client); -} diff --git a/esp32/esp_project/main/wifi.c b/esp32/esp_project/main/wifi.c index 07d1e41..788d61c 100644 --- a/esp32/esp_project/main/wifi.c +++ b/esp32/esp_project/main/wifi.c @@ -1,4 +1,9 @@ -// Code taken from the ESP32 IDF WiFi station Example +/* + * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ + #include #include "esp_event.h" @@ -13,8 +18,6 @@ #include "lwip/err.h" #include "lwip/sys.h" -#include "mongoose.h" - static EventGroupHandle_t s_wifi_event_group; /* The event group allows multiple bits for each event, but we only care about @@ -35,14 +38,14 @@ static void event_handler(void *arg, esp_event_base_t event_base, if (s_retry_num < 3) { esp_wifi_connect(); s_retry_num++; - MG_INFO(("retry to connect to the AP")); + printf("retry to connect to the AP\n"); } else { xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); } - MG_ERROR(("connect to the AP fail")); + printf("connect to the AP fail\n"); } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data; - MG_INFO(("IP ADDRESS:" IPSTR, IP2STR(&event->ip_info.ip))); + printf("IP ADDRESS:" IPSTR "\n", IP2STR(&event->ip_info.ip)); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); } @@ -81,18 +84,18 @@ void wifi_init(const char *ssid, const char *pass) { ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &c)); ESP_ERROR_CHECK(esp_wifi_start()); - MG_DEBUG(("wifi_init_sta finished.")); + printf("wifi_init_sta finished.\n"); EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, pdFALSE, pdFALSE, portMAX_DELAY); if (bits & WIFI_CONNECTED_BIT) { - MG_INFO(("connected to ap SSID:%s password:%s", ssid, pass)); + printf("connected to ap SSID:%s password:%s\n", ssid, pass); } else if (bits & WIFI_FAIL_BIT) { - MG_ERROR(("Failed to connect to SSID:%s, password:%s", ssid, pass)); + printf("Failed to connect to SSID:%s, password:%s\n", ssid, pass); } else { - MG_ERROR(("UNEXPECTED EVENT")); + printf("UNEXPECTED EVENT\n"); } /* The event will not be processed after unregister */ diff --git a/esp32/esp_project/sdkconfig b/esp32/esp_project/sdkconfig index c55b691..def88a3 100644 --- a/esp32/esp_project/sdkconfig +++ b/esp32/esp_project/sdkconfig @@ -338,15 +338,15 @@ CONFIG_PARTITION_TABLE_MD5=y # # Compiler options # -CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y -# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set +# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set +CONFIG_COMPILER_OPTIMIZATION_SIZE=y # CONFIG_COMPILER_OPTIMIZATION_PERF is not set # CONFIG_COMPILER_OPTIMIZATION_NONE is not set -CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y -# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set +# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE is not set +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y # CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB=y -CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2 +CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=1 # CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT is not set CONFIG_COMPILER_HIDE_PATHS_MACROS=y # CONFIG_COMPILER_CXX_EXCEPTIONS is not set @@ -516,7 +516,8 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y # CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS is not set # CONFIG_ESP_TLS_SERVER is not set # CONFIG_ESP_TLS_PSK_VERIFICATION is not set -# CONFIG_ESP_TLS_INSECURE is not set +CONFIG_ESP_TLS_INSECURE=y +CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y # end of ESP-TLS # @@ -793,7 +794,7 @@ CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS=0 CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y # CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1 is not set # CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set @@ -997,7 +998,6 @@ CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1 # # Port # -CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y # CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y # CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set @@ -1026,8 +1026,7 @@ CONFIG_FREERTOS_DEBUG_OCDAWARE=y CONFIG_HAL_ASSERTION_EQUALS_SYSTEM=y # CONFIG_HAL_ASSERTION_DISABLE is not set # CONFIG_HAL_ASSERTION_SILENT is not set -# CONFIG_HAL_ASSERTION_ENABLE is not set -CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=2 +CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=1 CONFIG_HAL_SPI_MASTER_FUNC_IN_IRAM=y CONFIG_HAL_SPI_SLAVE_FUNC_IN_IRAM=y # end of Hardware Abstraction Layer (HAL) and Low Level (LL) @@ -1278,7 +1277,10 @@ CONFIG_MBEDTLS_TLS_ENABLED=y # # TLS Key Exchange Methods # -# CONFIG_MBEDTLS_PSK_MODES is not set +CONFIG_MBEDTLS_PSK_MODES=y +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK=y +CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK=y CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y @@ -1424,9 +1426,9 @@ CONFIG_MMU_PAGE_SIZE=0x10000 # CONFIG_SPI_FLASH_VERIFY_WRITE is not set # CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y -CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y +# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS is not set # CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set -# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set +CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED=y # CONFIG_SPI_FLASH_SHARE_SPI1_BUS is not set # CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y @@ -1592,14 +1594,14 @@ CONFIG_LOG_BOOTLOADER_LEVEL=3 CONFIG_FLASHMODE_DIO=y # CONFIG_FLASHMODE_DOUT is not set CONFIG_MONITOR_BAUD=115200 -CONFIG_OPTIMIZATION_LEVEL_DEBUG=y -CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y -# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set -# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set -CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y -# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set +# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set +# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set +CONFIG_OPTIMIZATION_LEVEL_RELEASE=y +CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y +# CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED is not set +CONFIG_OPTIMIZATION_ASSERTIONS_SILENT=y # CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set -CONFIG_OPTIMIZATION_ASSERTION_LEVEL=2 +CONFIG_OPTIMIZATION_ASSERTION_LEVEL=1 # CONFIG_CXX_EXCEPTIONS is not set CONFIG_STACK_CHECK_NONE=y # CONFIG_STACK_CHECK_NORM is not set @@ -1652,7 +1654,7 @@ CONFIG_ESP32_PANIC_PRINT_REBOOT=y # CONFIG_ESP32_PANIC_GDBSTUB is not set CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_MAIN_TASK_STACK_SIZE=3584 +CONFIG_MAIN_TASK_STACK_SIZE=8192 CONFIG_CONSOLE_UART_DEFAULT=y # CONFIG_CONSOLE_UART_CUSTOM is not set # CONFIG_CONSOLE_UART_NONE is not set @@ -1773,9 +1775,9 @@ CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y # CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1 is not set CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1 CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread" -CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y +# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS is not set # CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set -# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set +CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED=y # CONFIG_ESP32_ULP_COPROC_ENABLED is not set CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y CONFIG_SUPPORT_TERMIOS=y diff --git a/examples/Send.c b/examples/Send.c index cddb966..9ab7dfb 100644 --- a/examples/Send.c +++ b/examples/Send.c @@ -1,8 +1,7 @@ #include #define SERVER "https://matrix.org" -#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO" -#define DEVICE_ID "MAZNCCZLBR" +#define USER_ID "@pscho:matrix.org" #define ROOM_ID "!koVStwyiiKcBVbXZYz:matrix.org" int @@ -14,14 +13,23 @@ main(void) MatrixHttpInit(&client); - MatrixClientSetAccessToken(&client, - ACCESS_TOKEN); + + MatrixClientSetUserId(&client, USER_ID); + + MatrixClientLoginPassword(&client, + "pscho", + "Wc23EbmB9G3faMq", + "Test1"); + MatrixClientSendEvent(&client, ROOM_ID, "m.room.message", "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"); + + MatrixClientDeleteDevice(&client); + MatrixHttpDeinit(&client); return 0; diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c index df1d272..c2fda6c 100644 --- a/examples/SendEncrypted.c +++ b/examples/SendEncrypted.c @@ -34,7 +34,7 @@ main(void) // create megolmsession MatrixMegolmOutSession * megolmOutSession; - MatrixClientGetMegolmOutSession(&client, + MatrixClientNewMegolmOutSession(&client, ROOM_ID, &megolmOutSession); printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key); diff --git a/src/matrix.c b/src/matrix.c index 40c2e5b..ef094b8 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -4,6 +4,11 @@ #include #include +#ifdef ESP_PLATFORM +#include +#endif + +#define STATIC #define LOGIN_REQUEST_SIZE 1024 #define LOGIN_RESPONSE_SIZE 1024 @@ -47,13 +52,24 @@ Randomize( uint8_t * random, int randomLen) { - static bool first = true; + #ifdef ESP_PLATFORM + + for (int i = 0; i < randomLen; i++) + { + random[i] = esp_random() % 256; + } + + #else + + STATIC bool first = true; if (first) { srand(time(0)); first = false; } for (int i = 0; i < randomLen; i++) { random[i] = rand() % 256; } + + #endif } bool @@ -130,7 +146,7 @@ JsonCanonicalize( int valLen; mjson_find(sIn, sInLen, jp, &valPtr, &valLen); - static char newEntry[JSON_MAX_ENTRY_SIZE]; + STATIC char newEntry[JSON_MAX_ENTRY_SIZE]; snprintf(newEntry, JSON_MAX_ENTRY_SIZE, "{%.*s:%.*s}", keys[i].len, keys[i].ptr, valLen, valPtr); char * buffer = strdup(sOut); @@ -151,7 +167,7 @@ bool JsonSign( const char * sIn, int sInLen, char * sOut, int sOutCap) { - static char signature[OLM_SIGNATURE_SIZE]; + STATIC char signature[OLM_SIGNATURE_SIZE]; size_t res = olm_account_sign(client->olmAccount.account, sIn, sInLen, @@ -159,10 +175,10 @@ bool JsonSign( int signatureLen = res; - static char thisSigningKey[SIGNING_KEY_SIZE]; + STATIC char thisSigningKey[SIGNING_KEY_SIZE]; MatrixOlmAccountGetSigningKey(&client->olmAccount, thisSigningKey, SIGNING_KEY_SIZE); - static char signatureJson[JSON_SIGNATURE_SIZE]; + STATIC char signatureJson[JSON_SIGNATURE_SIZE]; int signatureJsonLen = mjson_snprintf(signatureJson, JSON_SIGNATURE_SIZE, "{" @@ -194,7 +210,7 @@ MatrixOlmAccountInit( { account->account = olm_account(account->memory); - static uint8_t random[OLM_ACCOUNT_RANDOM_SIZE]; + STATIC uint8_t random[OLM_ACCOUNT_RANDOM_SIZE]; Randomize(random, OLM_ACCOUNT_RANDOM_SIZE); size_t res = olm_create_account( @@ -227,7 +243,7 @@ MatrixOlmAccountGetDeviceKey( MatrixOlmAccount * account, char * key, int keyCap) { - static char deviceKeysJson[OLM_IDENTITY_KEYS_JSON_SIZE]; + STATIC char deviceKeysJson[OLM_IDENTITY_KEYS_JSON_SIZE]; size_t res = olm_account_identity_keys(account->account, deviceKeysJson, OLM_IDENTITY_KEYS_JSON_SIZE); @@ -242,7 +258,7 @@ MatrixOlmAccountGetSigningKey( MatrixOlmAccount * account, char * key, int keyCap) { - static char deviceKeysJson[OLM_IDENTITY_KEYS_JSON_SIZE]; + STATIC char deviceKeysJson[OLM_IDENTITY_KEYS_JSON_SIZE]; size_t res = olm_account_identity_keys(account->account, deviceKeysJson, OLM_IDENTITY_KEYS_JSON_SIZE); @@ -268,7 +284,7 @@ MatrixOlmSessionFrom( olm_session(session->memory); char * encryptedCopy = strdup(encrypted); - + size_t res = olm_create_inbound_session_from(session->session, olmAccount, deviceKey, strlen(deviceKey), @@ -296,7 +312,7 @@ MatrixOlmSessionTo( session->session = olm_session(session->memory); - static uint8_t random[OLM_OUTBOUND_SESSION_RANDOM_SIZE]; + STATIC uint8_t random[OLM_OUTBOUND_SESSION_RANDOM_SIZE]; Randomize(random, OLM_OUTBOUND_SESSION_RANDOM_SIZE); size_t res = @@ -345,7 +361,7 @@ MatrixOlmSessionEncrypt( const char * plaintext, char * outBuffer, int outBufferCap) { - static uint8_t random[OLM_ENCRYPT_RANDOM_SIZE]; + STATIC uint8_t random[OLM_ENCRYPT_RANDOM_SIZE]; Randomize(random, OLM_ENCRYPT_RANDOM_SIZE); size_t res = olm_encrypt(session->session, @@ -363,7 +379,7 @@ MatrixOlmSessionDecrypt( char * encrypted, char * outBuffer, int outBufferCap) { - static uint8_t random[OLM_ENCRYPT_RANDOM_SIZE]; + STATIC uint8_t random[OLM_ENCRYPT_RANDOM_SIZE]; Randomize(random, OLM_ENCRYPT_RANDOM_SIZE); size_t res = @@ -423,7 +439,7 @@ MatrixMegolmInSessionDecrypt( (uint8_t *)outDecrypted, outDecryptedCap, &megolmInMessageIndex); - printf("message index: %d\n", megolmInMessageIndex); + printf("message index: %d\n", (int)megolmInMessageIndex); if (res == olm_error()) { printf("error decrypting megolm message: %s\n", olm_inbound_group_session_last_error(session->session)); @@ -443,7 +459,7 @@ MatrixMegolmOutSessionInit( { memset(session, 0, sizeof(MatrixMegolmOutSession)); - static uint8_t random[MEGOLM_INIT_RANDOM_SIZE]; + STATIC uint8_t random[MEGOLM_INIT_RANDOM_SIZE]; Randomize(random, MEGOLM_INIT_RANDOM_SIZE); strncpy(session->roomId, roomId, ROOM_ID_SIZE); @@ -550,13 +566,10 @@ MatrixMegolmOutSessionLoad( bool MatrixClientInit( - MatrixClient * client, - const char * server) + MatrixClient * client) { memset(client, 0, sizeof(MatrixClient)); - strcpy(client->server, server); - // init olm account MatrixOlmAccountInit(&client->olmAccount); @@ -580,7 +593,6 @@ MatrixClientSave( fwrite(thisDeviceKey, 1, DEVICE_KEY_SIZE, f); fwrite(thisSigningKey, 1, DEVICE_KEY_SIZE, f); fwrite(client->userId, 1, USER_ID_SIZE, f); - fwrite(client->server, 1, SERVER_SIZE, f); fwrite(client->accessToken, 1, ACCESS_TOKEN_SIZE, f); fwrite(client->deviceId, 1, DEVICE_ID_SIZE, f); fwrite(client->expireMs, 1, EXPIRE_MS_SIZE, f); @@ -613,7 +625,6 @@ MatrixClientLoad( fread(thisDeviceKey, 1, DEVICE_KEY_SIZE, f); fread(thisSigningKey, 1, DEVICE_KEY_SIZE, f); fread(client->userId, 1, USER_ID_SIZE, f); - fread(client->server, 1, SERVER_SIZE, f); fread(client->accessToken, 1, ACCESS_TOKEN_SIZE, f); fread(client->deviceId, 1, DEVICE_ID_SIZE, f); fread(client->expireMs, 1, EXPIRE_MS_SIZE, f); @@ -670,7 +681,7 @@ MatrixClientGenerateOnetimeKeys( MatrixClient * client, int numberOfKeys) { - static uint8_t random[OLM_ONETIME_KEYS_RANDOM_SIZE]; + STATIC uint8_t random[OLM_ONETIME_KEYS_RANDOM_SIZE]; Randomize(random, OLM_ONETIME_KEYS_RANDOM_SIZE); size_t res = @@ -685,12 +696,12 @@ bool MatrixClientUploadOnetimeKeys( MatrixClient * client) { - static char requestBuffer[KEYS_UPLOAD_REQUEST_SIZE]; + STATIC char requestBuffer[KEYS_UPLOAD_REQUEST_SIZE]; mjson_snprintf(requestBuffer, KEYS_UPLOAD_REQUEST_SIZE, "{"); - static char onetimeKeysBuffer[1024]; + STATIC char onetimeKeysBuffer[1024]; olm_account_one_time_keys(client->olmAccount.account, onetimeKeysBuffer, 1024); @@ -700,14 +711,14 @@ MatrixClientUploadOnetimeKeys( int koff, klen, voff, vlen, vtype, off = 0; while ((off = mjson_next(keys, keysLen, off, &koff, &klen, &voff, &vlen, &vtype)) != 0) { - static char keyJson[JSON_ONETIME_KEY_SIZE]; + STATIC char keyJson[JSON_ONETIME_KEY_SIZE]; int keyJsonLen = snprintf(keyJson, JSON_ONETIME_KEY_SIZE, "{\"key\":\"%.*s\"}", vlen-2, keys + voff+1); - static char keyJsonSigned[JSON_ONETIME_KEY_SIGNED_SIZE]; + STATIC char keyJsonSigned[JSON_ONETIME_KEY_SIGNED_SIZE]; JsonSign(client, keyJson, keyJsonLen, @@ -725,20 +736,20 @@ MatrixClientUploadOnetimeKeys( mjson_snprintf(requestBuffer+strlen(requestBuffer), KEYS_UPLOAD_REQUEST_SIZE-strlen(requestBuffer), "}"); - // static char onetimeKeysSignedBuffer[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; + // STATIC char onetimeKeysSignedBuffer[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; // JsonSign(client, // requestBuffer, strlen(requestBuffer), // onetimeKeysSignedBuffer, KEYS_UPLOAD_REQUEST_SIZE); - // static char finalEvent[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; + // STATIC char finalEvent[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; // snprintf(finalEvent, KEYS_UPLOAD_REQUEST_SIGNED_SIZE, // "{\"one_time_keys\":%s}", onetimeKeysSignedBuffer); - static char finalEvent[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; + STATIC char finalEvent[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; snprintf(finalEvent, KEYS_UPLOAD_REQUEST_SIGNED_SIZE, "{\"one_time_keys\":%s}", requestBuffer); - static char responseBuffer[KEYS_UPLOAD_RESPONSE_SIZE]; - MatrixHttpPost(client, + STATIC char responseBuffer[KEYS_UPLOAD_RESPONSE_SIZE]; + MatrixHttpPost(client->hc, KEYS_UPLOAD_URL, finalEvent, responseBuffer, KEYS_UPLOAD_RESPONSE_SIZE, @@ -757,7 +768,7 @@ MatrixClientUploadDeviceKey( char thisSigningKey[DEVICE_KEY_SIZE]; MatrixOlmAccountGetSigningKey(&client->olmAccount, thisSigningKey, DEVICE_KEY_SIZE); - static char deviceKeysBuffer[KEYS_UPLOAD_REQUEST_SIZE]; + STATIC char deviceKeysBuffer[KEYS_UPLOAD_REQUEST_SIZE]; int deviceKeysBufferLen = mjson_snprintf(deviceKeysBuffer, KEYS_UPLOAD_REQUEST_SIZE, @@ -775,17 +786,17 @@ MatrixClientUploadDeviceKey( client->deviceId, thisSigningKey, client->userId); - static char deviceKeysSignedBuffer[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; + STATIC char deviceKeysSignedBuffer[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; JsonSign(client, deviceKeysBuffer, deviceKeysBufferLen, deviceKeysSignedBuffer, KEYS_UPLOAD_REQUEST_SIZE); - static char finalEvent[KEYS_UPLOAD_REQUEST_SIGNED_SIZE]; - snprintf(finalEvent, KEYS_UPLOAD_REQUEST_SIGNED_SIZE, + STATIC char finalEvent[KEYS_UPLOAD_REQUEST_SIGNED_SIZE+30]; + snprintf(finalEvent, KEYS_UPLOAD_REQUEST_SIGNED_SIZE+30, "{\"device_keys\":%s}", deviceKeysSignedBuffer); - static char responseBuffer[KEYS_UPLOAD_RESPONSE_SIZE]; - MatrixHttpPost(client, + STATIC char responseBuffer[KEYS_UPLOAD_RESPONSE_SIZE]; + MatrixHttpPost(client->hc, KEYS_UPLOAD_URL, finalEvent, responseBuffer, KEYS_UPLOAD_RESPONSE_SIZE, @@ -802,7 +813,7 @@ MatrixClientClaimOnetimeKey( const char * deviceId, char * outOnetimeKey, int outOnetimeKeyCap) { - static char requestBuffer[KEYS_CLAIM_REQUEST_SIZE]; + STATIC char requestBuffer[KEYS_CLAIM_REQUEST_SIZE]; mjson_snprintf(requestBuffer, KEYS_CLAIM_REQUEST_SIZE, "{" "\"one_time_keys\":{" @@ -815,18 +826,18 @@ MatrixClientClaimOnetimeKey( userId, deviceId); - static char responseBuffer[KEYS_CLAIM_RESPONSE_SIZE]; - MatrixHttpPost(client, + STATIC char responseBuffer[KEYS_CLAIM_RESPONSE_SIZE]; + MatrixHttpPost(client->hc, KEYS_CLAIM_URL, requestBuffer, responseBuffer, KEYS_CLAIM_RESPONSE_SIZE, true); - char userIdEscaped[USER_ID_SIZE]; + STATIC char userIdEscaped[USER_ID_SIZE]; JsonEscape(userId, strlen(userId), userIdEscaped, USER_ID_SIZE); - static char query[JSON_QUERY_SIZE]; + STATIC char query[JSON_QUERY_SIZE]; snprintf(query, JSON_QUERY_SIZE, "$.one_time_keys.%s.%s", userIdEscaped, @@ -858,7 +869,7 @@ MatrixClientLoginPassword( const char * password, const char * displayName) { - static char requestBuffer[LOGIN_REQUEST_SIZE]; + STATIC char requestBuffer[LOGIN_REQUEST_SIZE]; mjson_snprintf(requestBuffer, LOGIN_REQUEST_SIZE, "{" @@ -874,9 +885,9 @@ MatrixClientLoginPassword( password, displayName); - static char responseBuffer[LOGIN_RESPONSE_SIZE]; + STATIC char responseBuffer[LOGIN_RESPONSE_SIZE]; bool result = - MatrixHttpPost(client, + MatrixHttpPost(client->hc, LOGIN_URL, requestBuffer, responseBuffer, LOGIN_RESPONSE_SIZE, @@ -899,6 +910,8 @@ MatrixClientLoginPassword( mjson_get_string(responseBuffer, responseLen, "$.refresh_token", client->refreshToken, REFRESH_TOKEN_SIZE); + + MatrixHttpSetAccessToken(client->hc, client->accessToken); return true; } @@ -911,13 +924,13 @@ MatrixClientSendEvent( const char * msgType, const char * msgBody) { - static char requestUrl[MAX_URL_LEN]; + STATIC char requestUrl[MAX_URL_LEN]; sprintf(requestUrl, ROOM_SEND_URL, roomId, msgType, (int)time(NULL)); - static char responseBuffer[ROOM_SEND_RESPONSE_SIZE]; + STATIC char responseBuffer[ROOM_SEND_RESPONSE_SIZE]; bool result = - MatrixHttpPut(client, + MatrixHttpPut(client->hc, requestUrl, msgBody, responseBuffer, ROOM_SEND_RESPONSE_SIZE, @@ -936,7 +949,7 @@ MatrixClientSendEventEncrypted( const char * msgBody) { // event json - static char requestBuffer[ROOM_SEND_REQUEST_SIZE]; + STATIC char requestBuffer[ROOM_SEND_REQUEST_SIZE]; sprintf(requestBuffer, "{" "\"type\":\"%s\"," @@ -953,7 +966,7 @@ MatrixClientSendEventEncrypted( MatrixClientNewMegolmOutSession(client, roomId, &outSession); // encrypt - static char encryptedBuffer[ENCRYPTED_REQUEST_SIZE]; + STATIC char encryptedBuffer[ENCRYPTED_REQUEST_SIZE/10]; MatrixMegolmOutSessionEncrypt(outSession, requestBuffer, encryptedBuffer, ENCRYPTED_REQUEST_SIZE); @@ -967,7 +980,7 @@ MatrixClientSendEventEncrypted( const char * sessionId = outSession->id; const char * deviceId = client->deviceId; - static char encryptedEventBuffer[ENCRYPTED_EVENT_SIZE]; + STATIC char encryptedEventBuffer[ENCRYPTED_EVENT_SIZE/10]; sprintf(encryptedEventBuffer, "{" "\"algorithm\":\"m.megolm.v1.aes-sha2\"," @@ -996,7 +1009,7 @@ MatrixClientSync( const char * nextBatch) { // filter={\"event_fields\":[\"to_device\"]} - static char url[MAX_URL_LEN]; + STATIC char url[MAX_URL_LEN]; snprintf(url, MAX_URL_LEN, "/_matrix/client/v3/sync?timeout=%d%s", SYNC_TIMEOUT, @@ -1019,7 +1032,7 @@ MatrixClientSync( url[index] = '\0'; return - MatrixHttpGet(client, + MatrixHttpGet(client->hc, url, outSyncBuffer, outSyncCap, true); @@ -1033,14 +1046,14 @@ MatrixClientGetRoomEvent( const char * eventId, char * outEvent, int outEventCap) { - static char url[MAX_URL_LEN]; + STATIC char url[MAX_URL_LEN]; snprintf(url, MAX_URL_LEN, "/_matrix/client/v3/rooms/%s/event/%s", roomId, eventId); return - MatrixHttpGet(client, + MatrixHttpGet(client->hc, url, outEvent, outEventCap, true); @@ -1054,7 +1067,7 @@ MatrixClientShareMegolmOutSession( MatrixMegolmOutSession * session) { // generate room key event - static char eventBuffer[KEY_SHARE_EVENT_LEN]; + STATIC char eventBuffer[KEY_SHARE_EVENT_LEN]; sprintf(eventBuffer, "{" "\"algorithm\":\"m.megolm.v1.aes-sha2\"," @@ -1210,7 +1223,7 @@ MatrixClientRequestMegolmInSession( // TODO: cancel requests MatrixClientSendDummy(client, userId, deviceId); - static char event[ROOMKEY_REQUEST_SIZE]; + STATIC char event[ROOMKEY_REQUEST_SIZE]; snprintf(event, ROOMKEY_REQUEST_SIZE, "{" "\"action\":\"request\"," @@ -1220,7 +1233,7 @@ MatrixClientRequestMegolmInSession( "\"sender_key\":\"%s\"," "\"session_id\":\"%s\"" "}," - "\"request_id\":\"%d\"," + "\"request_id\":\"%lld\"," "\"requesting_device_id\":\"%s\"" "}", roomId, @@ -1244,7 +1257,6 @@ MatrixClientGetOlmSessionIn( MatrixClient * client, const char * userId, const char * deviceId, - const char * encrypted, MatrixOlmSession ** outSession) { for (int i = 0; i < client->numOlmSessions; i++) @@ -1256,9 +1268,20 @@ MatrixClientGetOlmSessionIn( } } + return false; +} + +bool +MatrixClientNewOlmSessionIn( + MatrixClient * client, + const char * userId, + const char * deviceId, + const char * encrypted, + MatrixOlmSession ** outSession) +{ if (client->numOlmSessions < NUM_OLM_SESSIONS) { - static char deviceKey[DEVICE_KEY_SIZE]; + STATIC char deviceKey[DEVICE_KEY_SIZE]; MatrixClientRequestDeviceKey(client, deviceId, deviceKey, DEVICE_KEY_SIZE); @@ -1296,9 +1319,19 @@ MatrixClientGetOlmSessionOut( } } + return false; +} + +bool +MatrixClientNewOlmSessionOut( + MatrixClient * client, + const char * userId, + const char * deviceId, + MatrixOlmSession ** outSession) +{ if (client->numOlmSessions < NUM_OLM_SESSIONS) { - static char deviceKey[DEVICE_KEY_SIZE]; + STATIC char deviceKey[DEVICE_KEY_SIZE]; MatrixClientRequestDeviceKey(client, deviceId, deviceKey, DEVICE_KEY_SIZE); @@ -1335,11 +1368,11 @@ MatrixClientSendToDevice( const char * message, const char * msgType) { - static char requestUrl[MAX_URL_LEN]; + STATIC char requestUrl[MAX_URL_LEN]; sprintf(requestUrl, TODEVICE_URL, msgType, (int)time(NULL)); - static char eventBuffer[TODEVICE_EVENT_SIZE]; + STATIC char eventBuffer[TODEVICE_EVENT_SIZE]; snprintf(eventBuffer, TODEVICE_EVENT_SIZE, "{" "\"messages\":{" @@ -1352,9 +1385,9 @@ MatrixClientSendToDevice( deviceId, message); - static char responseBuffer[ROOM_SEND_RESPONSE_SIZE]; + STATIC char responseBuffer[ROOM_SEND_RESPONSE_SIZE]; bool result = - MatrixHttpPut(client, + MatrixHttpPut(client->hc, requestUrl, eventBuffer, responseBuffer, ROOM_SEND_RESPONSE_SIZE, @@ -1375,7 +1408,8 @@ MatrixClientSendToDeviceEncrypted( { // get olm session MatrixOlmSession * olmSession; - MatrixClientGetOlmSessionOut(client, userId, deviceId, &olmSession); + if (! MatrixClientGetOlmSessionOut(client, userId, deviceId, &olmSession)) + MatrixClientNewOlmSessionOut(client, userId, deviceId, &olmSession); // create event json char targetDeviceKey[DEVICE_KEY_SIZE]; @@ -1386,7 +1420,7 @@ MatrixClientSendToDeviceEncrypted( char thisSigningKey[DEVICE_KEY_SIZE]; MatrixOlmAccountGetSigningKey(&client->olmAccount, thisSigningKey, DEVICE_KEY_SIZE); - static char eventBuffer[TODEVICE_EVENT_SIZE]; + STATIC char eventBuffer[TODEVICE_EVENT_SIZE]; sprintf(eventBuffer, "{" "\"type\":\"%s\"," @@ -1408,7 +1442,7 @@ MatrixClientSendToDeviceEncrypted( thisSigningKey); // encrypt - static char encryptedBuffer[ENCRYPTED_REQUEST_SIZE]; + STATIC char encryptedBuffer[ENCRYPTED_REQUEST_SIZE]; MatrixOlmSessionEncrypt(olmSession, eventBuffer, encryptedBuffer, ENCRYPTED_REQUEST_SIZE); @@ -1417,7 +1451,7 @@ MatrixClientSendToDeviceEncrypted( MatrixOlmAccountGetDeviceKey(&client->olmAccount, thisDeviceKey, DEVICE_KEY_SIZE); - static char encryptedEventBuffer[ENCRYPTED_EVENT_SIZE]; + STATIC char encryptedEventBuffer[ENCRYPTED_EVENT_SIZE]; sprintf(encryptedEventBuffer, "{" "\"algorithm\":\"m.olm.v1.curve25519-aes-sha2\"," @@ -1535,16 +1569,21 @@ bool MatrixClientRequestDeviceKeys( MatrixClient * client) { - static char userIdEscaped[USER_ID_SIZE]; + if (client->numDevices >= NUM_DEVICES) { + printf("Maximum number of devices reached\n"); + return false; + } + + STATIC char userIdEscaped[USER_ID_SIZE]; JsonEscape(client->userId, strlen(client->userId), userIdEscaped, USER_ID_SIZE); - static char request[KEYS_QUERY_REQUEST_SIZE]; + STATIC char request[KEYS_QUERY_REQUEST_SIZE]; snprintf(request, KEYS_QUERY_REQUEST_SIZE, "{\"device_keys\":{\"%s\":[]}}", client->userId); - static char responseBuffer[KEYS_QUERY_RESPONSE_SIZE]; - bool requestResult = MatrixHttpPost(client, + STATIC char responseBuffer[KEYS_QUERY_RESPONSE_SIZE]; + bool requestResult = MatrixHttpPost(client->hc, KEYS_QUERY_URL, request, responseBuffer, KEYS_QUERY_RESPONSE_SIZE, @@ -1554,7 +1593,7 @@ MatrixClientRequestDeviceKeys( return false; // query for retrieving device keys for user id - static char query[JSON_QUERY_SIZE]; + STATIC char query[JSON_QUERY_SIZE]; snprintf(query, JSON_QUERY_SIZE, "$.device_keys.%s", userIdEscaped); @@ -1577,14 +1616,14 @@ MatrixClientRequestDeviceKeys( "%.*s", klen-2, key+1); // look for device key in value - static char deviceKeyQuery[JSON_QUERY_SIZE]; + STATIC char deviceKeyQuery[JSON_QUERY_SIZE]; snprintf(deviceKeyQuery, JSON_QUERY_SIZE, "$.keys.curve25519:%s", d.deviceId); mjson_get_string(val, vlen, deviceKeyQuery, d.deviceKey, DEVICE_KEY_SIZE); // look for signing key in value - static char signingKeyQuery[JSON_QUERY_SIZE]; + STATIC char signingKeyQuery[JSON_QUERY_SIZE]; snprintf(signingKeyQuery, JSON_QUERY_SIZE, "$.keys.ed25519:%s", d.deviceId); mjson_get_string(val, vlen, @@ -1617,12 +1656,12 @@ bool MatrixClientDeleteDevice( MatrixClient * client) { - static char deleteRequest[1024]; + STATIC char deleteRequest[1024]; snprintf(deleteRequest, 1024, "{\"devices\":[\"%s\"]}", client->deviceId); - static char deleteResponse[1024]; - bool res = MatrixHttpPost(client, "/_matrix/client/v3/delete_devices", + STATIC char deleteResponse[1024]; + bool res = MatrixHttpPost(client->hc, "/_matrix/client/v3/delete_devices", deleteRequest, deleteResponse, 1024, true); return res; } \ No newline at end of file diff --git a/src/matrix.h b/src/matrix.h index 4037f09..d31a7f6 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -49,7 +49,54 @@ #define NUM_MEGOLM_SESSIONS 10 #define NUM_OLM_SESSIONS 10 -#define NUM_DEVICES 100 +#define NUM_DEVICES 10 + +// HTTP + +typedef struct MatrixHttpConnection MatrixHttpConnection; + +bool +MatrixHttpInit( + MatrixHttpConnection ** hc, + const char * host); + +// bool +// MatrixHttpConnect( +// MatrixHttpConnection * hc); + +bool +MatrixHttpDeinit( + MatrixHttpConnection ** hc); + +bool +MatrixHttpSetAccessToken( + MatrixHttpConnection * hc, + const char * accessToken); + +bool +MatrixHttpGet( + MatrixHttpConnection * hc, + const char * url, + char * outResponseBuffer, int outResponseCap, + bool authenticated); + +bool +MatrixHttpPost( + MatrixHttpConnection * hc, + const char * url, + const char * requestBuffer, + char * outResponseBuffer, int outResponseCap, + bool authenticated); + +bool +MatrixHttpPut( + MatrixHttpConnection * hc, + const char * url, + const char * requestBuffer, + char * outResponseBuffer, int outResponseCap, + bool authenticated); + + // Matrix Device @@ -212,19 +259,17 @@ typedef struct MatrixClient { // char signingKey[DEVICE_KEY_SIZE]; char userId[USER_ID_SIZE]; - char server[SERVER_SIZE]; char accessToken[ACCESS_TOKEN_SIZE]; char deviceId[DEVICE_ID_SIZE]; char expireMs[EXPIRE_MS_SIZE]; char refreshToken[REFRESH_TOKEN_SIZE]; - void * httpUserData; + MatrixHttpConnection * hc; } MatrixClient; bool MatrixClientInit( - MatrixClient * client, - const char * server); + MatrixClient * client); bool MatrixClientSave( @@ -357,6 +402,13 @@ MatrixClientRequestMegolmInSession( bool MatrixClientGetOlmSessionIn( + MatrixClient * client, + const char * userId, + const char * deviceId, + MatrixOlmSession ** outSession); + +bool +MatrixClientNewOlmSessionIn( MatrixClient * client, const char * userId, const char * deviceId, @@ -369,6 +421,13 @@ MatrixClientGetOlmSessionOut( const char * userId, const char * deviceId, MatrixOlmSession ** outSession); + +bool +MatrixClientNewOlmSessionOut( + MatrixClient * client, + const char * userId, + const char * deviceId, + MatrixOlmSession ** outSession); bool MatrixClientSendToDevice( @@ -413,43 +472,6 @@ MatrixClientDeleteDevice( MatrixClient * client); - - -bool -MatrixHttpInit( - MatrixClient * client); - -bool -MatrixHttpConnect( - MatrixClient * client); - -bool -MatrixHttpDeinit( - MatrixClient * client); - -bool -MatrixHttpGet( - MatrixClient * client, - const char * url, - char * outResponseBuffer, int outResponseCap, - bool authenticated); - -bool -MatrixHttpPost( - MatrixClient * client, - const char * url, - const char * requestBuffer, - char * outResponseBuffer, int outResponseCap, - bool authenticated); - -bool -MatrixHttpPut( - MatrixClient * client, - const char * url, - const char * requestBuffer, - char * outResponseBuffer, int outResponseCap, - bool authenticated); - // util void -- 2.50.1