mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-20 18:54:05 -04:00
[httpd_dacp] Clean up code, remove dead stores
This commit is contained in:
parent
1070f507a2
commit
a57f7fc188
@ -1004,7 +1004,6 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
const char *sort;
|
const char *sort;
|
||||||
const char *cuequery;
|
const char *cuequery;
|
||||||
const char *param;
|
const char *param;
|
||||||
uint32_t item_id;
|
|
||||||
uint32_t pos;
|
uint32_t pos;
|
||||||
int clear;
|
int clear;
|
||||||
struct db_queue_item *queue_item = NULL;
|
struct db_queue_item *queue_item = NULL;
|
||||||
@ -1052,7 +1051,6 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
if (param)
|
if (param)
|
||||||
dacp_propset_shufflestate(param, NULL);
|
dacp_propset_shufflestate(param, NULL);
|
||||||
|
|
||||||
item_id = 0;
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
param = evhttp_find_header(query, "index");
|
param = evhttp_find_header(query, "index");
|
||||||
if (param)
|
if (param)
|
||||||
@ -1074,9 +1072,8 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
|
|||||||
if (history->count > pos)
|
if (history->count > pos)
|
||||||
{
|
{
|
||||||
pos = (history->start_index + history->count - pos - 1) % MAX_HISTORY_COUNT;
|
pos = (history->start_index + history->count - pos - 1) % MAX_HISTORY_COUNT;
|
||||||
item_id = history->item_id[pos];
|
|
||||||
|
|
||||||
queue_item = db_queue_fetch_byitemid(item_id);
|
queue_item = db_queue_fetch_byitemid(history->item_id[pos]);
|
||||||
if (!queue_item)
|
if (!queue_item)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not start playback from history\n");
|
DPRINTF(E_LOG, L_DACP, "Could not start playback from history\n");
|
||||||
@ -1595,7 +1592,7 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
int count;
|
int count;
|
||||||
int ret;
|
int ret;
|
||||||
int start_index;
|
int start_index;
|
||||||
struct query_params query_params;
|
struct query_params qp;
|
||||||
struct db_queue_item queue_item;
|
struct db_queue_item queue_item;
|
||||||
|
|
||||||
/* /ctrl-int/1/playqueue-contents?span=50&session-id=... */
|
/* /ctrl-int/1/playqueue-contents?span=50&session-id=... */
|
||||||
@ -1615,7 +1612,6 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
DPRINTF(E_LOG, L_DACP, "Invalid span value in playqueue-contents request\n");
|
DPRINTF(E_LOG, L_DACP, "Invalid span value in playqueue-contents request\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
count = 0; // count of songs in songlist
|
|
||||||
songlist = evbuffer_new();
|
songlist = evbuffer_new();
|
||||||
if (!songlist)
|
if (!songlist)
|
||||||
{
|
{
|
||||||
@ -1627,6 +1623,8 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
|
|
||||||
player_get_status(&status);
|
player_get_status(&status);
|
||||||
|
|
||||||
|
count = 0; // count of songs in songlist
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the span parameter is negativ make song list for Previously Played,
|
* If the span parameter is negativ make song list for Previously Played,
|
||||||
* otherwise make song list for Up Next and begin with first song after playlist position.
|
* otherwise make song list for Up Next and begin with first song after playlist position.
|
||||||
@ -1642,59 +1640,51 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
{
|
{
|
||||||
start_index = (history->start_index + history->count - abs(span)) % MAX_HISTORY_COUNT;
|
start_index = (history->start_index + history->count - abs(span)) % MAX_HISTORY_COUNT;
|
||||||
}
|
}
|
||||||
for (count = 0; count < history->count && count < abs(span); count++)
|
|
||||||
|
while ((count < history->count) && (count < abs(span)))
|
||||||
{
|
{
|
||||||
ret = playqueuecontents_add_source(songlist, history->id[(start_index + count) % MAX_HISTORY_COUNT], (count + 1), status.plid);
|
ret = playqueuecontents_add_source(songlist, history->id[(start_index + count) % MAX_HISTORY_COUNT], (count + 1), status.plid);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
goto error;
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not add song to songlist for playqueue-contents\n");
|
|
||||||
|
|
||||||
dmap_send_error(req, "ceQR", "Out of memory");
|
count++;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset(&query_params, 0, sizeof(struct query_params));
|
memset(&qp, 0, sizeof(struct query_params));
|
||||||
if (status.shuffle)
|
|
||||||
query_params.sort = S_SHUFFLE_POS;
|
|
||||||
ret = db_queue_enum_start(&query_params);
|
|
||||||
|
|
||||||
count = 0; //FIXME [queue] Check count value
|
if (status.shuffle)
|
||||||
while ((ret = db_queue_enum_fetch(&query_params, &queue_item)) == 0 && queue_item.id > 0)
|
qp.sort = S_SHUFFLE_POS;
|
||||||
|
|
||||||
|
ret = db_queue_enum_start(&qp);
|
||||||
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
//FIXME [queue] Check count value
|
||||||
|
while ((db_queue_enum_fetch(&qp, &queue_item) == 0) && (queue_item.id > 0))
|
||||||
{
|
{
|
||||||
if (status.item_id == 0 || status.item_id == queue_item.id)
|
if (status.item_id == 0 || status.item_id == queue_item.id)
|
||||||
|
{
|
||||||
count = 1;
|
count = 1;
|
||||||
|
}
|
||||||
else if (count > 0)
|
else if (count > 0)
|
||||||
{
|
{
|
||||||
ret = playqueuecontents_add_queue_item(songlist, &queue_item, count, status.plid);
|
ret = playqueuecontents_add_queue_item(songlist, &queue_item, count, status.plid);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
goto error;
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not add song to songlist for playqueue-contents\n");
|
|
||||||
|
|
||||||
dmap_send_error(req, "ceQR", "Out of memory");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_queue_enum_end(&query_params);
|
db_queue_enum_end(&qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Playlists are hist, curr and main. */
|
/* Playlists are hist, curr and main. */
|
||||||
playlists = evbuffer_new();
|
playlists = evbuffer_new();
|
||||||
if (!playlists)
|
if (!playlists)
|
||||||
{
|
goto error;
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not allocate playlists evbuffer for playqueue-contents\n");
|
|
||||||
if (songlist)
|
|
||||||
evbuffer_free(songlist);
|
|
||||||
|
|
||||||
dmap_send_error(req, "ceQR", "Out of memory");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dmap_add_container(playlists, "mlit", 61);
|
dmap_add_container(playlists, "mlit", 61);
|
||||||
dmap_add_string(playlists, "ceQk", "hist"); /* 12 */
|
dmap_add_string(playlists, "ceQk", "hist"); /* 12 */
|
||||||
@ -1702,7 +1692,7 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
dmap_add_int(playlists, "ceQm", 200); /* 12 */
|
dmap_add_int(playlists, "ceQm", 200); /* 12 */
|
||||||
dmap_add_string(playlists, "ceQl", "Previously Played"); /* 25 = 8 + 17 */
|
dmap_add_string(playlists, "ceQl", "Previously Played"); /* 25 = 8 + 17 */
|
||||||
|
|
||||||
if (songlist)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
dmap_add_container(playlists, "mlit", 36);
|
dmap_add_container(playlists, "mlit", 36);
|
||||||
dmap_add_string(playlists, "ceQk", "curr"); /* 12 */
|
dmap_add_string(playlists, "ceQk", "curr"); /* 12 */
|
||||||
@ -1730,34 +1720,30 @@ dacp_reply_playqueuecontents(struct evhttp_request *req, struct evbuffer *evbuf,
|
|||||||
dmap_add_char(evbuf, "ceQu", 0); /* 9 */
|
dmap_add_char(evbuf, "ceQu", 0); /* 9 */
|
||||||
dmap_add_container(evbuf, "mlcl", 8 + playlist_length + songlist_length); /* 8 */
|
dmap_add_container(evbuf, "mlcl", 8 + playlist_length + songlist_length); /* 8 */
|
||||||
dmap_add_container(evbuf, "ceQS", playlist_length); /* 8 */
|
dmap_add_container(evbuf, "ceQS", playlist_length); /* 8 */
|
||||||
|
|
||||||
ret = evbuffer_add_buffer(evbuf, playlists);
|
ret = evbuffer_add_buffer(evbuf, playlists);
|
||||||
evbuffer_free(playlists);
|
evbuffer_free(playlists);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
goto error;
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not add playlists to evbuffer for playqueue-contents\n");
|
|
||||||
if (songlist)
|
|
||||||
evbuffer_free(songlist);
|
|
||||||
|
|
||||||
dmap_send_error(req, "ceQR", "Out of memory");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (songlist)
|
|
||||||
{
|
|
||||||
ret = evbuffer_add_buffer(evbuf, songlist);
|
ret = evbuffer_add_buffer(evbuf, songlist);
|
||||||
evbuffer_free(songlist);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
goto error;
|
||||||
DPRINTF(E_LOG, L_DACP, "Could not add songlist to evbuffer for playqueue-contents\n");
|
|
||||||
|
evbuffer_free(songlist);
|
||||||
|
|
||||||
dmap_send_error(req, "ceQR", "Out of memory");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dmap_add_char(evbuf, "apsm", status.shuffle); /* 9, daap.playlistshufflemode - not part of mlcl container */
|
dmap_add_char(evbuf, "apsm", status.shuffle); /* 9, daap.playlistshufflemode - not part of mlcl container */
|
||||||
dmap_add_char(evbuf, "aprm", status.repeat); /* 9, daap.playlistrepeatmode - not part of mlcl container */
|
dmap_add_char(evbuf, "aprm", status.repeat); /* 9, daap.playlistrepeatmode - not part of mlcl container */
|
||||||
|
|
||||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf, 0);
|
httpd_send_reply(req, HTTP_OK, "OK", evbuf, 0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
DPRINTF(E_LOG, L_DACP, "Out of memory in dacp_reply_playqueuecontents or database error\n");
|
||||||
|
|
||||||
|
evbuffer_free(songlist);
|
||||||
|
dmap_send_error(req, "ceQR", "Out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user