Remove osquery/json
authorSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 14 May 2020 07:56:24 +0000 (16:56 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Wed, 20 May 2020 01:51:37 +0000 (10:51 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
19 files changed:
src/osquery/core/CMakeLists.txt
src/osquery/core/plugins/plugin.h
src/osquery/core/query.cpp
src/osquery/core/sql/diff_results.cpp
src/osquery/core/sql/diff_results.h
src/osquery/core/sql/query_data.cpp [deleted file]
src/osquery/core/sql/query_data.h
src/osquery/core/sql/row.cpp [deleted file]
src/osquery/core/sql/row.h
src/osquery/core/sql/table_row.h
src/osquery/core/sql/table_rows.cpp [deleted file]
src/osquery/core/sql/table_rows.h [deleted file]
src/osquery/include/osquery/query.h
src/osquery/include/osquery/tables.h
src/osquery/registry/registry_factory.cpp
src/osquery/sql/dynamic_table_row.cpp
src/osquery/sql/dynamic_table_row.h
src/osquery/sql/tests/sql.cpp
src/osquery/sql/tests/sqlite_util_tests.cpp

index 7df85b8..9416338 100644 (file)
@@ -1,4 +1,4 @@
-#  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.
@@ -18,10 +18,7 @@ ADD_OSQUERY_LIBRARY(osquery_core tables.cpp
                                                                 plugins/sql.cpp
                                                                 sql/column.cpp
                                                                 sql/diff_results.cpp
-                                                                sql/query_data.cpp
-                                                                sql/row.cpp
-                                                                sql/scheduled_query.cpp
-                                                                sql/table_rows.cpp)
+                                                                sql/scheduled_query.cpp)
 
 FILE(GLOB OSQUERY_CORE_TESTS "tests/*.cpp")
 ADD_OSQUERY_TEST(${OSQUERY_SQL_TESTS})
index 801cad4..3ea4d8c 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <boost/noncopyable.hpp>
 
-#include <osquery/core/sql/table_rows.h>
+#include <osquery/core/sql/table_row.h>
 #include <osquery/utils/status/status.h>
 
 namespace osquery {
index 27bd3f1..a38c749 100644 (file)
 #include <vector>
 
 #include <vist/logger.hpp>
-#include <osquery/query.h>
-
-#include <osquery/utils/json/json.h>
 
-namespace rj = rapidjson;
+#include <osquery/query.h>
+#include <osquery/utils/status/status.h>
 
 namespace osquery {
 
@@ -105,163 +103,4 @@ Status Query::addNewResults(QueryDataTyped current_qd,
   return Status::success();
 }
 
-Status deserializeDiffResults(const rj::Value& doc, DiffResults& dr) {
-  if (!doc.IsObject()) {
-    return Status(1);
-  }
-
-  if (doc.HasMember("removed")) {
-    auto status = deserializeQueryData(doc["removed"], dr.removed);
-    if (!status.ok()) {
-      return status;
-    }
-  }
-
-  if (doc.HasMember("added")) {
-    auto status = deserializeQueryData(doc["added"], dr.added);
-    if (!status.ok()) {
-      return status;
-    }
-  }
-  return Status::success();
-}
-
-inline void addLegacyFieldsAndDecorations(const QueryLogItem& item,
-                                          JSON& doc,
-                                          rj::Document& obj) {
-  // Apply legacy fields.
-  doc.addRef("name", item.name, obj);
-  doc.addRef("hostIdentifier", item.identifier, obj);
-  doc.addRef("calendarTime", item.calendar_time, obj);
-  doc.add("unixTime", item.time, obj);
-  doc.add("epoch", static_cast<size_t>(item.epoch), obj);
-  doc.add("counter", static_cast<size_t>(item.counter), obj);
-
-  // Append the decorations.
-  if (!item.decorations.empty()) {
-    auto dec_obj = doc.getObject();
-    auto target_obj = std::ref(dec_obj);
-    target_obj = std::ref(obj);
-
-    for (const auto& name : item.decorations) {
-      doc.addRef(name.first, name.second, target_obj);
-    }
-  }
-}
-
-inline void getLegacyFieldsAndDecorations(const JSON& doc, QueryLogItem& item) {
-  if (doc.doc().HasMember("decorations")) {
-    if (doc.doc()["decorations"].IsObject()) {
-      for (const auto& i : doc.doc()["decorations"].GetObject()) {
-        item.decorations[i.name.GetString()] = i.value.GetString();
-      }
-    }
-  }
-
-  item.name = doc.doc()["name"].GetString();
-  item.identifier = doc.doc()["hostIdentifier"].GetString();
-  item.calendar_time = doc.doc()["calendarTime"].GetString();
-  item.time = doc.doc()["unixTime"].GetUint64();
-}
-
-Status serializeQueryLogItem(const QueryLogItem& item, JSON& doc) {
-  if (item.results.added.size() > 0 || item.results.removed.size() > 0) {
-    auto obj = doc.getObject();
-    auto status = serializeDiffResults(
-        item.results, doc, obj, 0);
-    if (!status.ok()) {
-      return status;
-    }
-
-    doc.add("diffResults", obj);
-  } else {
-    auto arr = doc.getArray();
-    auto status = serializeQueryData(
-        item.snapshot_results, doc, arr, 0);
-    if (!status.ok()) {
-      return status;
-    }
-
-    doc.add("snapshot", arr);
-    doc.addRef("action", "snapshot");
-  }
-
-  addLegacyFieldsAndDecorations(item, doc, doc.doc());
-  return Status::success();
-}
-
-Status serializeEvent(const QueryLogItem& item,
-                      const rj::Value& event_obj,
-                      JSON& doc,
-                      rj::Document& obj) {
-  addLegacyFieldsAndDecorations(item, doc, obj);
-  auto columns_obj = doc.getObject();
-  for (const auto& i : event_obj.GetObject()) {
-    // Yield results as a "columns." map to avoid namespace collisions.
-    doc.add(i.name.GetString(), i.value, columns_obj);
-  }
-  doc.add("columns", columns_obj, obj);
-  return Status::success();
-}
-
-Status serializeQueryLogItemAsEvents(const QueryLogItem& item, JSON& doc) {
-  auto temp_doc = JSON::newObject();
-  if (!item.results.added.empty() || !item.results.removed.empty()) {
-    auto status = serializeDiffResults(
-        item.results, temp_doc, temp_doc.doc(), 0);
-    if (!status.ok()) {
-      return status;
-    }
-  } else if (!item.snapshot_results.empty()) {
-    auto arr = doc.getArray();
-    auto status = serializeQueryData(
-        item.snapshot_results, temp_doc, arr, 0);
-    if (!status.ok()) {
-      return status;
-    }
-    temp_doc.add("snapshot", arr);
-  } else {
-    // This error case may also be represented in serializeQueryLogItem.
-    return Status(1, "No differential or snapshot results");
-  }
-
-  for (auto& action : temp_doc.doc().GetObject()) {
-    for (auto& row : action.value.GetArray()) {
-      auto obj = doc.getObject();
-      serializeEvent(item, row, doc, obj);
-      doc.addCopy("action", action.name.GetString(), obj);
-      doc.push(obj);
-    }
-  }
-  return Status::success();
-}
-
-Status serializeQueryLogItemJSON(const QueryLogItem& item, std::string& json) {
-  auto doc = JSON::newObject();
-  auto status = serializeQueryLogItem(item, doc);
-  if (!status.ok()) {
-    return status;
-  }
-
-  return doc.toString(json);
-}
-
-Status serializeQueryLogItemAsEventsJSON(const QueryLogItem& item,
-                                         std::vector<std::string>& items) {
-  auto doc = JSON::newArray();
-  auto status = serializeQueryLogItemAsEvents(item, doc);
-  if (!status.ok()) {
-    return status;
-  }
-
-  // return doc.toString()
-  for (auto& event : doc.doc().GetArray()) {
-    rj::StringBuffer sb;
-    rj::Writer<rj::StringBuffer> writer(sb);
-    event.Accept(writer);
-    items.push_back(sb.GetString());
-  }
-  return Status::success();
-}
-
 }
index 80c7a10..ba35e57 100644 (file)
@@ -8,47 +8,8 @@
 
 #include "diff_results.h"
 
-namespace rj = rapidjson;
-
 namespace osquery {
 
-Status serializeDiffResults(const DiffResults& d,
-                            JSON& doc,
-                            rj::Document& obj,
-                            bool asNumeric) {
-  // Serialize and add "removed" first.
-  // A property tree is somewhat ordered, this provides a loose contract to
-  // the logger plugins and their aggregations, allowing them to parse chunked
-  // lines. Note that the chunking is opaque to the database functions.
-  auto removed_arr = doc.getArray();
-  auto status = serializeQueryData(d.removed, doc, removed_arr, asNumeric);
-  if (!status.ok()) {
-    return status;
-  }
-  doc.add("removed", removed_arr, obj);
-
-  auto added_arr = doc.getArray();
-  status = serializeQueryData(d.added, doc, added_arr, asNumeric);
-  if (!status.ok()) {
-    return status;
-  }
-  doc.add("added", added_arr, obj);
-  return Status::success();
-}
-
-Status serializeDiffResultsJSON(const DiffResults& d,
-                                std::string& json,
-                                bool asNumeric) {
-  auto doc = JSON::newObject();
-
-  ColumnNames cols;
-  auto status = serializeDiffResults(d, doc, doc.doc(), asNumeric);
-  if (!status.ok()) {
-    return status;
-  }
-  return doc.toString(json);
-}
-
 DiffResults diff(QueryDataSet& old, QueryDataTyped& current) {
   DiffResults r;
 
index d07f902..0b1732e 100644 (file)
@@ -9,6 +9,7 @@
 #pragma once
 
 #include <osquery/core/sql/query_data.h>
+#include <osquery/utils/only_movable.h>
 
 namespace osquery {
 
@@ -44,36 +45,6 @@ struct DiffResults : private only_movable {
 };
 
 /**
- * @brief Serialize a DiffResults object into a JSON object.
- *
- * The object JSON will contain two new keys: added and removed.
- *
- * @param d the DiffResults to serialize.
- * @param doc the managed JSON document.
- * @param obj [output] the output JSON object.
- * @param asNumeric true iff numeric values are serialized as such
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeDiffResults(const DiffResults& d,
-                            JSON& doc,
-                            rapidjson::Document& obj,
-                            bool asNumeric);
-
-/**
- * @brief Serialize a DiffResults object into a JSON string.
- *
- * @param d the DiffResults to serialize.
- * @param json [output] the output JSON string.
- * @param asNumeric true iff numeric values are serialized as such
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeDiffResultsJSON(const DiffResults& d,
-                                std::string& json,
-                                bool asNumeric);
-
-/**
  * @brief Diff QueryDataSet object and QueryData object
  *        and create a DiffResults object
  *
diff --git a/src/osquery/core/sql/query_data.cpp b/src/osquery/core/sql/query_data.cpp
deleted file mode 100644 (file)
index c9bff06..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include "query_data.h"
-
-namespace rj = rapidjson;
-
-namespace osquery {
-
-Status serializeQueryData(const QueryData& q,
-                          const ColumnNames& cols,
-                          JSON& doc,
-                          rj::Document& arr) {
-  for (const auto& r : q) {
-    auto row_obj = doc.getObject();
-    auto status = serializeRow(r, cols, doc, row_obj);
-    if (!status.ok()) {
-      return status;
-    }
-    doc.push(row_obj, arr);
-  }
-  return Status::success();
-}
-
-Status serializeQueryData(const QueryDataTyped& q,
-                          JSON& doc,
-                          rj::Document& arr,
-                          bool asNumeric) {
-  for (const auto& r : q) {
-    auto row_obj = doc.getObject();
-    auto status = serializeRow(r, doc, row_obj, asNumeric);
-    if (!status.ok()) {
-      return status;
-    }
-    doc.push(row_obj, arr);
-  }
-  return Status::success();
-}
-
-Status serializeQueryDataJSON(const QueryData& q, std::string& json) {
-  auto doc = JSON::newArray();
-
-  ColumnNames cols;
-  auto status = serializeQueryData(q, cols, doc, doc.doc());
-  if (!status.ok()) {
-    return status;
-  }
-  return doc.toString(json);
-}
-
-Status serializeQueryDataJSON(const QueryDataTyped& q,
-                              std::string& json,
-                              bool asNumeric) {
-  auto doc = JSON::newArray();
-
-  auto status = serializeQueryData(q, doc, doc.doc(), asNumeric);
-  if (!status.ok()) {
-    return status;
-  }
-  return doc.toString(json);
-}
-
-Status deserializeQueryData(const rj::Value& arr, QueryData& qd) {
-  if (!arr.IsArray()) {
-    return Status(1);
-  }
-
-  for (const auto& i : arr.GetArray()) {
-    Row r;
-    auto status = deserializeRow(i, r);
-    if (!status.ok()) {
-      return status;
-    }
-    qd.push_back(r);
-  }
-  return Status::success();
-}
-
-Status deserializeQueryData(const rj::Value& arr, QueryDataTyped& qd) {
-  if (!arr.IsArray()) {
-    return Status(1);
-  }
-
-  for (const auto& i : arr.GetArray()) {
-    RowTyped r;
-    auto status = deserializeRow(i, r);
-    if (!status.ok()) {
-      return status;
-    }
-    qd.push_back(r);
-  }
-  return Status::success();
-}
-
-Status deserializeQueryData(const rj::Value& v, QueryDataSet& qd) {
-  if (!v.IsArray()) {
-    return Status(1, "JSON object was not an array");
-  }
-
-  for (const auto& i : v.GetArray()) {
-    RowTyped r;
-    auto status = deserializeRow(i, r);
-    if (!status.ok()) {
-      return status;
-    }
-    qd.insert(std::move(r));
-  }
-  return Status::success();
-}
-
-Status deserializeQueryDataJSON(const std::string& json, QueryData& qd) {
-  auto doc = JSON::newArray();
-  if (!doc.fromString(json) || !doc.doc().IsArray()) {
-    return Status(1, "Cannot deserializing JSON");
-  }
-
-  return deserializeQueryData(doc.doc(), qd);
-}
-
-Status deserializeQueryDataJSON(const std::string& json, QueryDataSet& qd) {
-  rj::Document doc;
-  if (doc.Parse(json.c_str()).HasParseError()) {
-    return Status(1, "Error serializing JSON");
-  }
-  return deserializeQueryData(doc, qd);
-}
-
-bool addUniqueRowToQueryData(QueryDataTyped& q, const RowTyped& r) {
-  if (std::find(q.begin(), q.end(), r) != q.end()) {
-    return false;
-  }
-  q.push_back(r);
-  return true;
-}
-
-} // namespace osquery
index 2bf50b9..25533f6 100644 (file)
@@ -38,89 +38,4 @@ using QueryDataTyped = std::vector<RowTyped>;
  */
 using QueryDataSet = std::multiset<RowTyped>;
 
-/**
- * @brief Serialize a QueryData object into a JSON array.
- *
- * @param q the QueryData to serialize.
- * @param cols the TableColumn vector indicating column order.
- * @param doc the managed JSON document.
- * @param arr [output] the output JSON array.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeQueryData(const QueryData& q,
-                          const ColumnNames& cols,
-                          JSON& doc,
-                          rapidjson::Document& arr);
-
-/**
- * @brief Serialize a QueryDataTyped object into a JSON array.
- *
- * @param q the QueryDataTyped to serialize.
- * @param cols the TableColumn vector indicating column order.
- * @param doc the managed JSON document.
- * @param arr [output] the output JSON array.
- * @param asNumeric true iff numeric values are serialized as such
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeQueryData(const QueryDataTyped& q,
-                          JSON& doc,
-                          rapidjson::Document& arr,
-                          bool asNumeric);
-
-/**
- * @brief Serialize a QueryData object into a JSON string.
- *
- * @param q the QueryData to serialize.
- * @param json [output] the output JSON string.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeQueryDataJSON(const QueryData& q, std::string& json);
-
-/**
- * @brief Serialize a QueryDataTyped object into a JSON string.
- *
- * @param q the QueryDataTyped to serialize.
- * @param json [output] the output JSON string.
- * @param asNumeric true iff numeric values are serialized as such
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeQueryDataJSON(const QueryDataTyped& q,
-                              std::string& json,
-                              bool asNumeric);
-
-/// Inverse of serializeQueryData, convert JSON to QueryData.
-Status deserializeQueryData(const rapidjson::Value& arr, QueryData& qd);
-
-/// Inverse of serializeQueryData, convert JSON to QueryDataTyped.
-Status deserializeQueryData(const rapidjson::Value& arr, QueryDataTyped& qd);
-
-/// Inverse of serializeQueryData, convert JSON to QueryDataSet.
-Status deserializeQueryData(const rapidjson::Value& arr, QueryDataSet& qd);
-
-/// Inverse of serializeQueryDataJSON, convert a JSON string to QueryData.
-Status deserializeQueryDataJSON(const std::string& json, QueryData& qd);
-
-/// Inverse of serializeQueryDataJSON, convert a JSON string to QueryDataSet.
-Status deserializeQueryDataJSON(const std::string& json, QueryDataSet& qd);
-
-/**
- * @brief Add a Row to a QueryData if the Row hasn't appeared in the QueryData
- * already
- *
- * Note that this function will iterate through the QueryData list until a
- * given Row is found (or not found). This shouldn't be that significant of an
- * overhead for most use-cases, but it's worth keeping in mind before you use
- * this in it's current state.
- *
- * @param q the QueryDataTyped list to append to
- * @param r the RowTyped to add to q
- *
- * @return true if the Row was added to the QueryData, false if it was not
- */
-bool addUniqueRowToQueryData(QueryDataTyped& q, const RowTyped& r);
-
 } // namespace osquery
diff --git a/src/osquery/core/sql/row.cpp b/src/osquery/core/sql/row.cpp
deleted file mode 100644 (file)
index 76aea18..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include "row.h"
-#include <osquery/utils/conversions/castvariant.h>
-
-namespace rj = rapidjson;
-
-namespace osquery {
-
-Status serializeRow(const Row& r,
-                    const ColumnNames& cols,
-                    JSON& doc,
-                    rj::Value& obj) {
-  if (cols.empty()) {
-    for (const auto& i : r) {
-      doc.addRef(i.first, i.second, obj);
-    }
-  } else {
-    for (const auto& c : cols) {
-      auto i = r.find(c);
-      if (i != r.end()) {
-        doc.addRef(c, i->second, obj);
-      }
-    }
-  }
-
-  return Status::success();
-}
-
-class DocAppenderVisitor : public boost::static_visitor<> {
- public:
-  DocAppenderVisitor(JSON& dc, rj::Value& ob) : doc(dc), obj(ob) {}
-  void operator()(const std::string& key, const long long& i) const {
-    doc.add(key, i, obj);
-  }
-
-  void operator()(const std::string& key, const double& d) const {
-    doc.add(key, d, obj);
-  }
-
-  void operator()(const std::string& key, const std::string& str) const {
-    doc.addRef(key, str, obj);
-  }
-
- private:
-  JSON& doc;
-  rj::Value& obj;
-};
-
-Status serializeRow(const RowTyped& r,
-                    JSON& doc,
-                    rj::Value& obj,
-                    bool asNumeric) {
-  DocAppenderVisitor visitor(doc, obj);
-  for (const auto& i : r) {
-    if (asNumeric) {
-      boost::apply_visitor([&doc, &obj, key = i.first](
-                               auto value) { doc.add(key, value, obj); },
-                           i.second);
-    } else {
-      doc.addRef(i.first, castVariant(i.second), obj);
-    }
-  }
-  return Status::success();
-}
-
-Status serializeRowJSON(const RowTyped& r, std::string& json, bool asNumeric) {
-  auto doc = JSON::newObject();
-  auto status = serializeRow(r, doc, doc.doc(), asNumeric);
-  if (!status.ok()) {
-    return status;
-  }
-  return doc.toString(json);
-}
-
-Status serializeRowJSON(const Row& r, std::string& json) {
-  auto doc = JSON::newObject();
-
-  // An empty column list will traverse the row map.
-  ColumnNames cols;
-  auto status = serializeRow(r, cols, doc, doc.doc());
-  if (!status.ok()) {
-    return status;
-  }
-  return doc.toString(json);
-}
-
-Status deserializeRow(const rj::Value& doc, Row& r) {
-  if (!doc.IsObject()) {
-    return Status(1);
-  }
-
-  for (const auto& i : doc.GetObject()) {
-    std::string name(i.name.GetString());
-    if (!name.empty() && i.value.IsString()) {
-      r[name] = i.value.GetString();
-    }
-  }
-  return Status::success();
-}
-
-Status deserializeRow(const rj::Value& doc, RowTyped& r) {
-  if (!doc.IsObject()) {
-    return Status(1);
-  }
-
-  for (const auto& i : doc.GetObject()) {
-    std::string name(i.name.GetString());
-    if (!name.empty()) {
-      if (i.value.IsString()) {
-        r[name] = i.value.GetString();
-      } else if (i.value.IsDouble()) {
-        r[name] = i.value.GetDouble();
-      } else if (i.value.IsInt64()) {
-        // Cast required for linux-x86_64
-        r[name] = (long long)i.value.GetInt64();
-      }
-    }
-  }
-  return Status::success();
-}
-
-Status deserializeRowJSON(const std::string& json, Row& r) {
-  auto doc = JSON::newObject();
-  if (!doc.fromString(json) || !doc.doc().IsObject()) {
-    return Status(1, "Cannot deserializing JSON");
-  }
-  return deserializeRow(doc.doc(), r);
-}
-
-Status deserializeRowJSON(const std::string& json, RowTyped& r) {
-  auto doc = JSON::newObject();
-  if (!doc.fromString(json) || !doc.doc().IsObject()) {
-    return Status(1, "Cannot deserializing JSON");
-  }
-  return deserializeRow(doc.doc(), r);
-}
-
-} // namespace osquery
index 3a05825..4b49500 100644 (file)
 #include <string>
 #include <vector>
 
-#include <boost/lexical_cast.hpp>
 #include <boost/variant.hpp>
 
-#include <osquery/utils/json/json.h>
-#include <osquery/utils/status/status.h>
-
 namespace osquery {
 
 /**
@@ -53,95 +49,4 @@ using RowTyped = std::map<std::string, RowDataTyped>;
  */
 using ColumnNames = std::vector<std::string>;
 
-/**
- * @brief Serialize a Row into a JSON document.
- *
- * @param r the Row to serialize.
- * @param cols the TableColumn vector indicating column order
- * @param doc the managed JSON document.
- * @param obj [output] the JSON object to assign values.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeRow(const Row& r,
-                    const ColumnNames& cols,
-                    JSON& doc,
-                    rapidjson::Value& obj);
-
-/**
- * @brief Serialize a RowTyped into a JSON document.
- *
- * @param r the RowTyped to serialize.
- * @param doc the managed JSON document.
- * @param obj [output] the JSON object to assign values.
- * @param asNumeric true iff numeric values are serialized as such
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeRow(const RowTyped& r,
-                    JSON& doc,
-                    rapidjson::Value& obj,
-                    bool asNumeric);
-
-/**
- * @brief Serialize a Row object into a JSON string.
- *
- * @param r the Row to serialize.
- * @param json [output] the output JSON string.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeRowJSON(const Row& r, std::string& json);
-
-/**
- * @brief Serialize a RowTyped object into a JSON string.
- *
- * @param r the Row to serialize.
- * @param json [output] the output JSON string.
- * @param asNumeric true iff numeric values are serialized as such
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeRowJSON(const RowTyped& r, std::string& json, bool asNumeric);
-
-/**
- * @brief Deserialize a Row object from JSON object.
- *
- * @param obj the input JSON value (should be an object).
- * @param r [output] the output Row structure.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status deserializeRow(const rapidjson::Value& obj, Row& r);
-
-/**
- * @brief Deserialize a RowTyped object from JSON object.
- *
- * @param obj the input JSON value (should be an object).
- * @param r [output] the output Row structure.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status deserializeRow(const rapidjson::Value& obj, RowTyped& r);
-
-/**
- * @brief Deserialize a Row object from a JSON string.
- *
- * @param json the input JSON string.
- * @param r [output] the output Row structure.
- *
- * @return Status indicating the success or failure of the operation
- */
-Status deserializeRowJSON(const std::string& json, Row& r);
-
-/**
- * @brief Deserialize a RowTyped object from a JSON string.
- *
- * @param json the input JSON string.
- * @param r [output] the output Row structure.
- *
- * @return Status indicating the success or failure of the operation
- */
-Status deserializeRowJSON(const std::string& json, RowTyped& r);
-
 } // namespace osquery
index ed92cb8..9b517c5 100644 (file)
 
 #include "row.h"
 
+#include <osquery/utils/status/status.h>
+
 #include <sqlite3.h>
 
+#include <vector>
+
 namespace osquery {
 
 class TableRow;
 
 using TableRowHolder = std::unique_ptr<TableRow>;
+using TableRows = std::vector<TableRowHolder>;
 
 /**
  * Interface for accessing a table row. Implementations may be backed by
@@ -41,11 +46,6 @@ class TableRow {
                          sqlite3_vtab* pVtab,
                          int col) = 0;
   /**
-   * Serialize this row as key,value pairs into the given JSON object.
-   */
-  virtual Status serialize(JSON& doc, rapidjson::Value& obj) const = 0;
-
-  /**
    * Clone this row.
    */
   virtual TableRowHolder clone() const = 0;
diff --git a/src/osquery/core/sql/table_rows.cpp b/src/osquery/core/sql/table_rows.cpp
deleted file mode 100644 (file)
index 740efeb..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include "table_rows.h"
-
-namespace rj = rapidjson;
-
-namespace osquery {
-
-Status serializeTableRows(const TableRows& rows, JSON& doc, rj::Document& arr) {
-  for (const auto& r : rows) {
-    auto row_obj = doc.getObject();
-    auto status = r->serialize(doc, row_obj);
-    if (!status.ok()) {
-      return status;
-    }
-    doc.push(row_obj, arr);
-  }
-  return Status::success();
-}
-
-Status serializeTableRowsJSON(const TableRows& rows, std::string& json) {
-  auto doc = JSON::newArray();
-
-  auto status = serializeTableRows(rows, doc, doc.doc());
-  if (!status.ok()) {
-    return status;
-  }
-  return doc.toString(json);
-}
-
-} // namespace osquery
diff --git a/src/osquery/core/sql/table_rows.h b/src/osquery/core/sql/table_rows.h
deleted file mode 100644 (file)
index 053b637..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <osquery/utils/json/json.h>
-
-#include "query_data.h"
-#include "table_row.h"
-
-namespace osquery {
-
-using TableRows = std::vector<TableRowHolder>;
-
-/**
- * @brief Serialize a TableRows object into a JSON array.
- *
- * @param rows the TableRows to serialize.
- * @param doc the managed JSON document.
- * @param arr [output] the output JSON array.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeTableRows(const TableRows& rows,
-                          JSON& doc,
-                          rapidjson::Document& arr);
-
-/**
- * @brief Serialize a TableRows object into a JSON string.
- *
- * @param rows the TableRows to serialize.
- * @param json [output] the output JSON string.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeTableRowsJSON(const TableRows& rows, std::string& json);
-
-/// Inverse of serializeTableRows, convert JSON to TableRows.
-Status deserializeTableRows(const rapidjson::Value& arr, TableRows& rows);
-
-/// Inverse of serializeTableRowsJSON, convert a JSON string to TableRows.
-Status deserializeTableRowsJSON(const std::string& json, TableRows& rows);
-
-} // namespace osquery
index 4404b7c..05b6158 100644 (file)
@@ -19,7 +19,6 @@
 #include <osquery/core.h>
 #include <osquery/core/sql/diff_results.h>
 #include <osquery/core/sql/scheduled_query.h>
-#include <osquery/utils/json/json.h>
 
 namespace osquery {
 
@@ -73,49 +72,6 @@ struct QueryLogItem {
 };
 
 /**
- * @brief Serialize a QueryLogItem object into a JSON document.
- *
- * @param item the QueryLogItem to serialize.
- * @param doc [output] the output JSON document (object type).
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeQueryLogItem(const QueryLogItem& item, JSON& doc);
-
-/**
- * @brief Serialize a QueryLogItem object into a JSON string.
- *
- * @param item the QueryLogItem to serialize.
- * @param json [output] the output JSON string.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status serializeQueryLogItemJSON(const QueryLogItem& item, std::string& json);
-
-/**
- * @brief Serialize a QueryLogItem object into a JSON document containing
- * events, a list of actions.
- *
- * @param item the QueryLogItem to serialize
- * @param json [output] the output JSON document.
- *
- * @return Status indicating the success or failure of the operation
- */
-Status serializeQueryLogItemAsEvents(const QueryLogItem& item, JSON& json);
-
-/**
- * @brief Serialize a QueryLogItem object into a JSON string of events,
- * a list of actions.
- *
- * @param i the QueryLogItem to serialize
- * @param items [output] vector of JSON output strings
- *
- * @return Status indicating the success or failure of the operation
- */
-Status serializeQueryLogItemAsEventsJSON(const QueryLogItem& i,
-                                         std::vector<std::string>& items);
-
-/**
  * @brief Interact with the historical on-disk storage for a given query.
  */
 class Query {
index 240a45e..a59cc70 100644 (file)
 #include <osquery/core/sql/column.h>
 #include <osquery/plugins/plugin.h>
 #include <osquery/query.h>
+#include <osquery/utils/json/json.h>
 
 #include <gtest/gtest_prod.h>
 
-/// Allow Tables to use "tracked" deprecated OS APIs.
-#define OSQUERY_USE_DEPRECATED(expr)                                           \
-  do {                                                                         \
-    _Pragma("clang diagnostic push") _Pragma(                                  \
-        "clang diagnostic ignored \"-Wdeprecated-declarations\"")(expr);       \
-    _Pragma("clang diagnostic pop")                                            \
-  } while (0)
-
 namespace osquery {
 
 class Status;
index c8a6813..fb2acff 100644 (file)
@@ -15,7 +15,6 @@
 #include <vist/logger.hpp>
 #include <osquery/registry.h>
 #include <osquery/utils/conversions/split.h>
-#include <osquery/utils/json/json.h>
 
 namespace osquery {
 
index a553f47..4ee27e1 100644 (file)
@@ -26,45 +26,6 @@ TableRows tableRowsFromQueryData(QueryData&& rows) {
   return result;
 }
 
-Status deserializeTableRows(const rj::Value& arr, TableRows& rows) {
-  if (!arr.IsArray()) {
-    return Status(1);
-  }
-
-  for (const auto& i : arr.GetArray()) {
-    auto r = make_table_row();
-    auto status = deserializeRow(i, r);
-    if (!status.ok()) {
-      return status;
-    }
-    rows.push_back(std::move(r));
-  }
-  return Status::success();
-}
-
-Status deserializeTableRowsJSON(const std::string& json, TableRows& rows) {
-  auto doc = JSON::newArray();
-  if (!doc.fromString(json) || !doc.doc().IsArray()) {
-    return Status(1, "Cannot deserializing JSON");
-  }
-
-  return deserializeTableRows(doc.doc(), rows);
-}
-
-Status deserializeRow(const rj::Value& doc, DynamicTableRowHolder& r) {
-  if (!doc.IsObject()) {
-    return Status(1);
-  }
-
-  for (const auto& i : doc.GetObject()) {
-    std::string name(i.name.GetString());
-    if (!name.empty() && i.value.IsString()) {
-      r[name] = i.value.GetString();
-    }
-  }
-  return Status::success();
-}
-
 int DynamicTableRow::get_rowid(sqlite_int64 default_value,
                                sqlite_int64* pRowid) const {
   auto& current_row = this->row;
@@ -143,14 +104,6 @@ int DynamicTableRow::get_column(sqlite3_context* ctx,
   return SQLITE_OK;
 }
 
-Status DynamicTableRow::serialize(JSON& doc, rj::Value& obj) const {
-  for (const auto& i : row) {
-    doc.addRef(i.first, i.second, obj);
-  }
-
-  return Status::success();
-}
-
 TableRowHolder DynamicTableRow::clone() const {
   Row new_row = row;
   return TableRowHolder(new DynamicTableRow(std::move(new_row)));
index e994873..7da1493 100644 (file)
@@ -8,9 +8,8 @@
 
 #pragma once
 
+#include <osquery/core/sql/query_data.h>
 #include <osquery/core/sql/table_row.h>
-#include <osquery/core/sql/table_rows.h>
-#include <osquery/utils/json/json.h>
 
 namespace osquery {
 
@@ -29,7 +28,6 @@ class DynamicTableRow : public TableRow {
   }
   virtual int get_rowid(sqlite_int64 default_value, sqlite_int64* pRowid) const;
   virtual int get_column(sqlite3_context* ctx, sqlite3_vtab* pVtab, int col);
-  virtual Status serialize(JSON& doc, rapidjson::Value& obj) const;
   virtual TableRowHolder clone() const;
   inline std::string& operator[](const std::string& key) {
     return row[key];
@@ -81,14 +79,4 @@ inline DynamicTableRowHolder make_table_row(
 /// generated code.
 TableRows tableRowsFromQueryData(QueryData&& rows);
 
-/**
- * @brief Deserialize a DynamicTableRow object from JSON object.
- *
- * @param obj the input JSON value (should be an object).
- * @param r [output] the output DynamicTableRowHolder structure.
- *
- * @return Status indicating the success or failure of the operation.
- */
-Status deserializeRow(const rapidjson::Value& doc, DynamicTableRowHolder& r);
-
 } // namespace osquery
index fb31540..4e32a2a 100644 (file)
@@ -27,14 +27,6 @@ class SQLTests : public testing::Test {
   }
 };
 
-
-TEST_F(SQLTests, test_raw_access) {
-  // Access to the table plugins (no SQL parsing required) works in both
-  // extensions and core, though with limitations on available tables.
-  auto results = SQL::selectAllFrom("time");
-  EXPECT_EQ(results.size(), 1U);
-}
-
 class TestTablePlugin : public TablePlugin {
  private:
   TableColumns columns() const {
index 4b35b8e..de26224 100644 (file)
@@ -63,13 +63,6 @@ TEST_F(SQLiteUtilTests, test_precision_is_maintained) {
   EXPECT_EQ(sql.rows()[0], r);
 }
 
-TEST_F(SQLiteUtilTests, test_simple_query_execution) {
-  // Access to the internal SQL implementation is only available in core.
-  auto sql = SQL("SELECT * FROM time");
-  EXPECT_TRUE(sql.ok());
-  EXPECT_EQ(sql.rows().size(), 1U);
-}
-
 TEST_F(SQLiteUtilTests, test_sqlite_instance_manager) {
   auto dbc1 = SQLiteDBManager::get();
   auto dbc2 = SQLiteDBManager::get();
@@ -139,13 +132,6 @@ TEST_F(SQLiteUtilTests, test_whitespace_query) {
   EXPECT_TRUE(status.ok());
 }
 
-TEST_F(SQLiteUtilTests, test_whitespace_then_nonwhitespace_query) {
-  auto dbc = getTestDBC();
-  QueryDataTyped results;
-  auto status = queryInternal("     ; select * from time  ", results, dbc);
-  EXPECT_TRUE(status.ok());
-}
-
 TEST_F(SQLiteUtilTests, test_get_test_db_result_stream) {
   auto dbc = getTestDBC();
   auto results = getTestDBResultStream();