diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp index 8cd957b62..31c0cc050 100644 --- a/controller/JSONDB.cpp +++ b/controller/JSONDB.cpp @@ -97,7 +97,7 @@ bool JSONDB::writeRaw(const std::string &n,const std::string &obj) Utils::snprintf(tmp,sizeof(tmp),"%lu",(unsigned long)obj.length()); reqHeaders["Content-Length"] = tmp; reqHeaders["Content-Type"] = "application/json"; - const unsigned int sc = Http::PUT(1048576,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),(_basePath+"/"+n).c_str(),reqHeaders,obj.data(),(unsigned long)obj.length(),headers,body); + const unsigned int sc = Http::PUT(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),(_basePath+"/"+n).c_str(),reqHeaders,obj.data(),(unsigned long)obj.length(),headers,body); return (sc == 200); } else { const std::string path(_genPath(n,true)); @@ -208,7 +208,7 @@ nlohmann::json JSONDB::eraseNetwork(const uint64_t networkId) // Deletion is currently done by Central in harnessed mode //std::map headers; //std::string body; - //Http::DEL(1048576,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body); + //Http::DEL(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body); } else { const std::string path(_genPath(n,false)); if (path.length()) @@ -235,7 +235,7 @@ nlohmann::json JSONDB::eraseNetworkMember(const uint64_t networkId,const uint64_ // Deletion is currently done by the caller in Central harnessed mode //std::map headers; //std::string body; - //Http::DEL(1048576,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body); + //Http::DEL(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body); } else { const std::string path(_genPath(n,false)); if (path.length()) @@ -347,7 +347,7 @@ bool JSONDB::_load(const std::string &p) std::string body; std::map headers; - const unsigned int sc = Http::GET(2147483647,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),_basePath.c_str(),_ZT_JSONDB_GET_HEADERS,headers,body); + const unsigned int sc = Http::GET(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast(&_httpAddr),_basePath.c_str(),_ZT_JSONDB_GET_HEADERS,headers,body); if (sc == 200) { try { nlohmann::json dbImg(OSUtils::jsonParse(body)); diff --git a/osdep/Http.cpp b/osdep/Http.cpp index d2540071c..f1d3bfe2c 100644 --- a/osdep/Http.cpp +++ b/osdep/Http.cpp @@ -112,12 +112,12 @@ struct HttpPhyHandler inline void phyOnTcpWritable(PhySocket *sock,void **uptr) { - if (writePtr < writeSize) { - long n = phy->streamSend(sock,writeBuf + writePtr,writeSize - writePtr,true); + if (writePtr < (unsigned long)writeBuf.length()) { + long n = phy->streamSend(sock,writeBuf.data() + writePtr,(unsigned long)writeBuf.length() - writePtr,true); if (n > 0) writePtr += n; } - if (writePtr >= writeSize) + if (writePtr >= (unsigned long)writeBuf.length()) phy->setNotifyWritable(sock,false); } @@ -135,8 +135,7 @@ struct HttpPhyHandler unsigned long messageSize; unsigned long writePtr; uint64_t lastActivity; - unsigned long writeSize; - char writeBuf[32768]; + std::string writeBuf; unsigned long maxResponseSize; std::map *responseHeaders; @@ -244,24 +243,26 @@ unsigned int Http::_do( handler.lastActivity = OSUtils::now(); try { - handler.writeSize = Utils::snprintf(handler.writeBuf,sizeof(handler.writeBuf),"%s %s HTTP/1.1\r\n",method,path); - for(std::map::const_iterator h(requestHeaders.begin());h!=requestHeaders.end();++h) - handler.writeSize += Utils::snprintf(handler.writeBuf + handler.writeSize,sizeof(handler.writeBuf) - handler.writeSize,"%s: %s\r\n",h->first.c_str(),h->second.c_str()); - handler.writeSize += Utils::snprintf(handler.writeBuf + handler.writeSize,sizeof(handler.writeBuf) - handler.writeSize,"\r\n"); - if ((requestBody)&&(requestBodyLength)) { - if ((handler.writeSize + requestBodyLength) > sizeof(handler.writeBuf)) { - responseBody = "request too large"; - return 0; - } - memcpy(handler.writeBuf + handler.writeSize,requestBody,requestBodyLength); - handler.writeSize += requestBodyLength; + char tmp[1024]; + Utils::snprintf(tmp,sizeof(tmp),"%s %s HTTP/1.1\r\n",method,path); + handler.writeBuf.append(tmp); + for(std::map::const_iterator h(requestHeaders.begin());h!=requestHeaders.end();++h) { + Utils::snprintf(tmp,sizeof(tmp),"%s: %s\r\n",h->first.c_str(),h->second.c_str()); + handler.writeBuf.append(tmp); } + handler.writeBuf.append("\r\n"); + if ((requestBody)&&(requestBodyLength)) + handler.writeBuf.append((const char *)requestBody,requestBodyLength); } catch ( ... ) { responseBody = "request too large"; return 0; } - handler.maxResponseSize = maxResponseSize; + if (maxResponseSize) { + handler.maxResponseSize = maxResponseSize; + } else { + handler.maxResponseSize = 2147483647; + } handler.responseHeaders = &responseHeaders; handler.responseBody = &responseBody; handler.error = false;