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 |
|
Matrix Client Library in C
This is a library implementing parts of the Matrix Client-Server API. It is written in C and supports sending and receiving of messages, including end-to-end encryption. Device verification is also supported.
Building
Building requires a C/C++ compiler and make.
To build the dependencies run make deps.
To build any of the examples run make out/examples/<example>.
To use the library:
- Add
src/matrix.cto compilation - Add either
src/matrix_http_mongoose.corsrc/matrix_http_esp32.cto compilation - Add
out/*.oto compilation - Add include path
src/ - Add include path
ext/olm/include/ - Add include path
ext/mjson/src/ - Add include path
ext/mongoose/
Dependencies
Examples
Sending an encrypted message
MatrixMegolmOutSession * megolmOutSession;
MatrixClientNewMegolmOutSession(&client,
ROOM_ID,
&megolmOutSession);
printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key);
MatrixClientShareMegolmOutSession(&client,
USER_ID,
"ULZZOKJBYN",
megolmOutSession);
MatrixClientSendEventEncrypted(&client,
ROOM_ID,
"m.room.message",
"{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");
Verification
// Request an encrypted event to enable verification
STATIC char eventBuffer[1024];
MatrixClientGetRoomEvent(client,
ROOM_ID,
EVENT_ID,
eventBuffer, 1024);
#define SYNC_BUFFER_SIZE 1024*10
STATIC char syncBuffer[SYNC_BUFFER_SIZE];
STATIC char nextBatch[1024];
while (! client->verified) {
MatrixClientSync(client, syncBuffer, SYNC_BUFFER_SIZE, nextBatch, 1024);
}
