summaryrefslogtreecommitdiff
path: root/libs/IO
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-29 15:15:58 +0200
committergeronimo <geronimo013@gmx.de>2012-07-29 15:15:58 +0200
commit4039d18078da508ba8c628df8e2aa741cf91f266 (patch)
treef5914b1767c612aad44a9d8a335bafa96940de81 /libs/IO
parent85cb3f04252b0228830903b21c08bb64e9919c18 (diff)
downloadcmp-4039d18078da508ba8c628df8e2aa741cf91f266.tar.gz
cmp-4039d18078da508ba8c628df8e2aa741cf91f266.tar.bz2
files have been moved
Diffstat (limited to 'libs/IO')
-rw-r--r--libs/IO/File.cc181
-rw-r--r--libs/IO/File.h67
-rw-r--r--libs/IO/FileRepresentation.cc132
-rw-r--r--libs/IO/FileRepresentation.h56
-rw-r--r--libs/IO/FileSystem.cc132
-rw-r--r--libs/IO/FileSystem.h50
6 files changed, 0 insertions, 618 deletions
diff --git a/libs/IO/File.cc b/libs/IO/File.cc
deleted file mode 100644
index 477c5c8..0000000
--- a/libs/IO/File.cc
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: File.cc
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 = getcwd(NULL, 0);
- rep = fs->representationOfFile(Path);
- free((char *) 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;
- struct dirent entryBuffer, *pE;
- DIR *dir = opendir(AbsolutePath());
-
- 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/File.h b/libs/IO/File.h
deleted file mode 100644
index 587d99c..0000000
--- a/libs/IO/File.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: File.h
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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/FileRepresentation.cc b/libs/IO/FileRepresentation.cc
deleted file mode 100644
index 81599a3..0000000
--- a/libs/IO/FileRepresentation.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileRepresentation.cc
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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());
- 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/FileRepresentation.h b/libs/IO/FileRepresentation.h
deleted file mode 100644
index 39a3c1e..0000000
--- a/libs/IO/FileRepresentation.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileRepresentation.h
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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/FileSystem.cc b/libs/IO/FileSystem.cc
deleted file mode 100644
index 3891c97..0000000
--- a/libs/IO/FileSystem.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileSystem.cc
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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;
- cFileRepresentation *tmp = NULL;
- cStringBuilder *sb = new cStringBuilder(Parent.AbsolutePath());
- 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;
-
- for (p = strrchr(scratch, PathSeparator); !rv && p; p = strrchr(scratch, PathSeparator)) {
- if (p > scratch) *p = 0;
- else {
- if (!(rv = cacheEntry(RootPath))) {
- *p = 0;
- tmp = new cFileRepresentation(RootPath);
- fileCache[RootPath] = tmp;
- break;
- }
- }
- if ((tmp = cacheEntry(scratch))) break;
- }
-
- 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/FileSystem.h b/libs/IO/FileSystem.h
deleted file mode 100644
index 0cf4a2f..0000000
--- a/libs/IO/FileSystem.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileSystem.h
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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);
- std::tr1::unordered_map<std::string, cFileRepresentation *> fileCache;
- static char PathSeparator;
- static char RootPath[4];
- friend class cFileRepresentation;
- };
-
-#endif /* FILESYSTEM_H */
-