X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/d43e8671acc5709c192e159e0d91626f0677cdf1..30bde47d1d5d9b6f0b59c318ff16caed6268d1a8:/examples/SendEncrypted.c?ds=sidebyside diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c index 2d3bd74..df1d272 100644 --- a/examples/SendEncrypted.c +++ b/examples/SendEncrypted.c @@ -1,32 +1,69 @@ #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, + MatrixClientInit(&client, SERVER); + + MatrixHttpInit(&client); - MatrixClientSetAccessToken(&client, - ACCESS_TOKEN); + MatrixClientSetUserId(&client, USER_ID); - MatrixMegolmSession megolm; - MatrixMegolmSessionInit(&megolm); - - MatrixRoomShareMegolmSession(&client, + MatrixClientLoginPassword(&client, + "pscho", + "Wc23EbmB9G3faMq", + "Test1"); + + MatrixClientUploadDeviceKey(&client); + MatrixClientGenerateOnetimeKeys(&client, 10); + MatrixClientUploadOnetimeKeys(&client); + + // // get device key + // static char deviceKey[128]; + // MatrixClientGetDeviceKey(&client, + // "ULZZOKJBYN", + // deviceKey, 128); + // printf("device key for %s: %s\n", "ULZZOKJBYN", deviceKey); + + // create megolmsession + MatrixMegolmOutSession * megolmOutSession; + MatrixClientGetMegolmOutSession(&client, ROOM_ID, - megolm); - - MatrixClientSendGroupEncrypted(&client, + &megolmOutSession); + printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key); + + // // create olmsession + // MatrixOlmSession * olmSession; + // MatrixClientGetOlmSession(&client, + // USER_ID, + // "ULZZOKJBYN", + // &olmSession); + // printf("olm session created\n"); + + MatrixClientShareMegolmOutSession(&client, + USER_ID, + "ULZZOKJBYN", + megolmOutSession); + // MatrixClientShareMegolmOutSessionTest(&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); return 0; -} \ No newline at end of file +}