--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugins.cpp
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @brief Definition of types, constants and functions common for both tests and plugins
+ */
+
+#include <vector>
+#include <sstream>
+#include <string>
+
+#include <plugins.h>
+
+namespace CynaraTestPlugins {
+
+Cynara::PluginData wrapAgentData(const AgentDataVector &data) {
+ std::stringstream wrappedData;
+ wrappedData << AGENT_DATA_RECORD_SEPARATOR;
+ for (size_t i = 0; i < data.size(); ++i) {
+ wrappedData << AGENT_DATA_UNIT_SEPARATOR
+ << data[i]
+ << AGENT_DATA_UNIT_SEPARATOR;
+ }
+ wrappedData << AGENT_DATA_RECORD_SEPARATOR;
+ return wrappedData.str();
+}
+
+static bool unwrapAgentDataFromSeparator(const Cynara::PluginData &wrappedData,
+ const std::string &separator,
+ size_t &pos, std::string &unit) {
+//check if wrapped data starts with separator
+ size_t separatorSize = separator.size();
+ if (wrappedData.compare(pos, separatorSize, separator) != 0)
+ return false;
+
+//find ending separator
+ size_t unitStartIndex = pos + separatorSize;
+ size_t endingSeparatorIndex = wrappedData.find(separator, unitStartIndex);
+ if (endingSeparatorIndex == std::string::npos)
+ return false;
+
+//return found unit
+ pos = endingSeparatorIndex + separatorSize;
+ size_t unitSize = endingSeparatorIndex - unitStartIndex;
+ unit.assign(wrappedData, unitStartIndex, unitSize);
+ return true;
+}
+
+bool unwrapAgentData(const Cynara::PluginData &wrappedData, AgentDataVector& data) {
+ std::string record;
+ size_t pos = 0;
+ if (!unwrapAgentDataFromSeparator(wrappedData, AGENT_DATA_RECORD_SEPARATOR, pos, record))
+ return false;
+
+ pos = 0;
+ while (pos < record.size()) {
+ std::string unit;
+ if (!unwrapAgentDataFromSeparator(record, AGENT_DATA_UNIT_SEPARATOR, pos, unit))
+ return false;
+ data.push_back(unit);
+ }
+ return true;
+}
+
+} // namespace CynaraTestPlugins
/**
* @file plugins.h
* @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
- * @brief Definition of policy types and description used by test plugins
+ * @brief Definition of types, constants and functions common for both tests and plugins
*/
#ifndef CYNARA_TEST_PLUGINS_H
#include <map>
#include <string>
+#include <cynara-plugin.h>
#include <cynara/types/PolicyDescription.h>
#include <cynara/types/PolicyType.h>
}),
};
+static const std::string AGENT_DATA_UNIT_SEPARATOR("\31");
+static const std::string AGENT_DATA_RECORD_SEPARATOR("\30");
+static const std::string AGENT_DATA_ALLOW("Allow");
+static const std::string AGENT_DATA_DENY("Deny");
+
+typedef std::vector<std::string> AgentDataVector;
+
+Cynara::PluginData wrapAgentData(const AgentDataVector &data);
+bool unwrapAgentData(const Cynara::PluginData &wrappedData, AgentDataVector& data);
+
} // namespace CynaraTestPlugins
#endif // CYNARA_TEST_PLUGINS_H