aboutsummaryrefslogtreecommitdiff
path: root/backends/networking
diff options
context:
space:
mode:
authorEugene Sandulenko2016-07-22 15:38:24 +0300
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitd57fca4665e65bca1cf487fb109d020d1233e800 (patch)
treec5a8b0e88f4c55e0f2e2afb2f78a4cd1f89d66f3 /backends/networking
parentcccfe7c247fed9b00c100e64433439386d6ef077 (diff)
downloadscummvm-rg350-d57fca4665e65bca1cf487fb109d020d1233e800.tar.gz
scummvm-rg350-d57fca4665e65bca1cf487fb109d020d1233e800.tar.bz2
scummvm-rg350-d57fca4665e65bca1cf487fb109d020d1233e800.zip
CLOUD: JANITORIAL: Fix code formatting
Diffstat (limited to 'backends/networking')
-rw-r--r--backends/networking/curl/cloudicon.cpp19
-rw-r--r--backends/networking/curl/connectionmanager.cpp30
-rw-r--r--backends/networking/curl/curljsonrequest.cpp12
-rw-r--r--backends/networking/curl/curlrequest.cpp9
-rw-r--r--backends/networking/curl/networkreadstream.cpp21
-rw-r--r--backends/networking/curl/request.cpp8
-rw-r--r--backends/networking/sdl_net/client.cpp45
-rw-r--r--backends/networking/sdl_net/getclienthandler.cpp12
-rw-r--r--backends/networking/sdl_net/handlers/createdirectoryhandler.cpp9
-rw-r--r--backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp4
-rw-r--r--backends/networking/sdl_net/handlers/filesbasehandler.cpp12
-rw-r--r--backends/networking/sdl_net/handlers/filespagehandler.cpp75
-rw-r--r--backends/networking/sdl_net/handlers/listajaxhandler.cpp44
-rw-r--r--backends/networking/sdl_net/handlers/resourcehandler.cpp6
-rw-r--r--backends/networking/sdl_net/handlerutils.cpp18
-rw-r--r--backends/networking/sdl_net/localwebserver.cpp49
-rw-r--r--backends/networking/sdl_net/reader.cpp109
-rw-r--r--backends/networking/sdl_net/uploadfileclienthandler.cpp19
18 files changed, 338 insertions, 163 deletions
diff --git a/backends/networking/curl/cloudicon.cpp b/backends/networking/curl/cloudicon.cpp
index 80e26169dd..1c1ecf2f85 100644
--- a/backends/networking/curl/cloudicon.cpp
+++ b/backends/networking/curl/cloudicon.cpp
@@ -83,14 +83,16 @@ bool CloudIcon::draw() {
if (g_system) {
Graphics::TransparentSurface *surface = &_icon;
makeAlphaIcon((_showingDisabled ? _disabledIcon : _icon), _currentAlpha);
- if (_alphaIcon.getPixels()) surface = &_alphaIcon;
+ if (_alphaIcon.getPixels())
+ surface = &_alphaIcon;
if (surface && surface->getPixels()) {
int x = g_system->getOverlayWidth() - surface->w - 10, y = 10;
g_system->copyRectToOSD(surface->getPixels(), surface->pitch, x, y, surface->w, surface->h);
}
}
- if (stop) _showingDisabled = false;
+ if (stop)
+ _showingDisabled = false;
return stop;
}
@@ -103,7 +105,8 @@ void CloudIcon::showDisabled() {
#include "backends/networking/curl/cloudicon_disabled_data.h"
void CloudIcon::initIcons() {
- if (_iconsInited) return;
+ if (_iconsInited)
+ return;
loadIcon(_icon, cloudicon_data, ARRAYSIZE(cloudicon_data));
loadIcon(_disabledIcon, cloudicon_disabled_data, ARRAYSIZE(cloudicon_disabled_data));
_iconsInited = true;
@@ -120,14 +123,18 @@ void CloudIcon::loadIcon(Graphics::TransparentSurface &icon, byte *data, uint32
Graphics::PixelFormat f = g_system->getOSDFormat();
if (f != s->format) {
Graphics::TransparentSurface *s2 = s->convertTo(f);
- if (s2) icon.copyFrom(*s2);
- else warning("CloudIcon::loadIcon: failed converting TransparentSurface");
+ if (s2)
+ icon.copyFrom(*s2);
+ else
+ warning("CloudIcon::loadIcon: failed converting TransparentSurface");
delete s2;
} else {
icon.copyFrom(*s);
}
delete s;
- } else warning("CloudIcon::loadIcon: failed reading TransparentSurface from PNGDecoder");
+ } else {
+ warning("CloudIcon::loadIcon: failed reading TransparentSurface from PNGDecoder");
+ }
}
void CloudIcon::makeAlphaIcon(Graphics::TransparentSurface &icon, float alpha) {
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index cb0e24645e..1d5fd0d0cb 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -50,9 +50,11 @@ ConnectionManager::~ConnectionManager() {
for (Common::Array<RequestWithCallback>::iterator i = _requests.begin(); i != _requests.end(); ++i) {
Request *request = i->request;
RequestCallback callback = i->onDeleteCallback;
- if (request) request->finish();
+ if (request)
+ request->finish();
delete request;
- if (callback) (*callback)(request);
+ if (callback)
+ (*callback)(request);
}
_requests.clear();
@@ -70,7 +72,8 @@ void ConnectionManager::registerEasyHandle(CURL *easy) const {
Request *ConnectionManager::addRequest(Request *request, RequestCallback callback) {
_addedRequestsMutex.lock();
_addedRequests.push_back(RequestWithCallback(request, callback));
- if (!_timerStarted) startTimer();
+ if (!_timerStarted)
+ startTimer();
_addedRequestsMutex.unlock();
return request;
}
@@ -81,7 +84,8 @@ void ConnectionManager::showCloudDisabledIcon() {
}
Common::String ConnectionManager::urlEncode(Common::String s) const {
- if (!_multi) return "";
+ if (!_multi)
+ return "";
char *output = curl_easy_escape(_multi, s.c_str(), s.size());
if (output) {
Common::String result = output;
@@ -128,8 +132,10 @@ void ConnectionManager::handle() {
//lock mutex here (in case another handle() would be called before this one ends)
_handleMutex.lock();
++_frame;
- if (_frame % CLOUD_PERIOD == 0) interateRequests();
- if (_frame % CURL_PERIOD == 0) processTransfers();
+ if (_frame % CLOUD_PERIOD == 0)
+ interateRequests();
+ if (_frame % CURL_PERIOD == 0)
+ processTransfers();
if (_icon.draw() && _requests.empty() && !hasAddedRequests())
stopTimer();
@@ -150,13 +156,16 @@ void ConnectionManager::interateRequests() {
for (Common::Array<RequestWithCallback>::iterator i = _requests.begin(); i != _requests.end();) {
Request *request = i->request;
if (request) {
- if (request->state() == PROCESSING) request->handle();
- else if (request->state() == RETRY) request->handleRetry();
+ if (request->state() == PROCESSING)
+ request->handle();
+ else if (request->state() == RETRY)
+ request->handleRetry();
}
if (!request || request->state() == FINISHED) {
delete (i->request);
- if (i->onDeleteCallback) (*i->onDeleteCallback)(i->request); //that's not a mistake (we're passing an address and that method knows there is no object anymore)
+ if (i->onDeleteCallback)
+ (*i->onDeleteCallback)(i->request); //that's not a mistake (we're passing an address and that method knows there is no object anymore)
_requests.erase(i);
continue;
}
@@ -179,7 +188,8 @@ void ConnectionManager::processTransfers() {
NetworkReadStream *stream;
curl_easy_getinfo(easyHandle, CURLINFO_PRIVATE, &stream);
- if (stream) stream->finished();
+ if (stream)
+ stream->finished();
if (curlMsg->msg == CURLMSG_DONE) {
debug(9, "ConnectionManager: SUCCESS (%d - %s)", curlMsg->data.result, curl_easy_strerror(curlMsg->data.result));
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index 7f7cbca2e0..4d87aa2649 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -49,7 +49,8 @@ char *CurlJsonRequest::getPreparedContents() {
byte *result = _contentsStream.getData();
uint32 size = _contentsStream.size();
for (uint32 i = 0; i < size; ++i) {
- if (result[i] == '\n') result[i] = ' '; //yeah, kinda stupid
+ if (result[i] == '\n')
+ result[i] = ' '; //yeah, kinda stupid
else if (result[i] < 0x20 || result[i] > 0x7f)
result[i] = '.';
}
@@ -85,7 +86,8 @@ void CurlJsonRequest::handle() {
}
void CurlJsonRequest::restart() {
- if (_stream) delete _stream;
+ if (_stream)
+ delete _stream;
_stream = nullptr;
_contentsStream = Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
//with no stream available next handle() will create another one
@@ -93,8 +95,10 @@ void CurlJsonRequest::restart() {
void CurlJsonRequest::finishJson(Common::JSONValue *json) {
Request::finishSuccess();
- if (_jsonCallback) (*_jsonCallback)(JsonResponse(this, json)); //potential memory leak, free it in your callbacks!
- else delete json;
+ if (_jsonCallback)
+ (*_jsonCallback)(JsonResponse(this, json)); //potential memory leak, free it in your callbacks!
+ else
+ delete json;
}
bool CurlJsonRequest::jsonIsObject(Common::JSONValue *item, const char *warningPrefix) {
diff --git a/backends/networking/curl/curlrequest.cpp b/backends/networking/curl/curlrequest.cpp
index 4420b6f524..2d5bb1fa2b 100644
--- a/backends/networking/curl/curlrequest.cpp
+++ b/backends/networking/curl/curlrequest.cpp
@@ -63,7 +63,8 @@ void CurlRequest::handle() {
}
void CurlRequest::restart() {
- if (_stream) delete _stream;
+ if (_stream)
+ delete _stream;
_stream = nullptr;
//with no stream available next handle() will create another one
}
@@ -78,7 +79,8 @@ Common::String CurlRequest::date() const {
Common::String result = "";
char c;
for (const char *i = position + 6; c = *i, c != 0; ++i) {
- if (c == '\n' || c == '\r') break;
+ if (c == '\n' || c == '\r')
+ break;
result += c;
}
return result;
@@ -135,7 +137,8 @@ void CurlRequest::setBuffer(byte *buffer, uint32 size) {
if (_postFields != "")
warning("CurlRequest: added POST fields would be ignored, because buffer added");
- if (_bytesBuffer) delete _bytesBuffer;
+ if (_bytesBuffer)
+ delete _bytesBuffer;
_bytesBuffer = buffer;
_bytesBufferSize = size;
diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp
index 1764a939fd..5c760d9e01 100644
--- a/backends/networking/curl/networkreadstream.cpp
+++ b/backends/networking/curl/networkreadstream.cpp
@@ -31,25 +31,29 @@ namespace Networking {
static size_t curlDataCallback(char *d, size_t n, size_t l, void *p) {
NetworkReadStream *stream = (NetworkReadStream *)p;
- if (stream) return stream->write(d, n * l);
+ if (stream)
+ return stream->write(d, n * l);
return 0;
}
static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p) {
NetworkReadStream *stream = (NetworkReadStream *)p;
- if (stream) return stream->fillWithSendingContents(d, n * l);
+ if (stream)
+ return stream->fillWithSendingContents(d, n * l);
return 0;
}
static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p) {
NetworkReadStream *stream = (NetworkReadStream *)p;
- if (stream) return stream->addResponseHeaders(d, n * l);
+ if (stream)
+ return stream->addResponseHeaders(d, n * l);
return 0;
}
static int curlProgressCallback(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
NetworkReadStream *stream = (NetworkReadStream *)p;
- if (stream) stream->setProgress(dlnow, dltotal);
+ if (stream)
+ stream->setProgress(dlnow, dltotal);
return 0;
}
@@ -171,7 +175,8 @@ uint32 NetworkReadStream::read(void *dataPtr, uint32 dataSize) {
uint32 actuallyRead = MemoryReadWriteStream::read(dataPtr, dataSize);
if (actuallyRead == 0) {
- if (_requestComplete) _eos = true;
+ if (_requestComplete)
+ _eos = true;
return 0;
}
@@ -205,7 +210,8 @@ Common::String NetworkReadStream::responseHeaders() const {
uint32 NetworkReadStream::fillWithSendingContents(char *bufferToFill, uint32 maxSize) {
uint32 size = _sendingContentsSize - _sendingContentsPos;
- if (size > maxSize) size = maxSize;
+ if (size > maxSize)
+ size = maxSize;
for (uint32 i = 0; i < size; ++i) {
bufferToFill[i] = _sendingContentsBuffer[_sendingContentsPos + i];
}
@@ -219,7 +225,8 @@ uint32 NetworkReadStream::addResponseHeaders(char *buffer, uint32 size) {
}
double NetworkReadStream::getProgress() const {
- if (_progressTotal < 1) return 0;
+ if (_progressTotal < 1)
+ return 0;
return (double)_progressDownloaded / (double)_progressTotal;
}
diff --git a/backends/networking/curl/request.cpp b/backends/networking/curl/request.cpp
index 4a2704fc76..30af48a478 100644
--- a/backends/networking/curl/request.cpp
+++ b/backends/networking/curl/request.cpp
@@ -39,8 +39,9 @@ Request::~Request() {
}
void Request::handleRetry() {
- if (_retryInSeconds > 0) --_retryInSeconds;
- else {
+ if (_retryInSeconds > 0) {
+ --_retryInSeconds;
+ } else {
_state = PROCESSING;
restart();
}
@@ -64,7 +65,8 @@ Common::String Request::date() const { return ""; }
void Request::finishError(ErrorResponse error) {
_state = FINISHED;
- if (_errorCallback) (*_errorCallback)(error);
+ if (_errorCallback)
+ (*_errorCallback)(error);
}
void Request::finishSuccess() { _state = FINISHED; }
diff --git a/backends/networking/sdl_net/client.cpp b/backends/networking/sdl_net/client.cpp
index 6cef5ffc93..0026d0e346 100644
--- a/backends/networking/sdl_net/client.cpp
+++ b/backends/networking/sdl_net/client.cpp
@@ -45,15 +45,18 @@ Client::~Client() {
}
void Client::open(SDLNet_SocketSet set, TCPsocket socket) {
- if (_state != INVALID) close();
+ if (_state != INVALID)
+ close();
_state = READING_HEADERS;
_socket = socket;
_set = set;
Reader cleanReader;
_reader = cleanReader;
- if (_handler) delete _handler;
+ if (_handler)
+ delete _handler;
_handler = nullptr;
- if (_previousHandler) delete _previousHandler;
+ if (_previousHandler)
+ delete _previousHandler;
_previousHandler = nullptr;
_stream = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
if (set) {
@@ -65,10 +68,14 @@ void Client::open(SDLNet_SocketSet set, TCPsocket socket) {
}
bool Client::readMoreIfNeeded() {
- if (_stream == nullptr) return false; //nothing to read into
- if (_stream->size() - _stream->pos() > 0) return true; //not needed, some data left in the stream
- if (!_socket) return false;
- if (!SDLNet_SocketReady(_socket)) return false;
+ if (_stream == nullptr)
+ return false; //nothing to read into
+ if (_stream->size() - _stream->pos() > 0)
+ return true; //not needed, some data left in the stream
+ if (!_socket)
+ return false;
+ if (!SDLNet_SocketReady(_socket))
+ return false;
int bytes = SDLNet_TCP_Recv(_socket, _buffer, CLIENT_BUFFER_SIZE);
if (bytes <= 0) {
@@ -87,33 +94,38 @@ bool Client::readMoreIfNeeded() {
}
void Client::readHeaders() {
- if (!readMoreIfNeeded()) return;
+ if (!readMoreIfNeeded())
+ return;
_reader.setContent(_stream);
if (_reader.readFirstHeaders())
_state = (_reader.badRequest() ? BAD_REQUEST : READ_HEADERS);
}
bool Client::readContent(Common::WriteStream *stream) {
- if (!readMoreIfNeeded()) return false;
+ if (!readMoreIfNeeded())
+ return false;
_reader.setContent(_stream);
return _reader.readFirstContent(stream);
}
bool Client::readBlockHeaders(Common::WriteStream *stream) {
- if (!readMoreIfNeeded()) return false;
+ if (!readMoreIfNeeded())
+ return false;
_reader.setContent(_stream);
return _reader.readBlockHeaders(stream);
}
bool Client::readBlockContent(Common::WriteStream *stream) {
- if (!readMoreIfNeeded()) return false;
+ if (!readMoreIfNeeded())
+ return false;
_reader.setContent(_stream);
return _reader.readBlockContent(stream);
}
void Client::setHandler(ClientHandler *handler) {
if (_handler) {
- if (_previousHandler) delete _previousHandler;
+ if (_previousHandler)
+ delete _previousHandler;
_previousHandler = _handler; //can't just delete it, as setHandler() could've been called by handler itself
}
_state = BEING_HANDLED;
@@ -121,9 +133,12 @@ void Client::setHandler(ClientHandler *handler) {
}
void Client::handle() {
- if (_state != BEING_HANDLED) warning("handle() called in a wrong Client's state");
- if (!_handler) warning("Client doesn't have handler to be handled by");
- if (_handler) _handler->handle(this);
+ if (_state != BEING_HANDLED)
+ warning("handle() called in a wrong Client's state");
+ if (!_handler)
+ warning("Client doesn't have handler to be handled by");
+ if (_handler)
+ _handler->handle(this);
}
void Client::close() {
diff --git a/backends/networking/sdl_net/getclienthandler.cpp b/backends/networking/sdl_net/getclienthandler.cpp
index cdbcd96c61..1c4f5db8a8 100644
--- a/backends/networking/sdl_net/getclienthandler.cpp
+++ b/backends/networking/sdl_net/getclienthandler.cpp
@@ -121,15 +121,18 @@ void GetClientHandler::prepareHeaders() {
}
void GetClientHandler::handle(Client *client) {
- if (!client) return;
- if (!_headersPrepared) prepareHeaders();
+ if (!client)
+ return;
+ if (!_headersPrepared)
+ prepareHeaders();
uint32 readBytes;
// send headers first
if (_headers.size() > 0) {
readBytes = _headers.size();
- if (readBytes > CLIENT_HANDLER_BUFFER_SIZE) readBytes = CLIENT_HANDLER_BUFFER_SIZE;
+ if (readBytes > CLIENT_HANDLER_BUFFER_SIZE)
+ readBytes = CLIENT_HANDLER_BUFFER_SIZE;
memcpy(_buffer, _headers.c_str(), readBytes);
_headers.erase(0, readBytes);
} else {
@@ -149,7 +152,8 @@ void GetClientHandler::handle(Client *client) {
}
// we're done here!
- if (_stream->eos()) client->close();
+ if (_stream->eos())
+ client->close();
}
void GetClientHandler::setHeader(Common::String name, Common::String value) { _specialHeaders[name] = value; }
diff --git a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp
index b16827dc58..474ac7465e 100644
--- a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp
+++ b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp
@@ -61,7 +61,8 @@ void CreateDirectoryHandler::handle(Client &client) {
}
// check that <directory_name> doesn't exist or is directory
- if (path.lastChar() != '/' && path.lastChar() != '\\') path += '/';
+ if (path.lastChar() != '/' && path.lastChar() != '\\')
+ path += '/';
node = g_system->getFilesystemFactory()->makeFileNodePath(path + name);
if (node->exists()) {
if (!node->isDirectory()) {
@@ -97,8 +98,10 @@ void CreateDirectoryHandler::handle(Client &client) {
}
void CreateDirectoryHandler::handleError(Client &client, Common::String message) const {
- if (client.queryParameter("answer_json") == "true") setJsonResponseHandler(client, "error", message);
- else HandlerUtils::setFilesManagerErrorMessageHandler(client, message);
+ if (client.queryParameter("answer_json") == "true")
+ setJsonResponseHandler(client, "error", message);
+ else
+ HandlerUtils::setFilesManagerErrorMessageHandler(client, message);
}
void CreateDirectoryHandler::setJsonResponseHandler(Client &client, Common::String type, Common::String message) const {
diff --git a/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp b/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp
index 6cf18aeb79..e0ecae9632 100644
--- a/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp
+++ b/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp
@@ -42,7 +42,9 @@ Common::String encodeDoubleQuotesAndSlashes(Common::String s) {
result += "\\\"";
} else if (s[i] == '\\') {
result += "\\\\";
- } else result += s[i];
+ } else {
+ result += s[i];
+ }
return result;
}
diff --git a/backends/networking/sdl_net/handlers/filesbasehandler.cpp b/backends/networking/sdl_net/handlers/filesbasehandler.cpp
index 9546c5c845..68d7919d4a 100644
--- a/backends/networking/sdl_net/handlers/filesbasehandler.cpp
+++ b/backends/networking/sdl_net/handlers/filesbasehandler.cpp
@@ -40,20 +40,24 @@ Common::String FilesBaseHandler::parentPath(Common::String path) {
break;
}
}
- if (path.size() && path.lastChar() != '/' && path.lastChar() != '\\') path += '/';
+ if (path.size() && path.lastChar() != '/' && path.lastChar() != '\\')
+ path += '/';
return path;
}
bool FilesBaseHandler::transformPath(Common::String &path, Common::String &prefixToRemove, Common::String &prefixToAdd, bool isDirectory) {
// <path> is not empty, but could lack the trailing slash
- if (isDirectory && path.lastChar() != '/' && path.lastChar() != '\\') path += '/';
+ if (isDirectory && path.lastChar() != '/' && path.lastChar() != '\\')
+ path += '/';
if (path.hasPrefix("/root")) {
prefixToAdd = "/root/";
prefixToRemove = "";
path.erase(0, 5);
- if (path == "") path = "/"; // absolute root is '/'
- if (path != "/") path.deleteChar(0); // if that was "/root/ab/c", it becomes "/ab/c", but we need "ab/c"
+ if (path == "")
+ path = "/"; // absolute root is '/'
+ if (path != "/")
+ path.deleteChar(0); // if that was "/root/ab/c", it becomes "/ab/c", but we need "ab/c"
return true;
}
diff --git a/backends/networking/sdl_net/handlers/filespagehandler.cpp b/backends/networking/sdl_net/handlers/filespagehandler.cpp
index d3fa459aeb..abe6f42d8f 100644
--- a/backends/networking/sdl_net/handlers/filespagehandler.cpp
+++ b/backends/networking/sdl_net/handlers/filespagehandler.cpp
@@ -40,17 +40,23 @@ Common::String encodeDoubleQuotes(Common::String s) {
for (uint32 i = 0; i < s.size(); ++i)
if (s[i] == '"') {
result += "\\\"";
- } else result += s[i];
+ } else {
+ result += s[i];
+ }
return result;
}
Common::String encodeHtmlEntities(Common::String s) {
Common::String result = "";
for (uint32 i = 0; i < s.size(); ++i)
- if (s[i] == '<') result += "&lt;";
- else if (s[i] == '>') result += "&gt;";
- else if (s[i] == '&') result += "&amp;";
- else if (s[i] > 0x7F) result += Common::String::format("&#%d;", (int)s[i]);
+ if (s[i] == '<')
+ result += "&lt;";
+ else if (s[i] == '>')
+ result += "&gt;";
+ else if (s[i] == '&')
+ result += "&amp;";
+ else if (s[i] > 0x7F)
+ result += Common::String::format("&#%d;", (int)s[i]);
else result += s[i];
return result;
}
@@ -58,9 +64,12 @@ Common::String encodeHtmlEntities(Common::String s) {
Common::String getDisplayPath(Common::String s) {
Common::String result = "";
for (uint32 i = 0; i < s.size(); ++i)
- if (s[i] == '\\') result += '/';
- else result += s[i];
- if (result == "") return "/";
+ if (s[i] == '\\')
+ result += '/';
+ else
+ result += s[i];
+ if (result == "")
+ return "/";
return result;
}
}
@@ -93,7 +102,8 @@ void FilesPageHandler::handle(Client &client) {
// load stylish response page from the archive
Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME);
- if (stream) response = HandlerUtils::readEverythingFromStream(stream);
+ if (stream)
+ response = HandlerUtils::readEverythingFromStream(stream);
Common::String path = client.queryParameter("path");
Common::String content = "";
@@ -127,11 +137,14 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
}
Common::String prefixToRemove = "", prefixToAdd = "";
- if (!transformPath(path, prefixToRemove, prefixToAdd)) return false;
+ if (!transformPath(path, prefixToRemove, prefixToAdd))
+ return false;
Common::FSNode node = Common::FSNode(path);
- if (path == "/") node = node.getParent(); // absolute root
- if (!node.isDirectory()) return false;
+ if (path == "/")
+ node = node.getParent(); // absolute root
+ if (!node.isDirectory())
+ return false;
// list directory
Common::FSList _nodeContent;
@@ -155,7 +168,8 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
// fill the content
for (Common::FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) {
Common::String name = i->getDisplayName();
- if (i->isDirectory()) name += "/";
+ if (i->isDirectory())
+ name += "/";
Common::String filePath = i->getPath();
if (filePath.hasPrefix(prefixToRemove))
@@ -169,10 +183,14 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten
}
FilesPageHandler::ItemType FilesPageHandler::detectType(bool isDirectory, const Common::String &name) {
- if (isDirectory) return IT_DIRECTORY;
- if (name.hasSuffix(".txt")) return IT_TXT;
- if (name.hasSuffix(".zip")) return IT_ZIP;
- if (name.hasSuffix(".7z")) return IT_7Z;
+ if (isDirectory)
+ return IT_DIRECTORY;
+ if (name.hasSuffix(".txt"))
+ return IT_TXT;
+ if (name.hasSuffix(".zip"))
+ return IT_ZIP;
+ if (name.hasSuffix(".7z"))
+ return IT_7Z;
return IT_UNKNOWN;
}
@@ -180,12 +198,23 @@ void FilesPageHandler::addItem(Common::String &content, const Common::String &it
Common::String item = itemTemplate, icon;
bool isDirectory = (itemType == IT_DIRECTORY || itemType == IT_PARENT_DIRECTORY);
switch (itemType) {
- case IT_DIRECTORY: icon = "dir.png"; break;
- case IT_PARENT_DIRECTORY: icon = "up.png"; break;
- case IT_TXT: icon = "txt.png"; break;
- case IT_ZIP: icon = "zip.png"; break;
- case IT_7Z: icon = "7z.png"; break;
- default: icon = "unk.png";
+ case IT_DIRECTORY:
+ icon = "dir.png";
+ break;
+ case IT_PARENT_DIRECTORY:
+ icon = "up.png";
+ break;
+ case IT_TXT:
+ icon = "txt.png";
+ break;
+ case IT_ZIP:
+ icon = "zip.png";
+ break;
+ case IT_7Z:
+ icon = "7z.png";
+ break;
+ default:
+ icon = "unk.png";
}
replace(item, "{icon}", icon);
replace(item, "{link}", (isDirectory ? "files?path=" : "download?path=") + LocalWebserver::urlEncodeQueryParameterValue(path));
diff --git a/backends/networking/sdl_net/handlers/listajaxhandler.cpp b/backends/networking/sdl_net/handlers/listajaxhandler.cpp
index 2e2e138fd6..de349bd6ef 100644
--- a/backends/networking/sdl_net/handlers/listajaxhandler.cpp
+++ b/backends/networking/sdl_net/handlers/listajaxhandler.cpp
@@ -54,11 +54,14 @@ Common::JSONObject ListAjaxHandler::listDirectory(Common::String path) {
}
Common::String prefixToRemove = "", prefixToAdd = "";
- if (!transformPath(path, prefixToRemove, prefixToAdd)) return errorResult;
+ if (!transformPath(path, prefixToRemove, prefixToAdd))
+ return errorResult;
Common::FSNode node = Common::FSNode(path);
- if (path == "/") node = node.getParent(); // absolute root
- if (!node.isDirectory()) return errorResult;
+ if (path == "/")
+ node = node.getParent(); // absolute root
+ if (!node.isDirectory())
+ return errorResult;
// list directory
Common::FSList _nodeContent;
@@ -97,10 +100,14 @@ Common::JSONObject ListAjaxHandler::listDirectory(Common::String path) {
}
ListAjaxHandler::ItemType ListAjaxHandler::detectType(bool isDirectory, const Common::String &name) {
- if (isDirectory) return IT_DIRECTORY;
- if (name.hasSuffix(".txt")) return IT_TXT;
- if (name.hasSuffix(".zip")) return IT_ZIP;
- if (name.hasSuffix(".7z")) return IT_7Z;
+ if (isDirectory)
+ return IT_DIRECTORY;
+ if (name.hasSuffix(".txt"))
+ return IT_TXT;
+ if (name.hasSuffix(".zip"))
+ return IT_ZIP;
+ if (name.hasSuffix(".7z"))
+ return IT_7Z;
return IT_UNKNOWN;
}
@@ -108,12 +115,23 @@ void ListAjaxHandler::addItem(Common::JSONArray &responseItemsList, ItemType ite
Common::String icon;
bool isDirectory = (itemType == IT_DIRECTORY || itemType == IT_PARENT_DIRECTORY);
switch (itemType) {
- case IT_DIRECTORY: icon = "dir.png"; break;
- case IT_PARENT_DIRECTORY: icon = "up.png"; break;
- case IT_TXT: icon = "txt.png"; break;
- case IT_ZIP: icon = "zip.png"; break;
- case IT_7Z: icon = "7z.png"; break;
- default: icon = "unk.png";
+ case IT_DIRECTORY:
+ icon = "dir.png";
+ break;
+ case IT_PARENT_DIRECTORY:
+ icon = "up.png";
+ break;
+ case IT_TXT:
+ icon = "txt.png";
+ break;
+ case IT_ZIP:
+ icon = "zip.png";
+ break;
+ case IT_7Z:
+ icon = "7z.png";
+ break;
+ default:
+ icon = "unk.png";
}
Common::JSONObject item;
diff --git a/backends/networking/sdl_net/handlers/resourcehandler.cpp b/backends/networking/sdl_net/handlers/resourcehandler.cpp
index 1205c4aa7d..d6c419dd51 100644
--- a/backends/networking/sdl_net/handlers/resourcehandler.cpp
+++ b/backends/networking/sdl_net/handlers/resourcehandler.cpp
@@ -35,11 +35,13 @@ void ResourceHandler::handle(Client &client) {
filename.deleteChar(0);
// if archive hidden file is requested, ignore
- if (filename.size() && filename[0] == '.') return;
+ if (filename.size() && filename[0] == '.')
+ return;
// if file not found, don't set handler either
Common::SeekableReadStream *file = HandlerUtils::getArchiveFile(filename);
- if (file == nullptr) return;
+ if (file == nullptr)
+ return;
LocalWebserver::setClientGetHandler(client, file, 200, LocalWebserver::determineMimeType(filename));
}
diff --git a/backends/networking/sdl_net/handlerutils.cpp b/backends/networking/sdl_net/handlerutils.cpp
index bb6a036bdb..edb1484c16 100644
--- a/backends/networking/sdl_net/handlerutils.cpp
+++ b/backends/networking/sdl_net/handlerutils.cpp
@@ -45,7 +45,8 @@ Common::Archive *HandlerUtils::getZipArchive() {
if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) {
Common::SeekableReadStream *const stream = fileNode.createReadStream();
Common::Archive *zipArchive = Common::makeZipArchive(stream);
- if (zipArchive) return zipArchive;
+ if (zipArchive)
+ return zipArchive;
}
}
@@ -56,7 +57,8 @@ Common::Archive *HandlerUtils::getZipArchive() {
Common::ArchiveMember const &m = **it;
Common::SeekableReadStream *const stream = m.createReadStream();
Common::Archive *zipArchive = Common::makeZipArchive(stream);
- if (zipArchive) return zipArchive;
+ if (zipArchive)
+ return zipArchive;
}
return nullptr;
@@ -77,7 +79,8 @@ Common::SeekableReadStream *HandlerUtils::getArchiveFile(Common::String name) {
Common::Archive *zipArchive = getZipArchive();
if (zipArchive) {
const Common::ArchiveMemberPtr ptr = zipArchive->getMember(name);
- if (ptr.get() == nullptr) return nullptr;
+ if (ptr.get() == nullptr)
+ return nullptr;
result = ptr->createReadStream();
delete zipArchive;
}
@@ -100,11 +103,14 @@ void HandlerUtils::setMessageHandler(Client &client, Common::String message, Com
// load stylish response page from the archive
Common::SeekableReadStream *const stream = getArchiveFile(INDEX_PAGE_NAME);
- if (stream) response = readEverythingFromStream(stream);
+ if (stream)
+ response = readEverythingFromStream(stream);
replace(response, "{message}", message);
- if (redirectTo.empty()) LocalWebserver::setClientGetHandler(client, response);
- else LocalWebserver::setClientRedirectHandler(client, response, redirectTo);
+ if (redirectTo.empty())
+ LocalWebserver::setClientGetHandler(client, response);
+ else
+ LocalWebserver::setClientRedirectHandler(client, response, redirectTo);
}
void HandlerUtils::setFilesManagerErrorMessageHandler(Client &client, Common::String message, Common::String redirectTo) {
diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp
index 9b62bb8637..75dbea0d56 100644
--- a/backends/networking/sdl_net/localwebserver.cpp
+++ b/backends/networking/sdl_net/localwebserver.cpp
@@ -125,7 +125,8 @@ void LocalWebserver::start() {
void LocalWebserver::stop() {
_handleMutex.lock();
- if (_timerStarted) stopTimer();
+ if (_timerStarted)
+ stopTimer();
if (_serverSocket) {
SDLNet_TCP_Close(_serverSocket);
@@ -147,12 +148,14 @@ void LocalWebserver::stop() {
void LocalWebserver::stopOnIdle() { _stopOnIdle = true; }
void LocalWebserver::addPathHandler(Common::String path, ClientHandlerCallback handler) {
- if (_pathHandlers.contains(path)) warning("LocalWebserver::addPathHandler: path already had a handler");
+ if (_pathHandlers.contains(path))
+ warning("LocalWebserver::addPathHandler: path already had a handler");
_pathHandlers[path] = handler;
}
void LocalWebserver::removePathHandler(Common::String path) {
- if (!_pathHandlers.contains(path)) warning("LocalWebserver::removePathHandler: no handler known for this path");
+ if (!_pathHandlers.contains(path))
+ warning("LocalWebserver::removePathHandler: no handler known for this path");
_pathHandlers.erase(path);
}
@@ -181,7 +184,9 @@ void LocalWebserver::handle() {
int numready = SDLNet_CheckSockets(_set, 0);
if (numready == -1) {
error("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
- } else if (numready) acceptClient();
+ } else if (numready) {
+ acceptClient();
+ }
for (uint32 i = 0; i < MAX_CONNECTIONS; ++i)
handleClient(i);
@@ -191,8 +196,10 @@ void LocalWebserver::handle() {
if (_client[i].state() != INVALID)
++_clients;
- if (_clients == 0) ++_idlingFrames;
- else _idlingFrames = 0;
+ if (_clients == 0)
+ ++_idlingFrames;
+ else
+ _idlingFrames = 0;
if (_idlingFrames > FRAMES_PER_SECOND && _stopOnIdle) {
_handleMutex.unlock();
@@ -218,7 +225,8 @@ void LocalWebserver::handleClient(uint32 i) {
else if (_defaultHandler)
(*_defaultHandler)(_client[i]); //try default handler
- if (_client[i].state() == BEING_HANDLED || _client[i].state() == INVALID) break;
+ if (_client[i].state() == BEING_HANDLED || _client[i].state() == INVALID)
+ break;
//if no handler, answer with default BAD REQUEST
//fallthrough
case BAD_REQUEST:
@@ -231,10 +239,12 @@ void LocalWebserver::handleClient(uint32 i) {
}
void LocalWebserver::acceptClient() {
- if (!SDLNet_SocketReady(_serverSocket)) return;
+ if (!SDLNet_SocketReady(_serverSocket))
+ return;
TCPsocket client = SDLNet_TCP_Accept(_serverSocket);
- if (!client) return;
+ if (!client)
+ return;
if (_clients == MAX_CONNECTIONS) { //drop the connection
SDLNet_TCP_Close(client);
@@ -304,15 +314,16 @@ void LocalWebserver::resolveAddress(void *ipAddress) {
// IPv6
/*
if (i->ifa_addr->sa_family == AF_INET6) {
- tmpAddrPtr = &((struct sockaddr_in6 *)i->ifa_addr)->sin6_addr;
- char addressBuffer[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
- debug("%s IP Address %s", i->ifa_name, addressBuffer);
- addr = addressBuffer;
+ tmpAddrPtr = &((struct sockaddr_in6 *)i->ifa_addr)->sin6_addr;
+ char addressBuffer[INET6_ADDRSTRLEN];
+ inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
+ debug("%s IP Address %s", i->ifa_name, addressBuffer);
+ addr = addressBuffer;
}
*/
- if (addr.empty()) continue;
+ if (addr.empty())
+ continue;
// ignored IPv4 addresses
if (addr.equals("127.0.0.1") || addr.equals("0.0.0.0") || addr.equals("localhost"))
@@ -321,7 +332,7 @@ void LocalWebserver::resolveAddress(void *ipAddress) {
// ignored IPv6 addresses
/*
if (addr.equals("::1"))
- continue;
+ continue;
*/
// use the address found
@@ -342,7 +353,8 @@ void LocalWebserver::setClientGetHandler(Client &client, Common::String response
void LocalWebserver::setClientGetHandler(Client &client, Common::SeekableReadStream *responseStream, long code, const char *mimeType) {
GetClientHandler *handler = new GetClientHandler(responseStream);
handler->setResponseCode(code);
- if (mimeType) handler->setHeader("Content-Type", mimeType);
+ if (mimeType)
+ handler->setHeader("Content-Type", mimeType);
client.setHandler(handler);
}
@@ -357,7 +369,8 @@ void LocalWebserver::setClientRedirectHandler(Client &client, Common::SeekableRe
GetClientHandler *handler = new GetClientHandler(responseStream);
handler->setResponseCode(302); //redirect
handler->setHeader("Location", location);
- if (mimeType) handler->setHeader("Content-Type", mimeType);
+ if (mimeType)
+ handler->setHeader("Content-Type", mimeType);
client.setHandler(handler);
}
diff --git a/backends/networking/sdl_net/reader.cpp b/backends/networking/sdl_net/reader.cpp
index 66efeec8cc..828f583003 100644
--- a/backends/networking/sdl_net/reader.cpp
+++ b/backends/networking/sdl_net/reader.cpp
@@ -51,7 +51,8 @@ Reader::~Reader() {
}
Reader &Reader::operator=(Reader &r) {
- if (this == &r) return *this;
+ if (this == &r)
+ return *this;
cleanup();
_state = r._state;
@@ -83,7 +84,8 @@ Reader &Reader::operator=(Reader &r) {
void Reader::cleanup() {
//_content is not to be freed, it's not owned by Reader
- if (_window != nullptr) freeWindow();
+ if (_window != nullptr)
+ freeWindow();
}
bool Reader::readAndHandleFirstHeaders() {
@@ -94,7 +96,8 @@ bool Reader::readAndHandleFirstHeaders() {
}
while (readOneByteInString(_headers, boundary)) {
- if (!bytesLeft()) return false;
+ if (!bytesLeft())
+ return false;
}
handleFirstHeaders(_headers);
@@ -108,7 +111,8 @@ bool Reader::readBlockHeadersIntoStream(Common::WriteStream *stream) {
if (_window == nullptr) makeWindow(boundary.size());
while (readOneByteInStream(stream, boundary)) {
- if (!bytesLeft()) return false;
+ if (!bytesLeft())
+ return false;
}
if (stream) stream->flush();
@@ -124,7 +128,8 @@ void readFromThatUntilLineEnd(const char *cstr, Common::String needle, Common::S
if (position) {
char c;
for (const char *i = position + needle.size(); c = *i, c != 0; ++i) {
- if (c == '\n' || c == '\r') break;
+ if (c == '\n' || c == '\r')
+ break;
result += c;
}
}
@@ -166,14 +171,19 @@ void Reader::parseFirstLine(const Common::String &headers) {
//"<METHOD> <path> HTTP/<VERSION>\r\n"
Common::String method, path, http, buf;
uint32 length = position - cstr;
- if (headersSize > length) headersSize = length;
+ if (headersSize > length)
+ headersSize = length;
for (uint32 i = 0; i < headersSize; ++i) {
- if (headers[i] != ' ') buf += headers[i];
+ if (headers[i] != ' ')
+ buf += headers[i];
if (headers[i] == ' ' || i == headersSize - 1) {
- if (method == "") method = buf;
- else if (path == "") path = buf;
- else if (http == "") http = buf;
- else {
+ if (method == "") {
+ method = buf;
+ } else if (path == "") {
+ path = buf;
+ } else if (http == "") {
+ http = buf;
+ } else {
bad = true;
break;
}
@@ -182,10 +192,12 @@ void Reader::parseFirstLine(const Common::String &headers) {
}
//check that method is supported
- if (method != "GET" && method != "PUT" && method != "POST") bad = true;
+ if (method != "GET" && method != "PUT" && method != "POST")
+ bad = true;
//check that HTTP/<VERSION> is OK
- if (!http.hasPrefix("HTTP/")) bad = true;
+ if (!http.hasPrefix("HTTP/"))
+ bad = true;
_method = method;
parsePathQueryAndAnchor(path);
@@ -208,12 +220,18 @@ void Reader::parsePathQueryAndAnchor(Common::String path) {
if (path[i] == '?') {
readingPath = false;
readingQuery = true;
- } else _path += path[i];
+ } else {
+ _path += path[i];
+ }
} else if (readingQuery) {
if (path[i] == '#') {
readingQuery = false;
- } else _query += path[i];
- } else _anchor += path[i];
+ } else {
+ _query += path[i];
+ }
+ } else {
+ _anchor += path[i];
+ }
}
parseQueryParameters();
@@ -228,35 +246,48 @@ void Reader::parseQueryParameters() {
if (_query[i] == '=') {
readingKey = false;
value = "";
- } else key += _query[i];
+ } else {
+ key += _query[i];
+ }
} else {
if (_query[i] == '&') {
- if (_queryParameters.contains(key)) warning("Query parameter \"%s\" is already set!", key.c_str());
- else _queryParameters[key] = LocalWebserver::urlDecode(value);
+ if (_queryParameters.contains(key))
+ warning("Query parameter \"%s\" is already set!", key.c_str());
+ else
+ _queryParameters[key] = LocalWebserver::urlDecode(value);
readingKey = true;
key = "";
- } else value += _query[i];
+ } else {
+ value += _query[i];
+ }
}
}
if (!key.empty()) {
- if (_queryParameters.contains(key)) warning("Query parameter \"%s\" is already set!", key.c_str());
- else _queryParameters[key] = LocalWebserver::urlDecode(value);
+ if (_queryParameters.contains(key))
+ warning("Query parameter \"%s\" is already set!", key.c_str());
+ else
+ _queryParameters[key] = LocalWebserver::urlDecode(value);
}
}
bool Reader::readContentIntoStream(Common::WriteStream *stream) {
Common::String boundary = "--" + _boundary;
- if (!_firstBlock) boundary = "\r\n" + boundary;
- if (_boundary.empty()) boundary = "\r\n";
- if (_window == nullptr) makeWindow(boundary.size());
+ if (!_firstBlock)
+ boundary = "\r\n" + boundary;
+ if (_boundary.empty())
+ boundary = "\r\n";
+ if (_window == nullptr)
+ makeWindow(boundary.size());
while (readOneByteInStream(stream, boundary)) {
- if (!bytesLeft()) return false;
+ if (!bytesLeft())
+ return false;
}
_firstBlock = false;
- if (stream) stream->flush();
+ if (stream)
+ stream->flush();
freeWindow();
_state = RS_READING_HEADERS;
@@ -280,14 +311,16 @@ void Reader::freeWindow() {
bool Reader::readOneByteInStream(Common::WriteStream *stream, const Common::String &boundary) {
byte b = readOne();
_window[_windowUsed++] = b;
- if (_windowUsed < _windowSize) return true;
+ if (_windowUsed < _windowSize)
+ return true;
//when window is filled, check whether that's the boundary
if (Common::String((char *)_window, _windowSize) == boundary)
return false;
//if not, add the first byte of the window to the string
- if (stream) stream->writeByte(_window[0]);
+ if (stream)
+ stream->writeByte(_window[0]);
for (uint32 i = 1; i < _windowSize; ++i)
_window[i - 1] = _window[i];
--_windowUsed;
@@ -297,7 +330,8 @@ bool Reader::readOneByteInStream(Common::WriteStream *stream, const Common::Stri
bool Reader::readOneByteInString(Common::String &buffer, const Common::String &boundary) {
byte b = readOne();
_window[_windowUsed++] = b;
- if (_windowUsed < _windowSize) return true;
+ if (_windowUsed < _windowSize)
+ return true;
//when window is filled, check whether that's the boundary
if (Common::String((char *)_window, _windowSize) == boundary)
@@ -322,9 +356,11 @@ byte Reader::readOne() {
/// public
bool Reader::readFirstHeaders() {
- if (_state == RS_NONE) _state = RS_READING_HEADERS;
+ if (_state == RS_NONE)
+ _state = RS_READING_HEADERS;
- if (!bytesLeft()) return false;
+ if (!bytesLeft())
+ return false;
if (_state == RS_READING_HEADERS)
return readAndHandleFirstHeaders();
@@ -349,7 +385,8 @@ bool Reader::readBlockHeaders(Common::WriteStream *stream) {
return false;
}
- if (!bytesLeft()) return false;
+ if (!bytesLeft())
+ return false;
return readBlockHeadersIntoStream(stream);
}
@@ -360,7 +397,8 @@ bool Reader::readBlockContent(Common::WriteStream *stream) {
return false;
}
- if (!bytesLeft()) return false;
+ if (!bytesLeft())
+ return false;
if (!readContentIntoStream(stream))
return false;
@@ -369,7 +407,8 @@ bool Reader::readBlockContent(Common::WriteStream *stream) {
Common::String bts;
bts += readOne();
bts += readOne();
- if (bts == "--") _allContentRead = true;
+ if (bts == "--")
+ _allContentRead = true;
else if (bts != "\r\n")
warning("strange bytes: \"%s\"", bts.c_str());
} else {
diff --git a/backends/networking/sdl_net/uploadfileclienthandler.cpp b/backends/networking/sdl_net/uploadfileclienthandler.cpp
index 3c51c558a2..048ff39810 100644
--- a/backends/networking/sdl_net/uploadfileclienthandler.cpp
+++ b/backends/networking/sdl_net/uploadfileclienthandler.cpp
@@ -89,7 +89,8 @@ void readFromThatUntilDoubleQuote(const char *cstr, Common::String needle, Commo
if (position) {
char c;
for (const char *i = position + needle.size(); c = *i, c != 0; ++i) {
- if (c == '"') break;
+ if (c == '"')
+ break;
result += c;
}
}
@@ -101,7 +102,8 @@ Common::String readEverythingFromMemoryStream(Common::MemoryReadWriteStream *str
uint32 readBytes;
while (true) {
readBytes = stream->read(buf, 1024);
- if (readBytes == 0) break;
+ if (readBytes == 0)
+ break;
result += Common::String(buf, readBytes);
}
return result;
@@ -115,17 +117,20 @@ void UploadFileClientHandler::handleBlockHeaders(Client *client) {
Common::String headers = readEverythingFromMemoryStream(_headersStream);
Common::String fieldName = "";
readFromThatUntilDoubleQuote(headers.c_str(), "name=\"", fieldName);
- if (!fieldName.hasPrefix("upload_file")) return;
+ if (!fieldName.hasPrefix("upload_file"))
+ return;
Common::String filename = "";
readFromThatUntilDoubleQuote(headers.c_str(), "filename=\"", filename);
// skip block if <filename> is empty
- if (filename.empty()) return;
+ if (filename.empty())
+ return;
// check that <path>/<filename> doesn't exist
Common::String path = _parentDirectoryPath;
- if (path.lastChar() != '/' && path.lastChar() != '\\') path += '/';
+ if (path.lastChar() != '/' && path.lastChar() != '\\')
+ path += '/';
AbstractFSNode *originalNode = g_system->getFilesystemFactory()->makeFileNodePath(path + filename);
if (originalNode->exists()) {
setErrorMessageHandler(*client, _("There is a file with that name in the parent directory!"));
@@ -174,7 +179,9 @@ void UploadFileClientHandler::handleBlockContent(Client *client) {
// if no file field was found - failure
if (_uploadedFiles == 0) {
setErrorMessageHandler(*client, _("No file was passed!"));
- } else _state = UFH_STOP;
+ } else {
+ _state = UFH_STOP;
+ }
return;
}
}