X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/1273c8ea309926e377cbd5cc6dab6740910aa6ff..30bde47d1d5d9b6f0b59c318ff16caed6268d1a8:/src/matrix_http_mongoose.c diff --git a/src/matrix_http_mongoose.c b/src/matrix_http_mongoose.c index 2e500d6..b9b2ca3 100644 --- a/src/matrix_http_mongoose.c +++ b/src/matrix_http_mongoose.c @@ -56,7 +56,12 @@ MatrixHttpCallback( conn->dataLen = hm->body.len; conn->dataReceived = true; - printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data); + //printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data); + } + if (ev == MG_EV_CLOSE) + { + conn->connection = NULL; + conn->connected = false; } } @@ -71,7 +76,17 @@ MatrixHttpInit( mg_mgr_init(&conn->mgr); - struct mg_connection * c = + return MatrixHttpConnect(client); +} + +bool +MatrixHttpConnect( + MatrixClient * client) +{ + MatrixHttpConnection * conn = + (MatrixHttpConnection *)client->httpUserData; + + //struct mg_connection * c = mg_http_connect(&conn->mgr, client->server, MatrixHttpCallback, client); while (! conn->connected) @@ -101,6 +116,8 @@ MatrixHttpGet( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -115,6 +132,15 @@ MatrixHttpGet( else authorizationHeader[0] = '\0'; + printf( + "GET %s HTTP/1.1\r\n" + "Host: %.*s\r\n" + "%s" + "\r\n", + url, + host.len, host.ptr, + authorizationHeader); + mg_printf(conn->connection, "GET %s HTTP/1.1\r\n" "Host: %.*s\r\n" @@ -142,6 +168,8 @@ MatrixHttpPost( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -154,6 +182,21 @@ MatrixHttpPost( else authorizationHeader[0] = '\0'; + printf( + "POST %s HTTP/1.0\r\n" + "Host: %.*s\r\n" + "%s" + "Content-Type: application/json\r\n" + "Content-Length: %d\r\n" + "\r\n" + "%s" + "\r\n", + url, + host.len, host.ptr, + authorizationHeader, + strlen(requestBuffer), + requestBuffer); + mg_printf(conn->connection, "POST %s HTTP/1.0\r\n" "Host: %.*s\r\n" @@ -187,6 +230,8 @@ MatrixHttpPut( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -199,7 +244,9 @@ MatrixHttpPut( else authorizationHeader[0] = '\0'; - printf("PUT %s HTTP/1.0\r\n" + + printf( + "PUT %s HTTP/1.0\r\n" "Host: %.*s\r\n" "%s" "Content-Type: application/json\r\n"