summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2012-12-10 20:49:53 +0100
committermethodus <methodus@web.de>2012-12-10 20:49:53 +0100
commit7c5e5dac8eba1e6132582f7ff549fd04dc877ce1 (patch)
tree4f937c7a5eb686d25e44be178d0e7d6867456e1b
parentb36c18930b3221fbc7cfea674472d77cdb466c98 (diff)
downloadvdr-plugin-upnp-7c5e5dac8eba1e6132582f7ff549fd04dc877ce1.tar.gz
vdr-plugin-upnp-7c5e5dac8eba1e6132582f7ff549fd04dc877ce1.tar.bz2
Ignoring signal SIGPIPE which might cause crashes
-rw-r--r--include/plugin.h32
-rw-r--r--media/pluginManager.cpp41
-rw-r--r--plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp2
-rw-r--r--plugins/provider/fileProvider/fileProvider.cpp72
-rw-r--r--plugins/provider/recProvider/recProvider.cpp15
-rw-r--r--plugins/provider/vdrProvider/vdrProvider.cpp45
-rw-r--r--server/webserver.cpp3
7 files changed, 114 insertions, 96 deletions
diff --git a/include/plugin.h b/include/plugin.h
index beb24bf..fa167b7 100644
--- a/include/plugin.h
+++ b/include/plugin.h
@@ -376,6 +376,8 @@ public:
*/
virtual string GetHTTPUri(const string& uri, const string& currentIP, const string& protocolInfo);
+ virtual string GetFile(const string& uri);
+
virtual bool Seekable() const;
/**
@@ -479,6 +481,25 @@ protected:
void OnContainerUpdate(const string& uri, long containerUpdateId, const string& target = string());
/**
+ * Load a configuration file.
+ *
+ * This loads a configuration file from the configuration directory of
+ * the upnp plugin. Subplugins don't have their own configuration directory.
+ *
+ * If the seconds parameter is true, comments are allowed but skipped while
+ * parsing, i.e. they are not passed to Parse().
+ */
+ bool LoadConfigFile(const string& filename, bool allowComments = true);
+
+ /**
+ * Checks if the given URI contains the root container.
+ *
+ * This function returns true if the given uri contains the container
+ * returned by GetRootContainer().
+ */
+ bool HasRootContainer(const string& uri);
+
+ /**
* Thread action to check for updates
*
* This should be used to determine changes on the containers. It should
@@ -488,6 +509,14 @@ protected:
*/
virtual void Action();
+ /**
+ * Parses a single line of a configuration file.
+ *
+ * This function must be overriden if the sub plugin wants to read
+ * a configuration file.
+ */
+ bool Parse(const string& uri);
+
};
#define UPNP_REGISTER_MEDIA_PLUGIN(cls) extern "C" void *UPnPCreateMediaProfiler(void) { return new cls; }
@@ -541,10 +570,11 @@ public:
*
* @param uri the absolute path to the resource.
* @param metadata the metadate object, where the information shall be saved.
+ * @param provider the provider with which the file was accessed.
* @return true, if this profiler was able to get the specific metadata,
* false, if not.
*/
- virtual bool GetMetadata(const string& uri, cMetadata& metadata) = 0;
+ virtual bool GetMetadata(const string& uri, cMetadata& metadata, cUPnPResourceProvider* provider) = 0;
};
diff --git a/media/pluginManager.cpp b/media/pluginManager.cpp
index cd31be3..5f38aa8 100644
--- a/media/pluginManager.cpp
+++ b/media/pluginManager.cpp
@@ -11,6 +11,7 @@
#include "../include/tools/string.h"
#include "../include/tools/uuid.h"
#include <string>
+#include <fstream>
#include <sstream>
#include <dlfcn.h>
#include <dirent.h>
@@ -286,6 +287,10 @@ string cUPnPResourceProvider::GetHTTPUri(const string&, const string&, const str
return string();
}
+string cUPnPResourceProvider::GetFile(const string& uri){
+ return uri;
+}
+
bool cUPnPResourceProvider::Seekable() const {
return false;
}
@@ -309,6 +314,42 @@ void cUPnPResourceProvider::OnContainerUpdate(const string& uri, long int cUID,
cMediaServer::GetInstance()->GetManager().OnContainerUpdate(uri, cUID, target);
}
+bool cUPnPResourceProvider::HasRootContainer(const string& uri){
+ if(uri.find(GetRootContainer(), 0) != 0){
+ isyslog("RecProvider\tUri does not contain the root.");
+ return false;
+ } else {
+ return true;
+ }
+}
+
+bool cUPnPResourceProvider::Parse(const string& line){
+ return true;
+}
+
+bool cUPnPResourceProvider::LoadConfigFile(const string& fn, bool allowComments)
+{
+ string filename = cMediaServer::GetInstance()->GetConfigDirectory() + "/" + fn;
+ if (access(filename.c_str(), F_OK) == 0) {
+ isyslog("loading %s", filename.c_str());
+ ifstream file;
+ file.open(filename.c_str(), ifstream::in);
+ if(!file.is_open())
+ return false;
+ string line;
+ while(getline(file, line)){
+ if(line.length() > 0){
+ if(allowComments && line[0] == '#')
+ continue;
+ if(!Parse(line))
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
void cUPnPResourceProvider::Action(){}
upnp::cPluginManager::cPluginManager()
diff --git a/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp b/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp
index 0204b4e..6820481 100644
--- a/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp
+++ b/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp
@@ -122,7 +122,7 @@ public:
}
}
- virtual bool GetMetadata(const string& uri, cMetadata& metadata){
+ virtual bool GetMetadata(const string& uri, cMetadata& metadata, cUPnPResourceProvider*){
if (uri.find("vdr",0) == 0){
return GetChannelMetadata(uri, metadata);
}
diff --git a/plugins/provider/fileProvider/fileProvider.cpp b/plugins/provider/fileProvider/fileProvider.cpp
index a60d772..9121d90 100644
--- a/plugins/provider/fileProvider/fileProvider.cpp
+++ b/plugins/provider/fileProvider/fileProvider.cpp
@@ -6,11 +6,7 @@
*/
#include <plugin.h>
-#include <server.h>
-#include <fstream>
-#include <sstream>
#include <tools/string.h>
-#include <vdr/plugin.h>
#include <pwd.h>
#include <unistd.h>
@@ -24,47 +20,12 @@ private:
StringMap directoryMap;
FILE* fileFD;
- bool IsRootContainer(const string& uri){
- if(uri.find(GetRootContainer(), 0) != 0){
- isyslog("RecProvider\tUri does not contain the root.");
- return false;
- } else {
- return true;
- }
- }
-
- bool Load(const string& filename)
- {
- if (access(filename.c_str(), F_OK) == 0) {
- isyslog("loading %s", filename.c_str());
- ifstream file;
- file.open(filename.c_str(), ifstream::in);
- if(!file.is_open())
- return false;
- string line; int pos;
- while(getline(file, line)){
- if(line.length() > 0 && line[0] != '#'){
- if((pos = line.find_first_of(':')) != string::npos){
- directoryMap[tools::Trim(line.substr(0,pos))] = tools::Trim(line.substr(pos+1));
- }
- }
- }
- return true;
- }
- return false;
- }
-
- string GetFile(const string& uri){
- string mountPoint = uri.substr(7, uri.find_first_of('/',7) - 7);
-
- string file;
- if(!mountPoint.empty() && !directoryMap[mountPoint].empty()){
- file = directoryMap[mountPoint];
- if(uri.find_first_of('/', 7) != string::npos)
- file += uri.substr(uri.find_first_of('/',7));
+ bool Parse(const string& line){
+ int pos;
+ if((pos = line.find_first_of(':')) != string::npos){
+ directoryMap[tools::Trim(line.substr(0,pos))] = tools::Trim(line.substr(pos+1));
}
-
- return file;
+ return true;
}
bool GetFileStat(const string& uri, struct stat& fileStat){
@@ -82,9 +43,7 @@ public:
FileProvider()
: fileFD(NULL)
{
- stringstream file;
- file << cMediaServer::GetInstance()->GetConfigDirectory() << "/directories.conf";
- Load(file.str());
+ LoadConfigFile("directories.conf");
}
virtual string ProvidesSchema() { return "file"; }
@@ -120,6 +79,8 @@ public:
virtual StringList GetContainerEntries(const string& uri) {
StringList list;
+ if(!HasRootContainer(uri)) return list;
+
DIR* dirHandle;
struct dirent* dirEntry;
@@ -149,7 +110,7 @@ public:
}
virtual bool GetMetadata(const string& uri, cMetadata& metadata){
- if(!IsRootContainer(uri)) return false;
+ if(!HasRootContainer(uri)) return false;
if(!cUPnPResourceProvider::GetMetadata(uri, metadata)) return false;
@@ -173,6 +134,21 @@ public:
return true;
}
+ virtual string GetFile(const string& uri){
+ if(!HasRootContainer(uri)) return string();
+
+ string mountPoint = uri.substr(7, uri.find_first_of('/',7) - 7);
+
+ string file;
+ if(!mountPoint.empty() && !directoryMap[mountPoint].empty()){
+ file = directoryMap[mountPoint];
+ if(uri.find_first_of('/', 7) != string::npos)
+ file += uri.substr(uri.find_first_of('/',7));
+ }
+
+ return file;
+ }
+
virtual bool Open(const string& uri) {
if(fileFD)
Close();
diff --git a/plugins/provider/recProvider/recProvider.cpp b/plugins/provider/recProvider/recProvider.cpp
index c8273fd..41ca849 100644
--- a/plugins/provider/recProvider/recProvider.cpp
+++ b/plugins/provider/recProvider/recProvider.cpp
@@ -24,15 +24,6 @@ namespace upnp {
class RecProvider : public cUPnPResourceProvider {
private:
- bool IsRootContainer(const string& uri){
- if(uri.find(GetRootContainer(), 0) != 0){
- isyslog("RecProvider\tUri does not contain the root.");
- return false;
- } else {
- return true;
- }
- }
-
bool GetFileStat(const string& uri, struct stat& fileStat){
stringstream filename;
filename << VideoDirectory << "/" << uri.substr(6);
@@ -111,7 +102,7 @@ public:
}
virtual StringList GetContainerEntries(const string& u){
- if(!IsRootContainer(u)) return StringList();
+ if(!HasRootContainer(u)) return StringList();
StringList list;
string videoDir(VideoDirectory), fs, uri = u.substr(6);
@@ -169,7 +160,7 @@ public:
}
virtual bool GetMetadata(const string& uri, cMetadata& metadata){
- if(!IsRootContainer(uri)) return false;
+ if(!HasRootContainer(uri)) return false;
if(!cUPnPResourceProvider::GetMetadata(uri, metadata)) return false;
@@ -204,6 +195,8 @@ public:
}
virtual bool Open(const string& uri){
+ if(!HasRootContainer(uri)) return false;
+
filename = string(VideoDirectory) + "/" + uri.substr(6);
currentFileNumber = 1;
return ScanFiles();
diff --git a/plugins/provider/vdrProvider/vdrProvider.cpp b/plugins/provider/vdrProvider/vdrProvider.cpp
index c9b9a95..6b4c1b1 100644
--- a/plugins/provider/vdrProvider/vdrProvider.cpp
+++ b/plugins/provider/vdrProvider/vdrProvider.cpp
@@ -13,7 +13,6 @@
#include <vdr/plugin.h>
#include <string>
#include <sstream>
-#include <fstream>
#include <algorithm>
#include <tools.h>
#include <pwd.h>
@@ -29,39 +28,17 @@ private:
int from;
int to;
- bool Load(const string& filename)
+ bool Parse(const string& line)
{
- if (access(filename.c_str(), F_OK) == 0) {
- isyslog("loading %s", filename.c_str());
- ifstream file;
- file.open(filename.c_str(), ifstream::in);
- if(!file.is_open())
- return false;
- string line; int pos;
- while(getline(file, line)){
- if(line.length() > 0 && line[0] != '#'){
- if((pos = line.find_first_of('-')) != string::npos){
- from = atoi(line.substr(0, pos).c_str());
- to = atoi(line.substr(pos+1).c_str());
- break;
- }
- }
- }
- if(to == 0) to = INT_MAX;
+ int pos = 0;
+ if((pos = line.find_first_of('-')) != string::npos){
+ from = atoi(line.substr(0, pos).c_str());
+ to = atoi(line.substr(pos+1).c_str());
return true;
}
return false;
}
- bool IsRootContainer(const string& uri){
- if(uri.find(GetRootContainer(), 0) != 0){
- isyslog("VdrProvider\tUri does not contain the root.");
- return false;
- } else {
- return true;
- }
- }
-
int GetGroupByName(string name)
{
if(name.empty()) return -1;
@@ -83,9 +60,7 @@ public:
, from(0)
, to(INT_MAX)
{
- stringstream file;
- file << cMediaServer::GetInstance()->GetConfigDirectory() << "/vdrProvider.conf";
- Load(file.str());
+ LoadConfigFile("vdrProvider.conf");
}
virtual ~VdrProvider(){
@@ -99,7 +74,7 @@ public:
}
virtual StringList GetContainerEntries(const string& uri){
- if(!IsRootContainer(uri)) return StringList();
+ if(!HasRootContainer(uri)) return StringList();
StringList list;
int index;
@@ -143,14 +118,14 @@ public:
}
virtual long GetContainerUpdateId(const string& uri){
- if(!IsRootContainer(uri)) return 0;
+ if(!HasRootContainer(uri)) return 0;
// We now have containers. However, they do not support containerUpdateIDs separately.
return (long)lastModified;
}
virtual bool GetMetadata(const string& uri, cMetadata& metadata){
- if(!IsRootContainer(uri)) return false;
+ if(!HasRootContainer(uri)) return false;
if(!cUPnPResourceProvider::GetMetadata(uri, metadata)) return false;
@@ -179,7 +154,7 @@ public:
}
virtual string GetHTTPUri(const string& uri, const string& currentIP, const string& pInfo){
- if(!IsRootContainer(uri)) return string();
+ if(!HasRootContainer(uri)) return string();
int port = 3000;
diff --git a/server/webserver.cpp b/server/webserver.cpp
index c2dfad2..2ef058d 100644
--- a/server/webserver.cpp
+++ b/server/webserver.cpp
@@ -7,6 +7,7 @@
#include "../include/webserver.h"
#include "../upnp.h"
+#include <signal.h>
#include <sstream>
#include <tnt/job.h>
#include <tnt/configurator.h>
@@ -47,6 +48,8 @@ bool cWebserver::Initialise(){
// Map static contents
stringstream ss1, ss2;
+ signal(SIGPIPE, SIG_IGN);
+
mApplication.listen(mListenerAddress.c_str(), mListenerPort);
mApplication.mapUrl("^/$", "index");