abouttreesummaryrefslogcommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPatrick2023-06-19 21:21:16 +0200
committerPatrick2023-06-19 21:21:16 +0200
commitad9d01050b7b6d592a83ce14eeef7068bd981028 (patch)
treef6263c85f4c9905bccb1887e50d2777c61b24405 /examples
parentd382d193cb2d550cc769afa76e55823865a39023 (diff)
downloadmatrix_esp_thesis-ad9d01050b7b6d592a83ce14eeef7068bd981028.tar.gz
matrix_esp_thesis-ad9d01050b7b6d592a83ce14eeef7068bd981028.zip
olm session management
Diffstat (limited to 'examples')
-rw-r--r--examples/Decrypt.c45
-rw-r--r--examples/Login.c10
-rw-r--r--examples/Send.c2
-rw-r--r--examples/SendEncrypted.c40
-rw-r--r--examples/Sync.c31
5 files changed, 87 insertions, 41 deletions
diff --git a/examples/Decrypt.c b/examples/Decrypt.c
new file mode 100644
index 0000000..b496780
--- /dev/null
+++ b/examples/Decrypt.c
@@ -0,0 +1,45 @@
+#include <matrix.h>
+#include <stdio.h>
+
+#define SERVER "https://matrix.org"
+#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO"
+#define DEVICE_ID "MAZNCCZLBR"
+#define ROOM_ID "!koVStwyiiKcBVbXZYz:matrix.org"
+#define EVENT_ID ""
+
+int
+main(void)
+{
+ MatrixClient client;
+ MatrixClientInit(&client,
+ SERVER);
+
+ MatrixHttpInit(&client);
+
+ MatrixClientSetAccessToken(&client,
+ ACCESS_TOKEN);
+
+ static char eventBuffer[1024];
+ MatrixClientGetRoomEvent(&client,
+ ROOM_ID,
+ EVENT_ID,
+ eventBuffer, 1024);
+
+ MatrixMegolmInSession megolmSession;
+
+ MatrixClientRequestMegolmSession(&client,
+ ROOM_ID,
+ EVENT_ID,
+ &megolmSession);
+
+ static char decryptedBuffer[1024];
+ MatrixMegolmSessionDecrypt(&megolmSession,
+ eventBuffer,
+ decryptedBuffer, 1024);
+
+ printf("%s\n", decryptedBuffer);
+
+ MatrixHttpDeinit(&client);
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/Login.c b/examples/Login.c
index 45204fc..1ffbbc0 100644
--- a/examples/Login.c
+++ b/examples/Login.c
@@ -8,7 +8,7 @@
int
-main()
+main(void)
{
MatrixClient client;
MatrixClientInit(&client,
@@ -21,10 +21,10 @@ main()
PASSWORD,
DISPLAYNAME);
- printf("Access Token: %s\n", client.accessTokenBuffer);
- printf("Device ID: %s\n", client.deviceIdBuffer);
- printf("Expires in (ms): %s\n", client.expireMsBuffer);
- printf("Refresh Token: %s\n", client.refreshTokenBuffer);
+ printf("Access Token: %s\n", client.accessToken);
+ printf("Device ID: %s\n", client.deviceId);
+ printf("Expires in (ms): %s\n", client.expireMs);
+ printf("Refresh Token: %s\n", client.refreshToken);
MatrixHttpDeinit(&client);
diff --git a/examples/Send.c b/examples/Send.c
index e595ba7..cddb966 100644
--- a/examples/Send.c
+++ b/examples/Send.c
@@ -6,7 +6,7 @@
#define ROOM_ID "!koVStwyiiKcBVbXZYz:matrix.org"
int
-main()
+main(void)
{
MatrixClient client;
MatrixClientInit(&client,
diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c
index 2d3bd74..db2f83c 100644
--- a/examples/SendEncrypted.c
+++ b/examples/SendEncrypted.c
@@ -1,32 +1,36 @@
#include <matrix.h>
+#include <stdio.h>
-#define SERVER FixedBuf("matrix.org")
-#define ACCESS_TOKEN FixedBuf("abc")
-#define ROOM_ID FixedBuf("!jhpZBTbckszblMYjMK:matrix.org")
+#define SERVER "https://matrix.org"
+#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO"
+#define DEVICE_ID "MAZNCCZLBR"
+#define ROOM_ID "!koVStwyiiKcBVbXZYz:matrix.org"
int
-main(
- int argc,
- char **argv)
+main(void)
{
MatrixClient client;
- MatrixClientCreate(&client,
+ MatrixClientInit(&client,
SERVER);
+
+ MatrixHttpInit(&client);
MatrixClientSetAccessToken(&client,
ACCESS_TOKEN);
- MatrixMegolmSession megolm;
- MatrixMegolmSessionInit(&megolm);
-
- MatrixRoomShareMegolmSession(&client,
- ROOM_ID,
- megolm);
-
- MatrixClientSendGroupEncrypted(&client,
+ // MatrixMegolmOutSession megolmOutSession;
+ // MatrixMegolmOutSessionInit(&megolmOutSession);
+
+ // MatrixClientSetMegolmOutSession(&client,
+ // ROOM_ID,
+ // megolmOutSession);
+
+ MatrixClientSendEventEncrypted(&client,
ROOM_ID,
- FixedBuf("m.room.message"),
- FixedBuf("{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"));
+ "m.room.message",
+ "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");
+
+ MatrixHttpDeinit(&client);
return 0;
-} \ No newline at end of file
+}
diff --git a/examples/Sync.c b/examples/Sync.c
index 5043884..a49cf65 100644
--- a/examples/Sync.c
+++ b/examples/Sync.c
@@ -1,31 +1,28 @@
#include <matrix.h>
+#include <stdio.h>
-#define SERVER "matrix.org"
-#define ACCESS_TOKEN "abc"
-#define ROOM_ID "!jhpZBTbckszblMYjMK:matrix.org"
+#define SERVER "https://matrix.org"
+#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO"
+#define DEVICE_ID "MAZNCCZLBR"
int
-main(
- int argc,
- char **argv)
+main(void)
{
MatrixClient client;
- MatrixClientCreate(&client,
+ MatrixClientInit(&client,
SERVER);
+
+ MatrixHttpInit(&client);
MatrixClientSetAccessToken(&client,
ACCESS_TOKEN);
- static char syncCharBuffer[1024];
- FixedBuffer syncBuffer = { syncCharBuffer, 1024, 0 };
- int syncN = 1;
-
- while (syncN > 0)
- {
- MatrixClientSyncN(&client, &syncBuffer, &syncN);
- printf("%.*s", syncBuffer.len, (char *)syncBuffer.ptr);
- }
- printf("\n");
+ static char syncBuffer[20000];
+ MatrixClientSync(&client,
+ syncBuffer, 20000);
+ printf("%s", syncBuffer);
+
+ MatrixHttpDeinit(&client);
return 0;
} \ No newline at end of file