...
 
Commits (19)
......@@ -233,9 +233,10 @@ void Advanced_IP_Camera::SetupCurl(string sUrl, string sUser, string sPasswd)
curl_easy_setopt(m_pCurl, CURLOPT_URL, sUrl.c_str());
curl_easy_setopt(m_pCurl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
LoggerWrapper::GetInstance ()->Write (LV_STATUS, "HttpGet: sUser: %s", sUser.c_str());
if (!sUser.empty())
{
curl_easy_setopt(m_pCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(m_pCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
curl_easy_setopt(m_pCurl, CURLOPT_USERNAME, sUser.c_str());
if (!sPasswd.empty()) {
curl_easy_setopt(m_pCurl, CURLOPT_PASSWORD, sPasswd.c_str());
......@@ -295,19 +296,12 @@ bool Advanced_IP_Camera::HttpGet(string sUrl, string sUser, string sPasswd, char
CallbackData data;
PLUTO_SAFETY_LOCK (gm, m_CurlMutex);
curl_easy_reset(m_pCurl);
LoggerWrapper::GetInstance ()->Write (LV_STATUS, "HttpGet: sUrl: %s", sUrl.c_str ());
curl_easy_setopt(m_pCurl, CURLOPT_URL, sUrl.c_str());
SetupCurl(sUrl,sUser, sPasswd);
/* send all data to this function */
curl_easy_setopt(m_pCurl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(m_pCurl, CURLOPT_WRITEDATA, (void *)&data);
curl_easy_setopt(m_pCurl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
if (!sUser.empty())
{
curl_easy_setopt(m_pCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(m_pCurl, CURLOPT_USERNAME, sUser.c_str());
curl_easy_setopt(m_pCurl, CURLOPT_PASSWORD, sPasswd.c_str());
}
CURLcode res = curl_easy_perform(m_pCurl);
......
......@@ -37,12 +37,13 @@ using namespace DCE;
#endif
ClientSocket::ClientSocket( int iDeviceID, string sIPAddress, string sName ) : Socket( sName, sIPAddress )
ClientSocket::ClientSocket( int iDeviceID, string sIPAddress, string sName, bool bIsSSL ) : Socket( sName, sIPAddress )
{
m_dwPK_Device = iDeviceID;
m_eLastError = cs_err_None;
m_bNeedReload = false;
m_dwMaxRetries = MAX_RETRIES;
m_bIsSSL_set(bIsSSL);
/** @todo check comment */
// if( g_pDCELogger ) // This won't be created yet if this is the server logger socket
// g_pDCELogger->Write(LV_SOCKET,"Created client socket %p device: %d ip: %s",this,m_DeviceID,m_IPAddress.c_str());
......@@ -52,10 +53,65 @@ ClientSocket::ClientSocket( int iDeviceID, string sIPAddress, string sName ) : S
ClientSocket::~ClientSocket()
{
Disconnect();
if (m_bIsSSL)
{
SSL_CTX_free(m_sslctx);
}
}
bool ClientSocket::Connect( int PK_DeviceTemplate,string sExtraInfo,int iConnectRetries, int nConnectStepsLeft )
{
if (m_bIsSSL)
{
LoggerWrapper::GetInstance()->Write( LV_WARNING, "Connecting with SSL.\r" );
m_sslctx = SSL_CTX_new(SSLv23_client_method()); // TODO: replace with TLS_client_method when using new openssl
if ( !m_sslctx ) {
LoggerWrapper::GetInstance()->Write( LV_CRITICAL, "Couldn't create SSL context." );
ERR_print_errors_fp(stderr);
return false;
}
string path = s_sSSL_key_path + "dce-client.key.pem";
if ( SSL_CTX_use_PrivateKey_file(m_sslctx, path.c_str(), SSL_FILETYPE_PEM) <= 0 ) {
LoggerWrapper::GetInstance()->Write( LV_CRITICAL, "Couldn't set SSL private key. %s", path.c_str() );
DumpSSLError(LV_CRITICAL, ERR_get_error());
return false;
}
path = s_sSSL_key_path + "dce-client.crt";
int ret = SSL_CTX_use_certificate_file(m_sslctx, path.c_str() , SSL_FILETYPE_PEM);
if ( ret <= 0 ) {
LoggerWrapper::GetInstance()->Write( LV_CRITICAL, "Couldn't set SSL public key. %s", path.c_str() );
DumpSSLError(LV_CRITICAL, ERR_get_error());
return false;
}
if ( !SSL_CTX_check_private_key(m_sslctx) ) {
LoggerWrapper::GetInstance()->Write( LV_CRITICAL, "Public and private keys does not match." );
DumpSSLError(LV_CRITICAL, ERR_get_error());
return false;
}
path = s_sSSL_key_path + "CA/cacert.pem";
if (SSL_CTX_load_verify_locations(m_sslctx, path.c_str(), NULL) <= 0 ) {
LoggerWrapper::GetInstance()->Write( LV_CRITICAL, "Couldn't set SSL CA cert.\r %s", path.c_str() );
DumpSSLError(LV_CRITICAL, ERR_get_error());
return false;
}
/* path = s_sSSL_key_path + "CA/cacert.pem";
if ( SSL_CTX_use_certificate_chain_file(m_sslctx, path.c_str()) <= 0 ) {
LoggerWrapper::GetInstance()->Write( LV_CRITICAL, "Unable to set CA file. %s", path.c_str() );
DumpSSLError(LV_CRITICAL, 0);
return false;
}
*/
SSL_CTX_set_verify(m_sslctx, SSL_VERIFY_PEER, NULL);
SSL_CTX_set_verify_depth(m_sslctx, 1);
SSL_CTX_set_mode(m_sslctx, SSL_MODE_AUTO_RETRY);
}
m_bCancelSocketOp = false;
if( iConnectRetries==-1 )
......@@ -115,6 +171,8 @@ bool ClientSocket::Connect( int PK_DeviceTemplate,string sExtraInfo,int iConnect
string sAddress;
int iPort;
StringUtils::AddressAndPortFromString( m_sIPAddress, DCE_DEFAULT_PORT, sAddress, iPort );
if (m_bIsSSL)
iPort++;
addrT.sin_port = htons( iPort );
unsigned long dwAddr = inet_addr( sAddress.c_str() );
......@@ -158,7 +216,56 @@ bool ClientSocket::Connect( int PK_DeviceTemplate,string sExtraInfo,int iConnect
inet_ntop( AF_INET, &( addrT.sin_addr.s_addr), pcAddress, 32 );
m_sMyIPAddress = pcAddress;
#endif
bSuccess = true;
if (m_bIsSSL)
{
int err = -1;
m_pSSL = SSL_new (m_sslctx);
SSL_set_fd(m_pSSL, m_Socket);
bool bWantRead = false, bWantWrite = false;
do {
if (bWantRead || bWantWrite) {
fd_set rfds;
struct timeval tv;
FD_ZERO(&rfds);
FD_SET(m_Socket, &rfds);
tv.tv_sec = 1;
tv.tv_usec = 0;
if (bWantRead) {
int iRet = select((int) (m_Socket+1), &rfds, NULL, NULL, &tv);
} else {
int iRet = select((int) (m_Socket+1), NULL, &rfds, NULL, &tv);
}
}
bWantRead = false;
bWantWrite = false;
err = SSL_connect(m_pSSL);
if ( err != 1 )
{
int sslerr = SSL_get_error(m_pSSL, err);
switch (sslerr) {
case SSL_ERROR_WANT_WRITE:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::Connect() SSL Want WRITE");
bWantWrite = true;
break;
case SSL_ERROR_WANT_READ:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::Connect() SSL Want READ");
bWantRead = true;
break;
case SSL_ERROR_NONE:
break;
default:
LoggerWrapper::GetInstance()->Write(LV_WARNING, "SSL_Connect() failed, Error Code %d, %d", err, sslerr);
DumpSSLError( LV_WARNING, sslerr );
break;
}
}
} while (bWantRead || bWantWrite);
if ( err == 1 )
bSuccess = true;
} else {
bSuccess = true;
}
}
else
{
......
......@@ -32,6 +32,9 @@ Header file for the ClientSocket class
#endif
#include "Socket.h"
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define MAX_RETRIES 3 // Maximum retries to establish TCP connection
#define MAX_CONNECT_STEPS 10
......@@ -51,6 +54,7 @@ The derived ClientSocket's responsibility is to make, and keep a reliable connec
*/
class ClientSocket : public Socket
{
SSL_CTX *m_sslctx;
public:
bool m_bNeedReload; /**< the device was recently added and the router not yet reloaded, so functionality may be limited */
......@@ -66,7 +70,7 @@ The derived ClientSocket's responsibility is to make, and keep a reliable connec
@param sName is the socketrs name.
This assigns values to the member data
*/
ClientSocket( int iDeviceID, string sIPAddress, string sName );
ClientSocket( int iDeviceID, string sIPAddress, string sName, bool bIsSSL=false );
virtual ~ClientSocket();
......
......@@ -589,7 +589,7 @@ int Command_Impl::DeviceIdInvalid()
void Command_Impl::GetDevicesByTemplate(int PK_DeviceTemplate,map<int,string> *p_mapDevices)
{
Event_Impl *pEvent = new Event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);
Event_Impl *pEvent = new Event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, -1, -1, m_bIsSSL);
pEvent->m_pClientSocket->SendString("DEVICES BY TEMPLATE " + StringUtils::itos(PK_DeviceTemplate));
string sResponse;
if ( pEvent->m_pClientSocket->ReceiveString( sResponse ) && sResponse.substr(0,11)=="DEVICE_INFO" )
......@@ -616,7 +616,7 @@ void Command_Impl::GetDevicesByTemplate(int PK_DeviceTemplate,map<int,string> *p
void Command_Impl::GetDevicesByCategory(int PK_DeviceCategory,map<int,string> *p_mapDevices)
{
Event_Impl *pEvent = new Event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);
Event_Impl *pEvent = new Event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, -1, -1, m_bIsSSL);
pEvent->m_pClientSocket->SendString("DEVICES BY CATEGORY " + StringUtils::itos(PK_DeviceCategory));
string sResponse;
if ( pEvent->m_pClientSocket->ReceiveString( sResponse ) && sResponse.substr(0,11)=="DEVICE_INFO" )
......
......@@ -27,11 +27,10 @@
using namespace DCE;
Event_Impl::Event_Impl( long dwDevice, long dwDeviceTemplate, string sServerAddress, bool bConnectEventHandler, int nSocketTimeout, int nConnectRetries )
Event_Impl::Event_Impl( long dwDevice, long dwDeviceTemplate, string sServerAddress, bool bConnectEventHandler, int nSocketTimeout, int nConnectRetries, bool bIsSSL )
{
m_dwPK_Device = dwDevice;
m_pClientSocket = new ClientSocket( dwDevice, sServerAddress, string( "Event Dev #" ) + StringUtils::itos( dwDevice ) );
m_pClientSocket = new ClientSocket( dwDevice, sServerAddress, string( "Event Dev #" ) + StringUtils::itos( dwDevice ), bIsSSL );
if( bConnectEventHandler )
{
m_pClientSocket->Connect(dwDeviceTemplate,"Event #" + StringUtils::itos(dwDevice),nConnectRetries==-1 ? INITIAL_CONNECT_RETRIES : nConnectRetries);
......
......@@ -43,7 +43,7 @@ namespace DCE
* @brief If this is the master device's event, create a connection to the server
* @param bConnectEventHandler specifies if we should connect the client socket after creating it
*/
Event_Impl( long dwDevice, long dwDeviceTemplate, string sServerAddress, bool bConnectEventHandler=true, int nSocketTimeout = -1, int nConnectRetries = -1 /* default */ );
Event_Impl( long dwDevice, long dwDeviceTemplate, string sServerAddress, bool bConnectEventHandler=true, int nSocketTimeout = -1, int nConnectRetries = -1 /* default */, bool bIsSSL=false );
/**
* @brief If this is a sub-device's event, just use pointer to the connection
......
......@@ -8,7 +8,7 @@ CPPFLAGS = -I./ -I../ -I../DCE/ -I../VIPShared/ -D_FILE_OFFSET_BITS=64 -D_LARGEF
CXX = g++
LDFLAGS =
LDFLAGS += -L$(ROOT)/lib
LDLIBS = -lpthread -lSerializeClass
LDLIBS = -lpthread -lSerializeClass -lssl
MYSQL_FLAGS = $(shell pkg-config --cflags mysqlclient)
MYSQL_LIBS = $(shell pkg-config --libs mysqlclient)
......
......@@ -53,8 +53,8 @@ void *ServerSocket::BeginWapClientThread(void *SvSock)
return NULL;
}
ServerSocket::ServerSocket( SocketListener *pListener, SOCKET Sock, string sName, string sIPAddress, string sMacAddress ) :
Socket( sName, sIPAddress, sMacAddress ),
ServerSocket::ServerSocket( SocketListener *pListener, SOCKET Sock, string sName, string sIPAddress, string sMacAddress, SSL* ssl, bool isSSL ) :
Socket( sName, sIPAddress, sMacAddress, ssl, isSSL ),
m_bSelfDestroying(false),
m_ConnectionMutex( "connection " + sName ),
#ifdef PTHREAD2
......
......@@ -60,7 +60,7 @@ namespace DCE
/**
* @brief constructor, assignes values to the member data and starts the looping thread
*/
ServerSocket( SocketListener *pListener, SOCKET Sock, string sName, string sIPAddress="", string sMacAddress="" );
ServerSocket( SocketListener *pListener, SOCKET Sock, string sName, string sIPAddress="", string sMacAddress="", SSL* ssl=NULL, bool isSSL=false );
/**
* @brief destructor, kills the tread
......
......@@ -80,6 +80,8 @@ SocketInfo *Socket::g_mapSocketInfo_Find(int iSocketCounter,string sName,Socket
static int SocketCounter=0;
string Socket::s_sSSL_key_path = "/etc/pluto/certs/";
// An application can create another handler that gets called instead in the event of a deadlock
void (*g_pSocketCrashHandler)(Socket *pSocket)=NULL;
......@@ -149,9 +151,10 @@ void* PingLoop( void* param ) // renamed to cancel link-time name collision in M
}
}
Socket::Socket(string Name,string sIPAddress, string sMacAddress) :
Socket::Socket(string Name,string sIPAddress, string sMacAddress, SSL* pSSL, bool isSSL) :
m_pInternalBuffer_Data(NULL), m_nInternalBuffer_Position(0),
m_bReceiveData_TimedOut(false), m_SocketMutex("socket mutex " + Name)
m_bReceiveData_TimedOut(false), m_SocketMutex("socket mutex " + Name),
m_pSSL(pSSL), m_bIsSSL(isSSL)
{
m_bCancelSocketOp = false;
m_pcSockLogFile=m_pcSockLogErrorFile=NULL;
......@@ -232,6 +235,8 @@ Socket::~Socket()
{
PLUTO_SAFETY_LOCK_ERRORSONLY(sSM,m_SocketMutex); // don't log anything but failures
Close();
if (m_bIsSSL)
SSL_free(m_pSSL);
sSM.Release();
}
......@@ -445,6 +450,7 @@ bool Socket::SendData( int iSize, const char *pcData )
#endif //LL_DEBUG
int iBytesLeft = iSize;
bool bWantRead = false, bWantWrite = true;
while( iBytesLeft > 0 )
{
fd_set wrfds;
......@@ -477,10 +483,14 @@ bool Socket::SendData( int iSize, const char *pcData )
tv.tv_sec = 1;
tv.tv_usec = 0;
//before select
gettimeofday(&tv_select_1, NULL);
//before select
gettimeofday(&tv_select_1, NULL);
iRet = select((int) (m_Socket+1), NULL, &wrfds, NULL, &tv);
// Default is to wait for write, but with SSL we might need to wait for read as well
if (bWantRead)
iRet = select((int) (m_Socket+1), &wrfds, NULL, NULL, &tv);
else if (bWantWrite || !m_bIsSSL)
iRet = select((int) (m_Socket+1), NULL, &wrfds, NULL, &tv);
//after select
gettimeofday(&tv_select_2, NULL);
......@@ -503,15 +513,44 @@ bool Socket::SendData( int iSize, const char *pcData )
if (iRet == 1)
{
int iSendBytes = ( iBytesLeft > 16192 ) ? 16192 : iBytesLeft;
iSendBytes = send( m_Socket, pcData+( iSize-iBytesLeft ), iSendBytes, 0 );
bWantRead = false;
bWantWrite = false;
if (m_bIsSSL)
{
int cnt = SSL_write( m_pSSL, pcData+( iSize-iBytesLeft ), iSendBytes );
int sslerr = SSL_get_error(m_pSSL, cnt);
switch (sslerr) {
case SSL_ERROR_WANT_WRITE:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::SendData() SSL Want WRITE");
bWantWrite = true;
break;
case SSL_ERROR_WANT_READ:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::SendData() SSL Want Read");
bWantRead = true;
break;
case SSL_ERROR_NONE:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Sent %d bytes", cnt);
iSendBytes = cnt;
break;
default:
LoggerWrapper::GetInstance()->Write( LV_WARNING, "Socket::SendData() SSL other");
DumpSSLError( LV_WARNING, sslerr );
break;
}
}
else
iSendBytes = send( m_Socket, pcData+( iSize-iBytesLeft ), iSendBytes, 0 );
if ( iSendBytes > 0 )
iBytesLeft -= iSendBytes;
else
if ( !bWantRead && !bWantWrite )
{
LoggerWrapper::GetInstance()->Write(LV_WARNING,"Socket::SendData sendbytes==0");
Close();
return false;
if ( iSendBytes > 0 )
iBytesLeft -= iSendBytes;
else
{
LoggerWrapper::GetInstance()->Write(LV_WARNING,"Socket::SendData sendbytes==0");
Close();
return false;
}
}
}
else
......@@ -712,6 +751,7 @@ bool Socket::ReceiveData( int iSize, char *pcData, int nTimeout/* = -1*/ )
clock_t clk_select1=0, clk_select1b=0, clk_select2=0, clk_select2b=0;
#endif
bool bWantRead = true, bWantWrite = false;
while( iBytesLeft > 0 )
{
if ( m_pcCurInsockBuffer )
......@@ -762,16 +802,23 @@ bool Socket::ReceiveData( int iSize, char *pcData, int nTimeout/* = -1*/ )
tv.tv_usec = 0;
}
//before select
gettimeofday(&tv_select_1, NULL);
iRet = select((int) (m_Socket+1), &rfds, NULL, NULL, &tv);
//after select
gettimeofday(&tv_select_2, NULL);
//the select took 'tv_select' time
tv_select = tv_select_2 - tv_select_1;
//before select
gettimeofday(&tv_select_1, NULL);
// Default is to wait for read, but with SSL we might need to wait for write as well
// With SSL, we can not always wait for available data, because SSL might have read all data to its internal buffer
// so we only wait when SSL tells us to (bWantRead/bWantWrite)
if ( bWantWrite )
iRet = select((int) (m_Socket+1), NULL, &rfds, NULL, &tv);
else if (bWantRead || !m_bIsSSL)
iRet = select((int) (m_Socket+1), &rfds, NULL, NULL, &tv);
//after select
gettimeofday(&tv_select_2, NULL);
//the select took 'tv_select' time
tv_select = tv_select_2 - tv_select_1;
tv_total -= tv_select;
#ifndef WINCE
if (errno == EINTR)
{
......@@ -779,7 +826,6 @@ bool Socket::ReceiveData( int iSize, char *pcData, int nTimeout/* = -1*/ )
iRet = 0;
}
#endif
tv_total -= tv_select;
#ifndef DISABLE_SOCKET_TIMEOUTS
} while (iRet != -1 && iRet != 1 && (nInternalReceiveTimeout > 0 || nInternalReceiveTimeout==-2 ? tv_total.tv_sec > 0 : true));
#else
......@@ -821,12 +867,41 @@ bool Socket::ReceiveData( int iSize, char *pcData, int nTimeout/* = -1*/ )
return false;
}
m_iSockBufBytesLeft = recv( m_Socket, m_pcInSockBuffer, INSOCKBUFFER_SIZE - 1, 0 );
bWantRead = false;
bWantWrite = false;
if (m_bIsSSL) {
int pos = 0;
int read = 0;
read = SSL_read(m_pSSL, m_pcInSockBuffer, INSOCKBUFFER_SIZE - 1);
int sslerr = SSL_get_error(m_pSSL, read);
switch (sslerr)
{
case SSL_ERROR_NONE:
m_iSockBufBytesLeft = read;
break;
case SSL_ERROR_WANT_READ:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::ReceiveData() SSL Want Read");
m_iSockBufBytesLeft = 0;
bWantRead = true;
break;
case SSL_ERROR_WANT_WRITE:
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::ReceiveData() SSL Want Write");
m_iSockBufBytesLeft = 0;
bWantWrite = true;
break;
default:
LoggerWrapper::GetInstance()->Write( LV_WARNING, "Socket::ReceiveData() SSL other");
DumpSSLError( LV_WARNING, sslerr );
break;
}
}
else
m_iSockBufBytesLeft = recv( m_Socket, m_pcInSockBuffer, INSOCKBUFFER_SIZE - 1, 0 );
#ifndef PLATFORM_PR_MC1_CABLE
if ( m_iSockBufBytesLeft <= 0 )
if ( m_iSockBufBytesLeft <= 0 && !bWantRead && !bWantWrite)
#else
if ( m_iSockBufBytesLeft < 0 )
if ( m_iSockBufBytesLeft < 0 && !bWantRead && !bWantWrite )
#endif
{
#ifdef WIN32
......@@ -843,7 +918,8 @@ bool Socket::ReceiveData( int iSize, char *pcData, int nTimeout/* = -1*/ )
return false;
}
m_pcCurInsockBuffer = m_pcInSockBuffer; // refreshing the current position
if (!bWantRead && !bWantWrite)
m_pcCurInsockBuffer = m_pcInSockBuffer; // refreshing the current position
#ifdef LL_DEBUG
char *pcTmp = new char[m_iSockBufBytesLeft +1]; // freed after writing to the file
......@@ -1002,6 +1078,8 @@ void Socket::Close()
if ( m_Socket != INVALID_SOCKET )
{
if (m_bIsSSL)
SSL_free(m_pSSL);
#ifdef DEBUG
int iResult2=closesocket( m_Socket );
LoggerWrapper::GetInstance()->Write( LV_SOCKET, "Socket::Close() m_Socket %d closesocket: %d", m_Socket, iResult2 );
......
......@@ -35,6 +35,8 @@ Header file for the Socket class
#include "DCE/Logger.h"
#include "DCE/Message.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
/**
@namespace DCE
......@@ -64,6 +66,10 @@ namespace DCE
bool m_bReceiveData_TimedOut; /** < this will become true if ReceiveData times out */
int m_nReceiveData_BytesLeft; /** < the number of bytes left to receive */
protected:
bool m_bIsSSL;
SSL *m_pSSL;
static string s_sSSL_key_path;
public:
enum SocketType { st_Unknown, st_ServerCommand, st_ServerEvent, st_ClientCommand, st_ClientEvent } m_eSocketType;
......@@ -104,7 +110,7 @@ namespace DCE
/**
* @brief creates a new socket objest with the specified name, and it also writes a log
*/
Socket( string sName,string sIPAddress="",string sMacAddress="" );
Socket( string sName,string sIPAddress="",string sMacAddress="", SSL* ssl=NULL, bool isSSL=false );
/**
* @brief frees the allocated memory and closes the base socket, and it also writes a log
......@@ -211,6 +217,26 @@ namespace DCE
virtual void PingFailed();
static class SocketInfo *g_mapSocketInfo_Find(int iSocketCounter,string sName,Socket *pSocket);
static void setSSLKeyPath(string path) { s_sSSL_key_path = path; }
void m_bIsSSL_set(bool b) {
m_bIsSSL = b;
if (m_bIsSSL) {
SSL_library_init();
SSL_load_error_strings();
}
}
static string getSSLKeyPath() { return s_sSSL_key_path; }
static void DumpSSLError(int level, unsigned long sslerr) {
char error[256];
ERR_error_string(sslerr, error);
LoggerWrapper::GetInstance()->Write( level, "%s", error );
unsigned long er = ERR_get_error();
while (er != 0) {
ERR_error_string_n(er, error, sizeof(error));
LoggerWrapper::GetInstance()->Write( level, "%s", error );
er = ERR_get_error();
}
}
bool m_bQuit_get() { return m_bQuit; }
void m_bQuit_set(bool bQuit)
{
......
This diff is collapsed.
......@@ -33,6 +33,9 @@ This will only remove the socket when the number of references is 1.
#include <string>
#include "ServerSocket.h"
#include "DCE/Logger.h"
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
namespace DCE
{
......@@ -56,6 +59,10 @@ namespace DCE
SOCKET m_Socket; /**< the socket that listens for incomming connections */
bool m_bAllowIncommingConnections;
bool m_bSSL; /** true if we should also start a SSL listening socket */
pthread_t m_SSLListenerThreadID; /**< the thread on witch the socket runs */
SOCKET m_SSLSocket; /**< the socket that listens for incomming connections */
SSL_CTX *m_sslctx;
public:
string m_sName; /**< the socket listener name */
......@@ -109,10 +116,14 @@ namespace DCE
*/
void Run();
/** Runs the SSL listener by creating the master socket, setting it up and telling it to start listening.
*/
void RunSSL();
/** Creates a socket listener based on the parameter data.
@see the class member data
*/
virtual Socket *CreateSocket( SOCKET newsock, string sName, string sIPAddress="", string sMacAddress="" );
virtual Socket *CreateSocket( SOCKET newsock, string sName, string sIPAddress="", string sMacAddress="", SSL *ssl=NULL, bool isSSL=false );
/** Removes the socket from the listClients mb data and clears any dependencies.
*/
......
......@@ -367,8 +367,8 @@ void DCEGen::CreateDeviceFile(class Row_DeviceTemplate *p_Row_DeviceTemplate,map
fstr_DeviceCommand << "\t/**" << endl;
fstr_DeviceCommand << "\t* @brief Constructors" << endl;
fstr_DeviceCommand << "\t*/" << endl;
fstr_DeviceCommand << "\t" << Name << "_Event(int DeviceID, string ServerAddress, bool bConnectEventHandler=true) :" << endl;
fstr_DeviceCommand << "\t\t" << "Event_Impl(DeviceID, " << GetDeviceTemplateConstStr(p_Row_DeviceTemplate) << ", ServerAddress, bConnectEventHandler, " << (bIsPlugin ? "SOCKET_TIMEOUT_PLUGIN" : "SOCKET_TIMEOUT") << ") {};" << endl;
fstr_DeviceCommand << "\t" << Name << "_Event(int DeviceID, string ServerAddress, bool bConnectEventHandler=true, bool bUseSSL=false) :" << endl;
fstr_DeviceCommand << "\t\t" << "Event_Impl(DeviceID, " << GetDeviceTemplateConstStr(p_Row_DeviceTemplate) << ", ServerAddress, bConnectEventHandler, " << (bIsPlugin ? "SOCKET_TIMEOUT_PLUGIN" : "SOCKET_TIMEOUT") << ", -1, bUseSSL) {};" << endl;
fstr_DeviceCommand << "\t" << Name << "_Event(class ClientSocket *pOCClientSocket, int DeviceID) : Event_Impl(pOCClientSocket, DeviceID) {};" << endl;
fstr_DeviceCommand << endl;
......@@ -542,7 +542,7 @@ void DCEGen::CreateDeviceFile(class Row_DeviceTemplate *p_Row_DeviceTemplate,map
fstr_DeviceCommand << "\tvirtual bool GetConfig()" << endl;
fstr_DeviceCommand << "\t{" << endl;
fstr_DeviceCommand << "\t\tm_pData=NULL;" << endl;
fstr_DeviceCommand << "\t\tm_pEvent = new " << Name << "_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode);" << endl;
fstr_DeviceCommand << "\t\tm_pEvent = new " << Name << "_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode, m_bIsSSL);" << endl;
fstr_DeviceCommand << "\t\tif( m_pEvent->m_dwPK_Device )" << endl;
fstr_DeviceCommand << "\t\t\tm_dwPK_Device = m_pEvent->m_dwPK_Device;" << endl;
fstr_DeviceCommand << "\t\tif( m_sIPAddress!=m_pEvent->m_pClientSocket->m_sIPAddress ) " << endl;
......@@ -556,7 +556,7 @@ void DCEGen::CreateDeviceFile(class Row_DeviceTemplate *p_Row_DeviceTemplate,map
fstr_DeviceCommand << "\t\t\t\twhile( m_pEvent->m_pClientSocket->m_eLastError==cs_err_BadDevice && (m_dwPK_Device = DeviceIdInvalid())!=0 )" << endl;
fstr_DeviceCommand << "\t\t\t\t{" << endl;
fstr_DeviceCommand << "\t\t\t\t\tdelete m_pEvent;" << endl;
fstr_DeviceCommand << "\t\t\t\t\tm_pEvent = new " << Name << "_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode);" << endl;
fstr_DeviceCommand << "\t\t\t\t\tm_pEvent = new " << Name << "_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode, m_bIsSSL);" << endl;
fstr_DeviceCommand << "\t\t\t\t\tif( m_pEvent->m_dwPK_Device )" << endl;
fstr_DeviceCommand << "\t\t\t\t\t\tm_dwPK_Device = m_pEvent->m_dwPK_Device;" << endl;
fstr_DeviceCommand << "\t\t\t\t}" << endl;
......@@ -566,7 +566,7 @@ void DCEGen::CreateDeviceFile(class Row_DeviceTemplate *p_Row_DeviceTemplate,map
fstr_DeviceCommand << "\t\t\t\tif( RouterNeedsReload() )" << endl;
fstr_DeviceCommand << "\t\t\t\t{" << endl;
fstr_DeviceCommand << "\t\t\t\t\tstring sResponse;" << endl;
fstr_DeviceCommand << "\t\t\t\t\tEvent_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);" << endl;
fstr_DeviceCommand << "\t\t\t\t\tEvent_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, SOCKET_TIMEOUT, -1, m_bIsSSL);" << endl;
fstr_DeviceCommand << "\t\t\t\t\tevent_Impl.m_pClientSocket->SendString( \"RELOAD\" );" << endl;
fstr_DeviceCommand << "\t\t\t\t\tif( !event_Impl.m_pClientSocket->ReceiveString( sResponse ) || sResponse!=\"OK\" )" << endl;
fstr_DeviceCommand << "\t\t\t\t\t{" << endl;
......@@ -602,7 +602,7 @@ void DCEGen::CreateDeviceFile(class Row_DeviceTemplate *p_Row_DeviceTemplate,map
fstr_DeviceCommand << "\t\t{" << endl;
fstr_DeviceCommand << "\t\t\tm_pData->m_dwPK_Device=m_dwPK_Device; // Assign this here since it didn't get it's own data" << endl;
fstr_DeviceCommand << "\t\t\tstring sResponse;" << endl;
fstr_DeviceCommand << "\t\t\tEvent_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);" << endl;
fstr_DeviceCommand << "\t\t\tEvent_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, -1, -1, m_bIsSSL);" << endl;
fstr_DeviceCommand << "\t\t\tevent_Impl.m_pClientSocket->SendString( \"PARENT \" + StringUtils::itos(m_dwPK_Device) );" << endl;
fstr_DeviceCommand << "\t\t\tif( event_Impl.m_pClientSocket->ReceiveString( sResponse ) && sResponse.size()>=8 )" << endl;
fstr_DeviceCommand << "\t\t\t\tm_pData->m_dwPK_Device_ControlledVia = atoi( sResponse.substr(7).c_str() );" << endl;
......@@ -615,7 +615,7 @@ void DCEGen::CreateDeviceFile(class Row_DeviceTemplate *p_Row_DeviceTemplate,map
fstr_DeviceCommand << "\t\t\treturn false;" << endl;
fstr_DeviceCommand << "\t\tdelete[] pConfig;" << endl;
fstr_DeviceCommand << "\t\tm_pData->m_pEvent_Impl = m_pEvent;" << endl;
fstr_DeviceCommand << "\t\tm_pcRequestSocket = new Event_Impl(m_dwPK_Device, " << GetDeviceTemplateConstStr(p_Row_DeviceTemplate) << ",m_sHostName);" << endl;
fstr_DeviceCommand << "\t\tm_pcRequestSocket = new Event_Impl(m_dwPK_Device, " << GetDeviceTemplateConstStr(p_Row_DeviceTemplate) << ",m_sHostName, true, -1, -1, m_bIsSSL);" << endl;
fstr_DeviceCommand << "\t\tif( m_iInstanceID )" << endl;
fstr_DeviceCommand << "\t\t{" << endl;
fstr_DeviceCommand << "\t\t\tm_pEvent->m_pClientSocket->SendString(\"INSTANCE \" + StringUtils::itos(m_iInstanceID));" << endl;
......
......@@ -118,6 +118,7 @@ int main(int argc, char* argv[])
string sLogger="stdout";
bool bLocalMode=false,bError=false; // An error parsing the command line
bool bUseSSL = false;
char c;
for(int optnum=1;optnum<argc;++optnum)
{
......@@ -136,12 +137,15 @@ int main(int argc, char* argv[])
case 'd':
PK_Device = atoi(argv[++optnum]);
break;
case 'L':
bLocalMode = true;
break;
case 'L':
bLocalMode = true;
break;
case 'l':
sLogger = argv[++optnum];
break;
case 's':
bUseSSL = true;
break;
default:
bError=true;
break;
......@@ -154,7 +158,8 @@ int main(int argc, char* argv[])
<< "Usage: DCE_Template [-r Router's IP] [-d My Device ID] [-l dcerouter|stdout|null|filename]" << endl
<< "-r -- the IP address of the DCE Router Defaults to 'dcerouter'." << endl
<< "-d -- This device's ID number. If not specified, it will be requested from the router based on our IP address." << endl
<< "-l -- Where to save the log files. Specify 'dcerouter' to have the messages logged to the DCE Router. Defaults to stdout." << endl;
<< "-l -- Where to save the log files. Specify 'dcerouter' to have the messages logged to the DCE Router. Defaults to stdout." << endl
<< "-s -- Connect using SSL." << endl;
exit(1);
}
......@@ -194,6 +199,7 @@ int main(int argc, char* argv[])
try
{
DCE_Template *pDCE_Template = new DCE_Template(PK_Device, sRouter_IP,true,bLocalMode);
pDCE_Template->m_bIsSSL_set(bUseSSL);
if ( pDCE_Template->GetConfig() && pDCE_Template->Connect(pDCE_Template->PK_DeviceTemplate_get()) )
{
g_pCommand_Impl=pDCE_Template;
......
......@@ -9,7 +9,7 @@ CXX = g++
CXXFLAGS = -Wall -fPIC -ggdb3
CPPFLAGS = -I$(ROOT) -I$(ROOT)/DCE $(SNR_CPPFLAGS)
LDFLAGS = $(SNR_LDFLAGS) -L$(ROOT)/lib
BASELDLIBS = -lSerializeClass -lDCECommon -lPlutoUtils -lpthread
BASELDLIBS = -lSerializeClass -lDCECommon -lPlutoUtils -lpthread -lssl -lcrypto
MYSQL_FLAGS := $(shell pkg-config --cflags mysqlclient 2>/dev/null)
MYSQL_LIBS := $(shell pkg-config --libs mysqlclient 2>/dev/null)
......
......@@ -31,8 +31,8 @@ public:
/**
* @brief Constructors
*/
Text_To_Speech_Event(int DeviceID, string ServerAddress, bool bConnectEventHandler=true) :
Event_Impl(DeviceID, DEVICETEMPLATE_Text_To_Speech_CONST, ServerAddress, bConnectEventHandler, SOCKET_TIMEOUT) {};
Text_To_Speech_Event(int DeviceID, string ServerAddress, bool bConnectEventHandler=true, bool bUseSSL=false) :
Event_Impl(DeviceID, DEVICETEMPLATE_Text_To_Speech_CONST, ServerAddress, bConnectEventHandler, SOCKET_TIMEOUT, -1, bUseSSL) {};
Text_To_Speech_Event(class ClientSocket *pOCClientSocket, int DeviceID) : Event_Impl(pOCClientSocket, DeviceID) {};
/**
......@@ -80,6 +80,14 @@ public:
* @brief Device data access methods:
*/
int Get_PK_Language()
{
if( m_bRunningWithoutDeviceData )
return atoi(m_pEvent_Impl->GetDeviceDataFromDatabase(m_dwPK_Device,DEVICEDATA_PK_Language_CONST).c_str());
else
return atoi(m_mapParameters[DEVICEDATA_PK_Language_CONST].c_str());
}
string Get_BranchNo()
{
if( m_bRunningWithoutDeviceData )
......@@ -112,7 +120,7 @@ public:
virtual bool GetConfig()
{
m_pData=NULL;
m_pEvent = new Text_To_Speech_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode);
m_pEvent = new Text_To_Speech_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode, m_bIsSSL);
if( m_pEvent->m_dwPK_Device )
m_dwPK_Device = m_pEvent->m_dwPK_Device;
if( m_sIPAddress!=m_pEvent->m_pClientSocket->m_sIPAddress )
......@@ -125,7 +133,7 @@ public:
while( m_pEvent->m_pClientSocket->m_eLastError==cs_err_BadDevice && (m_dwPK_Device = DeviceIdInvalid())!=0 )
{
delete m_pEvent;
m_pEvent = new Text_To_Speech_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode);
m_pEvent = new Text_To_Speech_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode, m_bIsSSL);
if( m_pEvent->m_dwPK_Device )
m_dwPK_Device = m_pEvent->m_dwPK_Device;
}
......@@ -135,7 +143,7 @@ public:
if( RouterNeedsReload() )
{
string sResponse;
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, SOCKET_TIMEOUT, -1, m_bIsSSL);
event_Impl.m_pClientSocket->SendString( "RELOAD" );
if( !event_Impl.m_pClientSocket->ReceiveString( sResponse ) || sResponse!="OK" )
{
......@@ -168,7 +176,7 @@ public:
{
m_pData->m_dwPK_Device=m_dwPK_Device; // Assign this here since it didn't get it's own data
string sResponse;
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, -1, -1, m_bIsSSL);
event_Impl.m_pClientSocket->SendString( "PARENT " + StringUtils::itos(m_dwPK_Device) );
if( event_Impl.m_pClientSocket->ReceiveString( sResponse ) && sResponse.size()>=8 )
m_pData->m_dwPK_Device_ControlledVia = atoi( sResponse.substr(7).c_str() );
......@@ -180,7 +188,7 @@ public:
return false;
delete[] pConfig;
m_pData->m_pEvent_Impl = m_pEvent;
m_pcRequestSocket = new Event_Impl(m_dwPK_Device, DEVICETEMPLATE_Text_To_Speech_CONST,m_sHostName);
m_pcRequestSocket = new Event_Impl(m_dwPK_Device, DEVICETEMPLATE_Text_To_Speech_CONST,m_sHostName, true, -1, -1, m_bIsSSL);
if( m_iInstanceID )
{
m_pEvent->m_pClientSocket->SendString("INSTANCE " + StringUtils::itos(m_iInstanceID));
......@@ -200,6 +208,7 @@ public:
virtual void ReceivedUnknownCommand(string &sCMD_Result,Message *pMessage) { };
Command_Impl *CreateCommand(int PK_DeviceTemplate, Command_Impl *pPrimaryDeviceCommand, DeviceData_Impl *pData, Event_Impl *pEvent);
//Data accessors
int DATA_Get_PK_Language() { return GetData()->Get_PK_Language(); }
string DATA_Get_BranchNo() { return GetData()->Get_BranchNo(); }
string DATA_Get_default_voice() { return GetData()->Get_default_voice(); }
//Event accessors
......
......@@ -25,7 +25,7 @@ Event_Impl *qOrbiter_Event::CreateEvent( unsigned long dwPK_DeviceTemplate, Clie
{
switch(dwPK_DeviceTemplate) {
case 2186:
return (Event_Impl *) new qOrbiter_Event(pOCClientSocket, dwDevice);
return (Event_Impl *) new qOrbiter_Event(pOCClientSocket, dwDevice);
};
LoggerWrapper::GetInstance()->Write(LV_STATUS, "Got CreateEvent for unknown type %d.", dwPK_DeviceTemplate);
return NULL;
......
......@@ -32,8 +32,8 @@ public:
/**
* @brief Constructors
*/
qOrbiter_Event(int DeviceID, string ServerAddress, bool bConnectEventHandler=true) :
Event_Impl(DeviceID, DEVICETEMPLATE_qOrbiter_CONST, ServerAddress, bConnectEventHandler, SOCKET_TIMEOUT) {};
qOrbiter_Event(int DeviceID, string ServerAddress, bool bConnectEventHandler=true, bool ssl=false) :
Event_Impl(DeviceID, DEVICETEMPLATE_qOrbiter_CONST, ServerAddress, bConnectEventHandler, SOCKET_TIMEOUT, -1, ssl) {};
qOrbiter_Event(class ClientSocket *pOCClientSocket, int DeviceID) : Event_Impl(pOCClientSocket, DeviceID) {};
/**
......@@ -369,7 +369,7 @@ public:
virtual bool GetConfig()
{
m_pData=NULL;
m_pEvent = new qOrbiter_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode);
m_pEvent = new qOrbiter_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode, m_bIsSSL);
if( m_pEvent->m_dwPK_Device )
m_dwPK_Device = m_pEvent->m_dwPK_Device;
if( m_sIPAddress!=m_pEvent->m_pClientSocket->m_sIPAddress )
......@@ -382,7 +382,7 @@ public:
while( m_pEvent->m_pClientSocket->m_eLastError==cs_err_BadDevice && (m_dwPK_Device = DeviceIdInvalid())!=0 )
{
delete m_pEvent;
m_pEvent = new qOrbiter_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode);
m_pEvent = new qOrbiter_Event(m_dwPK_Device, m_sHostName, !m_bLocalMode, m_bIsSSL);
if( m_pEvent->m_dwPK_Device )
m_dwPK_Device = m_pEvent->m_dwPK_Device;
}
......@@ -392,7 +392,7 @@ public:
if( RouterNeedsReload() )
{
string sResponse;
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName,true, -1, -1, m_bIsSSL);
event_Impl.m_pClientSocket->SendString( "RELOAD" );
if( !event_Impl.m_pClientSocket->ReceiveString( sResponse ) || sResponse!="OK" )
{
......@@ -425,7 +425,7 @@ public:
{
m_pData->m_dwPK_Device=m_dwPK_Device; // Assign this here since it didn't get it's own data
string sResponse;
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName);
Event_Impl event_Impl(DEVICEID_MESSAGESEND, 0, m_sHostName, true, -1, -1, m_bIsSSL);
event_Impl.m_pClientSocket->SendString( "PARENT " + StringUtils::itos(m_dwPK_Device) );
if( event_Impl.m_pClientSocket->ReceiveString( sResponse ) && sResponse.size()>=8 )
m_pData->m_dwPK_Device_ControlledVia = atoi( sResponse.substr(7).c_str() );
......@@ -437,7 +437,7 @@ public:
return false;
delete[] pConfig;
m_pData->m_pEvent_Impl = m_pEvent;
m_pcRequestSocket = new Event_Impl(m_dwPK_Device, DEVICETEMPLATE_qOrbiter_CONST,m_sHostName);
m_pcRequestSocket = new Event_Impl(m_dwPK_Device, DEVICETEMPLATE_qOrbiter_CONST,m_sHostName, true, -1, -1, m_bIsSSL);
if( m_iInstanceID )
{
m_pEvent->m_pClientSocket->SendString("INSTANCE " + StringUtils::itos(m_iInstanceID));
......
......@@ -42,7 +42,7 @@ private:
XRRScreenSize *m_pSizes;
DCE::LMCE_Launch_Manager * m_pLMCE_Launch_Manager;
UI m_uiMainUI;
DCE::UI m_uiMainUI;
vector<string> m_vCoreDevices;
vector<string> m_vMediaDevices;
bool m_bRemoteAssistanceRunning;
......
......@@ -13,26 +13,26 @@
#include <fstream>
using namespace std; //DCE
using namespace DCE;
#include "Gen_Devices/AllCommandsRequests.h"
//UI class method impmlementations
UI::UI()
DCE::UI::UI()
{
m_sTitle = "Generic CLI app";
m_bCenterTitle = false;
}
UI::~UI()
DCE::UI::~UI()
{
}
void UI::initialize(string sTitle, bool bCenterTitle)
void DCE::UI::initialize(string sTitle, bool bCenterTitle)
{
m_sTitle = sTitle;
m_bCenterTitle = bCenterTitle;
}
void UI::writeLog(string s)
void DCE::UI::writeLog(string s)
{
m_vLog.push_back(s);
if (m_vLog.size() > 10) {
......@@ -40,18 +40,18 @@ void UI::writeLog(string s)
}
draw();
}
void UI::appendLog(string s)
void DCE::UI::appendLog(string s)
{
m_vLog.pop_back();
m_vLog.push_back(s);
draw();
}
void UI::flushLog()
void DCE::UI::flushLog()
{
DCE::LoggerWrapper::GetInstance()->Flush();
}
void UI::draw()
void DCE::UI::draw()
{
system("clear"); //yes, I know this is not the best way to do it...
cout << " LinuxMCE Launch Manager, V1.0 " << endl;
......@@ -74,7 +74,7 @@ void UI::draw()
cout << m_vLog[i] << endl;
}
}
string UI::checkBox(string s)
string DCE::UI::checkBox(string s)
{
string sRet;
......@@ -85,7 +85,7 @@ string UI::checkBox(string s)
}
return sRet;
}
string UI::checkBox(bool b)
string DCE::UI::checkBox(bool b)
{
string sRet;
......@@ -96,36 +96,36 @@ string UI::checkBox(bool b)
}
return sRet;
}
void UI::setCoreIP(string thisIP)
void DCE::UI::setCoreIP(string thisIP)
{
m_sCoreIP = thisIP;
}
void UI::setVideoDriver(string thisVideoDriver)
void DCE::UI::setVideoDriver(string thisVideoDriver)
{
m_sVideoDriver = thisVideoDriver;
}
void UI::setVideoResolution(string thisVideoResolution)
void DCE::UI::setVideoResolution(string thisVideoResolution)
{
m_sVideoResolution = thisVideoResolution;
}
void UI::setMySQLInfo(string mysqlHost, string mysqlUser, string mysqlPass)
void DCE::UI::setMySQLInfo(string mysqlHost, string mysqlUser, string mysqlPass)
{
m_sMySQLHost = mysqlHost;
m_sMySQLUser = mysqlUser;
m_sMySQLPass = mysqlPass;
}
void UI::setAudioInfo(string thisSetting, bool thisAC3Pass)
void DCE::UI::setAudioInfo(string thisSetting, bool thisAC3Pass)
{
m_bAC3Pass = thisAC3Pass;
m_sSoundSetting = thisSetting;
}
void UI::setStatus(string sAutostartCore, string sAutostartMedia, bool bRemoteAssistance)
void DCE::UI::setStatus(string sAutostartCore, string sAutostartMedia, bool bRemoteAssistance)
{
m_sAutostartCore = sAutostartCore;
m_sAutostartMedia = sAutostartMedia;
m_bRemoteAssistanceRunning = bRemoteAssistance;
}
string UI::padString(std::string s, std::string sPad, int len)
string DCE::UI::padString(std::string s, std::string sPad, int len)
{
string sRet;
......@@ -140,7 +140,7 @@ string UI::padString(std::string s, std::string sPad, int len)
}
return s+sRet;
}
string UI::wrapTo(string s, int width)
string DCE::UI::wrapTo(string s, int width)
{
int len = s.length();
while (len>width) {
......
......@@ -6,6 +6,7 @@
#include "Gen_Devices/LMCE_Launch_ManagerBase.h"
#include <vector>
namespace DCE {
class UI
{
private:
......@@ -46,6 +47,7 @@ public:
};
class CB
{
private:
string m_sLabel;
......@@ -64,5 +66,5 @@ public:
};
};
#endif
/*
Main
Copyright (C) 2013 LinuxMCE
Copyright (C) 2004 Pluto, Inc., a Florida Corporation
www.linuxmce.org
www.plutohome.com
Phone: +1 (877) 758-8648
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
This program is distributed according to the terms of the Pluto Public License, available at:
http://plutohome.com/index.php?section=public_license
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the Pluto Public License for more details.
*/
*/
//<-dceag-incl-b->
#include "Text_To_Speech.h"
#include "DCE/Logger.h"
......@@ -25,6 +20,7 @@
#include "PlutoUtils/Other.h"
#include "DCERouter.h"
// include the main LMCE version file
#include "version.h"
using namespace DCE;
......@@ -70,6 +66,19 @@ void Plugin_SocketCrashHandler(Socket *pSocket)
}
//<-dceag-incl-e->
extern "C" {
int IsRuntimePlugin()
{
// If you want this plug-in to be able to register and be used even if it is not in the Device table, set this to true.
// Then the Router will scan for all .so or .dll files, and if found they will be registered with a temporary device number
bool bIsRuntimePlugin=false;
if( bIsRuntimePlugin )
return Text_To_Speech::PK_DeviceTemplate_get_static();
else
return 0;
}
}
//<-dceag-plug-b->
extern "C" {
......@@ -109,6 +118,7 @@ int main(int argc, char* argv[])
string sLogger="stdout";
bool bLocalMode=false,bError=false; // An error parsing the command line
bool bUseSSL = false;
char c;
for(int optnum=1;optnum<argc;++optnum)
{
......@@ -127,12 +137,15 @@ int main(int argc, char* argv[])
case 'd':
PK_Device = atoi(argv[++optnum]);
break;
case 'L':
bLocalMode = true;
break;
case 'L':
bLocalMode = true;
break;
case 'l':
sLogger = argv[++optnum];
break;
case 's':
bUseSSL = true;
break;
default:
bError=true;
break;
......@@ -145,7 +158,8 @@ int main(int argc, char* argv[])
<< "Usage: Text_To_Speech [-r Router's IP] [-d My Device ID] [-l dcerouter|stdout|null|filename]" << endl
<< "-r -- the IP address of the DCE Router Defaults to 'dcerouter'." << endl
<< "-d -- This device's ID number. If not specified, it will be requested from the router based on our IP address." << endl
<< "-l -- Where to save the log files. Specify 'dcerouter' to have the messages logged to the DCE Router. Defaults to stdout." << endl;
<< "-l -- Where to save the log files. Specify 'dcerouter' to have the messages logged to the DCE Router. Defaults to stdout." << endl
<< "-s -- Connect using SSL." << endl;
exit(1);
}
......@@ -185,6 +199,7 @@ int main(int argc, char* argv[])
try
{
Text_To_Speech *pText_To_Speech = new Text_To_Speech(PK_Device, sRouter_IP,true,bLocalMode);
pText_To_Speech->m_bIsSSL_set(bUseSSL);
if ( pText_To_Speech->GetConfig() && pText_To_Speech->Connect(pText_To_Speech->PK_DeviceTemplate_get()) )
{
g_pCommand_Impl=pText_To_Speech;
......
......@@ -2,13 +2,14 @@
GENDEV=../Gen_Devices
SNR_CPPFLAGS ?= -DKDE_LMCE -DDEBUG -DTHREAD_LOG -DLOG_ALL_QUERIES
SNR_LDFLAGS ?=
ROOT = ..
CXX = g++
CXXFLAGS = -Wall -fPIC -ggdb3
CPPFLAGS = -I$(ROOT) -I$(ROOT)/DCE $(SNR_CPPFLAGS)
LDFLAGS = -L$(ROOT)/lib
BASELDLIBS = -lSerializeClass -lDCECommon -lPlutoUtils -lpthread
LDFLAGS = $(SNR_LDFLAGS) -L$(ROOT)/lib
BASELDLIBS = -lSerializeClass -lDCECommon -lPlutoUtils -lpthread -lssl -lcrypto
MYSQL_FLAGS := $(shell pkg-config --cflags mysqlclient 2>/dev/null)
MYSQL_LIBS := $(shell pkg-config --libs mysqlclient 2>/dev/null)
......@@ -22,7 +23,7 @@ endif
MYNAME = Text_To_Speech
VERSION = 2.0.0
MYDEVTEMPLATEID = 57mplateID
MYDEVTEMPLATEID = 57
Gen_Dev_Files = $(GENDEV)/Text_To_SpeechBase.cpp
sources = Main.cpp Text_To_Speech.cpp $(Gen_Dev_Files)
......@@ -39,7 +40,7 @@ sources +=
#<-dceag-mf-b->
LDLIBS = $(XTRALDLIBS) $(BASELDLIBS)
whattodo:
whattodo: all
@echo "type 'make bin', 'make so' or 'make all'"
all: bin so
......@@ -50,29 +51,31 @@ so: Text_To_Speech.so
Text_To_Speech.so: $(sources:.cpp=.o)
$(CXX) -shared -o $(MYNAME).so $(call cpath,$+) $(LDFLAGS) $(LDLIBS)
mkdir -p ../bin
cp $@ ../bin
chmod +x post_make.sh
./post_make.sh $@
# chmod +x post_make.sh
# ./post_make.sh $@
Text_To_Speech: $(sources:.cpp=.o)
$(CXX) -o $(MYNAME) $(call cpath,$+) $(LDFLAGS) $(LDLIBS)
mkdir -p ../bin
cp $@ ../bin
./post_make.sh $@
# ./post_make.sh $@
clean: clean-recursive
rm -f $(call cpath,$(sources:.cpp=.o) $(sources:.cpp=.d)) Text_To_Speech.bin Text_To_Speech.so >/dev/null
rm -f $(call cpath,$(sources:.cpp=.o) $(sources:.cpp=.d)) Text_To_Speech Text_To_Speech.so >/dev/null
package:
chmod +x make_package.sh
./make_package.sh $(MYNAME) $(VERSION) $(MYDEVTEMPLATEID)
install:
mkdir -p $(DESTDIR)/usr/pluto/bin
cp Text_To_Speech $(DESTDIR)/usr/pluto/bin
include $(ROOT)/PlutoUtils/make.rules
ifeq (,$(findstring clean, $(MAKECMDGOALS)))
-include $(sources:.cpp=.d)
endif
#<-dceag-mf-e->
install:
mkdir -p /usr/pluto/bin
cp Text_To_Speech $(DESTPATH)/usr/pluto/bin
......@@ -250,6 +250,7 @@ int main(int argc, char* argv[])
#ifdef __ANDROID__
AndroidSystem androidHelper;
deviceType=2;
Socket::setSSLKeyPath(androidHelper.getExternalStorageLocation().toStdString()+"/LinuxMCE/");
#endif
QOrbiterLogger localLogger;
......@@ -431,6 +432,14 @@ int main(int argc, char* argv[])
qOrbiter pqOrbiter(name, PK_Device, sRouter_IP,true,bLocalMode );
pqOrbiter.setOsd(isOsd);
// If we are not on our home network, or if no device id is yet set, don't use SSL
// We need to connect once at our home network to get the SSL keys
//TODO: add when ssl works with qt+android qDebug() << OpenSSL_version(OPENSSL_VERSION) << endl;
QVariant deviceID = settings.getOption(SettingsInterfaceType::Settings_Network, SettingsKeyType::Setting_Network_Device_ID).toString();
bool useSSL = !isHomeNetwork && deviceID.toInt() > 0;
qDebug() << "useSSL " < <useSSL << " (" << isHomeNetwork << ", " << deviceID << ")";
pqOrbiter.m_bIsSSL_set(false); //useSSL);
qmlRegisterType<FloorplanDevice>("org.linuxmce.floorplans",1,0,"FloorplanDevice");
qmlRegisterType<MediaTypesHelper>("org.linuxmce.enums",1,0,"MediaTypes");
//qmlRegisterSingletonType<MediaTypesHelper>("media.enums",1,0,"MediaTypesHelper", "Data Only for linuxMCE MediaTypes");
......
......@@ -42,7 +42,10 @@ linux-rasp-pi-g++{
android-g++{
DESTDIR=$$[QT_INSTALL_PREFIX]/qml/AudioVisual
}
INCLUDEPATH += /home/mb/project/openssl/openssl-master/include/
LIBS += /home/mb/project/openssl/openssl-master/libssl.a
LIBS += /home/mb/project/openssl/openssl-master/libcrypto.a
}
macx-g++{
message( Building for OS x )
......
......@@ -118,6 +118,9 @@ android-g++{
} else{
QMLDIR_TARGET=../../../platforms/Android/androidComponents/DceScreenSaver/qmldir
}
INCLUDEPATH += /home/mb/project/openssl/openssl-master/include/
LIBS += /home/mb/project/openssl/openssl-master/libssl.a
LIBS += /home/mb/project/openssl/openssl-master/libcrypto.a
}
linux-g++{
......
......@@ -297,6 +297,7 @@ win32{
DEFINES += USE_MYSQL_WRAPPER
QT += network
}
LIBS += -lssl -lcrypto
CONFIG +=warn_off
......
......@@ -793,6 +793,33 @@ void qorbiterManager::processConfig(QNetworkReply *config)
QObject::connect(this, SIGNAL(resetFilter()), attribFilter, SLOT(clear()) );
}
#ifdef ANDROID
// DCE SSL keys
QDomElement keysElement = root.firstChildElement("Keys");
QDomNodeList keylist = keysElement.childNodes();
string path = Socket::getSSLKeyPath();
FileUtils::MakeDir(path + "CA");
DCE::LoggerWrapper::GetInstance()->Write(LV_WARNING, "Attempting to store keys at: %s", path.c_str());
for(int index = 0; index < keylist.count(); index++)
{
QString id = keylist.at(index).attributes().namedItem("id").nodeValue();
QString data = keylist.at(index).firstChild().toCDATASection().data();
string file = path;
if (id.toStdString() == "ca") {
FileUtils::MakeDir(path + "CA");
file += "CA/cacert.pem";
} else if (id.toStdString() == "client") {
file += "dce-client.key.pem";
} else if (id.toStdString() == "clientp") {
file += "dce-client.crt";
}
DCE::LoggerWrapper::GetInstance()->Write(LV_WARNING, "Attempting to write: %s", file.c_str());
string certData = data.toStdString();
FileUtils::WriteTextFile(file, certData.c_str());
}
#endif
binaryConfig.clear();
tConf.clear();
configData.clear();
......
......@@ -380,8 +380,11 @@ OTHER_FILES += \
android/src/org/kde/necessitas/origo/QtApplication.java
ANDROID_EXTRA_LIBS += $$_PRO_FILE_PWD_/../../../platforms/Android/androidPlugins/Qt5/armeabi-v7a/libAudioVisual.so #On Android we have a special case where we need to split locations in necessitas of the lib and qmldir, unlike desktop versions.
# ANDROID_EXTRA_LIBS += /home/mb/project/openssl/openssl-master/libssl.a
# ANDROID_EXTRA_LIBS += /home/mb/project/openssl/openssl-master/libcrypto.a
unix|win32: LIBS += $$PWD/../../../../../../../../../../../../../home/mb/project/openssl/openssl-master/libssl.a
unix|win32: LIBS += $$PWD/../../../../../../../../../../../../../home/mb/project/openssl/openssl-master/libcrypto.a
INCLUDEPATH += $$PWD/../../../../../../../../../../../../../home/mb/project/openssl/openssl-master/include
DEPENDPATH += $$PWD/../../../../../../../../../../../../../home/mb/project/openssl/openssl-master/include
......@@ -110,6 +110,10 @@ if (getFloorPlanDevices($conn, $doc, $orbiterData)) {
// echo "....done!<br>";
}
if (getKeys($conn, $doc, $orbiterData)) {
// echo "....done!<br>";
}
if (mysqli_close($conn)) {
//echo "DB closed";
}
......@@ -122,6 +126,33 @@ echo file_get_contents($orbiterConfPath);
//function area-----------------------------------------------------------------------------------
//get floorplan information
function getKeys($conn, $doc, $orbiterData) {
$keysElement = $doc -> createElement("Keys");
$orbiterData -> appendChild($keysElement);
$t = $doc -> createElement("Key");
$attrib2 = $t -> setAttribute("id", "ca");
$keysElement -> appendChild($t);
$c = $doc -> createCDATASection( str_replace("\n", "\r\n", file_get_contents("/etc/pluto/certs/CA/cacert.pem")) );
$t -> appendChild($c);
$t = $doc -> createElement("Key");
$attrib2 = $t -> setAttribute("id", "clientp");
$keysElement -> appendChild($t);
$c = $doc -> createCDATASection( str_replace("\n", "\r\n", file_get_contents("/etc/pluto/certs/dce-client.crt")) );
$t -> appendChild($c);
$t = $doc -> createElement("Key");
$attrib2 = $t -> setAttribute("id", "client");
$keysElement -> appendChild($t);
$c = $doc -> createCDATASection( str_replace("\n", "\r\n", file_get_contents("/etc/pluto/certs/dce-client.key.pem")) );
$t -> appendChild($c);
return true;
}
//get floorplan information
function getFloorplans($conn, $doc, $orbiterData) {
$sql = "SELECT * FROM `Floorplan` ";
......