]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - Readme.md
update code block to include 'c' specifier
[matrix_esp_thesis] / Readme.md
index 606f53d46f33cc1a73eee761f5cc39ec67857d21..81b3c2f8d1632de2e0b17ffce1419b35c23a1e75 100644 (file)
--- a/Readme.md
+++ b/Readme.md
@@ -1 +1,122 @@
 # 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
+\r
+To build the dependencies run `make deps`.\r
+All dependencies are included in this repository.\r
+\r
+To build any of the examples run `make out/examples/<example>`.\r
+\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
+To build the example for the ESP32 start an ESP-IDF shell in esp32/esp_project or esp32/esp_project_riscv and run:\r
+- `idf.py build`\r
+- `idf.py flash`\r
+- `idf.py monitor`\r
+\r
+Examples for the ESP32 are in `esp32/esp_project/main`.\r
+There are currently two, SendEncrypted and Verify.\r
+The example can be set in `esp32/esp_project(_risc_v)/main/CMakeLists.txt` as the second argument after SRCS.\r
+\r
+Any code using the library should compile under ESP-IDF if the following code is added at the end of the file:\r
+```c\r
+#include "wifi.h"\r
+\r
+void\r
+app_main(void)\r
+{\r
+    wifi_init(WIFI_SSID, WIFI_PASSWORD);\r
+\r
+    main();\r
+}\r
+\r
+```\r
+\r
+To use the library in an ESP-IDF project:\r
+- Add the matrix and olm components (can be found in `esp32/esp_project/components/`)\r
+- Add `wifi.c/.h` (can be found in `esp32/esp_project/main/`)\r
+- Add `SET(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -fpermissive")` to CMakeLists.txt\r
+- Call `wifi_init("<SSID>", "<PASSWORD>")` before initializing the library\r
+\r
+## Dependencies\r
+[Mongoose](https://github.com/cesanta/mongoose)\r
+\r
+[mjson](https://github.com/cesanta/mjson)\r
+\r
+[Olm](https://gitlab.matrix.org/matrix-org/olm)\r
+\r
+## Examples\r
+\r
+### (De)Initialization\r
+```c\r
+MatrixClient * client = (MatrixClient*)malloc(sizeof(MatrixClient));\r
+MatrixClientInit(client);\r
+\r
+MatrixHttpInit(&client->hc, SERVER);\r
+MatrixClientSetUserId(client, USER_ID);\r
+\r
+MatrixClientLoginPassword(client,\r
+    USERNAME,\r
+    PASSWORD,\r
+    DEVICE_NAME);\r
+\r
+MatrixClientDeleteDevice(client);\r
+    \r
+MatrixHttpDeinit(&client->hc);\r
+```\r
+\r
+### Uploading keys\r
+```c\r
+MatrixClientGenerateOnetimeKeys(client, 10);\r
+MatrixClientUploadOnetimeKeys(client);\r
+MatrixClientUploadDeviceKeys(client);\r
+```\r
+\r
+### Sending an encrypted message\r
+```c\r
+MatrixMegolmOutSession * megolmOutSession;\r
+MatrixClientNewMegolmOutSession(&client,\r
+    ROOM_ID,\r
+    &megolmOutSession);\r
+\r
+MatrixClientShareMegolmOutSession(&client,\r
+    USER_ID,\r
+    DEVICE_ID2,\r
+    megolmOutSession);\r
+\r
+MatrixClientSendEventEncrypted(&client,\r
+    ROOM_ID,\r
+    "m.room.message",\r
+    "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");\r
+```\r
+\r
+### Verification\r
+```c\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
+```\r