mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
Revert/fix hatchet/websocket logging
This commit is contained in:
@@ -53,7 +53,7 @@ HatchetSipPlugin::HatchetSipPlugin( Tomahawk::Accounts::Account *account )
|
|||||||
|
|
||||||
QFile pemFile( ":/hatchet-account/dreamcatcher.pem" );
|
QFile pemFile( ":/hatchet-account/dreamcatcher.pem" );
|
||||||
pemFile.open( QIODevice::ReadOnly );
|
pemFile.open( QIODevice::ReadOnly );
|
||||||
tDebug() << Q_FUNC_INFO << "certs/dreamcatcher.pem: " << pemFile.readAll();
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "certs/dreamcatcher.pem: " << pemFile.readAll();
|
||||||
pemFile.close();
|
pemFile.close();
|
||||||
pemFile.open( QIODevice::ReadOnly );
|
pemFile.open( QIODevice::ReadOnly );
|
||||||
QCA::ConvertResult conversionResult;
|
QCA::ConvertResult conversionResult;
|
||||||
@@ -217,7 +217,7 @@ HatchetSipPlugin::webSocketConnected()
|
|||||||
QCA::SecureArray sa( m_uuid.toLatin1() );
|
QCA::SecureArray sa( m_uuid.toLatin1() );
|
||||||
QCA::SecureArray result = m_publicKey->encrypt( sa, QCA::EME_PKCS1_OAEP );
|
QCA::SecureArray result = m_publicKey->encrypt( sa, QCA::EME_PKCS1_OAEP );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "uuid:" << m_uuid << ", size of uuid:" << m_uuid.size() << ", size of sa:" << sa.size() << ", size of result:" << result.size();
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "uuid:" << m_uuid << ", size of uuid:" << m_uuid.size() << ", size of sa:" << sa.size() << ", size of result:" << result.size();
|
||||||
|
|
||||||
QVariantMap nonceVerMap;
|
QVariantMap nonceVerMap;
|
||||||
nonceVerMap[ "version" ] = VERSION;
|
nonceVerMap[ "version" ] = VERSION;
|
||||||
@@ -261,7 +261,6 @@ HatchetSipPlugin::webSocketDisconnected()
|
|||||||
bool
|
bool
|
||||||
HatchetSipPlugin::sendBytes( const QVariantMap& jsonMap ) const
|
HatchetSipPlugin::sendBytes( const QVariantMap& jsonMap ) const
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO;
|
|
||||||
if ( m_sipState == Closed )
|
if ( m_sipState == Closed )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "was told to send bytes on a closed connection, not gonna do it";
|
tLog() << Q_FUNC_INFO << "was told to send bytes on a closed connection, not gonna do it";
|
||||||
@@ -276,7 +275,7 @@ HatchetSipPlugin::sendBytes( const QVariantMap& jsonMap ) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "Sending bytes of size" << bytes.size();
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Sending bytes of size" << bytes.size();
|
||||||
emit rawBytes( bytes );
|
emit rawBytes( bytes );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -285,7 +284,7 @@ HatchetSipPlugin::sendBytes( const QVariantMap& jsonMap ) const
|
|||||||
void
|
void
|
||||||
HatchetSipPlugin::messageReceived( const QByteArray &msg )
|
HatchetSipPlugin::messageReceived( const QByteArray &msg )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "WebSocket message: " << msg;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WebSocket message: " << msg;
|
||||||
|
|
||||||
QJson::Parser parser;
|
QJson::Parser parser;
|
||||||
bool ok;
|
bool ok;
|
||||||
@@ -553,7 +552,6 @@ HatchetSipPlugin::sendOplog( const QVariantMap& valMap ) const
|
|||||||
void
|
void
|
||||||
HatchetSipPlugin::oplogFetched( const QString& sinceguid, const QString& /* lastguid */, const QList< dbop_ptr > ops )
|
HatchetSipPlugin::oplogFetched( const QString& sinceguid, const QString& /* lastguid */, const QList< dbop_ptr > ops )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
|
||||||
const uint_fast32_t byteMax = 1 << 25;
|
const uint_fast32_t byteMax = 1 << 25;
|
||||||
int currBytes = 0;
|
int currBytes = 0;
|
||||||
QVariantMap commandMap;
|
QVariantMap commandMap;
|
||||||
|
@@ -31,7 +31,7 @@ WebSocket::WebSocket( const QString& url )
|
|||||||
, m_lastSocketState( QAbstractSocket::UnconnectedState )
|
, m_lastSocketState( QAbstractSocket::UnconnectedState )
|
||||||
, m_connectionTimer( this )
|
, m_connectionTimer( this )
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "WebSocket constructing";
|
tLog() << Q_FUNC_INFO << "WebSocket constructing";
|
||||||
m_client = std::unique_ptr< hatchet_client >( new hatchet_client() );
|
m_client = std::unique_ptr< hatchet_client >( new hatchet_client() );
|
||||||
m_client->set_message_handler( std::bind(&onMessage, this, std::placeholders::_1, std::placeholders::_2 ) );
|
m_client->set_message_handler( std::bind(&onMessage, this, std::placeholders::_1, std::placeholders::_2 ) );
|
||||||
m_client->set_close_handler( std::bind(&onClose, this, std::placeholders::_1 ) );
|
m_client->set_close_handler( std::bind(&onClose, this, std::placeholders::_1 ) );
|
||||||
@@ -58,7 +58,7 @@ WebSocket::~WebSocket()
|
|||||||
void
|
void
|
||||||
WebSocket::setUrl( const QString &url )
|
WebSocket::setUrl( const QString &url )
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Setting url to" << url;
|
tLog() << Q_FUNC_INFO << "Setting url to" << url;
|
||||||
if ( m_url == url )
|
if ( m_url == url )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ WebSocket::setUrl( const QString &url )
|
|||||||
void
|
void
|
||||||
WebSocket::connectWs()
|
WebSocket::connectWs()
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Connecting";
|
tLog() << Q_FUNC_INFO << "Connecting";
|
||||||
m_disconnecting = false;
|
m_disconnecting = false;
|
||||||
if ( m_socket )
|
if ( m_socket )
|
||||||
{
|
{
|
||||||
@@ -99,7 +99,7 @@ WebSocket::connectWs()
|
|||||||
void
|
void
|
||||||
WebSocket::disconnectWs( websocketpp::close::status::value status, const QString &reason )
|
WebSocket::disconnectWs( websocketpp::close::status::value status, const QString &reason )
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Disconnecting";
|
tLog() << Q_FUNC_INFO << "Disconnecting";
|
||||||
m_disconnecting = true;
|
m_disconnecting = true;
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
@@ -130,7 +130,7 @@ WebSocket::disconnectSocket()
|
|||||||
void
|
void
|
||||||
WebSocket::cleanup()
|
WebSocket::cleanup()
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Cleaning up";
|
tLog() << Q_FUNC_INFO << "Cleaning up";
|
||||||
m_outputStream.seekg( std::ios_base::end );
|
m_outputStream.seekg( std::ios_base::end );
|
||||||
m_outputStream.seekp( std::ios_base::end );
|
m_outputStream.seekp( std::ios_base::end );
|
||||||
m_queuedMessagesToSend.empty();
|
m_queuedMessagesToSend.empty();
|
||||||
@@ -144,14 +144,14 @@ WebSocket::cleanup()
|
|||||||
void
|
void
|
||||||
WebSocket::socketStateChanged( QAbstractSocket::SocketState state )
|
WebSocket::socketStateChanged( QAbstractSocket::SocketState state )
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Socket state changed to" << state;
|
tLog() << Q_FUNC_INFO << "Socket state changed to" << state;
|
||||||
switch ( state )
|
switch ( state )
|
||||||
{
|
{
|
||||||
case QAbstractSocket::ClosingState:
|
case QAbstractSocket::ClosingState:
|
||||||
if ( m_lastSocketState == QAbstractSocket::ClosingState )
|
if ( m_lastSocketState == QAbstractSocket::ClosingState )
|
||||||
{
|
{
|
||||||
// It seems like it does not actually properly close, so force it
|
// It seems like it does not actually properly close, so force it
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Got a double closing state, cleaning up and emitting disconnected";
|
tLog() << Q_FUNC_INFO << "Got a double closing state, cleaning up and emitting disconnected";
|
||||||
m_socket->deleteLater();
|
m_socket->deleteLater();
|
||||||
m_lastSocketState = QAbstractSocket::UnconnectedState;
|
m_lastSocketState = QAbstractSocket::UnconnectedState;
|
||||||
QMetaObject::invokeMethod( this, "cleanup", Qt::QueuedConnection );
|
QMetaObject::invokeMethod( this, "cleanup", Qt::QueuedConnection );
|
||||||
@@ -161,7 +161,7 @@ WebSocket::socketStateChanged( QAbstractSocket::SocketState state )
|
|||||||
case QAbstractSocket::UnconnectedState:
|
case QAbstractSocket::UnconnectedState:
|
||||||
if ( m_lastSocketState == QAbstractSocket::UnconnectedState )
|
if ( m_lastSocketState == QAbstractSocket::UnconnectedState )
|
||||||
return;
|
return;
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Socket now unconnected, cleaning up and emitting disconnected";
|
tLog() << Q_FUNC_INFO << "Socket now unconnected, cleaning up and emitting disconnected";
|
||||||
m_socket->deleteLater();
|
m_socket->deleteLater();
|
||||||
m_lastSocketState = QAbstractSocket::UnconnectedState;
|
m_lastSocketState = QAbstractSocket::UnconnectedState;
|
||||||
QMetaObject::invokeMethod( this, "cleanup", Qt::QueuedConnection );
|
QMetaObject::invokeMethod( this, "cleanup", Qt::QueuedConnection );
|
||||||
@@ -186,7 +186,7 @@ WebSocket::sslErrors( const QList< QSslError >& errors )
|
|||||||
void
|
void
|
||||||
WebSocket::encrypted()
|
WebSocket::encrypted()
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Encrypted connection to Dreamcatcher established";
|
tLog() << Q_FUNC_INFO << "Encrypted connection to Dreamcatcher established";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
||||||
QUrl url(m_url);
|
QUrl url(m_url);
|
||||||
@@ -211,16 +211,13 @@ WebSocket::readOutput()
|
|||||||
if ( !m_connection )
|
if ( !m_connection )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//tDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
std::string outputString = m_outputStream.str();
|
std::string outputString = m_outputStream.str();
|
||||||
if ( outputString.size() > 0 )
|
if ( outputString.size() > 0 )
|
||||||
{
|
{
|
||||||
m_outputStream.str("");
|
m_outputStream.str("");
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Got string of size" << outputString.size() << "from ostream";
|
|
||||||
qint64 sizeWritten = m_socket->write( outputString.data(), outputString.size() );
|
qint64 sizeWritten = m_socket->write( outputString.data(), outputString.size() );
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Wrote" << sizeWritten << "bytes to the socket";
|
tDebug() << Q_FUNC_INFO << "Got " << outputString.size() << "from outstream, wrote" << sizeWritten << "bytes to the socket";
|
||||||
if ( sizeWritten == -1 )
|
if ( sizeWritten == -1 )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Error during writing, closing connection";
|
tLog() << Q_FUNC_INFO << "Error during writing, closing connection";
|
||||||
@@ -235,7 +232,7 @@ WebSocket::readOutput()
|
|||||||
{
|
{
|
||||||
foreach( QByteArray message, m_queuedMessagesToSend )
|
foreach( QByteArray message, m_queuedMessagesToSend )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Sending queued message of size" << message.size();
|
tDebug() << Q_FUNC_INFO << "Sending queued message of size" << message.size();
|
||||||
m_connection->send( std::string( message.constData(), message.size() ), websocketpp::frame::opcode::TEXT );
|
m_connection->send( std::string( message.constData(), message.size() ), websocketpp::frame::opcode::TEXT );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +250,6 @@ WebSocket::readOutput()
|
|||||||
void
|
void
|
||||||
WebSocket::socketReadyRead()
|
WebSocket::socketReadyRead()
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
if ( !m_socket || !m_socket->isEncrypted() )
|
if ( !m_socket || !m_socket->isEncrypted() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -267,11 +262,10 @@ WebSocket::socketReadyRead()
|
|||||||
|
|
||||||
if ( qint64 bytes = m_socket->bytesAvailable() )
|
if ( qint64 bytes = m_socket->bytesAvailable() )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Bytes available:" << bytes;
|
|
||||||
QByteArray buf;
|
QByteArray buf;
|
||||||
buf.resize( bytes );
|
buf.resize( bytes );
|
||||||
qint64 bytesRead = m_socket->read( buf.data(), bytes );
|
qint64 bytesRead = m_socket->read( buf.data(), bytes );
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Bytes read:" << bytesRead; // << ", content is" << websocketpp::utility::to_hex( buf.constData(), bytesRead ).data();
|
tDebug() << Q_FUNC_INFO << "Bytes available: " << bytes << ", bytes read:" << bytesRead; // << ", content is" << websocketpp::utility::to_hex( buf.constData(), bytesRead ).data();
|
||||||
if ( bytesRead != bytes )
|
if ( bytesRead != bytes )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Error occurred during socket read. Something is wrong; disconnecting";
|
tLog() << Q_FUNC_INFO << "Error occurred during socket read. Something is wrong; disconnecting";
|
||||||
@@ -289,7 +283,6 @@ WebSocket::socketReadyRead()
|
|||||||
void
|
void
|
||||||
WebSocket::encodeMessage( const QByteArray &bytes )
|
WebSocket::encodeMessage( const QByteArray &bytes )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Encoding message"; //, message is" << bytes.constData();
|
|
||||||
if ( !m_connection )
|
if ( !m_connection )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Asked to send message but do not have a valid connection!";
|
tLog() << Q_FUNC_INFO << "Asked to send message but do not have a valid connection!";
|
||||||
@@ -298,7 +291,7 @@ WebSocket::encodeMessage( const QByteArray &bytes )
|
|||||||
|
|
||||||
if ( m_connection->get_state() != websocketpp::session::state::open )
|
if ( m_connection->get_state() != websocketpp::session::state::open )
|
||||||
{
|
{
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Connection not yet open/upgraded, queueing work to send";
|
tLog() << Q_FUNC_INFO << "Connection not yet open/upgraded, queueing work to send";
|
||||||
m_queuedMessagesToSend.append( bytes );
|
m_queuedMessagesToSend.append( bytes );
|
||||||
m_connectionTimer.start();
|
m_connectionTimer.start();
|
||||||
}
|
}
|
||||||
@@ -311,7 +304,7 @@ WebSocket::encodeMessage( const QByteArray &bytes )
|
|||||||
void
|
void
|
||||||
onMessage( WebSocket* ws, websocketpp::connection_hdl, hatchet_client::message_ptr msg )
|
onMessage( WebSocket* ws, websocketpp::connection_hdl, hatchet_client::message_ptr msg )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Handling message";
|
tDebug() << Q_FUNC_INFO << "Handling message";
|
||||||
std::string payload = msg->get_payload();
|
std::string payload = msg->get_payload();
|
||||||
ws->decodedMessage( QByteArray( payload.data(), payload.length() ) );
|
ws->decodedMessage( QByteArray( payload.data(), payload.length() ) );
|
||||||
}
|
}
|
||||||
@@ -319,6 +312,6 @@ onMessage( WebSocket* ws, websocketpp::connection_hdl, hatchet_client::message_p
|
|||||||
void
|
void
|
||||||
onClose( WebSocket *ws, websocketpp::connection_hdl )
|
onClose( WebSocket *ws, websocketpp::connection_hdl )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Handling message";
|
tDebug() << Q_FUNC_INFO << "Handling message";
|
||||||
QMetaObject::invokeMethod( ws, "disconnectSocket", Qt::QueuedConnection );
|
QMetaObject::invokeMethod( ws, "disconnectSocket", Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user