]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix_http_mongoose.c
olm session management
[matrix_esp_thesis] / src / matrix_http_mongoose.c
index 8d575e5213bf37407c5590a85c03ce72123e74be..020b4c8cf638256edc9db6a521b454f7c71c4f98 100644 (file)
@@ -1,4 +1,5 @@
 #include "matrix.h"\r
+\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
@@ -35,7 +36,8 @@ MatrixHttpCallback(
         // If s_url is https://, tell client connection to use TLS\r
         if (mg_url_is_ssl(client->server))\r
         {\r
-            struct mg_tls_opts opts = {.srvname = host};\r
+            struct mg_tls_opts opts;\r
+            opts.srvname = host;\r
             mg_tls_init(c, &opts);\r
         }\r
 \r
@@ -48,10 +50,13 @@ MatrixHttpCallback(
         struct mg_http_message *hm = (struct mg_http_message *)ev_data;\r
         // memcpy_s(client->data, 1024, hm->message.ptr, hm->message.len);\r
         // client->dataLen = hm->message.len;\r
-        memcpy_s(conn->data, conn->dataCap, hm->body.ptr, hm->body.len);\r
+        memcpy(conn->data, hm->body.ptr, hm->body.len);\r
+        // memcpy_s(conn->data, conn->dataCap, hm->body.ptr, hm->body.len);\r
         conn->data[hm->body.len] = '\0';\r
         conn->dataLen = hm->body.len;\r
         conn->dataReceived = true;\r
+\r
+        printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data);\r
     }\r
 }\r
 \r
@@ -100,10 +105,14 @@ MatrixHttpGet(
 \r
     struct mg_str host = mg_url_host(client->server);\r
 \r
-    static char authorizationHeader[AUTHORIZATION_HEADER_LEN] = "\0";\r
+    static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
-        sprintf_s(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
-            "Authorization: Bearer %s\r\n", client->accessTokenBuffer);\r
+        sprintf(authorizationHeader,\r
+            "Authorization: Bearer %s\r\n", client->accessToken);\r
+        // sprintf_s(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
+        //     "Authorization: Bearer %s\r\n", client->accessToken);\r
+    else\r
+        authorizationHeader[0] = '\0';\r
 \r
     mg_printf(conn->connection,\r
         "GET %s HTTP/1.1\r\n"\r
@@ -137,10 +146,12 @@ MatrixHttpPost(
 \r
     struct mg_str host = mg_url_host(client->server);\r
 \r
-    static char authorizationHeader[AUTHORIZATION_HEADER_LEN] = "\0";\r
+    static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
-        sprintf_s(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
-            "Authorization: Bearer %s\r\n", client->accessTokenBuffer);\r
+        sprintf(authorizationHeader,\r
+            "Authorization: Bearer %s\r\n", client->accessToken);\r
+    else\r
+        authorizationHeader[0] = '\0';\r
 \r
     mg_printf(conn->connection,\r
             "POST %s HTTP/1.0\r\n"\r
@@ -182,8 +193,8 @@ MatrixHttpPut(
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
-        sprintf_s(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
-            "Authorization: Bearer %s\r\n", client->accessTokenBuffer);\r
+        sprintf(authorizationHeader,\r
+            "Authorization: Bearer %s\r\n", client->accessToken);\r
     else\r
         authorizationHeader[0] = '\0';\r
 \r