mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-12-23 03:11:49 +01:00
Format the code via clang-format
This commit is contained in:
parent
5e6e8bdb53
commit
63f21d5a18
67
.clang-format
Normal file
67
.clang-format
Normal file
@ -0,0 +1,67 @@
|
||||
# Generated from CLion C/C++ Code Style settings
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
||||
AlignOperands: Align
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: 0
|
||||
CompactNamespaces: false
|
||||
ContinuationIndentWidth: 8
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: All
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -6,8 +6,16 @@ on:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: clang-format
|
||||
run: |
|
||||
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src
|
||||
build-binary:
|
||||
runs-on: ubuntu-18.04
|
||||
needs: clang-format
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: build binary
|
||||
|
8
.github/workflows/pr.yml
vendored
8
.github/workflows/pr.yml
vendored
@ -3,8 +3,16 @@ name: CI-PR
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: clang-format
|
||||
run: |
|
||||
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src
|
||||
build-binary:
|
||||
runs-on: ubuntu-18.04
|
||||
needs: clang-format
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: build binary
|
||||
|
@ -1,3 +1,5 @@
|
||||
[![CI-Release](https://github.com/wiiu-env/ftpiiu_plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/ftpiiu_plugin/actions/workflows/ci.yml)
|
||||
|
||||
## Usage
|
||||
(`[ENVIRONMENT]` is a placeholder for the actual environment name.)
|
||||
|
||||
@ -18,3 +20,7 @@ docker run -it --rm -v ${PWD}:/project ftpiiuplugin-builder make
|
||||
# make clean
|
||||
docker run -it --rm -v ${PWD}:/project ftpiiuplugin-builder make clean
|
||||
```
|
||||
|
||||
## Format the code via docker
|
||||
|
||||
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i`
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "BackgroundThread.hpp"
|
||||
#include <cstring>
|
||||
#include "ftp.h"
|
||||
#include "net.h"
|
||||
#include <cstring>
|
||||
|
||||
BackgroundThread *BackgroundThread::instance = nullptr;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/BackgroundThreadWrapper.hpp"
|
||||
#include <coreinit/cache.h>
|
||||
#include "utils/logger.h"
|
||||
#include <coreinit/cache.h>
|
||||
|
||||
#define PORT 21
|
||||
#define PORT 21
|
||||
|
||||
class BackgroundThread : BackgroundThreadWrapper {
|
||||
public:
|
||||
|
142
src/ftp.c
142
src/ftp.c
@ -23,40 +23,39 @@ misrepresented as being the original software.
|
||||
3.This notice may not be removed or altered from any source distribution.
|
||||
|
||||
*/
|
||||
#include "main.h"
|
||||
#include "utils/logger.h"
|
||||
#include <coreinit/thread.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/dir.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "main.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
//! TODO: fix those function
|
||||
#define gettime() OSGetTick()
|
||||
#define gettime() OSGetTick()
|
||||
|
||||
#include "ftp.h"
|
||||
#include "virtualpath.h"
|
||||
#include "net.h"
|
||||
#include "virtualpath.h"
|
||||
#include "vrt.h"
|
||||
|
||||
#define UNUSED __attribute__((unused))
|
||||
#define UNUSED __attribute__((unused))
|
||||
|
||||
#define FTP_BUFFER_SIZE 1024
|
||||
#define MAX_CLIENTS 5
|
||||
#define MAX_CLIENTS 5
|
||||
|
||||
static const uint16_t SRC_PORT = 20;
|
||||
static const int32_t EQUIT = 696969;
|
||||
static const char *CRLF = "\r\n";
|
||||
static const uint16_t SRC_PORT = 20;
|
||||
static const int32_t EQUIT = 696969;
|
||||
static const char *CRLF = "\r\n";
|
||||
static const uint32_t CRLF_LENGTH = 2;
|
||||
|
||||
static uint8_t num_clients = 0;
|
||||
static uint8_t num_clients = 0;
|
||||
static uint16_t passive_port = 1024;
|
||||
static char *password = NULL;
|
||||
static char *password = NULL;
|
||||
|
||||
#define console_printf(FMT, ARGS...) DEBUG_FUNCTION_LINE_WRITE(FMT, ## ARGS);
|
||||
#define console_printf(FMT, ARGS...) DEBUG_FUNCTION_LINE_WRITE(FMT, ##ARGS);
|
||||
|
||||
typedef int32_t (*data_connection_callback)(int32_t data_socket, void *arg);
|
||||
|
||||
@ -108,7 +107,7 @@ static bool compare_ftp_password(char *password_attempt) {
|
||||
*/
|
||||
static int32_t write_reply(client_t *client, uint16_t code, char *msg) {
|
||||
uint32_t msglen = 4 + strlen(msg) + CRLF_LENGTH;
|
||||
char *msgbuf = (char *) malloc(msglen + 1);
|
||||
char *msgbuf = (char *) malloc(msglen + 1);
|
||||
if (msgbuf == NULL)
|
||||
return -ENOMEM;
|
||||
sprintf(msgbuf, "%u %s\r\n", code, msg);
|
||||
@ -131,9 +130,9 @@ static void close_passive_socket(client_t *client) {
|
||||
*/
|
||||
static uint32_t split(char *s, char sep, uint32_t maxsplit, char *result[]) {
|
||||
uint32_t num_results = 0;
|
||||
uint32_t result_pos = 0;
|
||||
uint32_t trim_pos = 0;
|
||||
bool in_word = false;
|
||||
uint32_t result_pos = 0;
|
||||
uint32_t trim_pos = 0;
|
||||
bool in_word = false;
|
||||
for (; *s; s++) {
|
||||
if (*s == sep) {
|
||||
if (num_results <= maxsplit) {
|
||||
@ -153,7 +152,7 @@ static uint32_t split(char *s, char sep, uint32_t maxsplit, char *result[]) {
|
||||
}
|
||||
}
|
||||
result[num_results - 1][result_pos++] = *s;
|
||||
result[num_results - 1][result_pos] = '\0';
|
||||
result[num_results - 1][result_pos] = '\0';
|
||||
}
|
||||
if (trim_pos) {
|
||||
result[num_results - 1][trim_pos] = '\0';
|
||||
@ -182,7 +181,7 @@ static int32_t ftp_REIN(client_t *client, char *rest UNUSED) {
|
||||
close_passive_socket(client);
|
||||
strcpy(client->cwd, "/");
|
||||
client->representation_type = 'A';
|
||||
client->authenticated = false;
|
||||
client->authenticated = false;
|
||||
return write_reply(client, 220, "Service ready for new user.");
|
||||
}
|
||||
|
||||
@ -198,7 +197,7 @@ static int32_t ftp_SYST(client_t *client, char *rest UNUSED) {
|
||||
|
||||
static int32_t ftp_TYPE(client_t *client, char *rest) {
|
||||
char representation_type[FTP_BUFFER_SIZE], param[FTP_BUFFER_SIZE];
|
||||
char *args[] = {representation_type, param};
|
||||
char *args[] = {representation_type, param};
|
||||
uint32_t num_args = split(rest, ' ', 1, args);
|
||||
if (num_args == 0) {
|
||||
return write_reply(client, 501, "Syntax error in parameters.");
|
||||
@ -288,7 +287,7 @@ static int32_t ftp_RNTO(client_t *client, char *path) {
|
||||
} else {
|
||||
result = write_reply(client, 550, strerror(
|
||||
|
||||
errno));
|
||||
errno));
|
||||
}
|
||||
*client->pending_rename = '\0';
|
||||
return result;
|
||||
@ -314,8 +313,8 @@ static int32_t ftp_PASV(client_t *client, char *rest UNUSED) {
|
||||
set_blocking(client->passive_socket, false);
|
||||
struct sockaddr_in bindAddress;
|
||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = htons(passive_port++); // XXX: BUG: This will overflow eventually, with interesting results...
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = htons(passive_port++); // XXX: BUG: This will overflow eventually, with interesting results...
|
||||
bindAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
int32_t result;
|
||||
if ((result = network_bind(client->passive_socket, (struct sockaddr *) &bindAddress, sizeof(bindAddress))) < 0) {
|
||||
@ -327,10 +326,10 @@ static int32_t ftp_PASV(client_t *client, char *rest UNUSED) {
|
||||
return write_reply(client, 520, "Unable to listen on socket.");
|
||||
}
|
||||
char reply[49];
|
||||
uint16_t port = bindAddress.sin_port;
|
||||
uint32_t ip = network_gethostip();
|
||||
uint16_t port = bindAddress.sin_port;
|
||||
uint32_t ip = network_gethostip();
|
||||
struct in_addr addr = {};
|
||||
addr.s_addr = ip;
|
||||
addr.s_addr = ip;
|
||||
console_printf("Listening for data connections at %s:%u...\n", inet_ntoa(addr), port);
|
||||
sprintf(reply, "Entering Passive Mode (%u,%u,%u,%u,%u,%u).", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, (port >> 8) & 0xff, port & 0xff);
|
||||
return write_reply(client, 227, reply);
|
||||
@ -348,7 +347,7 @@ static int32_t ftp_PORT(client_t *client, char *portspec) {
|
||||
return write_reply(client, 501, "Syntax error in parameters.");
|
||||
}
|
||||
close_passive_socket(client);
|
||||
uint16_t port = ((p1 & 0xff) << 8) | (p2 & 0xff);
|
||||
uint16_t port = ((p1 & 0xff) << 8) | (p2 & 0xff);
|
||||
client->address.sin_addr = sin_addr;
|
||||
client->address.sin_port = htons(port);
|
||||
console_printf("Set client address to %s:%u\n", addr_str, port);
|
||||
@ -364,8 +363,8 @@ static int32_t prepare_data_connection_active(client_t *client, data_connection_
|
||||
set_blocking(data_socket, false);
|
||||
struct sockaddr_in bindAddress;
|
||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = htons(SRC_PORT);
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = htons(SRC_PORT);
|
||||
bindAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
int32_t result;
|
||||
if ((result = network_bind(data_socket, (struct sockaddr *) &bindAddress, sizeof(bindAddress))) < 0) {
|
||||
@ -394,11 +393,11 @@ static int32_t prepare_data_connection(client_t *client, void *callback, void *a
|
||||
if (result < 0) {
|
||||
result = write_reply(client, 520, "Closing data connection, error occurred during transfer.");
|
||||
} else {
|
||||
client->data_connection_connected = false;
|
||||
client->data_callback = callback;
|
||||
client->data_connection_connected = false;
|
||||
client->data_callback = callback;
|
||||
client->data_connection_callback_arg = arg;
|
||||
client->data_connection_cleanup = cleanup;
|
||||
client->data_connection_timer = gettime() + OSSecondsToTicks(10);
|
||||
client->data_connection_cleanup = cleanup;
|
||||
client->data_connection_timer = gettime() + OSSecondsToTicks(10);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -413,7 +412,7 @@ static int32_t send_nlst(int32_t data_socket, DIR_P *iter) {
|
||||
if (end_index + 2 >= MAXPATHLEN)
|
||||
continue;
|
||||
strcpy(filename, dirent->d_name);
|
||||
filename[end_index] = CRLF[0];
|
||||
filename[end_index] = CRLF[0];
|
||||
filename[end_index + 1] = CRLF[1];
|
||||
filename[end_index + 2] = '\0';
|
||||
if ((result = send_exact(data_socket, filename, strlen(filename))) < 0) {
|
||||
@ -426,8 +425,8 @@ static int32_t send_nlst(int32_t data_socket, DIR_P *iter) {
|
||||
static int32_t send_list(int32_t data_socket, DIR_P *iter) {
|
||||
struct stat st;
|
||||
int32_t result = 0;
|
||||
time_t mtime = 0;
|
||||
uint64_t size = 0;
|
||||
time_t mtime = 0;
|
||||
uint64_t size = 0;
|
||||
char filename[MAXPATHLEN];
|
||||
char line[MAXPATHLEN + 56 + CRLF_LENGTH + 1];
|
||||
struct dirent *dirent = NULL;
|
||||
@ -436,10 +435,10 @@ static int32_t send_list(int32_t data_socket, DIR_P *iter) {
|
||||
snprintf(filename, sizeof(filename), "%s/%s", iter->path, dirent->d_name);
|
||||
if (stat(filename, &st) == 0) {
|
||||
mtime = st.st_mtime;
|
||||
size = st.st_size;
|
||||
size = st.st_size;
|
||||
} else {
|
||||
mtime = time(0);
|
||||
size = 0;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
char timestamp[13];
|
||||
@ -614,14 +613,14 @@ static int32_t ftp_SITE_UNKNOWN(client_t *client, char *rest UNUSED) {
|
||||
}
|
||||
|
||||
static int32_t ftp_SITE_LOAD(client_t *client, char *path UNUSED) {
|
||||
// FILE *f = vrt_fopen(client->cwd, path, "rb");
|
||||
// if (!f) return write_reply(client, 550, strerror(errno));
|
||||
// char *real_path = to_real_path(client->cwd, path);
|
||||
// if (!real_path) goto end;
|
||||
// load_from_file(f, real_path);
|
||||
// free(real_path);
|
||||
// end:
|
||||
// fclose(f);
|
||||
// FILE *f = vrt_fopen(client->cwd, path, "rb");
|
||||
// if (!f) return write_reply(client, 550, strerror(errno));
|
||||
// char *real_path = to_real_path(client->cwd, path);
|
||||
// if (!real_path) goto end;
|
||||
// load_from_file(f, real_path);
|
||||
// free(real_path);
|
||||
// end:
|
||||
// fclose(f);
|
||||
return write_reply(client, 500, "Unable to load.");
|
||||
}
|
||||
|
||||
@ -639,7 +638,7 @@ static int32_t dispatch_to_handler(client_t *client, char *cmd_line, const char
|
||||
return handlers[i](client, rest);
|
||||
}
|
||||
|
||||
static const char *site_commands[] = {"LOADER", "CLEAR", "CHMOD", "PASSWD", "NOPASSWD", "EJECT", "MOUNT", "UNMOUNT", "LOAD", NULL};
|
||||
static const char *site_commands[] = {"LOADER", "CLEAR", "CHMOD", "PASSWD", "NOPASSWD", "EJECT", "MOUNT", "UNMOUNT", "LOAD", NULL};
|
||||
static const ftp_command_handler site_handlers[] = {ftp_SITE_LOADER, ftp_SITE_CLEAR, ftp_SITE_CHMOD, ftp_SITE_PASSWD, ftp_SITE_NOPASSWD, ftp_SITE_EJECT, ftp_SITE_MOUNT, ftp_SITE_UNMOUNT,
|
||||
ftp_SITE_LOAD, ftp_SITE_UNKNOWN};
|
||||
|
||||
@ -663,7 +662,7 @@ static int32_t ftp_UNKNOWN(client_t *client, char *rest UNUSED) {
|
||||
return write_reply(client, 502, "Command not implemented.");
|
||||
}
|
||||
|
||||
static const char *unauthenticated_commands[] = {"USER", "PASS", "QUIT", "REIN", "NOOP", NULL};
|
||||
static const char *unauthenticated_commands[] = {"USER", "PASS", "QUIT", "REIN", "NOOP", NULL};
|
||||
static const ftp_command_handler unauthenticated_handlers[] = {ftp_USER, ftp_PASS, ftp_QUIT, ftp_REIN, ftp_NOOP, ftp_NEEDAUTH};
|
||||
|
||||
static const char *authenticated_commands[] = {
|
||||
@ -671,15 +670,13 @@ static const char *authenticated_commands[] = {
|
||||
"SIZE", "PASV", "PORT", "TYPE", "SYST", "MODE",
|
||||
"RETR", "STOR", "APPE", "REST", "DELE", "MKD",
|
||||
"RMD", "RNFR", "RNTO", "NLST", "QUIT", "REIN",
|
||||
"SITE", "NOOP", "ALLO", NULL
|
||||
};
|
||||
"SITE", "NOOP", "ALLO", NULL};
|
||||
static const ftp_command_handler authenticated_handlers[] = {
|
||||
ftp_USER, ftp_PASS, ftp_LIST, ftp_PWD, ftp_CWD, ftp_CDUP,
|
||||
ftp_SIZE, ftp_PASV, ftp_PORT, ftp_TYPE, ftp_SYST, ftp_MODE,
|
||||
ftp_RETR, ftp_STOR, ftp_APPE, ftp_REST, ftp_DELE, ftp_MKD,
|
||||
ftp_DELE, ftp_RNFR, ftp_RNTO, ftp_NLST, ftp_QUIT, ftp_REIN,
|
||||
ftp_SITE, ftp_NOOP, ftp_SUPERFLUOUS, ftp_UNKNOWN
|
||||
};
|
||||
ftp_SITE, ftp_NOOP, ftp_SUPERFLUOUS, ftp_UNKNOWN};
|
||||
|
||||
/*
|
||||
returns negative to signal an error that requires closing the connection
|
||||
@ -691,7 +688,7 @@ static int32_t process_command(client_t *client, char *cmd_line) {
|
||||
|
||||
console_printf("Got command: %s\n", cmd_line);
|
||||
|
||||
const char **commands = unauthenticated_commands;
|
||||
const char **commands = unauthenticated_commands;
|
||||
const ftp_command_handler *handlers = unauthenticated_handlers;
|
||||
|
||||
if (client->authenticated) {
|
||||
@ -706,15 +703,15 @@ static void cleanup_data_resources(client_t *client) {
|
||||
if (client->data_socket >= 0 && client->data_socket != client->passive_socket) {
|
||||
network_close_blocking(client->data_socket);
|
||||
}
|
||||
client->data_socket = -1;
|
||||
client->data_socket = -1;
|
||||
client->data_connection_connected = false;
|
||||
client->data_callback = NULL;
|
||||
client->data_callback = NULL;
|
||||
if (client->data_connection_cleanup) {
|
||||
client->data_connection_cleanup(client->data_connection_callback_arg);
|
||||
}
|
||||
client->data_connection_callback_arg = NULL;
|
||||
client->data_connection_cleanup = NULL;
|
||||
client->data_connection_timer = 0;
|
||||
client->data_connection_cleanup = NULL;
|
||||
client->data_connection_timer = 0;
|
||||
}
|
||||
|
||||
static void cleanup_client(client_t *client) {
|
||||
@ -768,20 +765,20 @@ static bool process_accept_events(int32_t server) {
|
||||
network_close(peer);
|
||||
return true;
|
||||
}
|
||||
client->socket = peer;
|
||||
client->socket = peer;
|
||||
client->representation_type = 'A';
|
||||
client->passive_socket = -1;
|
||||
client->data_socket = -1;
|
||||
client->passive_socket = -1;
|
||||
client->data_socket = -1;
|
||||
strcpy(client->cwd, "/");
|
||||
*client->pending_rename = '\0';
|
||||
client->restart_marker = 0;
|
||||
client->authenticated = false;
|
||||
client->offset = 0;
|
||||
client->data_connection_connected = false;
|
||||
client->data_callback = NULL;
|
||||
*client->pending_rename = '\0';
|
||||
client->restart_marker = 0;
|
||||
client->authenticated = false;
|
||||
client->offset = 0;
|
||||
client->data_connection_connected = false;
|
||||
client->data_callback = NULL;
|
||||
client->data_connection_callback_arg = NULL;
|
||||
client->data_connection_cleanup = NULL;
|
||||
client->data_connection_timer = 0;
|
||||
client->data_connection_cleanup = NULL;
|
||||
client->data_connection_timer = 0;
|
||||
memcpy(&client->address, &client_address, sizeof(client_address));
|
||||
int client_index;
|
||||
if (write_reply(client, 220, "ftpii") < 0) {
|
||||
@ -807,9 +804,9 @@ static void process_data_events(client_t *client) {
|
||||
if (client->passive_socket >= 0) {
|
||||
struct sockaddr_in data_peer_address;
|
||||
socklen_t addrlen = sizeof(data_peer_address);
|
||||
result = network_accept(client->passive_socket, (struct sockaddr *) &data_peer_address, &addrlen);
|
||||
result = network_accept(client->passive_socket, (struct sockaddr *) &data_peer_address, &addrlen);
|
||||
if (result >= 0) {
|
||||
client->data_socket = result;
|
||||
client->data_socket = result;
|
||||
client->data_connection_connected = true;
|
||||
}
|
||||
} else {
|
||||
@ -890,7 +887,6 @@ static void process_control_events(client_t *client) {
|
||||
goto recv_loop_end;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (next != client->buf) { // some lines were processed
|
||||
@ -902,7 +898,7 @@ static void process_control_events(client_t *client) {
|
||||
}
|
||||
console_printf("Received line longer than %u bytes, closing client.\n", FTP_BUFFER_SIZE - 1);
|
||||
|
||||
recv_loop_end:
|
||||
recv_loop_end:
|
||||
cleanup_client(client);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ misrepresented as being the original software.
|
||||
#define _FTP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
17
src/main.cpp
17
src/main.cpp
@ -1,15 +1,15 @@
|
||||
#include <wups.h>
|
||||
#include "BackgroundThread.hpp"
|
||||
#include "utils/logger.h"
|
||||
#include "virtualpath.h"
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/dynload.h>
|
||||
#include <cstring>
|
||||
#include <iosuhax.h>
|
||||
#include <iosuhax_devoptab.h>
|
||||
#include <iosuhax_disc_interface.h>
|
||||
#include <coreinit/dynload.h>
|
||||
#include <nn/ac.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include "utils/logger.h"
|
||||
#include <whb/log_udp.h>
|
||||
#include "virtualpath.h"
|
||||
#include "BackgroundThread.hpp"
|
||||
#include <wups.h>
|
||||
|
||||
WUPS_PLUGIN_NAME("FTPiiU");
|
||||
WUPS_PLUGIN_DESCRIPTION("FTP Server");
|
||||
@ -20,8 +20,8 @@ WUPS_PLUGIN_LICENSE("GPL");
|
||||
WUPS_USE_WUT_DEVOPTAB();
|
||||
|
||||
uint32_t hostIpAddress = 0;
|
||||
int iosuhaxMount = 0;
|
||||
int fsaFd = -1;
|
||||
int iosuhaxMount = 0;
|
||||
int fsaFd = -1;
|
||||
|
||||
BackgroundThread *thread = nullptr;
|
||||
|
||||
@ -112,4 +112,3 @@ ON_APPLICATION_REQUESTS_EXIT() {
|
||||
|
||||
deinitLogging();
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "net.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAXPATHLEN 256
|
||||
#define MAXPATHLEN 256
|
||||
|
||||
#define wiiu_geterrno() (errno)
|
||||
#define wiiu_geterrno() (errno)
|
||||
|
||||
//! C wrapper for our C++ functions
|
||||
int Menu_Main(void);
|
||||
|
24
src/net.c
24
src/net.c
@ -21,21 +21,21 @@ misrepresented as being the original software.
|
||||
3.This notice may not be removed or altered from any source distribution.
|
||||
|
||||
*/
|
||||
#include "main.h"
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
#include "net.h"
|
||||
|
||||
#define MAX_NET_BUFFER_SIZE (128*1024)
|
||||
#define MAX_NET_BUFFER_SIZE (128 * 1024)
|
||||
#define MIN_NET_BUFFER_SIZE 4096
|
||||
#define FREAD_BUFFER_SIZE (128*1024)
|
||||
#define FREAD_BUFFER_SIZE (128 * 1024)
|
||||
|
||||
extern uint32_t hostIpAddress;
|
||||
|
||||
@ -131,7 +131,7 @@ int32_t network_write(int32_t s, const void *mem, int32_t len) {
|
||||
while (len) {
|
||||
int ret = send(s, mem, len, 0);
|
||||
if (ret < 0) {
|
||||
int err = -wiiu_geterrno();
|
||||
int err = -wiiu_geterrno();
|
||||
transfered = (err < 0) ? err : ret;
|
||||
break;
|
||||
}
|
||||
@ -180,8 +180,8 @@ int32_t create_server(uint16_t port) {
|
||||
|
||||
struct sockaddr_in bindAddress;
|
||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = htons(port);
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = htons(port);
|
||||
bindAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
int32_t ret;
|
||||
@ -202,12 +202,12 @@ int32_t create_server(uint16_t port) {
|
||||
typedef int32_t (*transferrer_type)(int32_t s, void *mem, int32_t len);
|
||||
|
||||
static int32_t transfer_exact(int32_t s, char *buf, int32_t length, transferrer_type transferrer) {
|
||||
int32_t result = 0;
|
||||
int32_t result = 0;
|
||||
int32_t remaining = length;
|
||||
int32_t bytes_transferred;
|
||||
set_blocking(s, true);
|
||||
while (remaining) {
|
||||
try_again_with_smaller_buffer:
|
||||
try_again_with_smaller_buffer:
|
||||
bytes_transferred = transferrer(s, buf, MIN(remaining, (int) NET_BUFFER_SIZE));
|
||||
if (bytes_transferred > 0) {
|
||||
remaining -= bytes_transferred;
|
||||
@ -253,7 +253,7 @@ int32_t send_from_file(int32_t s, FILE *f) {
|
||||
}
|
||||
free(buf);
|
||||
return -EAGAIN;
|
||||
end:
|
||||
end:
|
||||
free(buf);
|
||||
return result;
|
||||
}
|
||||
@ -265,7 +265,7 @@ int32_t recv_to_file(int32_t s, FILE *f) {
|
||||
|
||||
int32_t bytes_read;
|
||||
while (1) {
|
||||
try_again_with_smaller_buffer:
|
||||
try_again_with_smaller_buffer:
|
||||
bytes_read = network_read(s, buf, NET_BUFFER_SIZE);
|
||||
if (bytes_read < 0) {
|
||||
if (bytes_read == -EINVAL && NET_BUFFER_SIZE == MAX_NET_BUFFER_SIZE) {
|
||||
|
12
src/net.h
12
src/net.h
@ -25,18 +25,18 @@ misrepresented as being the original software.
|
||||
#define _NET_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if 0
|
||||
void initialise_network();
|
||||
|
@ -19,4 +19,3 @@ void BackgroundThreadWrapper::executeThread() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "CThread.h"
|
||||
#include <wut_types.h>
|
||||
#include <mutex>
|
||||
#include <wut_types.h>
|
||||
|
||||
class BackgroundThreadWrapper : public CThread {
|
||||
public:
|
||||
@ -20,6 +20,7 @@ protected:
|
||||
}
|
||||
|
||||
std::recursive_mutex mutex;
|
||||
|
||||
private:
|
||||
void executeThread() override;
|
||||
|
||||
|
@ -17,11 +17,11 @@
|
||||
#ifndef CTHREAD_H_
|
||||
#define CTHREAD_H_
|
||||
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include "utils/logger.h"
|
||||
#include <coreinit/systeminfo.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include "utils/logger.h"
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
|
||||
class CThread {
|
||||
public:
|
||||
@ -29,7 +29,7 @@ public:
|
||||
|
||||
//! constructor
|
||||
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr)
|
||||
: pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
|
||||
: pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
|
||||
//! save attribute assignment
|
||||
iAttributes = iAttr;
|
||||
//! allocate the thread
|
||||
@ -112,19 +112,20 @@ public:
|
||||
if (pThread)
|
||||
free(pThread);
|
||||
|
||||
pThread = nullptr;
|
||||
pThread = nullptr;
|
||||
pThreadStack = nullptr;
|
||||
}
|
||||
|
||||
//! Thread attributes
|
||||
enum eCThreadAttributes {
|
||||
eAttributeNone = 0x07,
|
||||
eAttributeAffCore0 = 0x01,
|
||||
eAttributeAffCore1 = 0x02,
|
||||
eAttributeAffCore2 = 0x04,
|
||||
eAttributeDetach = 0x08,
|
||||
eAttributeNone = 0x07,
|
||||
eAttributeAffCore0 = 0x01,
|
||||
eAttributeAffCore1 = 0x02,
|
||||
eAttributeAffCore2 = 0x04,
|
||||
eAttributeDetach = 0x08,
|
||||
eAttributePinnedAff = 0x10
|
||||
};
|
||||
|
||||
private:
|
||||
static int threadCallback(int argc, const char **argv) {
|
||||
//! After call to start() continue with the internal function
|
||||
|
@ -1,19 +1,19 @@
|
||||
#ifdef DEBUG
|
||||
#include <stdint.h>
|
||||
#include <whb/log_udp.h>
|
||||
#include <whb/log_cafe.h>
|
||||
#include <whb/log_module.h>
|
||||
#include <whb/log_udp.h>
|
||||
|
||||
uint32_t moduleLogInit = false;
|
||||
uint32_t cafeLogInit = false;
|
||||
uint32_t udpLogInit = false;
|
||||
uint32_t cafeLogInit = false;
|
||||
uint32_t udpLogInit = false;
|
||||
#endif // DEBUG
|
||||
|
||||
void initLogging() {
|
||||
#ifdef DEBUG
|
||||
if (!(moduleLogInit = WHBLogModuleInit())) {
|
||||
cafeLogInit = WHBLogCafeInit();
|
||||
udpLogInit = WHBLogUdpInit();
|
||||
udpLogInit = WHBLogUdpInit();
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <whb/log.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -9,26 +9,28 @@ extern "C" {
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
|
||||
#endif
|
||||
|
||||
@ -39,4 +41,3 @@ void deinitLogging();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <whb/log.h>
|
||||
#include "utils/logger.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
// https://gist.github.com/ccbrown/9722406
|
||||
void dumpHex(const void *data, size_t size) {
|
||||
|
@ -6,28 +6,29 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LIMIT(x, min, max) \
|
||||
({ \
|
||||
typeof( x ) _x = x; \
|
||||
typeof( min ) _min = min; \
|
||||
typeof( max ) _max = max; \
|
||||
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
|
||||
})
|
||||
#define LIMIT(x, min, max) \
|
||||
({ \
|
||||
typeof(x) _x = x; \
|
||||
typeof(min) _min = min; \
|
||||
typeof(max) _max = max; \
|
||||
(((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \
|
||||
: (_x)); \
|
||||
})
|
||||
|
||||
#define DegToRad(a) ( (a) * 0.01745329252f )
|
||||
#define RadToDeg(a) ( (a) * 57.29577951f )
|
||||
#define DegToRad(a) ((a) *0.01745329252f)
|
||||
#define RadToDeg(a) ((a) *57.29577951f)
|
||||
|
||||
#define ALIGN4(x) (((x) + 3) & ~3)
|
||||
#define ALIGN32(x) (((x) + 31) & ~31)
|
||||
#define ALIGN4(x) (((x) + 3) & ~3)
|
||||
#define ALIGN32(x) (((x) + 31) & ~31)
|
||||
|
||||
// those work only in powers of 2
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align-1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align)
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align - 1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
|
||||
|
||||
|
||||
#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8)))
|
||||
#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16)))
|
||||
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
|
||||
#define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8)))
|
||||
#define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16)))
|
||||
#define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32)))
|
||||
|
||||
//Needs to have log_init() called beforehand.
|
||||
void dumpHex(const void *data, size_t size);
|
||||
|
@ -26,18 +26,18 @@
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "virtualpath.h"
|
||||
#include "utils/logger.h"
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
uint8_t MAX_VIRTUAL_PARTITIONS = 0;
|
||||
uint8_t MAX_VIRTUAL_PARTITIONS = 0;
|
||||
VIRTUAL_PARTITION *VIRTUAL_PARTITIONS = NULL;
|
||||
|
||||
uint8_t MAX_VIRTUAL_FS = 0;
|
||||
uint8_t MAX_VIRTUAL_FS = 0;
|
||||
VIRTUAL_PARTITION *VIRTUAL_FS = NULL;
|
||||
|
||||
uint8_t MAX_VIRTUAL_FS_VOL = 0;
|
||||
uint8_t MAX_VIRTUAL_FS_VOL = 0;
|
||||
VIRTUAL_PARTITION *VIRTUAL_FS_VOL = NULL;
|
||||
|
||||
void VirtualMountDevice(const char *path) {
|
||||
@ -57,13 +57,13 @@ void VirtualMountDevice(const char *path) {
|
||||
namestop = true;
|
||||
|
||||
if (!namestop) {
|
||||
name[i] = path[i];
|
||||
name[i + 1] = '\0';
|
||||
name[i] = path[i];
|
||||
name[i + 1] = '\0';
|
||||
alias[i + 1] = path[i];
|
||||
alias[i + 2] = '\0';
|
||||
}
|
||||
|
||||
prefix[i] = path[i];
|
||||
prefix[i] = path[i];
|
||||
prefix[i + 1] = '\0';
|
||||
i++;
|
||||
} while (path[i - 1] != '/');
|
||||
@ -78,16 +78,16 @@ void AddVirtualPath(const char *name, const char *alias, const char *prefix) {
|
||||
VIRTUAL_PARTITION *tmp = realloc(VIRTUAL_PARTITIONS, sizeof(VIRTUAL_PARTITION) * (MAX_VIRTUAL_PARTITIONS + 1));
|
||||
if (!tmp) {
|
||||
free(VIRTUAL_PARTITIONS);
|
||||
VIRTUAL_PARTITIONS = NULL;
|
||||
VIRTUAL_PARTITIONS = NULL;
|
||||
MAX_VIRTUAL_PARTITIONS = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
VIRTUAL_PARTITIONS = tmp;
|
||||
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].name = strdup(name);
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].alias = strdup(alias);
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].prefix = strdup(prefix);
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].name = strdup(name);
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].alias = strdup(alias);
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].prefix = strdup(prefix);
|
||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].inserted = true;
|
||||
|
||||
MAX_VIRTUAL_PARTITIONS++;
|
||||
@ -187,10 +187,10 @@ void UnmountVirtualPaths() {
|
||||
if (VIRTUAL_FS) {
|
||||
free(VIRTUAL_FS);
|
||||
}
|
||||
VIRTUAL_PARTITIONS = NULL;
|
||||
VIRTUAL_FS_VOL = NULL;
|
||||
VIRTUAL_FS = NULL;
|
||||
VIRTUAL_PARTITIONS = NULL;
|
||||
VIRTUAL_FS_VOL = NULL;
|
||||
VIRTUAL_FS = NULL;
|
||||
MAX_VIRTUAL_PARTITIONS = 0;
|
||||
MAX_VIRTUAL_FS = 0;
|
||||
MAX_VIRTUAL_FS_VOL = 0;
|
||||
MAX_VIRTUAL_FS = 0;
|
||||
MAX_VIRTUAL_FS_VOL = 0;
|
||||
}
|
||||
|
@ -31,11 +31,11 @@
|
||||
#define _VIRTUALPATH_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
49
src/vrt.c
49
src/vrt.c
@ -23,12 +23,12 @@ misrepresented as being the original software.
|
||||
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/dirent.h>
|
||||
#include <unistd.h>
|
||||
#include "main.h"
|
||||
|
||||
#include "virtualpath.h"
|
||||
#include "vrt.h"
|
||||
@ -47,39 +47,44 @@ static char *virtual_abspath(char *virtual_cwd, char *virtual_path) {
|
||||
char *normalised_path = malloc(strlen(path) + 1);
|
||||
if (!normalised_path) goto end;
|
||||
*normalised_path = '\0';
|
||||
char *curr_dir = normalised_path;
|
||||
char *curr_dir = normalised_path;
|
||||
|
||||
uint32_t state = 0; // 0:start, 1:slash, 2:dot, 3:dotdot
|
||||
char *token = path;
|
||||
char *token = path;
|
||||
while (1) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (*token == '/') {
|
||||
state = 1;
|
||||
state = 1;
|
||||
curr_dir = normalised_path + strlen(normalised_path);
|
||||
strncat(normalised_path, token, 1);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (*token == '.') state = 2;
|
||||
else if (*token != '/') state = 0;
|
||||
else if (*token != '/')
|
||||
state = 0;
|
||||
break;
|
||||
case 2:
|
||||
if (*token == '/' || !*token) {
|
||||
state = 1;
|
||||
state = 1;
|
||||
*(curr_dir + 1) = '\0';
|
||||
} else if (*token == '.') state = 3;
|
||||
else state = 0;
|
||||
} else if (*token == '.')
|
||||
state = 3;
|
||||
else
|
||||
state = 0;
|
||||
break;
|
||||
case 3:
|
||||
if (*token == '/' || !*token) {
|
||||
state = 1;
|
||||
*curr_dir = '\0';
|
||||
state = 1;
|
||||
*curr_dir = '\0';
|
||||
char *prev_dir = strrchr(normalised_path, '/');
|
||||
if (prev_dir) curr_dir = prev_dir;
|
||||
else *curr_dir = '/';
|
||||
else
|
||||
*curr_dir = '/';
|
||||
*(curr_dir + 1) = '\0';
|
||||
} else state = 0;
|
||||
} else
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
if (!*token) break;
|
||||
@ -92,7 +97,7 @@ static char *virtual_abspath(char *virtual_cwd, char *virtual_path) {
|
||||
normalised_path[--end] = '\x00';
|
||||
}
|
||||
|
||||
end:
|
||||
end:
|
||||
if (path != virtual_path) free(path);
|
||||
return normalised_path;
|
||||
}
|
||||
@ -127,8 +132,8 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
|
||||
uint32_t i;
|
||||
for (i = 0; i < MAX_VIRTUAL_PARTITIONS; i++) {
|
||||
VIRTUAL_PARTITION *partition = VIRTUAL_PARTITIONS + i;
|
||||
const char *alias = partition->alias;
|
||||
size_t alias_len = strlen(alias);
|
||||
const char *alias = partition->alias;
|
||||
size_t alias_len = strlen(alias);
|
||||
if (!strcasecmp(alias, virtual_path) || (!strncasecmp(alias, virtual_path, alias_len) && virtual_path[alias_len] == '/')) {
|
||||
prefix = partition->prefix;
|
||||
rest += alias_len;
|
||||
@ -149,7 +154,7 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
|
||||
strcpy(path, prefix);
|
||||
strcat(path, rest);
|
||||
|
||||
end:
|
||||
end:
|
||||
free(virtual_path);
|
||||
return path;
|
||||
}
|
||||
@ -286,10 +291,10 @@ DIR_P *vrt_opendir(char *cwd, char *path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iter->virt_root = 0;
|
||||
iter->virtual_fs = 0;
|
||||
iter->virt_root = 0;
|
||||
iter->virtual_fs = 0;
|
||||
iter->virtual_fs_vol = 0;
|
||||
iter->path = real_path;
|
||||
iter->path = real_path;
|
||||
|
||||
if (*iter->path == 0 || (strncmp(iter->path, "fs:", 3) == 0 && strlen(iter->path) <= 4) || (strncmp(iter->path, "fs:/vol", 3) == 0 && strlen(iter->path) <= 8)) {
|
||||
iter->dir = malloc(sizeof(DIR));
|
||||
@ -331,13 +336,13 @@ struct dirent *vrt_readdir(DIR_P *pDir) {
|
||||
|
||||
DIR *iter = pDir->dir;
|
||||
if (pDir->virt_root || pDir->virtual_fs || pDir->virtual_fs_vol) {
|
||||
int max = MAX_VIRTUAL_PARTITIONS;
|
||||
int max = MAX_VIRTUAL_PARTITIONS;
|
||||
VIRTUAL_PARTITION *PARTITION_PTR = VIRTUAL_PARTITIONS;
|
||||
if (pDir->virtual_fs) {
|
||||
max = MAX_VIRTUAL_FS;
|
||||
max = MAX_VIRTUAL_FS;
|
||||
PARTITION_PTR = VIRTUAL_FS;
|
||||
} else if (pDir->virtual_fs_vol) {
|
||||
max = MAX_VIRTUAL_FS_VOL;
|
||||
max = MAX_VIRTUAL_FS_VOL;
|
||||
PARTITION_PTR = VIRTUAL_FS_VOL;
|
||||
}
|
||||
for (; (uint32_t) iter->position < max; iter->position++) {
|
||||
|
Loading…
Reference in New Issue
Block a user