summaryrefslogtreecommitdiff
path: root/libs/fsScan/src
diff options
context:
space:
mode:
Diffstat (limited to 'libs/fsScan/src')
-rw-r--r--libs/fsScan/src/AbstractMedia.cc2
-rw-r--r--libs/fsScan/src/AbstractMultiFileMovie.cc2
-rw-r--r--libs/fsScan/src/Audio.cc2
-rw-r--r--libs/fsScan/src/DVDImage.cc2
-rw-r--r--libs/fsScan/src/File.cc146
-rw-r--r--libs/fsScan/src/FileRepresentation.cc109
-rw-r--r--libs/fsScan/src/FileSystem.cc132
-rw-r--r--libs/fsScan/src/FilesystemScanner.cc14
-rw-r--r--libs/fsScan/src/LegacyVdrRecording.cc2
-rw-r--r--libs/fsScan/src/MediaFactory.cc2
-rw-r--r--libs/fsScan/src/Movie.cc2
-rw-r--r--libs/fsScan/src/Picture.cc2
-rw-r--r--libs/fsScan/src/VdrRecording.cc2
13 files changed, 403 insertions, 16 deletions
diff --git a/libs/fsScan/src/AbstractMedia.cc b/libs/fsScan/src/AbstractMedia.cc
index 3a3556b..17cf86c 100644
--- a/libs/fsScan/src/AbstractMedia.cc
+++ b/libs/fsScan/src/AbstractMedia.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: AbstractMedia.cc
- * Created: 2. Juli 2012, 14:33
+ * Created: 2. Juli 2012, 14
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/AbstractMultiFileMovie.cc b/libs/fsScan/src/AbstractMultiFileMovie.cc
index bcbd115..823130e 100644
--- a/libs/fsScan/src/AbstractMultiFileMovie.cc
+++ b/libs/fsScan/src/AbstractMultiFileMovie.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: AbstractMultiFileMovie.cc
- * Created: 3. Juli 2012, 07:39
+ * Created: 3. Juli 2012, 07
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/Audio.cc b/libs/fsScan/src/Audio.cc
index 25521dc..6d92576 100644
--- a/libs/fsScan/src/Audio.cc
+++ b/libs/fsScan/src/Audio.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: Audio.cc
- * Created: 2. Juli 2012, 15:00
+ * Created: 2. Juli 2012, 15
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/DVDImage.cc b/libs/fsScan/src/DVDImage.cc
index 5ffb170..6ce7d30 100644
--- a/libs/fsScan/src/DVDImage.cc
+++ b/libs/fsScan/src/DVDImage.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: DVDImage.cc
- * Created: 3. Juli 2012, 08:34
+ * Created: 3. Juli 2012, 08
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/File.cc b/libs/fsScan/src/File.cc
new file mode 100644
index 0000000..c88fd7c
--- /dev/null
+++ b/libs/fsScan/src/File.cc
@@ -0,0 +1,146 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: File.cc
+ * Created: 21. Juli 2012, 12:41
+ * 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();
+ rep = fs->representationOfFile(Path);
+}
+
+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()
+{
+}
+
+char *cFile::AbsolutePath(void) const
+{
+ cStringBuilder *sb = rep->internalPath();
+ char *rv = NULL;
+
+ if (sb) {
+ rv = sb->toString();
+ delete sb;
+ }
+ return rv;
+}
+
+bool cFile::Exists(void) const
+{
+ return rep->exists;
+}
+
+bool cFile::IsDirectory(void) const
+{
+ return (rep->mode & S_IFMT) == S_IFDIR;
+}
+
+bool cFile::IsFile(void) const
+{
+ return (rep->mode & S_IFMT) == S_IFREG;
+}
+
+bool cFile::IsSymbolic(void) const
+{
+ return (rep->mode & S_IFMT) == S_IFLNK;
+}
+
+bool cFile::CanRead(void) const
+{
+ return rep->mode & ReadMask;
+}
+
+bool cFile::CanWrite(void) const
+{
+ return rep->mode & WriteMask;
+}
+
+bool cFile::CanExecute(void) const
+{
+ return rep->mode & ExecMask;
+}
+
+off64_t cFile::Size(void) const
+{
+ return rep->size;
+}
+
+ulong cFile::LastModified(void) const
+{
+ return rep->lastModified;
+}
+
+cFile *cFile::Parent(void) const
+{
+ return new cFile(rep->getParent());
+}
+
+const char *cFile::Name(void) const
+{
+ return rep->name;
+}
+
+void cFile::Cleanup(void)
+{
+ if (fs) delete fs;
+}
+
+void cFile::VisitFiles(int (*cb)(cFile *, const char *))
+{
+ struct dirent entryBuffer, *pE;
+ char * path = AbsolutePath();
+ DIR *dir = opendir(path);
+
+ while (!readdir_r(dir, &entryBuffer, &pE) && pE) {
+ if (*(pE->d_name) == '.') continue; // don't bother with hidden stuff
+ cb(this, pE->d_name);
+ }
+ closedir(dir);
+ free(path);
+}
diff --git a/libs/fsScan/src/FileRepresentation.cc b/libs/fsScan/src/FileRepresentation.cc
new file mode 100644
index 0000000..8899e16
--- /dev/null
+++ b/libs/fsScan/src/FileRepresentation.cc
@@ -0,0 +1,109 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: FileRepresentation.cc
+ * Created: 21. Juli 2012, 12:41
+ * 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 <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+#include <iostream>
+#include <stack>
+
+cFileRepresentation::cFileRepresentation(const char *Path)
+ : exists(false)
+ , isRoot(true)
+ , mode(0)
+ , size(0)
+ , lastModified(0)
+ , name(NULL)
+ , parent(NULL)
+{
+ struct stat st;
+
+ if (!stat(Path, &st)) {
+ name = strdup(Path);
+ exists = true;
+ mode = st.st_mode;
+ size = st.st_size;
+ lastModified = st.st_mtime;
+ }
+}
+
+cFileRepresentation::cFileRepresentation(const cFileRepresentation *Parent, const char *Path)
+ : exists(false)
+ , isRoot(false)
+ , mode(0)
+ , size(0)
+ , lastModified(0)
+ , name(NULL)
+ , parent(Parent)
+{
+ name = strdup(Path);
+ cStringBuilder *sb = internalPath();
+ char *tmp = sb->toString();
+ struct stat st;
+
+ std::cout << "real path is: " << tmp << std::endl;
+ if (!stat(tmp, &st)) {
+ exists = true;
+ mode = st.st_mode;
+ size = st.st_size;
+ lastModified = st.st_mtime;
+ }
+ free(tmp);
+ delete sb;
+ std::cout << "should create file representation for " << Path << std::endl;
+}
+
+cFileRepresentation::~cFileRepresentation()
+{
+ free(name);
+}
+
+cStringBuilder *cFileRepresentation::internalPath(void) const
+{
+ cStringBuilder *sb = new cStringBuilder();
+ const cFileRepresentation *f = this;
+ std::stack<const cFileRepresentation *> rev;
+ char *chk;
+
+ while (!f->isRoot) {
+ rev.push(f);
+ f = f->parent;
+ }
+
+ for (;;) {
+ sb->Append(f->name);
+ if (rev.empty()) break;
+ chk = f->name + strlen(f->name) - 1;
+ if (*chk != cFileSystem::PathSeparator) sb->Append(cFileSystem::PathSeparator);
+ f = rev.top();
+ rev.pop();
+ }
+
+ return sb;
+}
+
diff --git a/libs/fsScan/src/FileSystem.cc b/libs/fsScan/src/FileSystem.cc
new file mode 100644
index 0000000..9d467c6
--- /dev/null
+++ b/libs/fsScan/src/FileSystem.cc
@@ -0,0 +1,132 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: FileSystem.cc
+ * Created: 21. Juli 2012, 12:44
+ * 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)
+{
+ 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 = parentRep->internalPath();
+ 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["/"] = tmp;
+ break;
+ }
+ }
+ std::cout << "check path " << scratch << std::endl;
+ 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/fsScan/src/FilesystemScanner.cc b/libs/fsScan/src/FilesystemScanner.cc
index 29fabba..2315ee1 100644
--- a/libs/fsScan/src/FilesystemScanner.cc
+++ b/libs/fsScan/src/FilesystemScanner.cc
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: FilesystemScanner.cc
- * Created: 2. Juli 2012, 13:58
+ * Created: 2. Juli 2012, 13
* 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 <FilesystemScanner.h>
diff --git a/libs/fsScan/src/LegacyVdrRecording.cc b/libs/fsScan/src/LegacyVdrRecording.cc
index ea2ed35..29bebe7 100644
--- a/libs/fsScan/src/LegacyVdrRecording.cc
+++ b/libs/fsScan/src/LegacyVdrRecording.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: LegacyVdrRecording.cc
- * Created: 3. Juli 2012, 08:16
+ * Created: 3. Juli 2012, 08
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/MediaFactory.cc b/libs/fsScan/src/MediaFactory.cc
index a94fbb1..dfb0142 100644
--- a/libs/fsScan/src/MediaFactory.cc
+++ b/libs/fsScan/src/MediaFactory.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: MediaFactory.cc
- * Created: 2. Juli 2012, 15:43
+ * Created: 2. Juli 2012, 15
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/Movie.cc b/libs/fsScan/src/Movie.cc
index a558f81..878beb0 100644
--- a/libs/fsScan/src/Movie.cc
+++ b/libs/fsScan/src/Movie.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: Movie.cc
- * Created: 2. Juli 2012, 15:12
+ * Created: 2. Juli 2012, 15
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/Picture.cc b/libs/fsScan/src/Picture.cc
index 3c44ce6..f1e509c 100644
--- a/libs/fsScan/src/Picture.cc
+++ b/libs/fsScan/src/Picture.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: Picture.cc
- * Created: 2. Juli 2012, 15:18
+ * Created: 2. Juli 2012, 15
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*
diff --git a/libs/fsScan/src/VdrRecording.cc b/libs/fsScan/src/VdrRecording.cc
index f706477..cf192ba 100644
--- a/libs/fsScan/src/VdrRecording.cc
+++ b/libs/fsScan/src/VdrRecording.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: VdrRecording.cc
- * Created: 3. Juli 2012, 08:30
+ * Created: 3. Juli 2012, 08
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libfsScan: mediatypes and filesystem scanning
*