From 66a46173faa676b42022e9c206cc607ce3780179 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sat, 21 Oct 2017 19:19:51 +0200 Subject: [PATCH] [httpd_daap.c] Improve user_agent_filter() code E.g. remove hardcoded values of DATA_KIND_x --- src/httpd_daap.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 8a58f872..90f483fe 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -531,25 +531,28 @@ is_remote(const char *user_agent) static void user_agent_filter(const char *user_agent, struct query_params *qp) { - const char *filter; - char *buffer; + char *filter; if (!user_agent) return; if (is_remote(user_agent)) - filter = "(f.data_kind <> 1)"; // No internet radio - else - filter = "(f.data_kind = 0)"; // Only real files - - if (qp->filter) { - buffer = safe_asprintf("%s AND %s", qp->filter, filter); - free(qp->filter); - qp->filter = buffer; + if (qp->filter) + filter = safe_asprintf("%s AND (f.data_kind <> %d)", qp->filter, DATA_KIND_HTTP); + else + filter = safe_asprintf("(f.data_kind <> %d)", DATA_KIND_HTTP); } else - qp->filter = strdup(filter); + { + if (qp->filter) + filter = safe_asprintf("%s AND (f.data_kind = %d)", qp->filter, DATA_KIND_FILE); + else + filter = safe_asprintf("(f.data_kind = %d)", DATA_KIND_FILE); + } + + free(qp->filter); + qp->filter = filter; DPRINTF(E_DBG, L_DAAP, "SQL filter w/client mod: %s\n", qp->filter); }