Handle hostname of remote 53/23353/1 8.99.4 8.99.5 icefish/8.99.4 icefish/8.99.5 icefish_8.99.4 icefish_8.99.5
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 13 Dec 2019 11:24:39 +0000 (12:24 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 13 Dec 2019 11:24:39 +0000 (12:24 +0100)
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: I13ef507b071bd75bc781d8abe8203da0beac1d7f
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
include/libhomescreen.hpp
src/libhomescreen.cpp

index e51e01c..417ccdc 100644 (file)
@@ -58,6 +58,7 @@ public:
        static const std::vector<std::string> event_list;
 
        /* Method */
+       int init(const char *hostname, const int port, const char *token);
        int init(const int port, const std::string& token);
 
        int tapShortcut(const char* application_id);
@@ -86,6 +87,7 @@ public:
 
 private:
        int initialize_websocket();
+       int initialize_websocket(const char *hostname, const int port, const char *token);
 
        void (*onEvent)(const std::string& event, struct json_object* event_contents);
        void (*onReply)(struct json_object* reply);
@@ -96,9 +98,6 @@ private:
        sd_event* mploop;
        std::string muri;
 
-       int mport = 2000;
-       std::string mtoken = "hs";
-
        std::map<EventType, handler_func> handlers;
 
 public:
index ad18ca4..dd5d363 100644 (file)
@@ -123,8 +123,9 @@ LibHomeScreen::~LibHomeScreen()
  * This function is initializer
  *
  * #### Parameters
- * - port  [in] : This argument should be specified to the port number to be used for websocket
- * - token [in] : This argument should be specified to the token to be used for websocket
+ * - hostname [in] : This argument should be specified to the hostname to be used for websocket
+ * - port     [in] : This argument should be specified to the port number to be used for websocket
+ * - token    [in] : This argument should be specified to the token to be used for websocket
  *
  * #### Return
  * Nothing
@@ -133,20 +134,16 @@ LibHomeScreen::~LibHomeScreen()
  * Use this constructor
  *
  */
-int LibHomeScreen::init(const int port, const string& token)
+int LibHomeScreen::init(const char *hostname, const int port, const char *token)
 {
        int ret = 0;
-       if(port > 0 && token.size() > 0)
-       {
-               mport = port;
-               mtoken = token;
-       }
-       else
+       if(port < 0 || token == nullptr || token[0] == 0)
        {
                HMI_ERROR("libhomescreen","port and token should be > 0, Initial port and token uses.");
        }
 
-       ret = initialize_websocket();
+       ret = initialize_websocket(hostname, port, token);
+
        if(ret != 0 )
        {
                HMI_ERROR("libhomescreen","Failed to initialize websocket");
@@ -158,6 +155,25 @@ int LibHomeScreen::init(const int port, const string& token)
        return ret;
 }
 
+/**
+ * This function is initializer
+ *
+ * #### Parameters
+ * - port  [in] : This argument should be specified to the port number to be used for websocket
+ * - token [in] : This argument should be specified to the token to be used for websocket
+ *
+ * #### Return
+ * Nothing
+ *
+ * #### Note
+ * Use this constructor
+ *
+ */
+int LibHomeScreen::init(const int port, const string& token)
+{
+       return init(nullptr, port, token.c_str());
+}
+
 /**
  * This function register callback function for reply/event message from home screen
  *
@@ -187,6 +203,7 @@ int LibHomeScreen::initialize_websocket()
        mploop = NULL;
        onEvent = nullptr;
        onReply = nullptr;
+
        int ret = sd_event_new(&mploop);
        if(ret < 0)
        {
@@ -204,7 +221,7 @@ int LibHomeScreen::initialize_websocket()
        minterface.on_hangup = _on_hangup_static;
        minterface.on_call = _on_call_static;
        minterface.on_event = _on_event_static;
-       muri += "ws://localhost:" + to_string(mport) + "/api?token=" + mtoken; /*To be modified*/
+
        sp_websock = afb_ws_client_connect_wsj1(mploop, muri.c_str(), &minterface, this);
        if(sp_websock == NULL)
        {
@@ -220,6 +237,16 @@ END:
        return -1;
 }
 
+int LibHomeScreen::initialize_websocket(const char *hostname, const int port, const char *token)
+{
+       if (hostname == nullptr)
+               hostname = "localhost";
+       muri = std::string("ws://") + hostname + ":" + to_string(port) + "/api?token=" + token; /*To be modified*/
+
+       return initialize_websocket();
+}
+
+
 /**
  * Sending ShortCut Icon tapped event
  *