Exemplo n.º 1
0
void
HatchetSipPlugin::messageReceived( const QByteArray &msg )
{
    tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WebSocket message: " << msg;

    QJson::Parser parser;
    bool ok;
    QVariant jsonVariant = parser.parse( msg, &ok );
    if ( !jsonVariant.isValid() )
    {
        tLog() << Q_FUNC_INFO << "Failed to parse message back from server";
        return;
    }

    QVariantMap retMap = jsonVariant.toMap();

    if ( m_sipState == AcquiringVersion )
    {
        tLog() << Q_FUNC_INFO << "In acquiring version state, expecting versioninformation";
        if ( !retMap.contains( "version" ) )
        {
            tLog() << Q_FUNC_INFO << "Failed to acquire version information";
            disconnectPlugin();
            return;
        }
        bool ok = false;
        int ver = retMap[ "version" ].toInt( &ok );
        if ( ver == 0 || !ok )
        {
            tLog() << Q_FUNC_INFO << "Failed to acquire version information";
            disconnectPlugin();
            return;
        }

        /*
        if ( retMap[ "nonce" ].toString() != m_uuid )
        {
            tLog() << Q_FUNC_INFO << "Failed to validate nonce";
            disconnectPlugin();
            return;
        }
        */

        m_version = ver;

        QVariantMap registerMap;
        registerMap[ "command" ] = "register";
        registerMap[ "token" ] = m_token;
        registerMap[ "dbid" ] = Tomahawk::Database::instance()->impl()->dbid();
        registerMap[ "alias" ] = QHostInfo::localHostName();

        QList< SipInfo > sipinfos = Servent::instance()->getLocalSipInfos( "default", "default" );
        QVariantList hostinfos;
        foreach ( SipInfo sipinfo, sipinfos )
        {
            QVariantMap hostinfo;
            hostinfo[ "host" ] = sipinfo.host();
            hostinfo[ "port" ] = sipinfo.port();
            hostinfos << hostinfo;
        }
Exemplo n.º 2
0
void
HatchetSipPlugin::webSocketConnected()
{
    tLog() << Q_FUNC_INFO << "WebSocket connected";

    if ( m_token.isEmpty() || !m_account->credentials().contains( "username" ) )
    {
        tLog() << Q_FUNC_INFO << "access token or username is empty, aborting";
        disconnectPlugin();
        return;
    }

    hatchetAccount()->setConnectionState( Tomahawk::Accounts::Account::Connected );
    m_sipState = AcquiringVersion;

    /*
    m_uuid = QUuid::createUuid().toString();
    QCA::SecureArray sa( m_uuid.toLatin1() );
    QCA::SecureArray result = m_publicKey->encrypt( sa, QCA::EME_PKCS1_OAEP );

    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;
    //nonceVerMap[ "nonce" ] = QString( result.toByteArray().toBase64() );
    sendBytes( nonceVerMap );
}
Exemplo n.º 3
0
void
HatchetSipPlugin::connectWebSocket()
{
    tLog() << Q_FUNC_INFO;
    if ( m_webSocketThreadController )
    {
        tLog() << Q_FUNC_INFO << "Already have a thread running, bailing";
        return;
    }

    m_webSocketThreadController = QPointer< WebSocketThreadController >( new WebSocketThreadController( this ) );

    if ( !m_webSocketThreadController )
    {
        tLog() << Q_FUNC_INFO << "Could not create a new thread, bailing";
        disconnectPlugin();
        return;
    }

    if ( !isValid() )
    {
      tLog() << Q_FUNC_INFO << "Invalid state, not continuing with connection";
      return;
    }

    m_token = m_account->credentials()[ "dreamcatcher_access_token" ].toString();


    if ( m_token.isEmpty() )
    {
        tLog() << Q_FUNC_INFO << "Unable to find an access token"; 
        disconnectPlugin();
        return;
    }

    QString url( "wss://dreamcatcher.hatchet.is:443" );
    tLog() << Q_FUNC_INFO << "Connecting to Dreamcatcher endpoint at: " << url;

    m_webSocketThreadController->setUrl( url );
    m_webSocketThreadController->start();
}
Exemplo n.º 4
0
	void YaDiskView::oAuthFinished(RESULT error, const QString& login, const QString& token)
	{
		if(error == eERROR_CANCEL)
		{
			emit disconnectPlugin();
		}
		else
		{
			PluginSettings pluginSettings; 
			Common::WebMounter::getSettingStorage()->getData(pluginSettings, "Yandex.Disk");
            pluginSettings.m_userName = login;
            pluginSettings.m_oAuthToken = token;

            static_cast<YaDiskRVFSDriver*>(m_driver)->connectHandlerStage2(error, pluginSettings);
		}
	}