summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchriszero <zerov83@gmail.com>2014-11-18 20:41:44 +0100
committerchriszero <zerov83@gmail.com>2014-11-18 20:41:44 +0100
commit53143efc7a8b93ac779b494588e44c2ef47a1f12 (patch)
tree68307c1498c3bb25d9c24bedfebf78d5e42e2bec
parentfc243d8bfde7c24168b67f90341e7d0d114114b2 (diff)
downloadvdr-plugin-plex-53143efc7a8b93ac779b494588e44c2ef47a1f12.tar.gz
vdr-plugin-plex-53143efc7a8b93ac779b494588e44c2ef47a1f12.tar.bz2
Fixes seg fault on some systems
-rw-r--r--Plexservice.cpp34
-rw-r--r--Plexservice.h10
-rw-r--r--plex.cpp26
-rw-r--r--po/.gitignore4
4 files changed, 29 insertions, 45 deletions
diff --git a/Plexservice.cpp b/Plexservice.cpp
index 066abe2..a4d886b 100644
--- a/Plexservice.cpp
+++ b/Plexservice.cpp
@@ -31,16 +31,18 @@ Poco::Net::HTTPClientSession* Plexservice::GetHttpSession(bool createNew)
std::string Plexservice::GetMyPlexToken()
{
+ // Syncronize
+ Poco::Mutex::ScopedLock lock(m_mutex);
+
//todo: cache token in file or db
- if(m_sToken.empty()) {
- std::ostringstream ss;
+ if(&m_sToken != 0 || m_sToken.empty()) {
+ std::stringstream ss;
Poco::Base64Encoder b64(ss);
b64 << Config::GetInstance().GetUsername() << ":" << Config::GetInstance().GetPassword();
b64.close();
m_sToken = ss.str();
- b64.~Base64Encoder();
Poco::Net::Context::Ptr context = new Poco::Net::Context(
Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE, // VERIFY_NONE...?!
@@ -53,10 +55,10 @@ std::string Plexservice::GetMyPlexToken()
request.add("X-Plex-Platform", "VDR");
request.add("X-Plex-Platform-Version", "2.0.4");
request.add("X-Plex-Provides", "player");
- request.add("X-Plex-Product", "plex-vdr");
+ request.add("X-Plex-Product", "plex for vdr");
request.add("X-Plex-Version", "0.0.1a");
request.add("X-Plex-Device", "Linux");
- request.add("X-Plex-Client-Identifier", "plex-vdr");
+ request.add("X-Plex-Client-Identifier", "plex for vdr");
request.add("Authorization", Poco::format("Basic %s", m_sToken));
plexSession.sendRequest(request);
@@ -77,13 +79,10 @@ std::string Plexservice::GetMyPlexToken()
void Plexservice::Authenticate()
{
- if(m_sToken.empty()) {
- GetMyPlexToken();
- //m_sToken = "";
- }
try {
GetHttpSession(true);
- Poco::Net::HTTPRequest *pRequest = CreateRequest("/?X-Plex-Token=" + m_sToken);
+ std::string token = GetMyPlexToken();
+ Poco::Net::HTTPRequest *pRequest = CreateRequest("/?X-Plex-Token=" + token);
m_pPlexSession->sendRequest(*pRequest);
Poco::Net::HTTPResponse response;
@@ -121,19 +120,16 @@ MediaContainer* Plexservice::GetAllSections()
MediaContainer* Plexservice::GetSection(std::string section)
{
- if(m_sToken.empty()) {
- GetMyPlexToken();
- }
-
+ 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, m_sToken));
+ 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, m_sToken));
+ pRequest = CreateRequest(Poco::format("/library/sections/%s?X-Plex-Token=%s", section, token));
} else {
- pRequest = CreateRequest("/library/sections/?X-Plex-Token=" + m_sToken);
+ pRequest = CreateRequest("/library/sections/?X-Plex-Token=" + token);
}
m_pPlexSession->sendRequest(*pRequest);
@@ -163,7 +159,7 @@ Poco::Net::HTTPRequest* Plexservice::CreateRequest(std::string path)
pRequest->add("X-Plex-Language", Config::GetInstance().GetLanguage());
pRequest->add("X-Plex-Model", "Linux");
pRequest->add("X-Plex-Platform", "VDR");
- pRequest->add("X-Plex-Product", "plex-vdr");
+ pRequest->add("X-Plex-Product", "plex for vdr");
pRequest->add("X-Plex-Provides", "player");
pRequest->add("X-Plex-Version", "0.0.1a");
@@ -186,7 +182,7 @@ MediaContainer* Plexservice::GetMediaContainer(std::string fullUrl) {
pRequest->add("X-Plex-Language", Config::GetInstance().GetLanguage());
pRequest->add("X-Plex-Model", "Linux");
pRequest->add("X-Plex-Platform", "VDR");
- pRequest->add("X-Plex-Product", "plex-vdr");
+ pRequest->add("X-Plex-Product", "plex for vdr");
pRequest->add("X-Plex-Provides", "player");
pRequest->add("X-Plex-Version", "0.0.1a");
diff --git a/Plexservice.h b/Plexservice.h
index aad20a9..456341b 100644
--- a/Plexservice.h
+++ b/Plexservice.h
@@ -28,6 +28,9 @@
#include "user.h"
#include "MediaContainer.h"
+#include <Poco/ScopedLock.h>
+#include <Poco/Mutex.h>
+
namespace plexclient
{
@@ -48,12 +51,15 @@ public:
static MediaContainer* GetMediaContainer(std::string fullUrl);
-private:
+ private:
+ Poco::Mutex m_mutex;
+ // Never Access m_sToken directly! => possible race condition
+ std::string m_sToken;
+
std::string USERAGENT;
Poco::Net::HTTPClientSession *m_pPlexSession;
PlexServer *pServer;
- std::string m_sToken;
Poco::Net::HTTPClientSession* GetHttpSession(bool createNew = false);
Poco::Net::HTTPRequest* CreateRequest(std::string path);
diff --git a/plex.cpp b/plex.cpp
index 60fd6e7..f424d18 100644
--- a/plex.cpp
+++ b/plex.cpp
@@ -1,24 +1,3 @@
-///
-/// @file play.cpp @brief A play plugin for VDR.
-///
-/// Copyright (c) 2012, 2013 by Johns. All Rights Reserved.
-///
-/// Contributor(s): Dennis Bendlin
-///
-/// License: AGPLv3
-///
-/// This program is free software: you can redistribute it and/or modify
-/// it under the terms of the GNU Affero General Public License as
-/// published by the Free Software Foundation, either version 3 of the
-/// License.
-///
-/// This program is distributed in the hope that it will be useful,
-/// but WITHOUT ANY WARRANTY; without even the implied warranty of
-/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-/// GNU Affero General Public License for more details.
-///
-/// $Id: 269426d9bc0f37cc7c07b21716c345e57148aecb $
-//////////////////////////////////////////////////////////////////////////////
#include "ControlServer.h"
#include "SubscriptionManager.h"
#include "plex.h"
@@ -34,10 +13,10 @@ static const char *const PLUGINNAME = "plex";
/// vdr-plugin description.
-static const char *const DESCRIPTION = trNOOP("VDR Plex Plugin");
+static const char *const DESCRIPTION = trNOOP("Plex for VDR Plugin");
/// vdr-plugin text of main menu entry
-static const char *MAINMENUENTRY = trNOOP("Plex");
+static const char *MAINMENUENTRY = trNOOP("Plex for VDR");
//////////////////////////////////////////////////////////////////////////////
@@ -1169,7 +1148,6 @@ bool cMyPlugin::Initialize(void)
pPlexgdm->Start();
pService = new plexclient::Plexservice(pServer);
- pService->GetMyPlexToken();
pService->Authenticate();
plexclient::ControlServer::GetInstance().Start();
diff --git a/po/.gitignore b/po/.gitignore
new file mode 100644
index 0000000..5e7d273
--- /dev/null
+++ b/po/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore