mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 23:55:57 -05:00
Factor out common code in RSP
This commit is contained in:
parent
0cb62fdabf
commit
b1e57f8f6a
@ -265,9 +265,31 @@ rsp_send_error(struct evhttp_request *req, char *errmsg)
|
||||
}
|
||||
|
||||
static void
|
||||
rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||
rsp_send_reply(struct evhttp_request *req, mxml_node_t *reply)
|
||||
{
|
||||
struct evbuffer *evbuf;
|
||||
|
||||
evbuf = mxml_to_evbuf(reply);
|
||||
mxmlDelete(reply);
|
||||
|
||||
if (!evbuf)
|
||||
{
|
||||
rsp_send_error(req, "Could not finalize reply");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Content-Type", "text/xml; charset=utf-8");
|
||||
evhttp_add_header(req->output_headers, "Connection", "close");
|
||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||
{
|
||||
mxml_node_t *reply;
|
||||
mxml_node_t *status;
|
||||
mxml_node_t *info;
|
||||
@ -316,21 +338,7 @@ rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||
node = mxmlNewElement(info, "name");
|
||||
mxmlNewText(node, 0, library);
|
||||
|
||||
evbuf = mxml_to_evbuf(reply);
|
||||
mxmlDelete(reply);
|
||||
|
||||
if (!evbuf)
|
||||
{
|
||||
rsp_send_error(req, "Could not finalize reply");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Content-Type", "text/xml; charset=utf-8");
|
||||
evhttp_add_header(req->output_headers, "Connection", "close");
|
||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
rsp_send_reply(req, reply);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -338,7 +346,6 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||
{
|
||||
struct query_params qp;
|
||||
struct db_playlist_info dbpli;
|
||||
struct evbuffer *evbuf;
|
||||
char **strval;
|
||||
mxml_node_t *reply;
|
||||
mxml_node_t *status;
|
||||
@ -422,21 +429,7 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||
|
||||
db_query_end(&qp);
|
||||
|
||||
evbuf = mxml_to_evbuf(reply);
|
||||
mxmlDelete(reply);
|
||||
|
||||
if (!evbuf)
|
||||
{
|
||||
rsp_send_error(req, "Could not finalize reply");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Content-Type", "text/xml; charset=utf-8");
|
||||
evhttp_add_header(req->output_headers, "Connection", "close");
|
||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
rsp_send_reply(req, reply);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -444,7 +437,6 @@ rsp_reply_playlist(struct evhttp_request *req, char **uri, struct evkeyvalq *que
|
||||
{
|
||||
struct query_params qp;
|
||||
struct db_media_file_info dbmfi;
|
||||
struct evbuffer *evbuf;
|
||||
const char *param;
|
||||
char **strval;
|
||||
mxml_node_t *reply;
|
||||
@ -617,28 +609,13 @@ rsp_reply_playlist(struct evhttp_request *req, char **uri, struct evkeyvalq *que
|
||||
|
||||
db_query_end(&qp);
|
||||
|
||||
evbuf = mxml_to_evbuf(reply);
|
||||
mxmlDelete(reply);
|
||||
|
||||
if (!evbuf)
|
||||
{
|
||||
rsp_send_error(req, "Could not finalize reply");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Content-Type", "text/xml; charset=utf-8");
|
||||
evhttp_add_header(req->output_headers, "Connection", "close");
|
||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
rsp_send_reply(req, reply);
|
||||
}
|
||||
|
||||
static void
|
||||
rsp_reply_browse(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||
{
|
||||
struct query_params qp;
|
||||
struct evbuffer *evbuf;
|
||||
char *browse_item;
|
||||
mxml_node_t *reply;
|
||||
mxml_node_t *status;
|
||||
@ -747,21 +724,7 @@ rsp_reply_browse(struct evhttp_request *req, char **uri, struct evkeyvalq *query
|
||||
|
||||
db_query_end(&qp);
|
||||
|
||||
evbuf = mxml_to_evbuf(reply);
|
||||
mxmlDelete(reply);
|
||||
|
||||
if (!evbuf)
|
||||
{
|
||||
rsp_send_error(req, "Could not finalize reply");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Content-Type", "text/xml; charset=utf-8");
|
||||
evhttp_add_header(req->output_headers, "Connection", "close");
|
||||
httpd_send_reply(req, HTTP_OK, "OK", evbuf);
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
rsp_send_reply(req, reply);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user