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