X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/d43e8671acc5709c192e159e0d91626f0677cdf1..HEAD:/examples/SendEncrypted.c?ds=sidebyside diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c index 2d3bd74..749037d 100644 --- a/examples/SendEncrypted.c +++ b/examples/SendEncrypted.c @@ -1,32 +1,56 @@ #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 "@example:matrix.org" +#define ROOM_ID "!example:matrix.org" +#define USERNAME "" +#define PASSWORD "" +#define DEVICE_NAME "" + +// device id of another device to share the megolm session with +// I used the device id of a logged in Element web session +#define DEVICE_ID2 "" 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, + USERNAME, + PASSWORD, + DEVICE_NAME); - 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, + DEVICE_ID2, + 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 +}