aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2020-05-25 18:17:03 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2020-05-25 18:17:03 +0200
commit6e1463620f9496b61ba565bfe07ce4822c162a94 (patch)
tree72da5b599d1fd7917c85cf345700ffcdb4130f14
parent5f6ef5f9b05a5a8aa6620f78411da74b1bcbadf4 (diff)
downloadtermsend-6e1463620f9496b61ba565bfe07ce4822c162a94.tar.gz
termsend-6e1463620f9496b61ba565bfe07ce4822c162a94.tar.bz2
termsend-6e1463620f9496b61ba565bfe07ce4822c162a94.zip
src: add -F, --ft-based-url to enable runtime configuration
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--src/Makefile.am2
-rw-r--r--src/config.c7
-rw-r--r--src/config.h1
-rw-r--r--src/server.c16
-rw-r--r--tst/Makefile.am2
-rw-r--r--tst/test-config.c5
-rwxr-xr-xtst/test-server.sh53
7 files changed, 61 insertions, 25 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 05ea44d..78728bb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,3 @@
-include ../Makefile.am.coverage
-
source = bnwlist.c \
config.c \
daemonize.c \
diff --git a/src/config.c b/src/config.c
index ea41eb2..a7b5fd8 100644
--- a/src/config.c
+++ b/src/config.c
@@ -67,7 +67,7 @@
/* list of short options for getopt_long */
static const char *shortopts =
- ":hvcDl:i:a:s:m:t:T:b:d:u:g:q:p:P:o:L:M:"
+ ":hvcDl:i:a:s:m:t:T:b:d:u:g:q:p:P:o:L:M:F"
#if HAVE_SSL
"I:A:k:C:f:"
#endif
@@ -98,6 +98,7 @@ struct option longopts[] =
{"pid-file", required_argument, NULL, 'P'},
{"output-dir", required_argument, NULL, 'o'},
{"list-file", required_argument, NULL, 'L'},
+ {"ft-based-url", no_argument, NULL, 'F'},
#if HAVE_SSL
{"ssl-listen-port", required_argument, NULL, 'I'},
{"timed-ssl-listen-port", required_argument, NULL, 'A'},
@@ -206,6 +207,7 @@ static int config_parse_arguments
{
case 'c': g_config.colorful_output = 1; break;
case 'D': g_config.daemonize = 1; break;
+ case 'F': g_config.ft_based_url = 1; break;
case 'l': PARSE_INT(log_level, 0, 7); break;
case 'i': PARSE_INT(listen_port, 0, UINT16_MAX); break;
case 'a': PARSE_INT(timed_listen_port, 0, UINT16_MAX); break;
@@ -244,6 +246,7 @@ static int config_parse_arguments
"\t-c, --colorful-output enable nice colors for logs\n"
"\t-i, --listen-port=<port> port on which program will listen\n"
"\t-a, --timed-listen-port=<port> port on which program will listen\n"
+"\t-F, --ft-based-url return different link based on file type\n"
#if HAVE_SSL
"\t-I, --ssl-listen-port=<port> ssl port on which program will listen\n"
"\t-A, --timed-ssl-listen-port=<port> ssl port on which program will listen\n"
@@ -373,6 +376,7 @@ int config_init
g_config.max_timeout = 60;
g_config.timed_max_timeout = 3;
g_config.pem_pass_file[0] = '\0';
+ g_config.ft_based_url = 0;
strcpy(g_config.domain, "localhost");
strcpy(g_config.bind_ip, "0.0.0.0");
strcpy(g_config.user, "termsend");
@@ -489,6 +493,7 @@ void config_print(void)
CONFIG_PRINT(output_dir, "%s");
CONFIG_PRINT(pid_file, "%s");
CONFIG_PRINT(bind_ip, "%s");
+ CONFIG_PRINT(ft_based_url, "%d");
#if HAVE_SSL
CONFIG_PRINT(ssl_listen_port, "%ld");
CONFIG_PRINT(timed_ssl_listen_port, "%ld");
diff --git a/src/config.h b/src/config.h
index f3e0c7f..4c362a7 100644
--- a/src/config.h
+++ b/src/config.h
@@ -38,6 +38,7 @@ struct config
long max_connections;
long max_timeout;
long timed_max_timeout;
+ int ft_based_url;
char domain[4096 + 1];
char bind_ip[1024 + 1];
char user[255 + 1];
diff --git a/src/server.c b/src/server.c
index 10c10ae..3911671 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1308,14 +1308,18 @@ int server_init(void)
* so do not exit when it fails
*/
- magic = magic_open(MAGIC_MIME_TYPE);
- if (magic == NULL)
- el_perror(ELW, "magic_open(MAGIC_MIME)");
+ if (g_config.ft_based_url)
+ {
+ el_print(ELF, "ft based url on");
+ magic = magic_open(MAGIC_MIME_TYPE);
+ if (magic == NULL)
+ el_perror(ELW, "magic_open(MAGIC_MIME)");
- /* load default magic database */
+ /* load default magic database */
- if (magic_load(magic, NULL) != 0)
- el_print(ELW, "magic_load(NULL) failed: %s", magic_error(magic));
+ if (magic_load(magic, NULL) != 0)
+ el_print(ELW, "magic_load(NULL) failed: %s", magic_error(magic));
+ }
return 0;
diff --git a/tst/Makefile.am b/tst/Makefile.am
index 5661f38..76329e8 100644
--- a/tst/Makefile.am
+++ b/tst/Makefile.am
@@ -1,5 +1,3 @@
-include ../Makefile.am.coverage
-
check_SCRIPTS = test-server.sh
check_PROGRAMS = test
test_SOURCES = main.c \
diff --git a/tst/test-config.c b/tst/test-config.c
index 0fbd734..a9782b5 100644
--- a/tst/test-config.c
+++ b/tst/test-config.c
@@ -74,6 +74,7 @@ static void test_prepare(void)
config.max_timeout = 60;
config.timed_max_timeout = 3;
config.pem_pass_file[0] = '\0';
+ config.ft_based_url = 0;
strcpy(config.domain, "localhost");
strcpy(config.bind_ip, "0.0.0.0");
strcpy(config.user, "termsend");
@@ -137,6 +138,7 @@ static void config_short_opts(void)
"-P/pid",
"-o", "/tmp",
"-b0.0.0.0,1.3.3.7",
+ "F",
#if HAVE_SSL
"-A103",
"-I101",
@@ -161,6 +163,7 @@ static void config_short_opts(void)
config.max_connections = 3;
config.max_timeout = 20;
config.timed_max_timeout = 7;
+ config.ft_based_url = 1;
strcpy(config.domain, "http://termsend.bofc.pl");
strcpy(config.bind_ip, "0.0.0.0,1.3.3.7");
strcpy(config.user, "kur");
@@ -210,6 +213,7 @@ static void config_long_opts(void)
"--pid-file=/pid",
"--output-dir=/tmp",
"--list-file=./main.c",
+ "--ft-based-url",
#if HAVE_SSL
"--timed-ssl-listen-port=103",
"--ssl-listen-port=101",
@@ -234,6 +238,7 @@ static void config_long_opts(void)
config.max_connections = 3;
config.max_timeout = 20;
config.timed_max_timeout = 7;
+ config.ft_based_url = 1;
strcpy(config.domain, "http://termsend.bofc.pl");
strcpy(config.bind_ip, "0.0.0.0,1.3.3.7");
strcpy(config.user, "kur");
diff --git a/tst/test-server.sh b/tst/test-server.sh
index ea6df2a..c54dd82 100755
--- a/tst/test-server.sh
+++ b/tst/test-server.sh
@@ -3,6 +3,7 @@
updir="./termsend-test/out"
data="./termsend-test/data"
pidfile="$(pwd)/termsend-test/termsend.pid"
+g_args=""
. ./mtest.sh
os="$(uname)"
@@ -34,9 +35,9 @@ start_termsend()
if [ ${ssl_test} = "openssl" ]
then
../src/termsend ${common_opts} -I61339 -A61340 -k./test-server.key.pem \
- -C./test-server.cert.pem -f./test-server.key.pass ${args}
+ -C./test-server.cert.pem -f./test-server.key.pass ${g_args}
else
- ../src/termsend ${common_opts} ${args}
+ ../src/termsend ${common_opts} ${g_args}
fi
# wait for termsend to start
@@ -362,11 +363,18 @@ test_is_running()
test_mime_text_c()
{
- out="$(termsend main.c | tail -n1)"
- mime="$(echo ${out} | rev | cut -d/ -f2 | rev)"
- file="$(echo ${out} | rev | cut -d/ -f-1 | rev)"
+ if echo "${g_args}" | grep "\-F"
+ then
+ # ft-based-url enabled
+ out="$(termsend main.c | tail -n1)"
+ mime="$(echo ${out} | rev | cut -d/ -f2 | rev)"
+ file="$(echo ${out} | rev | cut -d/ -f-1 | rev)"
+
+ mt_fail "[ \"x${mime}\" = \"xx-c\" ]"
+ else
+ file="$(termsend main.c | get_file)"
+ fi
- mt_fail "[ \"x${mime}\" = \"xx-c\" ]"
mt_fail "diff ${updir}/${file} main.c"
}
@@ -377,11 +385,18 @@ test_mime_text_c()
test_mime_text_shellscript()
{
- out="$(termsend shell-test.sh | tail -n1)"
- mime="$(echo ${out} | rev | cut -d/ -f2 | rev)"
- file="$(echo ${out} | rev | cut -d/ -f-1 | rev)"
+ if echo "${g_args}" | grep "\--ft-based-urll"
+ then
+ # ft-based-url enabled
+ out="$(termsend shell-test.sh | tail -n1)"
+ mime="$(echo ${out} | rev | cut -d/ -f2 | rev)"
+ file="$(echo ${out} | rev | cut -d/ -f-1 | rev)"
+
+ mt_fail "[ \"x${mime}\" = \"xx-shellscript\" ]"
+ else
+ file="$(termsend shell-test.sh | get_file)"
+ fi
- mt_fail "[ \"x${mime}\" = \"xx-shellscript\" ]"
mt_fail "diff ${updir}/${file} shell-test.sh"
}
@@ -825,10 +840,6 @@ run_tests()
timed_test=0
mt_run_named test_is_running "test_is_running-${prog_test}-${ssl_test}"
- mt_run_named test_mime_text_c "test_mime_text_c-${prog_test}-${ssl_test}"
- mt_run_named test_mime_text_shellscript "test_mime_text_shellscript-${prog_test}-${ssl_test}"
- mt_run_named test_mime_text_plain "test_mime_text_plain-${prog_test}-${ssl_test}"
- mt_run_named test_mime_bin "test_mime_bin-${prog_test}-${ssl_test}"
mt_run_named test_send_string "test_send_string-${prog_test}-${ssl_test}"
mt_run_named test_send_string_full "test_send_string_full-${prog_test}-${ssl_test}"
mt_run_named test_send_string_too_big "test_send_string_too_big-${prog_test}-${ssl_test}"
@@ -841,6 +852,20 @@ run_tests()
mt_run_named test_threaded "test_threaded-${prog_test}-${ssl_test}"
mt_run_named test_totally_random "test_totally_random-${prog_test}-${ssl_test}"
+ # run mime test with ft-based-url disabled
+ mt_run_named test_mime_text_c "test_mime_text_c-${prog_test}-${ssl_test}"
+ mt_run_named test_mime_text_shellscript "test_mime_text_shellscript-${prog_test}-${ssl_test}"
+ mt_run_named test_mime_text_plain "test_mime_text_plain-${prog_test}-${ssl_test}"
+ mt_run_named test_mime_bin "test_mime_bin-${prog_test}-${ssl_test}"
+
+ # run mime test with ft-based-url enabled
+ g_args="--ft-based-url"
+ mt_run_named test_mime_text_c "test_mime_text_c-${prog_test}-${ssl_test}"
+ mt_run_named test_mime_text_shellscript "test_mime_text_shellscript-${prog_test}-${ssl_test}"
+ mt_run_named test_mime_text_plain "test_mime_text_plain-${prog_test}-${ssl_test}"
+ mt_run_named test_mime_bin "test_mime_bin-${prog_test}-${ssl_test}"
+ g_args=""
+
timed_test=1
mt_run_named test_timed_upload "test_timed_upload-${prog_test}-${ssl_test}"