mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #478, CUrl class and moved network utils
* moved network utils into network folder * CUrl / CUrlList as DBus/JSON compliant class for locations * Added support for selsigned certificates in network utils
This commit is contained in:
committed by
Mathew Sutcliffe
parent
dff7ed5a90
commit
19df8a5d71
86
src/blackmisc/network/networkutils.h
Normal file
86
src/blackmisc/network/networkutils.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_NETWORKUTILS_H
|
||||
#define BLACKMISC_NETWORKUTILS_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/network/server.h"
|
||||
#include "blackmisc/network/url.h"
|
||||
#include <QUrl>
|
||||
#include <QStringList>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
//! Utilities, e.g. checking whether a network connection can be established
|
||||
class BLACKMISC_EXPORT CNetworkUtils
|
||||
{
|
||||
public:
|
||||
//! Is a connected interface available?
|
||||
//! \param withDebugOutput enables some debugging output
|
||||
//! \return
|
||||
static bool hasConnectedInterface(bool withDebugOutput = false);
|
||||
|
||||
//! Can connect?
|
||||
//! \param hostAddress 130.4.20.3, or myserver.com
|
||||
//! \param port 80, 1234
|
||||
//! \param timeoutMs
|
||||
//! \param message human readable message
|
||||
//! \return
|
||||
static bool canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs = 1500);
|
||||
|
||||
//! Can connect to server?
|
||||
//! \param server
|
||||
//! \param message human readable message
|
||||
//! \param timeoutMs
|
||||
//! \return
|
||||
static bool canConnect(const BlackMisc::Network::CServer &server, QString &message, int timeoutMs = 1500);
|
||||
|
||||
//! Can connect to URL?
|
||||
static bool canConnect(const QString &url, QString &message, int timeoutMs = 1500);
|
||||
|
||||
//! Can connect to URL?
|
||||
static bool canConnect(const QUrl &url, QString &message, int timeoutMs = 1500);
|
||||
|
||||
//! Can connect to URL?
|
||||
static bool canConnect(const BlackMisc::Network::CUrl &location, QString &message, int timeoutMs = 1500);
|
||||
|
||||
//! Find out my IPv4 address, empty if not possible
|
||||
static QStringList getKnownIpAddresses();
|
||||
|
||||
//! Valid IPv4 address
|
||||
static bool isValidIPv4Address(const QString &candidate);
|
||||
|
||||
//! Valid IPv6 address
|
||||
static bool isValidIPv6Address(const QString &candidate);
|
||||
|
||||
//! Valid port
|
||||
static bool isValidPort(const QString &port);
|
||||
|
||||
//! Build / concatenate an URL
|
||||
static QString buildUrl(const QString &protocol, const QString &server, const QString &baseUrl, const QString &serviceUrl);
|
||||
|
||||
//! Ignore SSL verification such as self signed certificates
|
||||
static void ignoreSslVerification(QNetworkRequest &request);
|
||||
|
||||
private:
|
||||
//! Deleted constructor
|
||||
CNetworkUtils() {}
|
||||
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user