diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6604adb..2c39731 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,7 +22,7 @@ variables:
UDNS: "-DWITH_UDNS=1"
SYSTEMD: "-DWITH_SYSTEMD=1"
LIBIDN: "-DWITH_LIBIDN=1"
- LITESQL: "-DWITH_LITESQL=1"
+ SQLITE3: "-DWITH_SQLITE3=1"
#
## Build jobs
@@ -33,8 +33,8 @@ variables:
tags:
- docker
script:
- - "echo Running cmake with the following parameters: -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${BOTAN} ${UDNS} ${SYSTEMD} ${LIBIDN} ${LITESQL}"
- - cmake .. -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${BOTAN} ${UDNS} ${SYSTEMD} ${LIBIDN} ${LITESQL}
+ - "echo Running cmake with the following parameters: -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${BOTAN} ${UDNS} ${SYSTEMD} ${LIBIDN} ${SQLITE3}"
+ - cmake .. -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${BOTAN} ${UDNS} ${SYSTEMD} ${LIBIDN} ${SQLITE3}
- make everything -j$(nproc || echo 1)
- make coverage_check -j$(nproc || echo 1)
artifacts:
@@ -77,19 +77,19 @@ build:2:
build:3:
variables:
- LITESQL: "-DWITHOUT_LITESQL=1"
+ SQLITE3: "-DWITHOUT_SQLITE3=1"
<<: *fedora_build
build:4:
variables:
- LITESQL: "-DWITHOUT_LITESQL=1"
+ SQLITE3: "-DWITHOUT_SQLITE3=1"
BOTAN: "-DWITHOUT_BOTAN=1"
LIBIDN: "-DWITHOUT_LIBIDN=1"
<<: *fedora_build
build:5:
variables:
- LITESQL: "-DWITHOUT_LITESQL=1"
+ SQLITE3: "-DWITHOUT_SQLITE3=1"
UDNS: "-DWITHOUT_UDNS=1"
<<: *fedora_build
@@ -156,14 +156,14 @@ test:alpine:
test:freebsd:
only:
- - master@louiz/biboumi
+ - branches@louiz/biboumi
tags:
- freebsd
variables:
SYSTEMD: "-DWITHOUT_SYSTEMD=1"
stage: test
script:
- - cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${BOTAN} ${UDNS} ${SYSTEMD} ${LIBIDN} ${LITESQL}
+ - cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${BOTAN} ${UDNS} ${SYSTEMD} ${LIBIDN} ${SQLITE3}
- make check
- make e2e
@@ -240,7 +240,7 @@ codecov:build:7:
coverity:
stage: external
only:
- - master@louiz/biboumi
+ - branches@louiz/biboumi
tags:
- docker
image: docker.louiz.org/biboumi-test-fedora:latest
@@ -298,16 +298,13 @@ packaging:deb:
packaging:archlinux:
stage: packaging
+ only:
+ - master@louiz/biboumi
tags:
- docker
image: docker.louiz.org/biboumi-test-archlinux:latest
before_script: []
script:
- - sudo pacman -Syuu --noconfirm
- - git clone https://aur.archlinux.org/litesql-git.git
- - cd litesql-git
- - makepkg -si --noconfirm
- - cd ..
- git clone https://aur.archlinux.org/biboumi-git.git
- cd biboumi-git
- makepkg -si --noconfirm
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 5709483..9bfecd6 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,9 @@
+Version 6.0
+===========
+
+ - The LiteSQL dependency was removed. Only libsqlite3 is now necessary
+ to work with the database.
+
Version 5.0 - 2017-05-24
========================
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6b081bc..ed20870 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -124,10 +124,10 @@ elseif(NOT WITHOUT_UDNS)
find_package(UDNS)
endif()
-if(WITH_LITESQL)
- find_package(LITESQL REQUIRED)
-elseif(NOT WITHOUT_LITESQL)
- find_package(LITESQL)
+if(WITH_SQLITE3)
+ find_package(SQLITE3 REQUIRED)
+elseif(NOT WITHOUT_SQLITE3)
+ find_package(SQLITE3)
endif()
#
@@ -158,17 +158,14 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}/")
file(GLOB source_utils
src/utils/*.[hc]pp)
add_library(utils OBJECT ${source_utils})
-add_dependencies(utils litesql_generated_sources)
file(GLOB source_irc
src/irc/*.[hc]pp)
add_library(irc OBJECT ${source_irc})
-add_dependencies(irc litesql_generated_sources)
file(GLOB source_xmpp
src/xmpp/*.[hc]pp)
add_library(xmpp OBJECT ${source_xmpp})
-add_dependencies(xmpp litesql_generated_sources)
file(GLOB source_identd
src/identd/*.[hc]pp)
@@ -177,7 +174,6 @@ add_library(identd OBJECT ${source_identd})
file(GLOB source_bridge
src/bridge/*.[hc]pp)
add_library(bridge OBJECT ${source_bridge})
-add_dependencies(bridge litesql_generated_sources)
file(GLOB source_config
src/config/*.[hc]pp)
@@ -191,20 +187,15 @@ file(GLOB source_network
src/network/*.[hc]pp)
add_library(network OBJECT ${source_network})
-if(LITESQL_FOUND)
- LITESQL_GENERATE_CPP("database/database.xml"
- "biboudb"
- LITESQL_GENERATED_SOURCES)
- add_custom_target(litesql_generated_sources SOURCES ${LITESQL_GENERATED_SOURCES})
+if(SQLITE3_FOUND)
+ file(GLOB source_database
+ src/database/*.[hc]pp)
+ add_library(database OBJECT ${source_database})
- add_library(database OBJECT src/database/database.cpp ${LITESQL_GENERATED_SOURCES})
- add_dependencies(database litesql_generated_sources)
-
- include_directories(database ${LITESQL_INCLUDE_DIRS})
+ include_directories(database ${SQLITE3_INCLUDE_DIRS})
set(USE_DATABASE TRUE)
else()
add_library(database OBJECT "")
- add_custom_target(litesql_generated_sources)
endif()
#
@@ -269,8 +260,8 @@ if(LIBIDN_FOUND)
target_link_libraries(test_suite ${LIBIDN_LIBRARIES})
endif()
if(USE_DATABASE)
- target_link_libraries(${PROJECT_NAME} ${LITESQL_LIBRARIES})
- target_link_libraries(test_suite ${LITESQL_LIBRARIES})
+ target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIBRARIES})
+ target_link_libraries(test_suite ${SQLITE3_LIBRARIES})
endif()
# Define a __FILENAME__ macro with the relative path (from the base project directory)
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 74459d1..8df4899 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -52,8 +52,8 @@ There are two test suites for biboumi:
uses a specific IRC server (`charybdis`_), and only tests the most complete
biboumi configuration (when all dependencies are used). To run it, you need
to install various dependencies: refer to fedora’s `Dockerfile.base`_ and
- `Dockerfile`_ to see how to install charybdis, slixmpp, botan, litesql, an
- ssl certificate, etc.
+ `Dockerfile`_ to see how to install charybdis, slixmpp, botan, a ssl
+ certificate, etc.
Once all the dependencies are correctly installed, the tests are run with
@@ -94,4 +94,4 @@ Please try to follow the existing style:
.. _Dockerfile.base: docker/biboumi-test/fedora/Dockerfile.base
.. _Dockerfile: docker/biboumi-test/fedora/Dockerfile
.. _charybdis: https://github.com/charybdis-ircd/charybdis
-.. _the __main__.py file: tests/end_to_end/__main__.py
\ No newline at end of file
+.. _the __main__.py file: tests/end_to_end/__main__.py
diff --git a/INSTALL.rst b/INSTALL.rst
index 6cd85d2..5bb0ca8 100644
--- a/INSTALL.rst
+++ b/INSTALL.rst
@@ -32,6 +32,12 @@ libiconv_
libuuid_
Generate unique IDs
+sqlite3_ (option, but highly recommended)
+ Provides a way to store various options in a (sqlite3) database. Each user
+ of the gateway can store their own values (for example their prefered port,
+ or their IRC password). Without this dependency, many interesting features
+ are missing.
+
libidn_ (optional, but recommended)
Provides the stringprep functionality. Without it, JIDs for IRC users are
not provided.
@@ -48,11 +54,6 @@ libbotan_ 1.11 or 2.0 (optional)
gcrypt_ (mandatory only if botan is absent)
Provides the SHA-1 hash function, for the case where Botan is absent.
-litesql_ (optional)
- Provides a way to store various options in a (sqlite3) database. Each user
- of the gateway can store their own values (for example their prefered port,
- or their IRC password).
-
systemd_ (optional)
Provides the support for a systemd service of Type=notify. This is useful only
if you are packaging biboumi in a distribution with Systemd.
@@ -160,7 +161,7 @@ to use biboumi.
.. _libidn: http://www.gnu.org/software/libidn/
.. _libbotan: http://botan.randombit.net/
.. _udns: http://www.corpit.ru/mjt/udns.html
-.. _litesql: http://git.louiz.org/litesql
+.. _sqlite3: https://sqlite.org
.. _systemd: https://www.freedesktop.org/wiki/Software/systemd/
.. _biboumi.1.rst: doc/biboumi.1.rst
.. _gcrypt: https://www.gnu.org/software/libgcrypt/
diff --git a/cmake/Modules/FindLITESQL.cmake b/cmake/Modules/FindLITESQL.cmake
deleted file mode 100644
index 2d3b073..0000000
--- a/cmake/Modules/FindLITESQL.cmake
+++ /dev/null
@@ -1,76 +0,0 @@
-# - Find LiteSQL
-#
-# Find the LiteSQL library, and defines a function to generate C++ files
-# from the database xml file using litesql-gen fro
-#
-# This module defines the following variables:
-# LITESQL_FOUND - True if library and include directory are found
-# If set to TRUE, the following are also defined:
-# LITESQL_INCLUDE_DIRS - The directory where to find the header file
-# LITESQL_LIBRARIES - Where to find the library file
-# LITESQL_GENERATE_CPP - A function, to be used like this:
-# LITESQL_GENERATE_CPP("db/database.xml" # The file defining the db schemas
-# "database" # The name of the C++ “module”
-# # that will be generated
-# LITESQL_GENERATED_SOURCES # Variable containing the
-# resulting C++ files to compile
-#
-# For conveniance, these variables are also set. They have the same values
-# than the variables above. The user can thus choose his/her prefered way
-# to write them.
-# LITESQL_INCLUDE_DIR
-# LITESQL_LIBRARY
-#
-# This file is in the public domain
-
-find_path(LITESQL_INCLUDE_DIRS NAMES litesql.hpp
- DOC "The LiteSQL include directory")
-
-find_library(LITESQL_LIBRARIES NAMES litesql
- DOC "The LiteSQL library")
-
-foreach(DB_TYPE sqlite postgresql mysql ocilib)
- string(TOUPPER ${DB_TYPE} DB_TYPE_UPPER)
- find_library(LITESQL_${DB_TYPE_UPPER}_LIB_PATH NAMES litesql_${DB_TYPE}
- DOC "The ${DB_TYPE} backend for LiteSQL")
- if(LITESQL_${DB_TYPE_UPPER}_LIB_PATH)
- list(APPEND LITESQL_LIBRARIES ${LITESQL_${DB_TYPE_UPPER}_LIB_PATH})
- endif()
- mark_as_advanced(LITESQL_${DB_TYPE_UPPER}_LIB_PATH)
-endforeach()
-
-find_program(LITESQLGEN_EXECUTABLE NAMES litesql-gen
- DOC "The utility that creates .h and .cpp files from a xml database description")
-
-# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
-# set LITESQL_FOUND to TRUE if these two variables are set.
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(LITESQL REQUIRED_VARS LITESQL_LIBRARIES LITESQL_INCLUDE_DIRS
- LITESQLGEN_EXECUTABLE)
-
-# Compatibility for all the ways of writing these variables
-if(LITESQL_FOUND)
- set(LITESQL_INCLUDE_DIR ${LITESQL_INCLUDE_DIRS})
- set(LITESQL_LIBRARY ${LITESQL_LIBRARIES})
-endif()
-
-mark_as_advanced(LITESQL_INCLUDE_DIRS LITESQL_LIBRARIES LITESQLGEN_EXECUTABLE)
-
-
-# LITESQL_GENERATE_CPP function
-
-function(LITESQL_GENERATE_CPP
- SOURCE_FILE OUTPUT_NAME OUTPUT_SOURCES)
- set(${OUTPUT_SOURCES})
- add_custom_command(
- OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.cpp"
- "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.hpp"
- COMMAND ${LITESQLGEN_EXECUTABLE}
- ARGS -t c++ --output-dir=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}
- DEPENDS ${SOURCE_FILE}
- COMMENT "Running litesql-gen on ${SOURCE_FILE}"
- VERBATIM)
- list(APPEND ${OUTPUT_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.cpp")
- set_source_files_properties(${${OUTPUT_SOURCES}} PROPERTIES GENERATED TRUE)
- set(${OUTPUT_SOURCES} ${${OUTPUT_SOURCES}} PARENT_SCOPE)
-endfunction()
diff --git a/cmake/Modules/FindSQLITE3.cmake b/cmake/Modules/FindSQLITE3.cmake
new file mode 100644
index 0000000..2861b37
--- /dev/null
+++ b/cmake/Modules/FindSQLITE3.cmake
@@ -0,0 +1,43 @@
+# - Find sqlite3
+# Find the sqlite3 cryptographic library
+#
+# This module defines the following variables:
+# SQLITE3_FOUND - True if library and include directory are found
+# If set to TRUE, the following are also defined:
+# SQLITE3_INCLUDE_DIRS - The directory where to find the header file
+# SQLITE3_LIBRARIES - Where to find the library file
+#
+# For conveniance, these variables are also set. They have the same values
+# than the variables above. The user can thus choose his/her prefered way
+# to write them.
+# SQLITE3_LIBRARY
+# SQLITE3_INCLUDE_DIR
+#
+# This file is in the public domain
+
+include(FindPkgConfig)
+
+if(NOT SQLITE3_FOUND)
+ pkg_check_modules(SQLITE3 sqlite3)
+endif()
+
+if(NOT SQLITE3_FOUND)
+ find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h
+ DOC "The sqlite3 include directory")
+
+ find_library(SQLITE3_LIBRARIES NAMES sqlite3
+ DOC "The sqlite3 library")
+
+ # Use some standard module to handle the QUIETLY and REQUIRED arguments, and
+ # set SQLITE3_FOUND to TRUE if these two variables are set.
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(SQLITE3 REQUIRED_VARS SQLITE3_LIBRARIES SQLITE3_INCLUDE_DIRS)
+
+ if(SQLITE3_FOUND)
+ set(SQLITE3_LIBRARY ${SQLITE3_LIBRARIES} CACHE INTERNAL "")
+ set(SQLITE3_INCLUDE_DIR ${SQLITE3_INCLUDE_DIRS} CACHE INTERNAL "")
+ set(SQLITE3_FOUND ${SQLITE3_FOUND} CACHE INTERNAL "")
+ endif()
+endif()
+
+mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
\ No newline at end of file
diff --git a/database/database.xml b/database/database.xml
deleted file mode 100644
index e641fdf..0000000
--- a/database/database.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/docker/biboumi-test/alpine/Dockerfile b/docker/biboumi-test/alpine/Dockerfile
index ab288b6..1938a8b 100644
--- a/docker/biboumi-test/alpine/Dockerfile
+++ b/docker/biboumi-test/alpine/Dockerfile
@@ -1,10 +1,54 @@
# This Dockerfile creates a docker image suitable to run biboumi’s build and
# tests. For example, it can be used on with gitlab-ci.
-FROM docker.louiz.org/biboumi-test-alpine-base
+FROM docker.io/alpine:latest
-# Install litesql
-RUN git clone git://git.louiz.org/litesql && mkdir /litesql/build && cd /litesql/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr && make -j8 && cd /litesql/build && make install && rm -rf /litesql && ldconfig || true
+ENV LC_ALL C.UTF-8
+
+# Needed to build biboumi
+RUN apk add --no-cache g++\
+ clang\
+ valgrind\
+ udns-dev\
+ c-ares-dev\
+ sqlite-dev\
+ libuuid\
+ util-linux-dev\
+ libgcrypt-dev\
+ cmake\
+ make\
+ expat-dev\
+ libidn-dev\
+ git\
+ py3-lxml\
+ libtool\
+ py3-pip\
+ python2\
+ python3-dev\
+ automake\
+ autoconf\
+ flex\
+ bison\
+ libltdl\
+ openssl\
+ libressl-dev\
+ zlib-dev\
+ curl
+
+# Install botan
+RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && rm -rf /botan
+
+# Install slixmpp, for e2e tests
+RUN git clone https://github.com/saghul/aiodns.git && cd aiodns && git checkout 7ee13f9bea25784322~ && python3 setup.py build && python3 setup.py install && git clone git://git.louiz.org/slixmpp && pip3 install pyasn1 && cd slixmpp && python3 setup.py build && python3 setup.py install
+
+RUN adduser tester -D -h /home/tester
+
+# Install charybdis, for e2e tests
+RUN git clone https://github.com/charybdis-ircd/charybdis.git && cd charybdis && cd /charybdis && git checkout 4f2b9a4 && sed s/113/1113/ -i /charybdis/authd/providers/ident.c && ./autogen.sh && ./configure --prefix=/home/tester/ircd --bindir=/usr/bin && make -j8 && make install && rm -rf /charybdis
+
+RUN chown -R tester:tester /home/tester/ircd
+
+RUN yes "" | openssl req -nodes -x509 -newkey rsa:4096 -keyout /home/tester/ircd/etc/ssl.key -out /home/tester/ircd/etc/ssl.pem
WORKDIR /home/tester
USER tester
diff --git a/docker/biboumi-test/alpine/Dockerfile.base b/docker/biboumi-test/alpine/Dockerfile.base
deleted file mode 100644
index dffa1d1..0000000
--- a/docker/biboumi-test/alpine/Dockerfile.base
+++ /dev/null
@@ -1,51 +0,0 @@
-# This Dockerfile creates a docker image suitable to run biboumi’s build and
-# tests. For example, it can be used on with gitlab-ci.
-
-FROM docker.io/alpine:latest
-
-ENV LC_ALL C.UTF-8
-
-# Needed to build biboumi
-RUN apk add --no-cache g++\
- clang\
- valgrind\
- udns-dev\
- c-ares-dev\
- sqlite-dev\
- libuuid\
- util-linux-dev\
- libgcrypt-dev\
- cmake\
- make\
- expat-dev\
- libidn-dev\
- git\
- py3-lxml\
- libtool\
- py3-pip\
- python2\
- python3-dev\
- automake\
- autoconf\
- flex\
- bison\
- libltdl\
- openssl\
- libressl-dev\
- zlib-dev\
- curl
-
-# Install botan
-RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && rm -rf /botan
-
-# Install slixmpp, for e2e tests
-RUN git clone https://github.com/saghul/aiodns.git && cd aiodns && git checkout 7ee13f9bea25784322~ && python3 setup.py build && python3 setup.py install && git clone git://git.louiz.org/slixmpp && pip3 install pyasn1 && cd slixmpp && python3 setup.py build && python3 setup.py install
-
-RUN adduser tester -D -h /home/tester
-
-# Install charybdis, for e2e tests
-RUN git clone https://github.com/charybdis-ircd/charybdis.git && cd charybdis && cd /charybdis && git checkout 4f2b9a4 && sed s/113/1113/ -i /charybdis/authd/providers/ident.c && ./autogen.sh && ./configure --prefix=/home/tester/ircd --bindir=/usr/bin && make -j8 && make install && rm -rf /charybdis
-
-RUN chown -R tester:tester /home/tester/ircd
-
-RUN yes "" | openssl req -nodes -x509 -newkey rsa:4096 -keyout /home/tester/ircd/etc/ssl.key -out /home/tester/ircd/etc/ssl.pem
diff --git a/docker/biboumi-test/debian/Dockerfile b/docker/biboumi-test/debian/Dockerfile
index b811ea4..232a585 100644
--- a/docker/biboumi-test/debian/Dockerfile
+++ b/docker/biboumi-test/debian/Dockerfile
@@ -1,10 +1,60 @@
# This Dockerfile creates a docker image suitable to run biboumi’s build and
# tests. For example, it can be used on with gitlab-ci.
-FROM docker.louiz.org/biboumi-test-debian-base
+FROM docker.io/debian:latest
-# Install litesql
-RUN git clone git://git.louiz.org/litesql && mkdir /litesql/build && cd /litesql/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr && make -j8 && cd /litesql/build && make install && rm -rf /litesql && ldconfig
+ENV LC_ALL C.UTF-8
+
+RUN apt update
+
+# Needed to build biboumi
+RUN apt install -y g++\
+ clang\
+ valgrind\
+ libudns-dev\
+ libc-ares-dev\
+ libsqlite3-dev\
+ libuuid1\
+ libgcrypt20-dev\
+ cmake\
+ make\
+ libexpat1-dev\
+ libidn11-dev\
+ uuid-dev\
+ libsystemd-dev\
+ pandoc\
+ libasan1\
+ libubsan0\
+ git\
+ python3-lxml\
+ lcov\
+ libtool\
+ python3-pip\
+ python3-dev\
+ automake\
+ autoconf\
+ flex\
+ bison\
+ libltdl-dev\
+ openssl\
+ zlib1g-dev\
+ libssl-dev\
+ curl
+
+# Install botan
+RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && rm -rf /botan
+
+# Install slixmpp, for e2e tests
+RUN git clone https://github.com/saghul/aiodns.git && cd aiodns && git checkout 7ee13f9bea25784322~ && python3 setup.py build && python3 setup.py install && git clone git://git.louiz.org/slixmpp && pip3 install pyasn1 && cd slixmpp && python3 setup.py build && python3 setup.py install
+
+RUN useradd tester -m
+
+# Install charybdis, for e2e tests
+RUN git clone https://github.com/charybdis-ircd/charybdis.git && cd charybdis && cd /charybdis && git checkout 4f2b9a4 && sed s/113/1113/ -i /charybdis/authd/providers/ident.c && ./autogen.sh && ./configure --prefix=/home/tester/ircd --bindir=/usr/bin && make -j8 && make install && rm -rf /charybdis
+
+RUN chown -R tester:tester /home/tester/ircd
+
+RUN yes "" | openssl req -nodes -x509 -newkey rsa:4096 -keyout /home/tester/ircd/etc/ssl.key -out /home/tester/ircd/etc/ssl.pem
WORKDIR /home/tester
USER tester
diff --git a/docker/biboumi-test/debian/Dockerfile.base b/docker/biboumi-test/debian/Dockerfile.base
deleted file mode 100644
index f5d061b..0000000
--- a/docker/biboumi-test/debian/Dockerfile.base
+++ /dev/null
@@ -1,57 +0,0 @@
-# This Dockerfile creates a docker image suitable to run biboumi’s build and
-# tests. For example, it can be used on with gitlab-ci.
-
-FROM docker.io/debian:latest
-
-ENV LC_ALL C.UTF-8
-
-RUN apt update
-
-# Needed to build biboumi
-RUN apt install -y g++\
- clang\
- valgrind\
- libudns-dev\
- libc-ares-dev\
- libsqlite3-dev\
- libuuid1\
- libgcrypt20-dev\
- cmake\
- make\
- libexpat1-dev\
- libidn11-dev\
- uuid-dev\
- libsystemd-dev\
- pandoc\
- libasan1\
- libubsan0\
- git\
- python3-lxml\
- lcov\
- libtool\
- python3-pip\
- python3-dev\
- automake\
- autoconf\
- flex\
- bison\
- libltdl-dev\
- openssl\
- zlib1g-dev\
- libssl-dev\
- curl
-
-# Install botan
-RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && rm -rf /botan
-
-# Install slixmpp, for e2e tests
-RUN git clone https://github.com/saghul/aiodns.git && cd aiodns && git checkout 7ee13f9bea25784322~ && python3 setup.py build && python3 setup.py install && git clone git://git.louiz.org/slixmpp && pip3 install pyasn1 && cd slixmpp && python3 setup.py build && python3 setup.py install
-
-RUN useradd tester -m
-
-# Install charybdis, for e2e tests
-RUN git clone https://github.com/charybdis-ircd/charybdis.git && cd charybdis && cd /charybdis && git checkout 4f2b9a4 && sed s/113/1113/ -i /charybdis/authd/providers/ident.c && ./autogen.sh && ./configure --prefix=/home/tester/ircd --bindir=/usr/bin && make -j8 && make install && rm -rf /charybdis
-
-RUN chown -R tester:tester /home/tester/ircd
-
-RUN yes "" | openssl req -nodes -x509 -newkey rsa:4096 -keyout /home/tester/ircd/etc/ssl.key -out /home/tester/ircd/etc/ssl.pem
diff --git a/docker/biboumi-test/fedora/Dockerfile b/docker/biboumi-test/fedora/Dockerfile
index 45dbe76..384fd51 100644
--- a/docker/biboumi-test/fedora/Dockerfile
+++ b/docker/biboumi-test/fedora/Dockerfile
@@ -1,10 +1,62 @@
# This Dockerfile creates a docker image suitable to run biboumi’s build and
# tests. For example, it can be used on with gitlab-ci.
-FROM docker.louiz.org/biboumi-test-fedora-base
+FROM docker.io/fedora:latest
-# Install litesql
-RUN git clone git://git.louiz.org/litesql && mkdir /litesql/build && cd /litesql/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr && make -j8 && cd /litesql/build && make install && ldconfig && rm -rf /litesql
+ENV LC_ALL C.UTF-8
+
+RUN dnf --refresh install -y\
+ gcc-c++\
+ clang\
+ valgrind\
+ udns-devel\
+ c-ares-devel\
+ sqlite-devel\
+ libuuid-devel\
+ libgcrypt-devel\
+ cmake\
+ make\
+ expat-devel\
+ libidn-devel\
+ uuid-devel\
+ systemd-devel\
+ pandoc\
+ libasan\
+ libubsan\
+ git\
+ fedora-packager\
+ python3-lxml\
+ lcov\
+ rpmdevtools\
+ python3-devel\
+ automake\
+ autoconf\
+ flex\
+ flex-devel\
+ bison\
+ libtool-ltdl-devel\
+ libtool\
+ openssl-devel\
+ which\
+ java-1.8.0-openjdk\
+ && dnf clean all
+
+# Install botan
+RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && ldconfig && rm -rf /botan
+
+# Install slixmpp, for e2e tests
+RUN git clone git://git.louiz.org/slixmpp && pip3 install pyasn1 && cd slixmpp && python3 setup.py build && python3 setup.py install
+
+RUN useradd tester
+
+# Install charybdis, for e2e tests
+RUN git clone https://github.com/charybdis-ircd/charybdis.git && cd charybdis && cd /charybdis && git checkout 4f2b9a4 && sed s/113/1113/ -i /charybdis/authd/providers/ident.c && ./autogen.sh && ./configure --prefix=/home/tester/ircd --bindir=/usr/bin --with-included-boost && make -j8 && make install && rm -rf /charybdis
+
+RUN chown -R tester:tester /home/tester/ircd
+
+RUN yes "" | openssl req -nodes -x509 -newkey rsa:4096 -keyout /home/tester/ircd/etc/ssl.key -out /home/tester/ircd/etc/ssl.pem
+
+COPY coverity /home/tester/coverity
WORKDIR /home/tester
USER tester
diff --git a/docker/biboumi-test/fedora/Dockerfile.base b/docker/biboumi-test/fedora/Dockerfile.base
deleted file mode 100644
index 20984a2..0000000
--- a/docker/biboumi-test/fedora/Dockerfile.base
+++ /dev/null
@@ -1,59 +0,0 @@
-# This Dockerfile creates a docker image suitable to run biboumi’s build and
-# tests. For example, it can be used on with gitlab-ci.
-
-FROM docker.io/fedora:latest
-
-ENV LC_ALL C.UTF-8
-
-RUN dnf --refresh install -y\
- gcc-c++\
- clang\
- valgrind\
- udns-devel\
- c-ares-devel\
- sqlite-devel\
- libuuid-devel\
- libgcrypt-devel\
- cmake\
- make\
- expat-devel\
- libidn-devel\
- uuid-devel\
- systemd-devel\
- pandoc\
- libasan\
- libubsan\
- git\
- fedora-packager\
- python3-lxml\
- lcov\
- rpmdevtools\
- python3-devel\
- automake\
- autoconf\
- flex\
- flex-devel\
- bison\
- libtool-ltdl-devel\
- libtool\
- openssl-devel\
- which\
- java-1.8.0-openjdk\
- && dnf clean all
-
-# Install botan
-RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && ldconfig && rm -rf /botan
-
-# Install slixmpp, for e2e tests
-RUN git clone git://git.louiz.org/slixmpp && pip3 install pyasn1 && cd slixmpp && python3 setup.py build && python3 setup.py install
-
-RUN useradd tester
-
-# Install charybdis, for e2e tests
-RUN git clone https://github.com/charybdis-ircd/charybdis.git && cd charybdis && cd /charybdis && git checkout 4f2b9a4 && sed s/113/1113/ -i /charybdis/authd/providers/ident.c && ./autogen.sh && ./configure --prefix=/home/tester/ircd --bindir=/usr/bin --with-included-boost && make -j8 && make install && rm -rf /charybdis
-
-RUN chown -R tester:tester /home/tester/ircd
-
-RUN yes "" | openssl req -nodes -x509 -newkey rsa:4096 -keyout /home/tester/ircd/etc/ssl.key -out /home/tester/ircd/etc/ssl.pem
-
-COPY coverity /home/tester/coverity
diff --git a/docker/biboumi/Dockerfile b/docker/biboumi/Dockerfile
index d27421b..67f0f41 100644
--- a/docker/biboumi/Dockerfile
+++ b/docker/biboumi/Dockerfile
@@ -18,15 +18,12 @@ RUN apk add --no-cache\
# Install botan
RUN git clone https://github.com/randombit/botan.git && cd botan && ./configure.py --prefix=/usr && make -j8 && make install && rm -rf /botan
-# Install litesql
-RUN git clone git://git.louiz.org/litesql && mkdir /litesql/build && cd /litesql/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr && make -j8 && cd /litesql/build && make install && rm -rf /litesql
-
# Install biboumi
RUN git clone git://git.louiz.org/biboumi && mkdir ./biboumi/build && cd ./biboumi/build &&\
cmake .. -DCMAKE_INSTALL_PREFIX=/usr\
-DCMAKE_BUILD_TYPE=Release\
-DWITH_BOTAN=1\
- -DWITH_LITESQL=1\
+ -DWITH_SQLITE3=1\
-DWITH_LIBIDN=1\
&& make -j8 && make install && rm -rf /biboumi
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 4a41b50..23ecfe9 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -23,22 +23,24 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid)
#ifdef USE_DATABASE
const auto jid = bridge.get_bare_jid();
auto options = Database::get_irc_channel_options_with_server_default(jid, iid.get_server(), iid.get_local());
- return options.encodingIn.value();
+ auto result = options.col();
+ if (!result.empty())
+ return result;
#else
(void)bridge;
(void)iid;
- return {"ISO-8859-1"};
#endif
+ return {"ISO-8859-1"};
}
Bridge::Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller):
- user_jid(std::move(user_jid)),
+ user_jid(std::move(user_jid)),
xmpp(xmpp),
poller(poller)
{
#ifdef USE_DATABASE
const auto options = Database::get_global_options(this->user_jid);
- this->set_record_history(options.recordHistory.value());
+ this->set_record_history(options.col());
#endif
}
@@ -258,7 +260,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
#ifdef USE_DATABASE
const auto xmpp_body = this->make_xmpp_body(line);
if (this->record_history)
- uuid = Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
+ uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(),
std::get<0>(xmpp_body), irc->get_own_nick());
#endif
for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
@@ -436,7 +438,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
#ifdef USE_DATABASE
const auto coptions = Database::get_irc_channel_options_with_server_default(this->user_jid,
iid.get_server(), iid.get_local());
- persistent = coptions.persistent.value();
+ persistent = coptions.col();
#endif
if (channel->joined && !channel->parting && !persistent)
{
@@ -837,7 +839,7 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
#ifdef USE_DATABASE
const auto xmpp_body = this->make_xmpp_body(body, encoding);
if (!nick.empty() && this->record_history)
- Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
+ Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(),
std::get<0>(xmpp_body), nick);
#endif
for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
@@ -994,12 +996,12 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam
{
#ifdef USE_DATABASE
const auto coptions = Database::get_irc_channel_options_with_server_and_global_default(this->user_jid, hostname, chan_name);
- const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, coptions.maxHistoryLength.value());
+ const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, coptions.col());
chan_name.append(utils::empty_if_fixed_server("%" + hostname));
for (const auto& line: lines)
{
- const auto seconds = line.date.value().timeStamp();
- this->xmpp.send_history_message(chan_name, line.nick.value(), line.body.value(),
+ const auto seconds = line.col();
+ this->xmpp.send_history_message(chan_name, line.col(), line.col(),
this->user_jid + "/" + resource, seconds);
}
#else
diff --git a/src/database/column.hpp b/src/database/column.hpp
new file mode 100644
index 0000000..22f4254
--- /dev/null
+++ b/src/database/column.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include
+
+template
+struct Column
+{
+ Column(T default_value):
+ value{default_value} {}
+ Column():
+ value{} {}
+ using real_type = T;
+ T value{};
+};
+
+struct Id: Column { static constexpr auto name = "id_";
+ static constexpr auto options = "PRIMARY KEY AUTOINCREMENT"; };
diff --git a/src/database/count_query.hpp b/src/database/count_query.hpp
new file mode 100644
index 0000000..b7bbf51
--- /dev/null
+++ b/src/database/count_query.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include
+#include
+
+#include
+
+#include
+
+struct CountQuery: public Query
+{
+ CountQuery(std::string name):
+ Query("SELECT count(*) FROM ")
+ {
+ this->body += std::move(name);
+ }
+
+ int64_t execute(sqlite3* db)
+ {
+ auto statement = this->prepare(db);
+ int64_t res = 0;
+ if (sqlite3_step(statement.get()) == SQLITE_ROW)
+ res = sqlite3_column_int64(statement.get(), 0);
+ else
+ {
+ log_error("Count request didn’t return a result");
+ return 0;
+ }
+ if (sqlite3_step(statement.get()) != SQLITE_DONE)
+ log_warning("Count request returned more than one result.");
+
+ log_debug("Returning count: ", res);
+ return res;
+ }
+};
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 9f310da..1738a69 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -2,175 +2,166 @@
#ifdef USE_DATABASE
#include
-#include
-#include
#include
#include
#include
-using namespace std::string_literals;
+#include
-std::unique_ptr Database::db;
+sqlite3* Database::db;
+Database::MucLogLineTable Database::muc_log_lines("MucLogLine_");
+Database::GlobalOptionsTable Database::global_options("GlobalOptions_");
+Database::IrcServerOptionsTable Database::irc_server_options("IrcServerOptions_");
+Database::IrcChannelOptionsTable Database::irc_channel_options("IrcChannelOptions_");
-void Database::open(const std::string& filename, const std::string& db_type)
+void Database::open(const std::string& filename)
{
- try
+ auto res = sqlite3_open_v2(filename.data(), &Database::db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
+ log_debug("open: ", res);
+ Database::muc_log_lines.create(Database::db);
+ Database::global_options.create(Database::db);
+ Database::irc_server_options.create(Database::db);
+ Database::irc_channel_options.create(Database::db);
+}
+
+
+Database::GlobalOptions Database::get_global_options(const std::string& owner)
+{
+ auto request = Database::global_options.select().where() << Owner{} << "=" << owner;
+
+ Database::GlobalOptions options{Database::global_options.get_name()};
+ auto result = request.execute(Database::db);
+ if (result.size() == 1)
+ options = result.front();
+ else
+ options.col() = owner;
+ return options;
+}
+
+Database::IrcServerOptions Database::get_irc_server_options(const std::string& owner, const std::string& server)
+{
+ auto request = Database::irc_server_options.select().where() << Owner{} << "=" << owner << " and " << Server{} << "=" << server;
+
+ Database::IrcServerOptions options{Database::irc_server_options.get_name()};
+ auto result = request.execute(Database::db);
+ if (result.size() == 1)
+ options = result.front();
+ else
{
- auto new_db = std::make_unique(db_type,
- "database="s + filename);
- if (new_db->needsUpgrade())
- new_db->upgrade();
- Database::db = std::move(new_db);
- } catch (const litesql::DatabaseError& e) {
- log_error("Failed to open database ", filename, ". ", e.what());
- throw;
+ options.col() = owner;
+ options.col() = server;
}
+ return options;
}
-void Database::set_verbose(const bool val)
+Database::IrcChannelOptions Database::get_irc_channel_options(const std::string& owner, const std::string& server, const std::string& channel)
{
- Database::db->verbose = val;
+ auto request = Database::irc_channel_options.select().where() << Owner{} << "=" << owner <<\
+ " and " << Server{} << "=" << server <<\
+ " and " << Channel{} << "=" << channel;
+ Database::IrcChannelOptions options{Database::irc_channel_options.get_name()};
+ auto result = request.execute(Database::db);
+ if (result.size() == 1)
+ options = result.front();
+ else
+ {
+ options.col() = owner;
+ options.col() = server;
+ options.col() = channel;
+ }
+ return options;
}
-db::GlobalOptions Database::get_global_options(const std::string& owner)
-{
- try {
- auto options = litesql::select(*Database::db,
- db::GlobalOptions::Owner == owner).one();
- return options;
- } catch (const litesql::NotFound& e) {
- db::GlobalOptions options(*Database::db);
- options.owner = owner;
- return options;
- }
-}
-
-db::IrcServerOptions Database::get_irc_server_options(const std::string& owner,
- const std::string& server)
-{
- try {
- auto options = litesql::select(*Database::db,
- db::IrcServerOptions::Owner == owner &&
- db::IrcServerOptions::Server == server).one();
- return options;
- } catch (const litesql::NotFound& e) {
- db::IrcServerOptions options(*Database::db);
- options.owner = owner;
- options.server = server;
- // options.update();
- return options;
- }
-}
-
-db::IrcChannelOptions Database::get_irc_channel_options(const std::string& owner,
- const std::string& server,
- const std::string& channel)
-{
- try {
- auto options = litesql::select(*Database::db,
- db::IrcChannelOptions::Owner == owner &&
- db::IrcChannelOptions::Server == server &&
- db::IrcChannelOptions::Channel == channel).one();
- return options;
- } catch (const litesql::NotFound& e) {
- db::IrcChannelOptions options(*Database::db);
- options.owner = owner;
- options.server = server;
- options.channel = channel;
- return options;
- }
-}
-
-db::IrcChannelOptions Database::get_irc_channel_options_with_server_default(const std::string& owner,
- const std::string& server,
- const std::string& channel)
+Database::IrcChannelOptions Database::get_irc_channel_options_with_server_default(const std::string& owner, const std::string& server,
+ const std::string& channel)
{
auto coptions = Database::get_irc_channel_options(owner, server, channel);
auto soptions = Database::get_irc_server_options(owner, server);
- coptions.encodingIn = get_first_non_empty(coptions.encodingIn.value(),
- soptions.encodingIn.value());
- coptions.encodingOut = get_first_non_empty(coptions.encodingOut.value(),
- soptions.encodingOut.value());
+ coptions.col() = get_first_non_empty(coptions.col(),
+ soptions.col());
+ coptions.col() = get_first_non_empty(coptions.col(),
+ soptions.col());
- coptions.maxHistoryLength = get_first_non_empty(coptions.maxHistoryLength.value(),
- soptions.maxHistoryLength.value());
+ coptions.col() = get_first_non_empty(coptions.col(),
+ soptions.col());
return coptions;
}
-db::IrcChannelOptions Database::get_irc_channel_options_with_server_and_global_default(const std::string& owner,
- const std::string& server,
- const std::string& channel)
+Database::IrcChannelOptions Database::get_irc_channel_options_with_server_and_global_default(const std::string& owner, const std::string& server, const std::string& channel)
{
auto coptions = Database::get_irc_channel_options(owner, server, channel);
auto soptions = Database::get_irc_server_options(owner, server);
auto goptions = Database::get_global_options(owner);
- coptions.encodingIn = get_first_non_empty(coptions.encodingIn.value(),
- soptions.encodingIn.value());
- coptions.encodingOut = get_first_non_empty(coptions.encodingOut.value(),
- soptions.encodingOut.value());
+ coptions.col() = get_first_non_empty(coptions.col(),
+ soptions.col());
- coptions.maxHistoryLength = get_first_non_empty(coptions.maxHistoryLength.value(),
- soptions.maxHistoryLength.value(),
- goptions.maxHistoryLength.value());
+ coptions.col() = get_first_non_empty(coptions.col(),
+ soptions.col());
+
+ coptions.col() = get_first_non_empty(coptions.col(),
+ soptions.col(),
+ goptions.col());
return coptions;
}
-std::string Database::store_muc_message(const std::string& owner, const Iid& iid,
- Database::time_point date,
- const std::string& body,
- const std::string& nick)
+std::string Database::store_muc_message(const std::string& owner, const std::string& chan_name,
+ const std::string& server_name, Database::time_point date,
+ const std::string& body, const std::string& nick)
{
- db::MucLogLine line(*Database::db);
+ auto line = Database::muc_log_lines.row();
auto uuid = Database::gen_uuid();
- line.uuid = uuid;
- line.owner = owner;
- line.ircChanName = iid.get_local();
- line.ircServerName = iid.get_server();
- line.date = std::chrono::duration_cast(date.time_since_epoch()).count();
- line.body = body;
- line.nick = nick;
+ line.col() = uuid;
+ line.col() = owner;
+ line.col() = chan_name;
+ line.col() = server_name;
+ line.col() = std::chrono::duration_cast(date.time_since_epoch()).count();
+ line.col() = body;
+ line.col() = nick;
- line.update();
+ line.save(Database::db);
return uuid;
}
-std::vector Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+std::vector Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
int limit, const std::string& start, const std::string& end)
{
- auto request = litesql::select(*Database::db,
- db::MucLogLine::Owner == owner &&
- db::MucLogLine::IrcChanName == chan_name &&
- db::MucLogLine::IrcServerName == server);
- request.orderBy(db::MucLogLine::Id, false);
+ auto request = Database::muc_log_lines.select().where() << Database::Owner{} << "=" << owner << \
+ " and " << Database::IrcChanName{} << "=" << chan_name << \
+ " and " << Database::IrcServerName{} << "=" << server;
- if (limit >= 0)
- request.limit(limit);
if (!start.empty())
{
const auto start_time = utils::parse_datetime(start);
if (start_time != -1)
- request.where(db::MucLogLine::Date >= start_time);
+ request << " and " << Database::Date{} << ">=" << start_time;
}
if (!end.empty())
{
const auto end_time = utils::parse_datetime(end);
if (end_time != -1)
- request.where(db::MucLogLine::Date <= end_time);
+ request << " and " << Database::Date{} << "<=" << end_time;
}
- const auto& res = request.all();
- return {res.crbegin(), res.crend()};
+
+ request.order_by() << Id{} << " DESC ";
+
+ if (limit >= 0)
+ request.limit() << limit;
+
+ auto result = request.execute(Database::db);
+
+ return {result.crbegin(), result.crend()};
}
void Database::close()
{
- Database::db.reset(nullptr);
+ sqlite3_close_v2(Database::db);
}
std::string Database::gen_uuid()
@@ -182,5 +173,4 @@ std::string Database::gen_uuid()
return uuid_str;
}
-
-#endif
+#endif
\ No newline at end of file
diff --git a/src/database/database.hpp b/src/database/database.hpp
index b08a175..1ad62fc 100644
--- a/src/database/database.hpp
+++ b/src/database/database.hpp
@@ -1,22 +1,107 @@
#pragma once
-
#include
#ifdef USE_DATABASE
-#include "biboudb.hpp"
+#include
+#include
+#include
+
+#include
+#include
#include
-#include
-#include
-
-class Iid;
class Database
{
-public:
+ public:
using time_point = std::chrono::system_clock::time_point;
+
+ struct Uuid: Column { static constexpr auto name = "uuid_";
+ static constexpr auto options = ""; };
+
+ struct Owner: Column { static constexpr auto name = "owner_";
+ static constexpr auto options = ""; };
+
+ struct IrcChanName: Column { static constexpr auto name = "ircChanName_";
+ static constexpr auto options = ""; };
+
+ struct Channel: Column { static constexpr auto name = "channel_";
+ static constexpr auto options = ""; };
+
+ struct IrcServerName: Column { static constexpr auto name = "ircServerName_";
+ static constexpr auto options = ""; };
+
+ struct Server: Column { static constexpr auto name = "server_";
+ static constexpr auto options = ""; };
+
+ struct Date: Column { static constexpr auto name = "date_";
+ static constexpr auto options = ""; };
+
+ struct Body: Column { static constexpr auto name = "body_";
+ static constexpr auto options = ""; };
+
+ struct Nick: Column { static constexpr auto name = "nick_";
+ static constexpr auto options = ""; };
+
+ struct Pass: Column { static constexpr auto name = "pass_";
+ static constexpr auto options = ""; };
+
+ struct Ports: Column { static constexpr auto name = "ports_";
+ static constexpr auto options = "";
+ Ports(): Column("6667") {} };
+
+ struct TlsPorts: Column { static constexpr auto name = "tlsPorts_";
+ static constexpr auto options = "";
+ TlsPorts(): Column("6697;6670") {} };
+
+ struct Username: Column { static constexpr auto name = "username_";
+ static constexpr auto options = ""; };
+
+ struct Realname: Column { static constexpr auto name = "realname_";
+ static constexpr auto options = ""; };
+
+ struct AfterConnectionCommand: Column { static constexpr auto name = "afterConnectionCommand_";
+ static constexpr auto options = ""; };
+
+ struct TrustedFingerprint: Column { static constexpr auto name = "trustedFingerprint_";
+ static constexpr auto options = ""; };
+
+ struct EncodingOut: Column { static constexpr auto name = "encodingOut_";
+ static constexpr auto options = ""; };
+
+ struct EncodingIn: Column { static constexpr auto name = "encodingIn_";
+ static constexpr auto options = ""; };
+
+ struct MaxHistoryLength: Column { static constexpr auto name = "maxHistoryLength_";
+ static constexpr auto options = "";
+ MaxHistoryLength(): Column(20) {} };
+
+ struct RecordHistory: Column { static constexpr auto name = "recordHistory_";
+ static constexpr auto options = "";
+ RecordHistory(): Column(true) {}};
+
+ struct VerifyCert: Column { static constexpr auto name = "verifyCert_";
+ static constexpr auto options = "";
+ VerifyCert(): Column(true) {} };
+
+ struct Persistent: Column { static constexpr auto name = "persistent_";
+ static constexpr auto options = "";
+ Persistent(): Column(false) {} };
+
+ using MucLogLineTable = Table;
+ using MucLogLine = MucLogLineTable::RowType;
+
+ using GlobalOptionsTable = Table;
+ using GlobalOptions = GlobalOptionsTable::RowType;
+
+ using IrcServerOptionsTable = Table;
+ using IrcServerOptions = IrcServerOptionsTable::RowType;
+
+ using IrcChannelOptionsTable = Table;
+ using IrcChannelOptions = IrcChannelOptionsTable::RowType;
+
Database() = default;
~Database() = default;
@@ -25,42 +110,40 @@ public:
Database& operator=(const Database&) = delete;
Database& operator=(Database&&) = delete;
- static void set_verbose(const bool val);
-
- template
- static size_t count()
- {
- return litesql::select(*Database::db).count();
- }
- /**
- * Return the object from the db. Create it beforehand (with all default
- * values) if it is not already present.
- */
- static db::GlobalOptions get_global_options(const std::string& owner);
- static db::IrcServerOptions get_irc_server_options(const std::string& owner,
+ static GlobalOptions get_global_options(const std::string& owner);
+ static IrcServerOptions get_irc_server_options(const std::string& owner,
const std::string& server);
- static db::IrcChannelOptions get_irc_channel_options(const std::string& owner,
- const std::string& server,
- const std::string& channel);
- static db::IrcChannelOptions get_irc_channel_options_with_server_default(const std::string& owner,
- const std::string& server,
- const std::string& channel);
- static db::IrcChannelOptions get_irc_channel_options_with_server_and_global_default(const std::string& owner,
- const std::string& server,
- const std::string& channel);
- static std::vector get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
- int limit=-1, const std::string& start="", const std::string& end="");
- static std::string store_muc_message(const std::string& owner, const Iid& iid,
- time_point date, const std::string& body, const std::string& nick);
+ static IrcChannelOptions get_irc_channel_options(const std::string& owner,
+ const std::string& server,
+ const std::string& channel);
+ static IrcChannelOptions get_irc_channel_options_with_server_default(const std::string& owner,
+ const std::string& server,
+ const std::string& channel);
+ static IrcChannelOptions get_irc_channel_options_with_server_and_global_default(const std::string& owner,
+ const std::string& server,
+ const std::string& channel);
+ static std::vector get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+ int limit=-1, const std::string& start="", const std::string& end="");
+ static std::string store_muc_message(const std::string& owner, const std::string& chan_name, const std::string& server_name,
+ time_point date, const std::string& body, const std::string& nick);
static void close();
- static void open(const std::string& filename, const std::string& db_type="sqlite3");
+ static void open(const std::string& filename);
+ template
+ static int64_t count(const TableType& table)
+ {
+ CountQuery query{table.get_name()};
+ return query.execute(Database::db);
+ }
-private:
+ static MucLogLineTable muc_log_lines;
+ static GlobalOptionsTable global_options;
+ static IrcServerOptionsTable irc_server_options;
+ static IrcChannelOptionsTable irc_channel_options;
+ static sqlite3* db;
+
+ private:
static std::string gen_uuid();
- static std::unique_ptr db;
};
#endif /* USE_DATABASE */
-
-
diff --git a/src/database/insert_query.hpp b/src/database/insert_query.hpp
new file mode 100644
index 0000000..4965fc0
--- /dev/null
+++ b/src/database/insert_query.hpp
@@ -0,0 +1,129 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+
+template
+typename std::enable_if, Id>::value, void>::type
+actual_bind(Statement& statement, std::vector& params, const std::tuple&)
+{
+ const auto value = params.front();
+ params.erase(params.begin());
+ if (sqlite3_bind_text(statement.get(), N + 1, value.data(), static_cast(value.size()), SQLITE_TRANSIENT) != SQLITE_OK)
+ log_error("Failed to bind ", value, " to param ", N);
+ else
+ log_debug("Bound (not id) [", value, "] to ", N);
+}
+
+template
+typename std::enable_if, Id>::value, void>::type
+actual_bind(Statement& statement, std::vector&, const std::tuple& columns)
+{
+ auto&& column = std::get(columns);
+ if (column.value != 0)
+ {
+ if (sqlite3_bind_int64(statement.get(), N + 1, static_cast(column.value)) != SQLITE_OK)
+ log_error("Failed to bind ", column.value, " to id.");
+ }
+ else if (sqlite3_bind_null(statement.get(), N + 1) != SQLITE_OK)
+ log_error("Failed to bind NULL to param ", N);
+ else
+ log_debug("Bound NULL to ", N);
+}
+
+struct InsertQuery: public Query
+{
+ InsertQuery(const std::string& name):
+ Query("INSERT OR REPLACE INTO ")
+ {
+ this->body += name;
+ }
+
+ template
+ void execute(const std::tuple& columns, sqlite3* db)
+ {
+ auto statement = this->prepare(db);
+ {
+ this->bind_param<0>(columns, statement);
+ if (sqlite3_step(statement.get()) != SQLITE_DONE)
+ log_error("Failed to execute query: ", sqlite3_errmsg(db));
+ }
+ }
+
+ template
+ typename std::enable_if::type
+ bind_param(const std::tuple& columns, Statement& statement)
+ {
+ using ColumnType = typename std::remove_reference(columns))>::type;
+
+ actual_bind(statement, this->params, columns);
+ this->bind_param(columns, statement);
+ }
+
+ template
+ typename std::enable_if::type
+ bind_param(const std::tuple&, Statement&)
+ {}
+
+ template
+ void insert_values(const std::tuple& columns)
+ {
+ this->body += "VALUES (";
+ this->insert_value<0>(columns);
+ this->body += ")";
+ }
+
+ template
+ typename std::enable_if::type
+ insert_value(const std::tuple& columns)
+ {
+ this->body += "?";
+ if (N != sizeof...(T) - 1)
+ this->body += ",";
+ this->body += " ";
+ add_param(*this, std::get(columns));
+ this->insert_value(columns);
+ }
+ template
+ typename std::enable_if::type
+ insert_value(const std::tuple&)
+ { }
+
+ template
+ void insert_col_names(const std::tuple& columns)
+ {
+ this->body += " (";
+ this->insert_col_name<0>(columns);
+ this->body += ")\n";
+ }
+
+ template
+ typename std::enable_if::type
+ insert_col_name(const std::tuple& columns)
+ {
+ using ColumnType = typename std::remove_reference(columns))>::type;
+
+ this->body += ColumnType::name;
+
+ if (N < (sizeof...(T) - 1))
+ this->body += ", ";
+
+ this->insert_col_name(columns);
+ }
+ template
+ typename std::enable_if::type
+ insert_col_name(const std::tuple&)
+ {}
+
+
+ private:
+};
diff --git a/src/database/query.cpp b/src/database/query.cpp
new file mode 100644
index 0000000..fb8c055
--- /dev/null
+++ b/src/database/query.cpp
@@ -0,0 +1,11 @@
+#include
+#include
+
+template <>
+void add_param(Query&, const Id&)
+{}
+
+void actual_add_param(Query& query, const std::string& val)
+{
+ query.params.push_back(val);
+}
diff --git a/src/database/query.hpp b/src/database/query.hpp
new file mode 100644
index 0000000..b77a421
--- /dev/null
+++ b/src/database/query.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include
+
+#include
+
+#include
+#include
+
+#include
+
+struct Query
+{
+ std::string body;
+ std::vector params;
+
+ Query(std::string str):
+ body(std::move(str))
+ {}
+
+ Statement prepare(sqlite3* db)
+ {
+ sqlite3_stmt* statement;
+ log_debug(this->body);
+ auto res = sqlite3_prepare(db, this->body.data(), static_cast(this->body.size()) + 1,
+ &statement, nullptr);
+ if (res != SQLITE_OK)
+ {
+ log_error("Error preparing statement: ", sqlite3_errmsg(db));
+ return nullptr;
+ }
+ return {statement};
+ }
+};
+
+template
+void add_param(Query& query, const ColumnType& column)
+{
+ actual_add_param(query, column.value);
+}
+
+template
+void actual_add_param(Query& query, const T& val)
+{
+ query.params.push_back(std::to_string(val));
+}
+
+void actual_add_param(Query& query, const std::string& val);
diff --git a/src/database/row.hpp b/src/database/row.hpp
new file mode 100644
index 0000000..b6887cb
--- /dev/null
+++ b/src/database/row.hpp
@@ -0,0 +1,75 @@
+#pragma once
+
+#include
+#include
+
+#include
+
+#include
+
+template
+typename std::enable_if, Id>::value, void>::type
+update_id(std::tuple&, sqlite3*)
+{}
+
+template
+typename std::enable_if, Id>::value, void>::type
+update_id(std::tuple& columns, sqlite3* db)
+{
+ auto&& column = std::get(columns);
+ log_debug("Found an autoincrement col.");
+ auto res = sqlite3_last_insert_rowid(db);
+ log_debug("Value is now: ", res);
+ column.value = static_cast(res);
+}
+
+template
+typename std::enable_if::type
+update_autoincrement_id(std::tuple& columns, sqlite3* db)
+{
+ using ColumnType = typename std::remove_reference(columns))>::type;
+ update_id(columns, db);
+ update_autoincrement_id(columns, db);
+}
+
+template
+typename std::enable_if::type
+update_autoincrement_id(std::tuple&, sqlite3*)
+{}
+
+template
+struct Row
+{
+ Row(std::string name):
+ table_name(std::move(name))
+ {}
+
+ template
+ auto& col()
+ {
+ auto&& col = std::get(this->columns);
+ return col.value;
+ }
+
+ template
+ const auto& col() const
+ {
+ auto&& col = std::get(this->columns);
+ return col.value;
+ }
+
+ void save(sqlite3* db)
+ {
+ InsertQuery query(this->table_name);
+ query.insert_col_names(this->columns);
+ query.insert_values(this->columns);
+ log_debug(query.body);
+
+ query.execute(this->columns, db);
+
+ update_autoincrement_id<0>(this->columns, db);
+ }
+
+ std::tuple columns;
+ std::string table_name;
+};
diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp
new file mode 100644
index 0000000..d0c1d59
--- /dev/null
+++ b/src/database/select_query.hpp
@@ -0,0 +1,153 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+
+using namespace std::string_literals;
+
+template
+typename std::enable_if::value, sqlite3_int64>::type
+extract_row_value(Statement& statement, const int i)
+{
+ return sqlite3_column_int64(statement.get(), i);
+}
+
+template
+typename std::enable_if::value, std::string>::type
+extract_row_value(Statement& statement, const int i)
+{
+ const auto size = sqlite3_column_bytes(statement.get(), i);
+ const unsigned char* str = sqlite3_column_text(statement.get(), i);
+ std::string result(reinterpret_cast(str), static_cast(size));
+ return result;
+}
+
+template
+typename std::enable_if::type
+extract_row_values(Row& row, Statement& statement)
+{
+ using ColumnType = typename std::remove_reference(row.columns))>::type;
+
+ auto&& column = std::get(row.columns);
+ column.value = static_cast(extract_row_value(statement, N));
+
+ extract_row_values(row, statement);
+}
+
+template
+typename std::enable_if::type
+extract_row_values(Row&, Statement&)
+{}
+
+template
+struct SelectQuery: public Query
+{
+ SelectQuery(std::string table_name):
+ Query("SELECT"),
+ table_name(table_name)
+ {
+ this->insert_col_name<0>();
+ this->body += " from " + this->table_name;
+ }
+
+ template
+ typename std::enable_if::type
+ insert_col_name()
+ {
+ using ColumnsType = std::tuple;
+ using ColumnType = typename std::remove_reference(std::declval()))>::type;
+
+ this->body += " "s + ColumnType::name;
+
+ if (N < (sizeof...(T) - 1))
+ this->body += ", ";
+
+ this->insert_col_name();
+ }
+ template
+ typename std::enable_if::type
+ insert_col_name()
+ {}
+
+ SelectQuery& where()
+ {
+ this->body += " WHERE ";
+ return *this;
+ };
+
+ SelectQuery& order_by()
+ {
+ this->body += " ORDER BY ";
+ return *this;
+ }
+
+ SelectQuery& limit()
+ {
+ this->body += " LIMIT ";
+ return *this;
+ }
+
+ auto execute(sqlite3* db)
+ {
+ auto statement = this->prepare(db);
+ int i = 1;
+ for (const std::string& param: this->params)
+ {
+ if (sqlite3_bind_text(statement.get(), i, param.data(), static_cast(param.size()), SQLITE_TRANSIENT) != SQLITE_OK)
+ log_debug("Failed to bind ", param, " to param ", i);
+ else
+ log_debug("Bound ", param, " to ", i);
+
+ i++;
+ }
+ std::vector> rows;
+ while (sqlite3_step(statement.get()) == SQLITE_ROW)
+ {
+ Row row(this->table_name);
+ extract_row_values(row, statement);
+ rows.push_back(row);
+ }
+ return rows;
+ }
+
+ const std::string table_name;
+};
+
+template
+typename std::enable_if::value, SelectQuery&>::type
+operator<<(SelectQuery& query, const T&)
+{
+ query.body += T::name;
+ return query;
+}
+
+template
+SelectQuery& operator<<(SelectQuery& query, const char* str)
+{
+ query.body += str;
+ return query;
+}
+
+template
+SelectQuery& operator<<(SelectQuery& query, const std::string& str)
+{
+ query.body += "?";
+ actual_add_param(query, str);
+ return query;
+}
+
+template
+typename std::enable_if::value, SelectQuery&>::type
+operator<<(SelectQuery& query, const Integer& i)
+{
+ query.body += "?";
+ actual_add_param(query, i);
+ return query;
+}
diff --git a/src/database/statement.hpp b/src/database/statement.hpp
new file mode 100644
index 0000000..87cd70f
--- /dev/null
+++ b/src/database/statement.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include
+
+class Statement
+{
+ public:
+ Statement(sqlite3_stmt* stmt):
+ stmt(stmt) {}
+ ~Statement()
+ {
+ sqlite3_finalize(this->stmt);
+ }
+
+ Statement(const Statement&) = delete;
+ Statement& operator=(const Statement&) = delete;
+ Statement(Statement&& other):
+ stmt(other.stmt)
+ {
+ other.stmt = nullptr;
+ }
+ Statement& operator=(Statement&& other)
+ {
+ this->stmt = other.stmt;
+ other.stmt = nullptr;
+ return *this;
+ }
+ sqlite3_stmt* get()
+ {
+ return this->stmt;
+ }
+
+ private:
+ sqlite3_stmt* stmt;
+};
diff --git a/src/database/table.hpp b/src/database/table.hpp
new file mode 100644
index 0000000..163b97f
--- /dev/null
+++ b/src/database/table.hpp
@@ -0,0 +1,84 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+template