[httpd_daap.c] Improve user_agent_filter() code

E.g. remove hardcoded values of DATA_KIND_x
This commit is contained in:
ejurgensen 2017-10-21 19:19:51 +02:00
parent 2deb3b1770
commit 66a46173fa
1 changed files with 14 additions and 11 deletions

View File

@ -531,25 +531,28 @@ is_remote(const char *user_agent)
static void static void
user_agent_filter(const char *user_agent, struct query_params *qp) user_agent_filter(const char *user_agent, struct query_params *qp)
{ {
const char *filter; char *filter;
char *buffer;
if (!user_agent) if (!user_agent)
return; return;
if (is_remote(user_agent)) 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); if (qp->filter)
free(qp->filter); filter = safe_asprintf("%s AND (f.data_kind <> %d)", qp->filter, DATA_KIND_HTTP);
qp->filter = buffer; else
filter = safe_asprintf("(f.data_kind <> %d)", DATA_KIND_HTTP);
} }
else 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); DPRINTF(E_DBG, L_DAAP, "SQL filter w/client mod: %s\n", qp->filter);
} }