1 /***************************************************************************
2 * copyright : (C) 2006 Ian Monroe <ian@monroe.nu> *
3 **************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
14 #include "amarokconfig.h"
15 #include "daapclient.h"
16 #include "daapreader/authentication/hasher.h"
21 #include <kapplication.h>
25 //input url: daap://host:port/databaseId/music.ext
27 bundle->setUrl( Amarok::QStringx("http://%1:3689/databases/%2/items/%3.%4?%5").args(
28 QStringList() << m_host
30 << QString::number( (*it).asMap()["miid"].asList()[0].asInt() )
31 << (*it).asMap()["asfm"].asList()[0].asString()
35 Proxy::Proxy(KUrl stream
, DaapClient
* client
, const char* name
)
36 : QObject(client
, name
)
37 , m_proxy( new Amarok::ProcIO() )
40 //find the request id and increment it
41 const QString hostKey
= stream
.host() + ':' + QString::number(stream
.port());
42 const int revisionId
= client
->incRevision( hostKey
);
43 const int sessionId
= client
->getSession( hostKey
);
45 KUrl realStream
= realStreamUrl( stream
, sessionId
);
50 , reinterpret_cast<const unsigned char*>((realStream
.path() + realStream
.query()).ascii())
52 , reinterpret_cast<unsigned char*>(hash
)
56 MyServerSocket
* socket
= new MyServerSocket();
57 const int port
= socket
->port();
58 debug() << "Proxy server using port: " << port
;
60 m_proxyUrl
= KUrl( QString("http://localhost:%1/daap.mp3").arg( port
) );
62 m_proxy
->setOutputChannelMode( ProcIO::MergedChannels
);
63 *m_proxy
<< "amarok_proxy.rb";
65 *m_proxy
<< QString::number( port
);
66 *m_proxy
<< realStream
.url();
67 *m_proxy
<< AmarokConfig::soundSystem();
69 *m_proxy
<< QString::number( revisionId
);
70 *m_proxy
<< Amarok::proxyForUrl( realStream
.url() );
73 if( m_proxy
->error() == ProcIO::FailedToStart
) {
74 error() << "Failed to start amarok_proxy.rb";
80 kapp
->processEvents();
81 m_proxy
->readln( line
);
82 if( line
== "AMAROK_PROXY: startup" ) break;
84 debug() << "started amarok_proxy.rb --daap " << QString::number( port
) << ' ' << realStream
.url() << ' ' << AmarokConfig::soundSystem() << ' ' << hash
<< ' ' << revisionId
;
85 connect( m_proxy
, SIGNAL( finished( int ) ), this, SLOT( playbackStopped() ) );
86 connect( m_proxy
, SIGNAL( readReady( ProcIO
* ) ), this, SLOT( readProxy() ) );
95 Proxy::playbackStopped()
105 while( m_proxy
->readln( line
) != -1 )
111 KUrl
Proxy::realStreamUrl( KUrl fakeStream
, int sessionId
)
114 realStream
.setProtocol( "http" );
115 realStream
.setHost(fakeStream
.host());
116 realStream
.setPort(fakeStream
.port());
117 realStream
.setPath( "/databases" + fakeStream
.directory() + "/items/" + fakeStream
.fileName() );
118 realStream
.setQuery( QString("?session-id=") + QString::number(sessionId
) );