06cbebe22e
* try to import mbedtls and build it * add stubs socket class * some boilterplate, read and write function implemented * more boilterplate / current error in handshake because no CA cert is setup * add something so skip ca verification, can ws curl https://google.com ! * cleanup / close implemented * tweak CMakefiles * typo in include * update readme * disable unittests
79 lines
1.7 KiB
C++
79 lines
1.7 KiB
C++
/*
|
|
* IXSocketFactory.cpp
|
|
* Author: Benjamin Sergeant
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
*/
|
|
|
|
#include "IXSocketFactory.h"
|
|
|
|
#ifdef IXWEBSOCKET_USE_TLS
|
|
|
|
# ifdef IXWEBSOCKET_USE_MBED_TLS
|
|
# include <ixwebsocket/IXSocketMbedTLS.h>
|
|
# elif __APPLE__
|
|
# include <ixwebsocket/IXSocketAppleSSL.h>
|
|
# elif defined(_WIN32)
|
|
# include <ixwebsocket/IXSocketSChannel.h>
|
|
# elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
|
# include <ixwebsocket/IXSocketOpenSSL.h>
|
|
# endif
|
|
|
|
#else
|
|
|
|
#include <ixwebsocket/IXSocket.h>
|
|
|
|
#endif
|
|
|
|
namespace ix
|
|
{
|
|
std::shared_ptr<Socket> createSocket(bool tls,
|
|
std::string& errorMsg)
|
|
{
|
|
errorMsg.clear();
|
|
std::shared_ptr<Socket> socket;
|
|
|
|
if (!tls)
|
|
{
|
|
socket = std::make_shared<Socket>();
|
|
}
|
|
else
|
|
{
|
|
#ifdef IXWEBSOCKET_USE_TLS
|
|
# if defined(IXWEBSOCKET_USE_MBED_TLS)
|
|
socket = std::make_shared<SocketMbedTLS>();
|
|
# elif defined(__APPLE__)
|
|
socket = std::make_shared<SocketAppleSSL>();
|
|
# elif defined(_WIN32)
|
|
socket = std::make_shared<SocketSChannel>();
|
|
# else
|
|
socket = std::make_shared<SocketOpenSSL>();
|
|
# endif
|
|
#else
|
|
errorMsg = "TLS support is not enabled on this platform.";
|
|
return nullptr;
|
|
#endif
|
|
}
|
|
|
|
if (!socket->init(errorMsg))
|
|
{
|
|
socket.reset();
|
|
}
|
|
|
|
return socket;
|
|
}
|
|
|
|
std::shared_ptr<Socket> createSocket(int fd,
|
|
std::string& errorMsg)
|
|
{
|
|
errorMsg.clear();
|
|
|
|
std::shared_ptr<Socket> socket = std::make_shared<Socket>(fd);
|
|
if (!socket->init(errorMsg))
|
|
{
|
|
socket.reset();
|
|
}
|
|
|
|
return socket;
|
|
}
|
|
}
|