abouttreesummaryrefslogcommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPatrick2023-07-17 17:37:49 +0200
committerPatrick2023-07-17 17:37:49 +0200
commit464bfb1912d0806143386f61c33dd45fbafc38e8 (patch)
tree0c6c64c8c144d262e64c14e5b3434b146928220d /examples
parent4c72c6901e007414aebb4cb6534c1a49d63558b0 (diff)
downloadmatrix_esp_thesis-464bfb1912d0806143386f61c33dd45fbafc38e8.tar.gz
matrix_esp_thesis-464bfb1912d0806143386f61c33dd45fbafc38e8.zip
cli send, save and load
Diffstat (limited to 'examples')
-rw-r--r--examples/Cli.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/examples/Cli.c b/examples/Cli.c
index af1d6b1..b2fbe45 100644
--- a/examples/Cli.c
+++ b/examples/Cli.c
@@ -76,14 +76,13 @@ ExecuteCommand(
const char * cmd,
int nargs, char ** args
) {
+#define CHECK_ARGS(N, ARGS) if (nargs != N) { Usage(cmd, ARGS); return; }
/**/ if (CheckCommand(cmd, "devicekey")) {
printf("%s\n", client->deviceKey);
}
else if (CheckCommand(cmd, "genkeys")) {
- if (nargs != 1) {
- Usage(cmd, "<number of keys>");
- return;
- }
+ CHECK_ARGS(1, "<number of keys>")
+
MatrixClientGenerateOnetimeKeys(client, atoi(args[0]));
}
else if (CheckCommand(cmd, "uploadkeys")) {
@@ -116,6 +115,40 @@ ExecuteCommand(
" ", mjson_print_fixed_buf, &fb);
printf("%.*s\n", fb.len, fb.ptr);
}
+ else if (CheckCommand(cmd, "save")) {
+ CHECK_ARGS(1, "<filename>")
+
+ MatrixClientSave(client, args[0]);
+ }
+ else if (CheckCommand(cmd, "load")) {
+ CHECK_ARGS(1, "<filename>")
+
+ MatrixClientLoad(client, args[0]);
+ }
+ else if (CheckCommand(cmd, "send")) {
+ CHECK_ARGS(2, "<room_id> <message>")
+
+ static char body[1024];
+ snprintf(body, 1024,
+ "{\"body\":\"%s\",\"msgtype\":\"m.text\"}",
+ args[1]);
+
+ printf("Sending %s to %s\n", body, args[0]);
+
+ MatrixClientSendEvent(client,
+ args[0],
+ "m.room.message",
+ body);
+ }
+ else if (CheckCommand(cmd, "setuserid")) {
+ CHECK_ARGS(1, "<user_id>")
+
+ MatrixClientSetUserId(client, args[0]);
+ }
+ else if (CheckCommand(cmd, "getuserid")) {
+ printf("User ID: %s\n", client->userId);
+ }
+#undef CHECK_ARGS
}
int
@@ -135,7 +168,7 @@ main(void)
USER_ID);
static char cmd[BUFFER_SIZE];
- static char args_[BUFFER_SIZE][NUMBER_ARGS];
+ static char args_[NUMBER_ARGS][BUFFER_SIZE];
char * args[NUMBER_ARGS];
for (int i = 0; i < NUMBER_ARGS; i++)
args[i] = args_[i];