From 949e8b8c90dfb37988b542df171c39941aee7bcb Mon Sep 17 00:00:00 2001 From: José Bollo Date: Fri, 13 Dec 2019 12:21:55 +0100 Subject: Handle hostname of remote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to separate applications for cookies and private data the framework uses the component nss-localuser to forge specific hostnames. This commit takes it into account by allowing to specify the hostname to contact at init. Bug-AGL: SPEC-3014 Change-Id: Iabf4a5604dae2c5c5279bc0f45ccfbf3526164d5 Signed-off-by: José Bollo --- src/libwindowmanager.cpp | 24 ++++++++++++------------ src/libwindowmanager.h | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp index 65684f1..8dae9c0 100644 --- a/src/libwindowmanager.cpp +++ b/src/libwindowmanager.cpp @@ -55,7 +55,7 @@ class LibWindowmanager::Impl { ~Impl(); // This is the LibWindowmanager interface impl - int init(int port, char const *token); + int init(const char *hostname, int port, char const *token); // WM API int requestSurface(json_object *object); @@ -186,7 +186,7 @@ LibWindowmanager::Impl::~Impl() { sd_event_unref(loop); } -int LibWindowmanager::Impl::init(int port, char const *token) { +int LibWindowmanager::Impl::init(const char *hostname, int port, char const *token) { TRACE(); HMI_DEBUG("libwm", "called"); @@ -219,7 +219,9 @@ int LibWindowmanager::Impl::init(int port, char const *token) { goto fail; } - asprintf(&uribuf, "ws://localhost:%d/api?token=%s", port, token); + if (hostname == nullptr) + hostname = "localhost"; + asprintf(&uribuf, "ws://%s:%d/api?token=%s", hostname, port, token); /* connect the websocket wsj1 to the uri given by the first argument */ this->wsj1 = afb_ws_client_connect_wsj1( @@ -952,8 +954,8 @@ int LibWindowmanager::Impl::runEventLoop() { /** * @class LibWindowmanager */ -int LibWindowmanager::init(int port, char const *token) { - int ret = this->d->init(port, token); +int LibWindowmanager::init(char const *hostname, int port, char const *token) { + int ret = this->d->init(hostname, port, token); if(ret == 0) { json_object* j = json_object_new_object(); ret = this->getDisplayInfo(j); // return 0 if success @@ -962,14 +964,12 @@ int LibWindowmanager::init(int port, char const *token) { return ret; } +int LibWindowmanager::init(int port, char const *token) { + return init(nullptr, port, token); +} + int LibWindowmanager::init(int port, const std::string &token) { - int ret = this->d->init(port, token.c_str()); - if(ret == 0) { - json_object* j = json_object_new_object(); - ret = this->getDisplayInfo(j); // return 0 if success - json_object_put(j); - } - return ret; + return init(nullptr, port, token.c_str()); } int LibWindowmanager::requestSurface(json_object *object) { diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h index c9da4ca..01d889f 100644 --- a/src/libwindowmanager.h +++ b/src/libwindowmanager.h @@ -128,6 +128,7 @@ public: Event_Val_Max = Event_Error }; + int init(char const *hostname, int port, char const *token); int init(int port, char const *token); int init(int port, const std::string &token); -- cgit 1.2.3-korg