diff options
author | methodus <methodus@web.de> | 2012-11-29 00:17:50 +0100 |
---|---|---|
committer | methodus <methodus@web.de> | 2012-11-29 00:17:50 +0100 |
commit | e6c28c5209b5508a61affc947179260cec0d2733 (patch) | |
tree | 2db88f7fe2d9f55309a267b35c401844cc657a08 /plugins/provider | |
parent | 387d734f97d9b7ad710eb84d2390e1cfe3f56c1d (diff) | |
download | vdr-plugin-upnp-e6c28c5209b5508a61affc947179260cec0d2733.tar.gz vdr-plugin-upnp-e6c28c5209b5508a61affc947179260cec0d2733.tar.bz2 |
Added some SQLite pragmas which should reduce accesses on the file system for writing
Diffstat (limited to 'plugins/provider')
-rw-r--r-- | plugins/provider/fileProvider/fileProvider.cpp | 87 |
1 files changed, 72 insertions, 15 deletions
diff --git a/plugins/provider/fileProvider/fileProvider.cpp b/plugins/provider/fileProvider/fileProvider.cpp index 15abc10..cbc84c2 100644 --- a/plugins/provider/fileProvider/fileProvider.cpp +++ b/plugins/provider/fileProvider/fileProvider.cpp @@ -7,6 +7,11 @@ #include <plugin.h> #include <fstream> +#include <sstream> +#include <tools/string.h> +#include <vdr/plugin.h> +#include <pwd.h> +#include <unistd.h> using namespace std; @@ -18,31 +23,44 @@ 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) { - bool result = false; 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[line.substr(0,pos)] = line.substr(pos+1); + directoryMap[tools::Trim(line.substr(0,pos))] = tools::Trim(line.substr(pos+1)); } } } + return true; } - return result; + return false; } string GetFile(const string& uri){ - string mountPoint = uri.substr(6, uri.find_first_of('/',6) - 7); + string mountPoint = uri.substr(7, uri.find_first_of('/',7) - 7); string file; if(!mountPoint.empty() && !directoryMap[mountPoint].empty()){ - file = directoryMap[mountPoint] + uri.substr(uri.find_first_of('/',6)); + file = directoryMap[mountPoint]; + if(uri.find_first_of('/', 7) != string::npos) + file += uri.substr(uri.find_first_of('/',7)); } return file; @@ -60,6 +78,14 @@ private: public: + FileProvider() + : fileFD(NULL) + { + stringstream file; + file << cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) << "/directories.conf"; + Load(file.str()); + } + virtual string ProvidesSchema() { return "file"; } virtual string GetRootContainer() { @@ -68,7 +94,8 @@ public: virtual bool IsContainer(const string& uri) { struct stat fileStat; - if(GetFileStat(uri, fileStat) && S_ISDIR(fileStat.st_mode)) return true; + if(GetRootContainer().compare(uri) == 0 || (GetFileStat(uri, fileStat) && S_ISDIR(fileStat.st_mode))) + return true; return false; } @@ -95,22 +122,52 @@ public: DIR* dirHandle; struct dirent* dirEntry; - if((dirHandle = opendir(GetFile(uri).c_str())) == NULL){ - return list; - } + if(GetRootContainer().compare(uri) == 0){ + for( StringMap::iterator it = directoryMap.begin(); it != directoryMap.end(); ++it ) { + list.push_back( it->first + "/" ); + } + } else { + if((dirHandle = opendir(GetFile(uri).c_str())) == NULL){ + return list; + } - string filename; - while ((dirEntry = readdir(dirHandle)) != NULL) { - filename = dirEntry->d_name; - if(filename.compare(".") || filename.compare("..")){ - list.push_back(filename); + string filename; + while ((dirEntry = readdir(dirHandle)) != NULL) { + filename = dirEntry->d_name; + if( filename.compare(".") != 0 && filename.compare("..") != 0 ) { + if(dirEntry->d_type == DT_DIR) { + filename += "/"; + } + list.push_back(filename); + } } + closedir(dirHandle); } - closedir(dirHandle); return list; } + virtual bool GetMetadata(const string& uri, cMetadata& metadata){ + if(!IsRootContainer(uri)) return false; + + if(!cUPnPResourceProvider::GetMetadata(uri, metadata)) return false; + + if(GetRootContainer().compare(uri) == 0){ + metadata.SetProperty(cMetadata::Property(property::object::KEY_TITLE, string("File system"))); + metadata.SetProperty(cMetadata::Property(property::object::KEY_DESCRIPTION, string("Access files on the file system"))); + } + + struct passwd *pw; + if((pw = getpwuid(getuid())) == NULL){ + metadata.SetProperty(cMetadata::Property(property::object::KEY_CREATOR, string("Klaus Schmidinger"))); + } else { + string name(pw->pw_gecos); name = name.substr(0,name.find(",,,",0)); + metadata.SetProperty(cMetadata::Property(property::object::KEY_CREATOR, name)); + } + + return true; + } + virtual bool Seekable() const { return true; } |