]> gitweb.ps.run Git - matrix_esp_thesis/commitdiff
Initial commit. Rudimentary readme, mockup examples without actual implementation...
authorPatrick <patrick.schoenberger@posteo.de>
Mon, 15 May 2023 16:47:59 +0000 (18:47 +0200)
committerPatrick <patrick.schoenberger@posteo.de>
Mon, 15 May 2023 16:47:59 +0000 (18:47 +0200)
.gitmodules [new file with mode: 0644]
Makefile [new file with mode: 0644]
Readme.md [new file with mode: 0644]
examples/Login.c [new file with mode: 0644]
examples/Send.c [new file with mode: 0644]
examples/SendEncrypted.c [new file with mode: 0644]
examples/Sync.c [new file with mode: 0644]
ext/olm [new submodule]
out/examples/keepme [new file with mode: 0644]
src/matrix.c [new file with mode: 0644]
src/matrix.h [new file with mode: 0644]

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..3d6f22a
--- /dev/null
@@ -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 (file)
index 0000000..d19abaa
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+CC=gcc\r
+\r
+C_OPTS=-Wall -Wextra -pedantic\r
+C_OPTS+=-I src/\r
+C_OPTS+=-I ext/olm/include/\r
+C_OPTS+=src/matrix.c\r
+\r
+out/examples/%: examples/%.c\r
+       $(CC) -o out/examples/$* examples/$*.c $(C_OPTS)\r
+\r
+\r
+.PHONY: examples\r
+\r
+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 (file)
index 0000000..606f53d
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1 @@
+# Matrix Client Library in C\r
diff --git a/examples/Login.c b/examples/Login.c
new file mode 100644 (file)
index 0000000..5f07e87
--- /dev/null
@@ -0,0 +1,27 @@
+#include <stdio.h>\r
+#include <matrix.h>\r
+\r
+#define SERVER FixedBuf("matrix.org")\r
+#define USERNAME FixedBuf("@pscho:matrix.org")\r
+#define PASSWORD FixedBuf("abcde")\r
+\r
+\r
+int\r
+main(\r
+    int argc,\r
+    char **argv)\r
+{\r
+    MatrixClient client;\r
+    MatrixClientInit(&client, SERVER);\r
+\r
+    MatrixClientLoginPassword(&client,\r
+        USERNAME,\r
+        PASSWORD);\r
+\r
+    static char accessTokenCharBuffer[ACCESS_TOKEN_LEN];\r
+    FixedBuffer accessTokenBuffer = { accessTokenCharBuffer, ACCESS_TOKEN_LEN, 0 };\r
+    MatrixClientGetAccessToken(&client, &accessTokenBuffer);\r
+    printf("Access Token: %.*s\n", accessTokenBuffer.len, (char *)accessTokenBuffer.ptr);\r
+\r
+    return 0;\r
+}
\ No newline at end of file
diff --git a/examples/Send.c b/examples/Send.c
new file mode 100644 (file)
index 0000000..95167cc
--- /dev/null
@@ -0,0 +1,25 @@
+#include <matrix.h>\r
+\r
+#define SERVER FixedBuf("matrix.org")\r
+#define ACCESS_TOKEN FixedBuf("abc")\r
+#define ROOM_ID FixedBuf("!jhpZBTbckszblMYjMK:matrix.org")\r
+\r
+int\r
+main(\r
+    int argc,\r
+    char **argv)\r
+{\r
+    MatrixClient client;\r
+    MatrixClientCreate(&client,\r
+        SERVER);\r
+\r
+    MatrixClientSetAccessToken(&client,\r
+        ACCESS_TOKEN);\r
+\r
+    MatrixClientSendEvent(&client,\r
+        ROOM_ID,\r
+        FixedBuf("m.room.message"),\r
+        FixedBuf("{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"));\r
+\r
+    return 0;\r
+}
\ No newline at end of file
diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c
new file mode 100644 (file)
index 0000000..2d3bd74
--- /dev/null
@@ -0,0 +1,32 @@
+#include <matrix.h>\r
+\r
+#define SERVER FixedBuf("matrix.org")\r
+#define ACCESS_TOKEN FixedBuf("abc")\r
+#define ROOM_ID FixedBuf("!jhpZBTbckszblMYjMK:matrix.org")\r
+\r
+int\r
+main(\r
+    int argc,\r
+    char **argv)\r
+{\r
+    MatrixClient client;\r
+    MatrixClientCreate(&client,\r
+        SERVER);\r
+\r
+    MatrixClientSetAccessToken(&client,\r
+        ACCESS_TOKEN);\r
+\r
+    MatrixMegolmSession megolm;\r
+    MatrixMegolmSessionInit(&megolm);\r
+        \r
+    MatrixRoomShareMegolmSession(&client,\r
+        ROOM_ID,\r
+        megolm);\r
+    \r
+    MatrixClientSendGroupEncrypted(&client,\r
+        ROOM_ID,\r
+        FixedBuf("m.room.message"),\r
+        FixedBuf("{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"));\r
+\r
+    return 0;\r
+}
\ No newline at end of file
diff --git a/examples/Sync.c b/examples/Sync.c
new file mode 100644 (file)
index 0000000..5043884
--- /dev/null
@@ -0,0 +1,31 @@
+#include <matrix.h>\r
+\r
+#define SERVER "matrix.org"\r
+#define ACCESS_TOKEN "abc"\r
+#define ROOM_ID "!jhpZBTbckszblMYjMK:matrix.org"\r
+\r
+int\r
+main(\r
+    int argc,\r
+    char **argv)\r
+{\r
+    MatrixClient client;\r
+    MatrixClientCreate(&client,\r
+        SERVER);\r
+\r
+    MatrixClientSetAccessToken(&client,\r
+        ACCESS_TOKEN);\r
+\r
+    static char syncCharBuffer[1024];\r
+    FixedBuffer syncBuffer = { syncCharBuffer, 1024, 0 };\r
+    int syncN = 1;\r
+\r
+    while (syncN > 0)\r
+    {\r
+        MatrixClientSyncN(&client, &syncBuffer, &syncN);\r
+        printf("%.*s", syncBuffer.len, (char *)syncBuffer.ptr);\r
+    }\r
+    printf("\n");\r
+\r
+    return 0;\r
+}
\ No newline at end of file
diff --git a/ext/olm b/ext/olm
new file mode 160000 (submodule)
index 0000000..66294cf
--- /dev/null
+++ b/ext/olm
@@ -0,0 +1 @@
+Subproject commit 66294cf7f66ae380683dbb7f43a16a8922249fc8
diff --git a/out/examples/keepme b/out/examples/keepme
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/matrix.c b/src/matrix.c
new file mode 100644 (file)
index 0000000..bc0f1ca
--- /dev/null
@@ -0,0 +1,38 @@
+#include "matrix.h"\r
+\r
+FixedBuffer\r
+FixedBuf(const char * str)\r
+{\r
+    int len = strlen(str);\r
+    FixedBuffer result;\r
+    result.ptr = (char *)str;\r
+    result.size = len;\r
+    result.len = len;\r
+    return result;\r
+}\r
+\r
+\r
+bool\r
+MatrixClientInit(\r
+    MatrixClient * client,\r
+    FixedBuffer server\r
+) {\r
+\r
+}\r
+\r
+bool\r
+MatrixClientLoginPassword(\r
+    MatrixClient * client,\r
+    FixedBuffer username,\r
+    FixedBuffer password\r
+) {\r
+\r
+}\r
+\r
+bool\r
+MatrixClientGetAccessToken(\r
+    MatrixClient * client,\r
+    FixedBuffer * outBuffer\r
+) {\r
+\r
+}\r
diff --git a/src/matrix.h b/src/matrix.h
new file mode 100644 (file)
index 0000000..d61c59b
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef MATRIX__H\r
+#define MATRIX__H\r
+\r
+#include <stdbool.h>\r
+#include <string.h>\r
+\r
+#include <olm/olm.h>\r
+\r
+\r
+\r
+\r
+\r
+typedef struct FixedBuffer {\r
+    void * ptr;\r
+    int size;\r
+    int len;\r
+} FixedBuffer;\r
+\r
+FixedBuffer\r
+FixedBuf(const char * str);\r
+\r
+\r
+\r
+#define ACCESS_TOKEN_LEN 20 // TODO: fix\r
+\r
+typedef struct MatrixClient {\r
+    OlmAccount * olmAcc;\r
+    char accessToken[ACCESS_TOKEN_LEN];\r
+} MatrixClient;\r
+\r
+bool\r
+MatrixClientInit(\r
+    MatrixClient * client,\r
+    FixedBuffer server\r
+);\r
+\r
+bool\r
+MatrixClientLoginPassword(\r
+    MatrixClient * client,\r
+    FixedBuffer username,\r
+    FixedBuffer password\r
+);\r
+\r
+bool\r
+MatrixClientGetAccessToken(\r
+    MatrixClient * client,\r
+    FixedBuffer * outBuffer\r
+);\r
+\r
+#endif\r