Skip to content

Commit

Permalink
Enable UI to use HTTP connection
Browse files Browse the repository at this point in the history
Re ECFLOW-1957
  • Loading branch information
marcosbento committed Sep 24, 2024
1 parent 7839841 commit bb21a5e
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 27 deletions.
21 changes: 19 additions & 2 deletions Viewer/ecflowUI/src/ServerAddDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>294</width>
<height>225</height>
<height>315</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -101,7 +101,24 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Use &amp;HTTP:</string>
</property>
<property name="buddy">
<cstring>httpCb</cstring>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="httpCb">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="MessageLabel" name="sslMessageLabel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
Expand All @@ -111,7 +128,7 @@
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand Down
17 changes: 17 additions & 0 deletions Viewer/ecflowUI/src/ServerEditDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,24 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="httpLabel">
<property name="text">
<string>Use &amp;HTTP:</string>
</property>
<property name="buddy">
<cstring>httpCh</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="httpCh">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="MessageLabel" name="sslMessageLabel" native="true"/>
</item>
</layout>
Expand Down
31 changes: 28 additions & 3 deletions Viewer/ecflowUI/src/ServerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ ServerHandler::ServerHandler(const std::string& name,
const std::string& host,
const std::string& port,
const std::string& user,
bool ssl)
bool ssl,
bool http)
: name_(name),
host_(host),
port_(port),
user_(user),
ssl_(ssl),
http_(http),
client_(nullptr),
updating_(false),
communicating_(false),
Expand Down Expand Up @@ -184,6 +186,8 @@ void ServerHandler::createClient(bool init) {

bool ssl_enabled = false;
std::string ssl_error;
bool http_enabled = false;
std::string http_error;

if (client_) {
#ifdef ECF_OPENSSL
Expand All @@ -203,6 +207,15 @@ void ServerHandler::createClient(bool init) {
client_->disable_ssl();
}
#endif
if (http_) {
try {
client_->enable_http();
http_enabled = true;
}
catch (std::exception& e) {
http_error = std::string(e.what());
}
}

if (!init || !user_.empty()) {
try {
Expand Down Expand Up @@ -315,6 +328,17 @@ void ServerHandler::setSsl(bool ssl) {
}
}

void ServerHandler::setHttp(bool http) {
if (http != http_) {
http_ = http;

if (connectState_->state() != ConnectState::VersionIncompatible &&
connectState_->state() != ConnectState::FailedClient) {
recreateClient();
}
}
}

void ServerHandler::setUser(const std::string& user) {
if (user != user_) {
user_ = user;
Expand Down Expand Up @@ -528,8 +552,9 @@ ServerHandler* ServerHandler::addServer(const std::string& name,
const std::string& host,
const std::string& port,
const std::string& user,
bool ssl) {
auto* sh = new ServerHandler(name, host, port, user, ssl);
bool ssl,
bool http) {
auto* sh = new ServerHandler(name, host, port, user, ssl, http);
return sh;
}

Expand Down
9 changes: 7 additions & 2 deletions Viewer/ecflowUI/src/ServerHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class ServerHandler : public QObject {
const std::string& fullLongName() const { return fullLongName_; }
const std::string& port() const { return port_; }
bool isSsl() const { return ssl_; }
bool isHttp() const { return http_; }
const std::string& user() { return user_; }
void setSsl(bool);
void setHttp(bool);
void setUser(const std::string& user);

Activity activity() const { return activity_; }
Expand Down Expand Up @@ -118,7 +120,8 @@ class ServerHandler : public QObject {
const std::string& host,
const std::string& port,
const std::string& user,
bool ssl);
bool ssl,
bool http);
static void removeServer(ServerHandler*);
static ServerHandler* findServer(const std::string& alias);

Expand All @@ -142,7 +145,8 @@ class ServerHandler : public QObject {
const std::string& host,
const std::string& port,
const std::string& user,
bool ssl);
bool ssl,
bool http);
~ServerHandler() override;
void logoutAndDelete();
void queueLoggedOut();
Expand All @@ -167,6 +171,7 @@ class ServerHandler : public QObject {
std::string port_;
std::string user_;
bool ssl_;
bool http_;
ClientInvoker* client_;
std::string longName_;
std::string fullLongName_;
Expand Down
17 changes: 14 additions & 3 deletions Viewer/ecflowUI/src/ServerItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ ServerItem::ServerItem(const std::string& name,
const std::string& port,
const std::string& user,
bool favourite,
bool ssl)
bool ssl,
bool http)
: name_(name),
host_(host),
port_(port),
user_(user),
favourite_(favourite),
ssl_(ssl) {
ssl_(ssl),
http_(http) {
}

ServerItem::~ServerItem() {
Expand Down Expand Up @@ -94,6 +96,15 @@ void ServerItem::setSsl(bool b) {
// broadcastChanged();
}

void ServerItem::setHttp(bool b) {
if (http_ != b) {
http_ = b;
if (handler_)
handler_->setHttp(http_);
}
// broadcastChanged();
}

void ServerItem::setUser(const std::string& user) {
if (user_ != user) {
user_ = user;
Expand All @@ -114,7 +125,7 @@ std::string ServerItem::longName() const {

void ServerItem::registerUsageBegin() {
if (!handler_) {
handler_ = ServerHandler::addServer(name_, host_, port_, user_, ssl_);
handler_ = ServerHandler::addServer(name_, host_, port_, user_, ssl_, http_);
}
if (handler_)
useCnt_++;
Expand Down
6 changes: 5 additions & 1 deletion Viewer/ecflowUI/src/ServerItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ServerItem {
bool isFavourite() const { return favourite_; }
bool isSystem() const { return system_; }
bool isSsl() const { return ssl_; }
bool isHttp() const { return http_; }

bool isUsed() const;
int useCnt() const { return useCnt_; }
Expand All @@ -56,7 +57,8 @@ class ServerItem {
const std::string& port,
const std::string& user,
bool favourite,
bool ssl);
bool ssl,
bool http);
~ServerItem();

void name(const std::string& name) { name_ = name; }
Expand All @@ -67,6 +69,7 @@ class ServerItem {
void setFavourite(bool b);
void setSystem(bool b);
void setSsl(bool b);
void setHttp(bool b);
void setUser(const std::string&);

void registerUsageBegin();
Expand All @@ -82,6 +85,7 @@ class ServerItem {
bool favourite_{false};
bool system_{false};
bool ssl_{false};
bool http_{false};
int useCnt_{0};
ServerHandler* handler_{nullptr};

Expand Down
24 changes: 16 additions & 8 deletions Viewer/ecflowUI/src/ServerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,15 @@ ServerItem* ServerList::add(const std::string& name,
const std::string& user,
bool favourite,
bool ssl,
bool http,
bool saveIt) {
std::string errStr;
if (!checkItemToAdd(name, host, port, true, errStr)) {
throw std::runtime_error(errStr);
return nullptr;
}

auto* item = new ServerItem(name, host, port, user, favourite, ssl);
auto* item = new ServerItem(name, host, port, user, favourite, ssl, http);

items_.push_back(item);

Expand Down Expand Up @@ -403,7 +404,8 @@ ServerItem* ServerList::reset(ServerItem* item,
const std::string& host,
const std::string& port,
const std::string& user,
bool ssl) {
bool ssl,
bool http) {
auto it = std::find(items_.begin(), items_.end(), item);
if (it != items_.end()) {
// Check if there is an item with the same name. Names have to be unique!
Expand All @@ -414,7 +416,7 @@ ServerItem* ServerList::reset(ServerItem* item,
items_.erase(it);
broadcastChanged();
delete item;
item = add(name, host, port, user, false, ssl, true);
item = add(name, host, port, user, false, ssl, http, true);
save();
broadcastChanged();
}
Expand Down Expand Up @@ -556,11 +558,16 @@ bool ServerList::load() {
if (sv.size() >= 7)
user = sv[6];

bool http = false;
if (sv.size() >= 8) {
http = (sv[7] == "1") ? true : false;
}

if (sv.size() >= 3) {
std::string name = sv[0], host = sv[1], port = sv[2];
ServerItem* item = nullptr;
try {
item = add(name, host, port, user, favourite, ssl, false);
item = add(name, host, port, user, favourite, ssl, http, false);
UI_ASSERT(item != nullptr, "name=" << name << " host=" << host << " port=" << port << " user=" << user);
item->setSystem(sys);
}
Expand Down Expand Up @@ -599,14 +606,15 @@ void ServerList::save() {
if (!out.good())
return;

out << "#Name Host Port Favourite System Ssl user" << std::endl;
out << "#Name Host Port Favourite System Ssl user Http" << std::endl;

for (auto& item : items_) {
std::string fav = (item->isFavourite()) ? "1" : "0";
std::string ssl = (item->isSsl()) ? "1" : "0";
std::string http = (item->isHttp()) ? "1" : "0";
std::string sys = (item->isSystem()) ? "1" : "0";
out << item->name() << "," << item->host() << "," << item->port() << "," << fav << "," << sys << "," << ssl
<< "," << item->user() << std::endl;
<< "," << item->user() << "," << http << std::endl;
}
out.close();
}
Expand Down Expand Up @@ -662,7 +670,7 @@ void ServerList::loadSystemItems(const std::vector<ServerListTmpItem>& sysVec,
changed = true;
std::string name = sysItem.name(), host = sysItem.host(), port = sysItem.port();
try {
item = add(name, host, port, "", false, false, false);
item = add(name, host, port, "", false, false, false, false);
UI_ASSERT(item != nullptr, "name=" << name << " host=" << host << " port=" << port);
item->setSystem(true);
changeVec.push_back(
Expand All @@ -688,7 +696,7 @@ void ServerList::loadSystemItems(const std::vector<ServerListTmpItem>& sysVec,
ServerListTmpItem localTmp(item);
changeVec.push_back(new ServerListSyncChangeItem(sysItem, localTmp, ServerListSyncChangeItem::MatchChange));

item = reset(item, sysItem.name(), sysItem.host(), sysItem.port(), "", false);
item = reset(item, sysItem.name(), sysItem.host(), sysItem.port(), "", false, false);
if (item) {
item->setSystem(true);
}
Expand Down
4 changes: 3 additions & 1 deletion Viewer/ecflowUI/src/ServerList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ class ServerList {
const std::string& user,
bool favorite,
bool ssl,
bool http,
bool saveIt);
void remove(ServerItem*);
ServerItem* reset(ServerItem*,
const std::string& name,
const std::string& host,
const std::string& port,
const std::string& user,
bool ssl);
bool ssl,
bool http);
void setFavourite(ServerItem*, bool);

std::string uniqueName(const std::string&);
Expand Down
Loading

0 comments on commit bb21a5e

Please sign in to comment.