swift
Loading...
Searching...
No Matches
swift::misc::network::CNetworkUtils Class Reference

Utilities, e.g. checking whether a network connection can be established. More...

#include <networkutils.h>

Public Types

enum  RequestType { Get , PostUrlEncoded , Multipart }
 Request type. More...

Static Public Member Functions

static int getTimeoutMs ()
 Default for timeout.
static int getLongTimeoutMs ()
 Default for timeout (long).
static bool canConnect (const QString &hostAddress, int port, QString &message, int timeoutMs=getTimeoutMs())
 Can connect?
static bool canConnect (const swift::misc::network::CServer &server, QString &message, int timeoutMs=getTimeoutMs())
 Can connect to server?
static bool canConnect (const QString &url, QString &message, int timeoutMs=getTimeoutMs())
 Can connect to URL?
static bool canConnect (const QUrl &url, QString &message, int timeoutMs=getTimeoutMs())
 Can connect to URL?
static bool canConnect (const QUrl &url, int timeoutMs=getTimeoutMs())
 Can connect to URL?
static QStringList getKnownLocalIpV4Addresses ()
 Find out my IPv4 addresses including loopback, empty if not possible.
static bool isValidIPv4Address (const QString &candidate)
 Valid IPv4 address.
static bool isValidIPv6Address (const QString &candidate)
 Valid IPv6 address.
static bool isValidPort (const QString &port)
 Valid port.
static QString buildUrl (const QString &protocol, const QString &server, const QString &baseUrl, const QString &serviceUrl)
 Build / concatenate an URL.
static void setSwiftUserAgent (QNetworkRequest &request, const QString &userAgentDetails={})
 Set user agent for request.
static void addDebugFlag (QUrlQuery &qurl)
 Add debug flag.
static QNetworkRequest getSwiftNetworkRequest (const QUrl &url, RequestType type=Get, const QString &userAgentDetails={})
 Our tweaked network request with swift header.
static QNetworkRequest getSwiftNetworkRequest (const QNetworkRequest &request, const QString &userAgentDetails={})
 Get a copied network request with swift header.
static qint64 lastModifiedMsSinceEpoch (const QNetworkReply *nwReply)
 Last modified from reply.
static QDateTime lastModifiedDateTime (const QNetworkReply *nwReply)
 Last modified from reply.
static qint64 lastModifiedSinceNow (const QNetworkReply *nwReply)
 Last modified from reply compared with now (in ms).
static qint64 requestDuration (const QNetworkReply *nwReply)
 Request duration (only works if requested by swift functions).
static int getHttpStatusCode (QNetworkReply *nwReply)
 Get the http status code.
static bool isHttpStatusRedirect (QNetworkReply *nwReply)
 Is the reply an HTTP redirect?
static QUrl getHttpRedirectUrl (QNetworkReply *nwReply)
 Get the redirect URL if any.
static QString removeHtmlPartsFromPhpErrorMessage (const QString &errorMessage)
 Remove the HTML formatting from a PHP error message.
static bool looksLikePhpErrorMessage (const QString &errorMessage)
 Looks like PHP error messages.
static const QString & networkOperationToString (QNetworkAccessManager::Operation operation)
 Operation to string.

Detailed Description

Utilities, e.g. checking whether a network connection can be established.

Definition at line 28 of file networkutils.h.

Member Enumeration Documentation

◆ RequestType

Request type.

Definition at line 32 of file networkutils.h.

Member Function Documentation

◆ addDebugFlag()

void swift::misc::network::CNetworkUtils::addDebugFlag ( QUrlQuery & qurl)
static

Add debug flag.

Definition at line 180 of file networkutils.cpp.

◆ buildUrl()

QString swift::misc::network::CNetworkUtils::buildUrl ( const QString & protocol,
const QString & server,
const QString & baseUrl,
const QString & serviceUrl )
static

Build / concatenate an URL.

Definition at line 153 of file networkutils.cpp.

◆ canConnect() [1/5]

bool swift::misc::network::CNetworkUtils::canConnect ( const QString & hostAddress,
int port,
QString & message,
int timeoutMs = getTimeoutMs() )
static

Can connect?

Parameters
hostAddress130.4.20.3, or myserver.com
port80, 1234
timeoutMs
messagehuman readable message

Definition at line 57 of file networkutils.cpp.

◆ canConnect() [2/5]

bool swift::misc::network::CNetworkUtils::canConnect ( const QString & url,
QString & message,
int timeoutMs = getTimeoutMs() )
static

Can connect to URL?

Definition at line 93 of file networkutils.cpp.

◆ canConnect() [3/5]

bool swift::misc::network::CNetworkUtils::canConnect ( const QUrl & url,
int timeoutMs = getTimeoutMs() )
static

Can connect to URL?

Definition at line 127 of file networkutils.cpp.

◆ canConnect() [4/5]

bool swift::misc::network::CNetworkUtils::canConnect ( const QUrl & url,
QString & message,
int timeoutMs = getTimeoutMs() )
static

Can connect to URL?

Definition at line 103 of file networkutils.cpp.

◆ canConnect() [5/5]

bool swift::misc::network::CNetworkUtils::canConnect ( const swift::misc::network::CServer & server,
QString & message,
int timeoutMs = getTimeoutMs() )
static

Can connect to server?

Parameters
server
messagehuman readable message
timeoutMs

Definition at line 88 of file networkutils.cpp.

◆ getHttpRedirectUrl()

QUrl swift::misc::network::CNetworkUtils::getHttpRedirectUrl ( QNetworkReply * nwReply)
static

Get the redirect URL if any.

Definition at line 271 of file networkutils.cpp.

◆ getHttpStatusCode()

int swift::misc::network::CNetworkUtils::getHttpStatusCode ( QNetworkReply * nwReply)
static

Get the http status code.

Definition at line 246 of file networkutils.cpp.

◆ getKnownLocalIpV4Addresses()

QStringList swift::misc::network::CNetworkUtils::getKnownLocalIpV4Addresses ( )
static

Find out my IPv4 addresses including loopback, empty if not possible.

Definition at line 37 of file networkutils.cpp.

◆ getLongTimeoutMs()

int swift::misc::network::CNetworkUtils::getLongTimeoutMs ( )
static

Default for timeout (long).

Definition at line 35 of file networkutils.cpp.

◆ getSwiftNetworkRequest() [1/2]

QNetworkRequest swift::misc::network::CNetworkUtils::getSwiftNetworkRequest ( const QNetworkRequest & request,
const QString & userAgentDetails = {} )
static

Get a copied network request with swift header.

Definition at line 197 of file networkutils.cpp.

◆ getSwiftNetworkRequest() [2/2]

QNetworkRequest swift::misc::network::CNetworkUtils::getSwiftNetworkRequest ( const QUrl & url,
RequestType type = Get,
const QString & userAgentDetails = {} )
static

Our tweaked network request with swift header.

Definition at line 182 of file networkutils.cpp.

◆ getTimeoutMs()

int swift::misc::network::CNetworkUtils::getTimeoutMs ( )
static

Default for timeout.

Definition at line 33 of file networkutils.cpp.

◆ isHttpStatusRedirect()

bool swift::misc::network::CNetworkUtils::isHttpStatusRedirect ( QNetworkReply * nwReply)
static

Is the reply an HTTP redirect?

Status codes:

  • 301: Permanent redirect. Clients making subsequent requests for this resource should use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
  • 302: Redirect for undefined reason. Clients making subsequent requests for this resource should not use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
  • 303: Redirect for undefined reason. Typically, 'Operation has completed, continue elsewhere.' Clients making subsequent requests for this resource should not use the new URI. Clients should follow the redirect for POST/PUT/DELETE requests.
  • 307: Temporary redirect. Resource may return to this location at a later point. Clients making subsequent requests for this resource should use the old URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.

Definition at line 261 of file networkutils.cpp.

◆ isValidIPv4Address()

bool swift::misc::network::CNetworkUtils::isValidIPv4Address ( const QString & candidate)
static

Valid IPv4 address.

Definition at line 133 of file networkutils.cpp.

◆ isValidIPv6Address()

bool swift::misc::network::CNetworkUtils::isValidIPv6Address ( const QString & candidate)
static

Valid IPv6 address.

Definition at line 139 of file networkutils.cpp.

◆ isValidPort()

bool swift::misc::network::CNetworkUtils::isValidPort ( const QString & port)
static

Valid port.

Definition at line 145 of file networkutils.cpp.

◆ lastModifiedDateTime()

QDateTime swift::misc::network::CNetworkUtils::lastModifiedDateTime ( const QNetworkReply * nwReply)
static

Last modified from reply.

Definition at line 212 of file networkutils.cpp.

◆ lastModifiedMsSinceEpoch()

qint64 swift::misc::network::CNetworkUtils::lastModifiedMsSinceEpoch ( const QNetworkReply * nwReply)
static

Last modified from reply.

Definition at line 205 of file networkutils.cpp.

◆ lastModifiedSinceNow()

qint64 swift::misc::network::CNetworkUtils::lastModifiedSinceNow ( const QNetworkReply * nwReply)
static

Last modified from reply compared with now (in ms).

Definition at line 223 of file networkutils.cpp.

◆ looksLikePhpErrorMessage()

bool swift::misc::network::CNetworkUtils::looksLikePhpErrorMessage ( const QString & errorMessage)
static

Looks like PHP error messages.

Definition at line 301 of file networkutils.cpp.

◆ networkOperationToString()

const QString & swift::misc::network::CNetworkUtils::networkOperationToString ( QNetworkAccessManager::Operation operation)
static

Operation to string.

Definition at line 310 of file networkutils.cpp.

◆ removeHtmlPartsFromPhpErrorMessage()

QString swift::misc::network::CNetworkUtils::removeHtmlPartsFromPhpErrorMessage ( const QString & errorMessage)
static

Remove the HTML formatting from a PHP error message.

Definition at line 290 of file networkutils.cpp.

◆ requestDuration()

qint64 swift::misc::network::CNetworkUtils::requestDuration ( const QNetworkReply * nwReply)
static

Request duration (only works if requested by swift functions).

Definition at line 230 of file networkutils.cpp.

◆ setSwiftUserAgent()

void swift::misc::network::CNetworkUtils::setSwiftUserAgent ( QNetworkRequest & request,
const QString & userAgentDetails = {} )
static

Set user agent for request.

Definition at line 170 of file networkutils.cpp.


The documentation for this class was generated from the following files: