Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in upstream changes #67

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
needs: clang-format
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: create version.h
run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
needs: clang-format
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: create version.h
run: |
git_hash=$(git rev-parse --short "${{ github.event.pull_request.head.sha }}")
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*.nso
*.pfs0
*.smdh
*~
.gdb_history
3ds/build
3ds-classic/build
Expand All @@ -24,7 +25,7 @@ switch-classic/build
switch/romfs/*.zst
switch/romfs/shaders/*.dksh
.idea/
build/
build*/
*.rpx
*.wuhb
*.wps
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3rd/gls"]
path = 3rd/gls
url = [email protected]:microsoft/GSL.git
1 change: 1 addition & 0 deletions 3rd/gls
Submodule gls added at a35345
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ WUPS_ROOT := $(DEVKITPRO)/wups
#-------------------------------------------------------------------------------
TARGET := ftpiiu
BUILD := build
SOURCES := source source/wiiu
SOURCES := source source/wiiu source/posix
DATA := data
INCLUDES := source include
INCLUDES := source include 3rd/gls/include

#-------------------------------------------------------------------------------
# options for code generation
Expand Down
28 changes: 14 additions & 14 deletions include/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2020 Michael Theall
// Copyright (C) 2024 Michael Theall
//
// 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
Expand All @@ -22,13 +22,16 @@

#include "ioBuffer.h"

#include <gsl/gsl>

#include <dirent.h>

#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <string_view>
#include <vector>

namespace fs
{
Expand Down Expand Up @@ -69,21 +72,21 @@ class File
/// \brief Open file
/// \param path_ Path to open
/// \param mode_ Access mode (\sa std::fopen)
bool open (char const *path_, char const *mode_ = "rb");
bool open (gsl::not_null<gsl::czstring> path_, gsl::not_null<gsl::czstring> mode_ = "rb");

/// \brief Close file
void close ();

/// \brief Seek to file position
/// \param pos_ File position
/// \param origin_ Reference position (\sa std::fseek)
std::make_signed_t<std::size_t> seek (std::size_t pos_, int origin_);
std::make_signed_t<std::size_t> seek (std::make_signed_t<std::size_t> pos_, int origin_);

/// \brief Read data
/// \param buffer_ Output buffer
/// \param size_ Size to read
/// \note Can return partial reads
std::make_signed_t<std::size_t> read (void *buffer_, std::size_t size_);
std::make_signed_t<std::size_t> read (gsl::not_null<void *> buffer_, std::size_t size_);

/// \brief Read data
/// \param buffer_ Output buffer
Expand All @@ -97,13 +100,13 @@ class File
/// \param buffer_ Output buffer
/// \param size_ Size to read
/// \note Fails on partial reads and errors
bool readAll (void *buffer_, std::size_t size_);
bool readAll (gsl::not_null<void *> buffer_, std::size_t size_);

/// \brief Write data
/// \param buffer_ Input data
/// \param size_ Size to write
/// \note Can return partial writes
std::make_signed_t<std::size_t> write (void const *buffer_, std::size_t size_);
std::make_signed_t<std::size_t> write (gsl::not_null<void const *> buffer_, std::size_t size_);

/// \brief Write data
/// \param buffer_ Input data
Expand All @@ -114,20 +117,17 @@ class File
/// \param buffer_ Input data
/// \param size_ Size to write
/// \note Fails on partials writes and errors
bool writeAll (void const *buffer_, std::size_t size_);
bool writeAll (gsl::not_null<void const *> buffer_, std::size_t size_);

private:
/// \brief Underlying std::FILE*
std::unique_ptr<std::FILE, int (*) (std::FILE *)> m_fp{nullptr, nullptr};

/// \brief Buffer
std::unique_ptr<char[]> m_buffer;

/// \brief Buffer size
std::size_t m_bufferSize = 0;
std::vector<char> m_buffer;

/// \brief Line buffer
char *m_lineBuffer = nullptr;
gsl::owner<char *> m_lineBuffer = nullptr;

/// \brief Line buffer size
std::size_t m_lineBufferSize = 0;
Expand Down Expand Up @@ -161,14 +161,14 @@ class Dir

/// \brief Open directory
/// \param path_ Path to open
bool open (char const *const path_);
bool open (gsl::not_null<gsl::czstring> path_);

/// \brief Close directory
void close ();

/// \brief Read a directory entry
/// \note Returns nullptr on end-of-directory or error; check errno
struct dirent *read ();
dirent *read ();

private:
/// \brief Underlying DIR*
Expand Down
33 changes: 23 additions & 10 deletions include/ftpConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2022 Michael Theall
// Copyright (C) 2024 Michael Theall
//
// 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
Expand All @@ -22,10 +22,13 @@

#include "platform.h"

#include <gsl/gsl>

#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <string_view>

class FtpConfig;
using UniqueFtpConfig = std::unique_ptr<FtpConfig>;
Expand All @@ -41,22 +44,25 @@ class FtpConfig

/// \brief Load config
/// \param path_ Path to config file
static UniqueFtpConfig load (char const *path_);
static UniqueFtpConfig load (gsl::not_null<gsl::czstring> path_);

#ifndef NDS
#ifndef __NDS__
std::scoped_lock<platform::Mutex> lockGuard ();
#endif

/// \brief Save config
/// \param path_ Path to config file
bool save (char const *path_);
bool save (gsl::not_null<gsl::czstring> path_);

/// \brief Get user
std::string const &user () const;

/// \brief Get password
std::string const &pass () const;

/// \brief Get hostname
std::string const &hostname () const;

/// \brief Get port
std::uint16_t port () const;

Expand All @@ -79,15 +85,19 @@ class FtpConfig

/// \brief Set user
/// \param user_ User
void setUser (std::string const &user_);
void setUser (std::string user_);

/// \brief Set password
/// \param pass_ Password
void setPass (std::string const &pass_);
void setPass (std::string pass_);

/// \brief Set hostname
/// \param hostname_ Hostname
void setHostname (std::string hostname_);

/// \brief Set listen port
/// \param port_ Listen port
bool setPort (std::string const &port_);
bool setPort (std::string_view port_);

/// \brief Set listen port
/// \param port_ Listen port
Expand All @@ -106,17 +116,17 @@ class FtpConfig

/// \brief Set access point SSID
/// \param ssid_ SSID
void setSSID (std::string const &ssid_);
void setSSID (std::string_view ssid_);

/// \brief Set access point passphrase
/// \param passphrase_ Passphrase
void setPassphrase (std::string const &passphrase_);
void setPassphrase (std::string_view passphrase_);
#endif

private:
FtpConfig ();

#ifndef NDS
#ifndef __NDS__
/// \brief Mutex
mutable platform::Mutex m_lock;
#endif
Expand All @@ -127,6 +137,9 @@ class FtpConfig
/// \brief Password
std::string m_pass;

/// \brief Hostname
std::string m_hostname;

/// \brief Listen port
std::uint16_t m_port;

Expand Down
26 changes: 21 additions & 5 deletions include/ftpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2022 Michael Theall
// Copyright (C) 2024 Michael Theall
//
// 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
Expand Down Expand Up @@ -48,6 +48,9 @@ class FtpServer
/// \brief Draw server and all of its sessions
void draw ();

/// \brief Whether server wants to quit
bool quit ();

/// \brief Create server
static UniqueFtpServer create ();

Expand All @@ -60,6 +63,11 @@ class FtpServer
/// \brief Server start time
static std::time_t startTime ();

#ifdef __3DS__
/// \brief Get timezone offset in seconds (only used on 3DS)
static int tzOffset ();
#endif

private:
/// \brief Paramterized constructor
/// \param config_ FTP config
Expand Down Expand Up @@ -88,7 +96,7 @@ class FtpServer
/// \brief Thread entry point
void threadFunc ();

#ifndef NDS
#ifndef __NDS__
/// \brief Thread
platform::Thread m_thread;

Expand All @@ -102,14 +110,19 @@ class FtpServer
/// \brief Listen socket
UniqueSocket m_socket;

#ifndef __NDS__
/// \brief mDNS socket
UniqueSocket m_mdnsSocket;
#endif

/// \brief ImGui window name
std::string m_name;

/// \brief Sessions
std::vector<UniqueFtpSession> m_sessions;

/// \brief Whether thread should quit
std::atomic<bool> m_quit;
std::atomic_bool m_quit = false;

#ifndef CLASSIC
/// \brief Log upload cURL context
Expand Down Expand Up @@ -143,8 +156,11 @@ class FtpServer
/// \brief Password setting
std::string m_passSetting;

/// \brief Hostname setting
std::string m_hostnameSetting;

/// \brief Port setting
std::uint16_t m_portSetting;
std::uint16_t m_portSetting = 0;

#ifdef __3DS__
/// \brief getMTime setting
Expand All @@ -153,7 +169,7 @@ class FtpServer

#ifdef __SWITCH__
/// \brief Whether an error occurred enabling access point
std::atomic<bool> m_apError = false;
std::atomic_bool m_apError = false;

/// \brief Enable access point setting
bool m_enableAPSetting;
Expand Down
Loading