mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-27 06:33:21 -05:00
Add sort-headers support to DAAP browse query
This commit is contained in:
parent
eaaaec91a1
commit
8a2d76895c
@ -2310,8 +2310,10 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct daap_session *s;
|
struct daap_session *s;
|
||||||
struct evbuffer *itemlist;
|
struct evbuffer *itemlist;
|
||||||
|
struct sort_ctx *sctx;
|
||||||
char *browse_item;
|
char *browse_item;
|
||||||
char *tag;
|
char *tag;
|
||||||
|
int sort_headers;
|
||||||
int nitems;
|
int nitems;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -2379,7 +2381,24 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_query_params(query, NULL, &qp);
|
get_query_params(query, &sort_headers, &qp);
|
||||||
|
|
||||||
|
sctx = NULL;
|
||||||
|
if (sort_headers)
|
||||||
|
{
|
||||||
|
sctx = daap_sort_context_new();
|
||||||
|
if (!sctx)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_DAAP, "Could not create sort context\n");
|
||||||
|
|
||||||
|
dmap_send_error(req, "abro", "Out of memory");
|
||||||
|
|
||||||
|
evbuffer_free(itemlist);
|
||||||
|
if (qp.filter)
|
||||||
|
free(qp.filter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = db_query_start(&qp);
|
ret = db_query_start(&qp);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -2388,6 +2407,9 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
|
|
||||||
dmap_send_error(req, "abro", "Could not start query");
|
dmap_send_error(req, "abro", "Could not start query");
|
||||||
|
|
||||||
|
if (sort_headers)
|
||||||
|
daap_sort_context_free(sctx);
|
||||||
|
|
||||||
evbuffer_free(itemlist);
|
evbuffer_free(itemlist);
|
||||||
if (qp.filter)
|
if (qp.filter)
|
||||||
free(qp.filter);
|
free(qp.filter);
|
||||||
@ -2399,6 +2421,17 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
{
|
{
|
||||||
nitems++;
|
nitems++;
|
||||||
|
|
||||||
|
if (sort_headers)
|
||||||
|
{
|
||||||
|
ret = daap_sort_build(sctx, browse_item);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_DAAP, "Could not add sort header to DAAP browse reply\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dmap_add_string(itemlist, "mlit", browse_item);
|
dmap_add_string(itemlist, "mlit", browse_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2407,18 +2440,27 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DAAP, "Error fetching results\n");
|
DPRINTF(E_LOG, L_DAAP, "Error fetching/building results\n");
|
||||||
|
|
||||||
dmap_send_error(req, "abro", "Error fetching query results");
|
dmap_send_error(req, "abro", "Error fetching/building query results");
|
||||||
db_query_end(&qp);
|
db_query_end(&qp);
|
||||||
|
|
||||||
|
if (sort_headers)
|
||||||
|
daap_sort_context_free(sctx);
|
||||||
|
|
||||||
evbuffer_free(itemlist);
|
evbuffer_free(itemlist);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmap_add_container(evbuf, "abro", EVBUFFER_LENGTH(itemlist) + 44);
|
if (sort_headers)
|
||||||
|
dmap_add_container(evbuf, "abro", EVBUFFER_LENGTH(itemlist) + EVBUFFER_LENGTH(sctx->headerlist) + 44);
|
||||||
|
else
|
||||||
|
dmap_add_container(evbuf, "abro", EVBUFFER_LENGTH(itemlist) + 44);
|
||||||
|
|
||||||
dmap_add_int(evbuf, "mstt", 200); /* 12 */
|
dmap_add_int(evbuf, "mstt", 200); /* 12 */
|
||||||
dmap_add_int(evbuf, "mtco", qp.results); /* 12 */
|
dmap_add_int(evbuf, "mtco", qp.results); /* 12 */
|
||||||
dmap_add_int(evbuf, "mrco", nitems); /* 12 */
|
dmap_add_int(evbuf, "mrco", nitems); /* 12 */
|
||||||
|
|
||||||
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(itemlist));
|
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(itemlist));
|
||||||
|
|
||||||
db_query_end(&qp);
|
db_query_end(&qp);
|
||||||
@ -2430,9 +2472,27 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
DPRINTF(E_LOG, L_DAAP, "Could not add item list to DAAP browse reply\n");
|
DPRINTF(E_LOG, L_DAAP, "Could not add item list to DAAP browse reply\n");
|
||||||
|
|
||||||
dmap_send_error(req, tag, "Out of memory");
|
dmap_send_error(req, tag, "Out of memory");
|
||||||
|
|
||||||
|
if (sort_headers)
|
||||||
|
daap_sort_context_free(sctx);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sort_headers)
|
||||||
|
{
|
||||||
|
ret = daap_sort_finalize(sctx, evbuf);
|
||||||
|
daap_sort_context_free(sctx);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_DAAP, "Could not add sort headers to DAAP browse reply\n");
|
||||||
|
|
||||||
|
dmap_send_error(req, tag, "Out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user