]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'refs/heads/t/sideband-cleanup'
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 4 Dec 2016 10:10:36 +0000 (11:10 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 4 Dec 2016 10:10:36 +0000 (11:10 +0100)
started on 2016-07-03, cooking since 2016-07-16

para_server announces sideband as an optional feature, which is
pointless since sideband connections have become mandatory in
paraslash-0.5.x, so they are always used. This patch set removes
the feature negitiation during the initial handshake. The sideband
protocol remains and is not affected.

Overwiew of the handshake in v0.5.x:
(SA) server announces sideband
(CC) client fails connection if server did not announce sideband
(CR) client requests sideband
(SC) server fails connection if sideband was not requested
already broken
- client-0.4/server-0.5 (!CR, SC)
- client-0.5/server-0.4 (!SA, CC)

Conversion plan:
rm (CC): breaks nothing
rm (SC): breaks nothing
rm (CR): breaks cl-0.6/server-0.5 (!CR, SC)
rm (SA): breaks cl-0.5/server-0.6 (!SA, CC)
server fails connection if client requests sideband

In this series only the first two conversion steps are done as they
can be merged early without breaking anything.

* refs/heads/t/sideband-cleanup:
  server: Do not fail if client does not request sideband.
  client: No longer fail connection if sideband was not announced.

25 files changed:
Makefile.in
Makefile.real
afh.c
afh_common.c
afs.c
audiod.c
audiod.h
audiod_command.c
configure.ac
daemon.c
daemon.h
error.h
filter.c
filter.h
filter_common.c
gcrypt.c
mood.c
mp3_afh.c
net.c
play.c
server.c
string.c
t/t0004-server.sh
t/test-lib.sh
version.c

index 61da659f370442e75173cd3a1810911a07c2575f..94b6482728bd940c124f6b57ae74fbf6113fdb65 100644 (file)
@@ -36,7 +36,6 @@ play_objs := @play_objs@
 speex_cppflags := @speex_cppflags@
 opus_cppflags := @opus_cppflags@
 vorbis_cppflags := @vorbis_cppflags@
-arch_cppflags := @arch_cppflags@
 osl_cppflags := @osl_cppflags@
 id3tag_cppflags := @id3tag_cppflags@
 openssl_cppflags := @openssl_cppflags@
@@ -70,8 +69,6 @@ ao_ldflags := @ao_ldflags@
 readline_ldflags := @readline_ldflags@
 samplerate_ldflags := @samplerate_ldflags@
 osl_ldflags := @osl_ldflags@
-socket_ldflags := @socket_ldflags@
-nsl_ldflags := @nsl_ldflags@
 curses_ldflags := @curses_ldflags@
 core_audio_ldflags := @core_audio_ldflags@
 crypto_ldflags := @crypto_ldflags@
index cc8225ba07852de3779fd21742b59442ba0cf336..ce4881d29c90c8626e44d384dab14c81e15b11b8 100644 (file)
@@ -19,6 +19,7 @@ uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
 uname_rs := $(shell uname -rs)
 cc_version := $(shell $(CC) --version | head -n 1)
 GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h)
+COPYRIGHT_YEAR := 2016
 
 ifeq ("$(origin O)", "command line")
        build_dir := $(O)
@@ -64,9 +65,8 @@ tarball_pfx := $(PACKAGE_TARNAME)-$(GIT_VERSION)
 tarball_delete := $(addprefix $(tarball_pfx)/, web .gitignore)
 tarball := $(tarball_pfx).tar.bz2
 
-.PHONY: dep all clean clean2 distclean maintainer-clean install man tarball
-all: dep $(prefixed_executables) $(man_pages)
-dep: $(deps)
+.PHONY: all clean clean2 distclean maintainer-clean install man tarball
+all: $(prefixed_executables) $(man_pages)
 man: $(man_pages)
 tarball: $(tarball)
 
@@ -91,6 +91,7 @@ $(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,\
 $(subst z,Z,$1))))))))))))))))))))))))))
 
 CPPFLAGS += -DBINDIR='"$(bindir)"'
+CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
 CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
 CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
 CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
@@ -113,6 +114,7 @@ STRICT_CFLAGS += -Wredundant-decls
 STRICT_CFLAGS += -Wno-sign-compare -Wno-unknown-pragmas
 STRICT_CFLAGS += -Wformat -Wformat-security
 STRICT_CFLAGS += -Wmissing-format-attribute
+STRICT_CFLAGS += -Wdeclaration-after-statement
 
 LDFLAGS += $(clock_gettime_ldflags)
 
@@ -331,14 +333,6 @@ para_recv \
 : LDFLAGS += \
        $(mp4v2_ldflags)
 
-para_server \
-para_client \
-para_audioc \
-para_audiod \
-para_recv \
-: LDFLAGS += \
-       $(socket_ldflags) $(nsl_ldflags)
-
 para_afh para_recv para_server para_play: LDFLAGS += $(iconv_ldflags)
 
 $(foreach exe,$(executables),$(eval para_$(exe): $$($(exe)_objs)))
diff --git a/afh.c b/afh.c
index 195b3788678549a5ab2554d0ac388e1a3a8f60f3..8975777bdb549ae68bc0fc125be7e959b4253ecc 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -169,7 +169,7 @@ __noreturn static void print_help_and_die(void)
  */
 int main(int argc, char **argv)
 {
-       int i, ret, audio_format_num, fd;
+       int i, ret = 0, audio_format_num, fd;
        void *audio_file_data;
        size_t audio_file_size;
        struct afh_info afhi;
@@ -177,12 +177,9 @@ int main(int argc, char **argv)
        afh_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        version_handle_flag("afh", conf.version_given);
-       if (conf.help_given || conf.detailed_help_given)
+       if (conf.help_given || conf.detailed_help_given || conf.inputs_num == 0)
                print_help_and_die();
        afh_init();
-       ret = -E_AFH_SYNTAX;
-       if (conf.inputs_num == 0)
-               goto out;
        for (i = 0; i < conf.inputs_num; i++) {
                int ret2;
                ret = mmap_full_file(conf.inputs[i], O_RDONLY, &audio_file_data,
index 063ae8f0b104ccab15e9f10f637ec34e7783e785..f36c32e20ec6332a24720d9bf106ab9b39d756ba 100644 (file)
@@ -139,6 +139,38 @@ int guess_audio_format(const char *name)
        return -E_AUDIO_FORMAT;
 }
 
+/**
+ * Get the name of the given audio format.
+ *
+ * \param i The audio format number.
+ *
+ * \return This returns a pointer to statically allocated memory so it
+ * must not be freed by the caller.
+ */
+const char *audio_format_name(int i)
+{
+       if (i < 0 || i >= ARRAY_SIZE(afl) - 1)
+               return "???";
+       return afl[i].name;
+}
+
+static int get_file_info(int format, const char *path, char *data,
+               size_t size, int fd, struct afh_info *afhi)
+{
+       int ret;
+       const char *fmt = audio_format_name(format);
+
+       memset(afhi, 0, sizeof(*afhi));
+       ret = afl[format].get_file_info(data, size, fd, afhi);
+       if (ret < 0) {
+               PARA_WARNING_LOG("%s: %s format not detected: %s\n",
+                       path, fmt, para_strerror(-ret));
+               return ret;
+       }
+       PARA_NOTICE_LOG("%s: detected %s format\n", path, fmt);
+       return format;
+}
+
 /**
  * Call get_file_info() to obtain an afhi structure.
  *
@@ -163,31 +195,18 @@ int compute_afhi(const char *path, char *data, size_t size, int fd,
 {
        int ret, i, format;
 
-       afhi->header_len = 0;
-       afhi->techinfo = NULL;
-       afhi->tags.artist = NULL;
-       afhi->tags.title = NULL;
-       afhi->tags.year = NULL;
-       afhi->tags.album = NULL;
-       afhi->tags.comment = NULL;
        format = guess_audio_format(path);
-
        if (format >= 0) {
-               ret = afl[format].get_file_info(data, size, fd, afhi);
-               if (ret >= 0) {
-                       ret = format;
+               ret = get_file_info(format, path, data, size, fd, afhi);
+               if (ret >= 0)
                        goto success;
-               }
        }
        FOR_EACH_AUDIO_FORMAT(i) {
                if (i == format) /* we already tried this one to no avail */
                        continue;
-               ret = afl[i].get_file_info(data, size, fd, afhi);
-               if (ret >= 0) {
-                       ret = i;
+               ret = get_file_info(i, path, data, size, fd, afhi);
+               if (ret >= 0)
                        goto success;
-               }
-               PARA_WARNING_LOG("%s\n", para_strerror(-ret));
        }
        return -E_AUDIO_FORMAT;
 success:
@@ -233,21 +252,6 @@ void clear_afhi(struct afh_info *afhi)
        free(afhi->tags.comment);
 }
 
-/**
- * Get the name of the given audio format.
- *
- * \param i The audio format number.
- *
- * \return This returns a pointer to statically allocated memory so it
- * must not be freed by the caller.
- */
-const char *audio_format_name(int i)
-{
-       if (i < 0 || i >= ARRAY_SIZE(afl) - 1)
-               return "???";
-       return afl[i].name;
-}
-
 static inline size_t get_chunk_len(long unsigned chunk_num,
                const struct afh_info *afhi)
 {
diff --git a/afs.c b/afs.c
index cc3fc020370821ff028a2543c354dab4acc08039..0accc45108f7c6ba0c2a3a89595d957d8a566920 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -607,14 +607,17 @@ static int com_select_callback(struct afs_callback_arg *aca)
        if (ret >= 0)
                goto out;
        /* ignore subsequent errors (but log them) */
-       para_printf(&aca->pbout, "could not activate %s: %s\n"
-               "switching back to %s\n",
-               arg, para_strerror(-ret), current_mop? current_mop : "dummy");
-       ret = activate_mood_or_playlist(current_mop, &num_admissible);
-       if (ret >= 0)
-               goto out;
-       para_printf(&aca->pbout, "could not activate %s: %s\nswitching to dummy\n",
-               current_mop, para_strerror(-ret));
+       para_printf(&aca->pbout, "could not activate %s\n", arg);
+       if (current_mop) {
+               int ret2;
+               para_printf(&aca->pbout, "switching back to %s\n", current_mop);
+               ret2 = activate_mood_or_playlist(current_mop, &num_admissible);
+               if (ret2 >= 0)
+                       goto out;
+               para_printf(&aca->pbout, "could not reactivate %s: %s\n",
+                       current_mop, para_strerror(-ret2));
+       }
+       para_printf(&aca->pbout, "activating dummy mood\n");
        activate_mood_or_playlist(NULL, &num_admissible);
 out:
        para_printf(&aca->pbout, "activated %s (%d admissible files)\n",
@@ -649,7 +652,7 @@ static int setup_command_socket_or_die(void)
        ret = create_local_socket(socket_name, 0);
        if (ret < 0) {
                ret = create_local_socket(socket_name,
-                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
+                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IROTH);
                if (ret < 0) {
                        PARA_EMERG_LOG("%s: %s\n", para_strerror(-ret),
                                socket_name);
index 5909859be6384604513185afebbe35e7152e27be..285d2762fa1093baf3e49211eab73ca631f605db 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -164,7 +164,7 @@ int audiod_status = AUDIOD_ON;
  * the gengetopt args_info struct that holds information on all command line
  * arguments
  */
-struct audiod_args_info conf;
+static struct audiod_args_info conf;
 
 static char *socket_name;
 static struct audio_format_info afi[NUM_AUDIO_FORMATS];
@@ -596,7 +596,8 @@ static void open_filters(struct slot_info *s)
                        EMBRACE(.name = f->name, .parent = parent,
                                .handler = f->execute, .context = fn));
 
-               f->open(fn);
+               if (f->open)
+                       f->open(fn);
                sprintf(buf, "%s (slot %d)", f->name, (int)(s - slot));
                fn->task = task_register(&(struct task_info) {
                        .name = buf,
@@ -1072,7 +1073,7 @@ static void init_local_sockets(struct command_task *ct)
                unlink(socket_name);
        ct->fd[0] = create_local_socket(socket_name, 0);
        ct->fd[1] = create_local_socket(socket_name,
-               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
+               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
        if (ct->fd[0] >= 0 || ct->fd[1] >= 0)
                return;
        PARA_EMERG_LOG("%s\n", para_strerror(-ct->fd[1]));
@@ -1123,7 +1124,7 @@ static int command_post_select(struct sched *s, void *context)
        for (i = 0; i < 2; i++) {
                if (ct->fd[i] < 0)
                        continue;
-               ret = handle_connect(ct->fd[i], &s->rfds, uid_whitelist);
+               ret = handle_connect(ct->fd[i], &s->rfds);
                if (ret < 0) {
                        PARA_ERROR_LOG("%s\n", para_strerror(-ret));
                        if (ret == -E_AUDIOD_TERM) {
@@ -1448,6 +1449,29 @@ __noreturn static void print_help_and_die(void)
        exit(0);
 }
 
+/**
+ * Lookup the given UID in the whitelist.
+ *
+ * The whitelist is the array of arguments to the --user-allow opion. If the
+ * option was not given, the array is empty, in which case the check succeeds.
+ *
+ * \param uid User ID to look up.
+ *
+ * \return True if --user-allow was not given, or if uid matches an element of
+ * the whitelist.
+ */
+bool uid_is_whitelisted(uid_t uid)
+{
+       int i;
+
+       if (!conf.user_allow_given)
+               return true;
+       for (i = 0; i < conf.user_allow_given; i++)
+               if (uid == uid_whitelist[i])
+                       return true;
+       return false;
+}
+
 /**
  * the main function of para_audiod
  *
@@ -1483,8 +1507,11 @@ int main(int argc, char *argv[])
        daemon_set_priority(conf.priority_arg);
        daemon_drop_privileges_or_die(conf.user_arg, conf.group_arg);
        parse_config_or_die();
-       daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
-               conf.logfile_given, conf.log_color_arg, conf.log_color_given);
+       if (daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
+               conf.logfile_given)) {
+                       for (i = 0; i < conf.log_color_given; i++)
+                               daemon_set_log_color_or_die(conf.log_color_arg[i]);
+       }
        init_random_seed_or_die();
        daemon_set_flag(DF_LOG_TIME);
        daemon_set_flag(DF_LOG_HOSTNAME);
index b9cfb25e8a34a931dab19e67303813f46ab6b738..7073c6dd2108fb31b915724fdbed431d76d51e63 100644 (file)
--- a/audiod.h
+++ b/audiod.h
@@ -22,15 +22,17 @@ extern const char *audio_formats[];
  */
 enum audiod_status_info {AUDIOD_OFF, AUDIOD_ON, AUDIOD_STANDBY};
 
-extern struct audiod_args_info conf;
 extern int audiod_status;
 
-int handle_connect(int accept_fd, fd_set *rfds, uid_t *uid_whitelist);
-void audiod_status_dump(bool force);
+/* defined in audiod.c */
+struct btr_node *audiod_get_btr_root(void);
 __malloc char *audiod_get_decoder_flags(void);
+void clear_and_dump_items(void);
 char *get_time_string(void);
-struct btr_node *audiod_get_btr_root(void);
+bool uid_is_whitelisted(uid_t uid);
 
-void stat_client_write_item(int item_num);
-void clear_and_dump_items(void);
+/* defined in audiod_command.c */
+void audiod_status_dump(bool force);
 void close_stat_clients(void);
+int handle_connect(int accept_fd, fd_set *rfds);
+void stat_client_write_item(int item_num);
index 278e6ef69e9f38a081aea8637405de8fcdc6e600..3a39027523a72c686d997d1b358912dc5dfd2363 100644 (file)
@@ -404,24 +404,11 @@ static int com_version(int fd, int argc, char **argv)
        return ret < 0? ret : 0;
 }
 
-static int check_perms(uid_t uid, uid_t *whitelist)
-{
-       int i;
-
-       if (!conf.user_allow_given)
-               return 1;
-       for (i = 0; i < conf.user_allow_given; i++)
-               if (uid == whitelist[i])
-                       return 1;
-       return -E_UCRED_PERM;
-}
-
 /**
  * Handle arriving connections on the local socket.
  *
  * \param accept_fd The fd to accept connections on.
  * \param rfds If \a accept_fd is not set in \a rfds, do nothing.
- * \param uid_whitelist Array of UIDs which are allowed to connect.
  *
  * This is called in each iteration of the select loop. If there is an incoming
  * connection on \a accept_fd, this function reads the command sent by the peer,
@@ -434,7 +421,7 @@ static int check_perms(uid_t uid, uid_t *whitelist)
  *
  * \sa para_accept(), recv_cred_buffer()
  * */
-int handle_connect(int accept_fd, fd_set *rfds, uid_t *uid_whitelist)
+int handle_connect(int accept_fd, fd_set *rfds)
 {
        int i, argc, ret, clifd;
        char buf[MAXLINE], **argv = NULL;
@@ -448,9 +435,9 @@ int handle_connect(int accept_fd, fd_set *rfds, uid_t *uid_whitelist)
        if (ret < 0)
                goto out;
        uid = ret;
-       PARA_INFO_LOG("connection from user %i, buf: %s\n", ret, buf);
-       ret = check_perms(uid, uid_whitelist);
-       if (ret < 0)
+       PARA_INFO_LOG("connection from UID %d, buf: %s\n", ret, buf);
+       ret = -E_UCRED_PERM;
+       if (!uid_is_whitelisted(uid))
                goto out;
        ret = create_argv(buf, "\n", &argv);
        if (ret <= 0)
index 953a9d213e5402055d1c22407daae60a292675e0..f9115fd652962881c1e7548c3cbac55e724305df 100644 (file)
@@ -159,12 +159,6 @@ case "$enable_cryptolib" in
        ;;
 esac
 AC_SUBST(crypto_ldflags)
-########################################################################### libsocket
-AC_CHECK_LIB([c], [socket],
-       [socket_ldlflags=],
-       [socket_ldflags="-lsocket"]
-)
-AC_SUBST(socket_ldflags)
 ########################################################################## iconv
 STASH_FLAGS
 LIBS=
@@ -189,12 +183,6 @@ AC_COMPILE_IFELSE([
 AC_DEFINE_UNQUOTED(ICONV_CAST, $cast, [cast for second arg to iconv()])
 AC_MSG_RESULT($msg)
 UNSTASH_FLAGS
-########################################################################### libnsl
-AC_CHECK_LIB([c], [gethostbyname],
-       [nsl_ldflags=],
-       [nsl_ldflags="-lnsl"]
-)
-AC_SUBST(nsl_ldflags)
 ########################################################################### ucred
 AC_MSG_CHECKING(for struct ucred)
 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
index 945c5a39a094e8314c5667f57f0b6a8099b12b45..7c625bbea9d84c5ac9b37a22253346576cbb7183 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -54,12 +54,12 @@ static void daemon_set_default_log_colors(void)
                color_parse_or_die(default_log_colors[i], me->log_colors[i]);
 }
 
-/*
+/**
  * Set the color for one loglevel.
  *
- * arg must be of the form "ll:[fg [bg]] [attr]".
+ * \param arg Must be of the form "ll:[fg [bg]] [attr]".
  */
-static void daemon_set_log_color_or_die(char const *arg)
+void daemon_set_log_color_or_die(const char *arg)
 {
        char *p = strchr(arg, ':');
        int ret, ll;
@@ -85,36 +85,31 @@ err:
  * \param color_arg_auto The value for automatic color detection.
  * \param color_arg_no The value to disable colored log messages.
  * \param logfile_given In auto mode colors are disabled if this value is true.
- * \param log_color_argv Color specifiers given to --log-color.
- * \param argc Number of color specifiers in \a log_color_argv.
  *
- * If \a color_arg equals \a color_arg_no, color mode is disabled, i.e., calls
- * to \a para_log() will not produce colored output. If \a color_arg == \a
- * color_arg_auto, the function autodetects whether to activate colors.
- * Otherwise color mode is enabled.
+ * If color_arg equals color_arg_no, color mode is disabled. That is, calls to
+ * para_log() will not produce colored output. If color_arg equals
+ * color_arg_auto, the function detects automatically whether to activate
+ * colors. Otherwise color mode is enabled.
+ *
+ * If color mode is to be enabled, the default colors are set for each
+ * loglevel. They can be overwritten by calling daemon_set_log_color_or_die().
  *
- * If color mode is to be enabled, the strings in \a log_color_argv are parsed
- * and the color scheme is updated accordingly. For each loglevel, the default
- * colors apply if there is no log_color_argv for this loglevel.
+ * \return Whether colors have been enabled by the function.
  */
-void daemon_init_colors_or_die(int color_arg, int color_arg_auto,
-               int color_arg_no, bool logfile_given, char **log_color_argv,
-               int argc)
+bool daemon_init_colors_or_die(int color_arg, int color_arg_auto,
+               int color_arg_no, bool logfile_given)
 {
-       int i;
-
        if (color_arg == color_arg_no)
-               return;
+               return false;
        if (color_arg == color_arg_auto) {
                if (logfile_given)
-                       return;
+                       return false;
                if (!isatty(STDERR_FILENO))
-                       return;
+                       return false;
        }
        daemon_set_flag(DF_COLOR_LOG);
        daemon_set_default_log_colors();
-       for (i = 0; i < argc; i++)
-               daemon_set_log_color_or_die(log_color_argv[i]);
+       return true;
 }
 
 /**
index e97678d660c12cf9a3ae1415c38fb0ae55b5ee5d..c715360583d350275641042b574708fd0cd2ec04 100644 (file)
--- a/daemon.h
+++ b/daemon.h
@@ -13,9 +13,9 @@ __malloc char *daemon_get_uptime_str(const struct timeval *current_time);
 void daemon_set_logfile(const char *logfile_name);
 void daemon_set_flag(unsigned flag);
 void daemon_set_loglevel(const char *loglevel);
-void daemon_init_colors_or_die(int color_arg, int color_arg_auto,
-               int color_arg_no, bool logfile_given, char **log_color_argv,
-               int argc);
+bool daemon_init_colors_or_die(int color_arg, int color_arg_auto,
+               int color_arg_no, bool logfile_given);
+void daemon_set_log_color_or_die(const char *arg);
 __printf_2_3 void daemon_log(int ll, const char* fmt,...);
 
 /** Daemon log configuration flags. */
diff --git a/error.h b/error.h
index 3bfd8a96cf306bfa1c86930a7d364753dcc761fb..3fda5787774ce739754a58d74706c3081f1e9da5 100644 (file)
--- a/error.h
+++ b/error.h
@@ -103,7 +103,7 @@ extern const char **para_errlist[];
 
 
 #define AFH_RECV_ERRORS \
-       PARA_ERROR(AFH_RECV_BAD_FILENAME, "invalid file name"), \
+       PARA_ERROR(AFH_RECV_BAD_FILENAME, "no file name given"), \
 
 
 #define OGG_AFH_COMMON_ERRORS \
index 9378e4695b6b113843d7d1b34a96ded4bdebd79e..804b5e1e569a9c680e309f14738e77481161682a 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -142,7 +142,8 @@ int main(int argc, char *argv[])
                ti.pre_select = f->pre_select;
                ti.post_select = f->post_select;
                ti.context = fn;
-               f->open(fn);
+               if (f->open)
+                       f->open(fn);
                fn->task = task_register(&ti, &s);
                parent = fn->btrn;
        }
index 686776a0b7e27c42645c143aeca4a79bd83d325c..0bd546903927d412fccef946cf8f43783ed8bc70 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -58,17 +58,18 @@ struct filter {
        /**
         * Open one instance of this filter.
         *
-        * This should allocate the output buffer of the given filter node and do any
-        * other filter-specific preparations like initializing the private_data member
-        * of \a fn suitably. The open function is assumed to succeed.
+        * This should allocate the output buffer of the given filter node and
+        * do any other filter-specific preparations like initializing the
+        * private_data member of \a fn suitably. The open function is
+        * optional, If it is provided, it is assumed to succeed.
         */
        void (*open)(struct filter_node *fn);
        /**
         * Close one instance of this filter.
         *
-        * Free all resources of associated with \a fn that were previously allocated
-        * by the open() function. It's OK to leave this alone if the filter does not
-        * need any cleanups.
+        * Free all resources associated with \a fn that were previously
+        * allocated by the open() function. It's OK to set this to NULL if the
+        * filter does not need to perform any cleanup operation.
         */
        void (*close)(struct filter_node *fn);
        /**
@@ -121,7 +122,7 @@ struct filter {
 };
 
 void filter_init(void);
-int check_filter_arg(char *filter_arg, void **conf);
+int check_filter_arg(const char *fa, void **conf);
 void print_filter_helps(unsigned flags);
 void generic_filter_pre_select(struct sched *s, void *context);
 int decoder_execute(const char *cmd, unsigned sample_rate, unsigned channels,
index 6fb9bd96ef8278b3e328198e24db78664a956542..84863b39fb489cb9b4ac546b6fe4f557b1d647bf 100644 (file)
@@ -58,7 +58,7 @@ void filter_init(void)
  * If the filter has a command line parser and options is not NULL, run it.
  * Returns filter_num on success, negative on errors
  */
-static int parse_filter_args(int filter_num, char *options, void **conf)
+static int parse_filter_args(int filter_num, const char *options, void **conf)
 {
        const struct filter *f = filter_get(filter_num);
        int ret, argc;
@@ -78,11 +78,12 @@ static int parse_filter_args(int filter_num, char *options, void **conf)
 /**
  * Check the filter command line options.
  *
- * \param fa The command line options.
+ * \param fa The filter argument.
  * \param conf Points to the filter configuration upon successful return.
  *
- * Check if \a fa starts with a the name of a supported filter, followed by
- * a colon. If yes, call the command line parser of that filter.
+ * Check if the given filter argument starts with the name of a supported
+ * filter, optionally followed by options for this filter. If yes, call the
+ * command line parser of that filter.
  *
  * \return On success, the number of the filter is returned and \a conf
  * is initialized to point to the filter configuration determined by \a fa.
@@ -93,7 +94,7 @@ static int parse_filter_args(int filter_num, char *options, void **conf)
  *
  * \sa filter::parse_config
  */
-int check_filter_arg(char *fa, void **conf)
+int check_filter_arg(const char *fa, void **conf)
 {
        int j;
 
index 45a1c67d20da0b6d229180de92be10644a63d082..3c6c1ad1d74c234f56f289a46fad98cede2a5140 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -212,7 +212,7 @@ static int decode_key(const char *key_file, const char *header_str,
 
        ret = mmap_full_file(key_file, O_RDONLY, &map, &map_size, NULL);
        if (ret < 0)
-               return ret;
+               goto out;
        ret = -E_KEY_MARKER;
        if (strncmp(map, header_str, strlen(header_str)))
                goto unmap;
@@ -257,6 +257,7 @@ unmap:
                free(blob);
                blob = NULL;
        }
+out:
        *result = blob;
        return ret;
 }
@@ -781,6 +782,9 @@ int priv_decrypt(const char *key_file, unsigned char *outbuf,
        gcry_sexp_t in, out, priv_key;
        size_t nbytes;
 
+       ret = check_key_file(key_file, true);
+       if (ret < 0)
+               return ret;
        PARA_INFO_LOG("decrypting %d byte input\n", inlen);
        /* key_file -> asymmetric key priv */
        ret = get_private_key(key_file, &priv);
diff --git a/mood.c b/mood.c
index 83c3a574a53c5658afe43a296ae2de9f2c368873..940d72a17f9cbeb1d8dec42ea26cd9a821f9cbb3 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -19,6 +19,7 @@
 #include "mm.h"
 #include "sideband.h"
 #include "mood.h"
+#include "sched.h"
 
 /**
  * Contains statistical data of the currently admissible audio files.
@@ -753,16 +754,27 @@ static int mood_update_audio_file(const struct osl_row *aft_row,
 static void log_statistics(void)
 {
        unsigned n = statistics.num;
+       int mean_days, sigma_days;
+       /*
+        * We can not use the "now" pointer from sched.c here because we are
+        * called before schedule(), which initializes "now".
+        */
+       struct timeval rnow;
 
+       assert(current_mood);
+       PARA_NOTICE_LOG("loaded mood %s\n", current_mood->name?
+               current_mood->name : "(dummy)");
        if (!n) {
-               PARA_NOTICE_LOG("no admissible files\n");
+               PARA_WARNING_LOG("no admissible files\n");
                return;
        }
-       PARA_INFO_LOG("last_played mean: %lli, last_played sigma: %llu\n",
-               (long long int)(statistics.last_played_sum / n),
-               (long long unsigned)int_sqrt(statistics.last_played_qd / n));
-       PARA_INFO_LOG("num_played mean: %lli, num_played sigma: %llu\n",
-               (long long int)statistics.num_played_sum / n,
+       PARA_NOTICE_LOG("%u admissible files\n", statistics.num);
+       clock_get_realtime(&rnow);
+       mean_days = (rnow.tv_sec - statistics.last_played_sum / n) / 3600 / 24;
+       sigma_days = int_sqrt(statistics.last_played_qd / n) / 3600 / 24;
+       PARA_NOTICE_LOG("last_played mean/sigma: %d/%d days\n", mean_days, sigma_days);
+       PARA_NOTICE_LOG("num_played mean/sigma: %llu/%llu\n",
+               (long long unsigned)statistics.num_played_sum / n,
                (long long unsigned)int_sqrt(statistics.num_played_qd / n));
 }
 
@@ -829,15 +841,13 @@ int change_current_mood(const char *mood_name)
        ret = audio_file_loop(&aa, add_if_admissible);
        if (ret < 0)
                return ret;
-       log_statistics();
-       PARA_INFO_LOG("%d admissible files\n", statistics.num);
        for (i = 0; i < statistics.num; i++) {
                struct admissible_file_info *a = aa.array + i;
                ret = add_to_score_table(a->aft_row, a->score);
                if (ret < 0)
                        goto out;
        }
-       PARA_NOTICE_LOG("loaded mood %s\n", mood_name? mood_name : "(dummy)");
+       log_statistics();
        ret = statistics.num;
 out:
        free(aa.array);
index 382b0e9091c4cb3d6679f9779ad6faff9fb1fe15..70f2ec9f6b3817887799edab3292f7136aec0a84 100644 (file)
--- a/mp3_afh.c
+++ b/mp3_afh.c
@@ -662,7 +662,6 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
                header_mode(&header), tag_versions[ret]);
        return 1;
 err_out:
-       PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        free(afhi->chunk_table);
        return ret;
 }
diff --git a/net.c b/net.c
index 1b142a3cd4a25b87fe2e31c86caaf32e4be5f51e..1369498905faa4ab729bac8209a6a03e8b920063 100644 (file)
--- a/net.c
+++ b/net.c
@@ -175,8 +175,7 @@ char *parse_url(const char *url,
        }
 
        if (*o == ':')
-               if (para_atoi32(++o, port) < 0 ||
-                   *port < 0 || *port > 0xffff)
+               if (para_atoi32(++o, port) < 0 || *port < 0 || *port > 0xffff)
                        goto failed;
        if (host_string_ok(host))
                return host;
@@ -187,6 +186,7 @@ failed:
 
 /**
  * Stringify port number, resolve into service name where defined.
+ *
  * \param port 2-byte port number, in host-byte-order.
  * \param transport Transport protocol name (e.g. "udp", "tcp"), or NULL.
  * \return Pointer to static result buffer.
diff --git a/play.c b/play.c
index a7ce563baafae4e39e33de07867669085c648ac3..d2539ee134773614a40bca9941f35dd161007946 100644 (file)
--- a/play.c
+++ b/play.c
@@ -397,7 +397,8 @@ static int load_file(struct play_task *pt)
        pt->fn.btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = decoder->name, .parent = pt->rn.btrn,
                        .handler = decoder->execute, .context = &pt->fn));
-       decoder->open(&pt->fn);
+       if (decoder->open)
+               decoder->open(&pt->fn);
 
        /* setup default writer */
        pt->wn.conf = check_writer_arg_or_die(NULL, &pt->wn.writer_num);
index 71a9ec505f6d096a1dc589a9cdf6c1f484e5090d..088cc8b124448123ed6f4cb73f0226f584dffc25 100644 (file)
--- a/server.c
+++ b/server.c
@@ -207,8 +207,12 @@ void parse_config_or_die(int override)
                daemon_open_log_or_die();
        }
 
-       daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
-               conf.logfile_given, conf.log_color_arg, conf.log_color_given);
+       if (daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
+                       conf.logfile_given)) {
+               int i;
+               for (i = 0; i < conf.log_color_given; i++)
+                       daemon_set_log_color_or_die(conf.log_color_arg[i]);
+       }
        daemon_set_flag(DF_LOG_PID);
        daemon_set_flag(DF_LOG_LL);
        daemon_set_flag(DF_LOG_TIME);
index 86e775387a9a7d5b1c0f429a99255ba621024d30..6033a008dbf154953de673f85048eb78812d1722 100644 (file)
--- a/string.c
+++ b/string.c
@@ -803,15 +803,18 @@ err:
  * Split a buffer into words.
  *
  * This parser honors single and double quotes, backslash-escaped characters
- * and special characters like \p \\n. The result contains pointers to copies
- * of the words contained in \a buf and has to be freed by using \ref
- * free_argv().
+ * and special characters like \\n. The result contains pointers to copies of
+ * the words contained in buf and has to be freed by using \ref free_argv().
  *
  * \param buf The buffer to be split.
  * \param delim Each character in this string is treated as a separator.
  * \param result The array of words is returned here.
  *
- * \return Number of words in \a buf, negative on errors.
+ * It's OK to pass NULL as the buffer argument. This is equivalent to passing
+ * the empty string.
+ *
+ * \return Number of words in buf, negative on errors. The array returned
+ * through the result pointer is NULL terminated.
  */
 int create_argv(const char *buf, const char *delim, char ***result)
 {
index 3cb37d4260cf21fb3ec83109642642cf67bc1f52..c2e809cb6da569d05177bd3552ece039047a96e7 100755 (executable)
@@ -108,6 +108,7 @@ EOF
                --user-list "$user_list" \
                --http-port "$stream_port" \
                --dccp-port "$stream_port"
+       (($? != 0)) && exit 1
 fi
 
 for ((i=0; i < ${#commands[@]}; i++)); do
index 99e575d3b66d0f54e9746647eee1af4eba84fa2c..1f9913e3cf9ba49b4cb76cc5b985d914cb527b69 100644 (file)
@@ -156,7 +156,7 @@ test_require_executables()
 test_duration()
 {
        local t=$(exec 2>&1 1>/dev/null; time -p "$@")
-       result=$(awk '{print $2 * 1000}' <<< $t)
+       result=$(awk '{print $2 * 1000; exit 0}' <<< "$t")
 }
 
 test_expect_success()
index 6cbb0534746197460f4aa75d2eb2caba1a4d4c0c..bc61f54bba03aaa5a3255c6831b1bf8d6e9d2324 100644 (file)
--- a/version.c
+++ b/version.c
@@ -43,7 +43,7 @@ const char *version_text(const char *pfx)
        static char buf[512];
 
        snprintf(buf, sizeof(buf) - 1, "%s\n"
-               "Copyright (C) 2002-2016 Andre Noll\n"
+               "Copyright (C) " COPYRIGHT_YEAR " Andre Noll\n"
                "This is free software with ABSOLUTELY NO WARRANTY."
                " See COPYING for details.\n"
                "Report bugs to <maan@tuebingen.mpg.de>.\n"