/* * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ #pragma once #include #include namespace osquery { /** * @brief Run an interactive SQL query shell. * * @code{.cpp} * // Copyright 2004-present Facebook. All Rights Reserved. * #include * #include * * int main(int argc, char *argv[]) { * osquery::initOsquery(argc, argv); * return osquery::launchIntoShell(argc, argv); * } * @endcode * * @param argc the number of elements in argv * @param argv the command-line flags * * @return an int which represents the "return code" */ int launchIntoShell(int argc, char** argv); /** * @brief Generate a pretty representation of a QueryData object * * @return The beautified string representation of the supplied QueryData * @param order The order of the keys (since maps are unordered) */ std::string beautify(const QueryData& q, const std::vector& order); /** * @brief Pretty print a QueryData object * * This is a helper method which called osquery::beautify on the supplied * QueryData object and prints the results to stdout. * * @param q The QueryData object to print * @param order The order of the keys (since maps are unordered) */ void prettyPrint(const QueryData& q, const std::vector& order); /** * @brief JSON print a QueryData object * * This is a helper method which allows a shell or other tool to print results * in a JSON format. * * @param q The QueryData object to print */ void jsonPrint(const QueryData& q); /** * @brief Compute a map of metadata about the supplied QueryData object * * @param q The QueryData object to analyze * * @return A map of string to int such that the key represents the "column" in * the supplied QueryData and the int represents the length of the longest key */ std::map computeQueryDataLengths(const QueryData& q); /** * @brief Generate the separator string for query results * * @param lengths The data returned from computeQueryDataLengths * @param order The order of the keys (since maps are unordered) * * @return A string, with a newline, representing your separator */ std::string generateSeparator(const std::map& lengths, const std::vector& order); /** * @brief Generate the header string for query results * * @param lengths The data returned from computeQueryDataLengths * @param order The order of the keys (since maps are unordered) * * @return A string, with a newline, representing your header */ std::string generateHeader(const std::map& lengths, const std::vector& order); /** * @brief Generate a row string for query results * * @param lengths The data returned from computeQueryDataLengths * @param order The order of the keys (since maps are unordered) * * @return A string, with a newline, representing your row */ std::string generateRow(const Row& r, const std::map& lengths, const std::vector& order); }