From 65a8349aa5526d071b18cd4d42586c46faaa3823 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 02:13:48 +0100 Subject: feat! breaking changes for OCL v1.0.48. Signed-off-by: Amlal El Mahrouss --- dev/lib/net/modem.hpp | 167 -------------------------------------------------- dev/lib/net/url.hpp | 120 ------------------------------------ 2 files changed, 287 deletions(-) delete mode 100644 dev/lib/net/modem.hpp delete mode 100644 dev/lib/net/url.hpp (limited to 'dev/lib/net') diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp deleted file mode 100644 index d86234b..0000000 --- a/dev/lib/net/modem.hpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * File: net/modem.hpp - * Purpose: Modem concept in modern C++ - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. - */ - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#define OCL_MODEM_INTERFACE : public ocl::net::modem - -namespace ocl::net -{ - class modem; - - /// ============================================================================= - /// @brief Modem container concept, a container to read and write on a network stream. - /// ============================================================================= - class modem final - { - public: - using socket_type = int64_t; - - private: - socket_type fd_{}; - bool server_fd_{false}; - bool bad_{true}; - - public: - const bool& bad{bad_}; - - explicit modem() = default; - - ~modem() - { - this->destroy(); - } - - modem& operator=(const modem&) = delete; - modem(const modem&) = delete; - - static constexpr auto local_address_ip4 = "127.0.0.1"; - static constexpr auto local_address_ip6 = "::1"; - static constexpr const auto backlog_count = 5U; - - /// ============================================================================= - /// @brief Check if the modem is valid. - /// @return true if valid, false otherwise. - /// ============================================================================= - - bool is_valid() const noexcept - { - return this->fd_ != -1 && !this->bad_; - } - - template - bool receive(ptr_type& out, std::size_t len) noexcept - { - static_assert(std::is_pointer::value, "ptr_type is not a pointer!"); - - if (!out) - return false; - - if (!len) - return false; - - socket_type cl_{fd_}; - - if (this->server_fd_) - cl_ = ::accept(fd_, nullptr, nullptr); - - auto ret = ::recv(cl_, out, len, 0); - - return ret > 0L; - } - - template - bool transmit(ptr_type& out, std::size_t len) noexcept - { - static_assert(std::is_pointer::value, "ptr_type is not a pointer!"); - - if (!out) - return false; - - if (!len) - return false; - - auto ret = ::send(fd_, out, len, 0); - - bad_ = !(ret >= 0L); - - return ret >= 0L; - } - - template - bool transmit(const std::basic_string& out) noexcept - { - if (out.empty()) - return false; - - auto ret = ::send(fd_, out.data(), out.size(), 0); - - bad_ = !(ret >= 0L); - - return ret >= 0L; - } - - template - bool construct(const char* addr = modem::local_address_ip4, const bool& is_server = false) noexcept - { - static_assert(af != 0, "Address family is zero"); - static_assert(kind != 0, "Kind is zero"); - - must_pass(); - must_pass(); - must_pass<(port > 0) && (port < 65536)>(); - - fd_ = ::socket(af, kind, 0); - server_fd_ = is_server; - - if (fd_ == -1) - return false; - - struct sockaddr_in addr_; - std::memset(&addr_, 0, sizeof(struct sockaddr_in)); - - addr_.sin_addr.s_addr = ::inet_addr(addr); - addr_.sin_port = htons(port); - addr_.sin_family = af; - - if (!is_server) - { - const auto ret = ::connect(fd_, reinterpret_cast(&addr_), sizeof(addr_)); - return ret == 0L; - } - - int ret = ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); - - bad_ = ret == -1; - - ::listen(fd_, modem::backlog_count); - - return bad_ == false; - } - - bool destroy() noexcept - { - if (!fd_) - return false; - - ::shutdown(fd_, SHUT_RDWR); - ::close(fd_); - - fd_ = 0L; - - return true; - } - }; -} // namespace ocl::net diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp deleted file mode 100644 index 60440ad..0000000 --- a/dev/lib/net/url.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * File: net/url.hpp - * Purpose: URL container in modern C++ - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. - */ - -#pragma once - -#include -#include - -/// @author Amlal El Mahrouss (amlal@nekernel.org) -/// @brief Parse URLs (in a non-standard way). - -namespace ocl::net -{ - template - class basic_url; - - enum class url_protocol - { - invalid = 0, - http, - https, - mailto, - ftp, - tel, - bad = 0xff, - }; - - /// @brief Basic URL parser container. - template - class basic_url final - { - url_protocol m_protocol_{url_protocol::invalid}; - std::basic_stringstream m_ss_{}; - std::basic_string m_port_{""}; - - public: - explicit basic_url(const std::basic_string& protocol) - { - if (protocol.starts_with("https://")) - { - m_protocol_ = url_protocol::https; - this->operator/=(protocol.substr(std::size("https://"))); - } - else if (protocol.starts_with("http://")) - { - m_protocol_ = url_protocol::http; - this->operator/=(protocol.substr(std::size("http://"))); - } - else if (protocol.starts_with("mailto:")) - { - m_protocol_ = url_protocol::mailto; - this->operator/=(protocol.substr(std::size("mailto:"))); - } - else if (protocol.starts_with("tel:")) - { - m_protocol_ = url_protocol::tel; - this->operator/=(protocol.substr(std::size("tel:"))); - } - else if (protocol.starts_with("ftp:")) - { - m_protocol_ = url_protocol::ftp; - this->operator/=(protocol.substr(std::size("ftp:"))); - } - } - - ~basic_url() = default; - - basic_url& operator=(const basic_url&) = default; - basic_url(const basic_url&) = default; - - private: - basic_url& operator/=(const std::basic_string& in) - { - if (in.empty()) - return *this; - - if (in.starts_with(":")) - { - m_port_ = in.substr(1); - return *this; - } - - m_ss_ += in; - return *this; - } - - basic_url& operator/=(const char_type& in) - { - m_ss_ += in; - return *this; - } - - explicit operator bool() - { - return this->is_valid(); - } - - public: - auto protocol() const noexcept - { - return this->m_protocol_; - } - - auto port() const noexcept - { - return this->m_port_; - } - - auto is_valid() const noexcept - { - return m_ss_.size() > 0 && this->m_protocol_ != url_protocol::bad || this->m_protocol_ != url_protocol::invalid; - } - }; - - using url = basic_url; -} // namespace ocl::net -- cgit v1.2.3