Factor out common code in RSP

This commit is contained in:
Julien BLACHE 2010-09-09 18:03:44 +02:00
parent 0cb62fdabf
commit b1e57f8f6a

View File

@ -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