summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Rozanov <daniilrozzanov@gmail.com>2023-07-05 03:11:34 +0300
committerDaniil Rozanov <daniilrozzanov@gmail.com>2023-07-05 03:11:34 +0300
commitd3f11e3b7b86eda4733ece84294d9dc8da1d23bc (patch)
tree860fea9c8e63d0f62e28a513c0e50d2d7171a8d4
parentf51c3ac3f1c0cac99eb8cfe91b280d84f128cdc9 (diff)
Added declaration of connection class with connect and execute members. Created detail and impl folder. Created one example's fileHEADmain
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt37
-rw-r--r--conanfile.txt1
-rw-r--r--examples/CMakeLists.txt2
-rw-r--r--examples/connect.cpp1
-rw-r--r--include/ftp/connection.hpp30
-rw-r--r--include/ftp/detail/network_algorithms.hpp31
-rw-r--r--include/ftp/error_code.hpp10
-rw-r--r--include/ftp/handshake_params.hpp16
-rw-r--r--include/ftp/impl/networking_algorithms.cpp34
-rw-r--r--tests/CMakeLists.txt (renamed from examples/connect.hpp)0
11 files changed, 162 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4469528
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+**/build
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3d04ea4..b332a52 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,3 +3,40 @@ project(
ftp
VERSION 0.0.1
LANGUAGES CXX)
+
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
+option(FTP_BUILD_TESTS "Enable tests build" OFF)
+option(FTP_BUILD_EXAMPLES "Enable examples build" ON)
+option(FTP_HEADER_ONLY "Install as header only" ON)
+
+find_package(Boost 1.82.0 REQUIRED COMPONENTS system thread regex context)
+
+add_library(ftp INTERFACE)
+add_library(ftp::ftp ALIAS ftp)
+
+target_include_directories(
+ ftp INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+ $<INSTALL_INTERFACE:include>)
+
+target_compile_features(ftp INTERFACE cxx_std_17)
+
+if(FTP_HEADER_ONLY)
+ target_compile_definitions(ftp INTERFACE "FTP_HEADER_ONLY")
+ target_sources(ftp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include/ftp/impl)
+endif()
+
+target_link_libraries(ftp INTERFACE Boost::thread)
+
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+if(FTP_BUILD_TESTS)
+ message("Building tests")
+ add_subdirectory(tests)
+endif()
+
+message(${FTP_BUILD_EXAMPLES})
+if(FTP_BUILD_EXAMPLES)
+ message("Building examples")
+ add_subdirectory(examples)
+endif()
diff --git a/conanfile.txt b/conanfile.txt
index 329f801..f688e47 100644
--- a/conanfile.txt
+++ b/conanfile.txt
@@ -1,5 +1,4 @@
[requires]
-range-v3/0.12.0
boost/1.82.0
[generators]
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..4ab084f
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(connect connect.cpp)
+target_link_libraries(connect ftp::ftp)
diff --git a/examples/connect.cpp b/examples/connect.cpp
new file mode 100644
index 0000000..76e8197
--- /dev/null
+++ b/examples/connect.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/include/ftp/connection.hpp b/include/ftp/connection.hpp
index e69de29..f0291f3 100644
--- a/include/ftp/connection.hpp
+++ b/include/ftp/connection.hpp
@@ -0,0 +1,30 @@
+#ifndef _CONNECTION_HPP_
+#define _CONNECTION_HPP_
+
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/ip/tcp.hpp>
+#include <ftp/error_code.hpp>
+#include <ftp/handshake_params.hpp>
+
+namespace ftp {
+namespace asio = boost::asio;
+
+using boost::asio::ip::tcp;
+
+class connection
+{
+ asio::io_context& ioc_;
+ tcp::socket cmd_socket_;
+
+public:
+ connection(asio::io_context& ioc) : ioc_(ioc), cmd_socket_(ioc_){};
+
+ void connect(const tcp::resolver::results_type& endpoints, const handshake_params& params);
+
+ void connect(const tcp::resolver::results_type& endpoint, const handshake_params& params, error_code& ec);
+
+ void execute(const std::string& command);
+};
+} // namespace ftp
+
+#endif // !_CONNECTION_HPP_
diff --git a/include/ftp/detail/network_algorithms.hpp b/include/ftp/detail/network_algorithms.hpp
new file mode 100644
index 0000000..159e6e2
--- /dev/null
+++ b/include/ftp/detail/network_algorithms.hpp
@@ -0,0 +1,31 @@
+#ifndef _NETWORKING_ALGORITHMS_HPP_
+#define _NETWORKING_ALGORITHMS_HPP_
+
+#include <boost/asio/ip/tcp.hpp>
+#include <ftp/error_code.hpp>
+#include <ftp/handshake_params.hpp>
+
+namespace ftp {
+
+namespace detail {
+
+using boost::asio::ip::tcp;
+
+inline void connect_interface(
+ tcp::socket& socket,
+ const tcp::resolver::results_type& endpoints,
+ const handshake_params& params,
+ error_code& ec
+);
+
+inline void handshake_interface(tcp::socket& socket, const handshake_params& params, error_code& ec);
+
+} // namespace detail
+
+} // namespace ftp
+
+#ifdef FTP_HEADER_ONLY
+#include <ftp/impl/networking_algorithms.cpp>
+#endif // FTP_HEADER_ONLY
+
+#endif // !_NETWORKING_ALGORITHMS_HPP_
diff --git a/include/ftp/error_code.hpp b/include/ftp/error_code.hpp
new file mode 100644
index 0000000..a3f789f
--- /dev/null
+++ b/include/ftp/error_code.hpp
@@ -0,0 +1,10 @@
+#ifndef _ERROR_CODE_HPP
+#define _ERROR_CODE_HPP
+
+#include <boost/system/detail/error_code.hpp>
+
+namespace ftp {
+using error_code = boost::system::error_code;
+}
+
+#endif // !_ERROR_CODE_HPP
diff --git a/include/ftp/handshake_params.hpp b/include/ftp/handshake_params.hpp
new file mode 100644
index 0000000..a616c20
--- /dev/null
+++ b/include/ftp/handshake_params.hpp
@@ -0,0 +1,16 @@
+#ifndef _HANDSHAKE_PARAMS_HPP_
+#define _HANDSHAKE_PARAMS_HPP_
+
+#include <string>
+
+namespace ftp {
+class handshake_params
+{
+ std::string host_;
+ std::string username_;
+ std::string password_;
+ int port;
+};
+} // namespace ftp
+
+#endif // !_HANDSHAKE_PARAMS_HPP_
diff --git a/include/ftp/impl/networking_algorithms.cpp b/include/ftp/impl/networking_algorithms.cpp
new file mode 100644
index 0000000..9920cfb
--- /dev/null
+++ b/include/ftp/impl/networking_algorithms.cpp
@@ -0,0 +1,34 @@
+#ifndef _NETWORKING_ALGORITHMS_CPP_
+#define _NETWORKING_ALGORITHMS_CPP_
+
+#pragma once
+
+#include <boost/asio/connect.hpp>
+#include <ftp/detail/network_algorithms.hpp>
+#include <ftp/handshake_params.hpp>
+
+namespace asio = boost::asio;
+
+inline void ftp::detail::connect_interface(
+ tcp::socket& socket,
+ const tcp::resolver::results_type& endpoints,
+ const handshake_params& params,
+ error_code& ec
+)
+{
+ asio::connect(socket, endpoints, ec);
+ if (ec)
+ {
+ return;
+ }
+}
+
+inline void ftp::detail::handshake_interface(
+ tcp::socket& socket,
+ const handshake_params& params,
+ error_code& ec
+)
+{
+}
+
+#endif
diff --git a/examples/connect.hpp b/tests/CMakeLists.txt
index e69de29..e69de29 100644
--- a/examples/connect.hpp
+++ b/tests/CMakeLists.txt