CLOUD: Fix redirect_uri selection code

Now it's not hardcoded based on USE_SDL_NET, but one or another value is
used depending on currently selected LocalWebserver's port.
This commit is contained in:
Alexander Tkachev 2016-07-21 12:06:00 +06:00
parent 438ba985a4
commit 772d8ee42b
9 changed files with 39 additions and 36 deletions

View file

@ -88,11 +88,11 @@ void BoxStorage::getAccessToken(BoolCallback callback, Networking::ErrorCallback
request->addPostField("client_id=" + Common::String(KEY)); request->addPostField("client_id=" + Common::String(KEY));
request->addPostField("client_secret=" + Common::String(SECRET)); request->addPostField("client_secret=" + Common::String(SECRET));
/* /*
#ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) {
request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345"); request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345");
#else } else {
request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code"); request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
#endif }
*/ */
addRequest(request); addRequest(request);
} }

View file

@ -28,6 +28,9 @@
#include "common/translation.h" #include "common/translation.h"
#include "common/config-manager.h" #include "common/config-manager.h"
#include "common/str.h" #include "common/str.h"
#ifdef USE_SDL_NET
#include "backends/networking/sdl_net/localwebserver.h"
#endif
namespace Common { namespace Common {
@ -296,6 +299,14 @@ bool CloudManager::isWorking() const {
return false; return false;
} }
bool CloudManager::couldUseLocalServer() {
#ifdef USE_SDL_NET
return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT;
#else
return false;
#endif
}
///// SavesSyncRequest-related ///// ///// SavesSyncRequest-related /////
bool CloudManager::isSyncing() const { bool CloudManager::isSyncing() const {

View file

@ -207,6 +207,9 @@ public:
/** Returns whether there are any requests running. */ /** Returns whether there are any requests running. */
bool isWorking() const; bool isWorking() const;
/** Returns whether LocalWebserver is available to use for auth. */
static bool couldUseLocalServer();
///// SavesSyncRequest-related ///// ///// SavesSyncRequest-related /////
/** Returns whether there is a SavesSyncRequest running. */ /** Returns whether there is a SavesSyncRequest running. */

View file

@ -69,11 +69,11 @@ void DropboxStorage::getAccessToken(Common::String code) {
request->addPostField("grant_type=authorization_code"); request->addPostField("grant_type=authorization_code");
request->addPostField("client_id=" + Common::String(KEY)); request->addPostField("client_id=" + Common::String(KEY));
request->addPostField("client_secret=" + Common::String(SECRET)); request->addPostField("client_secret=" + Common::String(SECRET));
#ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) {
request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F"); request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F");
#else } else {
request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code"); request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
#endif }
addRequest(request); addRequest(request);
} }

View file

@ -87,11 +87,11 @@ void GoogleDriveStorage::getAccessToken(BoolCallback callback, Networking::Error
} }
request->addPostField("client_id=" + Common::String(KEY)); request->addPostField("client_id=" + Common::String(KEY));
request->addPostField("client_secret=" + Common::String(SECRET)); request->addPostField("client_secret=" + Common::String(SECRET));
#ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) {
request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345"); request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345");
#else } else {
request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code"); request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
#endif }
addRequest(request); addRequest(request);
} }

View file

@ -88,11 +88,11 @@ void OneDriveStorage::getAccessToken(BoolCallback callback, Networking::ErrorCal
} }
request->addPostField("client_id=" + Common::String(KEY)); request->addPostField("client_id=" + Common::String(KEY));
request->addPostField("client_secret=" + Common::String(SECRET)); request->addPostField("client_secret=" + Common::String(SECRET));
#ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) {
request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F"); request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F");
#else } else {
request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code"); request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
#endif }
addRequest(request); addRequest(request);
} }

View file

@ -1320,7 +1320,7 @@ GlobalOptionsDialog::GlobalOptionsDialog(LauncherDialog *launcher)
_serverInfoLabel = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerInfoLabel", _("Not running")); _serverInfoLabel = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerInfoLabel", _("Not running"));
uint32 port = Networking::LocalWebserver::getPort(); uint32 port = Networking::LocalWebserver::getPort();
_serverPortDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortDesc", _("Server's port:"), _("Which port is used by server")); _serverPortDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortDesc", _("Server's port:"), _("Which port is used by server\nAuth with server is not available with non-default port"));
_serverPort = new EditTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortEditText", Common::String::format("%u", port), 0); _serverPort = new EditTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortEditText", Common::String::format("%u", port), 0);
_serverPortClearButton = addClearButton(container, "GlobalOptions_Cloud_Container.ServerPortClearButton", kServerPortClearCmd); _serverPortClearButton = addClearButton(container, "GlobalOptions_Cloud_Container.ServerPortClearButton", kServerPortClearCmd);

View file

@ -61,7 +61,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId):
new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd);
_connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd);
if (couldUseLocalServer()) { if (Cloud::CloudManager::couldUseLocalServer()) {
// hide fields and even the button if local webserver is on // hide fields and even the button if local webserver is on
returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); returnLine1->setLabel(_s("You would be navigated to ScummVM's page"));
returnLine2->setLabel(_s("when you'd allow it to use your storage.")); returnLine2->setLabel(_s("when you'd allow it to use your storage."));
@ -97,7 +97,7 @@ void StorageWizardDialog::open() {
} }
} }
if (couldUseLocalServer()) { if (Cloud::CloudManager::couldUseLocalServer()) {
_stopServerOnClose = !LocalServer.isRunning(); _stopServerOnClose = !LocalServer.isRunning();
LocalServer.start(); LocalServer.start();
LocalServer.indexPageHandler().setTarget(this); LocalServer.indexPageHandler().setTarget(this);
@ -105,7 +105,7 @@ void StorageWizardDialog::open() {
} }
void StorageWizardDialog::close() { void StorageWizardDialog::close() {
if (couldUseLocalServer()) { if (Cloud::CloudManager::couldUseLocalServer()) {
if (_stopServerOnClose) LocalServer.stopOnIdle(); if (_stopServerOnClose) LocalServer.stopOnIdle();
LocalServer.indexPageHandler().setTarget(nullptr); LocalServer.indexPageHandler().setTarget(nullptr);
} }
@ -209,18 +209,10 @@ Common::String StorageWizardDialog::getUrl() const {
case Cloud::kStorageBoxId: url += "bx"; break; case Cloud::kStorageBoxId: url += "bx"; break;
} }
if (couldUseLocalServer()) url += "s"; if (Cloud::CloudManager::couldUseLocalServer()) url += "s";
return url; return url;
} }
bool StorageWizardDialog::couldUseLocalServer() const {
#ifdef USE_SDL_NET
return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT;
#else
return false;
#endif
}
int StorageWizardDialog::decodeHashchar(char c) { int StorageWizardDialog::decodeHashchar(char c) {
const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!";
for (uint32 i = 0; i < 64; ++i) for (uint32 i = 0; i < 64; ++i)

View file

@ -51,9 +51,6 @@ class StorageWizardDialog : public Dialog {
/** Return short scummvm.org URL for user to navigate to. */ /** Return short scummvm.org URL for user to navigate to. */
Common::String getUrl() const; Common::String getUrl() const;
/** Return whether fields should be used or not. */
bool couldUseLocalServer() const;
/** /**
* Return the value corresponding to the given character. * Return the value corresponding to the given character.
* *