From 055fe8f442d0fb3e6120d8bc379901f3eb6c86ca Mon Sep 17 00:00:00 2001 From: Kai Elwert Date: Sat, 31 Jul 2010 10:27:33 +0200 Subject: [PATCH] Make player_queue_make() generic and introduce player_queue_make_daap() --- src/httpd_dacp.c | 2 +- src/player.c | 68 +++++++++++++++++++++++++++--------------------- src/player.h | 2 +- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index 95fa1520..a88aa59d 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -716,7 +716,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u { sort = evhttp_find_header(query, "sort"); - ps = player_queue_make(cuequery, sort); + ps = player_queue_make_daap(cuequery, sort); if (!ps) { DPRINTF(E_LOG, L_DACP, "Could not build song queue\n"); diff --git a/src/player.c b/src/player.c index c1728626..4de138e0 100644 --- a/src/player.c +++ b/src/player.c @@ -338,10 +338,9 @@ player_laudio_status_cb(enum laudio_state status) /* Audio sources */ /* Thread: httpd (DACP) */ -struct player_source * -player_queue_make(const char *query, const char *sort) +static struct player_source * +player_queue_make(struct query_params *qp, const char *sort) { - struct query_params qp; struct db_media_file_info dbmfi; struct player_source *q_head; struct player_source *q_tail; @@ -349,46 +348,30 @@ player_queue_make(const char *query, const char *sort) uint32_t id; int ret; - memset(&qp, 0, sizeof(struct query_params)); - - qp.type = Q_ITEMS; - qp.offset = 0; - qp.limit = 0; - qp.idx_type = I_NONE; - qp.sort = S_NONE; - - qp.filter = daap_query_parse_sql(query); - if (!qp.filter) - { - DPRINTF(E_LOG, L_PLAYER, "Improper DAAP query!\n"); - - return NULL; - } + qp->idx_type = I_NONE; + qp->sort = S_NONE; if (sort) { if (strcmp(sort, "name") == 0) - qp.sort = S_NAME; + qp->sort = S_NAME; else if (strcmp(sort, "album") == 0) - qp.sort = S_ALBUM; + qp->sort = S_ALBUM; } - ret = db_query_start(&qp); + ret = db_query_start(qp); if (ret < 0) { DPRINTF(E_LOG, L_PLAYER, "Could not start query\n"); - if (qp.filter) - free(qp.filter); - return NULL; } - DPRINTF(E_DBG, L_PLAYER, "Player queue query returned %d items\n", qp.results); + DPRINTF(E_DBG, L_PLAYER, "Player queue query returned %d items\n", qp->results); q_head = NULL; q_tail = NULL; - while (((ret = db_query_fetch_file(&qp, &dbmfi)) == 0) && (dbmfi.id)) + while (((ret = db_query_fetch_file(qp, &dbmfi)) == 0) && (dbmfi.id)) { ret = safe_atou32(dbmfi.id, &id); if (ret < 0) @@ -428,10 +411,7 @@ player_queue_make(const char *query, const char *sort) DPRINTF(E_DBG, L_PLAYER, "Added song id %d (%s)\n", id, dbmfi.title); } - if (qp.filter) - free(qp.filter); - - db_query_end(&qp); + db_query_end(qp); if (ret < 0) { @@ -449,6 +429,34 @@ player_queue_make(const char *query, const char *sort) return q_head; } +/* Thread: httpd (DACP) */ +struct player_source * +player_queue_make_daap(const char *query, const char *sort) +{ + struct query_params qp; + struct player_source *ps; + + memset(&qp, 0, sizeof(struct query_params)); + + qp.type = Q_ITEMS; + qp.offset = 0; + qp.limit = 0; + + qp.filter = daap_query_parse_sql(query); + if (!qp.filter) + { + DPRINTF(E_LOG, L_PLAYER, "Improper DAAP query!\n"); + + return NULL; + } + + ps = player_queue_make(&qp, sort); + + free(qp.filter); + + return ps; +} + static void source_free(struct player_source *ps) { diff --git a/src/player.h b/src/player.h index 24fbfa34..46018e12 100644 --- a/src/player.h +++ b/src/player.h @@ -95,7 +95,7 @@ player_shuffle_set(int enable); struct player_source * -player_queue_make(const char *query, const char *sort); +player_queue_make_daap(const char *query, const char *sort); int player_queue_add(struct player_source *ps);