]> gitweb.hamatoma.de Git - crepublib/commitdiff
ReSerializable, ReClassId, ReRemoteDir
authorhama <hama@siduction.net>
Sun, 29 Mar 2015 22:02:00 +0000 (00:02 +0200)
committerhama <hama@siduction.net>
Sun, 29 Mar 2015 22:02:00 +0000 (00:02 +0200)
15 files changed:
base/ReClassId.cpp [new file with mode: 0644]
base/ReClassId.hpp [new file with mode: 0644]
base/ReException.cpp
base/ReSerializable.cpp
base/ReSerializable.hpp
base/rebase.hpp
cunit/cuReDirTools.cpp
cunit/cuReSerializable.cpp
os/ReDirTools.cpp
os/ReDirTools.hpp
os/ReRemoteDir.cpp [new file with mode: 0644]
os/ReRemoteDir.hpp [new file with mode: 0644]
os/ReTraverser.cpp
os/ReTraverser.hpp
os/reos.hpp

diff --git a/base/ReClassId.cpp b/base/ReClassId.cpp
new file mode 100644 (file)
index 0000000..1838046
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * ReClassId.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
+#include "base/rebase.hpp"
+
+static ReByteBuffer s_unknownClassname;
+
+const char* classIdToString(ReClassId classId){
+       const char* rc = "?";
+       switch(classId){
+       case CLASSID_REMOTE_DIR:
+               rc = "ReRemoteDir";
+               break;
+       case CLASSID_DIR_ENTRY_FILTER:
+               rc = "ReRemoteDir";
+               break;
+       default:
+               s_unknownClassname.setLength(0).appendInt(classId);
+               rc = s_unknownClassname.str();
+       }
+       return rc;
+}
diff --git a/base/ReClassId.hpp b/base/ReClassId.hpp
new file mode 100644 (file)
index 0000000..feef67a
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * ReClassId.hpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef BASE_RECLASSID_HPP_
+#define BASE_RECLASSID_HPP_
+
+/**
+ * A unique identifier for each class. Used in serialization.
+ */
+enum ReClassId {
+       CLASSID_UNDEF,
+       CLASSID_REMOTE_DIR = 0x1001,    // = 4097
+       CLASSID_DIR_ENTRY_FILTER,       // 0x1002
+
+};
+/**
+ * Builds an unique identifier for serialization
+ *
+ * @param classId      an unique id for classes
+ * @param version      serialization version. Must be incremented if the format
+ *                                     of serialization has changed
+ */
+inline int buildSerialId(ReClassId classid, uint8_t version){
+       return (classid << 8) + version;
+}
+extern const char* classIdToString(ReClassId classId);
+
+
+#endif /* BASE_RECLASSID_HPP_ */
index 26ecb766f0ad0e91aadc47bfa7e80dec89434297..dc2a2166b0566e9b5bfde50c080a1aa37e0ada55 100644 (file)
@@ -23,7 +23,7 @@ ReException::ReException() :
  * @param message      The error message.
  */
 ReException::ReException(const char* message) :
-           m_message(_strdup(message)) {
+           m_message(message == NULL ? NULL : _strdup(message)) {
 }
 /** @brief Constructor.
  *
index 763eb4be5499a04e4753b53616b766673ee9dfdb..71451bb55ff1a464c901bcb9583a96139ab1c94c 100644 (file)
@@ -9,20 +9,52 @@
 
 #include "base/rebase.hpp"
 
+class ReSerialable;
+
+/**
+ * Constructor.
+ *
+ * @param message      description of the error
+ * @param instance     the object to serialize
+ */
+ReSerializationException::ReSerializationException(const char* message,
+    ReSerializable* instance) :
+           ReException(ReByteBuffer(message, -1).appendChar(' ').append(
+               instance->parentClassName()).str()) {
+}
 /**
  * Constructor.
  *
  * @param currentLength                the current length of the serialized bytes
  * @param expectedlength       the length needed for the current object
+ * @param instance                     the object to serialize
  */
 ReSerializationLengthException::ReSerializationLengthException(
-    int currentLength, int expectedlength) :
+    int currentLength, int expectedLength, ReSerializable* instance) :
            ReSerializationException(
                ReByteBuffer(i18n("pack error: length to small: ")).appendInt(
-                   currentLength).appendChar('/').appendInt(expectedlength).str()),
+                   currentLength).appendChar('/').appendInt(expectedLength).str(),
+               instance),
            m_currentLength(currentLength),
-           m_expectedLength(expectedlength) {
+           m_expectedLength(expectedLength) {
 }
+
+/**
+ * Constructor.
+ *
+ * @param currentLength                the length of the string
+ * @param maxLength                    the maximal length of the string
+ * @param instance                     the object to serialize
+ */
+ReSerializeStringLengthException::ReSerializeStringLengthException(int currentLength, int maxLength,
+               ReSerializable* instance) :
+       ReSerializationException(
+               ReByteBuffer(i18nTranslate("string length too large: ")).appendInt(
+                   currentLength).appendChar('/').appendInt(maxLength).str(), instance),
+           m_currentLength(currentLength),
+           m_maxLength(maxLength) {
+}
+
 /**
  * Constructor.
  *
@@ -31,6 +63,7 @@ ReSerializationLengthException::ReSerializationLengthException(
 ReSerializable::ReSerializable(int serialId) :
            m_serialId(serialId) {
 }
+
 /**
  * Destructor.
  */
index 6afb0f5217b2dd0ce3eee6b7ecd4d66c298f296b..6ad8e33fbbd1661293e745013c7adb3348bda2fc 100644 (file)
 #define BASE_RESERIALIZABLE_HPP_
 
 extern const char* i18nTranslate(const char* key);
+class ReSerializable;
+
 /**
  * Base class for all serialization/deserialization errors.
  */
 class ReSerializationException: public ReException {
 public:
-       /** Constructor.
-        * @param message       description of the error
-        */
-       ReSerializationException(const char* message) :
-                   ReException(message) {
-       }
+       ReSerializationException(const char* message, ReSerializable* instance);
 };
 /**
  * The length is not enough for the deserialization.
  */
 class ReSerializationLengthException: public ReSerializationException {
 public:
-       ReSerializationLengthException(int currentLength, int expectedLength);
+       ReSerializationLengthException(int currentLength, int expectedLength,
+               ReSerializable* instance);
 public:
        int m_currentLength;
        int m_expectedLength;
 };
+/**
+ * The length of a string on serialization is too large.
+ */
+class ReSerializeStringLengthException: public ReSerializationException {
+public:
+       ReSerializeStringLengthException(int currentLength, int maxLength,
+               ReSerializable* instance);
+public:
+       int m_currentLength;
+       int m_maxLength;
+};
+
 /**
  * Unexpected data found while unpacking.
  */
@@ -41,15 +51,16 @@ public:
        /** Constructor.
         * @param message       description of the error
         */
-       ReSerializeFormatException(const char* message) :
-                   ReSerializationException(message) {
+       ReSerializeFormatException(const char* message, ReSerializable* instance) :
+                   ReSerializationException(message, instance) {
        }
 };
+
 /**
  * Abstract base class for serializing.
  *
- * Serializing packs a class into a sequence of bytes.
- * Deserializing converts a sequence of bytes into the members of the instance.
+ * Serializing packs a class into a sequence of bytes.
+ * Deserializing: converts a sequence of bytes into the members of the instance.
  */
 class ReSerializable {
 public:
@@ -68,13 +79,29 @@ public:
         * @param value         the value to serialize
         */
        inline void packString255(ReByteBuffer& buffer, ReByteBuffer& value) {
+               if (value.length() > 255)
+                       throw ReSerializeStringLengthException(value.length(), 255, this);
                buffer.appendBits8(value.length()).append(value);
        }
+       /** Appends a string with a maximal length of 255 to the buffer.
+        * @param buffer        IN/OUT: the buffer with the serialized values
+        * @param value         the value to serialize
+        */
+       inline void packString255(ReByteBuffer& buffer, const char* value,
+               size_t length = -1) {
+               if (length == (size_t) -1)
+                       length = strlen(value);
+               if (length > 255)
+                       throw ReSerializeStringLengthException(length, 255, this);
+               buffer.appendBits8(length).append(value, length);
+       }
        /** Appends a string with a maximal length of 64KiByte to the buffer.
         * @param buffer        IN/OUT: the buffer with the serialized values
         * @param value         the value to serialize
         */
        inline void packString64k(ReByteBuffer& buffer, ReByteBuffer& value) {
+               if (value.length() > 0xffff)
+                       throw ReSerializeStringLengthException(value.length(), 0xffff, this);
                buffer.appendBits16(value.length()).append(value);
        }
        /** Appends a string with a maximal length of 4GiByte to the buffer.
@@ -84,6 +111,12 @@ public:
        inline void packString4t(ReByteBuffer& buffer, ReByteBuffer& value) {
                buffer.appendBits32(value.length()).append(value);
        }
+       /** Returns the name of the parent class.
+        * @return the parent's classname
+        */
+       inline const char* parentClassName() const {
+               return classIdToString(ReClassId(m_serialId >> 8));
+       }
        /** Sets the members of the instance from the byte sequence.
         *
         * @param sequence      IN: a byte sequence starting with the serialized members
@@ -103,7 +136,13 @@ public:
                uint8_t* seq = reinterpret_cast<uint8_t*>(sequence.buffer());
                deserialize(seq, length);
                if (length != 0)
-                       throw ReSerializationLengthException(length, 0);
+                       throw ReSerializationLengthException(length, 0, this);
+       }
+       /** Returns the unique serialization id of the parent class.
+        * @return the serialization id
+        */
+       inline int serialId() const {
+               return m_serialId;
        }
        /** Appends the class members to the end of the buffer.
         *
@@ -118,11 +157,11 @@ public:
         */
        inline void unpackBool(uint8_t*& sequence, size_t& length, bool& value) {
                if (length < 1)
-                       throw ReSerializationLengthException(length, 1);
+                       throw ReSerializationLengthException(length, 1, this);
                char cc = *sequence++;
                if (cc != 't' && cc != 'f')
                        throw ReSerializeFormatException(
-                           i18nTranslate("not a boolean value"));
+                           i18nTranslate("not a boolean value"), this);
                value = cc == 't';
                length--;
        }
@@ -133,7 +172,7 @@ public:
         */
        inline void unpackInt8(uint8_t*& sequence, size_t& length, int& value) {
                if (length < 1)
-                       throw ReSerializationLengthException(length, 1);
+                       throw ReSerializationLengthException(length, 1, this);
                value = *sequence++;
                length--;
        }
@@ -144,7 +183,7 @@ public:
         */
        inline void unpackInt16(uint8_t*& sequence, size_t& length, int& value) {
                if (length < 2)
-                       throw ReSerializationLengthException(length, 2);
+                       throw ReSerializationLengthException(length, 2, this);
                value = (*sequence++ << 8) + *sequence++;
                length -= 2;
        }
@@ -155,7 +194,7 @@ public:
         */
        inline void unpackInt24(uint8_t*& sequence, size_t& length, int& value) {
                if (length < 3)
-                       throw ReSerializationLengthException(length, 3);
+                       throw ReSerializationLengthException(length, 3, this);
                value = (*sequence++ << 16) + (*sequence++ << 8) + *sequence++;
                length -= 3;
        }
@@ -166,7 +205,7 @@ public:
         */
        inline void unpackInt32(uint8_t*& sequence, size_t& length, int& value) {
                if (length < 4)
-                       throw ReSerializationLengthException(length, 4);
+                       throw ReSerializationLengthException(length, 4, this);
                value = (*sequence++ << 24) + (*sequence++ << 16) + (*sequence++ << 8)
                    + *sequence++;
                length -= 4;
@@ -179,7 +218,7 @@ public:
        inline void unpackInt64(uint8_t*& sequence, size_t& length,
            int64_t& value) {
                if (length < 8)
-                       throw ReSerializationLengthException(length, 8);
+                       throw ReSerializationLengthException(length, 8, this);
                value = (int64_t(*sequence++) << 56) + (int64_t(*sequence++) << 48)
                    + (int64_t(*sequence++) << 40) + (int64_t(*sequence++) << 32)
                    + (int64_t(*sequence++) << 24) + (int64_t(*sequence++) << 16)
@@ -194,10 +233,12 @@ public:
        inline void unpackString255(uint8_t*& sequence, size_t& length,
            ReByteBuffer& value) {
                size_t strLen = 0;
-               if (length == 0 || (strLen = *sequence) > length)
-                       throw ReSerializationLengthException(length, 1 + strLen);
-               value.set(reinterpret_cast<char*>(sequence), strLen);
-               length -= strLen - 1;
+               if (length < 1 || (strLen = *sequence) > length)
+                       throw ReSerializationLengthException(length, 1 + strLen, this);
+               value.set(reinterpret_cast<char*>(sequence + 1), strLen);
+               strLen += 1;
+               sequence += strLen;
+               length -= strLen;
        }
        /** Reads a string with a max. length of 64KiByte  from the serialized byte sequence.
         * @param sequence      IN/OUT: the byte sequence with the serialized data
@@ -207,10 +248,12 @@ public:
        inline void unpackString64k(uint8_t*& sequence, size_t& length,
            ReByteBuffer& value) {
                size_t strLen = 0;
-               if (length == 0 || (strLen = (sequence[0] << 8) + sequence[1]) > length)
-                       throw ReSerializationLengthException(length, 1 + strLen);
-               value.set(reinterpret_cast<char*>(sequence), strLen);
-               length -= strLen - 2;
+               if (length < 2 || (strLen = (sequence[0] << 8) + sequence[1]) > length)
+                       throw ReSerializationLengthException(length, 2 + strLen, this);
+               value.set(reinterpret_cast<char*>(sequence + 2), strLen);
+               strLen += 2;
+               length -= strLen;
+               sequence += strLen;
        }
        /** Reads a string with a max. length of 64KiByte  from the serialized byte sequence.
         * @param sequence      IN/OUT: the byte sequence with the serialized data
@@ -220,12 +263,14 @@ public:
        inline void unpackString4t(uint8_t*& sequence, size_t& length,
            ReByteBuffer& value) {
                size_t strLen = 0;
-               if (length == 0
+               if (length < 4
                    || (strLen = (sequence[0] << 24) + (sequence[1] << 16)
                        + (sequence[2] << 8) + sequence[3]) > length)
-                       throw ReSerializationLengthException(length, 1 + strLen);
-               value.set(reinterpret_cast<char*>(sequence), strLen);
-               length -= strLen - 4;
+                       throw ReSerializationLengthException(length, 4 + strLen, this);
+               value.set(reinterpret_cast<char*>(sequence + 4), strLen);
+               strLen += 4;
+               length -= strLen;
+               sequence += strLen;
        }
 private:
        int m_serialId;
index 67d4e9e7773d14a4001292ac99908f7f1387aefc..673cb1df8a323f25e1b06581eecb22dd54c3f217 100644 (file)
@@ -118,6 +118,7 @@ inline int min(int a, int b) {
 inline int max(int a, int b) {\r
        return a < b ? a : b;\r
 }\r
+#include "base/ReClassId.hpp"\r
 #include "base/ReException.hpp"\r
 #include "base/ReMutex.hpp"\r
 #include "base/ReByteBuffer.hpp"\r
index 4f7ecd2390eb82a5de66bc40246c839962340095..6bd506f82daf0bd459d5d0c36d3bd9c01fbfefdc 100644 (file)
@@ -287,7 +287,7 @@ private:
                opts.addStandardFilterOptions();\r
                const char* argv[] = { "x", "-y1980.01.02", "-o1980.01.03", "-D5",\r
                    "-d1", "-z1k", "-Z2M", "-p;*;-*~" };\r
-               ReDirEntryFilter_t filter;\r
+               ReDirEntryFilter filter;\r
                opts.programArgsChangeable().init(sizeof argv / sizeof argv[0], argv);\r
                opts.setFilterFromProgramArgs(filter);\r
                // local time: +3600\r
index dbb53b1d946f4f3e1dd01f84750b0dddb57e1d3c..af70cb98d16303c58ca113b97b2b7edc1e65f01c 100644 (file)
@@ -36,6 +36,8 @@ public:
        virtual void deserialize(uint8_t*& sequence, size_t& length) {
                int id;
                unpackInt24(sequence, length, id);
+               if (id != m_serialId)
+                       throw ReSerializeFormatException("wrong serialId", this);
                unpackInt8(sequence, length, m_int8);
                unpackInt16(sequence, length, m_int16);
                unpackInt32(sequence, length, m_int32);
@@ -56,11 +58,11 @@ public:
        }
        const char* toString(ReByteBuffer& buffer) {
                buffer.setLength(0).append("id: ").appendInt(m_serialId);
-               buffer.append(" i8:").appendInt(m_int8);
-               buffer.append(" i16:").appendInt(m_int16);
-               buffer.append(" i32:").appendInt(m_int32);
+               buffer.append(" i8:").appendInt(m_int8, "%x");
+               buffer.append(" i16:").appendInt(m_int16, "%x");
+               buffer.append(" i32:").appendInt(m_int32, "%x");
                buffer.append(" b:").appendChar(m_bool ? 't' : 'f');
-               buffer.append(" i64:").appendInt(m_int64);
+               buffer.append(" i64:").appendInt(m_int64, "%0llx");
                buffer.append(" s255:").append(m_string255);
                buffer.append(" s64k:").append(m_string64k);
                buffer.append(" s4t:").append(m_string4t);
@@ -95,14 +97,14 @@ private:
                ReByteBuffer buffer;
                ExampleClass example(250, 64000, 12345678, true, 0x12345678abcdll,
                    "king", "lives", "!");
-               checkEqu(
-                   "id: 1192961 i8:250 i16:64000 i32:12345678 b:t i64:20015998348237 s255:king s64k:lives s4t:!",
+               checkEqu("id: 1192961 i8:fa i16:fa00 i32:bc614e b:t i64:12345678abcd s255:king s64k:lives s4t:!",
                    example.toString(buffer));
                ReByteBuffer serialBuffer;
                example.serialize(serialBuffer);
                ExampleClass example2;
-               example.deserializeBuffer(serialBuffer);
-               checkEqu("", example2.toString(buffer));
+               example2.deserializeBuffer(serialBuffer);
+               checkEqu("id: 1192961 i8:fa i16:fa00 i32:bc614e b:t i64:12345678abcd s255:king s64k:lives s4t:!",
+                   example2.toString(buffer));
        }
 };
 extern void testReSerializable(void);
index 28e4822fd83205069157a540900945349aac10c9..77828ac17f4157401c151f074a3aef2d1a1c2b7c 100644 (file)
@@ -640,7 +640,7 @@ void ReDirOptions::optimizePathPattern(ReByteBuffer& buffer) {
  *\r
  * @param filter    OUT: the filter to set\r
  */\r
-void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter_t& filter) {\r
+void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter& filter) {\r
        ReByteBuffer buffer;\r
        if (m_programArgs.getString("younger", buffer)[0] != '\0')\r
                filter.m_maxAge = checkDate(buffer.str());\r
@@ -1628,7 +1628,7 @@ void ReDirRandom::doIt() {
 const ReStringList& ReDirStatistic::calculate(const char* base, int level,\r
     void (*formatter)(const ReDirStatisticData& data, ReDirStatistic& parent,\r
         ReByteBuffer& line)) {\r
-       ReDirEntryFilter_t filter;\r
+       ReDirEntryFilter filter;\r
        ReTraverser traverser(base, this);\r
        setFilterFromProgramArgs(filter);\r
        traverser.setPropertiesFromFilter(&filter);\r
@@ -2242,7 +2242,7 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength,
  * Synchronizes two directory trees.\r
  */\r
 void ReDirSync::doIt() {\r
-       ReDirEntryFilter_t filter;\r
+       ReDirEntryFilter filter;\r
        const char* sep = OS_SEPARATOR;\r
        ReByteBuffer buffer;\r
        ReByteBuffer target(m_programArgs.arg(m_programArgs.argCount() - 1));\r
index 3623a0a07821f23d4c1f08befe0b955d317ba646..d2f7b600e97b90f90ff77648d38de6a2a9dabea8 100644 (file)
@@ -52,7 +52,7 @@ public:
        ReProgramArgs& programArgsChangeable() {
                return m_programArgs;
        }
-       void setFilterFromProgramArgs(ReDirEntryFilter_t& filter);
+       void setFilterFromProgramArgs(ReDirEntryFilter& filter);
 protected:
        void optimizePathPattern(ReByteBuffer& buffer);
 protected:
@@ -125,7 +125,7 @@ protected:
        bool m_addCurrentDirIfNoArguments;
        bool m_hasStandardArgs;
        ReTraverser m_traverser;
-       ReDirEntryFilter_t m_filter;
+       ReDirEntryFilter m_filter;
        int64_t m_start;
        struct stat m_statInfo;
        ReLogger* m_logger;
diff --git a/os/ReRemoteDir.cpp b/os/ReRemoteDir.cpp
new file mode 100644 (file)
index 0000000..0207988
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * ReRemoteDir.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
+
+#include "base/rebase.hpp"
+#include "net/renet.hpp"
+#include "os/reos.hpp"
+
+int ReRemoteDir::m_serialNo = (CLASSID_REMOTE_DIR << 8) + 1;
+
+/**
+ * Constructor.
+ */
+ReRemoteDir::ReRemoteDir() :
+       ReSerializable(m_serialNo),
+       m_parent(NULL),
+       m_indexFileInParent(-1),
+       m_namePool(),
+       m_fileCount(0),
+       m_files(NULL)
+{
+}
+
+/**
+ * Destructor.
+ */
+ReRemoteDir::~ReRemoteDir() {
+       // TODO Auto-generated destructor stub
+}
+
+/**
+ * Sets the members of the instance from a byte sequence.
+ *
+ * @param sequence     IN/OUT: the serialized byte sequence
+ * @param length       INT/OUT the length of <code>sequence</code>
+ */
+void ReRemoteDir::deserialize(uint8_t*& sequence, size_t& length){
+
+}
+/**
+ * Reads the info from a directory into the instance.
+ *
+ * @param path         the full path name of the directory to read
+ */
+void ReRemoteDir::populate(const char* path){
+       ReTraverser dir(path);
+
+}
+
+/**
+ * Packs the members into a byte sequence.
+ *
+ * @param sequence     IN/OUT: the place for the byte sequence
+ */
+ReByteBuffer& ReRemoteDir::serialize(ReByteBuffer& sequence){
+}
+
+/**
+ * Constructor.
+ */
+ReRemoteDirService::ReRemoteDirService() :
+       ReNetCommandHandler(){
+
+}
+
+ReRemoteDirService::~ReRemoteDirService(){
+}
+
+ReNetCommandHandler::ProcessingState ReRemoteDirService::handleNetCommand(ReByteBuffer& command,
+           ReByteBuffer& data, ReTCPConnection* connection){
+
+}
+
diff --git a/os/ReRemoteDir.hpp b/os/ReRemoteDir.hpp
new file mode 100644 (file)
index 0000000..c8837de
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ReRemoteDir.hpp
+ *
+ *  Created on: 25.03.2015
+ *      Author: hm
+ */
+
+#ifndef REREMOTEDIR_HPP_
+#define REREMOTEDIR_HPP_
+
+typedef struct {
+public:
+       int64_t m_modified;
+       int64_t m_acessed;
+       int32_t m_indexName;
+       int32_t m_rights;
+       int16_t m_user;
+       int16_t m_group;
+       char m_type;
+
+} ReRemoteFile;
+/*
+ *
+ */
+class ReRemoteDir : public ReSerializable {
+public:
+       ReRemoteDir();
+       virtual ~ReRemoteDir();
+public:
+       virtual void deserialize(uint8_t*& sequence, size_t& length);
+       void populate(const char* path);
+       virtual ReByteBuffer& serialize(ReByteBuffer& sequence);
+protected:
+       ReRemoteDir* m_parent;
+       int m_indexFileInParent;
+       ReByteBuffer m_namePool;
+       int m_fileCount;
+       ReRemoteFile* m_files;
+private:
+       static int m_serialNo;
+};
+
+/**
+ * A TCP server for file and directory processing.
+ */
+class ReRemoteDirService : public ReNetCommandHandler {
+public:
+       ReRemoteDirService();
+       ~ReRemoteDirService();
+public:
+       virtual ProcessingState handleNetCommand(ReByteBuffer& command,
+           ReByteBuffer& data, ReTCPConnection* connection);
+};
+#endif /* REREMOTEDIR_HPP_ */
index 02a95edba358ccfea76cff0e1e261b0e14f739a2..184b05c729d7f1aeb63bf51dfa1cb93eb96948b7 100644 (file)
@@ -26,6 +26,8 @@ enum RELOC_TRAVERSER {
        LC_GET_FILE_OWNER_2,    // 50408\r
 };\r
 \r
+int ReDirEntryFilter::m_serialId = buildSerialId(CLASSID_DIR_ENTRY_FILTER, 1);\r
+\r
 /**\r
  * Constructor.\r
  */\r
@@ -571,7 +573,8 @@ char ReDirStatus_t::typeAsChar() {
 /**\r
  * Constructor.\r
  */\r
-ReDirEntryFilter_t::ReDirEntryFilter_t() :\r
+ReDirEntryFilter::ReDirEntryFilter() :\r
+               ReSerializable(m_serialId),\r
            m_types(ReDirStatus_t::TC_ALL),\r
            m_nodePatterns(NULL),\r
            m_pathPatterns(NULL),\r
@@ -589,12 +592,59 @@ ReDirEntryFilter_t::ReDirEntryFilter_t() :
 /**\r
  * Destructor.\r
  */\r
-ReDirEntryFilter_t::~ReDirEntryFilter_t() {\r
+ReDirEntryFilter::~ReDirEntryFilter() {\r
+}\r
+\r
+/**\r
+ * Sets the members of the instance from a byte sequence.\r
+ *\r
+ * @param sequence     IN/OUT: the serialized byte sequence\r
+ * @param length       INT/OUT the length of <code>sequence</code>\r
+ */\r
+void ReDirEntryFilter::deserialize(uint8_t*& sequence, size_t& length){\r
+       /*ReDirStatus_t::Type_t m_types;\r
+       RePatternList* m_nodePatterns;\r
+       RePatternList* m_pathPatterns;\r
+       ReFileSize_t m_minSize;\r
+       ReFileSize_t m_maxSize;\r
+       ReFileTime_t m_minAge;\r
+       ReFileTime_t m_maxAge;\r
+       int m_minDepth;\r
+       int m_maxDepth;\r
+       bool m_allDirectories; */\r
+\r
+\r
 }\r
 /**\r
+ * Packs the members into a byte sequence.\r
+ *\r
+ * @param sequence     IN/OUT: the place for the byte sequence\r
+ */\r
+ReByteBuffer& ReDirEntryFilter::serialize(ReByteBuffer& sequence){\r
+       /*ReDirStatus_t::Type_t m_types;\r
+       RePatternList* m_nodePatterns;\r
+       RePatternList* m_pathPatterns;\r
+       ReFileSize_t m_minSize;\r
+       ReFileSize_t m_maxSize;\r
+       ReFileTime_t m_minAge;\r
+       ReFileTime_t m_maxAge;\r
+       int m_minDepth;\r
+       int m_maxDepth;\r
+       bool m_allDirectories; */\r
+       sequence.appendBits24(m_serialId);\r
+       packString255(sequence, m_nodePatterns->patternString());\r
+\r
+}\r
+\r
+\r
+/**\r
+ * Tests whether an entry matches the conditions of the filter.\r
  *\r
+ * @param entry                entry to test\r
+ * @return                     <true>: the entry matches the conditions of the filter<br>\r
+ *                                     <false>: otherwise\r
  */\r
-bool ReDirEntryFilter_t::match(ReDirStatus_t& entry) {\r
+bool ReDirEntryFilter::match(ReDirStatus_t& entry) {\r
        bool rc = false;\r
        do {\r
                if (m_allDirectories && entry.isDirectory()) {\r
@@ -857,7 +907,7 @@ ReDirStatus_t* ReTraverser::rawNextFile(int& level) {
  *                                     otherwise: the info about the next file in the\r
  *                                     directory tree\r
  */\r
-ReDirStatus_t* ReTraverser::nextFile(int& level, ReDirEntryFilter_t* filter) {\r
+ReDirStatus_t* ReTraverser::nextFile(int& level, ReDirEntryFilter* filter) {\r
        ReDirStatus_t* rc = rawNextFile(level);\r
        while (rc != NULL) {\r
                if (filter == NULL || filter->match(*rc)) {\r
@@ -905,7 +955,7 @@ bool ReTraverser::initEntry(const ReByteBuffer& parent, const char* node,
  *\r
  * @param filter       the filter with the properties to set\r
  */\r
-void ReTraverser::setPropertiesFromFilter(ReDirEntryFilter_t* filter) {\r
+void ReTraverser::setPropertiesFromFilter(ReDirEntryFilter* filter) {\r
        m_minLevel = filter->m_minDepth;\r
        m_maxLevel = filter->m_maxDepth;\r
        setDirPattern(filter->m_pathPatterns);\r
index 80ca6e2faddecfa1f1c4b4fa9522e79e44c631a7..7b42461c18265c95e025b32da0b0b06329cb03ea 100644 (file)
@@ -106,12 +106,14 @@ public:
        bool m_getPrivilege;
 #endif
 };
-class ReDirEntryFilter_t {
+class ReDirEntryFilter : public ReSerializable {
 public:
-       ReDirEntryFilter_t();
-       ~ReDirEntryFilter_t();
+       ReDirEntryFilter();
+       ~ReDirEntryFilter();
 public:
+       virtual void deserialize(uint8_t*& sequence, size_t& length);
        bool match(ReDirStatus_t& entry);
+       virtual ReByteBuffer& serialize(ReByteBuffer& sequence);
 public:
        ReDirStatus_t::Type_t m_types;
        RePatternList* m_nodePatterns;
@@ -123,7 +125,10 @@ public:
        int m_minDepth;
        int m_maxDepth;
        bool m_allDirectories;
+private:
+       static int m_serialId;
 };
+
 class ReTraceUnit {
 public:
        ReTraceUnit(int m_triggerCount = 10, int interval = 60);
@@ -212,7 +217,7 @@ public:
                return rc;
        }
        ReDirStatus_t* rawNextFile(int& level);
-       ReDirStatus_t* nextFile(int& level, ReDirEntryFilter_t* filter = NULL);
+       ReDirStatus_t* nextFile(int& level, ReDirEntryFilter* filter = NULL);
        /** Sets the tree traversal algorithm.
         * @param depthFirst    <code>true</code>: files of the subdirectories will
         *                      be returned earlier
@@ -240,7 +245,7 @@ public:
        inline void setMinLevel(int value) {
                m_minLevel = value;
        }
-       void setPropertiesFromFilter(ReDirEntryFilter_t* filter);
+       void setPropertiesFromFilter(ReDirEntryFilter* filter);
        /**
         * Return the sum of file lengths of the found files.
         * @return      the sum of file lengths of the files found until now
index 0cbcae77c145aad7f04991e49d4fb75eb506eb00..f6b57d36581f4ba7a068472100b25c3942a8868b 100644 (file)
@@ -40,5 +40,7 @@ inline bool operator >(const ReFileTime_t& time1, const ReFileTime_t& time2) {
 }
 #include "os/ReTraverser.hpp"
 #include "os/ReDirTools.hpp"
+#include "net/renet.hpp"
+#include "os/ReRemoteDir.hpp"
 
 #endif /* OS_REOS_HPP_ */