Rename package to ViST
authorSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 21 Oct 2019 05:24:37 +0000 (14:24 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 21 Oct 2019 05:41:49 +0000 (14:41 +0900)
ViST(Virtual Security Table) is a security monitoring framework using SQL query

Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
79 files changed:
CMake/Macro.cmake
CMakeLists.txt
LICENSE-Apache-2.0 [new file with mode: 0644]
LICENSE-GPL-2.0 [new file with mode: 0644]
LICENSE-MIT [new file with mode: 0644]
MIT-LICENSE [deleted file]
README.md
packaging/osquery-plugins.manifest [deleted file]
packaging/osquery.manifest [deleted file]
packaging/osquery.spec [deleted file]
packaging/vist-plugins.manifest [new file with mode: 0644]
packaging/vist.manifest [new file with mode: 0644]
packaging/vist.spec [new file with mode: 0644]
src/CMakeLists.txt
src/apix/CMakeLists.txt [deleted file]
src/apix/ipc/CMakeLists.txt [deleted file]
src/apix/ipc/client.h [deleted file]
src/apix/ipc/server.h [deleted file]
src/apix/ipc/tests/ipc_tests.cpp [deleted file]
src/apix/main/tests.cpp [deleted file]
src/apix/manager/CMakeLists.txt [deleted file]
src/apix/manager/manager.cpp [deleted file]
src/apix/manager/manager_impl.cpp [deleted file]
src/apix/manager/manager_impl.h [deleted file]
src/apix/manager/tests/manager_tests.cpp [deleted file]
src/apix/manager/tests/policy_tests.cpp [deleted file]
src/apix/notification/CMakeLists.txt [deleted file]
src/apix/notification/notification.cpp [deleted file]
src/apix/notification/tests/notification_tests.cpp [deleted file]
src/apix/property/CMakeLists.txt [deleted file]
src/apix/property/property.cpp [deleted file]
src/apix/property/tests/property_tests.cpp [deleted file]
src/apix/tsqb/CMakeLists.txt [deleted file]
src/apix/tsqb/include/column-pack.hxx [deleted file]
src/apix/tsqb/include/column.hxx [deleted file]
src/apix/tsqb/include/condition.hxx [deleted file]
src/apix/tsqb/include/crud.hxx [deleted file]
src/apix/tsqb/include/database.hxx [deleted file]
src/apix/tsqb/include/expression.hxx [deleted file]
src/apix/tsqb/include/table-pack.hxx [deleted file]
src/apix/tsqb/include/table.hxx [deleted file]
src/apix/tsqb/include/tuple-helper.hxx [deleted file]
src/apix/tsqb/include/type.hxx [deleted file]
src/apix/tsqb/include/util.hxx [deleted file]
src/apix/tsqb/tests/tsqb-tests.cpp [deleted file]
src/apix/tsqb/tsqb.hxx [deleted file]
src/policyd/CMakeLists.txt
src/vist/CMakeLists.txt [new file with mode: 0644]
src/vist/ipc/CMakeLists.txt [new file with mode: 0644]
src/vist/ipc/client.h [new file with mode: 0644]
src/vist/ipc/server.h [new file with mode: 0644]
src/vist/ipc/tests/ipc_tests.cpp [new file with mode: 0644]
src/vist/main/tests.cpp [new file with mode: 0644]
src/vist/manager/CMakeLists.txt [new file with mode: 0644]
src/vist/manager/manager.cpp [new file with mode: 0644]
src/vist/manager/manager_impl.cpp [new file with mode: 0644]
src/vist/manager/manager_impl.h [new file with mode: 0644]
src/vist/manager/tests/manager_tests.cpp [new file with mode: 0644]
src/vist/manager/tests/policy_tests.cpp [new file with mode: 0644]
src/vist/notification/CMakeLists.txt [new file with mode: 0644]
src/vist/notification/notification.cpp [new file with mode: 0644]
src/vist/notification/tests/notification_tests.cpp [new file with mode: 0644]
src/vist/property/CMakeLists.txt [new file with mode: 0644]
src/vist/property/property.cpp [new file with mode: 0644]
src/vist/property/tests/property_tests.cpp [new file with mode: 0644]
src/vist/tsqb/CMakeLists.txt [new file with mode: 0644]
src/vist/tsqb/include/column-pack.hxx [new file with mode: 0644]
src/vist/tsqb/include/column.hxx [new file with mode: 0644]
src/vist/tsqb/include/condition.hxx [new file with mode: 0644]
src/vist/tsqb/include/crud.hxx [new file with mode: 0644]
src/vist/tsqb/include/database.hxx [new file with mode: 0644]
src/vist/tsqb/include/expression.hxx [new file with mode: 0644]
src/vist/tsqb/include/table-pack.hxx [new file with mode: 0644]
src/vist/tsqb/include/table.hxx [new file with mode: 0644]
src/vist/tsqb/include/tuple-helper.hxx [new file with mode: 0644]
src/vist/tsqb/include/type.hxx [new file with mode: 0644]
src/vist/tsqb/include/util.hxx [new file with mode: 0644]
src/vist/tsqb/tests/tsqb-tests.cpp [new file with mode: 0644]
src/vist/tsqb/tsqb.hxx [new file with mode: 0644]

index 4c9f0209bf0fad67d96510bde9b9a45de64d1c4e..580b6f104a97149e9694c7509cf39ef3e9d13477 100644 (file)
@@ -29,22 +29,22 @@ MACRO(ADD_OSQUERY_LINK)
        SET(${TARGET_OSQUERY_LIB}_DEPS ${${TARGET_OSQUERY_LIB}_DEPS} PARENT_SCOPE)
 ENDMACRO(ADD_OSQUERY_LINK)
 
-## apix  #####################
-MACRO(ADD_APIX_LIBRARY TARGET)
+## VIST  #####################
+MACRO(ADD_VIST_LIBRARY TARGET)
        ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
-       LIST(APPEND ${TARGET_APIX_LIB}_SRCS $<TARGET_OBJECTS:${TARGET}>)
-       SET(${TARGET_APIX_LIB}_SRCS ${${TARGET_APIX_LIB}_SRCS} PARENT_SCOPE)
-ENDMACRO(ADD_APIX_LIBRARY)
+       LIST(APPEND ${TARGET_VIST_LIB}_SRCS $<TARGET_OBJECTS:${TARGET}>)
+       SET(${TARGET_VIST_LIB}_SRCS ${${TARGET_VIST_LIB}_SRCS} PARENT_SCOPE)
+ENDMACRO(ADD_VIST_LIBRARY)
 
-MACRO(ADD_APIX_TEST)
-       LIST(APPEND ${TARGET_APIX_LIB}_TESTS ${ARGN})
-       SET(${TARGET_APIX_LIB}_TESTS ${${TARGET_APIX_LIB}_TESTS} PARENT_SCOPE)
-ENDMACRO(ADD_APIX_TEST)
+MACRO(ADD_VIST_TEST)
+       LIST(APPEND ${TARGET_VIST_LIB}_TESTS ${ARGN})
+       SET(${TARGET_VIST_LIB}_TESTS ${${TARGET_VIST_LIB}_TESTS} PARENT_SCOPE)
+ENDMACRO(ADD_VIST_TEST)
 
-MACRO(ADD_APIX_LINK)
-       LIST(APPEND ${TARGET_APIX_LIB}_DEPS ${ARGN})
-       SET(${TARGET_APIX_LIB}_DEPS ${${TARGET_APIX_LIB}_DEPS} PARENT_SCOPE)
-ENDMACRO(ADD_APIX_LINK)
+MACRO(ADD_VIST_LINK)
+       LIST(APPEND ${TARGET_VIST_LIB}_DEPS ${ARGN})
+       SET(${TARGET_VIST_LIB}_DEPS ${${TARGET_VIST_LIB}_DEPS} PARENT_SCOPE)
+ENDMACRO(ADD_VIST_LINK)
 
 ## policyd #####################
 MACRO(ADD_POLICYD_LIBRARY TARGET)
@@ -64,5 +64,3 @@ MACRO(TARGET_LINK_WHOLE TARGET LIBRARY)
        TARGET_LINK_LIBRARIES(${TARGET} ${LIBRARY})
        TARGET_LINK_LIBRARIES(${TARGET} "-Wl,-no-whole-archive")
 ENDMACRO(TARGET_LINK_WHOLE)
-
-
index 4e56ba1e5fd522fbc7e52cdfb2667282392620d4..ff2dedf199313c5612c3bf8d7dcd25a156860cba 100644 (file)
@@ -13,7 +13,7 @@
 #  limitations under the License
 
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-PROJECT(OSQUERY)
+PROJECT(vist)
 
 INCLUDE(GNUInstallDirs)
 INCLUDE(CMake/Macro.cmake)
@@ -39,8 +39,9 @@ ADD_DEFINITIONS("-fPIC")
 #ADD_DEFINITIONS("-pedantic")
 #ADD_DEFINITIONS("-pedantic-errors")
 
-# TODO(sangwan.kwon): Get version from packing spec.
-SET(OSQUERY_VERSION "4.0.0")
+IF(NOT DEFINED OSQUERY_VERSION)
+       SET(OSQUERY_VERSION "4.0.0")
+ENDIF(NOT DEFINED OSQUERY_VERSION)
 
 # Set various platform/platform-version/build version/etc defines.
 ADD_DEFINITIONS(-DLINUX="1"
@@ -59,7 +60,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/api")
 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src")
 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/tools/sqlite3")
 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src/osquery/include")
-INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src/apix/tsqb")
+INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src/vist/tsqb")
 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src/osquery/extensions/thrift/gen")
 INCLUDE_DIRECTORIES("/usr/local/include")
 
diff --git a/LICENSE-Apache-2.0 b/LICENSE-Apache-2.0
new file mode 100644 (file)
index 0000000..8dada3e
--- /dev/null
@@ -0,0 +1,201 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "{}"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright {yyyy} {name of copyright owner}
+
+   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.
diff --git a/LICENSE-GPL-2.0 b/LICENSE-GPL-2.0
new file mode 100644 (file)
index 0000000..d159169
--- /dev/null
@@ -0,0 +1,339 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644 (file)
index 0000000..7ccc161
--- /dev/null
@@ -0,0 +1,57 @@
+Tencent is pleased to support the open source community by making RapidJSON available. 
+Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.  All rights reserved.
+
+If you have downloaded a copy of the RapidJSON binary from Tencent, please note that the RapidJSON binary is licensed under the MIT License.
+If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms.  Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. To avoid the problematic JSON license in your own projects, it's sufficient to exclude the bin/jsonchecker/ directory, as it's the only code under the JSON license.
+A copy of the MIT License is included in this file.
+
+Other dependencies and licenses:
+
+Open Source Software Licensed Under the BSD License:
+--------------------------------------------------------------------
+
+The msinttypes r29 
+Copyright (c) 2006-2013 Alexander Chemeris 
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+* Neither the name of  copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Open Source Software Licensed Under the JSON License:
+--------------------------------------------------------------------
+
+json.org 
+Copyright (c) 2002 JSON.org
+All Rights Reserved.
+
+JSON_checker
+Copyright (c) 2002 JSON.org
+All Rights Reserved.
+
+       
+Terms of the JSON License:
+---------------------------------------------------
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+Terms of the MIT License:
+--------------------------------------------------------------------
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/MIT-LICENSE b/MIT-LICENSE
deleted file mode 100644 (file)
index 7ccc161..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-Tencent is pleased to support the open source community by making RapidJSON available. 
-Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.  All rights reserved.
-
-If you have downloaded a copy of the RapidJSON binary from Tencent, please note that the RapidJSON binary is licensed under the MIT License.
-If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms.  Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. To avoid the problematic JSON license in your own projects, it's sufficient to exclude the bin/jsonchecker/ directory, as it's the only code under the JSON license.
-A copy of the MIT License is included in this file.
-
-Other dependencies and licenses:
-
-Open Source Software Licensed Under the BSD License:
---------------------------------------------------------------------
-
-The msinttypes r29 
-Copyright (c) 2006-2013 Alexander Chemeris 
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
-* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-* Neither the name of  copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-Open Source Software Licensed Under the JSON License:
---------------------------------------------------------------------
-
-json.org 
-Copyright (c) 2002 JSON.org
-All Rights Reserved.
-
-JSON_checker
-Copyright (c) 2002 JSON.org
-All Rights Reserved.
-
-       
-Terms of the JSON License:
----------------------------------------------------
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-
-Terms of the MIT License:
---------------------------------------------------------------------
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
index 00744fb6bad5c83a4b3064f2dae6de1f9f146f41..642b4c04cf35d5e322c415cecf690944f687d607 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-# Osquery for Tizen
-> [Osquery](https://osquery.io/) is open-source project which means "Performant endpoint visibility".  
-> It can be used as security monitoring, audit, malware anaysis.
-
-We fork osquery and improve it for **device security which manages device-policy and auditing**.  
-The supporting elements can be extended like security analyzer, network security, kernel integrity.
+# ViST, Virtual Security Table
+ViST(Virtual Security Table) is a security monitoring framework using SQL query.
+- Provides APIs for monitoring and controlling security resources.
+- Views security resources as virtual tables and manipulates them through SQL queries.
+- Adopts a plug-in architecture and uses [osquery](https://osquery.io/) as the query analysis engine.
 
+# Architecture
 ![tizen-osquery-architecture](https://github.sec.samsung.net/storage/user/692/files/74819c00-4c95-11e9-9648-54e02513e338)
 
 # Advantages of tizen-osquery better than osquery
diff --git a/packaging/osquery-plugins.manifest b/packaging/osquery-plugins.manifest
deleted file mode 100644 (file)
index 017d22d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
-    <domain name="_"/>
- </request>
-</manifest>
diff --git a/packaging/osquery.manifest b/packaging/osquery.manifest
deleted file mode 100644 (file)
index 017d22d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
-    <domain name="_"/>
- </request>
-</manifest>
diff --git a/packaging/osquery.spec b/packaging/osquery.spec
deleted file mode 100644 (file)
index 870edd1..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-Name: osquery
-Version: 0.0.0
-Release: 0
-License: Apache-2.0 and GPLv2 and MIT
-Summary: A SQL powered operating system instrumentation, monitoring framework.
-Url: https://github.com/facebook/osquery
-Group: Security/Libraries
-Source0: file://%{name}-%{version}.tar.gz
-Source1: %name.manifest
-BuildRequires: gcc-c++
-BuildRequires: make
-BuildRequires: cmake
-# osquery BRs
-BuildRequires: glog-devel
-BuildRequires: gflags-devel
-BuildRequires: boost-devel
-BuildRequires: python-jinja2
-BuildRequires: libuuid-devel
-BuildRequires: pkgconfig(libprocps)
-BuildRequires: pkgconfig(libsystemd)
-BuildRequires: pkgconfig(openssl)
-# policyd BRs
-BuildRequires: pkgconfig(klay)
-BuildRequires: pkgconfig(libtzplatform-config)
-Requires: glog
-Requires: gflag
-Requires: boost-regex boost-system boost-thread boost-filesystem
-Requires: procps-ng
-Requires: libsystemd
-Requires: klay
-
-%global user_name   security_fw
-%global group_name  security_fw
-%global smack_label System
-
-%global ro_dir %{_datadir}
-%global rw_dir %{TZ_SYS_DATA}
-
-%global vist_ro_dir %{ro_dir}/vist
-%global vist_rw_dir %{rw_dir}/vist
-
-%global vist_db_dir     %{vist_rw_dir}/db
-%global vist_plugin_dir %{vist_ro_dir}/plugin
-%global vist_script_dir %{vist_ro_dir}/script
-
-%description
-Osquery exposes an operating system as a high-performance relational database.
-This allows you to write SQL-based queries to explore operating system data.
-
-%files
-%manifest %{name}.manifest
-%license MIT-LICENSE
-
-%prep
-%setup -q
-cp %SOURCE1 .
-
-%build
-%{!?build_type:%define build_type "RELEASE"}
-
-%if %{build_type} == "DEBUG" || %{build_type} == "PROFILING" || %{build_type} == "CCOV"
-       CFLAGS="$CFLAGS -Wp,-U_FORTIFY_SOURCE"
-       CXXFLAGS="$CXXFLAGS -Wp,-U_FORTIFY_SOURCE"
-%endif
-
-%cmake . -DCMAKE_BUILD_TYPE=%{build_type} \
-                -DOSQUERY_BUILD_VERSION=%{version} \
-                -DGBS_BUILD="TRUE" \
-                -DVERSION=%{version} \
-                -DUSER_NAME=%{user_name} \
-                -DGROUP_NAME=%{group_name} \
-                -DSMACK_LABEL=%{smack_label} \
-                -DDB_INSTALL_DIR:PATH=%{vist_db_dir} \
-                -DPLUGIN_INSTALL_DIR:PATH=%{vist_plugin_dir} \
-                -DSCRIPT_INSTALL_DIR:PATH=%{vist_script_dir}
-
-make %{?jobs:-j%jobs}
-
-%install
-%make_install
-mkdir -p %{buildroot}/%{vist_db_dir}
-mkdir -p %{buildroot}/%{vist_plugin_dir}
-mkdir -p %{buildroot}/%{vist_script_dir}
-
-cp data/script/*.sql %{buildroot}/%{vist_script_dir}
-
-%clean
-rm -rf %{buildroot}
-
-%files
-%manifest %{name}.manifest
-%{vist_script_dir}/*.sql
-%dir %attr(-, %{user_name}, %{group_name}) %{vist_db_dir}
-
-## Test Package ##############################################################
-%package test 
-Summary: Osquery test
-Group: Security/Testing
-BuildRequires: gtest-devel
-Requires: gtest
-
-%description test 
-Testcases for osquery 
-
-%files test
-%{_bindir}/osquery-test
-%{_bindir}/apix-test
-%{_bindir}/policyd-test
-
-## ViST Plugins - ###########################################################
-%package policyd-plugins
-Summary: ViST plugins
-Group: Security/Other
-## Common
-BuildRequires: pkgconfig(buxton2)
-BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(capi-system-info)
-BuildRequires: pkgconfig(capi-base-common)
-BuildRequires: pkgconfig(klay)
-
-## Bluetooth
-BuildRequires: pkgconfig(bluetooth-api)
-BuildRequires: pkgconfig(capi-network-bluetooth)
-
-## Wifi
-BuildRequires: pkgconfig(capi-network-wifi-manager)
-BuildRequires: pkgconfig(capi-network-connection)
-Requires: klay
-
-%description policyd-plugins
-Provides plugins for device policy manager
-
-%files policyd-plugins
-%manifest packaging/%{name}-plugins.manifest
-%{vist_plugin_dir}/bluetooth
-%{vist_plugin_dir}/wifi
diff --git a/packaging/vist-plugins.manifest b/packaging/vist-plugins.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/vist.manifest b/packaging/vist.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/vist.spec b/packaging/vist.spec
new file mode 100644 (file)
index 0000000..4a4ad7e
--- /dev/null
@@ -0,0 +1,140 @@
+Name: vist
+Version: 0.0.0
+Release: 0
+License: Apache-2.0 and GPLv2 and MIT
+Summary: ViST(Virtual Security Table) is a security monitoring framework using SQL query.
+Url: https://github.com/facebook/osquery
+Group: Security/Libraries
+Source0: file://%{name}-%{version}.tar.gz
+Source1: %name.manifest
+BuildRequires: gcc-c++
+BuildRequires: make
+BuildRequires: cmake
+# osquery BRs
+BuildRequires: glog-devel
+BuildRequires: gflags-devel
+BuildRequires: boost-devel
+BuildRequires: python-jinja2
+BuildRequires: libuuid-devel
+BuildRequires: pkgconfig(libprocps)
+BuildRequires: pkgconfig(libsystemd)
+BuildRequires: pkgconfig(openssl)
+# policyd BRs
+BuildRequires: pkgconfig(klay)
+BuildRequires: pkgconfig(libtzplatform-config)
+Requires: glog
+Requires: gflag
+Requires: boost-regex boost-system boost-thread boost-filesystem
+Requires: procps-ng
+Requires: libsystemd
+Requires: klay
+
+%global osquery_version 4.0.0
+
+%global user_name   security_fw
+%global group_name  security_fw
+%global smack_label System
+
+%global ro_dir %{_datadir}
+%global rw_dir %{TZ_SYS_DATA}
+
+%global vist_ro_dir %{ro_dir}/vist
+%global vist_rw_dir %{rw_dir}/vist
+
+%global vist_db_dir     %{vist_rw_dir}/db
+%global vist_plugin_dir %{vist_ro_dir}/plugin
+%global vist_script_dir %{vist_ro_dir}/script
+
+%description
+ViST provides APIs for monitoring and controlling security resources.
+ViST views security resources as virtual tables and manipulates them through SQL queries.
+ViST adopts a plug-in architecture and uses osquery as the query analysis engine.
+
+%prep
+%setup -q
+cp %SOURCE1 .
+
+%build
+%{!?build_type:%define build_type "RELEASE"}
+
+%if %{build_type} == "DEBUG" || %{build_type} == "PROFILING" || %{build_type} == "CCOV"
+       CFLAGS="$CFLAGS -Wp,-U_FORTIFY_SOURCE"
+       CXXFLAGS="$CXXFLAGS -Wp,-U_FORTIFY_SOURCE"
+%endif
+
+%cmake . -DCMAKE_BUILD_TYPE=%{build_type} \
+                -DVERSION=%{version} \
+                -DOSQUERY_VERSION=%{osquery_version} \
+                -DGBS_BUILD="TRUE" \
+                -DUSER_NAME=%{user_name} \
+                -DGROUP_NAME=%{group_name} \
+                -DSMACK_LABEL=%{smack_label} \
+                -DDB_INSTALL_DIR:PATH=%{vist_db_dir} \
+                -DPLUGIN_INSTALL_DIR:PATH=%{vist_plugin_dir} \
+                -DSCRIPT_INSTALL_DIR:PATH=%{vist_script_dir}
+
+make %{?jobs:-j%jobs}
+
+%install
+%make_install
+mkdir -p %{buildroot}/%{vist_db_dir}
+mkdir -p %{buildroot}/%{vist_plugin_dir}
+mkdir -p %{buildroot}/%{vist_script_dir}
+
+cp data/script/*.sql %{buildroot}/%{vist_script_dir}
+
+%clean
+rm -rf %{buildroot}
+
+%files
+%manifest %{name}.manifest
+%license LICENSE-Apache-2.0
+%license LICENSE-GPL-2.0
+%license LICENSE-MIT
+%{vist_script_dir}/*.sql
+%dir %attr(-, %{user_name}, %{group_name}) %{vist_db_dir}
+%dir %attr(-, %{user_name}, %{group_name}) %{vist_plugin_dir}
+%dir %attr(-, %{user_name}, %{group_name}) %{vist_script_dir}
+
+## Test Package ##############################################################
+%package test 
+Summary: Virtaul Security Table (unit test)
+Group: Security/Testing
+BuildRequires: gtest-devel
+Requires: gtest
+
+%description test 
+Provides internal testcases for ViST implementation.
+
+%files test
+%{_bindir}/osquery-test
+%{_bindir}/vist-test
+%{_bindir}/policyd-test
+
+## ViST Plugins - ###########################################################
+%package plugins
+Summary: Virtaul Security Table (policy modules)
+Group: Security/Other
+## Common
+BuildRequires: pkgconfig(buxton2)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(klay)
+
+## Bluetooth
+BuildRequires: pkgconfig(bluetooth-api)
+BuildRequires: pkgconfig(capi-network-bluetooth)
+
+## Wifi
+BuildRequires: pkgconfig(capi-network-wifi-manager)
+BuildRequires: pkgconfig(capi-network-connection)
+Requires: klay
+
+%description plugins
+Provides plugins for controlling policies.
+
+%files plugins
+%manifest packaging/%{name}-plugins.manifest
+%{vist_plugin_dir}/bluetooth
+%{vist_plugin_dir}/wifi
index 41df5eaa42c4a32f7b0791d1e7bb8b77be84f0a2..20794edda7b24b552ba63d7700623ea403bfa2dc 100644 (file)
 #  See the License for the specific language governing permissions and
 #  limitations under the License
 
-SET(TARGET_APIX_LIB apix)
 SET(TARGET_OSQUERY_LIB osquery)
 SET(TARGET_POLICYD_LIB policyd)
+SET(TARGET_VIST_LIB vist)
 
-ADD_SUBDIRECTORY(apix)
 ADD_SUBDIRECTORY(osquery)
+ADD_SUBDIRECTORY(vist)
 
 IF(DEFINED GBS_BUILD)
        ADD_SUBDIRECTORY(policyd)
diff --git a/src/apix/CMakeLists.txt b/src/apix/CMakeLists.txt
deleted file mode 100644 (file)
index ddde13c..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#  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
-
-SET(TARGET_APIX_TEST apix-test)
-
-SET(${TARGET_APIX_LIB}_SRCS "")
-SET(${TARGET_APIX_LIB}_DEPS "")
-SET(${TARGET_APIX_LIB}_TESTS "")
-
-ADD_SUBDIRECTORY(ipc)
-ADD_SUBDIRECTORY(manager)
-ADD_SUBDIRECTORY(notification)
-ADD_SUBDIRECTORY(property)
-
-ADD_LIBRARY(${TARGET_APIX_LIB} STATIC ${${TARGET_APIX_LIB}_SRCS})
-TARGET_LINK_LIBRARIES(${TARGET_APIX_LIB} ${${TARGET_APIX_LIB}_DEPS}
-                                                                                ${TARGET_OSQUERY_LIB})
-
-ADD_EXECUTABLE(${TARGET_APIX_TEST} main/tests.cpp
-                                                                  ${${TARGET_APIX_LIB}_TESTS})
-TARGET_LINK_LIBRARIES(${TARGET_APIX_TEST} ${TARGET_APIX_LIB}
-                                                                                  gtest)
-TARGET_LINK_WHOLE(${TARGET_APIX_TEST} ${TARGET_OSQUERY_LIB})
-ADD_TEST(${TARGET_APIX_TEST} ${TARGET_APIX_TEST})
-INSTALL(TARGETS ${TARGET_APIX_TEST}
-               DESTINATION ${CMAKE_INSTALL_BINDIR}
-               PERMISSIONS OWNER_READ
-                                       OWNER_WRITE
-                                       OWNER_EXECUTE
-                                       GROUP_READ
-                                       GROUP_EXECUTE
-                                       WORLD_READ
-                                       WORLD_EXECUTE)
diff --git a/src/apix/ipc/CMakeLists.txt b/src/apix/ipc/CMakeLists.txt
deleted file mode 100644 (file)
index 7fb5a77..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#  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(GLOB SERVER_TESTS "tests/*.cpp")
-ADD_APIX_TEST(${SERVER_TESTS})
diff --git a/src/apix/ipc/client.h b/src/apix/ipc/client.h
deleted file mode 100644 (file)
index ddf7a5c..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  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
- */
-
-#pragma once
-
-#include <string>
-#include <memory>
-
-#include <klay/rmi/client.h>
-
-namespace ipc {
-
-class Client final {
-public:
-       Client(const Client&) = delete;
-       Client& operator=(const Client&) = delete;
-
-       Client(Client&&) = delete;
-       Client& operator=(Client&&) = delete;
-
-       static std::unique_ptr<klay::rmi::Client>& Instance(const std::string& sock)
-       {
-               static Client client(sock);
-               return client.instance;
-       }
-
-private:
-       explicit Client(const std::string& sock) :
-               instance(std::make_unique<klay::rmi::Client>(sock))
-       {
-               instance->connect();
-       }
-       ~Client() = default;
-
-       std::unique_ptr<klay::rmi::Client> instance;
-};
-
-} // namespace ipc
diff --git a/src/apix/ipc/server.h b/src/apix/ipc/server.h
deleted file mode 100644 (file)
index 5bbcc49..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  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
- */
-
-#pragma once
-
-#include <string>
-#include <memory>
-
-#include <klay/rmi/service.h>
-
-namespace ipc {
-
-class Server final {
-public:
-       Server(const Server&) = delete;
-       Server& operator=(const Server&) = delete;
-
-       Server(Server&&) = delete;
-       Server& operator=(Server&&) = delete;
-
-       static std::unique_ptr<klay::rmi::Service>& Instance(const std::string& sock)
-       {
-               static Server server(sock);
-               return server.instance;
-       }
-
-private:
-       explicit Server(const std::string& sock) :
-               instance(std::make_unique<klay::rmi::Service>(sock)) {}
-       ~Server() = default;
-
-       std::unique_ptr<klay::rmi::Service> instance;
-};
-
-} // namespace ipc
diff --git a/src/apix/ipc/tests/ipc_tests.cpp b/src/apix/ipc/tests/ipc_tests.cpp
deleted file mode 100644 (file)
index 40b7451..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  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 "../server.h"
-#include "../client.h"
-
-#include <chrono>
-#include <thread>
-
-#include <sys/types.h>
-#include <unistd.h>
-
-using namespace ipc;
-
-namespace {
-       std::string g_socket = "/tmp/vist-test";
-
-       void init()
-       {
-       }
-
-} // anonymous namespace
-
-class TestServer {
-public:
-       void init()
-       {
-               auto& server = ipc::Server::Instance(g_socket);
-               server->expose(this, "", (std::string)(TestServer::testMethod)());
-               server->start();
-       }
-
-       std::string testMethod()
-       {
-               return "test";
-       }
-};
-
-class IpcTests : public testing::Test {
-public:
-       void SetUp() override
-       {
-               ::unlink(g_socket.c_str());
-
-               this->pid = fork();
-               if (pid < 0) {
-                       return;
-               } else if (pid == 0) {
-                       TestServer server;
-                       server.init();
-                       
-               }
-
-               std::this_thread::sleep_for(std::chrono::seconds(1));
-       }
-
-       void TearDown() override
-       {
-               if (::kill(pid, SIGTERM) == -1)
-                       return;
-
-               std::this_thread::sleep_for(std::chrono::seconds(1));
-       }
-
-private:
-       pid_t pid = -1;
-};
-
-TEST_F(IpcTests, method_call) {
-       auto& client = ipc::Client::Instance(g_socket);
-
-       std::string ret = client->methodCall<std::string>("TestServer::testMethod");
-       EXPECT_EQ(ret, "test");
-}
diff --git a/src/apix/main/tests.cpp b/src/apix/main/tests.cpp
deleted file mode 100644 (file)
index e249cbe..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <gtest/gtest.h>
-
-int main(int argc, char* argv[]) {
-  testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/src/apix/manager/CMakeLists.txt b/src/apix/manager/CMakeLists.txt
deleted file mode 100644 (file)
index 7c4cfac..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#  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_APIX_LIBRARY(manager manager.cpp
-                                                manager_impl.cpp)
-
-FILE(GLOB MANAGER_TESTS "tests/m*.cpp")
-ADD_APIX_TEST(${MANAGER_TESTS})
-
-IF(DEFINED GBS_BUILD)
-       FILE(GLOB POLICYD_TESTS "tests/p*.cpp")
-       ADD_APIX_TEST(${POLICYD_TESTS})
-ENDIF(DEFINED GBS_BUILD)
diff --git a/src/apix/manager/manager.cpp b/src/apix/manager/manager.cpp
deleted file mode 100644 (file)
index 020e5be..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  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 manager.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of osquery manager
- */
-
-#include <osquery_manager.h>
-
-#include "manager_impl.h"
-
-namespace osquery {
-
-Rows OsqueryManager::execute(const std::string& query)
-{
-       return ManagerImpl::instance().execute(query);
-}
-
-void OsqueryManager::subscribe(const std::string& table, const Callback& callback)
-{
-       return ManagerImpl::instance().subscribe(table, callback);
-}
-
-std::vector<std::string> OsqueryManager::columns(const std::string& table) noexcept
-{
-       return ManagerImpl::instance().columns(table);
-}
-
-} // namespace osquery
diff --git a/src/apix/manager/manager_impl.cpp b/src/apix/manager/manager_impl.cpp
deleted file mode 100644 (file)
index f0d1ee6..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *  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 ManagerImplied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-/*
- * @file manager_impl.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of osquery manager's impl
- */
-
-#include "manager_impl.h"
-
-#include <osquery/registry.h>
-#include <osquery/core.h>
-#include <osquery/filesystem/filesystem.h>
-#include <osquery/flags.h>
-#include <osquery/logger.h>
-#include <osquery/notification.h>
-#include <osquery/sql.h>
-#include <osquery/status.h>
-
-#include <gflags/gflags.h>
-
-#include <boost/filesystem/operations.hpp>
-
-#include <functional>
-#include <sstream>
-#include <tuple>
-
-namespace osquery {
-
-ManagerImpl::ManagerImpl()
-{
-       auto logDir = Flag::getValue("osquery_log_dir");
-       if (!logDir.empty() && !(pathExists(logDir).ok()))
-               boost::filesystem::create_directories(logDir);
-
-       LOG(INFO) << "Initalize osquery manager. ";
-
-       registryAndPluginInit();
-}
-
-ManagerImpl::~ManagerImpl() noexcept
-{
-       LOG(INFO) << "Shutdown osquery manager.";
-}
-
-ManagerImpl& ManagerImpl::instance()
-{
-       static ManagerImpl instance;
-       return instance;
-}
-
-Rows ManagerImpl::execute(const std::string& query)
-{
-       LOG(INFO) << "Execute query: " << query;
-       osquery::SQL sql(query, true);
-       if (!sql.ok()) {
-               LOG(ERROR) << "Executing query failed: " << sql.getMessageString();
-               return Rows();
-       }
-
-       return std::move(sql.rows());
-}
-
-void ManagerImpl::subscribe(const std::string& table, const Callback& callback)
-{
-       LOG(INFO) << "Subscribe event: " << table;
-
-       auto status = Notification::instance().add(table, callback);
-       if (!status.ok())
-               LOG(ERROR) << "Subscribing event failed: " << status.getCode();
-}
-
-std::vector<std::string> ManagerImpl::columns(const std::string& table) noexcept
-{
-       std::stringstream query;
-       query << "SELECT * FROM " << table;
-
-       TableColumns columns;
-       getQueryColumns(query.str(), columns);
-
-       // Extract column names
-       std::vector<std::string> names;
-       for (auto& c : columns)
-               names.emplace_back(std::move(std::get<0>(c)));
-
-       return names;
-}
-
-} // namespace osquery
diff --git a/src/apix/manager/manager_impl.h b/src/apix/manager/manager_impl.h
deleted file mode 100644 (file)
index 6867d9a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- *  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 ManagerImplied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-/*
- * @file manager_impl.h
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation interface of osquery manager
- */
-
-#pragma once
-
-#include <osquery_manager.h>
-
-#include <string>
-#include <vector>
-
-namespace osquery {
-
-/// Singleton class
-class ManagerImpl final {
-public:
-       ManagerImpl(const ManagerImpl&) = delete;
-       ManagerImpl& operator=(const ManagerImpl&) = delete;
-
-       ManagerImpl(ManagerImpl&&) noexcept = default;
-       ManagerImpl& operator=(ManagerImpl&&) noexcept = default;
-
-       static ManagerImpl& instance();
-
-       Rows execute(const std::string& query);
-       void subscribe(const std::string& table, const Callback& callback);
-
-       std::vector<std::string> columns(const std::string& table) noexcept;
-
-private:
-       ManagerImpl();
-       ~ManagerImpl() noexcept;
-};
-
-} // namespace osquery
diff --git a/src/apix/manager/tests/manager_tests.cpp b/src/apix/manager/tests/manager_tests.cpp
deleted file mode 100644 (file)
index 30cac9a..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- *  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_manager.h>
-
-#include <osquery/notification.h>
-#include <osquery/logger.h>
-
-using namespace osquery;
-
-class ManagerTests : public testing::Test {};
-
-TEST_F(ManagerTests, test_manager_execute) {
-       std::string query = "SELECT * FROM time";
-       auto rows = OsqueryManager::execute(query);
-       EXPECT_EQ(rows.size(), 1);
-
-       LOG(INFO) << "[Test] time table rows:";
-       LOG(INFO) << "\t hour: " << rows[0]["hour"];
-       LOG(INFO) << "\t minutes: " << rows[0]["minutes"];
-       LOG(INFO) << "\t seconds: " << rows[0]["seconds"];
-}
-
-TEST_F(ManagerTests, test_manager_subscribe) {
-       int called = 0;
-       auto callback = [&](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-               called++;
-       };
-
-       OsqueryManager::subscribe("manager_test", callback);
-
-       Row row;
-       row["foo"] = "bar";
-       row["foo2"] = "bar2";
-       row["foo3"] = "bar3";
-
-       /// Notification trigger
-       auto s = Notification::instance().emit("manager_test", row);
-
-       EXPECT_TRUE(s.ok());
-       EXPECT_EQ(called, 1);
-}
-
-TEST_F(ManagerTests, test_manager_columns) {
-       auto columns = OsqueryManager::columns("time");
-       EXPECT_TRUE(columns.size() > 0);
-
-       LOG(INFO) << "[Test] Enabled columns of time table:";
-       for (const auto& c : columns)
-               LOG(INFO) << "\t" << c;
-}
diff --git a/src/apix/manager/tests/policy_tests.cpp b/src/apix/manager/tests/policy_tests.cpp
deleted file mode 100644 (file)
index 18ab5f6..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *  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_manager.h>
-
-#include <osquery/logger.h>
-
-#include <policyd/core/policy-manager.h>
-
-using namespace osquery;
-
-class PolicydTests : public testing::Test {};
-
-TEST_F(PolicydTests, select) {
-       std::string query = "SELECT * FROM policy";
-       auto rows = OsqueryManager::execute(query);
-       EXPECT_TRUE(rows.size() > 0);
-
-       LOG(INFO) << "[Test] policy table rows:";
-       for (auto& r : rows) {
-               LOG(INFO) << "\t name: " << r["name"];
-               LOG(INFO) << "\t value: " << r["value"];
-       }
-
-       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       rows = OsqueryManager::execute(query);
-
-       LOG(INFO) << "[Test] policy table rows with where clause:";
-       for (auto& r : rows) {
-               LOG(INFO) << "\t name: " << r["name"];
-               LOG(INFO) << "\t value: " << r["value"];
-       }
-
-       EXPECT_EQ(rows.size(), 1);
-}
-
-TEST_F(PolicydTests, update) {
-       auto& manager = policyd::PolicyManager::Instance();
-       manager.enroll("admin", 0);
-
-       std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       auto rows = OsqueryManager::execute(query);
-       /// Initial policy value
-       EXPECT_EQ(rows[0]["value"], std::to_string(1));
-
-       query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
-       rows = OsqueryManager::execute(query);
-       EXPECT_EQ(rows.size(), 0);
-
-       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
-       rows = OsqueryManager::execute(query);
-       EXPECT_EQ(rows[0]["value"], std::to_string(3));
-
-       manager.disenroll("admin", 0);
-}
diff --git a/src/apix/notification/CMakeLists.txt b/src/apix/notification/CMakeLists.txt
deleted file mode 100644 (file)
index e466faa..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#  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_APIX_LIBRARY(apix_notification notification.cpp)
-
-FILE(GLOB NOTIFICATION_TESTS "tests/*.cpp")
-ADD_APIX_TEST(${NOTIFICATION_TESTS})
diff --git a/src/apix/notification/notification.cpp b/src/apix/notification/notification.cpp
deleted file mode 100644 (file)
index 9db0272..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *  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 notification.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of notification
- */
-
-#include <mutex>
-
-#include <osquery/notification.h>
-#include <osquery/logger.h>
-
-namespace {
-       std::mutex mutex;
-} // anonymous namespace
-
-namespace osquery {
-
-Notification& Notification::instance()
-{
-       static Notification notifier;
-       return notifier;
-}
-
-Status Notification::add(const std::string& table, const NotifyCallback& callback)
-{
-       if (table.empty())
-               return Status(1, "Wrong table name");
-
-       LOG(INFO) << "Add NotifyCallback to:" << table;
-       {
-               std::lock_guard<std::mutex> lock(mutex);
-               this->callbacks.insert(std::make_pair(table, callback));
-       }
-
-       return Status(0, "OK");
-}
-
-Status Notification::emit(const std::string& table, const Row& result) const
-{
-       if (table.empty())
-               return Status(1, "Wrong table name");
-
-       auto iter = this->callbacks.find(table);
-       if (iter == this->callbacks.end())
-               return Status(1, "Registered callback not found");
-
-       LOG(INFO) << "Emit notification about:" << table;
-       {
-               std::lock_guard<std::mutex> lock(mutex);
-               while (iter != this->callbacks.end())  {
-                       const auto& callback = iter->second;
-                       callback(result);
-                       iter++;
-               }
-       }
-
-       return Status(0, "OK");
-}
-
-} // namespace osquery
diff --git a/src/apix/notification/tests/notification_tests.cpp b/src/apix/notification/tests/notification_tests.cpp
deleted file mode 100644 (file)
index 721bbf1..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- *  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/notification.h>
-#include <osquery/logger.h>
-
-using namespace osquery;
-
-class NotificationTests : public testing::Test {};
-
-TEST_F(NotificationTests, test_add_positive) {
-       auto& notifier = Notification::instance();
-
-       auto callback = [](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-       };
-
-       auto s = notifier.add("test", std::move(callback));
-       EXPECT_TRUE(s.ok());
-}
-
-TEST_F(NotificationTests, test_add_negative) {
-       auto& notifier = Notification::instance();
-
-       auto callback = [](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-       };
-
-       auto s = notifier.add("", std::move(callback));
-       EXPECT_FALSE(s.ok());
-}
-
-TEST_F(NotificationTests, test_emit_positive) {
-       auto& notifier = Notification::instance();
-
-       int called = 0;
-       auto callback = [&](const Row& row) {
-               LOG(INFO) << "NotifyCallback called:";
-               for (const auto& r : row)
-                       LOG(INFO) << "\t" << r.first << " : " << r.second;
-               called++;
-       };
-
-       auto s = notifier.add("test2", std::move(callback));
-       EXPECT_TRUE(s.ok());
-
-       Row row;
-       row["foo"] = "bar";
-       s = notifier.emit("test2", row);
-
-       EXPECT_TRUE(s.ok());
-       EXPECT_EQ(called, 1);
-}
diff --git a/src/apix/property/CMakeLists.txt b/src/apix/property/CMakeLists.txt
deleted file mode 100644 (file)
index b4eeb79..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#  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_APIX_LIBRARY(property property.cpp)
-
-FILE(GLOB PROPERTY_TESTS "tests/*.cpp")
-ADD_APIX_TEST(${PROPERTY_TESTS})
diff --git a/src/apix/property/property.cpp b/src/apix/property/property.cpp
deleted file mode 100644 (file)
index cbff8eb..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *  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 <schema/processes.h>
-
-#include <osquery/logger.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 processes = make_table("processes",
-                                                       make_column("pid", &Processes::pid),
-                                                       make_column("name", &Processes::name),
-                                                       make_column("path", &Processes::path),
-                                                       make_column("cmdline", &Processes::cmdline),
-                                                       make_column("uid", &Processes::uid),
-                                                       make_column("gid", &Processes::gid),
-                                                       make_column("euid", &Processes::euid),
-                                                       make_column("egid", &Processes::egid),
-                                                       make_column("on_disk", &Processes::on_disk),
-                                                       make_column("parent", &Processes::parent));
-
-auto db = make_database("db", time, processes);
-
-} // 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>
-Property<T>::Property(KeyValuePair&& kvp) : data(std::move(kvp))
-{
-}
-
-template <typename T>
-template<typename Struct, typename Member>
-Member Property<T>::at(Member Struct::* field) const
-{
-       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.at(key);
-       if (value.empty()) {
-               LOG(ERROR) << "The value of key[" << key << "] is not exist.";
-               return Member();
-       }
-
-       try {
-               return boost::lexical_cast<Member>(value);
-       } catch (...) {
-               LOG(ERROR) << "Failed to casting [key]: " << key;
-               return Member();
-       }
-}
-
-template <typename T>
-template<typename Struct, typename Member>
-Member Property<T>::operator[](Member Struct::*field) const
-{
-       return this->at(field);
-}
-
-template <typename T>
-Properties<T>::Properties()
-{
-       auto results = OsqueryManager::execute(db.selectAll<T>());
-       for (auto& r : results)
-               this->datas.emplace_back(Property<T>(std::move(r)));
-}
-
-/// Explicit instantiation
-template class Property<Time>;
-template class Properties<Time>;
-template int Property<Time>::at(int Time::*) const;
-template int Property<Time>::operator[](int Time::*) const;
-
-template class Property<Processes>;
-template class Properties<Processes>;
-template int Property<Processes>::at(int Processes::*) const;
-template int Property<Processes>::operator[](int Processes::*) const;
-template long long int Property<Processes>::at(long long int Processes::*) const;
-template long long int Property<Processes>::operator[](long long int Processes::*) const;
-template std::string Property<Processes>::at(std::string Processes::*) const;
-template std::string Property<Processes>::operator[](std::string Processes::*) const;
-
-} // namespace osquery
diff --git a/src/apix/property/tests/property_tests.cpp b/src/apix/property/tests/property_tests.cpp
deleted file mode 100644 (file)
index 00a7e43..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- *  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>
-#include <schema/processes.h>
-
-using namespace osquery;
-
-class PropertyTests : public testing::Test {};
-
-TEST_F(PropertyTests, property) {
-       Time result = { -1, -1, -1 };
-
-       Property<Time> time;
-       result.hour = time.at(&Time::hour);
-       result.minutes = time.at(&Time::minutes);
-       result.seconds = time.at(&Time::seconds);
-
-       /// Once query execution
-       LOG(INFO) << "[Test] time table:";
-       LOG(INFO) << "\t hour: " << result.hour;
-       LOG(INFO) << "\t minutes: " << result.minutes;
-       LOG(INFO) << "\t seconds: " << result.seconds;
-
-       /// Each query execution
-       LOG(INFO) << "[Test] time table:";
-       LOG(INFO) << "\t hour: " << Property<Time>().at(&Time::hour);
-       LOG(INFO) << "\t minutes: " << Property<Time>().at(&Time::minutes);
-       LOG(INFO) << "\t seconds: " <<  Property<Time>().at(&Time::seconds);
-
-       EXPECT_NE(result.hour, -1);
-       EXPECT_NE(result.minutes, -1);
-       EXPECT_NE(result.seconds, -1);
-}
-
-TEST_F(PropertyTests, propertyArrayOp) {
-       Time result = { -1, -1, -1 };
-
-       Property<Time> time;
-       result.hour = time[&Time::hour];
-       result.minutes = time[&Time::minutes];
-       result.seconds = time[&Time::seconds];
-
-       /// Once query execution
-       LOG(INFO) << "[Test] time table:";
-       LOG(INFO) << "\t hour: " << result.hour;
-       LOG(INFO) << "\t minutes: " << result.minutes;
-       LOG(INFO) << "\t seconds: " << result.seconds;
-
-       EXPECT_NE(result.hour, -1);
-       EXPECT_NE(result.minutes, -1);
-       EXPECT_NE(result.seconds, -1);
-}
-
-TEST_F(PropertyTests, propertiesProcesses) {
-       Processes result;
-       Properties<Processes> processes;
-       EXPECT_TRUE(processes.size() > 0);
-
-       for(auto& p : processes) {
-               EXPECT_TRUE(p.size() > 0);
-               result.pid = p.at(&Processes::pid);
-               result.name = p.at(&Processes::name);
-               result.path = p.at(&Processes::path);
-               result.cmdline = p.at(&Processes::cmdline);
-               result.uid = p.at(&Processes::uid);
-               result.gid = p.at(&Processes::gid);
-               result.euid = p.at(&Processes::euid);
-               result.egid = p.at(&Processes::egid);
-               result.on_disk = p.at(&Processes::on_disk);
-               result.parent = p.at(&Processes::parent);
-
-               LOG(INFO) << "[Test] Processes table:";
-               LOG(INFO) << "\t pid: " << result.pid;
-               LOG(INFO) << "\t name: " << result.name;
-               LOG(INFO) << "\t path: " << result.path;
-               LOG(INFO) << "\t cmdline: " << result.cmdline;
-               LOG(INFO) << "\t uid: " << result.uid;
-               LOG(INFO) << "\t gid: " << result.gid;
-               LOG(INFO) << "\t euid: " << result.euid;
-               LOG(INFO) << "\t egid: " << result.egid;
-               LOG(INFO) << "\t on_disk: " << result.on_disk;
-               LOG(INFO) << "\t parent: " << result.parent;
-       }
-}
diff --git a/src/apix/tsqb/CMakeLists.txt b/src/apix/tsqb/CMakeLists.txt
deleted file mode 100644 (file)
index 2142f70..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#  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(GLOB TSQB_TESTS "tests/*.cpp")
-ADD_APIX_TEST(${TSQB_TESTS})
diff --git a/src/apix/tsqb/include/column-pack.hxx b/src/apix/tsqb/include/column-pack.hxx
deleted file mode 100644 (file)
index 9688e8e..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 column-pack.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Tie different types of columns
- */
-
-#pragma once
-
-#include "type.hxx"
-
-#include <string>
-#include <vector>
-
-namespace tsqb {
-namespace internal {
-
-template<typename... Base>
-class ColumnPack {
-public:
-       virtual ~ColumnPack() = default;
-
-       template<typename ColumnType>
-       std::string getName(ColumnType&&) const noexcept { return std::string(); }
-       std::vector<std::string> getNames(void) const noexcept { return {}; }
-
-       int size() const noexcept { return 0; }
-};
-
-template<typename Front, typename... Rest>
-class ColumnPack<Front, Rest...> : public ColumnPack<Rest...> {
-public:
-       using Column = Front;
-       using TableType = typename Column::TableType;
-
-       explicit ColumnPack(Front&& front, Rest&& ...rest);
-       virtual ~ColumnPack() = default;
-
-       ColumnPack(const ColumnPack&) = delete;
-       ColumnPack& operator=(const ColumnPack&) = delete;
-
-       ColumnPack(ColumnPack&&) = default;
-       ColumnPack& operator=(ColumnPack&&) = default;
-
-       template<typename ColumnType>
-       std::string getName(ColumnType&& type) const noexcept;
-       std::vector<std::string> getNames(void) const noexcept;
-
-       int size() const noexcept { return Base::size() + 1; }
-
-private:
-       using Base = ColumnPack<Rest...>;
-
-       Column column;
-};
-
-template<typename Front, typename... Rest>
-ColumnPack<Front, Rest...>::ColumnPack(Front&& front, Rest&& ...rest) :
-       Base(std::forward<Rest>(rest)...), column(front)
-{
-}
-
-template<typename Front, typename... Rest>
-std::vector<std::string> ColumnPack<Front, Rest...>::getNames(void) const noexcept
-{
-       auto names = Base::getNames();
-       names.push_back(this->column.name);
-
-       return std::move(names);
-}
-
-template<typename Front, typename... Rest>
-template<typename ColumnType>
-std::string ColumnPack<Front, Rest...>::getName(ColumnType&& type) const noexcept
-{
-       if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
-               return column.name;
-
-       return Base::template getName<ColumnType>(std::forward<ColumnType>(type));
-}
-
-} // namespace internal
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/column.hxx b/src/apix/tsqb/include/column.hxx
deleted file mode 100644 (file)
index ca17415..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 culumn.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Capture member pointer of struct and use it for matching with column
- */
-
-#pragma once
-
-#include <string>
-#include <tuple>
-
-namespace tsqb {
-
-template<typename Object, typename Field>
-struct Column {
-       using Type = Field Object::*;
-       using FieldType = Field;
-       using TableType = Object;
-
-       std::string name;
-       Type type;
-};
-
-template<typename O, typename F>
-Column<O, F> make_column(const std::string& name, F O::*field)
-{
-       return {name, field};
-}
-
-template<typename Type>
-struct Distinct {
-       Type value;
-};
-
-template<typename... Args>
-auto distinct(Args&&... args) -> decltype(Distinct<std::tuple<Args...>>())
-{
-       return {std::make_tuple(std::forward<Args>(args)...)};
-}
-
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/condition.hxx b/src/apix/tsqb/include/condition.hxx
deleted file mode 100644 (file)
index 7ec13da..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 condition.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the condition statement of SQL
- */
-
-#pragma once
-
-#include "type.hxx"
-
-namespace tsqb {
-namespace condition {
-
-struct Base {};
-
-template<typename L, typename R>
-struct And : public Base {
-       L l;
-       R r;
-
-       And(L l, R r) : l(l), r(r) {}
-       operator std::string() const
-       {
-               return "AND";
-       }
-};
-
-template<typename L, typename R>
-struct Or : public Base {
-       L l;
-       R r;
-
-       Or(L l, R r) : l(l), r(r) {}
-       operator std::string() const
-       {
-               return "OR";
-       }
-};
-
-template<typename L, typename R>
-struct Binary : public Base {
-       L l;
-       R r;
-
-       Binary(L l, R r) : l(l), r(r)
-       {
-               using FieldType = typename L::FieldType;
-               type::assert_compare(FieldType(), r);
-       }
-};
-
-template<typename L>
-struct Binary<L, const char*> : public Base {
-       L l;
-       std::string r;
-
-       Binary(L l, const char* r) : l(l), r(r)
-       {
-               using FieldType = typename L::FieldType;
-               type::assert_compare(FieldType(), std::string());
-       }
-};
-
-enum class Join : int {
-       INNER,
-       CROSS,
-       LEFT_OUTER,
-       RIGHT_OUTER,
-       FULL_OUTER
-};
-
-inline std::string to_string(Join type)
-{
-       switch (type) {
-       case Join::CROSS: return "CROSS";
-       case Join::LEFT_OUTER: return "LEFT OUTER";
-       case Join::RIGHT_OUTER: return "RIGHT OUTER";
-       case Join::FULL_OUTER: return "FULL OUTER";
-       case Join::INNER:
-       default:
-               return "INNER";
-       }
-}
-
-} // namespace condition
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/crud.hxx b/src/apix/tsqb/include/crud.hxx
deleted file mode 100644 (file)
index be48c86..0000000
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 crud.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent four basic functions of CRUD
- */
-
-#pragma once
-
-#include "column.hxx"
-#include "expression.hxx"
-
-#include <string>
-#include <sstream>
-
-namespace tsqb {
-
-template<typename T>
-class Crud {
-public:
-       template<typename... ColumnTypes>
-       T& select(ColumnTypes&&... cts);
-
-       template<typename Type>
-       T& select(Distinct<Type> distinct);
-
-       template<typename TableType>
-       T& selectAll(void);
-
-       T& selectAll(void);
-
-       template<typename... ColumnTypes>
-       T& update(ColumnTypes&&... cts);
-
-       template<typename... ColumnTypes>
-       T& insert(ColumnTypes&&... cts);
-
-       template<typename... ColumnTypes>
-       T& remove(ColumnTypes&&... cts);
-
-       template<typename Expr>
-       T& where(Expr expr);
-
-private:
-       template<typename ColumnTuple>
-       T& selectInternal(ColumnTuple&& ct, bool distinct = false);
-
-       template<typename L, typename R>
-       std::string processWhere(condition::And<L,R>& expr);
-
-       template<typename L, typename R>
-       std::string processWhere(condition::Or<L,R>& expr);
-
-       template<typename Expr>
-       std::string processWhere(Expr expr);
-};
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::select(ColumnTypes&&... cts)
-{
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-
-       return this->selectInternal(std::move(columnTuple));
-}
-
-template<typename T>
-template<typename Type>
-T& Crud<T>::select(Distinct<Type> distinct)
-{
-       return this->selectInternal(std::move(distinct.value), true);
-}
-
-template<typename T>
-T& Crud<T>::selectAll(void)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       std::stringstream ss;
-       ss << "SELECT * FROM " << static_cast<T*>(this)->name;
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename TableType>
-T& Crud<T>::selectAll(void)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       std::stringstream ss;
-       auto tableName = static_cast<T*>(this)->getTableName(TableType());
-       ss << "SELECT * FROM " << tableName;
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename ColumnTuple>
-T& Crud<T>::selectInternal(ColumnTuple&& ct, bool distinct)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(ct));
-       auto tableNames = static_cast<T*>(this)->getTableNames(std::move(ct));
-
-       std::stringstream ss;
-       ss << "SELECT ";
-
-       if (distinct)
-               ss << "DISTINCT ";
-
-       int i = 0;
-       for (const auto& c : columnNames) {
-               ss << c;
-
-               if (i++ < columnNames.size() - 1)
-                       ss << ", ";
-       }
-
-       ss << " FROM ";
-
-       i = 0;
-       for (const auto& t : tableNames) {
-               ss << t;
-
-               if (i++ < tableNames.size() - 1)
-                       ss << ", ";
-       }
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::update(ColumnTypes&&... cts)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
-
-       std::stringstream ss;
-       ss << "UPDATE " << static_cast<T*>(this)->name << " ";
-       ss << "SET ";
-
-       int i = 0;
-       for (const auto& c : columnNames) {
-               ss << c << " = ?";
-
-               if (i++ < columnNames.size() - 1)
-                       ss << ", ";
-       }
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::insert(ColumnTypes&&... cts)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
-
-       std::stringstream ss;
-       ss << "INSERT INTO " << static_cast<T*>(this)->name << " (";
-
-       const int columnCount = columnNames.size();
-       for (int i = 0; i < columnCount; i++) {
-               ss << columnNames[i];
-               if (i < columnCount - 1)
-                       ss << ", ";
-       }
-
-       ss << ") VALUES (";
-
-       for (int i = 0; i < columnCount; i++) {
-               ss << "?";
-               if (i < columnCount - 1)
-                       ss << ", ";
-       }
-
-       ss << ")";
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename... ColumnTypes>
-T& Crud<T>::remove(ColumnTypes&&... cts)
-{
-       static_cast<T*>(this)->cache.clear();
-
-       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
-       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
-
-       std::stringstream ss;
-       ss << "DELETE FROM " << static_cast<T*>(this)->name;
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename Expr>
-T& Crud<T>::where(Expr expr)
-{
-       std::stringstream ss;
-       ss << "WHERE " << this->processWhere(expr);
-
-       static_cast<T*>(this)->cache.emplace_back(ss.str());
-
-       return *(static_cast<T*>(this));
-}
-
-template<typename T>
-template<typename L, typename R>
-std::string Crud<T>::processWhere(condition::And<L,R>& expr)
-{
-       std::stringstream ss;
-       ss << this->processWhere(expr.l) << " ";
-       ss << static_cast<std::string>(expr) << " ";
-       ss << this->processWhere(expr.r);
-
-       return ss.str();
-}
-
-template<typename T>
-template<typename L, typename R>
-std::string Crud<T>::processWhere(condition::Or<L,R>& expr)
-{
-       std::stringstream ss;
-       ss << this->processWhere(expr.l) << " ";
-       ss << static_cast<std::string>(expr) << " ";
-       ss << this->processWhere(expr.r);
-
-       return ss.str();
-}
-
-template<typename T>
-template<typename Expr>
-std::string Crud<T>::processWhere(Expr expr)
-{
-       std::stringstream ss;
-       ss << static_cast<T*>(this)->getColumnName(expr.l.type);
-       ss << " " << std::string(expr) << " ?";
-
-       return ss.str();
-}
-
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/database.hxx b/src/apix/tsqb/include/database.hxx
deleted file mode 100644 (file)
index 0c8bf54..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 database.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the database scheme of SQL
- */
-
-#pragma once
-
-#include "crud.hxx"
-#include "condition.hxx"
-#include "expression.hxx"
-#include "table-pack.hxx"
-#include "tuple-helper.hxx"
-#include "util.hxx"
-
-#include <vector>
-#include <set>
-#include <string>
-#include <sstream>
-#include <algorithm>
-
-namespace tsqb {
-
-template<typename... Tables>
-class Database : public Crud<Database<Tables...>> {
-public:
-       using Self = Database<Tables...>;
-
-       virtual ~Database() = default;
-
-       Database(const Database&) = delete;
-       Database& operator=(const Database&) = delete;
-
-       Database(Database&&) = default;
-       Database& operator=(Database&&) = default;
-
-       // Functions for Crud
-       template<typename Cs>
-       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
-       template<typename Cs>
-       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
-       template<typename TableType>
-       std::string getTableName(TableType&& type) const noexcept;
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& type) const noexcept;
-
-       template<typename Table>
-       Self& join(condition::Join type = condition::Join::INNER);
-
-       template<typename Expr>
-       Self& on(Expr expr);
-
-       operator std::string();
-
-       std::string name;
-       std::vector<std::string> cache;
-
-private:
-       using TablePackType = internal::TablePack<Tables...>;
-       using ColumnNames = std::vector<std::string>;
-       using TableNames = std::set<std::string>;
-
-       explicit Database(const std::string& name, TablePackType&& tablePack);
-
-       template<typename ...Ts>
-       friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
-
-       struct GetTableNames {
-               const TablePackType& tablePack;
-               std::set<std::string> names;
-               GetTableNames(const TablePackType& tablePack) : tablePack(tablePack) {}
-
-               template <typename T>
-               void operator()(T&& type)
-               {
-                       auto column = make_column("anonymous", type);
-                       using TableType = typename decltype(column)::TableType;
-                       auto name = this->tablePack.getName(TableType());
-                       if (!name.empty())
-                               names.emplace(name);
-               }
-       };
-
-       struct GetColumnNames {
-               const TablePackType& tablePack;
-               std::vector<std::string> names;
-
-               GetColumnNames(const TablePackType& tablePack) : tablePack(tablePack) {}
-
-               template <typename T>
-               void operator()(T&& type)
-               {
-                       auto column = make_column("anonymous", type);
-                       auto name = this->tablePack.getColumnName(std::move(column));
-                       if (!name.empty())
-                               names.emplace_back(name);
-               }
-       };
-
-       TablePackType tablePack;
-};
-
-template<typename ...Tables>
-Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
-{
-       auto tablePack = internal::TablePack<Tables...>(std::forward<Tables>(tables)...);
-       return Database<Tables...>(name, std::move(tablePack));
-}
-
-template<typename ...Tables>
-Database<Tables...>::Database(const std::string& name, TablePackType&& tablePack)
-       : name(name), tablePack(std::move(tablePack)) {}
-
-template<typename... Tables>
-template<typename Table>
-Database<Tables...>& Database<Tables...>::join(condition::Join type)
-{
-       std::stringstream ss;
-       ss << condition::to_string(type) << " ";
-       ss << "JOIN ";
-       ss << this->tablePack.getName(Table());
-
-       this->cache.emplace_back(ss.str());
-       return *this;
-}
-
-template<typename... Tables>
-template<typename Expr>
-Database<Tables...>& Database<Tables...>::on(Expr expr)
-{
-       std::stringstream ss;
-       ss << "ON ";
-
-       auto lname = this->tablePack.getColumnName(std::move(expr.l));
-       ss << lname << " ";
-
-       ss << std::string(expr) << " ";
-
-       auto rname = this->tablePack.getColumnName(std::move(expr.r));
-       ss << rname;
-
-       this->cache.emplace_back(ss.str());
-       return *this;
-}
-
-template<typename... Tables>
-Database<Tables...>::operator std::string()
-{
-       std::stringstream ss;
-       for (const auto& c : cache)
-               ss << c << " ";
-
-       this->cache.clear();
-       return util::rtrim(ss.str());
-}
-
-template<typename... Tables>
-template<typename Cs>
-std::set<std::string> Database<Tables...>::getTableNames(Cs&& tuple) const noexcept
-{
-       GetTableNames closure(this->tablePack);
-       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
-
-       return closure.names;
-}
-
-template<typename... Tables>
-template<typename Cs>
-std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& tuple) const noexcept
-{
-       GetColumnNames closure(this->tablePack);
-       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
-
-       return closure.names;
-}
-
-template<typename... Tables>
-template<typename TableType>
-std::string Database<Tables...>::getTableName(TableType&& type) const noexcept
-{
-       return this->tablePack.getName(std::forward<TableType>(type));
-}
-
-template<typename... Tables>
-template<typename ColumnType>
-std::string Database<Tables...>::getColumnName(ColumnType&& type) const noexcept
-{
-       auto column = make_column("anonymous", type);
-       return this->tablePack.getColumnName(std::move(column));
-}
-
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/expression.hxx b/src/apix/tsqb/include/expression.hxx
deleted file mode 100644 (file)
index c901ab0..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 expression.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the expression of SQL
- */
-
-#pragma once
-
-#include "column.hxx"
-#include "type.hxx"
-#include "condition.hxx"
-
-#include <type_traits>
-
-namespace tsqb {
-
-template<typename Type>
-struct Expression {
-       Type value;
-};
-
-template<typename O, typename F>
-Expression<Column<O, F>> expr(F O::*field)
-{
-       Column<O, F> anonymous = {"anonymous", field};
-       return {anonymous};
-}
-
-template<typename L, typename R>
-struct Lesser : public condition::Binary<L, R> {
-       using condition::Binary<L, R>::Binary;
-
-       operator std::string() const
-       {
-               return "<";
-       }
-};
-
-template<typename L, typename R>
-Lesser<L, R> operator<(Expression<L> expr, R r)
-{
-       return {expr.value, r};
-}
-
-template<typename L, typename R>
-struct Equal : public condition::Binary<L, R>
-{
-       using condition::Binary<L, R>::Binary;
-
-       operator std::string() const
-       {
-               return "=";
-       }
-};
-
-template<typename L, typename R>
-Equal<L, R> operator==(Expression<L> expr, R r)
-{
-       return {expr.value, r};
-}
-
-namespace join {
-
-template<typename L, typename R>
-struct Equal
-{
-       L l;
-       R r;
-
-       operator std::string() const
-       {
-               return "=";
-       }
-};
-
-} // namespace join
-
-template<typename L, typename R>
-join::Equal<L, R> operator==(Expression<L> l, Expression<R> r)
-{
-       return {l.value, r.value};
-}
-
-template<typename L, typename R>
-struct Greater : public condition::Binary<L, R>
-{
-       using condition::Binary<L, R>::Binary;
-
-       operator std::string() const
-       {
-               return ">";
-       }
-};
-
-template<typename L, typename R>
-Greater<L, R> operator>(Expression<L> expr, R r)
-{
-       return {expr.value, r};
-}
-
-template<bool B, typename T = void>
-using enable_if_t = typename std::enable_if<B, T>::type;
-
-template<typename T>
-using is_condition = typename std::is_base_of<condition::Base, T>;
-
-template<typename L,
-                typename R,
-                typename = typename tsqb::enable_if_t<is_condition<L>::value
-                                                        && tsqb::is_condition<R>::value>>
-condition::And<L, R> operator&&(const L& l, const R& r)
-{
-       return {l, r};
-}
-
-template<typename L,
-                typename R,
-                typename = typename tsqb::enable_if_t<is_condition<L>::value
-                                                        && tsqb::is_condition<R>::value>>
-condition::Or<L, R> operator||(const L& l, const R& r)
-{
-       return {l, r};
-}
-
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/table-pack.hxx b/src/apix/tsqb/include/table-pack.hxx
deleted file mode 100644 (file)
index d192886..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 table-pack.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Tie diffirent types of tables
- */
-
-#pragma once
-
-#include <vector>
-#include <set>
-#include <string>
-
-namespace tsqb {
-namespace internal {
-
-template<typename... Base>
-class TablePack {
-public:
-       virtual ~TablePack() = default;
-
-       template<typename TableType>
-       std::string getName(TableType&&) const noexcept { return std::string(); }
-
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&&) const noexcept { return std::string(); }
-};
-
-template<typename Front, typename... Rest>
-class TablePack<Front, Rest...> : public TablePack<Rest...> {
-public:
-       using Table = Front;
-
-       explicit TablePack(Front&& front, Rest&& ...rest);
-       virtual ~TablePack() = default;
-
-       TablePack(const TablePack&) = delete;
-       TablePack& operator=(const TablePack&) = delete;
-
-       TablePack(TablePack&&) = default;
-       TablePack& operator=(TablePack&&) = default;
-
-       template<typename TableType>
-       std::string getName(TableType&& table) const noexcept;
-
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& column) const noexcept;
-
-private:
-       using Base = TablePack<Rest...>;
-
-       Table table;
-};
-
-template<typename Front, typename... Rest>
-TablePack<Front, Rest...>::TablePack(Front&& front, Rest&& ...rest) :
-       Base(std::forward<Rest>(rest)...), table(front)
-{
-}
-
-template<typename Front, typename... Rest>
-template<typename TableType>
-std::string TablePack<Front, Rest...>::getName(TableType&& table) const noexcept
-{
-       if (this->table.compare(table))
-               return this->table.name;
-
-       return Base::template getName<TableType>(std::forward<TableType>(table));
-}
-
-template<typename Front, typename... Rest>
-template<typename ColumnType>
-std::string TablePack<Front, Rest...>::getColumnName(ColumnType&& column) const noexcept
-{
-       using DecayColumnType = typename std::decay<ColumnType>::type;
-       using DecayTableType = typename DecayColumnType::TableType;
-       if (this->table.compare(DecayTableType())) {
-               auto cname = this->table.getColumnName(column.type);
-               return this->table.name + "." + cname;
-       }
-
-       return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(column));
-}
-
-} // namespace internal
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/table.hxx b/src/apix/tsqb/include/table.hxx
deleted file mode 100644 (file)
index e1ac527..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 table.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Represent the table of SQL
- */
-
-#pragma once
-
-#include "crud.hxx"
-#include "column.hxx"
-#include "column-pack.hxx"
-#include "tuple-helper.hxx"
-#include "util.hxx"
-
-#include <vector>
-#include <string>
-#include <sstream>
-
-namespace tsqb {
-
-template<typename... Columns>
-class Table : public Crud<Table<Columns...>> {
-public:
-       virtual ~Table() = default;
-
-       Table(const Table&) = delete;
-       Table& operator=(const Table&) = delete;
-
-       Table(Table&&) = default;
-       Table& operator=(Table&&) = default;
-
-       // Functions for Crud
-       template<typename Cs>
-       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
-       template<typename Cs>
-       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
-       template<typename That>
-       std::string getTableName(That&& type) const noexcept;
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& type) const noexcept;
-
-       std::vector<std::string> getColumnNames(void) const noexcept;
-
-       template<typename That>
-       bool compare(const That& that) const noexcept;
-
-       int size() const noexcept;
-
-       operator std::string();
-
-       std::string name;
-       std::vector<std::string> cache;
-
-private:
-       using ColumnPackType = internal::ColumnPack<Columns...>;
-       using TableType = typename ColumnPackType::TableType;
-
-       explicit Table(const std::string& name, ColumnPackType&& columnPack);
-
-       template<typename ...Cs>
-       friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
-
-       struct GetColumnNames {
-               const ColumnPackType& columnPack;
-               std::vector<std::string> names;
-
-               GetColumnNames(const ColumnPackType& columnPack) : columnPack(columnPack) {}
-
-               template <typename T>
-               void operator()(T&& type)
-               {
-                       auto name = this->columnPack.getName(std::forward<T>(type));
-                       if (!name.empty())
-                               names.emplace_back(name);
-               }
-       };
-
-       ColumnPackType columnPack;
-};
-
-template<typename ...Columns>
-Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
-{
-       auto columnPack = internal::ColumnPack<Columns...>(std::forward<Columns>(cs)...);
-       return Table<Columns...>(name, std::move(columnPack));
-}
-
-template<typename... Columns>
-Table<Columns...>::Table(const std::string& name, ColumnPackType&& columnPack)
-       : name(name), columnPack(std::move(columnPack)) {}
-
-template<typename... Columns>
-template<typename Cs>
-std::set<std::string> Table<Columns...>::getTableNames(Cs&& tuple) const noexcept
-{
-       return {this->name};
-}
-
-template<typename... Columns>
-template<typename Cs>
-std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple) const noexcept
-{
-       GetColumnNames closure(this->columnPack);
-       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
-
-       return closure.names;
-}
-
-template<typename... Columns>
-template<typename That>
-std::string Table<Columns...>::getTableName(That&& type) const noexcept
-{
-       return this->name;
-}
-
-template<typename... Columns>
-template<typename ColumnType>
-std::string Table<Columns...>::getColumnName(ColumnType&& type) const noexcept
-{
-       return this->columnPack.getName(std::forward<ColumnType>(type));
-}
-
-template<typename... Columns>
-std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
-{
-       return this->columnPack.getNames();
-}
-
-template<typename... Columns>
-template<typename That>
-bool Table<Columns...>::compare(const That& that) const noexcept
-{
-       using This = TableType;
-       return type::compare(This(), that);
-}
-
-template<typename... Columns>
-Table<Columns...>::operator std::string()
-{
-       std::stringstream ss;
-       for (const auto& c : cache)
-               ss << c << " ";
-
-       this->cache.clear();
-       return util::rtrim(ss.str());
-}
-
-template<typename... Columns>
-int Table<Columns...>::size() const noexcept
-{
-       return this->columnPack.size();
-}
-
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/tuple-helper.hxx b/src/apix/tsqb/include/tuple-helper.hxx
deleted file mode 100644 (file)
index 495946e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 tuple-helper.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Iterator method for tuple
- */
-
-#pragma once
-
-#include <tuple>
-
-namespace tsqb {
-namespace tuple_helper {
-namespace internal {
-
-template<int n, typename T, typename C>
-class Iterator {
-public:
-       Iterator(const T& tuple, C&& closure) {
-               Iterator<n - 1, T, C> iter(tuple, std::forward<C>(closure));
-               closure(std::get<n-1>(tuple));
-       }
-};
-
-template<typename T, typename C>
-class Iterator<0, T, C> {
-public:
-       Iterator(const T&, C&&) {}
-};
-
-} // namespace internal
-
-template<typename T, typename C>
-void for_each(const T& tuple, C&& closure)
-{
-       using Iter = internal::Iterator<std::tuple_size<T>::value, T, C>;
-       Iter iter(tuple, std::forward<C>(closure));
-}
-
-} // namspace tuple-hepler
-} // namspace tsqb
diff --git a/src/apix/tsqb/include/type.hxx b/src/apix/tsqb/include/type.hxx
deleted file mode 100644 (file)
index 939b3da..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 type.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Make type safety with compile time checking
- */
-
-#pragma once
-
-#include <type_traits>
-
-namespace tsqb {
-namespace type {
-
-template<typename L, typename R>
-bool cast_compare(L l, R r)
-{
-       return l == reinterpret_cast<L>(r);
-}
-
-template<typename L, typename R>
-bool compare(L l, R r)
-{
-       return std::is_same<L, R>::value;
-}
-
-template<typename L, typename R>
-void assert_compare(L l, R r)
-{
-       static_assert(std::is_same<L, R>::value, "Type is unsafe.");
-}
-
-} // namespace type
-} // namespace tsqb
diff --git a/src/apix/tsqb/include/util.hxx b/src/apix/tsqb/include/util.hxx
deleted file mode 100644 (file)
index e65583d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 util.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- */
-
-#pragma once
-
-#include <string>
-#include <algorithm>
-#include <cctype>
-
-namespace tsqb {
-namespace util {
-
-inline std::string rtrim(std::string&& s)
-{
-       auto predicate = [](unsigned char c){ return !std::isspace(c); };
-       auto base = std::find_if(s.rbegin(), s.rend(), predicate).base();
-       s.erase(base, s.end());
-       return s;
-}
-
-} // namespace util
-} // namespace tsqb
diff --git a/src/apix/tsqb/tests/tsqb-tests.cpp b/src/apix/tsqb/tests/tsqb-tests.cpp
deleted file mode 100644 (file)
index 7770140..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 tsqb-tests.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Testcases of tsqb
- */
-
-#include "tsqb.hxx"
-
-#include <gtest/gtest.h>
-
-using namespace tsqb;
-
-struct Admin {
-       int id;
-       std::string pkg;
-       int uid;
-       std::string key;
-       int removable;
-};
-
-struct ManagedPolicy {
-       int id;
-       int aid;
-       int pid;
-       int value;
-};
-
-struct PolicyDefinition {
-       int id;
-       int scope;
-       std::string name;
-       int ivalue;
-};
-
-auto admin = make_table("admin", make_column("id", &Admin::id),
-                                                                make_column("pkg", &Admin::pkg),
-                                                                make_column("uid", &Admin::uid),
-                                                                make_column("key", &Admin::key),
-                                                                make_column("removable", &Admin::removable));
-
-auto managedPolicy = make_table("managed_policy",
-                                                                make_column("id", &ManagedPolicy::id),
-                                                                make_column("aid", &ManagedPolicy::aid),
-                                                                make_column("pid", &ManagedPolicy::pid),
-                                                                make_column("value", &ManagedPolicy::value));
-
-auto policyDefinition = make_table("policy_definition",
-                                                                  make_column("id", &PolicyDefinition::id),
-                                                                  make_column("scope", &PolicyDefinition::scope),
-                                                                  make_column("name", &PolicyDefinition::name),
-                                                                  make_column("ivalue", &PolicyDefinition::ivalue));
-
-auto db = make_database("dpm", admin, managedPolicy, policyDefinition);
-
-class TsqbTests : public testing::Test {};
-
-TEST_F(TsqbTests, SELECT)
-{
-       std::string select1 = admin.select(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
-       std::string select2 = admin.select(&Admin::id, &Admin::uid, &Admin::key);
-
-       EXPECT_EQ(select1, "SELECT id, pkg, uid, key FROM admin");
-       EXPECT_EQ(select2, "SELECT id, uid, key FROM admin");
-}
-
-TEST_F(TsqbTests, SELECT_ALL)
-{
-       std::string select = admin.selectAll();
-
-       EXPECT_EQ(select, "SELECT * FROM admin");
-}
-
-TEST_F(TsqbTests, SELECT_WHERE)
-{
-       std::string select1 = admin.select(&Admin::uid, &Admin::key)
-                                                          .where(expr(&Admin::id) > 3);
-       std::string select2 = admin.selectAll().where(expr(&Admin::uid) > 3);
-       std::string select3 = admin.selectAll().where(expr(&Admin::uid) > 3 &&
-                                                                                                 expr(&Admin::pkg) == "dpm");
-       std::string select4 = admin.selectAll().where(expr(&Admin::uid) > 3 ||
-                                                                                                 expr(&Admin::pkg) == "dpm");
-
-       EXPECT_EQ(select1, "SELECT uid, key FROM admin WHERE id > ?");
-       EXPECT_EQ(select2, "SELECT * FROM admin WHERE uid > ?");
-       EXPECT_EQ(select3, "SELECT * FROM admin WHERE uid > ? AND pkg = ?");
-       EXPECT_EQ(select4, "SELECT * FROM admin WHERE uid > ? OR pkg = ?");
-}
-
-TEST_F(TsqbTests, SELECT_DISTINCT)
-{
-       std::string select = admin.select(distinct(&Admin::uid, &Admin::key))
-                                                          .where(expr(&Admin::id) > 3);
-
-       EXPECT_EQ(select, "SELECT DISTINCT uid, key FROM admin WHERE id > ?");
-}
-
-TEST_F(TsqbTests, UPDATE)
-{
-       int uid = 0, id = 1;
-       std::string update1 = admin.update(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
-       std::string update2 = admin.update(&Admin::key).where(expr(&Admin::uid) == uid &&
-                                                                                                                 expr(&Admin::id) == id);
-       std::string update3 = admin.update(&Admin::key, &Admin::pkg)
-                                                          .where(expr(&Admin::uid) == 0 && expr(&Admin::id) == 1);
-
-       EXPECT_EQ(update1, "UPDATE admin SET id = ?, pkg = ?, uid = ?, key = ?");
-       EXPECT_EQ(update2, "UPDATE admin SET key = ? WHERE uid = ? AND id = ?");
-       EXPECT_EQ(update3, "UPDATE admin SET key = ?, pkg = ? WHERE uid = ? AND id = ?");
-}
-
-TEST_F(TsqbTests, DELETE)
-{
-       std::string delete1 = admin.remove();
-       std::string delete2 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
-                                                                                          expr(&Admin::uid) == 3);
-
-       EXPECT_EQ(delete1, "DELETE FROM admin");
-       EXPECT_EQ(delete2, "DELETE FROM admin WHERE pkg = ? AND uid = ?");
-}
-
-TEST_F(TsqbTests, INSERT)
-{
-       std::string insert1 = admin.insert(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
-       std::string insert2 = admin.insert(&Admin::id, &Admin::pkg, &Admin::key);
-
-       EXPECT_EQ(insert1, "INSERT INTO admin (id, pkg, uid, key) VALUES (?, ?, ?, ?)");
-       EXPECT_EQ(insert2, "INSERT INTO admin (id, pkg, key) VALUES (?, ?, ?)");
-}
-
-TEST_F(TsqbTests, TYPE_SAFE)
-{
-/*
- * Below cause complie error since expression types are dismatch.
-
-       std::string type_unsafe1 = admin.selectAll().where(expr(&Admin::uid) > "dpm");
-       std::string type_unsafe2 = admin.selectAll().where(expr(&Admin::uid) == "dpm");
-       std::string type_unsafe3 = admin.selectAll().where(expr(&Admin::pkg) == 3);
-       int pkg = 3;
-       std::string type_unsafe4 = admin.selectAll().where(expr(&Admin::pkg) < pkg);
-       std::string type_unsafe5 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
-                                                                                                       expr(&Admin::uid) == "dpm");
-*/
-}
-
-TEST_F(TsqbTests, MULTI_SELECT)
-{
-       std::string multiSelect1 = db.select(&Admin::uid, &Admin::key,
-                                                                                &ManagedPolicy::id, &ManagedPolicy::value);
-       std::string multiSelect2 = db.select(&Admin::uid, &Admin::key,
-                                                                                &ManagedPolicy::id, &ManagedPolicy::value)
-                                                                .where(expr(&Admin::uid) > 0 && expr(&ManagedPolicy::id) == 3);
-
-       EXPECT_EQ(multiSelect1, "SELECT admin.uid, admin.key, managed_policy.id, "
-                                                       "managed_policy.value FROM admin, managed_policy");
-       EXPECT_EQ(multiSelect2, "SELECT admin.uid, admin.key, managed_policy.id, "
-                                                       "managed_policy.value FROM admin, managed_policy "
-                                                       "WHERE admin.uid > ? AND managed_policy.id = ?");
-}
-
-TEST_F(TsqbTests, JOIN)
-{
-       std::string join1 = db.select(&Admin::uid, &Admin::key)
-                                                 .join<PolicyDefinition>(condition::Join::LEFT_OUTER);
-       std::string join2 = db.select(&Admin::uid, &Admin::key)
-                                                 .join<ManagedPolicy>(condition::Join::CROSS);
-       std::string join3 = db.select(&ManagedPolicy::value)
-                                                 .join<PolicyDefinition>()
-                                                 .on(expr(&ManagedPolicy::pid) == expr(&PolicyDefinition::id))
-                                                 .join<Admin>()
-                                                 .on(expr(&ManagedPolicy::aid) == expr(&Admin::id))
-                                                 .where(expr(&ManagedPolicy::pid) == 99);
-
-       EXPECT_EQ(join1, "SELECT admin.uid, admin.key FROM admin "
-                                        "LEFT OUTER JOIN policy_definition");
-       EXPECT_EQ(join2, "SELECT admin.uid, admin.key FROM admin "
-                                        "CROSS JOIN managed_policy");
-       EXPECT_EQ(join3, "SELECT managed_policy.value FROM managed_policy "
-                                        "INNER JOIN policy_definition "
-                                        "ON managed_policy.pid = policy_definition.id "
-                                        "INNER JOIN admin ON managed_policy.aid = admin.id "
-                                        "WHERE managed_policy.pid = ?");
-}
diff --git a/src/apix/tsqb/tsqb.hxx b/src/apix/tsqb/tsqb.hxx
deleted file mode 100644 (file)
index c3791f0..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  Copyright (c) 2017-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.
- *  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 tsqb.hxx
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief TSQB is type-safe query builder
- */
-
-#pragma once
-
-#include "include/database.hxx"
-#include "include/table.hxx"
-#include "include/column.hxx"
-#include "include/expression.hxx"
-#include "include/condition.hxx"
-#include "include/util.hxx"
index db86726d53c45bdae1aa75b44fbccee7869ce1d1..e148a03d9b8ab5ba9812a752cc46ab3eb102bd5a 100644 (file)
@@ -38,7 +38,7 @@ TARGET_LINK_LIBRARIES(${TARGET_POLICYD_LIB} ${POLICYD_DEPS_LIBRARIES} pthread dl
 SET_TARGET_PROPERTIES(${TARGET_POLICYD_LIB} PROPERTIES COMPILE_FLAGS "-fPIE")
 SET_TARGET_PROPERTIES(${TARGET_POLICYD_LIB} PROPERTIES LINK_FLAGS "-pie")
 
-ADD_EXECUTABLE(${TARGET_POLICYD_TEST} ../apix/main/tests.cpp
+ADD_EXECUTABLE(${TARGET_POLICYD_TEST} ../vist/main/tests.cpp
                                                                          ${${TARGET_POLICYD_LIB}_TESTS})
 
 TARGET_LINK_LIBRARIES(${TARGET_POLICYD_TEST} ${TARGET_POLICYD_LIB}
diff --git a/src/vist/CMakeLists.txt b/src/vist/CMakeLists.txt
new file mode 100644 (file)
index 0000000..203118a
--- /dev/null
@@ -0,0 +1,44 @@
+#  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
+
+SET(TARGET_VIST_TEST vist-test)
+
+SET(${TARGET_VIST_LIB}_SRCS "")
+SET(${TARGET_VIST_LIB}_DEPS "")
+SET(${TARGET_VIST_LIB}_TESTS "")
+
+ADD_SUBDIRECTORY(ipc)
+ADD_SUBDIRECTORY(manager)
+ADD_SUBDIRECTORY(notification)
+ADD_SUBDIRECTORY(property)
+
+ADD_LIBRARY(${TARGET_VIST_LIB} STATIC ${${TARGET_VIST_LIB}_SRCS})
+TARGET_LINK_LIBRARIES(${TARGET_VIST_LIB} ${${TARGET_VIST_LIB}_DEPS}
+                                                                                ${TARGET_OSQUERY_LIB})
+
+ADD_EXECUTABLE(${TARGET_VIST_TEST} main/tests.cpp
+                                                                  ${${TARGET_VIST_LIB}_TESTS})
+TARGET_LINK_LIBRARIES(${TARGET_VIST_TEST} ${TARGET_VIST_LIB}
+                                                                                  gtest)
+TARGET_LINK_WHOLE(${TARGET_VIST_TEST} ${TARGET_OSQUERY_LIB})
+ADD_TEST(${TARGET_VIST_TEST} ${TARGET_VIST_TEST})
+INSTALL(TARGETS ${TARGET_VIST_TEST}
+               DESTINATION ${CMAKE_INSTALL_BINDIR}
+               PERMISSIONS OWNER_READ
+                                       OWNER_WRITE
+                                       OWNER_EXECUTE
+                                       GROUP_READ
+                                       GROUP_EXECUTE
+                                       WORLD_READ
+                                       WORLD_EXECUTE)
diff --git a/src/vist/ipc/CMakeLists.txt b/src/vist/ipc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..68418d1
--- /dev/null
@@ -0,0 +1,16 @@
+#  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(GLOB SERVER_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${SERVER_TESTS})
diff --git a/src/vist/ipc/client.h b/src/vist/ipc/client.h
new file mode 100644 (file)
index 0000000..ddf7a5c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+
+#include <klay/rmi/client.h>
+
+namespace ipc {
+
+class Client final {
+public:
+       Client(const Client&) = delete;
+       Client& operator=(const Client&) = delete;
+
+       Client(Client&&) = delete;
+       Client& operator=(Client&&) = delete;
+
+       static std::unique_ptr<klay::rmi::Client>& Instance(const std::string& sock)
+       {
+               static Client client(sock);
+               return client.instance;
+       }
+
+private:
+       explicit Client(const std::string& sock) :
+               instance(std::make_unique<klay::rmi::Client>(sock))
+       {
+               instance->connect();
+       }
+       ~Client() = default;
+
+       std::unique_ptr<klay::rmi::Client> instance;
+};
+
+} // namespace ipc
diff --git a/src/vist/ipc/server.h b/src/vist/ipc/server.h
new file mode 100644 (file)
index 0000000..5bbcc49
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  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
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+
+#include <klay/rmi/service.h>
+
+namespace ipc {
+
+class Server final {
+public:
+       Server(const Server&) = delete;
+       Server& operator=(const Server&) = delete;
+
+       Server(Server&&) = delete;
+       Server& operator=(Server&&) = delete;
+
+       static std::unique_ptr<klay::rmi::Service>& Instance(const std::string& sock)
+       {
+               static Server server(sock);
+               return server.instance;
+       }
+
+private:
+       explicit Server(const std::string& sock) :
+               instance(std::make_unique<klay::rmi::Service>(sock)) {}
+       ~Server() = default;
+
+       std::unique_ptr<klay::rmi::Service> instance;
+};
+
+} // namespace ipc
diff --git a/src/vist/ipc/tests/ipc_tests.cpp b/src/vist/ipc/tests/ipc_tests.cpp
new file mode 100644 (file)
index 0000000..40b7451
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ *  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 "../server.h"
+#include "../client.h"
+
+#include <chrono>
+#include <thread>
+
+#include <sys/types.h>
+#include <unistd.h>
+
+using namespace ipc;
+
+namespace {
+       std::string g_socket = "/tmp/vist-test";
+
+       void init()
+       {
+       }
+
+} // anonymous namespace
+
+class TestServer {
+public:
+       void init()
+       {
+               auto& server = ipc::Server::Instance(g_socket);
+               server->expose(this, "", (std::string)(TestServer::testMethod)());
+               server->start();
+       }
+
+       std::string testMethod()
+       {
+               return "test";
+       }
+};
+
+class IpcTests : public testing::Test {
+public:
+       void SetUp() override
+       {
+               ::unlink(g_socket.c_str());
+
+               this->pid = fork();
+               if (pid < 0) {
+                       return;
+               } else if (pid == 0) {
+                       TestServer server;
+                       server.init();
+                       
+               }
+
+               std::this_thread::sleep_for(std::chrono::seconds(1));
+       }
+
+       void TearDown() override
+       {
+               if (::kill(pid, SIGTERM) == -1)
+                       return;
+
+               std::this_thread::sleep_for(std::chrono::seconds(1));
+       }
+
+private:
+       pid_t pid = -1;
+};
+
+TEST_F(IpcTests, method_call) {
+       auto& client = ipc::Client::Instance(g_socket);
+
+       std::string ret = client->methodCall<std::string>("TestServer::testMethod");
+       EXPECT_EQ(ret, "test");
+}
diff --git a/src/vist/main/tests.cpp b/src/vist/main/tests.cpp
new file mode 100644 (file)
index 0000000..e249cbe
--- /dev/null
@@ -0,0 +1,6 @@
+#include <gtest/gtest.h>
+
+int main(int argc, char* argv[]) {
+  testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}
diff --git a/src/vist/manager/CMakeLists.txt b/src/vist/manager/CMakeLists.txt
new file mode 100644 (file)
index 0000000..41b6d57
--- /dev/null
@@ -0,0 +1,24 @@
+#  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_VIST_LIBRARY(manager manager.cpp
+                                                manager_impl.cpp)
+
+FILE(GLOB MANAGER_TESTS "tests/m*.cpp")
+ADD_VIST_TEST(${MANAGER_TESTS})
+
+IF(DEFINED GBS_BUILD)
+       FILE(GLOB POLICYD_TESTS "tests/p*.cpp")
+       ADD_VIST_TEST(${POLICYD_TESTS})
+ENDIF(DEFINED GBS_BUILD)
diff --git a/src/vist/manager/manager.cpp b/src/vist/manager/manager.cpp
new file mode 100644 (file)
index 0000000..020e5be
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  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 manager.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Implementation of osquery manager
+ */
+
+#include <osquery_manager.h>
+
+#include "manager_impl.h"
+
+namespace osquery {
+
+Rows OsqueryManager::execute(const std::string& query)
+{
+       return ManagerImpl::instance().execute(query);
+}
+
+void OsqueryManager::subscribe(const std::string& table, const Callback& callback)
+{
+       return ManagerImpl::instance().subscribe(table, callback);
+}
+
+std::vector<std::string> OsqueryManager::columns(const std::string& table) noexcept
+{
+       return ManagerImpl::instance().columns(table);
+}
+
+} // namespace osquery
diff --git a/src/vist/manager/manager_impl.cpp b/src/vist/manager/manager_impl.cpp
new file mode 100644 (file)
index 0000000..f0d1ee6
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  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 ManagerImplied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file manager_impl.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Implementation of osquery manager's impl
+ */
+
+#include "manager_impl.h"
+
+#include <osquery/registry.h>
+#include <osquery/core.h>
+#include <osquery/filesystem/filesystem.h>
+#include <osquery/flags.h>
+#include <osquery/logger.h>
+#include <osquery/notification.h>
+#include <osquery/sql.h>
+#include <osquery/status.h>
+
+#include <gflags/gflags.h>
+
+#include <boost/filesystem/operations.hpp>
+
+#include <functional>
+#include <sstream>
+#include <tuple>
+
+namespace osquery {
+
+ManagerImpl::ManagerImpl()
+{
+       auto logDir = Flag::getValue("osquery_log_dir");
+       if (!logDir.empty() && !(pathExists(logDir).ok()))
+               boost::filesystem::create_directories(logDir);
+
+       LOG(INFO) << "Initalize osquery manager. ";
+
+       registryAndPluginInit();
+}
+
+ManagerImpl::~ManagerImpl() noexcept
+{
+       LOG(INFO) << "Shutdown osquery manager.";
+}
+
+ManagerImpl& ManagerImpl::instance()
+{
+       static ManagerImpl instance;
+       return instance;
+}
+
+Rows ManagerImpl::execute(const std::string& query)
+{
+       LOG(INFO) << "Execute query: " << query;
+       osquery::SQL sql(query, true);
+       if (!sql.ok()) {
+               LOG(ERROR) << "Executing query failed: " << sql.getMessageString();
+               return Rows();
+       }
+
+       return std::move(sql.rows());
+}
+
+void ManagerImpl::subscribe(const std::string& table, const Callback& callback)
+{
+       LOG(INFO) << "Subscribe event: " << table;
+
+       auto status = Notification::instance().add(table, callback);
+       if (!status.ok())
+               LOG(ERROR) << "Subscribing event failed: " << status.getCode();
+}
+
+std::vector<std::string> ManagerImpl::columns(const std::string& table) noexcept
+{
+       std::stringstream query;
+       query << "SELECT * FROM " << table;
+
+       TableColumns columns;
+       getQueryColumns(query.str(), columns);
+
+       // Extract column names
+       std::vector<std::string> names;
+       for (auto& c : columns)
+               names.emplace_back(std::move(std::get<0>(c)));
+
+       return names;
+}
+
+} // namespace osquery
diff --git a/src/vist/manager/manager_impl.h b/src/vist/manager/manager_impl.h
new file mode 100644 (file)
index 0000000..6867d9a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  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 ManagerImplied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file manager_impl.h
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Implementation interface of osquery manager
+ */
+
+#pragma once
+
+#include <osquery_manager.h>
+
+#include <string>
+#include <vector>
+
+namespace osquery {
+
+/// Singleton class
+class ManagerImpl final {
+public:
+       ManagerImpl(const ManagerImpl&) = delete;
+       ManagerImpl& operator=(const ManagerImpl&) = delete;
+
+       ManagerImpl(ManagerImpl&&) noexcept = default;
+       ManagerImpl& operator=(ManagerImpl&&) noexcept = default;
+
+       static ManagerImpl& instance();
+
+       Rows execute(const std::string& query);
+       void subscribe(const std::string& table, const Callback& callback);
+
+       std::vector<std::string> columns(const std::string& table) noexcept;
+
+private:
+       ManagerImpl();
+       ~ManagerImpl() noexcept;
+};
+
+} // namespace osquery
diff --git a/src/vist/manager/tests/manager_tests.cpp b/src/vist/manager/tests/manager_tests.cpp
new file mode 100644 (file)
index 0000000..30cac9a
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  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_manager.h>
+
+#include <osquery/notification.h>
+#include <osquery/logger.h>
+
+using namespace osquery;
+
+class ManagerTests : public testing::Test {};
+
+TEST_F(ManagerTests, test_manager_execute) {
+       std::string query = "SELECT * FROM time";
+       auto rows = OsqueryManager::execute(query);
+       EXPECT_EQ(rows.size(), 1);
+
+       LOG(INFO) << "[Test] time table rows:";
+       LOG(INFO) << "\t hour: " << rows[0]["hour"];
+       LOG(INFO) << "\t minutes: " << rows[0]["minutes"];
+       LOG(INFO) << "\t seconds: " << rows[0]["seconds"];
+}
+
+TEST_F(ManagerTests, test_manager_subscribe) {
+       int called = 0;
+       auto callback = [&](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+               called++;
+       };
+
+       OsqueryManager::subscribe("manager_test", callback);
+
+       Row row;
+       row["foo"] = "bar";
+       row["foo2"] = "bar2";
+       row["foo3"] = "bar3";
+
+       /// Notification trigger
+       auto s = Notification::instance().emit("manager_test", row);
+
+       EXPECT_TRUE(s.ok());
+       EXPECT_EQ(called, 1);
+}
+
+TEST_F(ManagerTests, test_manager_columns) {
+       auto columns = OsqueryManager::columns("time");
+       EXPECT_TRUE(columns.size() > 0);
+
+       LOG(INFO) << "[Test] Enabled columns of time table:";
+       for (const auto& c : columns)
+               LOG(INFO) << "\t" << c;
+}
diff --git a/src/vist/manager/tests/policy_tests.cpp b/src/vist/manager/tests/policy_tests.cpp
new file mode 100644 (file)
index 0000000..18ab5f6
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  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_manager.h>
+
+#include <osquery/logger.h>
+
+#include <policyd/core/policy-manager.h>
+
+using namespace osquery;
+
+class PolicydTests : public testing::Test {};
+
+TEST_F(PolicydTests, select) {
+       std::string query = "SELECT * FROM policy";
+       auto rows = OsqueryManager::execute(query);
+       EXPECT_TRUE(rows.size() > 0);
+
+       LOG(INFO) << "[Test] policy table rows:";
+       for (auto& r : rows) {
+               LOG(INFO) << "\t name: " << r["name"];
+               LOG(INFO) << "\t value: " << r["value"];
+       }
+
+       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       rows = OsqueryManager::execute(query);
+
+       LOG(INFO) << "[Test] policy table rows with where clause:";
+       for (auto& r : rows) {
+               LOG(INFO) << "\t name: " << r["name"];
+               LOG(INFO) << "\t value: " << r["value"];
+       }
+
+       EXPECT_EQ(rows.size(), 1);
+}
+
+TEST_F(PolicydTests, update) {
+       auto& manager = policyd::PolicyManager::Instance();
+       manager.enroll("admin", 0);
+
+       std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       auto rows = OsqueryManager::execute(query);
+       /// Initial policy value
+       EXPECT_EQ(rows[0]["value"], std::to_string(1));
+
+       query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
+       rows = OsqueryManager::execute(query);
+       EXPECT_EQ(rows.size(), 0);
+
+       query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+       rows = OsqueryManager::execute(query);
+       EXPECT_EQ(rows[0]["value"], std::to_string(3));
+
+       manager.disenroll("admin", 0);
+}
diff --git a/src/vist/notification/CMakeLists.txt b/src/vist/notification/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3389443
--- /dev/null
@@ -0,0 +1,18 @@
+#  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_VIST_LIBRARY(vist_notification notification.cpp)
+
+FILE(GLOB NOTIFICATION_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${NOTIFICATION_TESTS})
diff --git a/src/vist/notification/notification.cpp b/src/vist/notification/notification.cpp
new file mode 100644 (file)
index 0000000..9db0272
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *  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 notification.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Implementation of notification
+ */
+
+#include <mutex>
+
+#include <osquery/notification.h>
+#include <osquery/logger.h>
+
+namespace {
+       std::mutex mutex;
+} // anonymous namespace
+
+namespace osquery {
+
+Notification& Notification::instance()
+{
+       static Notification notifier;
+       return notifier;
+}
+
+Status Notification::add(const std::string& table, const NotifyCallback& callback)
+{
+       if (table.empty())
+               return Status(1, "Wrong table name");
+
+       LOG(INFO) << "Add NotifyCallback to:" << table;
+       {
+               std::lock_guard<std::mutex> lock(mutex);
+               this->callbacks.insert(std::make_pair(table, callback));
+       }
+
+       return Status(0, "OK");
+}
+
+Status Notification::emit(const std::string& table, const Row& result) const
+{
+       if (table.empty())
+               return Status(1, "Wrong table name");
+
+       auto iter = this->callbacks.find(table);
+       if (iter == this->callbacks.end())
+               return Status(1, "Registered callback not found");
+
+       LOG(INFO) << "Emit notification about:" << table;
+       {
+               std::lock_guard<std::mutex> lock(mutex);
+               while (iter != this->callbacks.end())  {
+                       const auto& callback = iter->second;
+                       callback(result);
+                       iter++;
+               }
+       }
+
+       return Status(0, "OK");
+}
+
+} // namespace osquery
diff --git a/src/vist/notification/tests/notification_tests.cpp b/src/vist/notification/tests/notification_tests.cpp
new file mode 100644 (file)
index 0000000..721bbf1
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ *  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/notification.h>
+#include <osquery/logger.h>
+
+using namespace osquery;
+
+class NotificationTests : public testing::Test {};
+
+TEST_F(NotificationTests, test_add_positive) {
+       auto& notifier = Notification::instance();
+
+       auto callback = [](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+       };
+
+       auto s = notifier.add("test", std::move(callback));
+       EXPECT_TRUE(s.ok());
+}
+
+TEST_F(NotificationTests, test_add_negative) {
+       auto& notifier = Notification::instance();
+
+       auto callback = [](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+       };
+
+       auto s = notifier.add("", std::move(callback));
+       EXPECT_FALSE(s.ok());
+}
+
+TEST_F(NotificationTests, test_emit_positive) {
+       auto& notifier = Notification::instance();
+
+       int called = 0;
+       auto callback = [&](const Row& row) {
+               LOG(INFO) << "NotifyCallback called:";
+               for (const auto& r : row)
+                       LOG(INFO) << "\t" << r.first << " : " << r.second;
+               called++;
+       };
+
+       auto s = notifier.add("test2", std::move(callback));
+       EXPECT_TRUE(s.ok());
+
+       Row row;
+       row["foo"] = "bar";
+       s = notifier.emit("test2", row);
+
+       EXPECT_TRUE(s.ok());
+       EXPECT_EQ(called, 1);
+}
diff --git a/src/vist/property/CMakeLists.txt b/src/vist/property/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e216823
--- /dev/null
@@ -0,0 +1,18 @@
+#  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_VIST_LIBRARY(property property.cpp)
+
+FILE(GLOB PROPERTY_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${PROPERTY_TESTS})
diff --git a/src/vist/property/property.cpp b/src/vist/property/property.cpp
new file mode 100644 (file)
index 0000000..cbff8eb
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ *  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 <schema/processes.h>
+
+#include <osquery/logger.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 processes = make_table("processes",
+                                                       make_column("pid", &Processes::pid),
+                                                       make_column("name", &Processes::name),
+                                                       make_column("path", &Processes::path),
+                                                       make_column("cmdline", &Processes::cmdline),
+                                                       make_column("uid", &Processes::uid),
+                                                       make_column("gid", &Processes::gid),
+                                                       make_column("euid", &Processes::euid),
+                                                       make_column("egid", &Processes::egid),
+                                                       make_column("on_disk", &Processes::on_disk),
+                                                       make_column("parent", &Processes::parent));
+
+auto db = make_database("db", time, processes);
+
+} // 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>
+Property<T>::Property(KeyValuePair&& kvp) : data(std::move(kvp))
+{
+}
+
+template <typename T>
+template<typename Struct, typename Member>
+Member Property<T>::at(Member Struct::* field) const
+{
+       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.at(key);
+       if (value.empty()) {
+               LOG(ERROR) << "The value of key[" << key << "] is not exist.";
+               return Member();
+       }
+
+       try {
+               return boost::lexical_cast<Member>(value);
+       } catch (...) {
+               LOG(ERROR) << "Failed to casting [key]: " << key;
+               return Member();
+       }
+}
+
+template <typename T>
+template<typename Struct, typename Member>
+Member Property<T>::operator[](Member Struct::*field) const
+{
+       return this->at(field);
+}
+
+template <typename T>
+Properties<T>::Properties()
+{
+       auto results = OsqueryManager::execute(db.selectAll<T>());
+       for (auto& r : results)
+               this->datas.emplace_back(Property<T>(std::move(r)));
+}
+
+/// Explicit instantiation
+template class Property<Time>;
+template class Properties<Time>;
+template int Property<Time>::at(int Time::*) const;
+template int Property<Time>::operator[](int Time::*) const;
+
+template class Property<Processes>;
+template class Properties<Processes>;
+template int Property<Processes>::at(int Processes::*) const;
+template int Property<Processes>::operator[](int Processes::*) const;
+template long long int Property<Processes>::at(long long int Processes::*) const;
+template long long int Property<Processes>::operator[](long long int Processes::*) const;
+template std::string Property<Processes>::at(std::string Processes::*) const;
+template std::string Property<Processes>::operator[](std::string Processes::*) const;
+
+} // namespace osquery
diff --git a/src/vist/property/tests/property_tests.cpp b/src/vist/property/tests/property_tests.cpp
new file mode 100644 (file)
index 0000000..00a7e43
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ *  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>
+#include <schema/processes.h>
+
+using namespace osquery;
+
+class PropertyTests : public testing::Test {};
+
+TEST_F(PropertyTests, property) {
+       Time result = { -1, -1, -1 };
+
+       Property<Time> time;
+       result.hour = time.at(&Time::hour);
+       result.minutes = time.at(&Time::minutes);
+       result.seconds = time.at(&Time::seconds);
+
+       /// Once query execution
+       LOG(INFO) << "[Test] time table:";
+       LOG(INFO) << "\t hour: " << result.hour;
+       LOG(INFO) << "\t minutes: " << result.minutes;
+       LOG(INFO) << "\t seconds: " << result.seconds;
+
+       /// Each query execution
+       LOG(INFO) << "[Test] time table:";
+       LOG(INFO) << "\t hour: " << Property<Time>().at(&Time::hour);
+       LOG(INFO) << "\t minutes: " << Property<Time>().at(&Time::minutes);
+       LOG(INFO) << "\t seconds: " <<  Property<Time>().at(&Time::seconds);
+
+       EXPECT_NE(result.hour, -1);
+       EXPECT_NE(result.minutes, -1);
+       EXPECT_NE(result.seconds, -1);
+}
+
+TEST_F(PropertyTests, propertyArrayOp) {
+       Time result = { -1, -1, -1 };
+
+       Property<Time> time;
+       result.hour = time[&Time::hour];
+       result.minutes = time[&Time::minutes];
+       result.seconds = time[&Time::seconds];
+
+       /// Once query execution
+       LOG(INFO) << "[Test] time table:";
+       LOG(INFO) << "\t hour: " << result.hour;
+       LOG(INFO) << "\t minutes: " << result.minutes;
+       LOG(INFO) << "\t seconds: " << result.seconds;
+
+       EXPECT_NE(result.hour, -1);
+       EXPECT_NE(result.minutes, -1);
+       EXPECT_NE(result.seconds, -1);
+}
+
+TEST_F(PropertyTests, propertiesProcesses) {
+       Processes result;
+       Properties<Processes> processes;
+       EXPECT_TRUE(processes.size() > 0);
+
+       for(auto& p : processes) {
+               EXPECT_TRUE(p.size() > 0);
+               result.pid = p.at(&Processes::pid);
+               result.name = p.at(&Processes::name);
+               result.path = p.at(&Processes::path);
+               result.cmdline = p.at(&Processes::cmdline);
+               result.uid = p.at(&Processes::uid);
+               result.gid = p.at(&Processes::gid);
+               result.euid = p.at(&Processes::euid);
+               result.egid = p.at(&Processes::egid);
+               result.on_disk = p.at(&Processes::on_disk);
+               result.parent = p.at(&Processes::parent);
+
+               LOG(INFO) << "[Test] Processes table:";
+               LOG(INFO) << "\t pid: " << result.pid;
+               LOG(INFO) << "\t name: " << result.name;
+               LOG(INFO) << "\t path: " << result.path;
+               LOG(INFO) << "\t cmdline: " << result.cmdline;
+               LOG(INFO) << "\t uid: " << result.uid;
+               LOG(INFO) << "\t gid: " << result.gid;
+               LOG(INFO) << "\t euid: " << result.euid;
+               LOG(INFO) << "\t egid: " << result.egid;
+               LOG(INFO) << "\t on_disk: " << result.on_disk;
+               LOG(INFO) << "\t parent: " << result.parent;
+       }
+}
diff --git a/src/vist/tsqb/CMakeLists.txt b/src/vist/tsqb/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d6bf3fe
--- /dev/null
@@ -0,0 +1,16 @@
+#  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(GLOB TSQB_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${TSQB_TESTS})
diff --git a/src/vist/tsqb/include/column-pack.hxx b/src/vist/tsqb/include/column-pack.hxx
new file mode 100644 (file)
index 0000000..9688e8e
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 column-pack.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Tie different types of columns
+ */
+
+#pragma once
+
+#include "type.hxx"
+
+#include <string>
+#include <vector>
+
+namespace tsqb {
+namespace internal {
+
+template<typename... Base>
+class ColumnPack {
+public:
+       virtual ~ColumnPack() = default;
+
+       template<typename ColumnType>
+       std::string getName(ColumnType&&) const noexcept { return std::string(); }
+       std::vector<std::string> getNames(void) const noexcept { return {}; }
+
+       int size() const noexcept { return 0; }
+};
+
+template<typename Front, typename... Rest>
+class ColumnPack<Front, Rest...> : public ColumnPack<Rest...> {
+public:
+       using Column = Front;
+       using TableType = typename Column::TableType;
+
+       explicit ColumnPack(Front&& front, Rest&& ...rest);
+       virtual ~ColumnPack() = default;
+
+       ColumnPack(const ColumnPack&) = delete;
+       ColumnPack& operator=(const ColumnPack&) = delete;
+
+       ColumnPack(ColumnPack&&) = default;
+       ColumnPack& operator=(ColumnPack&&) = default;
+
+       template<typename ColumnType>
+       std::string getName(ColumnType&& type) const noexcept;
+       std::vector<std::string> getNames(void) const noexcept;
+
+       int size() const noexcept { return Base::size() + 1; }
+
+private:
+       using Base = ColumnPack<Rest...>;
+
+       Column column;
+};
+
+template<typename Front, typename... Rest>
+ColumnPack<Front, Rest...>::ColumnPack(Front&& front, Rest&& ...rest) :
+       Base(std::forward<Rest>(rest)...), column(front)
+{
+}
+
+template<typename Front, typename... Rest>
+std::vector<std::string> ColumnPack<Front, Rest...>::getNames(void) const noexcept
+{
+       auto names = Base::getNames();
+       names.push_back(this->column.name);
+
+       return std::move(names);
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string ColumnPack<Front, Rest...>::getName(ColumnType&& type) const noexcept
+{
+       if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
+               return column.name;
+
+       return Base::template getName<ColumnType>(std::forward<ColumnType>(type));
+}
+
+} // namespace internal
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/column.hxx b/src/vist/tsqb/include/column.hxx
new file mode 100644 (file)
index 0000000..ca17415
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 culumn.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Capture member pointer of struct and use it for matching with column
+ */
+
+#pragma once
+
+#include <string>
+#include <tuple>
+
+namespace tsqb {
+
+template<typename Object, typename Field>
+struct Column {
+       using Type = Field Object::*;
+       using FieldType = Field;
+       using TableType = Object;
+
+       std::string name;
+       Type type;
+};
+
+template<typename O, typename F>
+Column<O, F> make_column(const std::string& name, F O::*field)
+{
+       return {name, field};
+}
+
+template<typename Type>
+struct Distinct {
+       Type value;
+};
+
+template<typename... Args>
+auto distinct(Args&&... args) -> decltype(Distinct<std::tuple<Args...>>())
+{
+       return {std::make_tuple(std::forward<Args>(args)...)};
+}
+
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/condition.hxx b/src/vist/tsqb/include/condition.hxx
new file mode 100644 (file)
index 0000000..7ec13da
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 condition.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Represent the condition statement of SQL
+ */
+
+#pragma once
+
+#include "type.hxx"
+
+namespace tsqb {
+namespace condition {
+
+struct Base {};
+
+template<typename L, typename R>
+struct And : public Base {
+       L l;
+       R r;
+
+       And(L l, R r) : l(l), r(r) {}
+       operator std::string() const
+       {
+               return "AND";
+       }
+};
+
+template<typename L, typename R>
+struct Or : public Base {
+       L l;
+       R r;
+
+       Or(L l, R r) : l(l), r(r) {}
+       operator std::string() const
+       {
+               return "OR";
+       }
+};
+
+template<typename L, typename R>
+struct Binary : public Base {
+       L l;
+       R r;
+
+       Binary(L l, R r) : l(l), r(r)
+       {
+               using FieldType = typename L::FieldType;
+               type::assert_compare(FieldType(), r);
+       }
+};
+
+template<typename L>
+struct Binary<L, const char*> : public Base {
+       L l;
+       std::string r;
+
+       Binary(L l, const char* r) : l(l), r(r)
+       {
+               using FieldType = typename L::FieldType;
+               type::assert_compare(FieldType(), std::string());
+       }
+};
+
+enum class Join : int {
+       INNER,
+       CROSS,
+       LEFT_OUTER,
+       RIGHT_OUTER,
+       FULL_OUTER
+};
+
+inline std::string to_string(Join type)
+{
+       switch (type) {
+       case Join::CROSS: return "CROSS";
+       case Join::LEFT_OUTER: return "LEFT OUTER";
+       case Join::RIGHT_OUTER: return "RIGHT OUTER";
+       case Join::FULL_OUTER: return "FULL OUTER";
+       case Join::INNER:
+       default:
+               return "INNER";
+       }
+}
+
+} // namespace condition
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/crud.hxx b/src/vist/tsqb/include/crud.hxx
new file mode 100644 (file)
index 0000000..be48c86
--- /dev/null
@@ -0,0 +1,278 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 crud.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Represent four basic functions of CRUD
+ */
+
+#pragma once
+
+#include "column.hxx"
+#include "expression.hxx"
+
+#include <string>
+#include <sstream>
+
+namespace tsqb {
+
+template<typename T>
+class Crud {
+public:
+       template<typename... ColumnTypes>
+       T& select(ColumnTypes&&... cts);
+
+       template<typename Type>
+       T& select(Distinct<Type> distinct);
+
+       template<typename TableType>
+       T& selectAll(void);
+
+       T& selectAll(void);
+
+       template<typename... ColumnTypes>
+       T& update(ColumnTypes&&... cts);
+
+       template<typename... ColumnTypes>
+       T& insert(ColumnTypes&&... cts);
+
+       template<typename... ColumnTypes>
+       T& remove(ColumnTypes&&... cts);
+
+       template<typename Expr>
+       T& where(Expr expr);
+
+private:
+       template<typename ColumnTuple>
+       T& selectInternal(ColumnTuple&& ct, bool distinct = false);
+
+       template<typename L, typename R>
+       std::string processWhere(condition::And<L,R>& expr);
+
+       template<typename L, typename R>
+       std::string processWhere(condition::Or<L,R>& expr);
+
+       template<typename Expr>
+       std::string processWhere(Expr expr);
+};
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::select(ColumnTypes&&... cts)
+{
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+
+       return this->selectInternal(std::move(columnTuple));
+}
+
+template<typename T>
+template<typename Type>
+T& Crud<T>::select(Distinct<Type> distinct)
+{
+       return this->selectInternal(std::move(distinct.value), true);
+}
+
+template<typename T>
+T& Crud<T>::selectAll(void)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       std::stringstream ss;
+       ss << "SELECT * FROM " << static_cast<T*>(this)->name;
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename TableType>
+T& Crud<T>::selectAll(void)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       std::stringstream ss;
+       auto tableName = static_cast<T*>(this)->getTableName(TableType());
+       ss << "SELECT * FROM " << tableName;
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename ColumnTuple>
+T& Crud<T>::selectInternal(ColumnTuple&& ct, bool distinct)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(ct));
+       auto tableNames = static_cast<T*>(this)->getTableNames(std::move(ct));
+
+       std::stringstream ss;
+       ss << "SELECT ";
+
+       if (distinct)
+               ss << "DISTINCT ";
+
+       int i = 0;
+       for (const auto& c : columnNames) {
+               ss << c;
+
+               if (i++ < columnNames.size() - 1)
+                       ss << ", ";
+       }
+
+       ss << " FROM ";
+
+       i = 0;
+       for (const auto& t : tableNames) {
+               ss << t;
+
+               if (i++ < tableNames.size() - 1)
+                       ss << ", ";
+       }
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::update(ColumnTypes&&... cts)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
+
+       std::stringstream ss;
+       ss << "UPDATE " << static_cast<T*>(this)->name << " ";
+       ss << "SET ";
+
+       int i = 0;
+       for (const auto& c : columnNames) {
+               ss << c << " = ?";
+
+               if (i++ < columnNames.size() - 1)
+                       ss << ", ";
+       }
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::insert(ColumnTypes&&... cts)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
+
+       std::stringstream ss;
+       ss << "INSERT INTO " << static_cast<T*>(this)->name << " (";
+
+       const int columnCount = columnNames.size();
+       for (int i = 0; i < columnCount; i++) {
+               ss << columnNames[i];
+               if (i < columnCount - 1)
+                       ss << ", ";
+       }
+
+       ss << ") VALUES (";
+
+       for (int i = 0; i < columnCount; i++) {
+               ss << "?";
+               if (i < columnCount - 1)
+                       ss << ", ";
+       }
+
+       ss << ")";
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename... ColumnTypes>
+T& Crud<T>::remove(ColumnTypes&&... cts)
+{
+       static_cast<T*>(this)->cache.clear();
+
+       auto columnTuple = std::make_tuple(std::forward<ColumnTypes>(cts)...);
+       auto columnNames = static_cast<T*>(this)->getColumnNames(std::move(columnTuple));
+
+       std::stringstream ss;
+       ss << "DELETE FROM " << static_cast<T*>(this)->name;
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename Expr>
+T& Crud<T>::where(Expr expr)
+{
+       std::stringstream ss;
+       ss << "WHERE " << this->processWhere(expr);
+
+       static_cast<T*>(this)->cache.emplace_back(ss.str());
+
+       return *(static_cast<T*>(this));
+}
+
+template<typename T>
+template<typename L, typename R>
+std::string Crud<T>::processWhere(condition::And<L,R>& expr)
+{
+       std::stringstream ss;
+       ss << this->processWhere(expr.l) << " ";
+       ss << static_cast<std::string>(expr) << " ";
+       ss << this->processWhere(expr.r);
+
+       return ss.str();
+}
+
+template<typename T>
+template<typename L, typename R>
+std::string Crud<T>::processWhere(condition::Or<L,R>& expr)
+{
+       std::stringstream ss;
+       ss << this->processWhere(expr.l) << " ";
+       ss << static_cast<std::string>(expr) << " ";
+       ss << this->processWhere(expr.r);
+
+       return ss.str();
+}
+
+template<typename T>
+template<typename Expr>
+std::string Crud<T>::processWhere(Expr expr)
+{
+       std::stringstream ss;
+       ss << static_cast<T*>(this)->getColumnName(expr.l.type);
+       ss << " " << std::string(expr) << " ?";
+
+       return ss.str();
+}
+
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/database.hxx b/src/vist/tsqb/include/database.hxx
new file mode 100644 (file)
index 0000000..0c8bf54
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 database.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Represent the database scheme of SQL
+ */
+
+#pragma once
+
+#include "crud.hxx"
+#include "condition.hxx"
+#include "expression.hxx"
+#include "table-pack.hxx"
+#include "tuple-helper.hxx"
+#include "util.hxx"
+
+#include <vector>
+#include <set>
+#include <string>
+#include <sstream>
+#include <algorithm>
+
+namespace tsqb {
+
+template<typename... Tables>
+class Database : public Crud<Database<Tables...>> {
+public:
+       using Self = Database<Tables...>;
+
+       virtual ~Database() = default;
+
+       Database(const Database&) = delete;
+       Database& operator=(const Database&) = delete;
+
+       Database(Database&&) = default;
+       Database& operator=(Database&&) = default;
+
+       // Functions for Crud
+       template<typename Cs>
+       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
+       template<typename Cs>
+       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
+       template<typename TableType>
+       std::string getTableName(TableType&& type) const noexcept;
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& type) const noexcept;
+
+       template<typename Table>
+       Self& join(condition::Join type = condition::Join::INNER);
+
+       template<typename Expr>
+       Self& on(Expr expr);
+
+       operator std::string();
+
+       std::string name;
+       std::vector<std::string> cache;
+
+private:
+       using TablePackType = internal::TablePack<Tables...>;
+       using ColumnNames = std::vector<std::string>;
+       using TableNames = std::set<std::string>;
+
+       explicit Database(const std::string& name, TablePackType&& tablePack);
+
+       template<typename ...Ts>
+       friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
+
+       struct GetTableNames {
+               const TablePackType& tablePack;
+               std::set<std::string> names;
+               GetTableNames(const TablePackType& tablePack) : tablePack(tablePack) {}
+
+               template <typename T>
+               void operator()(T&& type)
+               {
+                       auto column = make_column("anonymous", type);
+                       using TableType = typename decltype(column)::TableType;
+                       auto name = this->tablePack.getName(TableType());
+                       if (!name.empty())
+                               names.emplace(name);
+               }
+       };
+
+       struct GetColumnNames {
+               const TablePackType& tablePack;
+               std::vector<std::string> names;
+
+               GetColumnNames(const TablePackType& tablePack) : tablePack(tablePack) {}
+
+               template <typename T>
+               void operator()(T&& type)
+               {
+                       auto column = make_column("anonymous", type);
+                       auto name = this->tablePack.getColumnName(std::move(column));
+                       if (!name.empty())
+                               names.emplace_back(name);
+               }
+       };
+
+       TablePackType tablePack;
+};
+
+template<typename ...Tables>
+Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
+{
+       auto tablePack = internal::TablePack<Tables...>(std::forward<Tables>(tables)...);
+       return Database<Tables...>(name, std::move(tablePack));
+}
+
+template<typename ...Tables>
+Database<Tables...>::Database(const std::string& name, TablePackType&& tablePack)
+       : name(name), tablePack(std::move(tablePack)) {}
+
+template<typename... Tables>
+template<typename Table>
+Database<Tables...>& Database<Tables...>::join(condition::Join type)
+{
+       std::stringstream ss;
+       ss << condition::to_string(type) << " ";
+       ss << "JOIN ";
+       ss << this->tablePack.getName(Table());
+
+       this->cache.emplace_back(ss.str());
+       return *this;
+}
+
+template<typename... Tables>
+template<typename Expr>
+Database<Tables...>& Database<Tables...>::on(Expr expr)
+{
+       std::stringstream ss;
+       ss << "ON ";
+
+       auto lname = this->tablePack.getColumnName(std::move(expr.l));
+       ss << lname << " ";
+
+       ss << std::string(expr) << " ";
+
+       auto rname = this->tablePack.getColumnName(std::move(expr.r));
+       ss << rname;
+
+       this->cache.emplace_back(ss.str());
+       return *this;
+}
+
+template<typename... Tables>
+Database<Tables...>::operator std::string()
+{
+       std::stringstream ss;
+       for (const auto& c : cache)
+               ss << c << " ";
+
+       this->cache.clear();
+       return util::rtrim(ss.str());
+}
+
+template<typename... Tables>
+template<typename Cs>
+std::set<std::string> Database<Tables...>::getTableNames(Cs&& tuple) const noexcept
+{
+       GetTableNames closure(this->tablePack);
+       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
+
+       return closure.names;
+}
+
+template<typename... Tables>
+template<typename Cs>
+std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& tuple) const noexcept
+{
+       GetColumnNames closure(this->tablePack);
+       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
+
+       return closure.names;
+}
+
+template<typename... Tables>
+template<typename TableType>
+std::string Database<Tables...>::getTableName(TableType&& type) const noexcept
+{
+       return this->tablePack.getName(std::forward<TableType>(type));
+}
+
+template<typename... Tables>
+template<typename ColumnType>
+std::string Database<Tables...>::getColumnName(ColumnType&& type) const noexcept
+{
+       auto column = make_column("anonymous", type);
+       return this->tablePack.getColumnName(std::move(column));
+}
+
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/expression.hxx b/src/vist/tsqb/include/expression.hxx
new file mode 100644 (file)
index 0000000..c901ab0
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 expression.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Represent the expression of SQL
+ */
+
+#pragma once
+
+#include "column.hxx"
+#include "type.hxx"
+#include "condition.hxx"
+
+#include <type_traits>
+
+namespace tsqb {
+
+template<typename Type>
+struct Expression {
+       Type value;
+};
+
+template<typename O, typename F>
+Expression<Column<O, F>> expr(F O::*field)
+{
+       Column<O, F> anonymous = {"anonymous", field};
+       return {anonymous};
+}
+
+template<typename L, typename R>
+struct Lesser : public condition::Binary<L, R> {
+       using condition::Binary<L, R>::Binary;
+
+       operator std::string() const
+       {
+               return "<";
+       }
+};
+
+template<typename L, typename R>
+Lesser<L, R> operator<(Expression<L> expr, R r)
+{
+       return {expr.value, r};
+}
+
+template<typename L, typename R>
+struct Equal : public condition::Binary<L, R>
+{
+       using condition::Binary<L, R>::Binary;
+
+       operator std::string() const
+       {
+               return "=";
+       }
+};
+
+template<typename L, typename R>
+Equal<L, R> operator==(Expression<L> expr, R r)
+{
+       return {expr.value, r};
+}
+
+namespace join {
+
+template<typename L, typename R>
+struct Equal
+{
+       L l;
+       R r;
+
+       operator std::string() const
+       {
+               return "=";
+       }
+};
+
+} // namespace join
+
+template<typename L, typename R>
+join::Equal<L, R> operator==(Expression<L> l, Expression<R> r)
+{
+       return {l.value, r.value};
+}
+
+template<typename L, typename R>
+struct Greater : public condition::Binary<L, R>
+{
+       using condition::Binary<L, R>::Binary;
+
+       operator std::string() const
+       {
+               return ">";
+       }
+};
+
+template<typename L, typename R>
+Greater<L, R> operator>(Expression<L> expr, R r)
+{
+       return {expr.value, r};
+}
+
+template<bool B, typename T = void>
+using enable_if_t = typename std::enable_if<B, T>::type;
+
+template<typename T>
+using is_condition = typename std::is_base_of<condition::Base, T>;
+
+template<typename L,
+                typename R,
+                typename = typename tsqb::enable_if_t<is_condition<L>::value
+                                                        && tsqb::is_condition<R>::value>>
+condition::And<L, R> operator&&(const L& l, const R& r)
+{
+       return {l, r};
+}
+
+template<typename L,
+                typename R,
+                typename = typename tsqb::enable_if_t<is_condition<L>::value
+                                                        && tsqb::is_condition<R>::value>>
+condition::Or<L, R> operator||(const L& l, const R& r)
+{
+       return {l, r};
+}
+
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/table-pack.hxx b/src/vist/tsqb/include/table-pack.hxx
new file mode 100644 (file)
index 0000000..d192886
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 table-pack.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Tie diffirent types of tables
+ */
+
+#pragma once
+
+#include <vector>
+#include <set>
+#include <string>
+
+namespace tsqb {
+namespace internal {
+
+template<typename... Base>
+class TablePack {
+public:
+       virtual ~TablePack() = default;
+
+       template<typename TableType>
+       std::string getName(TableType&&) const noexcept { return std::string(); }
+
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&&) const noexcept { return std::string(); }
+};
+
+template<typename Front, typename... Rest>
+class TablePack<Front, Rest...> : public TablePack<Rest...> {
+public:
+       using Table = Front;
+
+       explicit TablePack(Front&& front, Rest&& ...rest);
+       virtual ~TablePack() = default;
+
+       TablePack(const TablePack&) = delete;
+       TablePack& operator=(const TablePack&) = delete;
+
+       TablePack(TablePack&&) = default;
+       TablePack& operator=(TablePack&&) = default;
+
+       template<typename TableType>
+       std::string getName(TableType&& table) const noexcept;
+
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& column) const noexcept;
+
+private:
+       using Base = TablePack<Rest...>;
+
+       Table table;
+};
+
+template<typename Front, typename... Rest>
+TablePack<Front, Rest...>::TablePack(Front&& front, Rest&& ...rest) :
+       Base(std::forward<Rest>(rest)...), table(front)
+{
+}
+
+template<typename Front, typename... Rest>
+template<typename TableType>
+std::string TablePack<Front, Rest...>::getName(TableType&& table) const noexcept
+{
+       if (this->table.compare(table))
+               return this->table.name;
+
+       return Base::template getName<TableType>(std::forward<TableType>(table));
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string TablePack<Front, Rest...>::getColumnName(ColumnType&& column) const noexcept
+{
+       using DecayColumnType = typename std::decay<ColumnType>::type;
+       using DecayTableType = typename DecayColumnType::TableType;
+       if (this->table.compare(DecayTableType())) {
+               auto cname = this->table.getColumnName(column.type);
+               return this->table.name + "." + cname;
+       }
+
+       return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(column));
+}
+
+} // namespace internal
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/table.hxx b/src/vist/tsqb/include/table.hxx
new file mode 100644 (file)
index 0000000..e1ac527
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 table.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Represent the table of SQL
+ */
+
+#pragma once
+
+#include "crud.hxx"
+#include "column.hxx"
+#include "column-pack.hxx"
+#include "tuple-helper.hxx"
+#include "util.hxx"
+
+#include <vector>
+#include <string>
+#include <sstream>
+
+namespace tsqb {
+
+template<typename... Columns>
+class Table : public Crud<Table<Columns...>> {
+public:
+       virtual ~Table() = default;
+
+       Table(const Table&) = delete;
+       Table& operator=(const Table&) = delete;
+
+       Table(Table&&) = default;
+       Table& operator=(Table&&) = default;
+
+       // Functions for Crud
+       template<typename Cs>
+       std::set<std::string> getTableNames(Cs&& tuple) const noexcept;
+       template<typename Cs>
+       std::vector<std::string> getColumnNames(Cs&& tuple) const noexcept;
+       template<typename That>
+       std::string getTableName(That&& type) const noexcept;
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& type) const noexcept;
+
+       std::vector<std::string> getColumnNames(void) const noexcept;
+
+       template<typename That>
+       bool compare(const That& that) const noexcept;
+
+       int size() const noexcept;
+
+       operator std::string();
+
+       std::string name;
+       std::vector<std::string> cache;
+
+private:
+       using ColumnPackType = internal::ColumnPack<Columns...>;
+       using TableType = typename ColumnPackType::TableType;
+
+       explicit Table(const std::string& name, ColumnPackType&& columnPack);
+
+       template<typename ...Cs>
+       friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
+
+       struct GetColumnNames {
+               const ColumnPackType& columnPack;
+               std::vector<std::string> names;
+
+               GetColumnNames(const ColumnPackType& columnPack) : columnPack(columnPack) {}
+
+               template <typename T>
+               void operator()(T&& type)
+               {
+                       auto name = this->columnPack.getName(std::forward<T>(type));
+                       if (!name.empty())
+                               names.emplace_back(name);
+               }
+       };
+
+       ColumnPackType columnPack;
+};
+
+template<typename ...Columns>
+Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
+{
+       auto columnPack = internal::ColumnPack<Columns...>(std::forward<Columns>(cs)...);
+       return Table<Columns...>(name, std::move(columnPack));
+}
+
+template<typename... Columns>
+Table<Columns...>::Table(const std::string& name, ColumnPackType&& columnPack)
+       : name(name), columnPack(std::move(columnPack)) {}
+
+template<typename... Columns>
+template<typename Cs>
+std::set<std::string> Table<Columns...>::getTableNames(Cs&& tuple) const noexcept
+{
+       return {this->name};
+}
+
+template<typename... Columns>
+template<typename Cs>
+std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple) const noexcept
+{
+       GetColumnNames closure(this->columnPack);
+       tuple_helper::for_each(std::forward<Cs>(tuple), closure);
+
+       return closure.names;
+}
+
+template<typename... Columns>
+template<typename That>
+std::string Table<Columns...>::getTableName(That&& type) const noexcept
+{
+       return this->name;
+}
+
+template<typename... Columns>
+template<typename ColumnType>
+std::string Table<Columns...>::getColumnName(ColumnType&& type) const noexcept
+{
+       return this->columnPack.getName(std::forward<ColumnType>(type));
+}
+
+template<typename... Columns>
+std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
+{
+       return this->columnPack.getNames();
+}
+
+template<typename... Columns>
+template<typename That>
+bool Table<Columns...>::compare(const That& that) const noexcept
+{
+       using This = TableType;
+       return type::compare(This(), that);
+}
+
+template<typename... Columns>
+Table<Columns...>::operator std::string()
+{
+       std::stringstream ss;
+       for (const auto& c : cache)
+               ss << c << " ";
+
+       this->cache.clear();
+       return util::rtrim(ss.str());
+}
+
+template<typename... Columns>
+int Table<Columns...>::size() const noexcept
+{
+       return this->columnPack.size();
+}
+
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/tuple-helper.hxx b/src/vist/tsqb/include/tuple-helper.hxx
new file mode 100644 (file)
index 0000000..495946e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 tuple-helper.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Iterator method for tuple
+ */
+
+#pragma once
+
+#include <tuple>
+
+namespace tsqb {
+namespace tuple_helper {
+namespace internal {
+
+template<int n, typename T, typename C>
+class Iterator {
+public:
+       Iterator(const T& tuple, C&& closure) {
+               Iterator<n - 1, T, C> iter(tuple, std::forward<C>(closure));
+               closure(std::get<n-1>(tuple));
+       }
+};
+
+template<typename T, typename C>
+class Iterator<0, T, C> {
+public:
+       Iterator(const T&, C&&) {}
+};
+
+} // namespace internal
+
+template<typename T, typename C>
+void for_each(const T& tuple, C&& closure)
+{
+       using Iter = internal::Iterator<std::tuple_size<T>::value, T, C>;
+       Iter iter(tuple, std::forward<C>(closure));
+}
+
+} // namspace tuple-hepler
+} // namspace tsqb
diff --git a/src/vist/tsqb/include/type.hxx b/src/vist/tsqb/include/type.hxx
new file mode 100644 (file)
index 0000000..939b3da
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 type.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Make type safety with compile time checking
+ */
+
+#pragma once
+
+#include <type_traits>
+
+namespace tsqb {
+namespace type {
+
+template<typename L, typename R>
+bool cast_compare(L l, R r)
+{
+       return l == reinterpret_cast<L>(r);
+}
+
+template<typename L, typename R>
+bool compare(L l, R r)
+{
+       return std::is_same<L, R>::value;
+}
+
+template<typename L, typename R>
+void assert_compare(L l, R r)
+{
+       static_assert(std::is_same<L, R>::value, "Type is unsafe.");
+}
+
+} // namespace type
+} // namespace tsqb
diff --git a/src/vist/tsqb/include/util.hxx b/src/vist/tsqb/include/util.hxx
new file mode 100644 (file)
index 0000000..e65583d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 util.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ */
+
+#pragma once
+
+#include <string>
+#include <algorithm>
+#include <cctype>
+
+namespace tsqb {
+namespace util {
+
+inline std::string rtrim(std::string&& s)
+{
+       auto predicate = [](unsigned char c){ return !std::isspace(c); };
+       auto base = std::find_if(s.rbegin(), s.rend(), predicate).base();
+       s.erase(base, s.end());
+       return s;
+}
+
+} // namespace util
+} // namespace tsqb
diff --git a/src/vist/tsqb/tests/tsqb-tests.cpp b/src/vist/tsqb/tests/tsqb-tests.cpp
new file mode 100644 (file)
index 0000000..7770140
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 tsqb-tests.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief Testcases of tsqb
+ */
+
+#include "tsqb.hxx"
+
+#include <gtest/gtest.h>
+
+using namespace tsqb;
+
+struct Admin {
+       int id;
+       std::string pkg;
+       int uid;
+       std::string key;
+       int removable;
+};
+
+struct ManagedPolicy {
+       int id;
+       int aid;
+       int pid;
+       int value;
+};
+
+struct PolicyDefinition {
+       int id;
+       int scope;
+       std::string name;
+       int ivalue;
+};
+
+auto admin = make_table("admin", make_column("id", &Admin::id),
+                                                                make_column("pkg", &Admin::pkg),
+                                                                make_column("uid", &Admin::uid),
+                                                                make_column("key", &Admin::key),
+                                                                make_column("removable", &Admin::removable));
+
+auto managedPolicy = make_table("managed_policy",
+                                                                make_column("id", &ManagedPolicy::id),
+                                                                make_column("aid", &ManagedPolicy::aid),
+                                                                make_column("pid", &ManagedPolicy::pid),
+                                                                make_column("value", &ManagedPolicy::value));
+
+auto policyDefinition = make_table("policy_definition",
+                                                                  make_column("id", &PolicyDefinition::id),
+                                                                  make_column("scope", &PolicyDefinition::scope),
+                                                                  make_column("name", &PolicyDefinition::name),
+                                                                  make_column("ivalue", &PolicyDefinition::ivalue));
+
+auto db = make_database("dpm", admin, managedPolicy, policyDefinition);
+
+class TsqbTests : public testing::Test {};
+
+TEST_F(TsqbTests, SELECT)
+{
+       std::string select1 = admin.select(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
+       std::string select2 = admin.select(&Admin::id, &Admin::uid, &Admin::key);
+
+       EXPECT_EQ(select1, "SELECT id, pkg, uid, key FROM admin");
+       EXPECT_EQ(select2, "SELECT id, uid, key FROM admin");
+}
+
+TEST_F(TsqbTests, SELECT_ALL)
+{
+       std::string select = admin.selectAll();
+
+       EXPECT_EQ(select, "SELECT * FROM admin");
+}
+
+TEST_F(TsqbTests, SELECT_WHERE)
+{
+       std::string select1 = admin.select(&Admin::uid, &Admin::key)
+                                                          .where(expr(&Admin::id) > 3);
+       std::string select2 = admin.selectAll().where(expr(&Admin::uid) > 3);
+       std::string select3 = admin.selectAll().where(expr(&Admin::uid) > 3 &&
+                                                                                                 expr(&Admin::pkg) == "dpm");
+       std::string select4 = admin.selectAll().where(expr(&Admin::uid) > 3 ||
+                                                                                                 expr(&Admin::pkg) == "dpm");
+
+       EXPECT_EQ(select1, "SELECT uid, key FROM admin WHERE id > ?");
+       EXPECT_EQ(select2, "SELECT * FROM admin WHERE uid > ?");
+       EXPECT_EQ(select3, "SELECT * FROM admin WHERE uid > ? AND pkg = ?");
+       EXPECT_EQ(select4, "SELECT * FROM admin WHERE uid > ? OR pkg = ?");
+}
+
+TEST_F(TsqbTests, SELECT_DISTINCT)
+{
+       std::string select = admin.select(distinct(&Admin::uid, &Admin::key))
+                                                          .where(expr(&Admin::id) > 3);
+
+       EXPECT_EQ(select, "SELECT DISTINCT uid, key FROM admin WHERE id > ?");
+}
+
+TEST_F(TsqbTests, UPDATE)
+{
+       int uid = 0, id = 1;
+       std::string update1 = admin.update(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
+       std::string update2 = admin.update(&Admin::key).where(expr(&Admin::uid) == uid &&
+                                                                                                                 expr(&Admin::id) == id);
+       std::string update3 = admin.update(&Admin::key, &Admin::pkg)
+                                                          .where(expr(&Admin::uid) == 0 && expr(&Admin::id) == 1);
+
+       EXPECT_EQ(update1, "UPDATE admin SET id = ?, pkg = ?, uid = ?, key = ?");
+       EXPECT_EQ(update2, "UPDATE admin SET key = ? WHERE uid = ? AND id = ?");
+       EXPECT_EQ(update3, "UPDATE admin SET key = ?, pkg = ? WHERE uid = ? AND id = ?");
+}
+
+TEST_F(TsqbTests, DELETE)
+{
+       std::string delete1 = admin.remove();
+       std::string delete2 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
+                                                                                          expr(&Admin::uid) == 3);
+
+       EXPECT_EQ(delete1, "DELETE FROM admin");
+       EXPECT_EQ(delete2, "DELETE FROM admin WHERE pkg = ? AND uid = ?");
+}
+
+TEST_F(TsqbTests, INSERT)
+{
+       std::string insert1 = admin.insert(&Admin::id, &Admin::pkg, &Admin::uid, &Admin::key);
+       std::string insert2 = admin.insert(&Admin::id, &Admin::pkg, &Admin::key);
+
+       EXPECT_EQ(insert1, "INSERT INTO admin (id, pkg, uid, key) VALUES (?, ?, ?, ?)");
+       EXPECT_EQ(insert2, "INSERT INTO admin (id, pkg, key) VALUES (?, ?, ?)");
+}
+
+TEST_F(TsqbTests, TYPE_SAFE)
+{
+/*
+ * Below cause complie error since expression types are dismatch.
+
+       std::string type_unsafe1 = admin.selectAll().where(expr(&Admin::uid) > "dpm");
+       std::string type_unsafe2 = admin.selectAll().where(expr(&Admin::uid) == "dpm");
+       std::string type_unsafe3 = admin.selectAll().where(expr(&Admin::pkg) == 3);
+       int pkg = 3;
+       std::string type_unsafe4 = admin.selectAll().where(expr(&Admin::pkg) < pkg);
+       std::string type_unsafe5 = admin.remove().where(expr(&Admin::pkg) == "dpm" &&
+                                                                                                       expr(&Admin::uid) == "dpm");
+*/
+}
+
+TEST_F(TsqbTests, MULTI_SELECT)
+{
+       std::string multiSelect1 = db.select(&Admin::uid, &Admin::key,
+                                                                                &ManagedPolicy::id, &ManagedPolicy::value);
+       std::string multiSelect2 = db.select(&Admin::uid, &Admin::key,
+                                                                                &ManagedPolicy::id, &ManagedPolicy::value)
+                                                                .where(expr(&Admin::uid) > 0 && expr(&ManagedPolicy::id) == 3);
+
+       EXPECT_EQ(multiSelect1, "SELECT admin.uid, admin.key, managed_policy.id, "
+                                                       "managed_policy.value FROM admin, managed_policy");
+       EXPECT_EQ(multiSelect2, "SELECT admin.uid, admin.key, managed_policy.id, "
+                                                       "managed_policy.value FROM admin, managed_policy "
+                                                       "WHERE admin.uid > ? AND managed_policy.id = ?");
+}
+
+TEST_F(TsqbTests, JOIN)
+{
+       std::string join1 = db.select(&Admin::uid, &Admin::key)
+                                                 .join<PolicyDefinition>(condition::Join::LEFT_OUTER);
+       std::string join2 = db.select(&Admin::uid, &Admin::key)
+                                                 .join<ManagedPolicy>(condition::Join::CROSS);
+       std::string join3 = db.select(&ManagedPolicy::value)
+                                                 .join<PolicyDefinition>()
+                                                 .on(expr(&ManagedPolicy::pid) == expr(&PolicyDefinition::id))
+                                                 .join<Admin>()
+                                                 .on(expr(&ManagedPolicy::aid) == expr(&Admin::id))
+                                                 .where(expr(&ManagedPolicy::pid) == 99);
+
+       EXPECT_EQ(join1, "SELECT admin.uid, admin.key FROM admin "
+                                        "LEFT OUTER JOIN policy_definition");
+       EXPECT_EQ(join2, "SELECT admin.uid, admin.key FROM admin "
+                                        "CROSS JOIN managed_policy");
+       EXPECT_EQ(join3, "SELECT managed_policy.value FROM managed_policy "
+                                        "INNER JOIN policy_definition "
+                                        "ON managed_policy.pid = policy_definition.id "
+                                        "INNER JOIN admin ON managed_policy.aid = admin.id "
+                                        "WHERE managed_policy.pid = ?");
+}
diff --git a/src/vist/tsqb/tsqb.hxx b/src/vist/tsqb/tsqb.hxx
new file mode 100644 (file)
index 0000000..c3791f0
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (c) 2017-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.
+ *  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 tsqb.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @brief TSQB is type-safe query builder
+ */
+
+#pragma once
+
+#include "include/database.hxx"
+#include "include/table.hxx"
+#include "include/column.hxx"
+#include "include/expression.hxx"
+#include "include/condition.hxx"
+#include "include/util.hxx"