X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/4c72c6901e007414aebb4cb6534c1a49d63558b0..c7aba5979c820958aa08947903afb47ace496a16:/examples/Cli.c diff --git a/examples/Cli.c b/examples/Cli.c index af1d6b1..daf79e9 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, ""); - return; - } + CHECK_ARGS(1, "") + MatrixClientGenerateOnetimeKeys(client, atoi(args[0])); } else if (CheckCommand(cmd, "uploadkeys")) { @@ -116,6 +115,103 @@ ExecuteCommand( " ", mjson_print_fixed_buf, &fb); printf("%.*s\n", fb.len, fb.ptr); } + else if (CheckCommand(cmd, "save")) { + CHECK_ARGS(1, "") + + MatrixClientSave(client, args[0]); + } + else if (CheckCommand(cmd, "load")) { + CHECK_ARGS(1, "") + + MatrixClientLoad(client, args[0]); + } + else if (CheckCommand(cmd, "send")) { + CHECK_ARGS(2, " ") + + static char body[1024]; + snprintf(body, 1024, + "{\"body\":\"%s\",\"msgtype\":\"m.text\"}", + args[1]); + + MatrixClientSendEvent(client, + args[0], + "m.room.message", + body); + } + else if (CheckCommand(cmd, "setuserid")) { + CHECK_ARGS(1, "") + + MatrixClientSetUserId(client, args[0]); + } + else if (CheckCommand(cmd, "getuserid")) { + printf("User ID: %s\n", client->userId); + } + else if (CheckCommand(cmd, "sendencrypted")) { + CHECK_ARGS(2, " ") + + static char body[1024]; + snprintf(body, 1024, + "{\"body\":\"%s\",\"msgtype\":\"m.text\"}", + args[1]); + + MatrixClientSendEventEncrypted(client, + args[0], + "m.room.message", + body); + } + else if (CheckCommand(cmd, "sharesession")) { + CHECK_ARGS(3, " ") + + int sessionIndex = atoi(args[0]); + + MatrixClientShareMegolmOutSession(client, + args[1], + args[2], + &client->megolmOutSessions[sessionIndex]); + } + else if (CheckCommand(cmd, "savesession")) { + CHECK_ARGS(3, " ") + + int sessionIndex = atoi(args[0]); + + MatrixMegolmOutSessionSave( + &client->megolmOutSessions[sessionIndex], + args[1], + args[2]); + } + else if (CheckCommand(cmd, "loadsession")) { + CHECK_ARGS(3, " ") + + int sessionIndex = atoi(args[0]); + + MatrixMegolmOutSessionLoad( + &client->megolmOutSessions[sessionIndex], + args[1], + args[2]); + } + else if (CheckCommand(cmd, "printsessions")) { + for (int i = 0; i < client->numMegolmOutSessions; i++) { + printf("%d: %s\t%s\t%s\n", i, + client->megolmOutSessions[i].roomId, + client->megolmOutSessions[i].id, + client->megolmOutSessions[i].key); + } + } + else if (CheckCommand(cmd, "initsession")) { + CHECK_ARGS(1, "") + + if (! MatrixClientInitMegolmOutSession(client, + args[0])) + { + printf("Maximum number of Megolm sessions reached (%d)\n", NUM_MEGOLM_SESSIONS); + } + } + + + else { + printf("Unknown command\n"); + } +#undef CHECK_ARGS } int @@ -135,7 +231,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];