mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-29 08:33:23 -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
|
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;
|
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 *reply;
|
||||||
mxml_node_t *status;
|
mxml_node_t *status;
|
||||||
mxml_node_t *info;
|
mxml_node_t *info;
|
||||||
@ -316,21 +338,7 @@ rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
|||||||
node = mxmlNewElement(info, "name");
|
node = mxmlNewElement(info, "name");
|
||||||
mxmlNewText(node, 0, library);
|
mxmlNewText(node, 0, library);
|
||||||
|
|
||||||
evbuf = mxml_to_evbuf(reply);
|
rsp_send_reply(req, 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
|
static void
|
||||||
@ -338,7 +346,6 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
|||||||
{
|
{
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct db_playlist_info dbpli;
|
struct db_playlist_info dbpli;
|
||||||
struct evbuffer *evbuf;
|
|
||||||
char **strval;
|
char **strval;
|
||||||
mxml_node_t *reply;
|
mxml_node_t *reply;
|
||||||
mxml_node_t *status;
|
mxml_node_t *status;
|
||||||
@ -422,21 +429,7 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
|||||||
|
|
||||||
db_query_end(&qp);
|
db_query_end(&qp);
|
||||||
|
|
||||||
evbuf = mxml_to_evbuf(reply);
|
rsp_send_reply(req, 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
|
static void
|
||||||
@ -444,7 +437,6 @@ rsp_reply_playlist(struct evhttp_request *req, char **uri, struct evkeyvalq *que
|
|||||||
{
|
{
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct db_media_file_info dbmfi;
|
struct db_media_file_info dbmfi;
|
||||||
struct evbuffer *evbuf;
|
|
||||||
const char *param;
|
const char *param;
|
||||||
char **strval;
|
char **strval;
|
||||||
mxml_node_t *reply;
|
mxml_node_t *reply;
|
||||||
@ -617,28 +609,13 @@ rsp_reply_playlist(struct evhttp_request *req, char **uri, struct evkeyvalq *que
|
|||||||
|
|
||||||
db_query_end(&qp);
|
db_query_end(&qp);
|
||||||
|
|
||||||
evbuf = mxml_to_evbuf(reply);
|
rsp_send_reply(req, 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
|
static void
|
||||||
rsp_reply_browse(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
rsp_reply_browse(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
|
||||||
{
|
{
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct evbuffer *evbuf;
|
|
||||||
char *browse_item;
|
char *browse_item;
|
||||||
mxml_node_t *reply;
|
mxml_node_t *reply;
|
||||||
mxml_node_t *status;
|
mxml_node_t *status;
|
||||||
@ -747,21 +724,7 @@ rsp_reply_browse(struct evhttp_request *req, char **uri, struct evkeyvalq *query
|
|||||||
|
|
||||||
db_query_end(&qp);
|
db_query_end(&qp);
|
||||||
|
|
||||||
evbuf = mxml_to_evbuf(reply);
|
rsp_send_reply(req, 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
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user