abouttreesummaryrefslogcommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Login.c27
-rw-r--r--examples/Send.c25
-rw-r--r--examples/SendEncrypted.c32
-rw-r--r--examples/Sync.c31
4 files changed, 115 insertions, 0 deletions
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