lib/net: Use std::string directly instead of String typedef
This commit is contained in:
parent
dbd10820c3
commit
b93bcccf57
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include "net/ISocket.h"
|
#include "net/ISocket.h"
|
||||||
#include "io/IStream.h"
|
#include "io/IStream.h"
|
||||||
#include "base/String.h"
|
|
||||||
#include "base/EventTypes.h"
|
#include "base/EventTypes.h"
|
||||||
|
|
||||||
//! Data stream socket interface
|
//! Data stream socket interface
|
||||||
|
@ -33,7 +32,7 @@ public:
|
||||||
class ConnectionFailedInfo {
|
class ConnectionFailedInfo {
|
||||||
public:
|
public:
|
||||||
ConnectionFailedInfo(const char* what) : m_what(what) { }
|
ConnectionFailedInfo(const char* what) : m_what(what) { }
|
||||||
String m_what;
|
std::string m_what;
|
||||||
};
|
};
|
||||||
|
|
||||||
IDataSocket(IEventQueue* events) { }
|
IDataSocket(IEventQueue* events) { }
|
||||||
|
|
|
@ -96,7 +96,7 @@ NetworkAddress::NetworkAddress(const NetworkAddress& addr) :
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkAddress::NetworkAddress(const String& hostname, int port) :
|
NetworkAddress::NetworkAddress(const std::string& hostname, int port) :
|
||||||
m_address(NULL),
|
m_address(NULL),
|
||||||
m_hostname(hostname),
|
m_hostname(hostname),
|
||||||
m_port(port)
|
m_port(port)
|
||||||
|
@ -196,8 +196,7 @@ NetworkAddress::getPort() const
|
||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
String
|
std::string NetworkAddress::getHostname() const
|
||||||
NetworkAddress::getHostname() const
|
|
||||||
{
|
{
|
||||||
return m_hostname;
|
return m_hostname;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "base/String.h"
|
|
||||||
#include "base/EventTypes.h"
|
#include "base/EventTypes.h"
|
||||||
#include "arch/IArchNetwork.h"
|
#include "arch/IArchNetwork.h"
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ public:
|
||||||
is thrown with an error of \c XSocketAddress::kBadPort. The hostname
|
is thrown with an error of \c XSocketAddress::kBadPort. The hostname
|
||||||
is not resolved by the c'tor; use \c resolve to do that.
|
is not resolved by the c'tor; use \c resolve to do that.
|
||||||
*/
|
*/
|
||||||
NetworkAddress(const String& hostname, int port);
|
NetworkAddress(const std::string& hostname, int port);
|
||||||
|
|
||||||
NetworkAddress(const NetworkAddress&);
|
NetworkAddress(const NetworkAddress&);
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
Returns the hostname passed to the c'tor sans any port suffix.
|
Returns the hostname passed to the c'tor sans any port suffix.
|
||||||
*/
|
*/
|
||||||
String getHostname() const;
|
std::string getHostname() const;
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
@ -118,6 +117,6 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ArchNetAddress m_address;
|
ArchNetAddress m_address;
|
||||||
String m_hostname;
|
std::string m_hostname;
|
||||||
int m_port;
|
int m_port;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "net/TSocketMultiplexerMethodJob.h"
|
#include "net/TSocketMultiplexerMethodJob.h"
|
||||||
#include "arch/XArch.h"
|
#include "arch/XArch.h"
|
||||||
#include "common/DataDirectories.h"
|
#include "common/DataDirectories.h"
|
||||||
|
#include "base/String.h"
|
||||||
|
|
||||||
static const char s_certificateDir[] = { "SSL" };
|
static const char s_certificateDir[] = { "SSL" };
|
||||||
static const char s_certificateFilename[] = { "Barrier.pem" };
|
static const char s_certificateFilename[] = { "Barrier.pem" };
|
||||||
|
@ -54,7 +55,7 @@ SecureListenSocket::accept()
|
||||||
setListeningJob();
|
setListeningJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
String certificateFilename = barrier::string::sprintf("%s/%s/%s",
|
std::string certificateFilename = barrier::string::sprintf("%s/%s/%s",
|
||||||
DataDirectories::profile().c_str(),
|
DataDirectories::profile().c_str(),
|
||||||
s_certificateDir,
|
s_certificateDir,
|
||||||
s_certificateFilename);
|
s_certificateFilename);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "mt/Lock.h"
|
#include "mt/Lock.h"
|
||||||
#include "arch/XArch.h"
|
#include "arch/XArch.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
|
#include "base/String.h"
|
||||||
#include "common/DataDirectories.h"
|
#include "common/DataDirectories.h"
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
@ -328,8 +329,7 @@ SecureSocket::initSsl(bool server)
|
||||||
initContext(server);
|
initContext(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool SecureSocket::loadCertificates(std::string& filename)
|
||||||
SecureSocket::loadCertificates(String& filename)
|
|
||||||
{
|
{
|
||||||
if (filename.empty()) {
|
if (filename.empty()) {
|
||||||
showError("ssl certificate is not specified");
|
showError("ssl certificate is not specified");
|
||||||
|
@ -341,7 +341,7 @@ SecureSocket::loadCertificates(String& filename)
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
String errorMsg("ssl certificate doesn't exist: ");
|
std::string errorMsg("ssl certificate doesn't exist: ");
|
||||||
errorMsg.append(filename);
|
errorMsg.append(filename);
|
||||||
showError(errorMsg.c_str());
|
showError(errorMsg.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
@ -630,14 +630,13 @@ SecureSocket::showError(const char* reason)
|
||||||
LOG((CLOG_ERR "%s", reason));
|
LOG((CLOG_ERR "%s", reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
String error = getError();
|
std::string error = getError();
|
||||||
if (!error.empty()) {
|
if (!error.empty()) {
|
||||||
LOG((CLOG_ERR "%s", error.c_str()));
|
LOG((CLOG_ERR "%s", error.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String
|
std::string SecureSocket::getError()
|
||||||
SecureSocket::getError()
|
|
||||||
{
|
{
|
||||||
unsigned long e = ERR_get_error();
|
unsigned long e = ERR_get_error();
|
||||||
|
|
||||||
|
@ -659,8 +658,7 @@ SecureSocket::disconnect()
|
||||||
sendEvent(getEvents()->forIStream().inputShutdown());
|
sendEvent(getEvents()->forIStream().inputShutdown());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void SecureSocket::formatFingerprint(std::string& fingerprint, bool hex, bool separator)
|
||||||
SecureSocket::formatFingerprint(String& fingerprint, bool hex, bool separator)
|
|
||||||
{
|
{
|
||||||
if (hex) {
|
if (hex) {
|
||||||
// to hexidecimal
|
// to hexidecimal
|
||||||
|
@ -696,11 +694,11 @@ SecureSocket::verifyCertFingerprint()
|
||||||
}
|
}
|
||||||
|
|
||||||
// format fingerprint into hexdecimal format with colon separator
|
// format fingerprint into hexdecimal format with colon separator
|
||||||
String fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
|
std::string fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
|
||||||
formatFingerprint(fingerprint);
|
formatFingerprint(fingerprint);
|
||||||
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
||||||
|
|
||||||
String trustedServersFilename;
|
std::string trustedServersFilename;
|
||||||
trustedServersFilename = barrier::string::sprintf(
|
trustedServersFilename = barrier::string::sprintf(
|
||||||
"%s/%s/%s",
|
"%s/%s/%s",
|
||||||
DataDirectories::profile().c_str(),
|
DataDirectories::profile().c_str(),
|
||||||
|
@ -711,7 +709,7 @@ SecureSocket::verifyCertFingerprint()
|
||||||
LOG((CLOG_NOTE "trustedServersFilename: %s", trustedServersFilename.c_str() ));
|
LOG((CLOG_NOTE "trustedServersFilename: %s", trustedServersFilename.c_str() ));
|
||||||
|
|
||||||
// check if this fingerprint exist
|
// check if this fingerprint exist
|
||||||
String fileLine;
|
std::string fileLine;
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
file.open(trustedServersFilename.c_str());
|
file.open(trustedServersFilename.c_str());
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
EJobResult doRead() override;
|
EJobResult doRead() override;
|
||||||
EJobResult doWrite() override;
|
EJobResult doWrite() override;
|
||||||
void initSsl(bool server);
|
void initSsl(bool server);
|
||||||
bool loadCertificates(String& CertFile);
|
bool loadCertificates(std::string& CertFile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// SSL
|
// SSL
|
||||||
|
@ -66,11 +66,9 @@ private:
|
||||||
bool showCertificate();
|
bool showCertificate();
|
||||||
void checkResult(int n, int& retry);
|
void checkResult(int n, int& retry);
|
||||||
void showError(const char* reason = NULL);
|
void showError(const char* reason = NULL);
|
||||||
String getError();
|
std::string getError();
|
||||||
void disconnect();
|
void disconnect();
|
||||||
void formatFingerprint(String& fingerprint,
|
void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
|
||||||
bool hex = true,
|
|
||||||
bool separator = true);
|
|
||||||
bool verifyCertFingerprint();
|
bool verifyCertFingerprint();
|
||||||
|
|
||||||
MultiplexerJobStatus serviceConnect(ISocketMultiplexerJob*, bool, bool, bool);
|
MultiplexerJobStatus serviceConnect(ISocketMultiplexerJob*, bool, bool, bool);
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
// XSocketAddress
|
// XSocketAddress
|
||||||
//
|
//
|
||||||
|
|
||||||
XSocketAddress::XSocketAddress(EError error,
|
XSocketAddress::XSocketAddress(EError error, const std::string& hostname, int port) _NOEXCEPT :
|
||||||
const String& hostname, int port) _NOEXCEPT :
|
|
||||||
m_error(error),
|
m_error(error),
|
||||||
m_hostname(hostname),
|
m_hostname(hostname),
|
||||||
m_port(port)
|
m_port(port)
|
||||||
|
@ -38,7 +37,7 @@ XSocketAddress::getError() const throw()
|
||||||
return m_error;
|
return m_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
String
|
std::string
|
||||||
XSocketAddress::getHostname() const throw()
|
XSocketAddress::getHostname() const throw()
|
||||||
{
|
{
|
||||||
return m_hostname;
|
return m_hostname;
|
||||||
|
@ -50,8 +49,7 @@ XSocketAddress::getPort() const throw()
|
||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
String
|
std::string XSocketAddress::getWhat() const throw()
|
||||||
XSocketAddress::getWhat() const throw()
|
|
||||||
{
|
{
|
||||||
static const char* s_errorID[] = {
|
static const char* s_errorID[] = {
|
||||||
"XSocketAddressUnknown",
|
"XSocketAddressUnknown",
|
||||||
|
@ -77,8 +75,7 @@ XSocketAddress::getWhat() const throw()
|
||||||
// XSocketIOClose
|
// XSocketIOClose
|
||||||
//
|
//
|
||||||
|
|
||||||
String
|
std::string XSocketIOClose::getWhat() const throw()
|
||||||
XSocketIOClose::getWhat() const throw()
|
|
||||||
{
|
{
|
||||||
return format("XSocketIOClose", "close: %{1}", what());
|
return format("XSocketIOClose", "close: %{1}", what());
|
||||||
}
|
}
|
||||||
|
@ -88,8 +85,7 @@ XSocketIOClose::getWhat() const throw()
|
||||||
// XSocketBind
|
// XSocketBind
|
||||||
//
|
//
|
||||||
|
|
||||||
String
|
std::string XSocketBind::getWhat() const throw()
|
||||||
XSocketBind::getWhat() const throw()
|
|
||||||
{
|
{
|
||||||
return format("XSocketBind", "cannot bind address: %{1}", what());
|
return format("XSocketBind", "cannot bind address: %{1}", what());
|
||||||
}
|
}
|
||||||
|
@ -99,8 +95,7 @@ XSocketBind::getWhat() const throw()
|
||||||
// XSocketConnect
|
// XSocketConnect
|
||||||
//
|
//
|
||||||
|
|
||||||
String
|
std::string XSocketConnect::getWhat() const throw()
|
||||||
XSocketConnect::getWhat() const throw()
|
|
||||||
{
|
{
|
||||||
return format("XSocketConnect", "cannot connect socket: %{1}", what());
|
return format("XSocketConnect", "cannot connect socket: %{1}", what());
|
||||||
}
|
}
|
||||||
|
@ -110,8 +105,7 @@ XSocketConnect::getWhat() const throw()
|
||||||
// XSocketCreate
|
// XSocketCreate
|
||||||
//
|
//
|
||||||
|
|
||||||
String
|
std::string XSocketCreate::getWhat() const throw()
|
||||||
XSocketCreate::getWhat() const throw()
|
|
||||||
{
|
{
|
||||||
return format("XSocketCreate", "cannot create socket: %{1}", what());
|
return format("XSocketCreate", "cannot create socket: %{1}", what());
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include "io/XIO.h"
|
#include "io/XIO.h"
|
||||||
#include "base/XBase.h"
|
#include "base/XBase.h"
|
||||||
#include "base/String.h"
|
|
||||||
#include "common/basic_types.h"
|
#include "common/basic_types.h"
|
||||||
|
|
||||||
//! Generic socket exception
|
//! Generic socket exception
|
||||||
|
@ -41,7 +40,7 @@ public:
|
||||||
kBadPort //!< The port is invalid
|
kBadPort //!< The port is invalid
|
||||||
};
|
};
|
||||||
|
|
||||||
XSocketAddress(EError, const String& hostname, int port) _NOEXCEPT;
|
XSocketAddress(EError, const std::string& hostname, int port) _NOEXCEPT;
|
||||||
virtual ~XSocketAddress() _NOEXCEPT { }
|
virtual ~XSocketAddress() _NOEXCEPT { }
|
||||||
|
|
||||||
//! @name accessors
|
//! @name accessors
|
||||||
|
@ -50,7 +49,7 @@ public:
|
||||||
//! Get the error code
|
//! Get the error code
|
||||||
EError getError() const throw();
|
EError getError() const throw();
|
||||||
//! Get the hostname
|
//! Get the hostname
|
||||||
String getHostname() const throw();
|
std::string getHostname() const throw();
|
||||||
//! Get the port
|
//! Get the port
|
||||||
int getPort() const throw();
|
int getPort() const throw();
|
||||||
|
|
||||||
|
@ -58,11 +57,11 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// XBase overrides
|
// XBase overrides
|
||||||
virtual String getWhat() const throw();
|
virtual std::string getWhat() const throw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EError m_error;
|
EError m_error;
|
||||||
String m_hostname;
|
std::string m_hostname;
|
||||||
int m_port;
|
int m_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue