ftpiiu_plugin/include/ftpConfig.h

162 lines
3.7 KiB
C
Raw Normal View History

2020-04-24 22:51:43 +02:00
// ftpd is a server implementation based on the following:
// - RFC 959 (https://tools.ietf.org/html/rfc959)
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2024 Michael Theall
2020-04-24 22:51:43 +02:00
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#pragma once
2020-12-12 02:15:33 +01:00
#include "platform.h"
#include <gsl/gsl>
2020-04-24 22:51:43 +02:00
#include <cstdint>
#include <memory>
2020-12-12 02:15:33 +01:00
#include <mutex>
2020-04-24 22:51:43 +02:00
#include <string>
#include <string_view>
2020-04-24 22:51:43 +02:00
class FtpConfig;
using UniqueFtpConfig = std::unique_ptr<FtpConfig>;
/// \brief FTP config
class FtpConfig
{
public:
~FtpConfig ();
/// \brief Create config
static UniqueFtpConfig create ();
/// \brief Load config
/// \param path_ Path to config file
static UniqueFtpConfig load (gsl::not_null<gsl::czstring> path_);
2020-04-24 22:51:43 +02:00
#ifndef __NDS__
2022-10-04 04:52:19 +02:00
std::scoped_lock<platform::Mutex> lockGuard ();
2020-12-12 02:15:33 +01:00
#endif
2020-04-24 22:51:43 +02:00
/// \brief Save config
/// \param path_ Path to config file
bool save (gsl::not_null<gsl::czstring> path_);
2020-04-24 22:51:43 +02:00
/// \brief Get user
std::string const &user () const;
/// \brief Get password
std::string const &pass () const;
/// \brief Get hostname
std::string const &hostname () const;
2020-04-24 22:51:43 +02:00
/// \brief Get port
std::uint16_t port () const;
2022-03-31 18:53:47 +02:00
#ifdef __3DS__
2020-04-24 22:51:43 +02:00
/// \brief Whether to get mtime
/// \note only effective on 3DS
bool getMTime () const;
#endif
2020-12-12 02:15:33 +01:00
#ifdef __SWITCH__
/// \brief Whether to enable access point
bool enableAP () const;
/// \brief Access point SSID
std::string const &ssid () const;
/// \brief Access point passphrase
std::string const &passphrase () const;
#endif
2020-04-24 22:51:43 +02:00
/// \brief Set user
/// \param user_ User
void setUser (std::string user_);
2020-04-24 22:51:43 +02:00
/// \brief Set password
/// \param pass_ Password
void setPass (std::string pass_);
/// \brief Set hostname
/// \param hostname_ Hostname
void setHostname (std::string hostname_);
2020-04-24 22:51:43 +02:00
/// \brief Set listen port
/// \param port_ Listen port
bool setPort (std::string_view port_);
2020-04-24 22:51:43 +02:00
/// \brief Set listen port
/// \param port_ Listen port
bool setPort (std::uint16_t port_);
2022-03-31 18:53:47 +02:00
#ifdef __3DS__
2020-04-24 22:51:43 +02:00
/// \brief Set whether to get mtime
/// \param getMTime_ Whether to get mtime
void setGetMTime (bool getMTime_);
#endif
2020-12-12 02:15:33 +01:00
#ifdef __SWITCH__
/// \brief Set whether to enable access point
/// \param enable_ Whether to enable access point
void setEnableAP (bool enable_);
/// \brief Set access point SSID
/// \param ssid_ SSID
void setSSID (std::string_view ssid_);
2020-12-12 02:15:33 +01:00
/// \brief Set access point passphrase
/// \param passphrase_ Passphrase
void setPassphrase (std::string_view passphrase_);
2020-12-12 02:15:33 +01:00
#endif
2020-04-24 22:51:43 +02:00
private:
FtpConfig ();
#ifndef __NDS__
2020-12-12 02:15:33 +01:00
/// \brief Mutex
mutable platform::Mutex m_lock;
#endif
2020-04-24 22:51:43 +02:00
/// \brief Username
std::string m_user;
/// \brief Password
std::string m_pass;
/// \brief Hostname
std::string m_hostname;
2020-04-24 22:51:43 +02:00
/// \brief Listen port
std::uint16_t m_port;
2022-03-31 18:53:47 +02:00
#ifdef __3DS__
2020-04-24 22:51:43 +02:00
/// \brief Whether to get mtime
bool m_getMTime = true;
#endif
2020-12-12 02:15:33 +01:00
#ifdef __SWITCH__
/// \brief Whether to enable access point
bool m_enableAP = false;
/// \brief Access point SSID
std::string m_ssid = "ftpd";
/// \brief Access point passphrase
std::string m_passphrase;
#endif
2020-04-24 22:51:43 +02:00
};