]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix_http_mongoose.c
upload device/onetime keys, fix recurring http accesses
[matrix_esp_thesis] / src / matrix_http_mongoose.c
index 2e500d69c5557ae35dff29bacb2a89bd4b8e4845..17edbc8cdcfabe7b53e453a05b057ae71520429f 100644 (file)
@@ -58,6 +58,11 @@ MatrixHttpCallback(
 \r
         printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data);\r
     }\r
+    if (ev == MG_EV_CLOSE)\r
+    {\r
+        conn->connection = NULL;\r
+        conn->connected = false;\r
+    }\r
 }\r
 \r
 bool\r
@@ -71,6 +76,16 @@ MatrixHttpInit(
     \r
     mg_mgr_init(&conn->mgr);\r
 \r
+    return MatrixHttpConnect(client);\r
+}\r
+\r
+bool\r
+MatrixHttpConnect(\r
+    MatrixClient * client)\r
+{\r
+    MatrixHttpConnection * conn =\r
+        (MatrixHttpConnection *)client->httpUserData;\r
+    \r
     struct mg_connection * c =\r
         mg_http_connect(&conn->mgr, client->server, MatrixHttpCallback, client);\r
 \r
@@ -101,6 +116,8 @@ MatrixHttpGet(
     bool authenticated)\r
 {\r
     MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData;\r
+    if (! conn->connected)\r
+        MatrixHttpConnect(client);\r
 \r
     conn->dataReceived = false;\r
 \r
@@ -142,6 +159,8 @@ MatrixHttpPost(
     bool authenticated)\r
 {\r
     MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData;\r
+    if (! conn->connected)\r
+        MatrixHttpConnect(client);\r
 \r
     conn->dataReceived = false;\r
 \r
@@ -187,6 +206,8 @@ MatrixHttpPut(
     bool authenticated)\r
 {\r
     MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData;\r
+    if (! conn->connected)\r
+        MatrixHttpConnect(client);\r
 \r
     conn->dataReceived = false;\r
 \r