Replace the mxml RSP root element hack by a better one

There's no proper way to add attributes to the root XML element in mxml;
the best way to do that is to create the root element like we would
create any other element and put the whole "? ... ?" stuff in there.
This commit is contained in:
Julien BLACHE 2009-06-04 10:24:04 +02:00
parent 4872077319
commit 68c74e6a88

View File

@ -48,6 +48,8 @@
#define RSP_VERSION "1.0" #define RSP_VERSION "1.0"
#define RSP_XML_ROOT "?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?"
#define F_FULL (1 << 0) #define F_FULL (1 << 0)
#define F_BROWSE (1 << 1) #define F_BROWSE (1 << 1)
@ -136,7 +138,6 @@ mxml_to_evbuf(mxml_node_t *tree)
{ {
struct evbuffer *evbuf; struct evbuffer *evbuf;
char *xml; char *xml;
char *content;
int ret; int ret;
evbuf = evbuffer_new(); evbuf = evbuffer_new();
@ -156,20 +157,7 @@ mxml_to_evbuf(mxml_node_t *tree)
return NULL; return NULL;
} }
ret = evbuffer_add(evbuf, xml, strlen(xml));
/* MiniXML doesn't support setting attributes on the root node */
content = strchr(xml, '>') + 1;
ret = evbuffer_add_printf(evbuf, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>");
if (ret < 0)
{
DPRINTF(E_LOG, L_RSP, "Could not prepare evbuffer for RSP error\n");
free(xml);
evbuffer_free(evbuf);
return NULL;
}
ret = evbuffer_add(evbuf, content, strlen(content));
free(xml); free(xml);
if (ret < 0) if (ret < 0)
{ {
@ -190,7 +178,10 @@ rsp_send_error(struct evhttp_request *req, char *errmsg)
mxml_node_t *status; mxml_node_t *status;
mxml_node_t *node; mxml_node_t *node;
reply = mxmlNewXML("1.0"); /* We'd use mxmlNewXML(), but then we can't put any attributes
* on the root node and we need some.
*/
reply = mxmlNewElement(MXML_NO_PARENT, RSP_XML_ROOT);
node = mxmlNewElement(reply, "response"); node = mxmlNewElement(reply, "response");
status = mxmlNewElement(node, "status"); status = mxmlNewElement(node, "status");
@ -252,7 +243,10 @@ rsp_reply_info(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
lib = cfg_getnsec(cfg, "library", 0); lib = cfg_getnsec(cfg, "library", 0);
library = cfg_getstr(lib, "name"); library = cfg_getstr(lib, "name");
reply = mxmlNewXML("1.0"); /* We'd use mxmlNewXML(), but then we can't put any attributes
* on the root node and we need some.
*/
reply = mxmlNewElement(MXML_NO_PARENT, RSP_XML_ROOT);
node = mxmlNewElement(reply, "response"); node = mxmlNewElement(reply, "response");
status = mxmlNewElement(node, "status"); status = mxmlNewElement(node, "status");
@ -334,7 +328,10 @@ rsp_reply_db(struct evhttp_request *req, char **uri, struct evkeyvalq *query)
return; return;
} }
reply = mxmlNewXML("1.0"); /* We'd use mxmlNewXML(), but then we can't put any attributes
* on the root node and we need some.
*/
reply = mxmlNewElement(MXML_NO_PARENT, RSP_XML_ROOT);
node = mxmlNewElement(reply, "response"); node = mxmlNewElement(reply, "response");
status = mxmlNewElement(node, "status"); status = mxmlNewElement(node, "status");
@ -549,7 +546,10 @@ rsp_reply_playlist(struct evhttp_request *req, char **uri, struct evkeyvalq *que
else else
records = limit; records = limit;
reply = mxmlNewXML("1.0"); /* We'd use mxmlNewXML(), but then we can't put any attributes
* on the root node and we need some.
*/
reply = mxmlNewElement(MXML_NO_PARENT, RSP_XML_ROOT);
node = mxmlNewElement(reply, "response"); node = mxmlNewElement(reply, "response");
status = mxmlNewElement(node, "status"); status = mxmlNewElement(node, "status");
@ -800,7 +800,10 @@ rsp_reply_browse(struct evhttp_request *req, char **uri, struct evkeyvalq *query
else else
records = limit; records = limit;
reply = mxmlNewXML("1.0"); /* We'd use mxmlNewXML(), but then we can't put any attributes
* on the root node and we need some.
*/
reply = mxmlNewElement(MXML_NO_PARENT, RSP_XML_ROOT);
node = mxmlNewElement(reply, "response"); node = mxmlNewElement(reply, "response");
status = mxmlNewElement(node, "status"); status = mxmlNewElement(node, "status");