summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-29 14:00:29 (GMT)
committergeronimo <geronimo013@gmx.de>2012-07-29 14:00:29 (GMT)
commitaa714b0076c06d7133c625ab22c86114d4f17e23 (patch)
treef4773543d7c0bf593c20b1a033dea8dc28dd8ad5
parent4039d18078da508ba8c628df8e2aa741cf91f266 (diff)
downloadcmp-aa714b0076c06d7133c625ab22c86114d4f17e23.tar.gz
cmp-aa714b0076c06d7133c625ab22c86114d4f17e23.tar.bz2
cleanup
-rw-r--r--README55
-rw-r--r--cmpcj/.classpath9
-rw-r--r--cmpcj/.project17
-rw-r--r--cmps/server.cbp.save65
-rw-r--r--cmps/serverlib/serverlib.layout.save24
-rw-r--r--libs/IO/.dep.inc5
-rw-r--r--libs/IO/IO.cbp.save68
-rw-r--r--libs/IO/IO.layout.save34
-rw-r--r--libs/IO/include/ConfigReader.h48
-rw-r--r--libs/IO/include/File.h67
-rw-r--r--libs/IO/include/FileReader.h44
-rw-r--r--libs/IO/include/FileRepresentation.h56
-rw-r--r--libs/IO/include/FileSystem.h52
-rw-r--r--libs/IO/include/LineReader.h48
-rw-r--r--libs/IO/src/ConfigReader.cc64
-rw-r--r--libs/IO/src/File.cc185
-rw-r--r--libs/IO/src/FileReader.cc63
-rw-r--r--libs/IO/src/FileRepresentation.cc132
-rw-r--r--libs/IO/src/FileSystem.cc141
-rw-r--r--libs/IO/src/LineReader.cc100
-rw-r--r--libs/fsScan/fsScan.layout.save34
-rw-r--r--libs/networking/networking.layout.save54
-rw-r--r--libs/util/util.layout.save54
-rw-r--r--libs/vdr/vdr.layout.save44
-rw-r--r--tests/FilesystemTest/FilesystemTest.cbp74
-rw-r--r--tests/FilesystemTest/FilesystemTest.cscope_file_list1
-rw-r--r--tests/FilesystemTest/FilesystemTest.depend1
-rw-r--r--tests/FilesystemTest/FilesystemTest.layout (renamed from cmps/server.layout.save)4
-rw-r--r--tests/FilesystemTest/src/File.cc11
-rw-r--r--tests/MetaScanTest/MetaScanTest.cbp (renamed from tests/JSonTest/JSonTest.cbp.save)25
-rw-r--r--tests/MetaScanTest/MetaScanTest.depend28
-rw-r--r--tests/MetaScanTest/MetaScanTest.layout (renamed from tests/CredentialPersistence/CredentialPersistence.layout.save)4
-rw-r--r--tests/MetaScanTest/main.cpp147
-rw-r--r--tests/StringBuilderTest/StringBuilderTest.cbp (renamed from tests/CredentialPersistence/CredentialPersistence.cbp.save)36
-rw-r--r--tests/StringBuilderTest/StringBuilderTest.depend1
-rw-r--r--tests/StringBuilderTest/StringBuilderTest.layout (renamed from tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save)4
-rw-r--r--tests/StringBuilderTest/main.cpp76
l---------tests/StringBuilderTest/srclient.conf1
38 files changed, 1445 insertions, 431 deletions
diff --git a/README b/README
index fba16ee..c496c94 100644
--- a/README
+++ b/README
@@ -23,12 +23,47 @@ So the complete (runtime) dependencies of cmps are:
libssl
libcrypto
libstdc++
+ libpcrecpp
+
+cmps supports these commandline parameters:
+-h, --help the help, you are reading
+-d, --appDir <path> the directory, where the server may write config files
+ (default is /var/lib/cmp)
+-r, --realm <path> absolute path to credential file. That file must be
+ writable to enable remote administration of principals
+ (default is no file / no authorization required)
+
+- configuration (srserver.conf)
+server configuration is put into a config file, so remote administration can
+be worked out (some day).
+Within config-files, each line that starts with '#' will be treaten as comment.
+Each config line has the format: 'name' = 'value'
+These are the supported entries:
+- media-root contains the absolute path of the directory where scanning
+ for media will start
+- favicon the absolute path to a icon that serves to identify the server
+ using standard webbrowsers
+- cmps-port the backend port, where clients can connect to
+- want-auth flag to signal, whether the server should require authorization
+- want-meta flag to enable deeper scan for media informations. If set to
+ false, only information from filesystem will be used. Enabling
+ the scan for meta information will slow down the media scan.
+- mediainfo the absolute path to mediainfo (external tool to retrieve info)
+- ffmpeg the absolute path to ffmpeg, which will be used to retrieve
+ media information too (on some media types).
+A sample server configuration file might look like:
+
+ #
+ # config for cmps - the backend of CMP
+ #
+ media-root = /media
+ favicon = /media/favicon.ico
+ cmps-port = 9000
+ want-auth = true
+ want-meta = true
+ mediainfo = /usr/bin/mediainfo
+ ffmpeg = /usr/local/bin/ffmpeg
-cmps supports three commandline parameters:
- -r <Path> the directory where to start scanning for media
- -p ### the serverport where the mediaserver can be connected to
- -i <Path> the favicon - the icon to distinguish the server, if list is
- requested by standard web-browsers.
> attribution:
cmps uses some classes from the vdr-project, a project of Klaus Schmidinger,
@@ -72,14 +107,18 @@ The C/C++ libraries
------------
basic helper classes, used by other libs
-3. libs/networking
+3. libs/IO
+-----------
+ filesystem abstraction and basic input/output
+
+4. libs/networking
------------------
classes to handle sockets and i.e. http protocol
-4. fsScan
+5. fsScan
---------
classes around filesystem scanning, and media base classes
-5. cmps/serverlib
+6. cmps/serverlib
-----------------
classes used by backend only
diff --git a/cmpcj/.classpath b/cmpcj/.classpath
new file mode 100644
index 0000000..ae6697e
--- /dev/null
+++ b/cmpcj/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="res"/>
+ <classpathentry kind="lib" path="lib/glazedlists_java15.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="lib/jackson-all-1.9.2.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/cmpcj/.project b/cmpcj/.project
new file mode 100644
index 0000000..1485529
--- /dev/null
+++ b/cmpcj/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>CMPCJ</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/cmps/server.cbp.save b/cmps/server.cbp.save
deleted file mode 100644
index f33bde6..0000000
--- a/cmps/server.cbp.save
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<CodeBlocks_project_file>
- <FileVersion major="1" minor="6" />
- <Project>
- <Option title="CMP.server" />
- <Option pch_mode="2" />
- <Option compiler="gcc" />
- <Build>
- <Target title="Debug">
- <Option output="bin/Debug/cmps" prefix_auto="1" extension_auto="1" />
- <Option object_output="obj/Debug/" />
- <Option type="1" />
- <Option compiler="gcc" />
- <Compiler>
- <Add option="-g" />
- </Compiler>
- </Target>
- <Target title="Release">
- <Option output="bin/Release/cmps" prefix_auto="1" extension_auto="1" />
- <Option object_output="obj/Release/" />
- <Option type="1" />
- <Option compiler="gcc" />
- <Compiler>
- <Add option="-O2" />
- </Compiler>
- <Linker>
- <Add option="-s" />
- </Linker>
- </Target>
- </Build>
- <Compiler>
- <Add option="-Wall" />
- <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 directory="../libs/vdr/include" />
- <Add directory="../libs/util/include" />
- <Add directory="../libs/networking/include" />
- <Add directory="../libs/IO/include" />
- <Add directory="../libs/fsScan/include" />
- <Add directory="serverlib/include" />
- <Add directory="include" />
- </Compiler>
- <Linker>
- <Add library="serverlib/libserverlib.a" />
- <Add library="../libs/fsScan/libfsScan.a" />
- <Add library="../libs/networking/libnetworking.a" />
- <Add library="../libs/IO/libIO.a" />
- <Add library="../libs/util/libutil.a" />
- <Add library="../libs/vdr/libvdr.a" />
- <Add library="pthread" />
- <Add library="ssl" />
- <Add library="crypt" />
- <Add library="rt" />
- <Add library="pcrecpp" />
- </Linker>
- <Unit filename="main.cc" />
- <Extensions>
- <code_completion />
- <envvars />
- <lib_finder disable_auto="1" />
- <debugger />
- </Extensions>
- </Project>
-</CodeBlocks_project_file>
diff --git a/cmps/serverlib/serverlib.layout.save b/cmps/serverlib/serverlib.layout.save
deleted file mode 100644
index de6ba2e..0000000
--- a/cmps/serverlib/serverlib.layout.save
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<CodeBlocks_layout_file>
- <ActiveTarget name="Debug" />
- <File name="src/HTMLListAssembler.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="src/MediaListHandler.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="src/JSonListAssembler.cc" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
- <Cursor>
- <Cursor1 position="1183" topLine="0" />
- </Cursor>
- </File>
- <File name="src/AbstractMediaRequestHandler.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>
-</CodeBlocks_layout_file>
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>
diff --git a/tests/FilesystemTest/FilesystemTest.cbp b/tests/FilesystemTest/FilesystemTest.cbp
new file mode 100644
index 0000000..43f5b5c
--- /dev/null
+++ b/tests/FilesystemTest/FilesystemTest.cbp
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="Tests.FilesystemTest" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="bin/Debug/Tests" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Debug/" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="bin/Release/Tests" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Release/" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-fexceptions -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__STDC_CONSTANT_MACROS" />
+ <Add option="-D__STDC_FORMAT_MACROS" />
+ <Add option="-D__STDC_LIMIT_MACROS" />
+ <Add directory="../../libs/vdr/include" />
+ <Add directory="../../libs/util/include" />
+ <Add directory="../../libs/networking/include" />
+ <Add directory="../../libs/IO/include" />
+ <Add directory="../../libs/fsScan/include" />
+ <Add directory="include" />
+ </Compiler>
+ <Linker>
+ <Add library="pthread" />
+ <Add library="rt" />
+ <Add library="ssl" />
+ <Add library="crypt" />
+ <Add library="../../libs/fsScan/libfsScan.a" />
+ <Add library="../../libs/networking/libnetworking.a" />
+ <Add library="../../libs/IO/libIO.a" />
+ <Add library="../../libs/util/libutil.a" />
+ <Add library="../../libs/vdr/libvdr.a" />
+ </Linker>
+ <Unit filename="main.cpp" />
+ <Extensions>
+ <code_completion />
+ <envvars />
+ <lib_finder disable_auto="1" />
+ <debugger />
+ <DoxyBlocks>
+ <comment_style block="0" line="0" />
+ <doxyfile_project />
+ <doxyfile_build />
+ <doxyfile_warnings />
+ <doxyfile_output />
+ <doxyfile_dot />
+ <general />
+ </DoxyBlocks>
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
diff --git a/tests/FilesystemTest/FilesystemTest.cscope_file_list b/tests/FilesystemTest/FilesystemTest.cscope_file_list
new file mode 100644
index 0000000..7ac8741
--- /dev/null
+++ b/tests/FilesystemTest/FilesystemTest.cscope_file_list
@@ -0,0 +1 @@
+"/d/linux/CMP/tests/FilesystemTest/main.cpp"
diff --git a/tests/FilesystemTest/FilesystemTest.depend b/tests/FilesystemTest/FilesystemTest.depend
new file mode 100644
index 0000000..c4ac310
--- /dev/null
+++ b/tests/FilesystemTest/FilesystemTest.depend
@@ -0,0 +1 @@
+# depslib dependency file v1.0
diff --git a/cmps/server.layout.save b/tests/FilesystemTest/FilesystemTest.layout
index 697bb3f..68e17b2 100644
--- a/cmps/server.layout.save
+++ b/tests/FilesystemTest/FilesystemTest.layout
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
- <File name="main.cc" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="main.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="4020" topLine="55" />
+ <Cursor1 position="133" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
diff --git a/tests/FilesystemTest/src/File.cc b/tests/FilesystemTest/src/File.cc
deleted file mode 100644
index 8f3b528..0000000
--- a/tests/FilesystemTest/src/File.cc
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "File.h"
-
-File::File(const char *Path)
-{
- //ctor
-}
-
-File::~File()
-{
- //dtor
-}
diff --git a/tests/JSonTest/JSonTest.cbp.save b/tests/MetaScanTest/MetaScanTest.cbp
index 9328615..832ce4a 100644
--- a/tests/JSonTest/JSonTest.cbp.save
+++ b/tests/MetaScanTest/MetaScanTest.cbp
@@ -2,7 +2,7 @@
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
- <Option title="Tests.JSonTest" />
+ <Option title="Tests.MetaScanTest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
@@ -30,32 +30,35 @@
</Build>
<Compiler>
<Add option="-Wall" />
- <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 -ansi" />
+ <Add option="-fexceptions -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="../../libs/fsScan/include" />
<Add directory="../../libs/networking/include" />
+ <Add directory="../../libs/IO/include" />
<Add directory="../../libs/util/include" />
<Add directory="../../libs/vdr/include" />
</Compiler>
<Linker>
<Add library="../../libs/fsScan/libfsScan.a" />
<Add library="../../libs/networking/libnetworking.a" />
+ <Add library="../../libs/IO/libIO.a" />
<Add library="../../libs/util/libutil.a" />
<Add library="../../libs/vdr/libvdr.a" />
- <Add library="jpeg" />
- <Add library="pthread" />
- <Add library="dl" />
- <Add library="cap" />
<Add library="rt" />
- <Add library="fribidi" />
- <Add library="freetype" />
- <Add library="fontconfig" />
- <Add library="yajl" />
+ <Add library="pthread" />
<Add library="ssl" />
<Add library="crypt" />
+ <Add library="pcrecpp" />
+ <Add directory="/usr/lib" />
</Linker>
- <Unit filename="JSonTest.cc" />
+ <Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
diff --git a/tests/MetaScanTest/MetaScanTest.depend b/tests/MetaScanTest/MetaScanTest.depend
new file mode 100644
index 0000000..aa86b49
--- /dev/null
+++ b/tests/MetaScanTest/MetaScanTest.depend
@@ -0,0 +1,28 @@
+# depslib dependency file v1.0
+1343547065 source:/d/linux/CMP/tests/MetaScanTest/main.cpp
+ <File.h>
+ <FileReader.h>
+ <LineReader.h>
+ <ConfigReader.h>
+ <iostream>
+ <stdlib.h>
+ <string.h>
+ <errno.h>
+ <fcntl.h>
+ <stdio.h>
+ <unistd.h>
+ <wait.h>
+ <tr1/tuple>
+
+1343485153 /d/linux/CMP/libs/IO/include/File.h
+ <stddef.h>
+ <sys/types.h>
+
+1343485153 /d/linux/CMP/libs/IO/include/FileReader.h
+
+1343485153 /d/linux/CMP/libs/IO/include/LineReader.h
+
+1343538490 /d/linux/CMP/libs/IO/include/ConfigReader.h
+ <tuple>
+ <string>
+
diff --git a/tests/CredentialPersistence/CredentialPersistence.layout.save b/tests/MetaScanTest/MetaScanTest.layout
index f0df7b3..c9eeb3d 100644
--- a/tests/CredentialPersistence/CredentialPersistence.layout.save
+++ b/tests/MetaScanTest/MetaScanTest.layout
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
- <File name="CredentialPersistence.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="main.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="98" topLine="0" />
+ <Cursor1 position="1602" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
diff --git a/tests/MetaScanTest/main.cpp b/tests/MetaScanTest/main.cpp
new file mode 100644
index 0000000..62c1bda
--- /dev/null
+++ b/tests/MetaScanTest/main.cpp
@@ -0,0 +1,147 @@
+/*
+ * test case for scanning of meta data
+ */
+#include <File.h>
+#include <FileReader.h>
+#include <LineReader.h>
+#include <ConfigReader.h>
+#include <iostream>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <wait.h>
+#include <tr1/tuple>
+
+//static const char *mediaInfo = NULL;
+//static const char *ffmpeg = NULL;
+static void testPipe(const char *chk = NULL);
+
+#define ASSERT_IS(rv, x) if (x != rv) { fprintf(stderr, "assertation failed at %s #%d\n",__FILE__,__LINE__); exit(-1); }
+#define ASSERT_NOT(rv, x) if (x == rv) { fprintf(stderr, "assertation failed at %s #%d\n",__FILE__,__LINE__); exit(-1); }
+#define FAIL(s) fprintf(stderr, s);
+
+static void parseConfig(const char *FileName)
+{
+ cConfigReader *cr = new cConfigReader(new cLineReader(new cFileReader(new cFile(FileName))));
+ cConfigReader::ConfigEntry *ce;
+
+ while ((ce = cr->ReadValue())) {
+ std::cout << "config entry [" << std::get<0>(*ce) << "] => " << std::get<1>(*ce) << std::endl;
+ delete ce;
+ }
+ cr->Close();
+ delete cr;
+}
+
+static void testMediaFiles(const char *FileName)
+{
+ cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
+ const char *line;
+
+ while ((line = lr->ReadLine())) {
+ std::cout << "media-test-file: " << line << std::endl;
+ testPipe(line);
+ }
+ lr->Close();
+ delete lr;
+}
+
+static const short BufferSize = 100;
+enum PipeFileDescriptors {
+ READ_FD = 0,
+ WRITE_FD = 1
+};
+
+static void testPipe(const char *chk)
+{
+ int parent2Child[2];
+ int child2Parent[2];
+ pid_t pid;
+ std::string dataReadFromChild;
+ char buffer[BufferSize + 1];
+ ssize_t readResult;
+ bool run = true;
+ int status;
+
+ ASSERT_IS(0, pipe(parent2Child));
+ ASSERT_IS(0, pipe(child2Parent));
+
+ switch (pid = fork()) {
+ case -1:
+ FAIL("fork failed");
+ exit(-1);
+
+ case 0: /* child */
+ ASSERT_NOT(-1, dup2(parent2Child[READ_FD], STDIN_FILENO));
+ ASSERT_NOT(-1, dup2(child2Parent[WRITE_FD], STDOUT_FILENO));
+ ASSERT_NOT(-1, dup2(child2Parent[WRITE_FD], STDERR_FILENO));
+ ASSERT_IS(0, close(parent2Child[WRITE_FD]));
+ ASSERT_IS(0, close(child2Parent[READ_FD]));
+
+ if (chk) {
+ execlp("mediainfo", "mediainfo", chk, NULL);
+ }
+ else execlp("ls", "ls", "-al", "--color", NULL);
+ FAIL("this line should never be reached!");
+ exit(-1);
+
+ default: /* parent */
+ std::cout << "child " << pid << " process running ..." << std::endl;
+
+ ASSERT_IS(0, close(parent2Child[READ_FD]));
+ ASSERT_IS(0, close(child2Parent[WRITE_FD]));
+
+ while (run) {
+ switch (readResult = read(child2Parent[READ_FD], buffer, BufferSize)) {
+ case 0: /* end of file, or non-blocking read. */
+ std::cout << "End of File reached ..." << std::endl
+ << "Data received was ("
+ << dataReadFromChild.size() << "):" << std::endl
+ << dataReadFromChild << std::endl;
+ ASSERT_IS(pid, waitpid(pid, &status, 0));
+
+ std::cout << std::endl
+ << "child exit status is: " << WEXITSTATUS(status) << std::endl << std::endl;
+// exit(0);
+ run = false;
+ break;
+
+ case -1:
+ if ((errno == EINTR) || (errno == EAGAIN)) {
+ errno = 0;
+ }
+ else {
+ FAIL("read() failed");
+ run = false;
+ } break;
+
+ default:
+ dataReadFromChild.append(buffer, readResult);
+ break;
+ }
+ }
+ }
+}
+
+
+// mediainfo ${media} | grep "Scan type"
+// ffmpeg -i ${media}
+int main()
+{
+ parseConfig("srclient.conf");
+
+ std::cout << std::endl << "===========================================" << std::endl << std::endl;
+ parseConfig("srserver.conf");
+
+ std::cout << std::endl << "===========================================" << std::endl << std::endl;
+ testPipe();
+
+ std::cout << std::endl << "===========================================" << std::endl << std::endl;
+ testMediaFiles("testMedia.files");
+
+ cFile::Cleanup();
+ return 0;
+}
diff --git a/tests/CredentialPersistence/CredentialPersistence.cbp.save b/tests/StringBuilderTest/StringBuilderTest.cbp
index 0a5cfce..bc86f1b 100644
--- a/tests/CredentialPersistence/CredentialPersistence.cbp.save
+++ b/tests/StringBuilderTest/StringBuilderTest.cbp
@@ -2,7 +2,7 @@
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
- <Option title="Tests.CredentialPersistence" />
+ <Option title="Tests.StringBuilderTest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
@@ -30,33 +30,33 @@
</Build>
<Compiler>
<Add option="-Wall" />
- <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 -ansi" />
+ <Add option="-fexceptions -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 directory="../../cmps/serverlib/include" />
- <Add directory="../../libs/fsScan/include" />
- <Add directory="../../libs/networking/include" />
- <Add directory="../../libs/util/include" />
+ <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="../../libs/vdr/include" />
+ <Add directory="../../libs/util/include" />
+ <Add directory="../../libs/IO/include" />
+ <Add directory="../../libs/networking/include" />
+ <Add directory="../../libs/fsScan/include" />
</Compiler>
<Linker>
- <Add library="../../cmps/serverlib/libserverlib.a" />
- <Add library="../../libs/fsScan/libfsScan.a" />
- <Add library="../../libs/networking/libnetworking.a" />
- <Add library="../../libs/util/libutil.a" />
- <Add library="../../libs/vdr/libvdr.a" />
- <Add library="jpeg" />
<Add library="pthread" />
- <Add library="dl" />
- <Add library="cap" />
<Add library="rt" />
- <Add library="fribidi" />
- <Add library="freetype" />
- <Add library="yajl" />
<Add library="ssl" />
<Add library="crypt" />
+ <Add library="../../libs/fsScan/libfsScan.a" />
+ <Add library="../../libs/networking/libnetworking.a" />
+ <Add library="../../libs/IO/libIO.a" />
+ <Add library="../../libs/util/libutil.a" />
+ <Add library="../../libs/vdr/libvdr.a" />
</Linker>
- <Unit filename="CredentialPersistence.cc" />
+ <Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
diff --git a/tests/StringBuilderTest/StringBuilderTest.depend b/tests/StringBuilderTest/StringBuilderTest.depend
new file mode 100644
index 0000000..c4ac310
--- /dev/null
+++ b/tests/StringBuilderTest/StringBuilderTest.depend
@@ -0,0 +1 @@
+# depslib dependency file v1.0
diff --git a/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save b/tests/StringBuilderTest/StringBuilderTest.layout
index 130e1dc..a2754af 100644
--- a/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save
+++ b/tests/StringBuilderTest/StringBuilderTest.layout
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
- <File name="ConnectionHandlerTest.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="main.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="916" topLine="0" />
+ <Cursor1 position="1759" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
diff --git a/tests/StringBuilderTest/main.cpp b/tests/StringBuilderTest/main.cpp
new file mode 100644
index 0000000..c06034a
--- /dev/null
+++ b/tests/StringBuilderTest/main.cpp
@@ -0,0 +1,76 @@
+/*
+ * small tests for class StringBuilder
+ */
+#include <StringBuilder.h>
+#include <FileReader.h>
+#include <LineReader.h>
+#include <File.h>
+#include <string.h>
+#include <iostream>
+
+#define NEW_LINE '\n'
+
+void rangeTests()
+{ // 12345678901
+ static const char *sample = "Hello World";
+ cStringBuilder *sb;
+ int chunkSize = strlen(sample) - 4;
+ char *result;
+
+ std::cout << sample << " has length: " << strlen(sample) << std::endl;
+
+ for (int i=0; i < 6; ++i) {
+ std::cout << "check chunkSize of " << chunkSize + i << std::endl;
+ sb = new cStringBuilder(chunkSize + i);
+
+ sb->Append(sample).Append(NEW_LINE);
+ result = sb->toString();
+
+ std::cout << "assembled text looks like: " << std::endl << result;
+ free(result);
+ delete sb;
+ }
+}
+
+void basicTests()
+{
+ cStringBuilder sb(179);
+
+ sb.Append("hello World").Append(NEW_LINE);
+ sb.Append("logical default true: ").Append(true).Append(NEW_LINE);
+ sb.Append("logical default false: ").Append(false).Append(NEW_LINE);
+ sb.Append("logical true value: ").Append(true, "true", "false").Append(NEW_LINE);
+ sb.Append("logical false value: ").Append(false, "true", "false").Append(NEW_LINE);
+ sb.Append("double: ").Append(3.1456789).Append(NEW_LINE);
+ sb.Append("unsigned long: ").Append((size_t) 91237485l).Append(NEW_LINE);
+ sb.Append("long: ").Append(1234567890l).Append(NEW_LINE);
+ sb.Append("int: ").Append(512).Append(NEW_LINE);
+
+ char *result = sb.toString();
+
+ std::cout << "sizeof assembled text: " << sb.Size() << std::endl;
+ std::cout << "assembled text looks like:" << std::endl << result;
+
+ free(result);
+}
+
+void lineReaderTest()
+{
+ cLineReader lr(new cFileReader(new cFile("srclient.conf")));
+ const char *line = NULL;
+
+ while ((line = lr.ReadLine())) {
+ std::cout << "line: " << line << std::endl;
+ }
+ lr.Close();
+ cFile::Cleanup();
+}
+
+int main()
+{
+ lineReaderTest();
+ basicTests();
+ rangeTests();
+
+ return 0;
+}
diff --git a/tests/StringBuilderTest/srclient.conf b/tests/StringBuilderTest/srclient.conf
new file mode 120000
index 0000000..a159926
--- /dev/null
+++ b/tests/StringBuilderTest/srclient.conf
@@ -0,0 +1 @@
+/home/django/.cmp/srclient.conf \ No newline at end of file