# HG changeset patch # User František Kučera # Date 1659178694 -7200 # Node ID 3e17086fffea87c274a13ac8df4a42d132bbaea5 # Parent e6f005f3edfe185fa89bd2e6a52cf14886937b59 process only relations named 'message' or matching the --relation pattern diff -r e6f005f3edfe -r 3e17086fffea src/Configuration.h --- a/src/Configuration.h Sat Jul 30 11:33:56 2022 +0200 +++ b/src/Configuration.h Sat Jul 30 12:58:14 2022 +0200 @@ -44,7 +44,7 @@ }; - relpipe::common::type::StringX relation = L"socket"; + relpipe::common::type::StringX relation = L"message"; std::vector options; virtual ~Configuration() { diff -r e6f005f3edfe -r 3e17086fffea src/SocketHandler.h --- a/src/SocketHandler.h Sat Jul 30 11:33:56 2022 +0200 +++ b/src/SocketHandler.h Sat Jul 30 12:58:14 2022 +0200 @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -42,10 +43,12 @@ std::wstring_convert> convertor; // TODO: support also other encodings. Configuration configuration; std::shared_ptr socket; + std::wregex relationPattern; struct CurrentRelation { relpipe::common::type::StringX name; std::vector attributes; + bool valid; relpipe::common::type::Integer attributeIndex = 0; std::string currentValue; } currentRelation; @@ -62,28 +65,28 @@ public: - SocketHandler(Configuration configuration) : configuration(configuration) { + SocketHandler(Configuration configuration) : configuration(configuration), relationPattern(std::wregex(configuration.relation)) { } void startRelation(relpipe::common::type::StringX name, std::vector attributes) override { - configureSocket(); - currentRelation = CurrentRelation{name, attributes}; + currentRelation = CurrentRelation{name, attributes, std::regex_match(name, relationPattern)}; + if (currentRelation.valid) configureSocket(); } void attribute(const relpipe::common::type::StringX& value) override { - - auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName(); - if (attributeName == L"text" && value.size()) currentRelation.currentValue = convertor.to_bytes(value); - else if (attributeName == L"data" && value.size()) currentRelation.currentValue = Hex::fromHex(value).str(); - else if (attributeName == L"text"); // keep empty or value from 'data' - else if (attributeName == L"data"); // keep empty or value from 'text' + if (currentRelation.valid) { + auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName(); + if (attributeName == L"text" && value.size()) currentRelation.currentValue = convertor.to_bytes(value); + else if (attributeName == L"data" && value.size()) currentRelation.currentValue = Hex::fromHex(value).str(); + else if (attributeName == L"text"); // keep empty or value from 'data' + else if (attributeName == L"data"); // keep empty or value from 'text' - currentRelation.attributeIndex++; - if (currentRelation.attributeIndex == currentRelation.attributes.size()) { - currentRelation.attributeIndex = 0; - socket->send(currentRelation.currentValue); + currentRelation.attributeIndex++; + if (currentRelation.attributeIndex == currentRelation.attributes.size()) { + currentRelation.attributeIndex = 0; + socket->send(currentRelation.currentValue); + } } - } void endOfPipe() {