]> gitweb.hamatoma.de Git - reqt/commitdiff
ReCharSet, ReCryptFileSystem
authorhama <hama@siduction.net>
Sun, 25 Oct 2015 22:05:36 +0000 (23:05 +0100)
committerhama <hama@siduction.net>
Sun, 25 Oct 2015 22:05:36 +0000 (23:05 +0100)
* new ReCharSet
* implementation of ReCryptFileSystem

13 files changed:
.cproject
base/ReMatcher.cpp
base/ReMatcher.hpp
base/ReStringUtils.cpp
base/ReStringUtils.hpp
cunit/allTests.cpp
cunit/cuReCryptFileSystem.cpp [new file with mode: 0644]
cunit/cuReFileSystem.cpp
cunit/cunit.pro
os/ReCryptFileSystem.cpp
os/ReCryptFileSystem.hpp
os/ReFileSystem.cpp
os/ReFileSystem.hpp

index 427ca30fa725901c6f752a87c8f7b5b80aa9f0ce..bed0e561c4fe8f1b8e032bc8834fc6ad406f7bac 100644 (file)
--- a/.cproject
+++ b/.cproject
@@ -1,54 +1,45 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
        <storageModule moduleId="org.eclipse.cdt.core.settings">
-               <cconfiguration id="0.800691153">
-                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.800691153" moduleId="org.eclipse.cdt.core.settings" name="Default">
+               <cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1502790854">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1502790854" moduleId="org.eclipse.cdt.core.settings" name="Default">
                                <externalSettings/>
                                <extensions>
-                                       <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
                                </extensions>
                        </storageModule>
                        <storageModule moduleId="cdtBuildSystem" version="4.0.0">
-                               <configuration buildProperties="" description="" id="0.800691153" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
-                                       <folderInfo id="0.800691153." name="/" resourcePath="">
-                                               <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.295364492" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
-                                                       <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.295364492.978176953" name=""/>
-                                                       <builder id="org.eclipse.cdt.build.core.settings.default.builder.1827277458" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
-                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.libs.247202732" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
-                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.1313807664" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
-                                                               <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1190613361" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
-                                                       </tool>
-                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.814499006" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
-                                                               <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1978993617" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
-                                                       </tool>
-                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.1957234262" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
-                                                               <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.151373444" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
-                                                       </tool>
+                               <configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.base.1502790854" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+                                       <folderInfo id="cdt.managedbuild.toolchain.gnu.base.1502790854.1490597040" name="/" resourcePath="">
+                                               <toolChain id="cdt.managedbuild.toolchain.gnu.base.1847887429" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
+                                                       <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.766304052" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
+                                                       <builder id="cdt.managedbuild.target.gnu.builder.base.1548452526" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.archiver.base.1423237140" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.637115277" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1722302407" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1123712484" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1202319664" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.assembler.base.1781648326" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"/>
                                                </toolChain>
                                        </folderInfo>
-                                       <sourceEntries>
-                                               <entry excluding="rqfilesearch|appl" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
-                                               <entry excluding="rqfilesearch" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="appl"/>
-                                       </sourceEntries>
                                </configuration>
                        </storageModule>
                        <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
                </cconfiguration>
        </storageModule>
-       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
-               <project id="rplqt.null.1220808761" name="rplqt"/>
-       </storageModule>
        <storageModule moduleId="scannerConfiguration">
                <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
                <scannerConfigBuildInfo instanceId="0.800691153">
                        <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
                </scannerConfigBuildInfo>
        </storageModule>
+       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+               <project id="reqt.null.1795700801" name="reqt"/>
+       </storageModule>
        <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
-       <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
 </cproject>
index cae8662f75b21023eba6fa8a7c14fef99c88c3f9..7d468125f7abb15fb5f9252ecf898f7ed9f871c9 100644 (file)
@@ -22,7 +22,7 @@
 
 QStringList* ReListMatcher::m_allMatchingList = NULL;
 ReListMatcher* ReListMatcher::m_allMatcher = NULL;
-
+ReIncludeExcludeMatcher* ReIncludeExcludeMatcher::m_allMatcher = NULL;
 /**
  * Constructor.
  *
@@ -35,12 +35,12 @@ ReListMatcher* ReListMatcher::m_allMatcher = NULL;
  */
 
 ReMatcher::ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensivity,
-    bool anchored) :
-           m_pattern(),
-           m_needles(),
-           m_restLengths(),
-           m_anchored(anchored),
-           m_caseSensivitiy(caseSensivity) {
+       bool anchored) :
+               m_pattern(),
+               m_needles(),
+               m_restLengths(),
+               m_anchored(anchored),
+               m_caseSensivitiy(caseSensivity) {
        setPattern(pattern, anchored);
 }
 
@@ -55,10 +55,10 @@ bool ReMatcher::matches(const QString& text) {
        int endIx = m_needles.size() - 1;
        if (!found && m_anchored) {
                found = m_needles.at(0).size() == 0
-                   || text.startsWith(m_needles.at(0), m_caseSensivitiy);
+                       || text.startsWith(m_needles.at(0), m_caseSensivitiy);
                if (found && (endIx > 0 || text.length() != m_pattern.length())) {
                        found = m_needles.at(endIx).size() == 0
-                           || text.endsWith(m_needles.at(endIx), m_caseSensivitiy);
+                               || text.endsWith(m_needles.at(endIx), m_caseSensivitiy);
                }
        }
        if (!found || (m_anchored && endIx > 1)) {
@@ -75,7 +75,7 @@ bool ReMatcher::matches(const QString& text) {
                        found = text.size() - textIndex >= m_restLengths.at(ix);
                        if (found)
                                found = (textIndex = text.indexOf(m_needles.at(ix), textIndex,
-                                   m_caseSensivitiy)) >= 0;
+                                       m_caseSensivitiy)) >= 0;
                }
        }
        return found;
@@ -159,11 +159,11 @@ void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy) {
  *                                                     the string
  */
 ReListMatcher::ReListMatcher(const QStringList& patterns,
-    Qt::CaseSensitivity caseSensivity, bool anchored) :
-           m_patterns(patterns),
-           m_list(),
-           m_empty(false),
-           m_allMatching(false) {
+       Qt::CaseSensitivity caseSensivity, bool anchored) :
+               m_patterns(patterns),
+               m_list(),
+               m_empty(false),
+               m_allMatching(false) {
        setPatterns(patterns, caseSensivity, anchored);
 }
 /**
@@ -267,7 +267,7 @@ bool ReListMatcher::matches(const QString& text) {
  * @param caseSensivitiy       <code>true</code>: the character case is relevant
  */
 void ReListMatcher::setCaseSensivitiy(
-    const Qt::CaseSensitivity& caseSensivitiy) {
+       const Qt::CaseSensitivity& caseSensivitiy) {
        QList<ReMatcher*>::const_iterator it;
        for (it = m_list.begin(); it != m_list.end(); ++it) {
                (*it)->setCaseSensivitiy(caseSensivitiy);
@@ -282,7 +282,7 @@ void ReListMatcher::setCaseSensivitiy(
  *                                     <code>false<code>: the pattern can match anywhere
  */
 void ReListMatcher::setPatterns(const QStringList& patterns,
-    Qt::CaseSensitivity caseSensivity, bool anchored) {
+       Qt::CaseSensitivity caseSensivity, bool anchored) {
        destroy();
        m_patterns = patterns;
        m_empty = true;
@@ -309,10 +309,26 @@ void ReListMatcher::setPatterns(const QStringList& patterns,
  *                                                     the string
  */
 ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QStringList& includes,
-    const QStringList& excludes, Qt::CaseSensitivity caseSensivity,
-    bool anchored) :
-           m_includes(includes, caseSensivity, anchored),
-           m_excludes(excludes, caseSensivity, anchored) {
+       const QStringList& excludes, Qt::CaseSensitivity caseSensivity,
+       bool anchored) :
+               m_includes(includes, caseSensivity, anchored),
+               m_excludes(excludes, caseSensivity, anchored) {
+}
+
+/**
+ * Returns the singleton instance of a matcher matching all strings.
+ *
+ * @return a matcher matching all strings
+ */
+const ReIncludeExcludeMatcher& ReIncludeExcludeMatcher::allMatcher()
+{
+       if (m_allMatcher == NULL){
+               QStringList includes;
+               includes.append("*");
+               QStringList excludes;
+               m_allMatcher = new ReIncludeExcludeMatcher(includes, excludes);
+       }
+       return *m_allMatcher;
 }
 
 /**
@@ -362,7 +378,7 @@ bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo) {
  * @param caseSensivitiy       <code>true</code>: the character case is relevant
  */
 void ReIncludeExcludeMatcher::setCaseSensivitiy(
-    const Qt::CaseSensitivity& caseSensivitiy) {
+       const Qt::CaseSensitivity& caseSensivitiy) {
        m_includes.setCaseSensivitiy(caseSensivitiy);
        m_excludes.setCaseSensivitiy(caseSensivitiy);
 }
index e89c8884e89a5fe0b1f34824ceb112f3edea3e1e..c26e87fa089b61fb0368ec794a09551dbeabc715 100644 (file)
@@ -20,7 +20,7 @@
 class ReMatcher {
 public:
        ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensitivty =
-           Qt::CaseSensitive, bool anchored = false);
+               Qt::CaseSensitive, bool anchored = false);
 public:
        bool allMatching() const;
        Qt::CaseSensitivity caseSensivitiy() const;
@@ -45,8 +45,8 @@ protected:
 class ReListMatcher {
 public:
        ReListMatcher(const QStringList& patterns,
-           Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored =
-               false);
+               Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored =
+                       false);
        ~ReListMatcher();
 public:
        bool allMatching() const;
@@ -56,8 +56,8 @@ public:
        const QStringList& patterns() const;
        void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy);
        void setPatterns(const QStringList& patterns,
-           Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored =
-               false);
+               Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored =
+                       false);
 public:
        static const ReListMatcher& allMatcher();
        static const QStringList& allMatchingList();
@@ -80,15 +80,18 @@ protected:
 class ReIncludeExcludeMatcher {
 public:
        ReIncludeExcludeMatcher(const QStringList& includes,
-           const QStringList& excludes, Qt::CaseSensitivity caseSensitivty =
-               Qt::CaseSensitive, bool anchored = false);
+               const QStringList& excludes, Qt::CaseSensitivity caseSensitivty =
+                       Qt::CaseSensitive, bool anchored = false);
 public:
        Qt::CaseSensitivity caseSensivitiy() const;
        bool matches(const QString& text, bool excludeToo = true);
        const ReListMatcher& includes() const;
        const ReListMatcher& excludes() const;
        void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy);
-
+public:
+       static const ReIncludeExcludeMatcher& allMatcher();
+private:
+       static ReIncludeExcludeMatcher* m_allMatcher;
 protected:
        ReListMatcher m_includes;
        ReListMatcher m_excludes;
index 03e57e7ec25f4713a72144f345a1d08970322e49..d01b4c1ef8f7e52332ac9f2356fcd897842e95c3 100644 (file)
@@ -540,3 +540,114 @@ int ReStringUtils::lengthOfReal(const char* text, qreal* pValue) {
        return found ? length : 0;
 }
 
+/**
+ * Constructor.
+ *
+ * @param charOf       a string containing all member characters of the char set.
+ * @param indexOf      an array containing the index of the char at the position
+ *                                     of the char, starting with the minimum character
+ * @param count                -1: strlen(charOf) is taken<br>
+ *
+ *                                     otherwise: the length of charOf[]
+ */
+ReCharSet::ReCharSet(const char* charOf, int* indexOf,
+       char minChar, char maxChar, int count) :
+       m_count(count < 0 ? strlen(charOf) : count),
+       m_minChar(minChar),
+       m_maxChar(maxChar),
+       m_charOf(charOf),
+       m_indexOf(indexOf),
+       m_ownsCharOf(false)
+{
+       if (minChar == 0 && maxChar == 0)
+               getMinMax(m_charOf, m_minChar, m_maxChar);
+       if (indexOf == NULL){
+               int length = m_maxChar - m_minChar + 1;
+               m_indexOf = new int[length];
+               m_ownsCharOf = true;
+               fillIndexOf(m_charOf, m_minChar, m_maxChar, m_indexOf,
+                                       length * sizeof *m_indexOf);
+       }
+}
+
+/**
+ * Writes the definition of indexOf into a string.
+ *
+ * @return the indexOf array as C text
+ */
+QByteArray ReCharSet::dumpIndexOf(){
+       QByteArray rc;
+       int length = m_maxChar - m_minChar + 1;
+       rc.reserve(100 + length * 10);
+       rc.append("// minChar = ").append(QByteArray::number(m_minChar)).append('\n');
+       rc.append("// maxChar = ").append(QByteArray::number(m_maxChar)).append('\n');
+       rc.append("int* indexOf[] = {\n");
+       for (int ix = 0; ix < length; ix++){
+               rc.append(QString::number(m_indexOf[ix])).append(',');
+               if (m_indexOf[ix] >= 0)
+                       rc.append("\t// '").append(m_charOf[m_indexOf[ix]]).append('\'');
+               rc.append('\n');
+       }
+       rc.append("};\n");
+       return rc;
+}
+
+/**
+ * Finds the minimum and the maximum char of an ascii string.
+ *
+ * The minimum of "badc" is 'a', the maximum is 'd'.
+ *
+ * @param charSet      a string with the characters to inspect
+ * @param minChar      OUT: the minimum character
+ * @param maxChar      OUT: the maximum character
+ */
+void ReCharSet::getMinMax(const char* charSet, char& minChar, char& maxChar)
+{
+       minChar = maxChar = charSet[0];
+       while(*charSet != '\0'){
+               if (*charSet < minChar)
+                       minChar = *charSet;
+               else if (*charSet > maxChar)
+                       maxChar = *charSet;
+               ++charSet;
+       }
+}
+
+/**
+ * Calculates the indexOf table from the character set.
+ *
+ * Invalid character positions will be set to -1.
+ * For all valid characters of the set is:
+ * <code>assert(indexOf[charset[ix] - minChar] == ix
+ * && charSet[indexOf[cc - minChar] == cc)</code>
+ *
+ * @param charSet              the character set
+ * @param minChar              the character of the set with the minimal value:
+ *                                             If 0 and maxChar == 0: the values will be calculated
+ * @param maxChar              the character of the set with the maximal value
+ * @param indexOf              OUT: the table to fill
+ * @param sizeIndexOf  the size of <code>indexOf</code>
+ * @return                             <code>true</code>: success<br>
+ *                                             <code>false</code>: minChar or maxChar invalid or wrong size
+ */
+bool ReCharSet::fillIndexOf(const char* charSet, char minChar, char maxChar,
+                                                       int* indexOf, size_t sizeIndexOf)
+{
+       bool rc = true;
+       int length = maxChar - minChar + 1;
+       if (length != sizeIndexOf / sizeof*indexOf)
+               rc = false;
+       else {
+               int ix = 0;
+               memset(indexOf, -1, sizeIndexOf);
+               while(*charSet != '\0'){
+                       char cc = *charSet++;
+                       if (cc < minChar || cc > maxChar)
+                               rc = false;
+                       else
+                               indexOf[cc - minChar] = ix;
+                       ix++;
+               }
+       }
+       return rc;
+}
index dfcf76ccf5e26e9e1d5c865c8e359e241dd195ce..26e54a783e4fd76d5c4f30f2fd101800427767d8 100644 (file)
 #ifndef RPLSTRING_HPP
 #define RPLSTRING_HPP
 
+class ReCharSet {
+public:
+       ReCharSet(const char* indexToChar, int* charToIndex,
+                         char minChar = 0, char maxChar = 0, int count = -1);
+public:
+       inline char charOf(int index){
+               return index >= 0 && index < m_count ? m_charOf[index] : 0;
+       }
+       inline char indexOf(char cc){
+               return cc < m_minChar || cc > m_maxChar ? -1 : m_indexOf[cc - m_minChar];
+       }
+       QByteArray dumpIndexOf();
+
+public:
+       static void getMinMax(const char* charSet, char& minChar, char& maxChar);
+       static bool fillIndexOf(const char* charSet, char minChar, char maxChar,
+               int* indexOf, size_t sizeIndexOf);
+protected:
+       int m_count;
+       char m_minChar;
+       char m_maxChar;
+       const char* m_charOf;
+       int* m_indexOf;
+       bool m_ownsCharOf;
+};
+
 class ReStringUtils {
 public:
        static int countChar(const char* line, char cc);
index dfef20a90e9f75b47f5b8464253799d186de4087..dbfea147fd37b5c80bc64b3a6b604afc402c6221 100644 (file)
@@ -88,7 +88,9 @@ static void testNet() {
 }
 static void testOs() {
        void testReFileSystem();
+       void testReCryptFileSystem();
 
+       testReCryptFileSystem();
        testReFileSystem();
 }
 void allTests() {
diff --git a/cunit/cuReCryptFileSystem.cpp b/cunit/cuReCryptFileSystem.cpp
new file mode 100644 (file)
index 0000000..f163648
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * cuReCryptFileSystem.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+#include "base/rebase.hpp"
+#include "os/reos.hpp"
+
+/** @file
+ * @brief Unit test of the basic exceptions.
+ */
+
+class MyReCryptFileSystem : private ReCryptFileSystem, private ReTest {
+public:
+       MyReCryptFileSystem(ReLocalFileSystem& hostFs, ReRandomizer& random,
+                                               ReLogger* logger) :
+               ReCryptFileSystem(hostFs, random, logger),
+               ReTest("MyReCryptFileSystem")
+       {
+       }
+public:
+       virtual void run(void){
+               log("run");
+       }
+
+       void testRead(){
+               readMetaFile();
+               ReFileMetaDataList list;
+               checkEqu(3, listInfos(ReIncludeExcludeMatcher::allMatcher(), list));
+               ReFileMetaData entry = list.at(0);
+               checkEqu("Homunculus.txt", entry.m_node);
+               entry = list.at(1);
+               checkEqu("NewYork.png", entry.m_node);
+               entry = list.at(2);
+               checkEqu("tiger.in.india.mov", entry.m_node);
+       }
+       void testWrite(){
+               addFile("Homunculus.txt");
+               addFile("NewYork.png");
+               addFile("tiger.in.india.mov");
+               writeMetaFile();
+       }
+
+};
+
+class TestReCryptFileSystem: public ReTest {
+public:
+       TestReCryptFileSystem() :
+                       ReTest("ReCryptFileSystem"),
+                       m_sourceBase(),
+                       m_hostBase(),
+                       m_sourceFs(NULL),
+                       m_hostFs(NULL),
+                       m_cryptFs(NULL)
+       {
+               doIt();
+       }
+       ~TestReCryptFileSystem(){
+               destroy();
+       }
+
+private:
+       QByteArray m_sourceBase;
+       QByteArray m_hostBase;
+       ReLocalFileSystem* m_sourceFs;
+       ReLocalFileSystem* m_hostFs;
+       ReCryptFileSystem* m_cryptFs;
+       ReKISSRandomizer m_contentRandom;
+protected:
+       void init() {
+               m_hostBase = ReFileUtils::tempDir("cryptfs");
+               m_sourceBase = ReFileUtils::tempDir("sourcefs");
+               m_hostFs = new ReLocalFileSystem(m_hostBase, &m_logger);
+               m_cryptFs = new ReCryptFileSystem(*m_hostFs, m_contentRandom, &m_logger);
+       }
+       void destroy(){
+               delete m_sourceFs;
+               delete m_hostFs;
+               delete m_cryptFs;
+               m_sourceFs = NULL;
+               m_hostFs = NULL;
+               m_cryptFs = NULL;
+       }
+       void testWriteRead(){
+               MyReCryptFileSystem cryptFs1(*m_hostFs, m_contentRandom, &m_logger);
+               cryptFs1.testWrite();
+
+               MyReCryptFileSystem cryptFs2(*m_hostFs, m_contentRandom, &m_logger);
+               cryptFs2.testRead();
+
+
+       }
+
+       virtual void run() {
+               init();
+               testWriteRead();
+       }
+};
+void testReCryptFileSystem() {
+       TestReCryptFileSystem test;
+}
+
index 4945b1beb9e56cca2176b1c715804adc9d1e2da2..d1b6d0911f299c4182777fe6507b1109c7297b46 100644 (file)
@@ -152,8 +152,40 @@ protected:
                struct stat info;
                checkEqu(0, stat(path.toUtf8().constData(), &info));
        }
+       void testReOSPermissions(){
+               ReOSPermissions p1;
+               int owner, group;
+#if defined __linux__
+               owner = getuid();
+               group = getgid();
+#else
+               owner = -1;
+               group = -1;
+#endif
+               checkEqu(owner, p1.m_user);
+               checkEqu(group, p1.m_group);
+               checkEqu( S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH, p1.m_fileMode);
+               checkEqu(S_IWUSR | S_IRUSR | S_IXUSR | S_IWGRP | S_IRGRP
+                                | S_IXGRP | S_IROTH | S_IXOTH | __S_IFDIR, p1.m_dirMode);
+               ReOSPermissions p2(p1);
+               checkEqu(owner, p2.m_user);
+               checkEqu(group, p2.m_group);
+               checkEqu( S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH, p2.m_fileMode);
+               checkEqu(S_IWUSR | S_IRUSR | S_IXUSR | S_IWGRP | S_IRGRP
+                                | S_IXGRP | S_IROTH | S_IXOTH | __S_IFDIR, p2.m_dirMode);
+               p2.m_user = 0x4711;
+               p2.m_group = 0x1147;
+               p2.m_dirMode = 123;
+               p2.m_fileMode = 7766;
+               p1 = p2;
+               checkEqu(0x4711, p2.m_user);
+               checkEqu(0x1147, p2.m_group);
+               checkEqu(123, p2.m_dirMode);
+               checkEqu(7766, p2.m_fileMode);
+       }
 
        virtual void run() {
+               testReOSPermissions();
                init();
                testReListInfos();
                testSetProperties();
index 8f8bf06470fba160712ab98f6ca586b51432f010..85044ea759c991e977d8595dd73a5298d6712921 100644 (file)
@@ -16,6 +16,8 @@ TEMPLATE = app
 INCLUDEPATH = ..
 
 SOURCES += main.cpp \
+        cuReFileSystem.cpp \
+        cuReCryptFileSystem.cpp \
         cuReRandomizer.cpp \
         cuReQStringUtils.cpp \
         cuReStringUtils.cpp \
@@ -42,7 +44,7 @@ SOURCES += main.cpp \
         ../gui/ReSettings.cpp \
        ../gui/ReEdit.cpp \
        ../os/ReFileSystem.cpp \
-        cuReFileSystem.cpp \
+       ../os/ReCryptFileSystem.cpp \
         cuReConfig.cpp \
         cuReContainer.cpp \
         cuReWriter.cpp \
@@ -51,13 +53,13 @@ SOURCES += main.cpp \
        cuReStateStorage.cpp \
        cuReSettings.cpp \
        cuReMatcher.cpp \
-        allTests.cpp \
-    ../os/ReCryptFileSystem.cpp
+        allTests.cpp
 
 HEADERS += \
         ../base/ReFile.hpp \
         ../base/rebase.hpp \
        ../gui/ReEdit.hpp \
        ../math/ReMatrix.hpp \
-       ../math/remath.hpp \
-    ../os/ReCryptFileSystem.hpp
+       ../os/reos.hpp \
+       ../math/remath.hpp
+
index 1af6608bb0b067ed86b84beb65c43acf1dec9e87..b24a8eb1c30db05108236ab6b67da175bec06198 100644 (file)
@@ -149,6 +149,20 @@ ReFileSystem::ErrorCode ReCryptFileSystem::write(const QString& target,
        return EC_SUCCESS;
 }
 
+/**
+ * Adds a file to the current directory.
+ *
+ * @param node filename without path
+ */
+void ReCryptFileSystem::addFile(const QString& node)
+{
+       QDateTime now = QDateTime::currentDateTime();
+       ReFileMetaData entry(node, now, now, m_osPermissions.m_user,
+                                                m_osPermissions.m_group, m_osPermissions.m_fileMode,
+                                                0, ++m_maxFileId);
+       m_list.append(entry);
+}
+
 /**
  * Constructor
  *
@@ -165,7 +179,8 @@ ReCryptDirectory::ReCryptDirectory(ReRandomizer& contentRandom,
        m_currentNode(),
        m_fileBuffer(),
        m_entryBuffer(),
-       m_blockSize(1024 * 1024)
+       m_blockSize(1024 * 1024),
+       m_maxFileId(0)
 {
        m_fileBuffer.reserve(m_blockSize);
        m_entryBuffer.reserve(m_blockSize + MAX_ENTRY_SIZE + 10);
@@ -294,6 +309,7 @@ bool ReCryptDirectory::readMetaFile()
        m_list.clear();
        QString fnMetaFile = m_parent->directory() + ReCryptFileSystem::NODE_META_DIR;
        FILE* fp = fopen(fnMetaFile.toUtf8().constData(), "rb");
+       m_maxFileId = 0;
        if (fp != NULL){
                QByteArray header;
                header.resize(META_DIR_HEADER_LENGTH);
@@ -432,6 +448,8 @@ void ReCryptDirectory::splitBlock(bool isLast, QByteArray& block){
                file.m_size = src->m_size;
                file.m_mode = src->m_mode;
                file.m_id = src->m_id;
+               if (file.m_id > m_maxFileId)
+                       m_maxFileId = file.m_id;
                srcPtr += sizeof(FileEntry_t);
                int nodeLength = src->m_nodeLength != 0 ? src->m_nodeLength : strlen(srcPtr);
                QByteArray node(srcPtr, nodeLength);
@@ -454,3 +472,4 @@ const QString& ReCryptDirectory::hostedFilename(const ReFileMetaData& entry)
        m_currentNode = ReFileUtils::pathAppend(m_parent->directory(), node);
        return m_currentNode;
 }
+
index 9d4c1390fd0159c569c4adbb25cdade7be0c2233..15181dba397f85bbccbb043b1d755f0f2f2ebb07 100644 (file)
@@ -60,6 +60,7 @@ protected:
        QByteArray m_fileBuffer;
        QByteArray m_entryBuffer;
        int m_blockSize;
+       int m_maxFileId;
 };
 
 /**
@@ -104,7 +105,7 @@ public:
        ReFileSystem& host() const {
                return m_host;
        }
-
+       void addFile(const QString& node);
 protected:
        ReFileSystem& m_host;
 };
index 516ebfd159ff47640660d879644b1fc8220879e3..9edc0b28d300bf26f88106b070521ba72e931b39 100644 (file)
@@ -106,6 +106,16 @@ bool ReFileSystem::writeable() const {
        return m_writeable;
 }
 
+ReOSPermissions ReFileSystem::osPermissions() const
+{
+       return m_osPermissions;
+}
+
+void ReFileSystem::setOsPermissions(const ReOSPermissions& osPermissions)
+{
+       m_osPermissions = osPermissions;
+}
+
 /**
  * Sets the filesystem to writeable or readonly.
  *
@@ -596,3 +606,45 @@ ReFileMetaData&ReFileMetaData::operator =(const ReFileMetaData& source) {
        return *this;
 }
 
+/**
+ * Constructor.
+ */
+ReOSPermissions::ReOSPermissions() :
+       m_user(-1),
+       m_group(-1),
+       m_fileMode(0),
+       m_dirMode(0){
+#if defined __linux__
+       m_user = getuid();
+       m_group = getgid();
+       m_fileMode =  S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH;
+       m_dirMode =  S_IWUSR | S_IRUSR | S_IXUSR | S_IWGRP | S_IRGRP
+                       | S_IXGRP | S_IROTH | S_IXOTH | __S_IFDIR;
+#endif
+}
+
+/**
+ * Copy constructor.
+ * @param source       source to copy
+ */
+ReOSPermissions::ReOSPermissions(const ReOSPermissions& source) :
+       m_user(source.m_user),
+       m_group(source.m_group),
+       m_fileMode(source.m_fileMode),
+       m_dirMode(source.m_dirMode){
+}
+
+/**
+ * Assignment operator.
+ *
+ * @param source       source to copy
+ * @return                     the instance itself
+ */
+ReOSPermissions&ReOSPermissions::operator =(const ReOSPermissions& source)
+{
+       m_user = source.m_user;
+       m_group = source.m_group;
+       m_fileMode = source.m_fileMode;
+       m_dirMode = source.m_dirMode;
+}
+
index f664234b7abe3d63c356d70e579a5e64fe3a1459..5aad9783da96ad5616bf28fb7cb4ba080959d06b 100644 (file)
 #ifndef OS_REFILESYSTEM_HPP_
 #define OS_REFILESYSTEM_HPP_
 
+class ReOSPermissions {
+public:
+       ReOSPermissions();
+       ReOSPermissions(const ReOSPermissions& source);
+       ReOSPermissions& operator =(const ReOSPermissions& source);
+public:
+       int m_user;
+       int m_group;
+       mode_t m_fileMode;
+       mode_t m_dirMode;
+};
+
 class ReFileMetaData {
 public:
        ReFileMetaData();
@@ -140,10 +152,13 @@ public:
        QByteArray fullNameAsUTF8(const QString& node) const {
                return (m_directory + node).toUtf8();
        }
-       void setWriteable(bool writeable);
+       ReOSPermissions osPermissions() const;
        void setBlocksize(int blocksize);
+       void setOsPermissions(const ReOSPermissions& osPermissions);
+       void setWriteable(bool writeable);
        bool writeable() const;
 
+
 protected:
        QString m_name;
 #ifdef __linux__
@@ -157,6 +172,7 @@ protected:
        QByteArray m_buffer;
        int m_blocksize;
        QDateTime m_undefinedTime;
+       ReOSPermissions m_osPermissions;
 };
 
 class ReLocalFileSystem: public ReFileSystem {