From 17e905b95d287be1a4c26395354e4cf55cded622 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 27 May 2024 16:31:25 +0200 Subject: [PATCH] [SFTP] Added -Dsftp option. Enabled by default Fixed building tests. SFTP can be disabled, even if FTP and libcurl are enabled. --- Makefile.config.in | 1 + config2.h.in | 3 +++ configure.ac | 3 +++ features.conf | 7 +++++++ meson.build | 1 + meson_options.txt | 1 + src/protocol/Makefile | 3 +++ src/protocol/curl/ftp.c | 16 ++++++++++++---- src/protocol/curl/sftp.h | 2 +- src/protocol/ftp/Makefile | 4 ++-- src/protocol/ftp/ftp-parser.c | 2 +- src/protocol/ftp/ftp.c | 2 +- src/protocol/ftp/meson.build | 4 ++-- src/protocol/{ftp/parse.c => ftpparse.c} | 2 +- src/protocol/{ftp/parse.h => ftpparse.h} | 4 ++-- src/protocol/meson.build | 5 +++++ src/protocol/protocol.c | 2 +- src/protocol/test/Makefile | 2 +- src/protocol/test/meson.build | 2 +- 19 files changed, 49 insertions(+), 17 deletions(-) rename src/protocol/{ftp/parse.c => ftpparse.c} (99%) rename src/protocol/{ftp/parse.h => ftpparse.h} (95%) diff --git a/Makefile.config.in b/Makefile.config.in index 4fd203d24..845d6efd4 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -180,6 +180,7 @@ CONFIG_SCRIPTING_PERL = @CONFIG_SCRIPTING_PERL@ CONFIG_SCRIPTING_PYTHON = @CONFIG_SCRIPTING_PYTHON@ CONFIG_SCRIPTING_RUBY = @CONFIG_SCRIPTING_RUBY@ CONFIG_SCRIPTING_SPIDERMONKEY = @CONFIG_SCRIPTING_SPIDERMONKEY@ +CONFIG_SFTP = @CONFIG_SFTP@ CONFIG_SMALL = @CONFIG_SMALL@ CONFIG_SMB = @CONFIG_SMB@ CONFIG_SPIDERMONKEY = @CONFIG_SPIDERMONKEY@ diff --git a/config2.h.in b/config2.h.in index b2d846339..9fbd0f69b 100644 --- a/config2.h.in +++ b/config2.h.in @@ -247,6 +247,9 @@ /* Define if you want: SpiderMonkey support */ #mesondefine CONFIG_SCRIPTING_SPIDERMONKEY +/* Define if you want: SFTP protocol support. Requires libcurl */ +#mesondefine CONFIG_SFTP + /* Define if you want: Small binary support */ #mesondefine CONFIG_SMALL diff --git a/configure.ac b/configure.ac index a514391b7..cf1642916 100644 --- a/configure.ac +++ b/configure.ac @@ -1691,6 +1691,9 @@ fi EL_ARG_ENABLE(CONFIG_FTP, ftp, [FTP protocol], [ --disable-ftp disable ftp protocol support]) +EL_ARG_ENABLE(CONFIG_SFTP, sftp, [SFTP protocol], + [ --disable-sftp disable sftp protocol support]) + EL_ARG_ENABLE(CONFIG_GEMINI, gemini, [Gemini protocol], [ --enable-gemini enable gemini protocol support]) diff --git a/features.conf b/features.conf index e809c016f..7c0665854 100644 --- a/features.conf +++ b/features.conf @@ -375,6 +375,13 @@ CONFIG_FSP=no CONFIG_FTP=yes +# SFTP +# See https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol . +# Requires libcurl. +# +# Default: enabled + +CONFIG_SFTP=yes ### Gopher Protocol Support # diff --git a/meson.build b/meson.build index e42727e1d..076106bb2 100644 --- a/meson.build +++ b/meson.build @@ -43,6 +43,7 @@ conf_data.set('CONFIG_FINGER', get_option('finger')) conf_data.set('CONFIG_FSP', get_option('fsp')) conf_data.set('CONFIG_FSP2', get_option('fsp2')) conf_data.set('CONFIG_FTP', get_option('ftp')) +conf_data.set('CONFIG_SFTP', get_option('sftp')) conf_data.set('CONFIG_GOPHER', get_option('gopher')) conf_data.set('CONFIG_NNTP', get_option('nntp')) conf_data.set('CONFIG_SMB', get_option('smb')) diff --git a/meson_options.txt b/meson_options.txt index b5f178e68..d4c77d3ae 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -82,5 +82,6 @@ option('pdfdoc', type: 'boolean', value: true, description: 'whether to build ma option('libcss', type: 'boolean', value: true, description: 'whether to compile libcss support, requires libdom. This option is automatically enabled with js support') option('libsixel', type: 'boolean', value: false, description: 'whether to compile libsixel support to show images directly on sixel compatible terminals') option('libcurl', type: 'boolean', value: true, description: 'whether to compile libcurl support. This option is automatically enabled with js support') +option('sftp', type: 'boolean', value: true, description: 'whether to compile SFTP protocol support. Requires libcurl') option('msys2', type: 'boolean', value: false, description: 'whether to build for msys2') diff --git a/src/protocol/Makefile b/src/protocol/Makefile index e563d765b..378ee793e 100644 --- a/src/protocol/Makefile +++ b/src/protocol/Makefile @@ -16,6 +16,9 @@ SUBDIRS = auth file http test OBJS-$(CONFIG_DATA) += data.o +OBJS-$(CONFIG_FTP) += ftpparse.o +OBJS-$(CONFIG_SFTP) += ftpparse.o + OBJS = about.o common.o date.o header.o protocol.o proxy.o uri.o user.o include $(top_srcdir)/Makefile.lib diff --git a/src/protocol/curl/ftp.c b/src/protocol/curl/ftp.c index a7136913b..0e7e4bfbd 100644 --- a/src/protocol/curl/ftp.c +++ b/src/protocol/curl/ftp.c @@ -48,15 +48,16 @@ #include "protocol/curl/ftpes.h" #include "protocol/curl/http.h" #include "protocol/curl/sftp.h" -#include "protocol/ftp/parse.h" +#include "protocol/ftpparse.h" #include "protocol/uri.h" #include "util/conv.h" #include "util/error.h" #include "util/memory.h" #include "util/string.h" -#ifdef CONFIG_FTP +#if defined(CONFIG_FTP) || defined(CONFIG_SFTP) +#ifdef CONFIG_FTP static char el_curlversion[256]; static void @@ -75,7 +76,9 @@ struct module ftpes_protocol_module = struct_module( /* init: */ init_ftpes, /* done: */ NULL ); +#endif +#ifdef CONFIG_SFTP struct module sftp_protocol_module = struct_module( /* name: */ N_("SFTP"), /* options: */ NULL, @@ -85,7 +88,7 @@ struct module sftp_protocol_module = struct_module( /* init: */ NULL, /* done: */ NULL ); - +#endif #define FTP_BUF_SIZE 16384 @@ -643,6 +646,7 @@ ftp_curl_handle_error(struct connection *conn, CURLcode res) abort_connection(conn, connection_state(S_CURL_ERROR - res)); } +#ifdef CONFIG_FTP void ftpes_protocol_handler(struct connection *conn) { @@ -650,7 +654,9 @@ ftpes_protocol_handler(struct connection *conn) do_ftpes(conn); } } +#endif +#ifdef CONFIG_SFTP void sftp_protocol_handler(struct connection *conn) { @@ -658,4 +664,6 @@ sftp_protocol_handler(struct connection *conn) do_ftpes(conn); } } -#endif \ No newline at end of file +#endif + +#endif diff --git a/src/protocol/curl/sftp.h b/src/protocol/curl/sftp.h index cdcafd572..2ec5a0542 100644 --- a/src/protocol/curl/sftp.h +++ b/src/protocol/curl/sftp.h @@ -10,7 +10,7 @@ extern "C" { extern struct module sftp_protocol_module; -#if defined(CONFIG_FTP) && defined(CONFIG_LIBCURL) +#if defined(CONFIG_SFTP) && defined(CONFIG_LIBCURL) extern protocol_handler_T sftp_protocol_handler; #else #define sftp_protocol_handler NULL diff --git a/src/protocol/ftp/Makefile b/src/protocol/ftp/Makefile index bcd0019df..9dd44de90 100644 --- a/src/protocol/ftp/Makefile +++ b/src/protocol/ftp/Makefile @@ -1,13 +1,13 @@ top_builddir=../../.. include $(top_builddir)/Makefile.config -OBJS = ftp.o parse.o +OBJS = ftp.o TEST_PROGS = \ ftp-parser$(EXEEXT) TESTDEPS = \ $(top_builddir)/src/protocol/date.o \ - $(top_builddir)/src/protocol/ftp/parse.o + $(top_builddir)/src/protocol/ftpparse.o include $(top_srcdir)/Makefile.lib diff --git a/src/protocol/ftp/ftp-parser.c b/src/protocol/ftp/ftp-parser.c index aed7ce1c2..ea152a921 100644 --- a/src/protocol/ftp/ftp-parser.c +++ b/src/protocol/ftp/ftp-parser.c @@ -12,7 +12,7 @@ #include "elinks.h" #include "osdep/stat.h" -#include "protocol/ftp/parse.h" +#include "protocol/ftpparse.h" #include "util/test.h" /* fake tty get function, needed for charsets.c */ diff --git a/src/protocol/ftp/ftp.c b/src/protocol/ftp/ftp.c index 8afe2b34b..c96bd28f2 100644 --- a/src/protocol/ftp/ftp.c +++ b/src/protocol/ftp/ftp.c @@ -49,7 +49,7 @@ #include "protocol/common.h" #include "protocol/curl/ftpes.h" #include "protocol/ftp/ftp.h" -#include "protocol/ftp/parse.h" +#include "protocol/ftpparse.h" #include "protocol/uri.h" #include "util/conv.h" #include "util/error.h" diff --git a/src/protocol/ftp/meson.build b/src/protocol/ftp/meson.build index 8445a4b40..a273c6db6 100644 --- a/src/protocol/ftp/meson.build +++ b/src/protocol/ftp/meson.build @@ -1,7 +1,7 @@ -srcs += files('ftp.c', 'parse.c') +srcs += files('ftp.c') if get_option('test') - exe = executable('ftp-parser', 'ftp-parser.c', 'parse.c', meson.source_root()+'/src/protocol/date.c', testdeps, dependencies:[iconvdeps], + exe = executable('ftp-parser', 'ftp-parser.c', meson.source_root()+'/src/protocol/date.c', meson.source_root()+'/src/protocol/ftpparse.c', testdeps, dependencies:[iconvdeps], c_args:['-DHAVE_CONFIG_H'], cpp_args:['-DHAVE_CONFIG_H'], include_directories:['.','../..','../../..'], build_by_default:false) diff --git a/src/protocol/ftp/parse.c b/src/protocol/ftpparse.c similarity index 99% rename from src/protocol/ftp/parse.c rename to src/protocol/ftpparse.c index a532fb3a5..4e8e207d2 100644 --- a/src/protocol/ftp/parse.c +++ b/src/protocol/ftpparse.c @@ -23,7 +23,7 @@ #include "osdep/ascii.h" #include "osdep/stat.h" #include "protocol/date.h" -#include "protocol/ftp/parse.h" +#include "protocol/ftpparse.h" #include "util/conv.h" #include "util/string.h" #include "util/time.h" diff --git a/src/protocol/ftp/parse.h b/src/protocol/ftpparse.h similarity index 95% rename from src/protocol/ftp/parse.h rename to src/protocol/ftpparse.h index 80315ebab..8d385c51c 100644 --- a/src/protocol/ftp/parse.h +++ b/src/protocol/ftpparse.h @@ -1,7 +1,7 @@ /* FTP directory parsing */ -#ifndef EL__PROTOCOL_FTP_PARSE_H -#define EL__PROTOCOL_FTP_PARSE_H +#ifndef EL__PROTOCOL_FTPPARSE_H +#define EL__PROTOCOL_FTPPARSE_H #include "util/string.h" diff --git a/src/protocol/meson.build b/src/protocol/meson.build index f7da535db..aadadfc27 100644 --- a/src/protocol/meson.build +++ b/src/protocol/meson.build @@ -35,6 +35,11 @@ subdir('http') if conf_data.get('CONFIG_DATA') srcs += files('data.c') endif + +if conf_data.get('CONFIG_FTP') or conf_data.get('CONFIG_SFTP') + srcs += files('ftpparse.c') +endif + srcs += files('about.c', 'common.c', 'date.c', 'header.c', 'protocol.c', 'proxy.c', 'uri.c', 'user.c') if get_option('test') diff --git a/src/protocol/protocol.c b/src/protocol/protocol.c index d3fae896c..b8e79a0e5 100644 --- a/src/protocol/protocol.c +++ b/src/protocol/protocol.c @@ -336,7 +336,7 @@ static struct module *protocol_submodules[] = { #ifdef CONFIG_NNTP &nntp_protocol_module, #endif -#if defined(CONFIG_FTP) && defined(CONFIG_LIBCURL) +#if defined(CONFIG_SFTP) && defined(CONFIG_LIBCURL) &sftp_protocol_module, #endif #ifdef CONFIG_SMB diff --git a/src/protocol/test/Makefile b/src/protocol/test/Makefile index 706d0d243..964b1c771 100644 --- a/src/protocol/test/Makefile +++ b/src/protocol/test/Makefile @@ -5,7 +5,7 @@ TEST_PROGS = \ uri-test$(EXEEXT) TESTDEPS = \ - $(top_builddir)/src/protocol/protocol.obj \ + $(top_builddir)/src/protocol/protocol.o \ $(top_builddir)/src/protocol/uri.o \ stub.o diff --git a/src/protocol/test/meson.build b/src/protocol/test/meson.build index bdcf8ee08..6341f4a4b 100644 --- a/src/protocol/test/meson.build +++ b/src/protocol/test/meson.build @@ -1,6 +1,6 @@ idna_dep = dependency('libidn2') -uri_test_files = files('uri-test.c', 'stub.c', meson.current_source_dir()+'/../protocol.cpp', meson.current_source_dir()+'/../uri.c') +uri_test_files = files('uri-test.c', 'stub.c', meson.current_source_dir()+'/../protocol.c', meson.current_source_dir()+'/../uri.c') exe = executable('uri-test', uri_test_files, testdeps, dependencies: [iconvdeps, idna_dep, mozjsdeps, wattdeps],