From: hama Date: Sun, 29 Mar 2015 22:02:00 +0000 (+0200) Subject: ReSerializable, ReClassId, ReRemoteDir X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=c80e3fae51d07040ac50f3459ae7e98a06326c31;p=crepublib ReSerializable, ReClassId, ReRemoteDir --- diff --git a/base/ReClassId.cpp b/base/ReClassId.cpp new file mode 100644 index 0000000..1838046 --- /dev/null +++ b/base/ReClassId.cpp @@ -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 index 0000000..feef67a --- /dev/null +++ b/base/ReClassId.hpp @@ -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_ */ diff --git a/base/ReException.cpp b/base/ReException.cpp index 26ecb76..dc2a216 100644 --- a/base/ReException.cpp +++ b/base/ReException.cpp @@ -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. * diff --git a/base/ReSerializable.cpp b/base/ReSerializable.cpp index 763eb4b..71451bb 100644 --- a/base/ReSerializable.cpp +++ b/base/ReSerializable.cpp @@ -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. */ diff --git a/base/ReSerializable.hpp b/base/ReSerializable.hpp index 6afb0f5..6ad8e33 100644 --- a/base/ReSerializable.hpp +++ b/base/ReSerializable.hpp @@ -11,28 +11,38 @@ #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(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(sequence), strLen); - length -= strLen - 1; + if (length < 1 || (strLen = *sequence) > length) + throw ReSerializationLengthException(length, 1 + strLen, this); + value.set(reinterpret_cast(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(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(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(sequence), strLen); - length -= strLen - 4; + throw ReSerializationLengthException(length, 4 + strLen, this); + value.set(reinterpret_cast(sequence + 4), strLen); + strLen += 4; + length -= strLen; + sequence += strLen; } private: int m_serialId; diff --git a/base/rebase.hpp b/base/rebase.hpp index 67d4e9e..673cb1d 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -118,6 +118,7 @@ inline int min(int a, int b) { inline int max(int a, int b) { return a < b ? a : b; } +#include "base/ReClassId.hpp" #include "base/ReException.hpp" #include "base/ReMutex.hpp" #include "base/ReByteBuffer.hpp" diff --git a/cunit/cuReDirTools.cpp b/cunit/cuReDirTools.cpp index 4f7ecd2..6bd506f 100644 --- a/cunit/cuReDirTools.cpp +++ b/cunit/cuReDirTools.cpp @@ -287,7 +287,7 @@ private: opts.addStandardFilterOptions(); const char* argv[] = { "x", "-y1980.01.02", "-o1980.01.03", "-D5", "-d1", "-z1k", "-Z2M", "-p;*;-*~" }; - ReDirEntryFilter_t filter; + ReDirEntryFilter filter; opts.programArgsChangeable().init(sizeof argv / sizeof argv[0], argv); opts.setFilterFromProgramArgs(filter); // local time: +3600 diff --git a/cunit/cuReSerializable.cpp b/cunit/cuReSerializable.cpp index dbb53b1..af70cb9 100644 --- a/cunit/cuReSerializable.cpp +++ b/cunit/cuReSerializable.cpp @@ -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); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 28e4822..77828ac 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -640,7 +640,7 @@ void ReDirOptions::optimizePathPattern(ReByteBuffer& buffer) { * * @param filter OUT: the filter to set */ -void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter_t& filter) { +void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter& filter) { ReByteBuffer buffer; if (m_programArgs.getString("younger", buffer)[0] != '\0') filter.m_maxAge = checkDate(buffer.str()); @@ -1628,7 +1628,7 @@ void ReDirRandom::doIt() { const ReStringList& ReDirStatistic::calculate(const char* base, int level, void (*formatter)(const ReDirStatisticData& data, ReDirStatistic& parent, ReByteBuffer& line)) { - ReDirEntryFilter_t filter; + ReDirEntryFilter filter; ReTraverser traverser(base, this); setFilterFromProgramArgs(filter); traverser.setPropertiesFromFilter(&filter); @@ -2242,7 +2242,7 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength, * Synchronizes two directory trees. */ void ReDirSync::doIt() { - ReDirEntryFilter_t filter; + ReDirEntryFilter filter; const char* sep = OS_SEPARATOR; ReByteBuffer buffer; ReByteBuffer target(m_programArgs.arg(m_programArgs.argCount() - 1)); diff --git a/os/ReDirTools.hpp b/os/ReDirTools.hpp index 3623a0a..d2f7b60 100644 --- a/os/ReDirTools.hpp +++ b/os/ReDirTools.hpp @@ -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 index 0000000..0207988 --- /dev/null +++ b/os/ReRemoteDir.cpp @@ -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 sequence + */ +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 index 0000000..c8837de --- /dev/null +++ b/os/ReRemoteDir.hpp @@ -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_ */ diff --git a/os/ReTraverser.cpp b/os/ReTraverser.cpp index 02a95ed..184b05c 100644 --- a/os/ReTraverser.cpp +++ b/os/ReTraverser.cpp @@ -26,6 +26,8 @@ enum RELOC_TRAVERSER { LC_GET_FILE_OWNER_2, // 50408 }; +int ReDirEntryFilter::m_serialId = buildSerialId(CLASSID_DIR_ENTRY_FILTER, 1); + /** * Constructor. */ @@ -571,7 +573,8 @@ char ReDirStatus_t::typeAsChar() { /** * Constructor. */ -ReDirEntryFilter_t::ReDirEntryFilter_t() : +ReDirEntryFilter::ReDirEntryFilter() : + ReSerializable(m_serialId), m_types(ReDirStatus_t::TC_ALL), m_nodePatterns(NULL), m_pathPatterns(NULL), @@ -589,12 +592,59 @@ ReDirEntryFilter_t::ReDirEntryFilter_t() : /** * Destructor. */ -ReDirEntryFilter_t::~ReDirEntryFilter_t() { +ReDirEntryFilter::~ReDirEntryFilter() { +} + +/** + * 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 sequence + */ +void ReDirEntryFilter::deserialize(uint8_t*& sequence, size_t& length){ + /*ReDirStatus_t::Type_t m_types; + RePatternList* m_nodePatterns; + RePatternList* m_pathPatterns; + ReFileSize_t m_minSize; + ReFileSize_t m_maxSize; + ReFileTime_t m_minAge; + ReFileTime_t m_maxAge; + int m_minDepth; + int m_maxDepth; + bool m_allDirectories; */ + + } /** + * Packs the members into a byte sequence. + * + * @param sequence IN/OUT: the place for the byte sequence + */ +ReByteBuffer& ReDirEntryFilter::serialize(ReByteBuffer& sequence){ + /*ReDirStatus_t::Type_t m_types; + RePatternList* m_nodePatterns; + RePatternList* m_pathPatterns; + ReFileSize_t m_minSize; + ReFileSize_t m_maxSize; + ReFileTime_t m_minAge; + ReFileTime_t m_maxAge; + int m_minDepth; + int m_maxDepth; + bool m_allDirectories; */ + sequence.appendBits24(m_serialId); + packString255(sequence, m_nodePatterns->patternString()); + +} + + +/** + * Tests whether an entry matches the conditions of the filter. * + * @param entry entry to test + * @return : the entry matches the conditions of the filter
+ * : otherwise */ -bool ReDirEntryFilter_t::match(ReDirStatus_t& entry) { +bool ReDirEntryFilter::match(ReDirStatus_t& entry) { bool rc = false; do { if (m_allDirectories && entry.isDirectory()) { @@ -857,7 +907,7 @@ ReDirStatus_t* ReTraverser::rawNextFile(int& level) { * otherwise: the info about the next file in the * directory tree */ -ReDirStatus_t* ReTraverser::nextFile(int& level, ReDirEntryFilter_t* filter) { +ReDirStatus_t* ReTraverser::nextFile(int& level, ReDirEntryFilter* filter) { ReDirStatus_t* rc = rawNextFile(level); while (rc != NULL) { if (filter == NULL || filter->match(*rc)) { @@ -905,7 +955,7 @@ bool ReTraverser::initEntry(const ReByteBuffer& parent, const char* node, * * @param filter the filter with the properties to set */ -void ReTraverser::setPropertiesFromFilter(ReDirEntryFilter_t* filter) { +void ReTraverser::setPropertiesFromFilter(ReDirEntryFilter* filter) { m_minLevel = filter->m_minDepth; m_maxLevel = filter->m_maxDepth; setDirPattern(filter->m_pathPatterns); diff --git a/os/ReTraverser.hpp b/os/ReTraverser.hpp index 80ca6e2..7b42461 100644 --- a/os/ReTraverser.hpp +++ b/os/ReTraverser.hpp @@ -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 true: 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 diff --git a/os/reos.hpp b/os/reos.hpp index 0cbcae7..f6b57d3 100644 --- a/os/reos.hpp +++ b/os/reos.hpp @@ -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_ */