]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix_http_mongoose.c
delete OlmJS example
[matrix_esp_thesis] / src / matrix_http_mongoose.c
index 2e500d69c5557ae35dff29bacb2a89bd4b8e4845..452e26c59fb0b26de08671e449e16caaa029feec 100644 (file)
@@ -43,6 +43,10 @@ MatrixHttpCallback(
 \r
         conn->connection = c;\r
         conn->connected = true;\r
+    }\r
+    if (ev == MG_EV_HTTP_CHUNK)\r
+    {\r
+        \r
     }\r
     if (ev == MG_EV_HTTP_MSG)\r
     {\r
@@ -56,7 +60,12 @@ MatrixHttpCallback(
         conn->dataLen = hm->body.len;\r
         conn->dataReceived = true;\r
 \r
-        printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data);\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
@@ -71,7 +80,17 @@ MatrixHttpInit(
     \r
     mg_mgr_init(&conn->mgr);\r
 \r
-    struct mg_connection * c =\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
     while (! conn->connected)\r
@@ -101,6 +120,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
@@ -115,6 +136,15 @@ MatrixHttpGet(
     else\r
         authorizationHeader[0] = '\0';\r
 \r
+    printf(\r
+        "GET %s HTTP/1.1\r\n"\r
+        "Host: %.*s\r\n"\r
+        "%s"\r
+        "\r\n",\r
+        url,\r
+        host.len, host.ptr,\r
+        authorizationHeader);\r
+\r
     mg_printf(conn->connection,\r
         "GET %s HTTP/1.1\r\n"\r
         "Host: %.*s\r\n"\r
@@ -142,6 +172,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
@@ -154,6 +186,21 @@ MatrixHttpPost(
     else\r
         authorizationHeader[0] = '\0';\r
 \r
+    printf(\r
+            "POST %s HTTP/1.0\r\n"\r
+            "Host: %.*s\r\n"\r
+            "%s"\r
+            "Content-Type: application/json\r\n"\r
+            "Content-Length: %d\r\n"\r
+            "\r\n"\r
+            "%s"\r
+            "\r\n",\r
+            url,\r
+            host.len, host.ptr,\r
+            authorizationHeader,\r
+            strlen(requestBuffer),\r
+            requestBuffer);\r
+\r
     mg_printf(conn->connection,\r
             "POST %s HTTP/1.0\r\n"\r
             "Host: %.*s\r\n"\r
@@ -187,6 +234,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
@@ -199,7 +248,9 @@ MatrixHttpPut(
     else\r
         authorizationHeader[0] = '\0';\r
 \r
-    printf("PUT %s HTTP/1.0\r\n"\r
+    \r
+    printf(\r
+            "PUT %s HTTP/1.0\r\n"\r
             "Host: %.*s\r\n"\r
             "%s"\r
             "Content-Type: application/json\r\n"\r