diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b58de2..49cbb15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,13 @@ cmake_minimum_required(VERSION 3.13) +set(FTPSRV_VERSION_MAJOR 0) +set(FTPSRV_VERSION_MINOR 2) +set(FTPSRV_VERSION_PATCH 0) +set(FTPSRV_VERSION ${FTPSRV_VERSION_MAJOR}.${FTPSRV_VERSION_MINOR}.${FTPSRV_VERSION_PATCH}) + project(ftpsrv LANGUAGES C - VERSION 0.2.0 + VERSION ${FTPSRV_VERSION} DESCRIPTION "small and fast ftp server" ) @@ -73,6 +78,35 @@ check_c_source_compiles(" int main(void) { strncasecmp(0, 0, 0); }" HAVE_STRNCASECMP) +find_package(Git REQUIRED) + +execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND "${GIT_EXECUTABLE}" symbolic-ref --short HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND "${GIT_EXECUTABLE}" status --porcelain + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_DIRTY + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if (GIT_DIRTY) + set(FTPSRV_VERSION_HASH "${FTPSRV_VERSION} ${GIT_COMMIT}-dirty") +else() + set(FTPSRV_VERSION_HASH "${FTPSRV_VERSION} ${GIT_COMMIT}-dirty") +endif() + function(fetch_minini) FetchContent_Declare(minIni GIT_REPOSITORY https://github.com/ITotalJustice/minIni-nx.git @@ -87,17 +121,24 @@ function(fetch_minini) endfunction(fetch_minini) function(ftp_set_compile_definitions target) - target_compile_definitions(${target} PRIVATE - HAVE_READLINK=$ - HAVE_GETPWUID=$ - HAVE_GETGRGID=$ - HAVE_STRNCASECMP=$ - HAVE_POLL=$ - HAVE_IPTOS_THROUGHPUT=$ - HAVE_TCP_NODELAY=$ - HAVE_SO_KEEPALIVE=$ - HAVE_SO_REUSEADDR=$ - ) + target_compile_definitions(${target} + PRIVATE + HAVE_READLINK=$ + HAVE_GETPWUID=$ + HAVE_GETGRGID=$ + HAVE_STRNCASECMP=$ + HAVE_POLL=$ + HAVE_IPTOS_THROUGHPUT=$ + HAVE_TCP_NODELAY=$ + HAVE_SO_KEEPALIVE=$ + HAVE_SO_REUSEADDR=$ + PUBLIC + FTPSRV_VERSION_MAJOR=${FTPSRV_VERSION_MAJOR} + FTPSRV_VERSION_MINOR=${FTPSRV_VERSION_MINOR} + FTPSRV_VERSION_PATCH=${FTPSRV_VERSION_PATCH} + FTPSRV_VERSION_STR="${FTPSRV_VERSION}" + FTPSRV_VERSION_HASH="${FTPSRV_VERSION_HASH}" + ) endfunction(ftp_set_compile_definitions) function(ftp_set_options target path_size sessions buf_size) @@ -202,6 +243,8 @@ if (NINTENDO_SWITCH) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B/flags) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/sysftp.json ${CMAKE_CURRENT_BINARY_DIR}/sysftp.json) + add_custom_command( TARGET ftpexe POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy @@ -214,7 +257,7 @@ if (NINTENDO_SWITCH) nx_create_exefs(sysftp OUTPUT 420000000000011B/exefs.nsp - CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/sysftp.json + CONFIG ${CMAKE_CURRENT_BINARY_DIR}/sysftp.json ) elseif(NINTENDO_DS) ftp_set_options(ftpsrv 769 16 1024*64) diff --git a/src/ftpsrv.c b/src/ftpsrv.c index d662842..93f87e2 100644 --- a/src/ftpsrv.c +++ b/src/ftpsrv.c @@ -1185,7 +1185,7 @@ static void ftp_cmd_STAT(struct FtpSession* session, const char* data) { // HELP | 211, 214, 500, 501, 502, 421 static void ftp_cmd_HELP(struct FtpSession* session, const char* data) { - ftp_client_msg(session, 214, "ftpsrv 0.2.0 By TotalJustice."); + ftp_client_msg(session, 214, "ftpsrv " FTPSRV_VERSION_STR " By TotalJustice."); } // NOOP | 200, 500, 421 diff --git a/src/ftpsrv.h b/src/ftpsrv.h index 48a5f92..248d4d0 100644 --- a/src/ftpsrv.h +++ b/src/ftpsrv.h @@ -45,16 +45,6 @@ int ftpsrv_init(const struct FtpSrvConfig* cfg); int ftpsrv_loop(int timeout_ms); void ftpsrv_exit(void); -#if 0 -int ftpsrv_config_init(struct FtpSrvConfig* cfg); -int ftpsrv_config_set_user(struct FtpSrvConfig* cfg, const char* user); -int ftpsrv_config_set_pass(struct FtpSrvConfig* cfg, const char* pass); -int ftpsrv_config_set_port(struct FtpSrvConfig* cfg, int port); -int ftpsrv_config_set_anon(struct FtpSrvConfig* cfg, int anon); -int ftpsrv_config_set_devices(struct FtpSrvConfig* cfg, const struct FtpSrvDevice* devices, unsigned count); -int ftpsrv_config_set_log_callback(struct FtpSrvConfig* cfg, FtpSrvLogCallback log_callback); -#endif - #ifdef __cplusplus } #endif diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index d996aa5..a4d820f 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -131,7 +131,7 @@ int main(void) { gfxInitDefault(); consoleInit(GFX_TOP, &topScreen); consoleInit(GFX_BOTTOM, &bottomScreen); - consolePrint("\n[ftpsrv 0.2.0 By TotalJustice]\n\n"); + consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n"); g_ftpsrv_config.log_callback = ftp_log_callback; g_ftpsrv_config.anon = ini_getbool("Login", "anon", 0, INI_PATH); @@ -142,7 +142,7 @@ int main(void) { const bool log_enabled = ini_getbool("Log", "log", 0, INI_PATH); if (log_enabled) { - log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - 3DS"); + log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - 3DS"); } if (!user_len && !pass_len) { diff --git a/src/platform/nds/main.c b/src/platform/nds/main.c index 43d3538..15b84a6 100644 --- a/src/platform/nds/main.c +++ b/src/platform/nds/main.c @@ -104,7 +104,7 @@ int main(void) { consoleInit(&topScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&bottomScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true); - consolePrint("\n[ftpsrv 0.2.0 By TotalJustice]\n\n"); + consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n"); // init sd card. if (!fatInitDefault()) { @@ -120,7 +120,7 @@ int main(void) { const bool log_enabled = ini_getbool("Log", "log", 0, INI_PATH); if (log_enabled) { - log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - NDS"); + log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - NDS"); } if (!user_len && !pass_len) { diff --git a/src/platform/nx/main.c b/src/platform/nx/main.c index b34c474..a773f95 100644 --- a/src/platform/nx/main.c +++ b/src/platform/nx/main.c @@ -131,7 +131,7 @@ static int error_loop(const char* msg) { } int main(int argc, char** argv) { - consolePrint("\n[ftpsrv 0.2.0-v1 By TotalJustice]\n\n"); + consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n"); padConfigureInput(8, HidNpadStyleSet_NpadStandard); padInitializeDefault(&g_pad); @@ -150,7 +150,7 @@ int main(int argc, char** argv) { g_ftpsrv_config.port = ini_getl("Nx", "app_port", g_ftpsrv_config.port, INI_PATH); if (log_enabled) { - log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - NX-app"); + log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - NX-app"); } vfs_nx_init(mount_devices, save_writable); diff --git a/src/platform/nx/main_sysmod.c b/src/platform/nx/main_sysmod.c index f06a707..f682d30 100644 --- a/src/platform/nx/main_sysmod.c +++ b/src/platform/nx/main_sysmod.c @@ -41,7 +41,7 @@ int main(void) { g_ftpsrv_config.port = ini_getl("Nx", "sys_port", g_ftpsrv_config.port, INI_PATH); if (log_enabled) { - log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - NX-sys"); + log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - NX-sys"); } vfs_nx_init(mount_devices, save_writable); diff --git a/src/platform/nx/sysftp.json b/src/platform/nx/sysftp.json index 6d754cf..293ac73 100644 --- a/src/platform/nx/sysftp.json +++ b/src/platform/nx/sysftp.json @@ -1,6 +1,6 @@ { "name": "sys-ftp", - "version": "0.2.0", + "version": "${FTPSRV_VERSION}", "program_id": "0x420000000000011B", "program_id_range_min": "0x420000000000011B", "program_id_range_max": "0x420000000000011B", diff --git a/src/platform/unistd/main.c b/src/platform/unistd/main.c index 6faa956..8bfb4e7 100644 --- a/src/platform/unistd/main.c +++ b/src/platform/unistd/main.c @@ -57,7 +57,7 @@ static void ftp_log_callback(enum FTP_API_LOG_TYPE type, const char* msg) { static int print_usage(int code) { printf("\ -[ftpsrv 0.2.0 By TotalJustice] \n\n\ +[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice] \n\n\ Usage\n\n\ -h, --help = Display help.\n\ -v, --version = Display version.\n\ diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index e5944a5..7d74977 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -161,7 +161,7 @@ int main(void) { VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); - consolePrint("\n[ftpsrv 0.2.0 By TotalJustice]\n\n"); + consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n"); if (!fatInitDefault()) { return error_loop("failed to init fat device\n"); @@ -176,7 +176,7 @@ int main(void) { const bool log_enabled = ini_getbool("Log", "log", 0, INI_PATH); if (log_enabled) { - log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - WII"); + log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - WII"); } if (!user_len && !pass_len) { diff --git a/src/platform/wii/meta.xml b/src/platform/wii/meta.xml index 0aae860..269c158 100644 --- a/src/platform/wii/meta.xml +++ b/src/platform/wii/meta.xml @@ -2,6 +2,6 @@ Ftpsrv TotalJustice - 0.2.0 + ${FTPSRV_VERSION} FTP server