X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/d43e8671acc5709c192e159e0d91626f0677cdf1..2130f565861a560c0f5ce98b3cc0c915e241bf79:/examples/SendEncrypted.c diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c index 2d3bd74..3debeab 100644 --- a/examples/SendEncrypted.c +++ b/examples/SendEncrypted.c @@ -1,32 +1,49 @@ #include +#include -#define SERVER FixedBuf("matrix.org") -#define ACCESS_TOKEN FixedBuf("abc") -#define ROOM_ID FixedBuf("!jhpZBTbckszblMYjMK:matrix.org") +#define SERVER "https://matrix.org" +#define USER_ID "@pscho:matrix.org" +#define ROOM_ID "!XKFUjAsGrSSrpDFIxB:matrix.org" int -main( - int argc, - char **argv) +main(void) { MatrixClient client; - MatrixClientCreate(&client, - SERVER); + MatrixClientInit(&client); + + MatrixHttpInit(&client.hc, SERVER); + + MatrixClientSetUserId(&client, USER_ID); - MatrixClientSetAccessToken(&client, - ACCESS_TOKEN); + MatrixClientLoginPassword(&client, + "pscho", + "Wc23EbmB9G3faMq", + "Test1"); - MatrixMegolmSession megolm; - MatrixMegolmSessionInit(&megolm); - - MatrixRoomShareMegolmSession(&client, + MatrixClientUploadDeviceKeys(&client); + MatrixClientGenerateOnetimeKeys(&client, 10); + MatrixClientUploadOnetimeKeys(&client); + + // create megolmsession + MatrixMegolmOutSession * megolmOutSession; + MatrixClientNewMegolmOutSession(&client, ROOM_ID, - megolm); - - MatrixClientSendGroupEncrypted(&client, + &megolmOutSession); + printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key); + + MatrixClientShareMegolmOutSession(&client, + USER_ID, + "ULZZOKJBYN", + megolmOutSession); + + MatrixClientSendEventEncrypted(&client, ROOM_ID, - FixedBuf("m.room.message"), - FixedBuf("{\"body\":\"Hello\",\"msgtype\":\"m.text\"}")); + "m.room.message", + "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"); + + MatrixClientDeleteDevice(&client); + + MatrixHttpDeinit(&client.hc); return 0; -} \ No newline at end of file +}