diff options
author | methodus <methodus@web.de> | 2012-11-15 19:02:14 +0100 |
---|---|---|
committer | methodus <methodus@web.de> | 2012-11-15 19:02:14 +0100 |
commit | 50f35873ed654ef3b289859a46aeb52c59df59ee (patch) | |
tree | 14b8aaaca680dfb72be68d5ab321f0110a2180c6 /plugins/provider/fileProvider/fileProvider.cpp | |
parent | 18080fafe37ccc18173099343ac06ce4d9ad7681 (diff) | |
download | vdr-plugin-upnp-50f35873ed654ef3b289859a46aeb52c59df59ee.tar.gz vdr-plugin-upnp-50f35873ed654ef3b289859a46aeb52c59df59ee.tar.bz2 |
Added file provider
Diffstat (limited to 'plugins/provider/fileProvider/fileProvider.cpp')
-rw-r--r-- | plugins/provider/fileProvider/fileProvider.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/provider/fileProvider/fileProvider.cpp b/plugins/provider/fileProvider/fileProvider.cpp new file mode 100644 index 0000000..89e6f43 --- /dev/null +++ b/plugins/provider/fileProvider/fileProvider.cpp @@ -0,0 +1,100 @@ +/* + * fileProvider.cpp + * + * Created on: 15.11.2012 + * Author: savop + */ + +#include <plugin.h> + +using namespace std; + +namespace upnp { + +class FileProvider : public cUPnPResourceProvider { +private: + + StringMap directoryMap; + FILE* fileFD; + + string GetFile(const string& uri){ + string mountPoint = uri.substr(6, uri.find_first_of('/',6) - 7); + + string file; + if(!mountPoint.empty() && !directoryMap[mountPoint].empty()){ + file = directoryMap[mountPoint] + uri.substr(uri.find_first_of('/',6)); + } + + return file; + } + +public: + + virtual string ProvidesSchema() { return "file"; } + + virtual string GetRootContainer() { + return ProvidesSchema() + "://"; + } + + virtual StringList GetContainerEntries(const string& uri) { + StringList list; + + return list; + } + + virtual bool IsContainer(const string& uri) { + return false; + } + + virtual bool IsLink(const string& uri, string& target) { + return false; + } + + virtual long GetContainerUpdateId(const string& uri) { + return 0; + } + + virtual bool GetMetadata(const string& uri, cMetadata& metadata) { + return false; + } + + virtual bool Seekable() const { + return true; + } + + virtual bool Open(const string& uri) { + if(fileFD) + Close(); + + string file = GetFile(uri); + + fileFD = fopen(file.c_str(), "r"); + + return (fileFD) ? true : false; + } + + virtual size_t Read(char* buf, size_t bufLen) { + if(!fileFD) return 0; + + return fread(buf, 1, bufLen, fileFD); + } + + virtual bool Seek(size_t offset, int origin) { + if(!fileFD) return 0; + + return fseek(fileFD, offset, origin) == 0; + } + + virtual void Close() { + if(fileFD){ + fclose(fileFD); + fileFD = NULL; + } + } + +}; + +UPNP_REGISTER_RESOURCE_PROVIDER(FileProvider); + +} + |