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 | |
parent | 18080fafe37ccc18173099343ac06ce4d9ad7681 (diff) | |
download | vdr-plugin-upnp-50f35873ed654ef3b289859a46aeb52c59df59ee.tar.gz vdr-plugin-upnp-50f35873ed654ef3b289859a46aeb52c59df59ee.tar.bz2 |
Added file provider
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/provider/fileProvider/Makefile | 27 | ||||
-rw-r--r-- | plugins/provider/fileProvider/README | 28 | ||||
-rw-r--r-- | plugins/provider/fileProvider/fileProvider.cpp | 100 |
3 files changed, 155 insertions, 0 deletions
diff --git a/plugins/provider/fileProvider/Makefile b/plugins/provider/fileProvider/Makefile new file mode 100644 index 0000000..c16064a --- /dev/null +++ b/plugins/provider/fileProvider/Makefile @@ -0,0 +1,27 @@ +# +# Makefile for a UPnP subplugin +# +# $Id$ +# + +SUBPLUGIN = file +CATEGORY = Provider +TARGET = $(SUBPLUGIN)-$(CATEGORY) + +OBJS = $(SUBPLUGIN)$(CATEGORY).o + + +ROOTBUILDDIR = ../../.. +-include ../../../Make.config + +all: + @$(MAKE) -f ../../../Makefile.plugins -C "$(shell pwd)" _all + +clean: + @$(MAKE) -f ../../../Makefile.plugins -C "$(shell pwd)" _clean + +install: + @$(MAKE) -f ../../../Makefile.plugins -C "$(shell pwd)" _install + +uninstall: + @$(MAKE) -f ../../../Makefile.plugins -C "$(shell pwd)" _uninstall diff --git a/plugins/provider/fileProvider/README b/plugins/provider/fileProvider/README new file mode 100644 index 0000000..83f19c1 --- /dev/null +++ b/plugins/provider/fileProvider/README @@ -0,0 +1,28 @@ +README File provider + +This is a sub-plug in for the VDR UPnP/DLNA media server plug in. + +Created on: 28.10.2012 +Written by: Denis Loh + +Projekt homepage: http://upnp.vdr-developer.org + +Latest version available at: http://upnp.vdr-developer.org + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Description: + +The file provider provides access to any files on the file system. It +scans all files, which listed in the directory configuration file of +the sub-plug in. + +It provides the following URI scheme: file:// + +Additionally, it is used to access the files for streaming. + +The provider implemented the seekable interface and therefore allows +seeking in the files via byte based seeks.
\ No newline at end of file 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); + +} + |