abouttreesummaryrefslogcommitdiff
path: root/examples/SendEncrypted.c
blob: df1d27291185f9a2329226d4c52dd9b1f7b0aea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <matrix.h>
#include <stdio.h>

#define SERVER       "https://matrix.org"
#define USER_ID      "@pscho:matrix.org"
#define ROOM_ID      "!XKFUjAsGrSSrpDFIxB:matrix.org"

int
main(void)
{
    MatrixClient client;
    MatrixClientInit(&client,
        SERVER);
    
    MatrixHttpInit(&client);

    MatrixClientSetUserId(&client, USER_ID);

    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,
        &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,
        "m.room.message",
        "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");
        
    MatrixClientDeleteDevice(&client);

    MatrixHttpDeinit(&client);

    return 0;
}