]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix_http_mongoose.c
clean up
[matrix_esp_thesis] / src / matrix_http_mongoose.c
index 3b6970cb0abee4d64a9e5d6518a2acc49c3fa7a9..2f5d768febc131c94712abed94d934d9f138f14f 100644 (file)
@@ -6,7 +6,6 @@
 #include <stdbool.h>\r
 #include <mongoose.h>\r
 \r
 #include <stdbool.h>\r
 #include <mongoose.h>\r
 \r
-//#define HTTP_DATA_SIZE 1024\r
 #define AUTHORIZATION_HEADER_LEN 64\r
 \r
 typedef struct MatrixHttpConnection {\r
 #define AUTHORIZATION_HEADER_LEN 64\r
 \r
 typedef struct MatrixHttpConnection {\r
@@ -55,15 +54,12 @@ MatrixHttpCallback(
     {\r
         // Response\r
         struct mg_http_message *hm = (struct mg_http_message *)ev_data;\r
     {\r
         // Response\r
         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
+        \r
         memcpy(conn->data, 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
+        \r
         conn->data[hm->body.len] = '\0';\r
         conn->dataLen = hm->body.len;\r
         conn->dataReceived = true;\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
     if (ev == MG_EV_CLOSE)\r
     {\r
     }\r
     if (ev == MG_EV_CLOSE)\r
     {\r
@@ -139,22 +135,11 @@ MatrixHttpGet(
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
-        sprintf(authorizationHeader,\r
+        snprintf(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
             "Authorization: Bearer %s\r\n", hc->accessToken);\r
             "Authorization: Bearer %s\r\n", hc->accessToken);\r
-        // sprintf_s(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
-        //     "Authorization: Bearer %s\r\n", client->accessToken);\r
     else\r
         authorizationHeader[0] = '\0';\r
 \r
     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(hc->connection,\r
         "GET %s HTTP/1.1\r\n"\r
         "Host: %.*s\r\n"\r
     mg_printf(hc->connection,\r
         "GET %s HTTP/1.1\r\n"\r
         "Host: %.*s\r\n"\r
@@ -190,26 +175,11 @@ MatrixHttpPost(
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
-        sprintf(authorizationHeader,\r
+        snprintf(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
             "Authorization: Bearer %s\r\n", hc->accessToken);\r
     else\r
         authorizationHeader[0] = '\0';\r
 \r
             "Authorization: Bearer %s\r\n", hc->accessToken);\r
     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(hc->connection,\r
             "POST %s HTTP/1.0\r\n"\r
             "Host: %.*s\r\n"\r
     mg_printf(hc->connection,\r
             "POST %s HTTP/1.0\r\n"\r
             "Host: %.*s\r\n"\r
@@ -220,9 +190,9 @@ MatrixHttpPost(
             "%s"\r
             "\r\n",\r
             url,\r
             "%s"\r
             "\r\n",\r
             url,\r
-            host.len, host.ptr,\r
+            (int)host.len, host.ptr,\r
             authorizationHeader,\r
             authorizationHeader,\r
-            strlen(requestBuffer),\r
+            (int)strlen(requestBuffer),\r
             requestBuffer);\r
 \r
     hc->data = outResponseBuffer;\r
             requestBuffer);\r
 \r
     hc->data = outResponseBuffer;\r
@@ -251,27 +221,11 @@ MatrixHttpPut(
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
 \r
     static char authorizationHeader[AUTHORIZATION_HEADER_LEN];\r
     if (authenticated)\r
-        sprintf(authorizationHeader,\r
+        snprintf(authorizationHeader, AUTHORIZATION_HEADER_LEN,\r
             "Authorization: Bearer %s\r\n", hc->accessToken);\r
     else\r
         authorizationHeader[0] = '\0';\r
 \r
             "Authorization: Bearer %s\r\n", hc->accessToken);\r
     else\r
         authorizationHeader[0] = '\0';\r
 \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
-            "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(hc->connection,\r
             "PUT %s HTTP/1.0\r\n"\r
             "Host: %.*s\r\n"\r
     mg_printf(hc->connection,\r
             "PUT %s HTTP/1.0\r\n"\r
             "Host: %.*s\r\n"\r
@@ -282,9 +236,9 @@ MatrixHttpPut(
             "%s"\r
             "\r\n",\r
             url,\r
             "%s"\r
             "\r\n",\r
             url,\r
-            host.len, host.ptr,\r
+            (int)host.len, host.ptr,\r
             authorizationHeader,\r
             authorizationHeader,\r
-            strlen(requestBuffer),\r
+            (int)strlen(requestBuffer),\r
             requestBuffer);\r
 \r
     hc->data = outResponseBuffer;\r
             requestBuffer);\r
 \r
     hc->data = outResponseBuffer;\r