bluetooth-test.cpp)
TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES}
vist-common
+ vist-client
gtest
pthread)
INSTALL(TARGETS ${TARGET_TEST}
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present 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.
#include "bluetooth.hpp"
#include "../test-util.hpp"
+#include <vist/client/query.hpp>
#include <vist/exception.hpp>
+#include <iostream>
+
#include <gtest/gtest.h>
using namespace vist;
EXPECT_TRUE(false) << e.what();
}
}
+
+TEST(BluetoothTests, get_policies)
+{
+ auto rows = Query::Execute("SELECT * FROM bluetooth");
+
+ EXPECT_TRUE(rows.size() == 1);
+}
+
+TEST(BluetoothTests, set_policies)
+{
+ Query::Execute("INSERT INTO policy_admin (name) VALUES ('vist-plugin-bluetooth-test')");
+
+ Query::Execute("UPDATE bluetooth SET desktopConnectivity = 3, state = 7");
+ Query::Execute("UPDATE bluetooth SET pairing = 2, tethering = 9");
+
+ auto rows = Query::Execute("SELECT * FROM bluetooth");
+ if (rows.size() == 1) {
+ EXPECT_EQ(rows[0]["state"], "7");
+ EXPECT_EQ(rows[0]["desktopConnectivity"], "3");
+ EXPECT_EQ(rows[0]["pairing"], "2");
+ EXPECT_EQ(rows[0]["tethering"], "9");
+ } else {
+ EXPECT_TRUE(false);
+ }
+
+ Query::Execute("DELETE FROM policy_admin WHERE name = 'vist-plugin-bluetooth-test'");
+}
table_name("bluetooth")
description("The policies related bluetooth.")
schema([
- Column("bluetooth", INTEGER, "The policy value about bluetooth state"),
- Column("bluetooth-desktop-connectivity", INTEGER, "The policy value about bt desktop connectivity"),
- Column("bluetooth-pairing", INTEGER, "The policy value about bluetooth pairing"),
- Column("bluetooth-tethering", INTEGER, "The policy value about bluetooth tethering"),
+ Column("state", INTEGER, "The policy value about bluetooth state"),
+ Column("desktopConnectivity", INTEGER, "The policy value about bt desktop connectivity"),
+ Column("pairing", INTEGER, "The policy value about bluetooth pairing"),
+ Column("tethering", INTEGER, "The policy value about bluetooth tethering"),
])
implementation("tizen/bluetooth@genBluetooth")
+implementation_update("tizen/bluetooth@updateBluetooth")
namespace {
-void getPolicy(Row& row, const std::string& name)
+std::map<std::string, std::string> ALIAS = {
+ { "state", "bluetooth" },
+ { "desktopConnectivity", "bluetooth-desktop-connectivity" },
+ { "pairing", "bluetooth-pairing" },
+ { "tethering", "bluetooth-tethering"} };
+
+void setPolicy(const std::string& name, int value)
{
- int value = vist::policy::API::Get(name);
- row[name] = std::to_string(value);
+ vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(value));
}
} // anonymous namespace
using namespace vist;
QueryData genBluetooth(QueryContext& context) try {
- INFO(VIST) << "Select query about policy table.";
+ INFO(VIST) << "Select query about bluetooth table.";
QueryData results;
Row row;
- getPolicy(row, "bluetooth");
- getPolicy(row, "bluetooth-desktop-connectivity");
- getPolicy(row, "bluetooth-pairing");
- getPolicy(row, "bluetooth-tethering");
+
+ for (const auto&[schemaName, policyName]: ALIAS) {
+ int value = vist::policy::API::Get(policyName);
+ row[schemaName] = std::to_string(value);
+ }
results.emplace_back(std::move(row));
return { r };
}
+QueryData updateBluetooth(QueryContext& context, const PluginRequest& request) try {
+ INFO(VIST) << "Update query about bluetooth table.";
+ if (request.count("json_value_array") == 0)
+ throw std::runtime_error("Wrong request format. Not found json value.");
+
+ std::string str = request.at("json_value_array");
+ rapidjson::Document document;
+ document.Parse(str.c_str());
+ if (document.HasParseError() || !document.IsArray())
+ throw std::runtime_error("Cannot parse request.");
+
+ if (document.Size() != 4)
+ throw std::runtime_error("Wrong request format.");
+
+ /// TODO(Sangwan): Sync vtab schema with policy definition
+ setPolicy("bluetooth", document[0].GetInt());
+ setPolicy("bluetooth-desktop-connectivity", document[1].GetInt());
+ setPolicy("bluetooth-pairing", document[2].GetInt());
+ setPolicy("bluetooth-tethering", document[3].GetInt());
+
+ Row r;
+ r["status"] = "success";
+ return { r };
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
+} catch (...) {
+ ERROR(VIST) << "Failed to query with unknown exception.";
+ Row r;
+ return { r };
+}
+
} // namespace tables
} // namespace osquery
#pragma once
+#include <vist/query-builder.hpp>
+
namespace vist {
namespace schema {
int tethering;
DECLARE_COLUMN(State, "state", &Bluetooth::state);
- DECLARE_COLUMN(DesktopConnectivity, "desktopConnectivity", &Bluetooth::DesktopConnectivity);
+ DECLARE_COLUMN(DesktopConnectivity, "desktopConnectivity", &Bluetooth::desktopConnectivity);
DECLARE_COLUMN(Pairing, "pairing", &Bluetooth::pairing);
DECLARE_COLUMN(Tethering, "tethering", &Bluetooth::tethering);
};
void Server::accept(const Task& task)
{
auto handler = [this, task]() {
- DEBUG(VIST) << "New session is accepted.";
auto connection = std::make_shared<Connection>(this->socket->accept());
+ DEBUG(VIST) << "New session is accepted: fd[" << connection->getFd() << "]";
/// process task per thread
this->worker.submit([this, connection, task]{
auto onRead = [connection, task]() {
Server::peer.reset(new Credentials(Credentials::Peer(connection->getFd())));
+ DEBUG(VIST) << "Read event occured: pid[" << Server::peer->pid << "]";
Message request = connection->recv();
DEBUG(VIST) << "Session header: " << request.signature;