X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/1273c8ea309926e377cbd5cc6dab6740910aa6ff..504241758d7b832af61939beaf61b0e0574174c4:/src/matrix_http_mongoose.c diff --git a/src/matrix_http_mongoose.c b/src/matrix_http_mongoose.c index 2e500d6..452e26c 100644 --- a/src/matrix_http_mongoose.c +++ b/src/matrix_http_mongoose.c @@ -43,6 +43,10 @@ MatrixHttpCallback( conn->connection = c; conn->connected = true; + } + if (ev == MG_EV_HTTP_CHUNK) + { + } if (ev == MG_EV_HTTP_MSG) { @@ -56,7 +60,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 +80,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 +120,8 @@ MatrixHttpGet( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -115,6 +136,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 +172,8 @@ MatrixHttpPost( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -154,6 +186,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 +234,8 @@ MatrixHttpPut( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -199,7 +248,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"