diff options
author | chriszero <zerov83@gmail.com> | 2014-11-19 19:44:37 +0100 |
---|---|---|
committer | chriszero <zerov83@gmail.com> | 2014-11-19 19:44:37 +0100 |
commit | 0b1771db632f525a68b18b9d57b93c9e843074bc (patch) | |
tree | f55c15e5f2ef2a5979c4e055c46026696c9b429c | |
parent | 53143efc7a8b93ac779b494588e44c2ef47a1f12 (diff) | |
download | vdr-plugin-plex-0b1771db632f525a68b18b9d57b93c9e843074bc.tar.gz vdr-plugin-plex-0b1771db632f525a68b18b9d57b93c9e843074bc.tar.bz2 |
Added more logging
-rw-r--r-- | Plexservice.cpp | 93 | ||||
-rw-r--r-- | plexgdm.cpp | 47 |
2 files changed, 81 insertions, 59 deletions
diff --git a/Plexservice.cpp b/Plexservice.cpp index a4d886b..03775f2 100644 --- a/Plexservice.cpp +++ b/Plexservice.cpp @@ -16,15 +16,21 @@ Plexservice::~Plexservice() Poco::Net::HTTPClientSession* Plexservice::GetHttpSession(bool createNew) { - if(pServer == 0) { - return NULL; - } - if (m_pPlexSession == 0 || createNew) { - if (createNew) { - //delete m_pPlexSession; + try { + if(pServer == 0) { + return NULL; } - m_pPlexSession = new Poco::Net::HTTPClientSession(pServer->GetIpAdress(), pServer->GetPort()); - m_pPlexSession->setKeepAlive(true); + if (m_pPlexSession == 0 || createNew) { + if (createNew) { + //delete m_pPlexSession; + } + m_pPlexSession = new Poco::Net::HTTPClientSession(pServer->GetIpAdress(), pServer->GetPort()); + m_pPlexSession->setKeepAlive(true); + } + } + catch(Poco::Exception &exc) { + esyslog("[plex]Exception in %s s%", __func__, exc.displayText().c_str() ); + m_pPlexSession = 0; } return m_pPlexSession; } @@ -70,7 +76,7 @@ std::string Plexservice::GetMyPlexToken() m_sToken = u->authenticationToken; plexSession.detachSocket(); } catch (Poco::Exception &exc) { - std::cerr << exc.displayText() << std::endl; + esyslog("[plex]Exception in %s s%", __func__, exc.displayText().c_str() ); } } @@ -80,20 +86,24 @@ std::string Plexservice::GetMyPlexToken() void Plexservice::Authenticate() { try { - GetHttpSession(true); - std::string token = GetMyPlexToken(); - Poco::Net::HTTPRequest *pRequest = CreateRequest("/?X-Plex-Token=" + token); + if(GetHttpSession(true)) { + std::string token = GetMyPlexToken(); + Poco::Net::HTTPRequest *pRequest = CreateRequest("/?X-Plex-Token=" + token); - m_pPlexSession->sendRequest(*pRequest); - Poco::Net::HTTPResponse response; - /*std::istream &rs = */ - m_pPlexSession->receiveResponse(response); + m_pPlexSession->sendRequest(*pRequest); + Poco::Net::HTTPResponse response; + /*std::istream &rs = */ + m_pPlexSession->receiveResponse(response); - // TODO: process response - //Poco::StreamCopier::copyStream(rs, std::cout); - delete pRequest; + // TODO: process response + //Poco::StreamCopier::copyStream(rs, std::cout); + delete pRequest; + } + else { + esyslog("[plex] %s HttpSession is NULL", __func__); + } } catch (Poco::Exception &exc) { - std::cerr << exc.displayText() << std::endl; + esyslog("[plex]Exception in %s s%", __func__, exc.displayText().c_str() ); } } /* @@ -121,32 +131,37 @@ MediaContainer* Plexservice::GetAllSections() MediaContainer* Plexservice::GetSection(std::string section) { std::string token = GetMyPlexToken(); - GetHttpSession(true); - - Poco::Net::HTTPRequest *pRequest; - if(section[0]=='/') { // Full URI? - pRequest = CreateRequest(Poco::format("%s?X-Plex-Token=%s", section, token)); - } else if(false == section.empty()) { - pRequest = CreateRequest(Poco::format("/library/sections/%s?X-Plex-Token=%s", section, token)); - } else { - pRequest = CreateRequest("/library/sections/?X-Plex-Token=" + token); - } + if(GetHttpSession(true)) { + + Poco::Net::HTTPRequest *pRequest; + if(section[0]=='/') { // Full URI? + pRequest = CreateRequest(Poco::format("%s?X-Plex-Token=%s", section, token)); + } else if(false == section.empty()) { + pRequest = CreateRequest(Poco::format("/library/sections/%s?X-Plex-Token=%s", section, token)); + } else { + pRequest = CreateRequest("/library/sections/?X-Plex-Token=" + token); + } - m_pPlexSession->sendRequest(*pRequest); - Poco::Net::HTTPResponse response; - std::istream &rs = m_pPlexSession->receiveResponse(response); + m_pPlexSession->sendRequest(*pRequest); + Poco::Net::HTTPResponse response; + std::istream &rs = m_pPlexSession->receiveResponse(response); - std::cout << "URI: " << m_pPlexSession->getHost() << "[" << pRequest->getURI() << "]" << std::endl; + dsyslog("[plex] URI: %s[s%]", m_pPlexSession->getHost().c_str(), pRequest->getURI().c_str()); + + MediaContainer* pAllsections = new MediaContainer(&rs); + //Poco::StreamCopier::copyStream(rs, std::cout); + delete pRequest; + return pAllsections; - MediaContainer* pAllsections = new MediaContainer(&rs); - //Poco::StreamCopier::copyStream(rs, std::cout); - delete pRequest; - return pAllsections; + } + else { + esyslog("[plex] %s HttpSession is NULL", __func__); + return 0; + } } Poco::Net::HTTPRequest* Plexservice::CreateRequest(std::string path) { - Poco::Net::HTTPRequest *pRequest = new Poco::Net::HTTPRequest(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1); diff --git a/plexgdm.cpp b/plexgdm.cpp index 12e1e8a..b7d45a1 100644 --- a/plexgdm.cpp +++ b/plexgdm.cpp @@ -1,3 +1,4 @@ +#include <vdr/tools.h> #include "plexgdm.h" namespace plexclient @@ -47,6 +48,7 @@ std::string plexgdm::getClientDetails() void plexgdm::Action() { + char buffer[1024]; m_registrationIsRunning = true; cMutexLock lock(&m_mutex); @@ -98,26 +100,31 @@ void plexgdm::Action() void plexgdm::discover() { - // TODO: Discover multiple servers - char buffer[1024]; - Poco::Net::MulticastSocket socket( - Poco::Net::SocketAddress( Poco::Net::IPAddress(), m_discoverAdress.port() ) - ); - socket.setReceiveTimeout(0.6); - //socket.setTimeToLive(0.6); - socket.sendTo(_discoverMessage.c_str(), _discoverMessage.length(), m_discoverAdress, 0); - - socket.joinGroup(m_discoverAdress.host()); - Poco::Net::SocketAddress sender; - int n = socket.receiveFrom(buffer, sizeof(buffer), sender); - std::string buf(buffer, n); - //std::cout << "Discover received from: " << sender.host().toString() << "\nData:\n" << buf; - - socket.close(); - m_discoveryComplete = true; - // check for a valid response - if(buf.find("200 OK") != std::string::npos) { - m_pServer = new PlexServer(buf, sender.host().toString()); + try { + // TODO: Discover multiple servers + char buffer[1024]; + Poco::Net::MulticastSocket socket( + Poco::Net::SocketAddress( Poco::Net::IPAddress(), m_discoverAdress.port() ) + ); + socket.setReceiveTimeout(0.6); + //socket.setTimeToLive(0.6); + socket.sendTo(_discoverMessage.c_str(), _discoverMessage.length(), m_discoverAdress, 0); + + socket.joinGroup(m_discoverAdress.host()); + Poco::Net::SocketAddress sender; + int n = socket.receiveFrom(buffer, sizeof(buffer), sender); + std::string buf(buffer, n); + //std::cout << "Discover received from: " << sender.host().toString() << "\nData:\n" << buf; + + socket.close(); + m_discoveryComplete = true; + // check for a valid response + if(buf.find("200 OK") != std::string::npos) { + m_pServer = new PlexServer(buf, sender.host().toString()); + } + } + catch(Poco::Exception &exc){ + esyslog("[plex]Exception in %s s%", __func__, exc.displayText().c_str() ); } } |