]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix.h
use global static buffers to save memory, get Verify example working on ESP32
[matrix_esp_thesis] / src / matrix.h
index da0e85930b726169adbcd3fd0dcbe663b58f884f..c07c742b0f6463a841d5f7810933d7c1d93c25c6 100644 (file)
 #define JSON_ONETIME_KEY_SIGNED_SIZE 256\r
 #define JSON_SIGNATURE_SIZE 256\r
 \r
-#define NUM_MEGOLM_SESSIONS 10\r
-#define NUM_OLM_SESSIONS 10\r
-#define NUM_DEVICES 10\r
+#define NUM_MEGOLM_SESSIONS 2\r
+#define NUM_OLM_SESSIONS 2\r
+#define NUM_DEVICES 5\r
+\r
+// HTTP\r
+\r
+typedef struct MatrixHttpConnection MatrixHttpConnection;\r
+\r
+bool\r
+MatrixHttpInit(\r
+    MatrixHttpConnection ** hc,\r
+    const char * host);\r
+\r
+// bool\r
+// MatrixHttpConnect(\r
+//     MatrixHttpConnection * hc);\r
+\r
+bool\r
+MatrixHttpDeinit(\r
+    MatrixHttpConnection ** hc);\r
+    \r
+bool\r
+MatrixHttpSetAccessToken(\r
+    MatrixHttpConnection * hc,\r
+    const char * accessToken);\r
+\r
+bool\r
+MatrixHttpGet(\r
+    MatrixHttpConnection * hc,\r
+    const char * url,\r
+    char * outResponseBuffer, int outResponseCap,\r
+    bool authenticated);\r
+\r
+bool\r
+MatrixHttpPost(\r
+    MatrixHttpConnection * hc,\r
+    const char * url,\r
+    const char * requestBuffer,\r
+    char * outResponseBuffer, int outResponseCap,\r
+    bool authenticated);\r
+\r
+bool\r
+MatrixHttpPut(\r
+    MatrixHttpConnection * hc,\r
+    const char * url,\r
+    const char * requestBuffer,\r
+    char * outResponseBuffer, int outResponseCap,\r
+    bool authenticated);\r
+\r
+\r
 \r
 // Matrix Device\r
 \r
@@ -105,6 +152,14 @@ MatrixOlmSessionUnpickle(
     void * pickled, int pickledLen,\r
     const void * key, int keyLen);\r
 \r
+bool\r
+MatrixOlmSessionFrom(\r
+    MatrixOlmSession * session,\r
+    OlmAccount * olmAccount,\r
+    const char * deviceId,\r
+    const char * deviceKey,\r
+    const char * encrypted);\r
+\r
 bool\r
 MatrixOlmSessionTo(\r
     MatrixOlmSession * session,\r
@@ -130,23 +185,35 @@ MatrixOlmSessionDecrypt(
 // Matrix Megolm Session\r
 \r
 typedef struct MatrixMegolmInSession {\r
+    char roomId[ROOM_ID_SIZE];\r
+    char id[MEGOLM_SESSION_ID_SIZE];\r
+    char key[MEGOLM_SESSION_KEY_SIZE];\r
+\r
     OlmInboundGroupSession * session;\r
+    char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
+\r
 } MatrixMegolmInSession;\r
 \r
+bool\r
+MatrixMegolmInSessionInit(\r
+    MatrixMegolmInSession * session,\r
+    const char * roomId,\r
+    const char * sessionId,\r
+    const char * sessionKey, int sessionKeyLen);\r
+\r
 bool\r
 MatrixMegolmInSessionDecrypt(\r
-    MatrixMegolmInSession * megolmInSession,\r
-    const char * encrypted,\r
+    MatrixMegolmInSession * session,\r
+    const char * encrypted, int encryptedLen,\r
     char * outDecrypted, int outDecryptedCap);\r
 \r
 typedef struct MatrixMegolmOutSession {\r
     char roomId[ROOM_ID_SIZE];\r
+    char id[MEGOLM_SESSION_ID_SIZE];\r
+    char key[MEGOLM_SESSION_KEY_SIZE];\r
 \r
     OlmOutboundGroupSession * session;\r
     char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
-\r
-    char id[MEGOLM_SESSION_ID_SIZE];\r
-    char key[MEGOLM_SESSION_KEY_SIZE];\r
 } MatrixMegolmOutSession;\r
 \r
 bool\r
@@ -192,19 +259,17 @@ typedef struct MatrixClient {
     // char signingKey[DEVICE_KEY_SIZE];\r
 \r
     char userId[USER_ID_SIZE];\r
-    char server[SERVER_SIZE];\r
     char accessToken[ACCESS_TOKEN_SIZE];\r
     char deviceId[DEVICE_ID_SIZE];\r
     char expireMs[EXPIRE_MS_SIZE];\r
     char refreshToken[REFRESH_TOKEN_SIZE];\r
 \r
-    void * httpUserData;\r
+    MatrixHttpConnection * hc;\r
 } MatrixClient;\r
 \r
 bool\r
 MatrixClientInit(\r
-    MatrixClient * client,\r
-    const char * server);\r
+    MatrixClient * client);\r
 \r
 bool\r
 MatrixClientSave(\r
@@ -306,15 +371,25 @@ MatrixClientGetMegolmOutSession(
     MatrixMegolmOutSession ** outSession);\r
 \r
 bool\r
-MatrixClientSetMegolmOutSession(\r
+MatrixClientNewMegolmOutSession(\r
     MatrixClient * client,\r
     const char * roomId,\r
-    MatrixMegolmOutSession session);\r
+    MatrixMegolmOutSession ** outSession);\r
 \r
 bool\r
-MatrixClientInitMegolmOutSession(\r
+MatrixClientGetMegolmInSession(\r
     MatrixClient * client,\r
-    const char * roomId);\r
+    const char * roomId, int roomIdLen,\r
+    const char * sessionId, int sessionIdLen,\r
+    MatrixMegolmInSession ** outSession);\r
+\r
+bool\r
+MatrixClientNewMegolmInSession(\r
+    MatrixClient * client,\r
+    const char * roomId,\r
+    const char * sessionId,\r
+    const char * sessionKey,\r
+    MatrixMegolmInSession ** outSession);\r
     \r
 bool\r
 MatrixClientRequestMegolmInSession(\r
@@ -323,8 +398,7 @@ MatrixClientRequestMegolmInSession(
     const char * sessionId,\r
     const char * senderKey,\r
     const char * userId,\r
-    const char * deviceId, // TODO: remove deviceId (query all devices)\r
-    MatrixMegolmInSession * outMegolmInSession);\r
+    const char * deviceId); // TODO: remove deviceId (query all devices)\r
 \r
 bool\r
 MatrixClientGetOlmSession(\r
@@ -333,6 +407,21 @@ MatrixClientGetOlmSession(
     const char * deviceId,\r
     MatrixOlmSession ** outSession);\r
 \r
+bool\r
+MatrixClientNewOlmSessionIn(\r
+    MatrixClient * client,\r
+    const char * userId,\r
+    const char * deviceId,\r
+    const char * encrypted,\r
+    MatrixOlmSession ** outSession);\r
+    \r
+bool\r
+MatrixClientNewOlmSessionOut(\r
+    MatrixClient * client,\r
+    const char * userId,\r
+    const char * deviceId,\r
+    MatrixOlmSession ** outSession);\r
+\r
 bool\r
 MatrixClientSendToDevice(\r
     MatrixClient * client,\r
@@ -376,43 +465,6 @@ MatrixClientDeleteDevice(
     MatrixClient * client);\r
 \r
 \r
-\r
-\r
-bool\r
-MatrixHttpInit(\r
-    MatrixClient * client);\r
-\r
-bool\r
-MatrixHttpConnect(\r
-    MatrixClient * client);\r
-\r
-bool\r
-MatrixHttpDeinit(\r
-    MatrixClient * client);\r
-\r
-bool\r
-MatrixHttpGet(\r
-    MatrixClient * client,\r
-    const char * url,\r
-    char * outResponseBuffer, int outResponseCap,\r
-    bool authenticated);\r
-\r
-bool\r
-MatrixHttpPost(\r
-    MatrixClient * client,\r
-    const char * url,\r
-    const char * requestBuffer,\r
-    char * outResponseBuffer, int outResponseCap,\r
-    bool authenticated);\r
-\r
-bool\r
-MatrixHttpPut(\r
-    MatrixClient * client,\r
-    const char * url,\r
-    const char * requestBuffer,\r
-    char * outResponseBuffer, int outResponseCap,\r
-    bool authenticated);\r
-\r
 // util\r
 \r
 void\r
@@ -423,6 +475,11 @@ JsonEscape(
     const char * sIn, int sInLen,\r
     char * sOut, int sOutCap);\r
     \r
+bool\r
+JsonCanonicalize(\r
+    const char * sIn, int sInLen,\r
+    char * sOut, int sOutCap);\r
+    \r
 bool\r
 JsonSign(\r
     MatrixClient * client,\r