mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-25 20:33:20 +01:00
Revert/fix hatchet/websocket logging
This commit is contained in:
parent
bc1ebfa89b
commit
02386935ad
@ -53,7 +53,7 @@ HatchetSipPlugin::HatchetSipPlugin( Tomahawk::Accounts::Account *account )
|
||||
|
||||
QFile pemFile( ":/hatchet-account/dreamcatcher.pem" );
|
||||
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.open( QIODevice::ReadOnly );
|
||||
QCA::ConvertResult conversionResult;
|
||||
@ -217,7 +217,7 @@ HatchetSipPlugin::webSocketConnected()
|
||||
QCA::SecureArray sa( m_uuid.toLatin1() );
|
||||
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;
|
||||
nonceVerMap[ "version" ] = VERSION;
|
||||
@ -261,7 +261,6 @@ HatchetSipPlugin::webSocketDisconnected()
|
||||
bool
|
||||
HatchetSipPlugin::sendBytes( const QVariantMap& jsonMap ) const
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
if ( m_sipState == Closed )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
tDebug() << Q_FUNC_INFO << "Sending bytes of size" << bytes.size();
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Sending bytes of size" << bytes.size();
|
||||
emit rawBytes( bytes );
|
||||
return true;
|
||||
}
|
||||
@ -285,7 +284,7 @@ HatchetSipPlugin::sendBytes( const QVariantMap& jsonMap ) const
|
||||
void
|
||||
HatchetSipPlugin::messageReceived( const QByteArray &msg )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "WebSocket message: " << msg;
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WebSocket message: " << msg;
|
||||
|
||||
QJson::Parser parser;
|
||||
bool ok;
|
||||
@ -553,7 +552,6 @@ HatchetSipPlugin::sendOplog( const QVariantMap& valMap ) const
|
||||
void
|
||||
HatchetSipPlugin::oplogFetched( const QString& sinceguid, const QString& /* lastguid */, const QList< dbop_ptr > ops )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
const uint_fast32_t byteMax = 1 << 25;
|
||||
int currBytes = 0;
|
||||
QVariantMap commandMap;
|
||||
|
@ -31,7 +31,7 @@ WebSocket::WebSocket( const QString& url )
|
||||
, m_lastSocketState( QAbstractSocket::UnconnectedState )
|
||||
, 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->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 ) );
|
||||
@ -58,7 +58,7 @@ WebSocket::~WebSocket()
|
||||
void
|
||||
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 )
|
||||
return;
|
||||
|
||||
@ -71,7 +71,7 @@ WebSocket::setUrl( const QString &url )
|
||||
void
|
||||
WebSocket::connectWs()
|
||||
{
|
||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Connecting";
|
||||
tLog() << Q_FUNC_INFO << "Connecting";
|
||||
m_disconnecting = false;
|
||||
if ( m_socket )
|
||||
{
|
||||
@ -99,7 +99,7 @@ WebSocket::connectWs()
|
||||
void
|
||||
WebSocket::disconnectWs( websocketpp::close::status::value status, const QString &reason )
|
||||
{
|
||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Disconnecting";
|
||||
tLog() << Q_FUNC_INFO << "Disconnecting";
|
||||
m_disconnecting = true;
|
||||
|
||||
error_code ec;
|
||||
@ -130,7 +130,7 @@ WebSocket::disconnectSocket()
|
||||
void
|
||||
WebSocket::cleanup()
|
||||
{
|
||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Cleaning up";
|
||||
tLog() << Q_FUNC_INFO << "Cleaning up";
|
||||
m_outputStream.seekg( std::ios_base::end );
|
||||
m_outputStream.seekp( std::ios_base::end );
|
||||
m_queuedMessagesToSend.empty();
|
||||
@ -144,14 +144,14 @@ WebSocket::cleanup()
|
||||
void
|
||||
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 )
|
||||
{
|
||||
case QAbstractSocket::ClosingState:
|
||||
if ( m_lastSocketState == QAbstractSocket::ClosingState )
|
||||
{
|
||||
// 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_lastSocketState = QAbstractSocket::UnconnectedState;
|
||||
QMetaObject::invokeMethod( this, "cleanup", Qt::QueuedConnection );
|
||||
@ -161,7 +161,7 @@ WebSocket::socketStateChanged( QAbstractSocket::SocketState state )
|
||||
case QAbstractSocket::UnconnectedState:
|
||||
if ( m_lastSocketState == QAbstractSocket::UnconnectedState )
|
||||
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_lastSocketState = QAbstractSocket::UnconnectedState;
|
||||
QMetaObject::invokeMethod( this, "cleanup", Qt::QueuedConnection );
|
||||
@ -186,7 +186,7 @@ WebSocket::sslErrors( const QList< QSslError >& errors )
|
||||
void
|
||||
WebSocket::encrypted()
|
||||
{
|
||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Encrypted connection to Dreamcatcher established";
|
||||
tLog() << Q_FUNC_INFO << "Encrypted connection to Dreamcatcher established";
|
||||
error_code ec;
|
||||
|
||||
QUrl url(m_url);
|
||||
@ -211,16 +211,13 @@ WebSocket::readOutput()
|
||||
if ( !m_connection )
|
||||
return;
|
||||
|
||||
//tDebug() << Q_FUNC_INFO;
|
||||
|
||||
std::string outputString = m_outputStream.str();
|
||||
if ( outputString.size() > 0 )
|
||||
{
|
||||
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() );
|
||||
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 )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Error during writing, closing connection";
|
||||
@ -235,7 +232,7 @@ WebSocket::readOutput()
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
@ -253,8 +250,6 @@ WebSocket::readOutput()
|
||||
void
|
||||
WebSocket::socketReadyRead()
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||
|
||||
if ( !m_socket || !m_socket->isEncrypted() )
|
||||
return;
|
||||
|
||||
@ -267,11 +262,10 @@ WebSocket::socketReadyRead()
|
||||
|
||||
if ( qint64 bytes = m_socket->bytesAvailable() )
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Bytes available:" << bytes;
|
||||
QByteArray buf;
|
||||
buf.resize( 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 )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Error occurred during socket read. Something is wrong; disconnecting";
|
||||
@ -289,7 +283,6 @@ WebSocket::socketReadyRead()
|
||||
void
|
||||
WebSocket::encodeMessage( const QByteArray &bytes )
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Encoding message"; //, message is" << bytes.constData();
|
||||
if ( !m_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 )
|
||||
{
|
||||
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_connectionTimer.start();
|
||||
}
|
||||
@ -311,7 +304,7 @@ WebSocket::encodeMessage( const QByteArray &bytes )
|
||||
void
|
||||
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();
|
||||
ws->decodedMessage( QByteArray( payload.data(), payload.length() ) );
|
||||
}
|
||||
@ -319,6 +312,6 @@ onMessage( WebSocket* ws, websocketpp::connection_hdl, hatchet_client::message_p
|
||||
void
|
||||
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 );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user