diff options
author | geronimo <geronimo013@gmx.de> | 2012-07-29 16:00:29 +0200 |
---|---|---|
committer | geronimo <geronimo013@gmx.de> | 2012-07-29 16:00:29 +0200 |
commit | aa714b0076c06d7133c625ab22c86114d4f17e23 (patch) | |
tree | f4773543d7c0bf593c20b1a033dea8dc28dd8ad5 /libs | |
parent | 4039d18078da508ba8c628df8e2aa741cf91f266 (diff) | |
download | cmp-aa714b0076c06d7133c625ab22c86114d4f17e23.tar.gz cmp-aa714b0076c06d7133c625ab22c86114d4f17e23.tar.bz2 |
cleanup
Diffstat (limited to 'libs')
-rw-r--r-- | libs/IO/.dep.inc | 5 | ||||
-rw-r--r-- | libs/IO/IO.cbp.save | 68 | ||||
-rw-r--r-- | libs/IO/IO.layout.save | 34 | ||||
-rw-r--r-- | libs/IO/include/ConfigReader.h | 48 | ||||
-rw-r--r-- | libs/IO/include/File.h | 67 | ||||
-rw-r--r-- | libs/IO/include/FileReader.h | 44 | ||||
-rw-r--r-- | libs/IO/include/FileRepresentation.h | 56 | ||||
-rw-r--r-- | libs/IO/include/FileSystem.h | 52 | ||||
-rw-r--r-- | libs/IO/include/LineReader.h | 48 | ||||
-rw-r--r-- | libs/IO/src/ConfigReader.cc | 64 | ||||
-rw-r--r-- | libs/IO/src/File.cc | 185 | ||||
-rw-r--r-- | libs/IO/src/FileReader.cc | 63 | ||||
-rw-r--r-- | libs/IO/src/FileRepresentation.cc | 132 | ||||
-rw-r--r-- | libs/IO/src/FileSystem.cc | 141 | ||||
-rw-r--r-- | libs/IO/src/LineReader.cc | 100 | ||||
-rw-r--r-- | libs/fsScan/fsScan.layout.save | 34 | ||||
-rw-r--r-- | libs/networking/networking.layout.save | 54 | ||||
-rw-r--r-- | libs/util/util.layout.save | 54 | ||||
-rw-r--r-- | libs/vdr/vdr.layout.save | 44 |
19 files changed, 1005 insertions, 288 deletions
diff --git a/libs/IO/.dep.inc b/libs/IO/.dep.inc new file mode 100644 index 0000000..4560e55 --- /dev/null +++ b/libs/IO/.dep.inc @@ -0,0 +1,5 @@ +# This code depends on make tool being used +DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES})) +ifneq (${DEPFILES},) +include ${DEPFILES} +endif diff --git a/libs/IO/IO.cbp.save b/libs/IO/IO.cbp.save deleted file mode 100644 index 52f0fe6..0000000 --- a/libs/IO/IO.cbp.save +++ /dev/null @@ -1,68 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_project_file> - <FileVersion major="1" minor="6" /> - <Project> - <Option title="CMP.libs.IO" /> - <Option pch_mode="2" /> - <Option compiler="gcc" /> - <Build> - <Target title="Debug"> - <Option output="IO" prefix_auto="1" extension_auto="1" /> - <Option working_dir="" /> - <Option object_output="obj/Debug/" /> - <Option type="2" /> - <Option compiler="gcc" /> - <Option createDefFile="1" /> - <Compiler> - <Add option="-Wall" /> - <Add option="-g" /> - </Compiler> - </Target> - <Target title="Release"> - <Option output="IO" prefix_auto="1" extension_auto="1" /> - <Option working_dir="" /> - <Option object_output="obj/Release/" /> - <Option type="2" /> - <Option compiler="gcc" /> - <Option createDefFile="1" /> - <Compiler> - <Add option="-Wall" /> - <Add option="-O2" /> - </Compiler> - <Linker> - <Add option="-s" /> - </Linker> - </Target> - </Build> - <Compiler> - <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration" /> - <Add option="-D_REENTRANT" /> - <Add option="-D_GNU_SOURCE=1" /> - <Add option="-D_FILE_OFFSET_BITS=64" /> - <Add option="-D_LARGEFILE_SOURCE" /> - <Add option="-D_LARGEFILE64_SOURCE" /> - <Add option="-D__STDC_CONSTANT_MACROS" /> - <Add option="-D__STDC_FORMAT_MACROS" /> - <Add option="-D__STDC_LIMIT_MACROS" /> - <Add directory="include" /> - <Add directory="../util/include" /> - <Add directory="../vdr/include" /> - </Compiler> - <Unit filename="include/File.h" /> - <Unit filename="include/FileReader.h" /> - <Unit filename="include/FileRepresentation.h" /> - <Unit filename="include/FileSystem.h" /> - <Unit filename="include/LineReader.h" /> - <Unit filename="src/File.cc" /> - <Unit filename="src/FileReader.cc" /> - <Unit filename="src/FileRepresentation.cc" /> - <Unit filename="src/FileSystem.cc" /> - <Unit filename="src/LineReader.cc" /> - <Extensions> - <code_completion /> - <envvars /> - <lib_finder disable_auto="1" /> - <debugger /> - </Extensions> - </Project> -</CodeBlocks_project_file> diff --git a/libs/IO/IO.layout.save b/libs/IO/IO.layout.save deleted file mode 100644 index e837daf..0000000 --- a/libs/IO/IO.layout.save +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_layout_file> - <ActiveTarget name="Debug" /> - <File name="src/ConfigReader.cc" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/File.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1638" topLine="30" /> - </Cursor> - </File> - <File name="src/FileReader.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1320" topLine="0" /> - </Cursor> - </File> - <File name="src/FileRepresentation.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1846" topLine="0" /> - </Cursor> - </File> - <File name="include/ConfigReader.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="475" topLine="0" /> - </Cursor> - </File> - <File name="src/LineReader.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="854" topLine="0" /> - </Cursor> - </File> -</CodeBlocks_layout_file> diff --git a/libs/IO/include/ConfigReader.h b/libs/IO/include/ConfigReader.h new file mode 100644 index 0000000..f3aa5eb --- /dev/null +++ b/libs/IO/include/ConfigReader.h @@ -0,0 +1,48 @@ +/** + * ======================== legal notice ====================== + * + * File: ConfigReader.h + * Created: 28. Juli 2012, 18:41 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef CONFIGREADER_H +#define CONFIGREADER_H + +#include <tuple> +#include <string> + +class cLineReader; +class cConfigReader +{ +public: + typedef std::tuple <std::string, std::string> ConfigEntry; + + cConfigReader(cLineReader *LineReader); + virtual ~cConfigReader(); + + void Close(void); + ConfigEntry *ReadValue(void); + +private: + cLineReader *reader; + }; + +#endif /* CONFIGREADER_H */ + diff --git a/libs/IO/include/File.h b/libs/IO/include/File.h new file mode 100644 index 0000000..b531bfc --- /dev/null +++ b/libs/IO/include/File.h @@ -0,0 +1,67 @@ +/** + * ======================== legal notice ====================== + * + * File: File.h + * Created: 21. Juli 2012, 12 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef FILE_H +#define FILE_H + +#include <stddef.h> +#include <sys/types.h> + +class cFileSystem; +class cFileRepresentation; +class cStringBuilder; +class cFile { +public: + cFile(const char *Path = NULL); + cFile(const cFile &other); + cFile(const cFile &Parent, const char *RelativePath); + virtual ~cFile(); + + cFile &operator =(const cFile &other); + bool CanRead(void) const; + bool CanWrite(void) const; + bool CanExecute(void) const; + bool Exists(void) const; + bool IsDirectory(void) const; + bool IsFile(void) const; + bool IsSymbolic(void) const; + off64_t Size(void) const; + ulong LastModified(void) const; + const char *Name(void) const; + void SetVirtualRoot(bool isRoot = true); + const char *AbsolutePath(void) const; ///< returns an allocated string + char *toURI(void) const; ///< returns an allocated string + cFile *Parent(void) const; ///< allocates a new file instance! + void VisitFiles(int (*cb)(void *, cFile *, const char *), void *opaque); + static void Cleanup(void); + +private: + cFile(const cFileRepresentation *); + const cFileRepresentation *rep; + static cFileSystem *fs; + friend class cFileSystem; + }; + +#endif /* FILE_H */ + diff --git a/libs/IO/include/FileReader.h b/libs/IO/include/FileReader.h new file mode 100644 index 0000000..31cb7d6 --- /dev/null +++ b/libs/IO/include/FileReader.h @@ -0,0 +1,44 @@ +/** + * ======================== legal notice ====================== + * + * File: FileReader.h + * Created: 28. Juli 2012, 15:00 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef FILEREADER_H +#define FILEREADER_H + +class cFile; +class cFileReader +{ +public: + cFileReader(cFile *Input); + virtual ~cFileReader(); + + int Read(char *buf, int bufSize); + void Close(); + +private: + int fd; + cFile *file; + }; + +#endif /* FILEREADER_H */ + diff --git a/libs/IO/include/FileRepresentation.h b/libs/IO/include/FileRepresentation.h new file mode 100644 index 0000000..2c2db5a --- /dev/null +++ b/libs/IO/include/FileRepresentation.h @@ -0,0 +1,56 @@ +/** + * ======================== legal notice ====================== + * + * File: FileRepresentation.h + * Created: 21. Juli 2012, 12 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef FILEREPRESENTATION_H +#define FILEREPRESENTATION_H + +#include <sys/types.h> + +class cStringBuilder; +class cFileRepresentation { +public: + virtual ~cFileRepresentation(); + + const char *Path(void) const; + const cFileRepresentation *getParent(void) const { return parent; }; + void SetVirtualRoot(bool isRoot); + +private: + cFileRepresentation(const char *Name); + cFileRepresentation(const cFileRepresentation *Parent, const char *Name); + char *toURI(void) const; + bool exists; + bool isRoot; + bool isVirtualRoot; + mode_t mode; + off64_t size; + ulong lastModified; + char *name; + mutable char *path; + const cFileRepresentation *parent; + friend class cFileSystem; + friend class cFile; + }; + +#endif // FILEREPRESENTATION_H diff --git a/libs/IO/include/FileSystem.h b/libs/IO/include/FileSystem.h new file mode 100644 index 0000000..cd085db --- /dev/null +++ b/libs/IO/include/FileSystem.h @@ -0,0 +1,52 @@ +/** + * ======================== legal notice ====================== + * + * File: FileSystem.h + * Created: 21. Juli 2012, 12 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef FILESYSTEM_H +#define FILESYSTEM_H + +#include <tr1/unordered_map> +#include <string> + +class cFile; +class cFileRepresentation; +class cFileSystem { +public: + cFileSystem(); + virtual ~cFileSystem(); + + cFileRepresentation *representationOfFile(const char *Path); + cFileRepresentation *representationOfFile(const cFile &Parent, const char *Path); + +private: + cFileRepresentation *cacheEntry(const char *Path); + cFileRepresentation *representationOfFile(const cFileRepresentation *parentRep, const char* Path); + std::tr1::unordered_map<std::string, cFileRepresentation *> fileCache; + static char PathSeparator; + static char RootPath[4]; + friend class cFileRepresentation; + friend class cFile; + }; + +#endif /* FILESYSTEM_H */ + diff --git a/libs/IO/include/LineReader.h b/libs/IO/include/LineReader.h new file mode 100644 index 0000000..8b8b754 --- /dev/null +++ b/libs/IO/include/LineReader.h @@ -0,0 +1,48 @@ +/** + * ======================== legal notice ====================== + * + * File: LineReader.h + * Created: 28. Juli 2012, 06 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef LINEREADER_H +#define LINEREADER_H + + +class cFileReader; +class cLineReader +{ +public: + cLineReader(cFileReader *FileReader); + virtual ~cLineReader(); + + const char *ReadLine(void); + void Close(void); + +private: + cFileReader *reader; + int bytesRead; + int off; + int bufSize; + char *buf; + char *lastLine; + }; + +#endif // LINEREADER_H diff --git a/libs/IO/src/ConfigReader.cc b/libs/IO/src/ConfigReader.cc new file mode 100644 index 0000000..152c908 --- /dev/null +++ b/libs/IO/src/ConfigReader.cc @@ -0,0 +1,64 @@ +/** + * ======================== legal notice ====================== + * + * File: ConfigReader.cc + * Created: 28. Juli 2012, 18:41 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <ConfigReader.h> +#include <LineReader.h> +#include <stddef.h> +#include <pcrecpp.h> + +cConfigReader::cConfigReader(cLineReader *LineReader) + : reader(LineReader) +{ +} + +cConfigReader::~cConfigReader() +{ + Close(); +} + +void cConfigReader::Close(void) +{ + if (reader) { + delete reader; + reader = NULL; + } +} + +cConfigReader::ConfigEntry *cConfigReader::ReadValue() +{ + if (!reader) return NULL; + const char *line = reader->ReadLine(); + static pcrecpp::RE comment("^\\s*#.*$"); + static pcrecpp::RE emptyLine("^\\s*$"); + static pcrecpp::RE entry("^\\s*(\\S+)\\s*=\\s*(.+)$"); + std::string name, value; + ConfigEntry *rv = NULL; + + while (line && (comment.FullMatch(line) || emptyLine.FullMatch(line))) + line = reader->ReadLine(); + if (line && entry.FullMatch(line, &name, &value)) { + rv = new ConfigEntry(name, value); + } + return rv; +} diff --git a/libs/IO/src/File.cc b/libs/IO/src/File.cc new file mode 100644 index 0000000..6770ec8 --- /dev/null +++ b/libs/IO/src/File.cc @@ -0,0 +1,185 @@ +/** + * ======================== legal notice ====================== + * + * File: File.cc + * Created: 21. Juli 2012, 12 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <File.h> +#include <FileSystem.h> +#include <FileRepresentation.h> +#include <StringBuilder.h> +#include <sys/stat.h> +#include <sys/dir.h> + +cFileSystem *cFile::fs = NULL; +static mode_t ReadMask = S_IRUSR | S_IRGRP | S_IROTH; +static mode_t WriteMask = S_IWUSR | S_IWGRP | S_IWOTH; +static mode_t ExecMask = S_IXUSR | S_IXGRP | S_IXOTH; + + +cFile::cFile(const char *Path) + : rep(NULL) +{ + if (!fs) fs = new cFileSystem(); + if (!Path || *Path != cFileSystem::PathSeparator) { + char *wd = getcwd(NULL, 0); + rep = fs->representationOfFile(wd); + free(wd); + if (Path) rep = fs->representationOfFile(rep, Path); + } + else rep = fs->representationOfFile(Path); +} + +cFile::cFile(const cFile &other) + : rep(other.rep) +{ + if (!fs) fs = new cFileSystem(); +} + +cFile::cFile(const cFile& Parent, const char* RelativePath) + : rep(NULL) +{ + if (!fs) fs = new cFileSystem(); + rep = fs->representationOfFile(Parent, RelativePath); +} + +cFile::cFile(const cFileRepresentation *fr) + : rep(fr) +{ + if (!fs) fs = new cFileSystem(); +} + +cFile::~cFile() +{ +} + +cFile &cFile::operator =(const cFile &other) +{ + rep = other.rep; + return *this; +} + +const char *cFile::AbsolutePath(void) const +{ + if (rep) return rep->Path(); + return NULL; +} + +bool cFile::Exists(void) const +{ + if (rep) return rep->exists; + return false; +} + +bool cFile::IsDirectory(void) const +{ + if (rep) return (rep->mode & S_IFMT) == S_IFDIR; + return false; +} + +bool cFile::IsFile(void) const +{ + if (rep) return (rep->mode & S_IFMT) == S_IFREG; + return false; +} + +bool cFile::IsSymbolic(void) const +{ + if (rep) return (rep->mode & S_IFMT) == S_IFLNK; + return false; +} + +bool cFile::CanRead(void) const +{ + if (rep) return rep->mode & ReadMask; + return false; +} + +bool cFile::CanWrite(void) const +{ + if (rep) return rep->mode & WriteMask; + return false; +} + +bool cFile::CanExecute(void) const +{ + if (rep) return rep->mode & ExecMask; + return false; +} + +off64_t cFile::Size(void) const +{ + if (rep) return rep->size; + return 0; +} + +ulong cFile::LastModified(void) const +{ + if (rep) return rep->lastModified; + return 0; +} + +cFile *cFile::Parent(void) const +{ + if (rep) return new cFile(rep->getParent()); + return NULL; +} + +const char *cFile::Name(void) const +{ + if (rep) return rep->name; + return NULL; +} + +void cFile::Cleanup(void) +{ + if (fs) { + delete fs; + fs = NULL; + } +} + +void cFile::VisitFiles(int (*cb)(void *, cFile *, const char *), void *opaque) +{ + if (!Exists() || !IsDirectory()) return; + const char *path = AbsolutePath(); + + if (!path) return; + struct dirent entryBuffer, *pE = NULL; + DIR *dir = opendir(path); + + while (!readdir_r(dir, &entryBuffer, &pE) && pE) { + if (*(pE->d_name) == '.') continue; // don't bother with hidden stuff + cb(opaque, this, pE->d_name); + } + closedir(dir); +} + +char *cFile::toURI() const +{ + if (rep) return rep->toURI(); + return NULL; +} + +void cFile::SetVirtualRoot(bool isRoot) +{ + if (rep) ((cFileRepresentation *)rep)->SetVirtualRoot(isRoot); +} diff --git a/libs/IO/src/FileReader.cc b/libs/IO/src/FileReader.cc new file mode 100644 index 0000000..519c749 --- /dev/null +++ b/libs/IO/src/FileReader.cc @@ -0,0 +1,63 @@ +/** + * ======================== legal notice ====================== + * + * File: FileReader.cc + * Created: 28. Juli 2012, 15:00 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <FileReader.h> +#include <File.h> +#include <Logging.h> +#include <fcntl.h> +#include <unistd.h> + +cFileReader::cFileReader(cFile *Input) + : fd(-1) + , file(Input) +{ + if (file && file->Exists() && file->CanRead()) { + fd = open(file->AbsolutePath(), O_RDONLY); + if (fd < 0) esyslog("ERROR: could not open %s", file->AbsolutePath()); + } +} + +cFileReader::~cFileReader() +{ + Close(); +} + +void cFileReader::Close() +{ + if (fd >= 0) { + close(fd); + fd = -1; + } + if (file) { + delete file; + file = NULL; + } +} + +int cFileReader::Read(char* buf, int bufSize) +{ + if (fd >= 0) return read(fd, buf, bufSize); + esyslog("ERROR: not an open file! %s", file->AbsolutePath()); + return 0; +} diff --git a/libs/IO/src/FileRepresentation.cc b/libs/IO/src/FileRepresentation.cc new file mode 100644 index 0000000..f74d2c8 --- /dev/null +++ b/libs/IO/src/FileRepresentation.cc @@ -0,0 +1,132 @@ +/** + * ======================== legal notice ====================== + * + * File: FileRepresentation.cc + * Created: 21. Juli 2012, 12 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <FileRepresentation.h> +#include <FileSystem.h> +#include <StringBuilder.h> +#include <Url.h> +#include <Codec.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdlib.h> +#include <iostream> +#include <stack> + +cFileRepresentation::cFileRepresentation(const char *Name) + : exists(false) + , isRoot(true) + , isVirtualRoot(true) + , mode(0) + , size(0) + , lastModified(0) + , name(NULL) + , path(NULL) + , parent(NULL) +{ + struct stat st; + + if (!stat(Name, &st)) { + name = strdup(Name); + exists = true; + mode = st.st_mode; + size = st.st_size; + lastModified = st.st_mtime; + } +} + +cFileRepresentation::cFileRepresentation(const cFileRepresentation *Parent, const char *Name) + : exists(false) + , isRoot(false) + , isVirtualRoot(false) + , mode(0) + , size(0) + , lastModified(0) + , name(strdup(Name)) + , path(NULL) + , parent(Parent) +{ + struct stat st; + + if (!stat(Path(), &st)) { + exists = true; + mode = st.st_mode; + size = st.st_size; + lastModified = st.st_mtime; + } +} + +cFileRepresentation::~cFileRepresentation() +{ + free(name); + free(path); +} + +const char *cFileRepresentation::Path() const +{ + if (!path) { + cStringBuilder sb; + + if (parent) sb.Append(parent->Path()); + if (strcmp(cFileSystem::RootPath, name)) sb.Append(cFileSystem::PathSeparator).Append(name); + path = sb.toString(); + } + return path; +} + +void cFileRepresentation::SetVirtualRoot(bool isRoot) +{ + isVirtualRoot = isRoot; +} + +char *cFileRepresentation::toURI() const +{ + cStringBuilder *sb = new cStringBuilder(); + const cFileRepresentation *f = this; + std::stack<const cFileRepresentation *> rev; + cURLEncoder *enc = cUrl::Encoder(); + char *tmp, *chk, *rv; + size_t stackSize; + + while (!f->isVirtualRoot) { + rev.push(f); + stackSize = rev.size(); + f = f->parent; + } + + for (;;) { + f = rev.top(); + rev.pop(); + chk = f->name + strlen(f->name) - 1; + if (*chk != cFileSystem::PathSeparator) sb->Append(cFileSystem::PathSeparator); + tmp = enc->Encode(f->name); + sb->Append(tmp); + free(tmp); + if (rev.empty()) break; + } + rv = sb->toString(); + delete sb; + + return rv; +} diff --git a/libs/IO/src/FileSystem.cc b/libs/IO/src/FileSystem.cc new file mode 100644 index 0000000..049ca07 --- /dev/null +++ b/libs/IO/src/FileSystem.cc @@ -0,0 +1,141 @@ +/** + * ======================== legal notice ====================== + * + * File: FileSystem.cc + * Created: 21. Juli 2012, 12 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <FileSystem.h> +#include <FileRepresentation.h> +#include <File.h> +#include <StringBuilder.h> +#include <iostream> +#include <stdlib.h> +#include <string.h> + +char cFileSystem::PathSeparator = '/'; +char cFileSystem::RootPath[4] = { PathSeparator, 0, 0, 0 }; + +cFileSystem::cFileSystem() +{ +} + +cFileSystem::~cFileSystem() +{ + std::tr1::unordered_map<std::string, cFileRepresentation *>::iterator it = fileCache.begin(); + + while (it != fileCache.end()) { + if (it->second) delete it->second; + ++it; + } +} + +cFileRepresentation *cFileSystem::cacheEntry(const char* Path) +{ + if (fileCache.empty()) return NULL; + std::tr1::unordered_map<std::string, cFileRepresentation *>::iterator it = fileCache.find(Path); + + if (it != fileCache.end()) return it->second; + return NULL; +} + +cFileRepresentation *cFileSystem::representationOfFile(const cFile &Parent, const char* Path) +{ + cFileRepresentation *parentRep = (cFileRepresentation *) Parent.rep; + + return representationOfFile(parentRep, Path); +} + +cFileRepresentation *cFileSystem::representationOfFile(const cFileRepresentation *parentRep, const char* Path) +{ + cFileRepresentation *tmp = NULL; + cStringBuilder *sb = new cStringBuilder(parentRep->Path()); + char *scratch = strdup(Path); + char *last = scratch + strlen(Path); + char *start = *scratch == PathSeparator ? scratch + 1 : scratch; + char *end = strchr(scratch, PathSeparator); + char *path; + + while (start < last) { + end = strchr(start, PathSeparator); + if (!end) end = start + strlen(start); + *end = 0; + sb->Append(PathSeparator).Append(start); + path = sb->toString(); + tmp = cacheEntry(path); + if (!tmp) { + tmp = new cFileRepresentation(parentRep, start); + fileCache[path] = tmp; + } + parentRep = tmp; + free(path); + start = end + 1; + } + free(scratch); + delete sb; + + if (tmp) return tmp; + return NULL; +} + +cFileRepresentation *cFileSystem::representationOfFile(const char* Path) +{ + cFileRepresentation *rv = cacheEntry(Path); + + if (!rv) { + cFileRepresentation *tmp = NULL; + char *scratch = strdup(Path); + char *p, *last = scratch + strlen(Path); + + for (p = strrchr(scratch, PathSeparator); !rv && p && p < last; p = strrchr(scratch, PathSeparator)) { + if (p > scratch) *p = 0; + else { + *p = 0; + if (!(rv = cacheEntry(RootPath))) { + tmp = new cFileRepresentation(RootPath); + fileCache[RootPath] = tmp; + break; + } + } + if ((tmp = cacheEntry(scratch))) break; + } + if (rv && strcmp(rv->Path(), Path)) { + tmp = rv; + rv = NULL; + } + if (tmp) { + cFileRepresentation *parent = tmp; + size_t poolSize = fileCache.size(); + const char *last = scratch + strlen(Path); + + for (p = scratch + strlen(scratch) + 1; p < last; p += strlen(p) + 1) { + if (!*(p - 1)) *(p - 1) = PathSeparator; + tmp = new cFileRepresentation(parent, p); + fileCache[scratch] = tmp; + poolSize = fileCache.size(); + parent = tmp; + } + rv = parent; + } + free(scratch); + } + return rv; +} + diff --git a/libs/IO/src/LineReader.cc b/libs/IO/src/LineReader.cc new file mode 100644 index 0000000..bf4bcc2 --- /dev/null +++ b/libs/IO/src/LineReader.cc @@ -0,0 +1,100 @@ +/** + * ======================== legal notice ====================== + * + * File: LineReader.cc + * Created: 28. Juli 2012, 06 + * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> + * Project: libIO: classes for files, filesystem and input/output + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#include <LineReader.h> +#include <FileReader.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <unistd.h> +#include <iostream> + +cLineReader::cLineReader(cFileReader *FileReader) + : reader(FileReader) + , bytesRead(0) + , off(0) + , bufSize(1024) + , buf(NULL) + , lastLine(NULL) +{ + buf = (char *) malloc(bufSize + 1); + if (buf) { + buf[bufSize] = 0; + *buf = 0; + } +} + +cLineReader::~cLineReader() +{ + Close(); +} + +void cLineReader::Close() +{ + if (reader) { + delete reader; + reader = NULL; + } + free(buf); + buf = NULL; + off = NULL; +} + +const char *cLineReader::ReadLine(void) +{ + const char *rv = NULL; + char *p; + + if (lastLine) lastLine += strlen(lastLine) + 1; + else lastLine = buf; + if (bytesRead && lastLine - buf >= bytesRead) return NULL; + p = strchr(lastLine, '\n'); + + if (!p && strlen(lastLine)) { + memmove(buf, lastLine, strlen(lastLine)); + buf[strlen(lastLine)] = 0; + lastLine = buf; + } + + if (!p && (!bytesRead || bytesRead == bufSize)) { + bytesRead = strlen(buf); + int br = reader->Read(buf + bytesRead, bufSize - bytesRead); + + if (br > 0) bytesRead += br; + if (bytesRead < bufSize) memset(buf + bytesRead, 0, bufSize - bytesRead); + } + + if (!p) p = strchr(lastLine, '\n'); + + if (p) { + if (p - buf <= bytesRead) { + *p = 0; + rv = lastLine; + } + } + else { + if (strlen(lastLine)) rv = lastLine; + } + return rv; +} diff --git a/libs/fsScan/fsScan.layout.save b/libs/fsScan/fsScan.layout.save deleted file mode 100644 index 2db2bda..0000000 --- a/libs/fsScan/fsScan.layout.save +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_layout_file> - <ActiveTarget name="Debug" /> - <File name="src/AbstractMedia.cc" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1453" topLine="0" /> - </Cursor> - </File> - <File name="src/MediaFactory.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1317" topLine="18" /> - </Cursor> - </File> - <File name="src/LegacyVdrRecording.cc" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1450" topLine="0" /> - </Cursor> - </File> - <File name="include/MediaFactory.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1670" topLine="0" /> - </Cursor> - </File> - <File name="src/VdrRecording.cc" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1404" topLine="0" /> - </Cursor> - </File> - <File name="include/AbstractMedia.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1008" topLine="0" /> - </Cursor> - </File> -</CodeBlocks_layout_file> diff --git a/libs/networking/networking.layout.save b/libs/networking/networking.layout.save deleted file mode 100644 index d0cb4d6..0000000 --- a/libs/networking/networking.layout.save +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_layout_file> - <ActiveTarget name="Debug" /> - <File name="src/ConnectionHandler.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1551" topLine="0" /> - </Cursor> - </File> - <File name="include/ConnectionPoint.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/ConnectionPoint.cc" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/HTTPFileResponse.cc" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/HTTPMessage.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/ConnectionHandler.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/HTTPMessage.cc" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/ServerConfig.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/HTTPResponse.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/ServerConfig.cc" open="1" top="1" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1538" topLine="0" /> - </Cursor> - </File> -</CodeBlocks_layout_file> diff --git a/libs/util/util.layout.save b/libs/util/util.layout.save deleted file mode 100644 index ef999ec..0000000 --- a/libs/util/util.layout.save +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_layout_file> - <ActiveTarget name="Debug" /> - <File name="src/AbstractListAssembler.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/Codec.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1385" topLine="0" /> - </Cursor> - </File> - <File name="include/ManagedMap.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/StringBuilder.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1953" topLine="59" /> - </Cursor> - </File> - <File name="src/Codec.cc" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1327" topLine="0" /> - </Cursor> - </File> - <File name="include/ManagedVector.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/StringBuilder.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1959" topLine="0" /> - </Cursor> - </File> - <File name="src/ManagedMap.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/JSonWriter.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1655" topLine="3" /> - </Cursor> - </File> - <File name="include/JSonWriter.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1532" topLine="0" /> - </Cursor> - </File> -</CodeBlocks_layout_file> diff --git a/libs/vdr/vdr.layout.save b/libs/vdr/vdr.layout.save deleted file mode 100644 index a8d4974..0000000 --- a/libs/vdr/vdr.layout.save +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_layout_file> - <ActiveTarget name="Debug" /> - <File name="src/TimeMs.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="2160" topLine="0" /> - </Cursor> - </File> - <File name="include/Logging.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1690" topLine="0" /> - </Cursor> - </File> - <File name="src/CharsetConv.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="3680" topLine="57" /> - </Cursor> - </File> - <File name="src/i18n.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/Thread.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="src/Thread.cc" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="0" topLine="0" /> - </Cursor> - </File> - <File name="include/CharsetConv.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="5244" topLine="0" /> - </Cursor> - </File> - <File name="src/Logging.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> - <Cursor> - <Cursor1 position="1283" topLine="0" /> - </Cursor> - </File> -</CodeBlocks_layout_file> |