* Add a flag to tell ParseNameValue() to store empty XML elements.

This commit is contained in:
Justin Maggard 2012-07-10 21:12:10 +00:00
parent 074055aa4d
commit f0c7768533
8 changed files with 24 additions and 16 deletions

View File

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

View File

@ -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");

View File

@ -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");

View File

@ -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 == '/')

View File

@ -31,6 +31,7 @@
*/
#ifndef __MINIXML_H__
#define __MINIXML_H__
#include <stdint.h>
#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);

View File

@ -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);
}

View File

@ -29,6 +29,7 @@
#ifndef __UPNPREPLYPARSE_H__
#define __UPNPREPLYPARSE_H__
#include <stdint.h>
#include <sys/queue.h>
#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

View File

@ -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, "<DeviceID>");
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 )