abouttreesummaryrefslogcommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick2023-07-21 23:04:48 +0200
committerPatrick2023-07-21 23:04:48 +0200
commitc7aba5979c820958aa08947903afb47ace496a16 (patch)
tree42dbeb78e724c62199e127ddf1712e662ab14419 /src
parent07e667e29883740aa0b82199cf0518a2e2684e26 (diff)
downloadmatrix_esp_thesis-c7aba5979c820958aa08947903afb47ace496a16.tar.gz
matrix_esp_thesis-c7aba5979c820958aa08947903afb47ace496a16.zip
share, save, load, init, print megolm out sessions
Diffstat (limited to 'src')
-rw-r--r--src/matrix.c23
-rw-r--r--src/matrix.h8
2 files changed, 26 insertions, 5 deletions
diff --git a/src/matrix.c b/src/matrix.c
index fa7303f..de936de 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -192,7 +192,7 @@ MatrixMegolmOutSessionInit(
static uint8_t random[MEGOLM_INIT_RANDOM_SIZE];
Randomize(random, MEGOLM_INIT_RANDOM_SIZE);
- session->roomId = roomId;
+ strncpy(session->roomId, roomId, ROOM_ID_SIZE);
session->session =
olm_outbound_group_session(session->memory);
@@ -268,6 +268,8 @@ MatrixMegolmOutSessionLoad(
size_t roomIdLen;
fread(&roomIdLen, sizeof(size_t), 1, f);
fread(session->roomId, 1, roomIdLen, f);
+ for (int i = roomIdLen; i < ROOM_ID_SIZE; i++)
+ session->roomId[i] = '\0';
size_t pickleBufferLen;
fread(&pickleBufferLen, sizeof(size_t), 1, f);
@@ -282,6 +284,9 @@ MatrixMegolmOutSessionLoad(
free(pickleBuffer);
+ olm_outbound_group_session_id(session->session, (uint8_t *)session->id, MEGOLM_SESSION_ID_SIZE);
+ olm_outbound_group_session_key(session->session, (uint8_t *)session->key, MEGOLM_SESSION_KEY_SIZE);
+
fclose(f);
return true;
@@ -816,19 +821,29 @@ MatrixClientGetMegolmOutSession(
}
}
+ if (MatrixClientInitMegolmOutSession(client, roomId)) {
+ *outSession = &client->megolmOutSessions[client->numMegolmOutSessions-1];
+ return true;
+ }
+
+ return false;
+}
+
+bool
+MatrixClientInitMegolmOutSession(
+ MatrixClient * client,
+ const char * roomId)
+{
if (client->numMegolmOutSessions < NUM_MEGOLM_SESSIONS)
{
MatrixMegolmOutSessionInit(
&client->megolmOutSessions[client->numMegolmOutSessions],
roomId);
-
- *outSession = &client->megolmOutSessions[client->numMegolmOutSessions];
client->numMegolmOutSessions++;
return true;
}
-
return false;
}
diff --git a/src/matrix.h b/src/matrix.h
index 073f610..3614b6a 100644
--- a/src/matrix.h
+++ b/src/matrix.h
@@ -11,6 +11,7 @@
#define USER_ID_SIZE 64
+#define ROOM_ID_SIZE 128
#define SERVER_SIZE 20
#define ACCESS_TOKEN_SIZE 40
#define DEVICE_ID_SIZE 20
@@ -102,7 +103,7 @@ typedef struct MatrixMegolmInSession {
} MatrixMegolmInSession;
typedef struct MatrixMegolmOutSession {
- const char * roomId;
+ char roomId[ROOM_ID_SIZE];
OlmOutboundGroupSession * session;
char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];
@@ -265,6 +266,11 @@ MatrixClientSetMegolmOutSession(
MatrixMegolmOutSession session);
bool
+MatrixClientInitMegolmOutSession(
+ MatrixClient * client,
+ const char * roomId);
+
+bool
MatrixClientGetOlmSession(
MatrixClient * client,
const char * userId,