From 72c5f4cc630c7c231348f46a506e049fdaf93654 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Fri, 23 Jan 2015 19:43:18 +0000 Subject: [PATCH] a licence agreement dialog can be requested by the server --- ChangeLog | 10 +++++++-- src/channel.cpp | 4 ++++ src/channel.h | 10 +++++---- src/client.cpp | 4 ++++ src/client.h | 1 + src/clientdlg.cpp | 30 ++++++++++++++++++++++++++- src/clientdlg.h | 1 + src/main.cpp | 53 +++++++++++++++++++++++++++++++---------------- src/protocol.cpp | 5 +++-- src/server.cpp | 30 +++++++++++++++++---------- src/server.h | 22 +++++++++++--------- src/testbench.h | 44 +++++++++++++++++++++++---------------- src/util.h | 3 ++- 13 files changed, 150 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7d4029e..96311f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,17 @@ -3.3.5 +3.3.6 + +- a licence agreement dialog can be requested by the server + + + +3.3.5 (2014-07-30) - new compile config options for disabling old CELT, use OPUS in a shared library and change the executable name - added a Linux jamulus.desktop file -3.3.4 +3.3.4 (2014-02-25) - true stereo reverberation effect (previously it was a mono reverberation effect on both stereo channels) diff --git a/src/channel.cpp b/src/channel.cpp index 01c76002..d5cf9274 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -111,6 +111,10 @@ QObject::connect ( &Protocol, QObject::connect ( &Protocol, SIGNAL ( ReqNetTranspProps() ), this, SLOT ( OnReqNetTranspProps() ) ); + + QObject::connect( &Protocol, + SIGNAL ( LicenceRequired ( ELicenceType ) ), + SIGNAL ( LicenceRequired ( ELicenceType ) ) ); } bool CChannel::ProtocolIsEnabled() diff --git a/src/channel.h b/src/channel.h index 3a98a5eb..91a1fde9 100755 --- a/src/channel.h +++ b/src/channel.h @@ -150,10 +150,11 @@ Protocol.CreateChanNameMes ( ChInfo.strName ); Protocol.CreateJitBufMes ( iJitBufSize ); } } - void CreateReqNetwTranspPropsMes() { Protocol.CreateReqNetwTranspPropsMes(); } - void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } - void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } - void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); } + void CreateReqNetwTranspPropsMes() { Protocol.CreateReqNetwTranspPropsMes(); } + void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } + void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } + void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); } + void CreateLicReqMes ( const ELicenceType eLicenceType ) { Protocol.CreateLicenceRequiredMes ( eLicenceType ); } // #### COMPATIBILITY OLD VERSION, TO BE REMOVED #### void CreateConClientListNameMes ( const CVector& vecChanInfo ) @@ -262,6 +263,7 @@ signals: void OpusSupported(); void ChatTextReceived ( QString strChatText ); void ReqNetTranspProps(); + void LicenceRequired ( ELicenceType eLicenceType ); void Disconnected(); void DetectedCLMessage ( CVector vecbyMesBodyData, diff --git a/src/client.cpp b/src/client.cpp index 90a25454..f34bd83e 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -182,6 +182,10 @@ CClient::CClient ( const quint16 iPortNumber ) : SIGNAL ( ChatTextReceived ( QString ) ), SIGNAL ( ChatTextReceived ( QString ) ) ); + QObject::connect( &Channel, + SIGNAL ( LicenceRequired ( ELicenceType ) ), + SIGNAL ( LicenceRequired ( ELicenceType ) ) ); + // #### COMPATIBILITY OLD VERSION, TO BE REMOVED #### #ifdef USE_LEGACY_CELT QObject::connect ( &Channel, SIGNAL ( OpusSupported() ), diff --git a/src/client.h b/src/client.h index e6c720e7..38f61599 100755 --- a/src/client.h +++ b/src/client.h @@ -417,6 +417,7 @@ signals: void ConClientListNameMesReceived ( CVector vecChanInfo ); void ConClientListMesReceived ( CVector vecChanInfo ); void ChatTextReceived ( QString strChatText ); + void LicenceRequired ( ELicenceType eLicenceType ); void PingTimeReceived ( int iPingTime ); void CLServerListReceived ( CHostAddress InetAddr, diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 3352f3d0..fefb7c55 100755 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -441,7 +441,16 @@ CClientDlg::CClientDlg ( CClient* pNCliP, SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceived ( QString ) ) ); - QObject::connect ( pClient, SIGNAL ( PingTimeReceived ( int ) ), + // This connection is a special case. On receiving a licence required message via the + // protocol, a modal licence dialog is opened. Since this blocks the thread, we need + // a queued connection to make sure the core protocol mechanism is not blocked, too. + qRegisterMetaType ( "ELicenceType" ); + QObject::connect ( pClient, + SIGNAL ( LicenceRequired ( ELicenceType ) ), + this, SLOT ( OnLicenceRequired ( ELicenceType ) ), Qt::QueuedConnection ); + + QObject::connect ( pClient, + SIGNAL ( PingTimeReceived ( int ) ), this, SLOT ( OnPingTimeResult ( int ) ) ); QObject::connect ( pClient, @@ -703,6 +712,25 @@ void CClientDlg::OnChatTextReceived ( QString strChatText ) UpdateDisplay(); } +void CClientDlg::OnLicenceRequired ( ELicenceType eLicenceType ) +{ + // right now only the creative common licence is supported + if ( eLicenceType == LT_CREATIVECOMMONS ) + { + CLicenceDlg LicenceDlg; + +// TODO mute the client + + // Open the licence dialog and check if the licence was accepted. In + // case the dialog is just closed or the decline button was pressed, + // disconnect from that server. + if ( !LicenceDlg.exec() ) + { + Disconnect(); + } + } +} + void CClientDlg::OnConClientListMesReceived ( CVector vecChanInfo ) { // update mixer board with the additional client infos diff --git a/src/clientdlg.h b/src/clientdlg.h index f77e5109..03f5c542 100755 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -158,6 +158,7 @@ public slots: void OnConClientListMesReceived ( CVector vecChanInfo ); void OnFaderTagTextChanged ( const QString& strNewName ); void OnChatTextReceived ( QString strChatText ); + void OnLicenceRequired ( ELicenceType eLicenceType ); void OnChangeChanGain ( int iId, double dGain ) { pClient->SetRemoteChanGain ( iId, dGain ); } diff --git a/src/main.cpp b/src/main.cpp index da91cb9f..3827c741 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,23 +53,24 @@ int main ( int argc, char** argv ) // initialize all flags and string which might be changed by command line // arguments - bool bIsClient = true; - bool bUseGUI = true; - bool bStartMinimized = false; - bool bConnectOnStartup = false; - bool bShowComplRegConnList = false; - bool bShowAnalyzerConsole = false; - bool bCentServPingServerInList = false; - int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; - quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; - QString strIniFileName = ""; - QString strHTMLStatusFileName = ""; - QString strServerName = ""; - QString strLoggingFileName = ""; - QString strHistoryFileName = ""; - QString strCentralServer = ""; - QString strServerInfo = ""; - QString strWelcomeMessage = ""; + bool bIsClient = true; + bool bUseGUI = true; + bool bStartMinimized = false; + bool bConnectOnStartup = false; + bool bShowComplRegConnList = false; + bool bShowAnalyzerConsole = false; + bool bCentServPingServerInList = false; + int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; + quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; + ELicenceType eLicenceType = LT_NO_LICENCE; + QString strIniFileName = ""; + QString strHTMLStatusFileName = ""; + QString strServerName = ""; + QString strLoggingFileName = ""; + QString strHistoryFileName = ""; + QString strCentralServer = ""; + QString strServerInfo = ""; + QString strWelcomeMessage = ""; // QT docu: argv()[0] is the program name, argv()[1] is the first // argument and argv()[argc()-1] is the last argument. @@ -100,6 +101,19 @@ int main ( int argc, char** argv ) } + // Use licence flag ---------------------------------------------------- + if ( GetFlagArgument ( argv, + i, + "-L", + "--licence" ) ) + { + // right now only the creative commons licence is supported + eLicenceType = LT_CREATIVECOMMONS; + tsConsole << "- licence required" << endl; + continue; + } + + // Maximum number of channels ------------------------------------------ if ( GetNumericArgument ( tsConsole, argc, @@ -419,7 +433,8 @@ int main ( int argc, char** argv ) strCentralServer, strServerInfo, strWelcomeMessage, - bCentServPingServerInList ); + bCentServPingServerInList, + eLicenceType ); if ( bUseGUI ) { @@ -507,6 +522,8 @@ QString UsageArguments ( char **argv ) " -h, -?, --help this help text\n" " -i, --inifile initialization file name (client only)\n" " -l, --log enable logging, set file name\n" + " -L, --licence a licence must be accepted on a new\n" + " connection (server only)\n" " -m, --htmlstatus enable HTML status file, set file name (server\n" " only)\n" " -n, --nogui disable GUI (server only)\n" diff --git a/src/protocol.cpp b/src/protocol.cpp index 8a48f8de..12c67e26 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -200,7 +200,7 @@ CONNECTION LESS MESSAGES +-----------------------------+---------------------------------+ -- PROTMESSID_SERVER_FULL: Connection less server full message +- PROTMESSID_CLM_SERVER_FULL: Connection less server full message note: does not have any data -> n = 0 @@ -1359,7 +1359,8 @@ bool CProtocol::EvaluateLicenceRequiredMes ( const CVector& vecData ) const ELicenceType eLicenceType = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); - if ( eLicenceType != LT_CREATIVECOMMONS ) + if ( ( eLicenceType != LT_CREATIVECOMMONS ) && + ( eLicenceType != LT_NO_LICENCE ) ) { return true; // return error code } diff --git a/src/server.cpp b/src/server.cpp index b0d6f3f1..a2d3a238 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -197,16 +197,17 @@ void CHighPrecisionTimer::run() // CServer implementation ****************************************************** -CServer::CServer ( const int iNewMaxNumChan, - const QString& strLoggingFileName, - const quint16 iPortNumber, - const QString& strHTMLStatusFileName, - const QString& strHistoryFileName, - const QString& strServerNameForHTMLStatusFile, - const QString& strCentralServer, - const QString& strServerInfo, - const QString& strNewWelcomeMessage, - const bool bNCentServPingServerInList ) : +CServer::CServer ( const int iNewMaxNumChan, + const QString& strLoggingFileName, + const quint16 iPortNumber, + const QString& strHTMLStatusFileName, + const QString& strHistoryFileName, + const QString& strServerNameForHTMLStatusFile, + const QString& strCentralServer, + const QString& strServerInfo, + const QString& strNewWelcomeMessage, + const bool bNCentServPingServerInList, + const ELicenceType eNLicenceType ) : iMaxNumChannels ( iNewMaxNumChan ), Socket ( this, iPortNumber ), bWriteStatusHTMLFile ( false ), @@ -217,7 +218,8 @@ CServer::CServer ( const int iNewMaxNumChan, bNCentServPingServerInList, &ConnLessProtocol ), bAutoRunMinimized ( false ), - strWelcomeMessage ( strNewWelcomeMessage ) + strWelcomeMessage ( strNewWelcomeMessage ), + eLicenceType ( eNLicenceType ) { int iOpusError; int i; @@ -608,6 +610,12 @@ CreateAndSendChanListForAllConChannels(); vecChannels[iChID].CreateChatTextMes ( strWelcomeMessageFormated ); } + + // send licence request message (if enabled) + if ( eLicenceType != LT_NO_LICENCE ) + { + vecChannels[iChID].CreateLicReqMes ( eLicenceType ); + } } void CServer::OnServerFull ( CHostAddress RecHostAddr ) diff --git a/src/server.h b/src/server.h index 7780216b..ca72072e 100755 --- a/src/server.h +++ b/src/server.h @@ -121,16 +121,17 @@ class CServer : public QObject Q_OBJECT public: - CServer ( const int iNewMaxNumChan, - const QString& strLoggingFileName, - const quint16 iPortNumber, - const QString& strHTMLStatusFileName, - const QString& strHistoryFileName, - const QString& strServerNameForHTMLStatusFile, - const QString& strCentralServer, - const QString& strServerInfo, - const QString& strNewWelcomeMessage, - const bool bNCentServPingServerInList ); + CServer ( const int iNewMaxNumChan, + const QString& strLoggingFileName, + const quint16 iPortNumber, + const QString& strHTMLStatusFileName, + const QString& strHistoryFileName, + const QString& strServerNameForHTMLStatusFile, + const QString& strCentralServer, + const QString& strServerInfo, + const QString& strNewWelcomeMessage, + const bool bNCentServPingServerInList, + const ELicenceType eNLicenceType ); void Start(); void Stop(); @@ -271,6 +272,7 @@ protected: // messaging QString strWelcomeMessage; + ELicenceType eLicenceType; signals: void Started(); diff --git a/src/testbench.h b/src/testbench.h index b8249781..d6c8c649 100755 --- a/src/testbench.h +++ b/src/testbench.h @@ -104,9 +104,10 @@ public slots: CVector vecServerInfo ( 1 ); CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort ); CChannelCoreInfo ChannelCoreInfo; + ELicenceType eLicenceType; // generate random protocol message - switch ( GenRandomIntInRange ( 0, 26 ) ) + switch ( GenRandomIntInRange ( 0, 27 ) ) { case 0: // PROTMESSID_JITT_BUF_SIZE Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) ); @@ -167,7 +168,14 @@ public slots: Protocol.CreateChatTextMes ( GenRandomString() ); break; - case 10: // PROTMESSID_NETW_TRANSPORT_PROPS + case 10: // PROTMESSID_LICENCE_REQUIRED + eLicenceType = + static_cast ( GenRandomIntInRange ( 0, 1 ) ); + + Protocol.CreateLicenceRequiredMes ( eLicenceType ); + break; + + case 11: // PROTMESSID_NETW_TRANSPORT_PROPS NetTrProps.eAudioCodingType = static_cast ( GenRandomIntInRange ( 0, 2 ) ); @@ -181,30 +189,30 @@ public slots: Protocol.CreateNetwTranspPropsMes ( NetTrProps ); break; - case 11: // PROTMESSID_REQ_NETW_TRANSPORT_PROPS + case 12: // PROTMESSID_REQ_NETW_TRANSPORT_PROPS Protocol.CreateReqNetwTranspPropsMes(); break; - case 12: // PROTMESSID_OPUS_SUPPORTED + case 13: // PROTMESSID_OPUS_SUPPORTED Protocol.CreateOpusSupportedMes(); break; - case 13: // PROTMESSID_CLM_PING_MS + case 14: // PROTMESSID_CLM_PING_MS Protocol.CreateCLPingMes ( CurHostAddress, GenRandomIntInRange ( -2, 1000 ) ); break; - case 14: // PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS + case 15: // PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS Protocol.CreateCLPingWithNumClientsMes ( CurHostAddress, GenRandomIntInRange ( -2, 1000 ), GenRandomIntInRange ( -2, 1000 ) ); break; - case 15: // PROTMESSID_CLM_SERVER_FULL + case 16: // PROTMESSID_CLM_SERVER_FULL Protocol.CreateCLServerFullMes ( CurHostAddress ); break; - case 16: // PROTMESSID_CLM_REGISTER_SERVER + case 17: // PROTMESSID_CLM_REGISTER_SERVER ServerInfo.bPermanentOnline = static_cast ( GenRandomIntInRange ( 0, 1 ) ); @@ -221,11 +229,11 @@ public slots: ServerInfo ); break; - case 17: // PROTMESSID_CLM_UNREGISTER_SERVER + case 18: // PROTMESSID_CLM_UNREGISTER_SERVER Protocol.CreateCLUnregisterServerMes ( CurHostAddress ); break; - case 18: // PROTMESSID_CLM_SERVER_LIST + case 19: // PROTMESSID_CLM_SERVER_LIST vecServerInfo[0].bPermanentOnline = static_cast ( GenRandomIntInRange ( 0, 1 ) ); @@ -243,37 +251,37 @@ public slots: vecServerInfo ); break; - case 19: // PROTMESSID_CLM_REQ_SERVER_LIST + case 20: // PROTMESSID_CLM_REQ_SERVER_LIST Protocol.CreateCLReqServerListMes ( CurHostAddress ); break; - case 20: // PROTMESSID_CLM_SEND_EMPTY_MESSAGE + case 21: // PROTMESSID_CLM_SEND_EMPTY_MESSAGE Protocol.CreateCLSendEmptyMesMes ( CurHostAddress, CurHostAddress ); break; - case 21: // PROTMESSID_CLM_EMPTY_MESSAGE + case 22: // PROTMESSID_CLM_EMPTY_MESSAGE Protocol.CreateCLEmptyMes ( CurHostAddress ); break; - case 22: // PROTMESSID_CLM_DISCONNECTION + case 23: // PROTMESSID_CLM_DISCONNECTION Protocol.CreateCLDisconnection ( CurHostAddress ); break; - case 23: // PROTMESSID_CLM_VERSION_AND_OS + case 24: // PROTMESSID_CLM_VERSION_AND_OS Protocol.CreateCLVersionAndOSMes ( CurHostAddress ); break; - case 24: // PROTMESSID_CLM_REQ_VERSION_AND_OS + case 25: // PROTMESSID_CLM_REQ_VERSION_AND_OS Protocol.CreateCLReqVersionAndOSMes ( CurHostAddress ); break; - case 25: // PROTMESSID_ACKN + case 26: // PROTMESSID_ACKN Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ), GenRandomIntInRange ( -100, 100 ) ); break; - case 26: + case 27: // arbitrary "audio" packet (with random sizes) CVector vecMessage ( GenRandomIntInRange ( 1, 1000 ) ); OnSendProtMessage ( vecMessage ); diff --git a/src/util.h b/src/util.h index d9e5e343..be54b8c6 100755 --- a/src/util.h +++ b/src/util.h @@ -502,7 +502,8 @@ enum EGUIDesign enum ELicenceType { // used for protocol -> enum values must be fixed! - LT_CREATIVECOMMONS = 0 + LT_NO_LICENCE = 0, + LT_CREATIVECOMMONS = 1 };