From f0c77685333dba8938b83235f6a4d4921c731d64 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 10 Jul 2012 21:12:10 +0000 Subject: [PATCH] * Add a flag to tell ParseNameValue() to store empty XML elements. --- image_utils.c | 2 +- metadata.c | 2 +- minissdp.c | 2 +- minixml.c | 8 ++++++-- minixml.h | 2 ++ upnpreplyparse.c | 3 ++- upnpreplyparse.h | 5 ++++- upnpsoap.c | 16 +++++++--------- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/image_utils.c b/image_utils.c index 0821507..6abdc96 100644 --- a/image_utils.c +++ b/image_utils.c @@ -372,7 +372,7 @@ image_get_jpeg_date_xmp(const char * path, char ** date) if( nread < 1 ) break; - ParseNameValue(data, offset, &xml); + ParseNameValue(data, offset, &xml, 0); exif = GetValueFromNameValueList(&xml, "DateTimeOriginal"); if( !exif ) { diff --git a/metadata.c b/metadata.c index 11d9b3d..a986c58 100644 --- a/metadata.c +++ b/metadata.c @@ -273,7 +273,7 @@ parse_nfo(const char *path, metadata_t *m) return; nread = fread(&buf, 1, sizeof(buf), nfo); - ParseNameValue(buf, nread, &xml); + ParseNameValue(buf, nread, &xml, 0); //printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement")); val = GetValueFromNameValueList(&xml, "title"); diff --git a/minissdp.c b/minissdp.c index d16e47d..883296b 100644 --- a/minissdp.c +++ b/minissdp.c @@ -452,7 +452,7 @@ close: if( !off ) return; nread -= off - buf; - ParseNameValue(off, nread, &xml); + ParseNameValue(off, nread, &xml, 0); model = GetValueFromNameValueList(&xml, "modelName"); serial = GetValueFromNameValueList(&xml, "serialNumber"); name = GetValueFromNameValueList(&xml, "friendlyName"); diff --git a/minixml.c b/minixml.c index 3dfb9a2..2fed4a1 100644 --- a/minixml.c +++ b/minixml.c @@ -30,6 +30,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "minixml.h" +#include "upnpreplyparse.h" /* parseatt : used to parse the argument list * return 0 (false) in case of success and -1 (true) if the end @@ -152,8 +153,11 @@ void parseelt(struct xmlparser * p) if (p->xml >= p->xmlend) return; } - if(i>0 && p->datafunc) - p->datafunc(p->data, data, i); + if (p->datafunc) + { + if (i > 0 || (p->flags & XML_STORE_EMPTY_FL)) + p->datafunc(p->data, data, i); + } } } else if(*p->xml == '/') diff --git a/minixml.h b/minixml.h index 91e5fdf..725c9e6 100644 --- a/minixml.h +++ b/minixml.h @@ -31,6 +31,7 @@ */ #ifndef __MINIXML_H__ #define __MINIXML_H__ +#include #define IS_WHITE_SPACE(c) ((c==' ') || (c=='\t') || (c=='\r') || (c=='\n')) /* if a callback function pointer is set to NULL, @@ -40,6 +41,7 @@ struct xmlparser { const char *xmlend; const char *xml; /* pointer to current character */ int xmlsize; + uint32_t flags; void * data; void (*starteltfunc) (void *, const char *, int); void (*endeltfunc) (void *, const char *, int); diff --git a/upnpreplyparse.c b/upnpreplyparse.c index 419dbf5..2411f05 100644 --- a/upnpreplyparse.c +++ b/upnpreplyparse.c @@ -71,7 +71,7 @@ NameValueParserGetData(void * d, const char * datas, int l) void ParseNameValue(const char * buffer, int bufsize, - struct NameValueParserData * data) + struct NameValueParserData * data, uint32_t flags) { struct xmlparser parser; LIST_INIT(&(data->head)); @@ -83,6 +83,7 @@ ParseNameValue(const char * buffer, int bufsize, parser.endeltfunc = 0; parser.datafunc = NameValueParserGetData; parser.attfunc = 0; + parser.flags = flags; parsexml(&parser); } diff --git a/upnpreplyparse.h b/upnpreplyparse.h index f887046..db7ff26 100644 --- a/upnpreplyparse.h +++ b/upnpreplyparse.h @@ -29,6 +29,7 @@ #ifndef __UPNPREPLYPARSE_H__ #define __UPNPREPLYPARSE_H__ +#include #include #ifdef __cplusplus @@ -46,10 +47,12 @@ struct NameValueParserData { char curelt[64]; }; +#define XML_STORE_EMPTY_FL 0x01 + /* ParseNameValue() */ void ParseNameValue(const char * buffer, int bufsize, - struct NameValueParserData * data); + struct NameValueParserData * data, uint32_t flags); /* ClearNameValueList() */ void diff --git a/upnpsoap.c b/upnpsoap.c index 1cd10da..395d206 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -138,10 +138,8 @@ IsAuthorizedValidated(struct upnphttp * h, const char * action) struct NameValueParserData data; const char * id; - ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); + ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data, XML_STORE_EMPTY_FL); id = GetValueFromNameValueList(&data, "DeviceID"); - if (!id) - id = strstr(h->req_buf + h->req_contentoff, ""); if(id) { int bodylen; @@ -270,12 +268,12 @@ GetCurrentConnectionInfo(struct upnphttp * h, const char * action) int id; char *endptr = NULL; - ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); + ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data, XML_STORE_EMPTY_FL); id_str = GetValueFromNameValueList(&data, "ConnectionID"); DPRINTF(E_INFO, L_HTTP, "GetCurrentConnectionInfo(%s)\n", id_str); if(id_str) id = strtol(id_str, &endptr, 10); - if(!id_str || !id_str[0] || !endptr || endptr[0] || id != 0) + if (!id_str || endptr == id_str) { SoapError(h, 402, "Invalid Args"); } @@ -1150,7 +1148,7 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) memset(&args, 0, sizeof(args)); memset(&str, 0, sizeof(str)); - ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); + ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data, 0); ObjectID = GetValueFromNameValueList(&data, "ObjectID"); Filter = GetValueFromNameValueList(&data, "Filter"); @@ -1360,7 +1358,7 @@ SearchContentDirectory(struct upnphttp * h, const char * action) memset(&args, 0, sizeof(args)); memset(&str, 0, sizeof(str)); - ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); + ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data, 0); ContainerID = GetValueFromNameValueList(&data, "ContainerID"); Filter = GetValueFromNameValueList(&data, "Filter"); @@ -1565,7 +1563,7 @@ QueryStateVariable(struct upnphttp * h, const char * action) struct NameValueParserData data; const char * var_name; - ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); + ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data, 0); /*var_name = GetValueFromNameValueList(&data, "QueryStateVariable"); */ /*var_name = GetValueFromNameValueListIgnoreNS(&data, "varName");*/ var_name = GetValueFromNameValueList(&data, "varName"); @@ -1624,7 +1622,7 @@ SamsungSetBookmark(struct upnphttp * h, const char * action) struct NameValueParserData data; char *ObjectID, *PosSecond; - ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); + ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data, 0); ObjectID = GetValueFromNameValueList(&data, "ObjectID"); PosSecond = GetValueFromNameValueList(&data, "PosSecond"); if( ObjectID && PosSecond )