ftpiiu_plugin/include/ftpServer.h

169 lines
3.7 KiB
C
Raw Normal View History

2020-04-05 21:16:16 +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
//
2022-10-04 04:52:19 +02:00
// Copyright (C) 2022 Michael Theall
2020-04-05 21:16:16 +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-04-24 22:51:43 +02:00
#include "ftpConfig.h"
2020-04-05 21:16:16 +02:00
#include "ftpSession.h"
#include "platform.h"
#include "socket.h"
2022-10-04 04:52:19 +02:00
#ifndef CLASSIC
#include <curl/curl.h>
#endif
2020-04-05 21:16:16 +02:00
#include <atomic>
#include <chrono>
#include <cstdint>
#include <memory>
2020-04-23 00:15:23 +02:00
#include <string>
2020-04-05 21:16:16 +02:00
#include <vector>
class FtpServer;
using UniqueFtpServer = std::unique_ptr<FtpServer>;
2020-04-06 07:36:03 +02:00
/// \brief FTP server
2020-04-05 21:16:16 +02:00
class FtpServer
{
public:
~FtpServer ();
2020-04-06 07:36:03 +02:00
/// \brief Draw server and all of its sessions
2020-04-05 21:16:16 +02:00
void draw ();
2020-04-06 07:36:03 +02:00
/// \brief Create server
2020-04-24 22:51:43 +02:00
static UniqueFtpServer create ();
2020-04-05 21:16:16 +02:00
2020-04-23 00:15:23 +02:00
/// \brief Get free space
static std::string getFreeSpace ();
2020-04-06 07:36:03 +02:00
/// \brief Update free space
2020-04-05 21:16:16 +02:00
static void updateFreeSpace ();
2020-04-06 07:36:03 +02:00
/// \brief Server start time
2020-04-05 21:16:16 +02:00
static std::time_t startTime ();
private:
2020-04-06 07:36:03 +02:00
/// \brief Paramterized constructor
2020-04-24 22:51:43 +02:00
/// \param config_ FTP config
FtpServer (UniqueFtpConfig config_);
2020-04-05 21:16:16 +02:00
/// \brief Handle when network is found
void handleNetworkFound ();
2020-04-06 07:36:03 +02:00
/// \brief Handle when network is lost
void handleNetworkLost ();
2020-04-05 21:16:16 +02:00
2020-12-12 02:15:33 +01:00
#ifndef CLASSIC
2020-04-24 22:51:43 +02:00
/// \brief Show menu in the current window
void showMenu ();
2020-04-26 00:47:55 +02:00
/// \brief Show settings menu
void showSettings ();
/// \brief Show about window
void showAbout ();
2020-12-12 02:15:33 +01:00
#endif
2020-04-26 00:47:55 +02:00
2020-04-06 07:36:03 +02:00
/// \brief Server loop
2020-04-05 21:16:16 +02:00
void loop ();
2020-04-06 07:36:03 +02:00
/// \brief Thread entry point
2020-04-05 21:16:16 +02:00
void threadFunc ();
2020-04-17 22:32:39 +02:00
#ifndef NDS
2020-04-06 07:36:03 +02:00
/// \brief Thread
2020-04-05 21:16:16 +02:00
platform::Thread m_thread;
2020-04-06 07:36:03 +02:00
/// \brief Mutex
2020-04-05 21:16:16 +02:00
platform::Mutex m_lock;
2020-04-17 22:32:39 +02:00
#endif
2020-04-05 21:16:16 +02:00
2020-04-24 22:51:43 +02:00
/// \brief Config
UniqueFtpConfig m_config;
2020-04-06 07:36:03 +02:00
/// \brief Listen socket
2020-04-05 21:16:16 +02:00
UniqueSocket m_socket;
2020-04-06 07:36:03 +02:00
/// \brief ImGui window name
2020-04-05 21:16:16 +02:00
std::string m_name;
2020-04-06 07:36:03 +02:00
/// \brief Sessions
2020-04-05 21:16:16 +02:00
std::vector<UniqueFtpSession> m_sessions;
2020-04-06 07:36:03 +02:00
/// \brief Whether thread should quit
2020-04-05 21:16:16 +02:00
std::atomic<bool> m_quit;
2020-04-24 22:51:43 +02:00
2022-10-04 04:52:19 +02:00
#ifndef CLASSIC
/// \brief Log upload cURL context
CURLM *m_uploadLogCurlM = nullptr;
/// \brief Log upload mime context
curl_mime *m_uploadLogMime = nullptr;
/// \brief Log upload cURL context
std::atomic<CURL *> m_uploadLogCurl = nullptr;
/// \brief Log upload data
std::string m_uploadLogData;
/// \brief Log upload result
std::string m_uploadLogResult;
#endif
2020-04-24 22:51:43 +02:00
#ifndef CLASSIC
/// \brief Whether to show settings menu
bool m_showSettings = false;
2020-12-12 02:15:33 +01:00
#ifdef __SWITCH__
/// \brief Whether to show access point menu
bool m_showAP = false;
#endif
2020-04-26 00:47:55 +02:00
/// \brief Whether to show about window
bool m_showAbout = false;
2020-04-24 22:51:43 +02:00
/// \brief User name setting
std::string m_userSetting;
/// \brief Password setting
std::string m_passSetting;
/// \brief Port setting
std::uint16_t m_portSetting;
2022-03-31 18:53:47 +02:00
#ifdef __3DS__
2020-04-24 22:51:43 +02:00
/// \brief getMTime setting
bool m_getMTimeSetting;
#endif
2020-12-12 02:15:33 +01:00
#ifdef __SWITCH__
/// \brief Whether an error occurred enabling access point
std::atomic<bool> m_apError = false;
/// \brief Enable access point setting
bool m_enableAPSetting;
/// \brief Access point SSID setting
std::string m_ssidSetting;
/// \brief Access point passphrase setting
std::string m_passphraseSetting;
#endif
2020-04-24 22:51:43 +02:00
#endif
2020-04-05 21:16:16 +02:00
};