diff options
| author | Patrick | 2023-07-14 13:46:27 +0200 |
|---|---|---|
| committer | Patrick | 2023-07-14 13:46:27 +0200 |
| commit | 4c72c6901e007414aebb4cb6534c1a49d63558b0 (patch) | |
| tree | c0530fbda67888a8857e5a08222ee6d19c41f260 /examples | |
| parent | 10325eaf40c80eb91f1c1eceea880c3abd54efd7 (diff) | |
| download | matrix_esp_thesis-4c72c6901e007414aebb4cb6534c1a49d63558b0.tar.gz matrix_esp_thesis-4c72c6901e007414aebb4cb6534c1a49d63558b0.zip | |
esp32 build, cli
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/Cli.c | 153 | ||||
| -rw-r--r-- | examples/Keys.rdbg | bin | 0 -> 1157 bytes | |||
| -rw-r--r-- | examples/ReplyRoomkey.c | 40 | ||||
| -rw-r--r-- | examples/SendEncrypted.rdbg | bin | 0 -> 709 bytes |
4 files changed, 193 insertions, 0 deletions
diff --git a/examples/Cli.c b/examples/Cli.c new file mode 100644 index 0000000..af1d6b1 --- /dev/null +++ b/examples/Cli.c @@ -0,0 +1,153 @@ +#include <stdio.h>
+#include <stdarg.h>
+
+#include <mjson.h>
+#include <matrix.h>
+
+#define SERVER "https://matrix.org"
+#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO"
+#define DEVICE_ID "MAZNCCZLBR"
+#define USER_ID "@pscho:matrix.org"
+#define ROOM_ID "!XKFUjAsGrSSrpDFIxB:matrix.org"
+
+#define BUFFER_SIZE 1024
+#define NUMBER_ARGS 10
+
+void
+GetCommand(
+ char * cmd,
+ int * nargs,
+ char ** args
+) {
+ int index = 0;
+ int c;
+
+ *nargs = 0;
+
+ printf("> ");
+ while ((c = getchar()), c != ' ' && c != '\n')
+ cmd[index++] = c;
+ cmd[index] = '\0';
+
+ if (c == '\n')
+ return;
+
+ *nargs = 1;
+ index = 0;
+ char * arg = args[0];
+ while ((c = getchar()), c != '\n') {
+ if (c == ' ') {
+ arg[index] = '\0';
+ arg = args[(*nargs)++];
+ index = 0;
+ continue;
+ }
+ arg[index++] = c;
+ }
+ arg[index] = '\0';
+}
+
+bool
+CheckCommand(
+ const char * cmd,
+ const char * str
+) {
+ if (strlen(cmd) != strlen(str))
+ return false;
+
+ for (size_t i = 0; i < strlen(cmd); i++) {
+ if (cmd[i] != str[i])
+ return false;
+ }
+ return true;
+}
+
+void
+Usage(
+ const char * cmd,
+ const char * args
+) {
+ printf("Usage: %s %s\n", cmd, args);
+}
+
+void
+ExecuteCommand(
+ MatrixClient * client,
+ const char * cmd,
+ int nargs, char ** args
+) {
+ /**/ if (CheckCommand(cmd, "devicekey")) {
+ printf("%s\n", client->deviceKey);
+ }
+ else if (CheckCommand(cmd, "genkeys")) {
+ if (nargs != 1) {
+ Usage(cmd, "<number of keys>");
+ return;
+ }
+ MatrixClientGenerateOnetimeKeys(client, atoi(args[0]));
+ }
+ else if (CheckCommand(cmd, "uploadkeys")) {
+ MatrixClientUploadOnetimeKeys(client);
+ }
+ else if (CheckCommand(cmd, "onetimekeys")) {
+ static char buffer[1024];
+ olm_account_one_time_keys(client->olmAccount.account, buffer, 1024);
+ printf("%s\n", buffer);
+ }
+ else if (CheckCommand(cmd, "getkeys")) {
+ MatrixClientRequestDeviceKeys(client);
+ for (int i = 0; i < client->numDevices; i++)
+ printf("id: %s key: %s\n",
+ client->devices[i].deviceId,
+ client->devices[i].deviceKey);
+ }
+ else if (CheckCommand(cmd, "todevice")) {
+ static char buffer[30000];
+ MatrixClientSync(client,
+ buffer, 30000);
+ const char * todevice;
+ int todeviceLen;
+ mjson_find(buffer, 30000,
+ "$.to_device",
+ &todevice, &todeviceLen);
+ static char prettyBuffer[10000];
+ struct mjson_fixedbuf fb = { prettyBuffer, 10000, 0 };
+ mjson_pretty(todevice, todeviceLen,
+ " ", mjson_print_fixed_buf, &fb);
+ printf("%.*s\n", fb.len, fb.ptr);
+ }
+}
+
+int
+main(void)
+{
+ MatrixClient client;
+ MatrixClientInit(&client,
+ SERVER);
+
+ MatrixHttpInit(&client);
+
+ MatrixClientSetAccessToken(&client,
+ ACCESS_TOKEN);
+ MatrixClientSetDeviceId(&client,
+ DEVICE_ID);
+ MatrixClientSetUserId(&client,
+ USER_ID);
+
+ static char cmd[BUFFER_SIZE];
+ static char args_[BUFFER_SIZE][NUMBER_ARGS];
+ char * args[NUMBER_ARGS];
+ for (int i = 0; i < NUMBER_ARGS; i++)
+ args[i] = args_[i];
+ int nargs;
+ do {
+ GetCommand(cmd, &nargs, args);
+
+ ExecuteCommand(&client, cmd, nargs, args);
+
+ } while (strcmp(cmd, "exit") != 0);
+
+ MatrixHttpDeinit(&client);
+
+ return 0;
+}
diff --git a/examples/Keys.rdbg b/examples/Keys.rdbg Binary files differnew file mode 100644 index 0000000..7bea6fe --- /dev/null +++ b/examples/Keys.rdbg diff --git a/examples/ReplyRoomkey.c b/examples/ReplyRoomkey.c new file mode 100644 index 0000000..8d61a4c --- /dev/null +++ b/examples/ReplyRoomkey.c @@ -0,0 +1,40 @@ +#include <matrix.h>
+#include <stdio.h>
+
+#define SERVER "https://matrix.org"
+#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO"
+#define DEVICE_ID "MAZNCCZLBR"
+#define USER_ID "@pscho:matrix.org"
+#define ROOM_ID "!XKFUjAsGrSSrpDFIxB:matrix.org"
+
+int
+main(void)
+{
+ MatrixClient client;
+ MatrixClientInit(&client,
+ SERVER);
+
+ MatrixHttpInit(&client);
+
+ MatrixClientSetAccessToken(&client,
+ ACCESS_TOKEN);
+ MatrixClientSetDeviceId(&client,
+ DEVICE_ID);
+ MatrixClientSetUserId(&client,
+ USER_ID);
+
+
+ MatrixClientSendEventEncrypted(&client,
+ ROOM_ID,
+ "m.room.message",
+ "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");
+
+ MatrixClientShareMegolmOutSession(&client,
+ USER_ID,
+ "ULZZOKJBYN",
+ &client.megolmOutSessions[0]);
+
+ MatrixHttpDeinit(&client);
+
+ return 0;
+}
diff --git a/examples/SendEncrypted.rdbg b/examples/SendEncrypted.rdbg Binary files differnew file mode 100644 index 0000000..120f0a0 --- /dev/null +++ b/examples/SendEncrypted.rdbg |
