2 Copyright (C) 2012-2023 Ben Kibbey <bjk@luxsci.net>
4 This file is part of qpwmc.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 #include "pwmdRemoteHost.h"
24 PwmdRemoteHost::PwmdRemoteHost (QString name
)
27 _type
= PWMD_SOCKET_LOCAL
;
28 _hostname
= _sshUsername
= QString ();
32 _tlsPriority
= QString ();
37 _clientCertificateAlias
= QString ();
42 PwmdRemoteHost::operator == (const PwmdRemoteHost
&other
) const
44 if (this->_name
== other
._name
46 && this->_clientCertificateAlias
== other
._clientCertificateAlias
48 && this->_type
== other
._type
49 && this->_hostname
== other
._hostname
50 && this->_port
== other
._port
51 && this->_ipProtocol
== other
._ipProtocol
52 && this->_tlsVerify
== other
._tlsVerify
53 && this->_tlsPriority
== other
._tlsPriority
54 && this->_socketTimeout
== other
._socketTimeout
55 && this->_connectTimeout
== other
._connectTimeout
56 && this->_sshAgent
== other
._sshAgent
57 && this->_socketArgs
== other
._socketArgs
)
64 PwmdRemoteHost::operator != (const PwmdRemoteHost
&other
) const
66 return !(*this == other
);
69 PwmdRemoteHost::~PwmdRemoteHost ()
74 PwmdRemoteHost::name ()
80 PwmdRemoteHost::setName (QString str
)
86 PwmdRemoteHost::hostname ()
92 PwmdRemoteHost::setHostname (QString h
)
98 PwmdRemoteHost::type ()
104 PwmdRemoteHost::setType (int n
)
110 PwmdRemoteHost::port ()
116 PwmdRemoteHost::setPort (int n
)
122 PwmdRemoteHost::ipProtocol ()
128 PwmdRemoteHost::setIpProtocol (int n
)
134 PwmdRemoteHost::socketArgs ()
140 PwmdRemoteHost::setSocketArgs (QStringList list
)
146 PwmdRemoteHost::tlsPriority ()
152 PwmdRemoteHost::setTlsPriority (QString s
)
158 PwmdRemoteHost::tlsVerify ()
164 PwmdRemoteHost::setTlsVerify (bool b
)
170 PwmdRemoteHost::socketTimeout ()
172 return _socketTimeout
;
176 PwmdRemoteHost::setSocketTimeout (int n
)
182 PwmdRemoteHost::connectTimeout ()
184 return _connectTimeout
;
188 PwmdRemoteHost::setConnectTimeout (int n
)
194 PwmdRemoteHost::sshUsername ()
200 PwmdRemoteHost::setSshUsername (QString s
)
206 PwmdRemoteHost::sshAgent ()
212 PwmdRemoteHost::setSshAgent (bool b
)
219 PwmdRemoteHost::clientCertificateAlias ()
221 return _clientCertificateAlias
;
225 PwmdRemoteHost::setClientCertificateAlias (QString s
)
227 _clientCertificateAlias
= s
;
232 PwmdRemoteHost::fillRemoteHost (const QString
&name
, PwmdRemoteHost
&data
)
234 QSettings
cfg ("qpwmc");
235 int size
= cfg
.beginReadArray ("remoteHosts");
237 for (int i
= 0; i
< size
; ++i
)
239 cfg
.setArrayIndex (i
);
241 if (cfg
.value ("name").toString () != name
)
244 data
= PwmdRemoteHost (cfg
.value ("name").toString ());
245 data
.setType (cfg
.value ("type").toInt ());
246 data
.setHostname (cfg
.value ("hostname").toString ());
247 data
.setPort (cfg
.value ("port").toInt ());
248 data
.setIpProtocol (cfg
.value ("ipProtocol").toInt ());
249 data
.setSocketArgs (cfg
.value ("socketArgs").toStringList ());
250 data
.setTlsVerify (cfg
.value ("tlsVerify").toBool ());
251 data
.setTlsPriority (cfg
.value ("tlsPriority").toString ());
252 data
.setConnectTimeout (cfg
.value ("connectTimeout").toInt ());
253 data
.setSocketTimeout (cfg
.value ("socketTimeout").toInt ());
254 data
.setSshAgent (cfg
.value ("sshAgent").toBool ());
255 data
.setSshUsername (cfg
.value ("sshUsername").toString ());
257 data
.setClientCertificateAlias (cfg
.value ("clientCertificateAlias").toString ());
267 PwmdRemoteHost::socketUrl (PwmdRemoteHost
&host
)
269 QString s
= QString ();
271 if (host
.type () == PWMD_SOCKET_SSH
)
276 if (host
.ipProtocol () != 0 && host
.ipProtocol () == 1)
278 else if (host
.ipProtocol () != 0)
283 if (host
.type () == PWMD_SOCKET_SSH
)
285 s
.append (host
.sshUsername ().isEmpty ()? "" : host
.sshUsername ());
289 if (host
.ipProtocol () != 0)
292 s
.append (host
.hostname ());
294 if (host
.ipProtocol () != 0)
297 s
.append (QString (":%1").arg (host
.port ()));