abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorPatrick2023-05-15 18:47:59 +0200
committerPatrick2023-05-15 18:47:59 +0200
commitd43e8671acc5709c192e159e0d91626f0677cdf1 (patch)
tree85d2c65ddb3c36bea1e9ea814cf9434e52fcae97
downloadmatrix_esp_thesis-d43e8671acc5709c192e159e0d91626f0677cdf1.tar.gz
matrix_esp_thesis-d43e8671acc5709c192e159e0d91626f0677cdf1.zip
Initial commit. Rudimentary readme, mockup examples without actual implementation, Makefile, Olm submodule
-rw-r--r--.gitmodules3
-rw-r--r--Makefile14
-rw-r--r--Readme.md1
-rw-r--r--examples/Login.c27
-rw-r--r--examples/Send.c25
-rw-r--r--examples/SendEncrypted.c32
-rw-r--r--examples/Sync.c31
m---------ext/olm0
-rw-r--r--out/examples/keepme0
-rw-r--r--src/matrix.c38
-rw-r--r--src/matrix.h50
11 files changed, 221 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..3d6f22a
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "ext/olm"]
+ path = ext/olm
+ url = https://gitlab.matrix.org/matrix-org/olm/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d19abaa
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+CC=gcc
+
+C_OPTS=-Wall -Wextra -pedantic
+C_OPTS+=-I src/
+C_OPTS+=-I ext/olm/include/
+C_OPTS+=src/matrix.c
+
+out/examples/%: examples/%.c
+ $(CC) -o out/examples/$* examples/$*.c $(C_OPTS)
+
+
+.PHONY: examples
+
+examples: out/examples/Login out/examples/Send out/examples/SendEncrypted out/examples/Sync \ No newline at end of file
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..606f53d
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1 @@
+# Matrix Client Library in C
diff --git a/examples/Login.c b/examples/Login.c
new file mode 100644
index 0000000..5f07e87
--- /dev/null
+++ b/examples/Login.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <matrix.h>
+
+#define SERVER FixedBuf("matrix.org")
+#define USERNAME FixedBuf("@pscho:matrix.org")
+#define PASSWORD FixedBuf("abcde")
+
+
+int
+main(
+ int argc,
+ char **argv)
+{
+ MatrixClient client;
+ MatrixClientInit(&client, SERVER);
+
+ MatrixClientLoginPassword(&client,
+ USERNAME,
+ PASSWORD);
+
+ static char accessTokenCharBuffer[ACCESS_TOKEN_LEN];
+ FixedBuffer accessTokenBuffer = { accessTokenCharBuffer, ACCESS_TOKEN_LEN, 0 };
+ MatrixClientGetAccessToken(&client, &accessTokenBuffer);
+ printf("Access Token: %.*s\n", accessTokenBuffer.len, (char *)accessTokenBuffer.ptr);
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/Send.c b/examples/Send.c
new file mode 100644
index 0000000..95167cc
--- /dev/null
+++ b/examples/Send.c
@@ -0,0 +1,25 @@
+#include <matrix.h>
+
+#define SERVER FixedBuf("matrix.org")
+#define ACCESS_TOKEN FixedBuf("abc")
+#define ROOM_ID FixedBuf("!jhpZBTbckszblMYjMK:matrix.org")
+
+int
+main(
+ int argc,
+ char **argv)
+{
+ MatrixClient client;
+ MatrixClientCreate(&client,
+ SERVER);
+
+ MatrixClientSetAccessToken(&client,
+ ACCESS_TOKEN);
+
+ MatrixClientSendEvent(&client,
+ ROOM_ID,
+ FixedBuf("m.room.message"),
+ FixedBuf("{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"));
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c
new file mode 100644
index 0000000..2d3bd74
--- /dev/null
+++ b/examples/SendEncrypted.c
@@ -0,0 +1,32 @@
+#include <matrix.h>
+
+#define SERVER FixedBuf("matrix.org")
+#define ACCESS_TOKEN FixedBuf("abc")
+#define ROOM_ID FixedBuf("!jhpZBTbckszblMYjMK:matrix.org")
+
+int
+main(
+ int argc,
+ char **argv)
+{
+ MatrixClient client;
+ MatrixClientCreate(&client,
+ SERVER);
+
+ MatrixClientSetAccessToken(&client,
+ ACCESS_TOKEN);
+
+ MatrixMegolmSession megolm;
+ MatrixMegolmSessionInit(&megolm);
+
+ MatrixRoomShareMegolmSession(&client,
+ ROOM_ID,
+ megolm);
+
+ MatrixClientSendGroupEncrypted(&client,
+ ROOM_ID,
+ FixedBuf("m.room.message"),
+ FixedBuf("{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"));
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/Sync.c b/examples/Sync.c
new file mode 100644
index 0000000..5043884
--- /dev/null
+++ b/examples/Sync.c
@@ -0,0 +1,31 @@
+#include <matrix.h>
+
+#define SERVER "matrix.org"
+#define ACCESS_TOKEN "abc"
+#define ROOM_ID "!jhpZBTbckszblMYjMK:matrix.org"
+
+int
+main(
+ int argc,
+ char **argv)
+{
+ MatrixClient client;
+ MatrixClientCreate(&client,
+ SERVER);
+
+ 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");
+
+ return 0;
+} \ No newline at end of file
diff --git a/ext/olm b/ext/olm
new file mode 160000
+Subproject 66294cf7f66ae380683dbb7f43a16a8922249fc
diff --git a/out/examples/keepme b/out/examples/keepme
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/out/examples/keepme
diff --git a/src/matrix.c b/src/matrix.c
new file mode 100644
index 0000000..bc0f1ca
--- /dev/null
+++ b/src/matrix.c
@@ -0,0 +1,38 @@
+#include "matrix.h"
+
+FixedBuffer
+FixedBuf(const char * str)
+{
+ int len = strlen(str);
+ FixedBuffer result;
+ result.ptr = (char *)str;
+ result.size = len;
+ result.len = len;
+ return result;
+}
+
+
+bool
+MatrixClientInit(
+ MatrixClient * client,
+ FixedBuffer server
+) {
+
+}
+
+bool
+MatrixClientLoginPassword(
+ MatrixClient * client,
+ FixedBuffer username,
+ FixedBuffer password
+) {
+
+}
+
+bool
+MatrixClientGetAccessToken(
+ MatrixClient * client,
+ FixedBuffer * outBuffer
+) {
+
+}
diff --git a/src/matrix.h b/src/matrix.h
new file mode 100644
index 0000000..d61c59b
--- /dev/null
+++ b/src/matrix.h
@@ -0,0 +1,50 @@
+#ifndef MATRIX__H
+#define MATRIX__H
+
+#include <stdbool.h>
+#include <string.h>
+
+#include <olm/olm.h>
+
+
+
+
+
+typedef struct FixedBuffer {
+ void * ptr;
+ int size;
+ int len;
+} FixedBuffer;
+
+FixedBuffer
+FixedBuf(const char * str);
+
+
+
+#define ACCESS_TOKEN_LEN 20 // TODO: fix
+
+typedef struct MatrixClient {
+ OlmAccount * olmAcc;
+ char accessToken[ACCESS_TOKEN_LEN];
+} MatrixClient;
+
+bool
+MatrixClientInit(
+ MatrixClient * client,
+ FixedBuffer server
+);
+
+bool
+MatrixClientLoginPassword(
+ MatrixClient * client,
+ FixedBuffer username,
+ FixedBuffer password
+);
+
+bool
+MatrixClientGetAccessToken(
+ MatrixClient * client,
+ FixedBuffer * outBuffer
+);
+
+#endif