INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/api")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/sqlite3")
+INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/tsqb")
INCLUDE_DIRECTORIES("/usr/local/include")
ENABLE_TESTING()
--- /dev/null
+/*
+ * Copyright (c) 2019 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 property.h
+ * @brief Provides type-safe getter method
+ */
+
+
+#pragma once
+
+#include <string>
+#include <map>
+#include <stdexcept>
+
+namespace osquery {
+
+/// TBD: Consider error handling.
+template <typename T>
+class Property {
+public:
+ explicit Property();
+
+ template<typename Struct, typename Member>
+ Member get(Member Struct::*);
+
+private:
+ std::map<std::string, std::string> data;
+};
+
+} // namespace osquery
--- /dev/null
+/*
+ * Copyright (c) 2019 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 time.h
+ * @brief The scheme of time (sync with osquery/tables/spec/time.table)
+ */
+
+
+#pragma once
+
+struct Time {
+ int hour;
+ int minutes;
+ int seconds;
+};
# tizen feature
ADD_SUBDIRECTORY(manager)
ADD_SUBDIRECTORY(notification)
+ADD_SUBDIRECTORY(property)
## Table generation #############################################################
FILE(GLOB TABLE_FILES "tables/specs/*.table")
--- /dev/null
+# Copyright (c) 2019 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
+
+ADD_OSQUERY_LIBRARY(TRUE osquery_property property.cpp)
+
+ADD_OSQUERY_TEST(TRUE osquery_property_tests property_tests.cpp)
--- /dev/null
+/*
+ * Copyright (c) 2019 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 property.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Implementation of Property
+ */
+
+#include <osquery_manager.h>
+#include <property.h>
+#include <schema/time.h>
+
+#include <tsqb.hxx>
+
+#include <boost/lexical_cast.hpp>
+
+namespace {
+
+using namespace tsqb;
+auto time = make_table("time",
+ make_column("hour", &Time::hour),
+ make_column("minutes", &Time::minutes),
+ make_column("seconds", &Time::seconds));
+
+auto db = make_database("db", time);
+
+} // anonymous namespace
+
+namespace osquery {
+
+template <typename T>
+Property<T>::Property()
+{
+ auto results = OsqueryManager::execute(db.selectAll<T>());
+ if (results.size() > 0)
+ this->data = std::move(results[0]);
+}
+
+template <typename T>
+template<typename Struct, typename Member>
+Member Property<T>::get(Member Struct::* field)
+{
+ if (this->data.size() == 0)
+ throw std::runtime_error("Data is not exist.");
+
+ std::string key = db.getColumnName(field);
+ if (key.empty())
+ throw std::runtime_error("Key is not exist.");
+
+ /// Convert "table.column" to "column"
+ std::size_t pos = key.find(".");
+ if (pos != std::string::npos && pos != key.size() - 1)
+ key = key.substr(pos + 1);
+
+ std::string value = this->data[key];
+ if (value.empty())
+ throw std::runtime_error("Value is not exist.");
+
+ /// TODO(Sangwan): Catch boost::bad_lexical_cast
+ return boost::lexical_cast<Member>(value);
+}
+
+/// Explicit instantiation
+template class Property<Time>;
+template int Property<Time>::get(int Time::*);
+
+} // namespace osquery
--- /dev/null
+/*
+ * Copyright (c) 2019 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
+ */
+
+#include <gtest/gtest.h>
+
+#include <osquery/logger.h>
+
+#include <property.h>
+#include <schema/time.h>
+
+using namespace osquery;
+
+class PropertyTests : public testing::Test {};
+
+TEST_F(PropertyTests, get) {
+ Time result = { -1, -1, -1 };
+
+ Property<Time> time;
+ result.hour = time.get(&Time::hour);
+ result.minutes = time.get(&Time::minutes);
+ result.seconds = time.get(&Time::seconds);
+
+ /// Once query execution
+ VLOG(1) << "[Test] time table:";
+ VLOG(1) << "\t hour: " << result.hour;
+ VLOG(1) << "\t minutes: " << result.minutes;
+ VLOG(1) << "\t seconds: " << result.seconds;
+
+ /// Each query execution
+ VLOG(1) << "[Test] time table:";
+ VLOG(1) << "\t hour: " << Property<Time>().get(&Time::hour);
+ VLOG(1) << "\t minutes: " << Property<Time>().get(&Time::minutes);
+ VLOG(1) << "\t seconds: " << Property<Time>().get(&Time::seconds);
+
+ EXPECT_NE(result.hour, -1);
+ EXPECT_NE(result.minutes, -1);
+ EXPECT_NE(result.seconds, -1);
+}
+
+int main(int argc, char* argv[]) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
# See the License for the specific language governing permissions and
# limitations under the License
-
-INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include")
-
ADD_OSQUERY_TEST(FALSE tsqb_tests tsqb-tests.cpp)
#pragma once
-#include "database.hxx"
-#include "table.hxx"
-#include "column.hxx"
-#include "expression.hxx"
-#include "condition.hxx"
-#include "util.hxx"
+#include "include/database.hxx"
+#include "include/table.hxx"
+#include "include/column.hxx"
+#include "include/expression.hxx"
+#include "include/condition.hxx"
+#include "include/util.hxx"