2009-04-18 21:25:23 +00:00
|
|
|
/* Copyright (c) 2007-2009 by Adalin B.V.
|
|
|
|
* Copyright (c) 2007-2009 by Erik Hofman
|
2008-06-29 13:08:24 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of (any of) the copyrightholder(s) nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2009-04-18 21:25:23 +00:00
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# include <windows.h>
|
|
|
|
# include <io.h>
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
HANDLE m;
|
|
|
|
void *p;
|
2008-06-29 13:08:24 +00:00
|
|
|
} SIMPLE_UNMMAP;
|
|
|
|
|
|
|
|
#else /* !WIN32 */
|
|
|
|
# include <sys/mman.h>
|
2009-04-18 14:13:13 +00:00
|
|
|
# include <unistd.h>
|
2008-06-29 13:08:24 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
# include <stdio.h>
|
|
|
|
#endif
|
2009-04-20 19:56:09 +00:00
|
|
|
#include <stdlib.h> /* free, malloc */
|
2009-04-18 21:25:23 +00:00
|
|
|
#include <string.h>
|
2009-04-20 19:56:09 +00:00
|
|
|
#include <fcntl.h>
|
2008-06-29 13:08:24 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2008-07-19 12:18:05 +00:00
|
|
|
#include <assert.h>
|
2008-06-29 13:08:24 +00:00
|
|
|
#include <ctype.h>
|
2009-04-18 14:13:13 +00:00
|
|
|
#ifndef _MSC_VER
|
2009-04-18 21:25:23 +00:00
|
|
|
# include <strings.h> /* strncasecmp */
|
2009-04-18 14:13:13 +00:00
|
|
|
#else
|
|
|
|
# define strncasecmp strnicmp
|
|
|
|
#endif
|
2009-04-18 21:25:23 +00:00
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
#include "xml.h"
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
static const char *__xml_error_str[XML_MAX_ERROR];
|
|
|
|
|
|
|
|
struct _xml_error
|
|
|
|
{
|
|
|
|
char *pos;
|
2009-04-18 22:20:50 +00:00
|
|
|
int err_no;
|
2009-04-18 21:25:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void __xmlErrorSet(const void *, const char *, unsigned int);
|
|
|
|
# define xmlErrorSet(a, b, c) __xmlErrorSet(a, b, c)
|
|
|
|
#else /* !XML_NONVALIDATING */
|
|
|
|
# define xmlErrorSet(a, b, c)
|
2009-04-16 19:03:22 +00:00
|
|
|
#endif
|
2009-03-31 08:06:17 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
/*
|
|
|
|
* It is required for both the rood node and the normal xml nodes to both
|
|
|
|
* have 'char *name' defined as the first entry. The code tests whether
|
|
|
|
* name == 0 to detect the root node.
|
|
|
|
*/
|
|
|
|
struct _root_id
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *start;
|
|
|
|
size_t len;
|
|
|
|
int fd;
|
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
struct _xml_error *info;
|
|
|
|
#endif
|
|
|
|
# ifdef WIN32
|
|
|
|
SIMPLE_UNMMAP un;
|
|
|
|
# endif
|
|
|
|
};
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
struct _xml_id
|
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
char *name;
|
2009-04-18 21:25:23 +00:00
|
|
|
char *start;
|
|
|
|
size_t len;
|
|
|
|
size_t name_len;
|
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
struct _root_id *root;
|
|
|
|
#endif
|
2008-06-29 13:08:24 +00:00
|
|
|
};
|
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
static char *__xmlNodeCopy(const char *, size_t *, const char **);
|
2009-04-16 19:03:22 +00:00
|
|
|
static char *__xmlNodeGetPath(const char *, size_t *, char **, size_t *);
|
|
|
|
static char *__xmlNodeGet(const char *, size_t *, char **, size_t *, size_t *);
|
|
|
|
static char *__xmlCommentSkip(const char *, size_t);
|
2009-04-18 21:25:23 +00:00
|
|
|
static char *__xmlInfoProcess(const char *, size_t);
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
static void *__xml_memncasecmp(const char *, size_t *, char **, size_t *);
|
2008-07-06 11:34:50 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
/*
|
|
|
|
* map 'filename' and return a pointer to it.
|
|
|
|
*/
|
|
|
|
static void *simple_mmap(int, size_t, SIMPLE_UNMMAP *);
|
|
|
|
static void simple_unmmap(SIMPLE_UNMMAP *);
|
|
|
|
|
|
|
|
# define mmap(a,b,c,d,e,f) simple_mmap((e), (b), &rid->un)
|
|
|
|
# define munmap(a,b) simple_unmmap(&rid->un)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
# define PRINT(a, b, c) { \
|
2008-07-06 11:34:50 +00:00
|
|
|
if (a) { \
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t q, len = c; \
|
|
|
|
if (b < c) len = b; \
|
|
|
|
if (len < 50000) { \
|
|
|
|
printf("(%i) '", len); \
|
|
|
|
for (q=0; q<len; q++) printf("%c", ((char *)(a))[q]); \
|
|
|
|
printf("'\n"); \
|
|
|
|
} else printf("Length (%u) seems too large at line %i\n",len, __LINE__); \
|
2008-07-06 11:34:50 +00:00
|
|
|
} else printf("NULL pointer at line %i\n", __LINE__); \
|
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
#endif
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
void *
|
2009-03-31 08:06:17 +00:00
|
|
|
xmlOpen(const char *filename)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _root_id *rid = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
if (filename)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
int fd = open(filename, O_RDONLY);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (fd > 0)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
rid = malloc(sizeof(struct _root_id));
|
|
|
|
if (rid)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct stat statbuf;
|
2009-04-25 09:54:28 +00:00
|
|
|
void *mm;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
fstat(fd, &statbuf);
|
2009-04-25 09:54:28 +00:00
|
|
|
mm = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0L);
|
|
|
|
if (mm != (void *)-1)
|
|
|
|
{
|
|
|
|
rid->fd = fd;
|
|
|
|
rid->start = mm;
|
|
|
|
rid->len = statbuf.st_size;
|
|
|
|
rid->name = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
#ifndef XML_NONVALIDATING
|
2009-04-25 09:54:28 +00:00
|
|
|
rid->info = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
#endif
|
2009-04-25 09:54:28 +00:00
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
return (void *)rid;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xmlClose(void *id)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _root_id *rid = (struct _root_id *)id;
|
2008-07-20 09:38:53 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(rid != 0);
|
|
|
|
assert(rid->name == 0);
|
|
|
|
|
|
|
|
munmap(rid->start, rid->len);
|
|
|
|
close(rid->fd);
|
2009-04-20 16:46:39 +00:00
|
|
|
|
|
|
|
if (rid->info) free(rid->info);
|
|
|
|
free(rid);
|
2009-04-18 21:25:23 +00:00
|
|
|
id = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGet(const void *id, const char *path)
|
2009-03-31 08:06:17 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
struct _xml_id *xsid = 0;
|
|
|
|
size_t len, slen;
|
|
|
|
char *ptr, *node;
|
2009-03-31 08:06:17 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(id != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
|
|
|
|
node = (char *)path;
|
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
|
|
|
ptr = __xmlNodeGetPath(xid->start, &len, &node, &slen);
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
xsid = malloc(sizeof(struct _xml_id));
|
|
|
|
if (xsid)
|
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
xsid->len = len;
|
|
|
|
xsid->start = ptr;
|
2009-04-18 21:25:23 +00:00
|
|
|
xsid->name_len = slen;
|
2009-03-31 08:06:17 +00:00
|
|
|
xsid->name = node;
|
2009-04-18 21:25:23 +00:00
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
if (xid->name)
|
|
|
|
xsid->root = xid->root;
|
|
|
|
else
|
|
|
|
xsid->root = (struct _root_id *)xid;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(xid, 0, XML_OUT_OF_MEMORY);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
2009-03-31 08:06:17 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
return (void *)xsid;
|
2009-03-31 08:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeCopy(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-06-29 13:08:24 +00:00
|
|
|
struct _xml_id *xsid = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
char *ptr, *node, *p;
|
|
|
|
size_t slen, len;
|
|
|
|
|
|
|
|
node = (char *)path;
|
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
|
|
|
ptr = __xmlNodeGetPath(xid->start, &len, &node, &slen);
|
|
|
|
if (ptr)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xsid = malloc(sizeof(struct _xml_id) + len);
|
|
|
|
if (xsid)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
p = (char *)xsid + sizeof(struct _xml_id);
|
|
|
|
|
|
|
|
xsid->len = len;
|
|
|
|
xsid->start = p;
|
|
|
|
xsid->name_len = slen;
|
|
|
|
xsid->name = node;
|
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
if (xid->name)
|
|
|
|
xsid->root = xid->root;
|
|
|
|
else
|
|
|
|
xsid->root = (struct _root_id *)xid;
|
|
|
|
#endif
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
memcpy(xsid->start, ptr, len);
|
|
|
|
}
|
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(xid, 0, XML_OUT_OF_MEMORY);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
return (void *)xsid;
|
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
char *
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGetName(const void *id)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-21 12:32:22 +00:00
|
|
|
size_t len;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ret;
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
|
|
|
|
len = xid->name_len;
|
2008-07-21 12:32:22 +00:00
|
|
|
ret = malloc(len+1);
|
2008-07-20 09:38:53 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
2008-07-21 12:32:22 +00:00
|
|
|
memcpy(ret, xid->name, len);
|
|
|
|
*(ret + len) = 0;
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(xid, 0, XML_OUT_OF_MEMORY);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2008-07-20 09:38:53 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlNodeCopyName(const void *id, char *buf, size_t buflen)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
size_t slen = 0;
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(buf != 0);
|
|
|
|
assert(buflen > 0);
|
|
|
|
|
2009-04-20 19:56:09 +00:00
|
|
|
slen = xid->name_len;
|
|
|
|
if (slen >= buflen)
|
2009-04-20 17:05:03 +00:00
|
|
|
{
|
2009-04-20 19:56:09 +00:00
|
|
|
slen = buflen-1;
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
memcpy(buf, xid->name, slen);
|
|
|
|
*(buf + slen) = 0;
|
2008-07-21 12:32:22 +00:00
|
|
|
|
|
|
|
return slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
unsigned int
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGetNum(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
size_t num = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
char *nodename, *pathname;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2009-03-31 08:06:17 +00:00
|
|
|
char *p;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
nodename = (char *)path;
|
|
|
|
if (*path == '/') nodename++;
|
|
|
|
slen = strlen(nodename);
|
2008-07-01 12:15:46 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
pathname = strchr(nodename, '/');
|
|
|
|
if (pathname)
|
|
|
|
{
|
|
|
|
char *node;
|
2008-07-01 12:15:46 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
len = xid->len;
|
|
|
|
pathname++;
|
|
|
|
slen -= pathname-nodename;
|
|
|
|
node = pathname;
|
2009-04-16 19:03:22 +00:00
|
|
|
p = __xmlNodeGetPath(xid->start, &len, &node, &slen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (p == 0 && slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
}
|
2009-03-31 08:06:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = xid->start;
|
|
|
|
len = xid->len;
|
|
|
|
}
|
2008-07-01 12:15:46 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
if (p)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
char *ret, *node = nodename;
|
|
|
|
ret = __xmlNodeGet(p, &len, &node, &slen, &num);
|
|
|
|
if (ret == 0 && slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
num = 0;
|
|
|
|
}
|
2009-03-31 08:06:17 +00:00
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
return num;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
void *
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGetPos(const void *pid, void *id, const char *element, size_t num)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xpid = (struct _xml_id *)pid;
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
size_t len, slen;
|
|
|
|
char *ptr, *node;
|
2009-03-31 08:06:17 +00:00
|
|
|
void *ret = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xpid != 0);
|
|
|
|
assert(xid != 0);
|
|
|
|
assert(element != 0);
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
len = xpid->len;
|
|
|
|
slen = strlen(element);
|
|
|
|
node = (char *)element;
|
|
|
|
ptr = __xmlNodeGet(xpid->start, &len, &node, &slen, &num);
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
xid->len = len;
|
|
|
|
xid->start = ptr;
|
|
|
|
xid->name = node;
|
|
|
|
xid->name_len = slen;
|
|
|
|
ret = xid;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xpid, node, len);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetString(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
char *str = 0;
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ps, *pe, *pend;
|
|
|
|
int nlen;
|
|
|
|
|
|
|
|
ps = xid->start;
|
|
|
|
nlen = xid->len;
|
|
|
|
pend = ps+nlen;
|
|
|
|
pe = pend;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
nlen = (pe-ps);
|
|
|
|
if (nlen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
str = malloc(nlen+1);
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
memcpy(str, ps, nlen);
|
|
|
|
*(str+nlen) = 0;
|
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(xid, 0, XML_OUT_OF_MEMORY);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
return str;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
size_t
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlCopyString(const void *id, char *buffer, size_t buflen)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2009-04-16 19:03:22 +00:00
|
|
|
size_t ret = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
|
|
|
|
assert(xid != 0);
|
|
|
|
assert(buffer != 0);
|
|
|
|
assert(buflen > 0);
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
if (xid->len)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
char *ps, *pe, *pend;
|
2009-04-16 19:03:22 +00:00
|
|
|
size_t slen, nlen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
*buffer = '\0';
|
|
|
|
nlen = buflen-1;
|
2008-07-20 09:38:53 +00:00
|
|
|
ps = xid->start;
|
|
|
|
slen = xid->len;
|
|
|
|
pend = ps+slen;
|
|
|
|
pe = pend;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
nlen = (pe-ps);
|
|
|
|
if (nlen > slen) nlen = slen;
|
|
|
|
|
|
|
|
if (nlen)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
if (nlen >= buflen)
|
|
|
|
{
|
|
|
|
nlen = buflen-1;
|
|
|
|
xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
memcpy(buffer, ps, nlen);
|
|
|
|
*(buffer+nlen) = 0;
|
|
|
|
ret = nlen;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
return ret;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
int
|
|
|
|
xmlCompareString(const void *id, const char *s)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
int ret = -1;
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(s != 0);
|
|
|
|
|
|
|
|
if (xid->len && (strlen(s) > 0))
|
2009-03-31 08:06:17 +00:00
|
|
|
{
|
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
ps = xid->start;
|
|
|
|
pe = ps + xid->len;
|
|
|
|
pe--;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
pe++;
|
|
|
|
|
|
|
|
ret = strncasecmp(ps, s, pe-ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGetString(const void *id, const char *path)
|
2009-03-31 08:06:17 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
char *str = 0;
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2009-03-31 08:06:17 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t len = xid->len;
|
|
|
|
char *node = (char *)path;
|
|
|
|
|
|
|
|
str = __xmlNodeCopy(xid->start, &len, &path);
|
2009-03-31 08:06:17 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
char *ps, *pe, *pend;
|
|
|
|
int slen;
|
|
|
|
|
|
|
|
ps = str;
|
|
|
|
slen = strlen(str);
|
|
|
|
pend = ps+slen;
|
|
|
|
pe = pend-1;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
|
|
|
|
*++pe = 0;
|
|
|
|
slen = (pe-ps);
|
|
|
|
if (slen && (ps>str)) memmove(str, ps, slen);
|
|
|
|
else if (!slen) *str = 0;
|
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
}
|
2009-03-31 08:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
size_t
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeCopyString(const void *id, const char *path, char *buffer, size_t buflen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2009-04-16 19:03:22 +00:00
|
|
|
size_t ret = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
assert(buffer != 0);
|
|
|
|
assert(buflen > 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *str, *node;
|
2009-04-16 19:03:22 +00:00
|
|
|
size_t slen, nlen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
*buffer = '\0';
|
2009-04-16 19:03:22 +00:00
|
|
|
nlen = xid->len;
|
2008-07-19 12:18:05 +00:00
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
2009-04-16 19:03:22 +00:00
|
|
|
str = __xmlNodeGetPath(xid->start, &nlen, &node, &slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
ps = str;
|
2009-04-16 19:03:22 +00:00
|
|
|
pe = ps+nlen-1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
nlen = (pe-ps)+1;
|
2009-04-18 21:25:23 +00:00
|
|
|
if (nlen >= buflen)
|
|
|
|
{
|
|
|
|
nlen = buflen-1;
|
|
|
|
xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
memcpy(buffer, ps, nlen);
|
|
|
|
*(buffer + nlen) = '\0';
|
|
|
|
ret = nlen;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, nlen);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
return ret;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
int
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeCompareString(const void *id, const char *path, const char *s)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2009-03-31 08:06:17 +00:00
|
|
|
int ret = -1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
assert(s != 0);
|
|
|
|
|
|
|
|
if (xid->len && (strlen(s) > 0))
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
char *node, *str, *ps, *pe;
|
2009-04-16 19:03:22 +00:00
|
|
|
size_t len, slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
2009-04-16 19:03:22 +00:00
|
|
|
str = __xmlNodeGetPath(xid->start, &len, &node, &slen);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (str)
|
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
ps = str;
|
|
|
|
pe = ps + len;
|
|
|
|
pe--;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
pe++;
|
|
|
|
|
|
|
|
ret = strncasecmp(ps, s, pe-ps);
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
return ret;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long int
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetInt(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
long int li = 0;
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *end = xid->start + xid->len;
|
|
|
|
li = strtol(xid->start, &end, 10);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
long int
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGetInt(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
long int li = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *str, *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
2009-04-16 19:03:22 +00:00
|
|
|
str = __xmlNodeGetPath(xid->start, &len, &node, &slen);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
char *end = str+len;
|
2009-03-31 08:06:17 +00:00
|
|
|
li = strtol(str, &end, 10);
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
return li;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetDouble(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
double d = 0.0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *end = xid->start + xid->len;
|
|
|
|
d = strtod(xid->start, &end);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
double
|
2009-04-16 19:03:22 +00:00
|
|
|
xmlNodeGetDouble(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2009-03-31 08:06:17 +00:00
|
|
|
double d = 0.0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(path != 0);
|
|
|
|
|
|
|
|
if (xid->len)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2009-03-31 08:06:17 +00:00
|
|
|
char *str, *node;
|
2008-07-20 09:38:53 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
|
|
|
node = (char *)path;
|
2009-04-16 19:03:22 +00:00
|
|
|
str = __xmlNodeGetPath(xid->start, &len, &node, &slen);
|
2009-03-31 08:06:17 +00:00
|
|
|
if (str)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
char *end = str+len;
|
|
|
|
d = strtod(str, &end);
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, node, len);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
return d;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlMarkId(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xmid = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(id != 0);
|
|
|
|
|
|
|
|
xmid = malloc(sizeof(struct _xml_id));
|
|
|
|
if (xmid)
|
|
|
|
{
|
|
|
|
struct _root_id *xrid = (struct _root_id *)id;
|
|
|
|
if (xrid->name == 0)
|
|
|
|
{
|
|
|
|
xmid->name = "";
|
|
|
|
xmid->start = xrid->start;
|
|
|
|
xmid->len = xrid->len;
|
|
|
|
xmid->name_len = 0;
|
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
xmid->root = xrid;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
memcpy(xmid, id, sizeof(struct _xml_id));
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(id, 0, XML_OUT_OF_MEMORY);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
return (void *)xmid;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
double
|
|
|
|
xmlAttributeGetDouble(const void *id, const char *name)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
double ret = 0.0;
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(name != 0);
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (xid->name_len)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t slen = strlen(name);
|
2009-04-18 21:25:23 +00:00
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
assert(xid->start > xid->name);
|
|
|
|
|
|
|
|
ps = xid->name + xid->name_len + 1;
|
|
|
|
pe = xid->start - 1;
|
|
|
|
while (ps<pe)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
if (((size_t)(pe-ps) > slen) && (strncasecmp(ps, name, slen) == 0))
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
ps += slen;
|
|
|
|
if ((ps<pe) && (*ps == '='))
|
|
|
|
{
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
ps++;
|
|
|
|
if (*ps == '"' || *ps == '\'') ps++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_OPENING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ps;
|
|
|
|
while ((ps<pe) && (*ps != '"') && (*ps != '\'')) ps++;
|
|
|
|
if (ps<pe)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
ret = strtod(start, &ps);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_CLOSING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long int
|
|
|
|
xmlAttributeGetInt(const void *id, const char *name)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
long int ret = 0;
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(name != 0);
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (xid->name_len)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t slen = strlen(name);
|
2009-04-18 21:25:23 +00:00
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
assert(xid->start > xid->name);
|
|
|
|
|
|
|
|
ps = xid->name + xid->name_len + 1;
|
|
|
|
pe = xid->start - 1;
|
|
|
|
while (ps<pe)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
if (((size_t)(pe-ps) > slen) && (strncasecmp(ps, name, slen) == 0))
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
ps += slen;
|
|
|
|
if ((ps<pe) && (*ps == '='))
|
|
|
|
{
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
ps++;
|
|
|
|
if (*ps == '"' || *ps == '\'') ps++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_OPENING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ps;
|
|
|
|
while ((ps<pe) && (*ps != '"') && (*ps != '\'')) ps++;
|
|
|
|
if (ps<pe)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
ret = strtol(start, &ps, 10);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_CLOSING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
xmlAttributeGetString(const void *id, const char *name)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
char *ret = 0;
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(name != 0);
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (xid->name_len)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t slen = strlen(name);
|
2009-04-18 21:25:23 +00:00
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
assert(xid->start > xid->name);
|
|
|
|
|
|
|
|
ps = xid->name + xid->name_len + 1;
|
|
|
|
pe = xid->start - 1;
|
|
|
|
while (ps<pe)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
if (((size_t)(pe-ps) > slen) && (strncasecmp(ps, name, slen) == 0))
|
2009-04-16 19:03:22 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
ps += slen;
|
|
|
|
if ((ps<pe) && (*ps == '='))
|
|
|
|
{
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
ps++;
|
|
|
|
if (*ps == '"' || *ps == '\'') ps++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_OPENING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ps;
|
|
|
|
while ((ps<pe) && (*ps != '"') && (*ps != '\'')) ps++;
|
|
|
|
if (ps<pe)
|
|
|
|
{
|
|
|
|
ret = malloc(ps-start);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
memcpy(ret, start, (ps-start));
|
|
|
|
*(ret+(ps-start)) = '\0';
|
|
|
|
}
|
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
xmlErrorSet(xid, 0, XML_OUT_OF_MEMORY);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_CLOSING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
break;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
return ret;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
xmlAttributeCopyString(const void *id, const char *name,
|
|
|
|
char *buffer, size_t buflen)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
size_t ret = 0;
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid != 0);
|
|
|
|
assert(name != 0);
|
|
|
|
assert(buffer != 0);
|
|
|
|
assert(buflen > 0);
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (xid->name_len)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t slen = strlen(name);
|
2009-04-18 21:25:23 +00:00
|
|
|
char *ps, *pe;
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid->start > xid->name);
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
*buffer = '\0';
|
|
|
|
ps = xid->name + xid->name_len + 1;
|
|
|
|
pe = xid->start - 1;
|
|
|
|
while (ps<pe)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
if (((size_t)(pe-ps) > slen) && (strncasecmp(ps, name, slen) == 0))
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
ps += slen;
|
|
|
|
if ((ps<pe) && (*ps == '='))
|
2009-04-16 19:03:22 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
char *start;
|
|
|
|
|
|
|
|
ps++;
|
|
|
|
if (*ps == '"' || *ps == '\'') ps++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_OPENING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ps;
|
|
|
|
while ((ps<pe) && (*ps != '"') && (*ps != '\'')) ps++;
|
|
|
|
if (ps<pe)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t restlen = ps-start;
|
2009-04-18 21:25:23 +00:00
|
|
|
if (restlen >= buflen)
|
|
|
|
{
|
|
|
|
restlen = buflen-1;
|
|
|
|
xmlErrorSet(xid, ps, XML_TRUNCATE_RESULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, start, restlen);
|
|
|
|
*(buffer+restlen) = 0;
|
|
|
|
ret = restlen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_CLOSING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
return ret;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xmlAttributeCompareString(const void *id, const char *name, const char *s)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
assert(xid != 0);
|
|
|
|
assert(name != 0);
|
|
|
|
assert(s != 0);
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (xid->name_len && strlen(s))
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
size_t slen = strlen(name);
|
2009-04-18 21:25:23 +00:00
|
|
|
char *ps, *pe;
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
assert(xid->start > xid->name);
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
ps = xid->name + xid->name_len + 1;
|
|
|
|
pe = xid->start - 1;
|
|
|
|
while (ps<pe)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
if (((size_t)(pe-ps) > slen) && (strncasecmp(ps, name, slen) == 0))
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
ps += slen;
|
|
|
|
if ((ps<pe) && (*ps == '='))
|
2009-04-16 19:03:22 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
char *start;
|
|
|
|
|
|
|
|
ps++;
|
|
|
|
if (*ps == '"' || *ps == '\'') ps++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_OPENING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ps;
|
|
|
|
while ((ps<pe) && (*ps != '"') && (*ps != '\'')) ps++;
|
|
|
|
if (ps<pe)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
ret = strncasecmp(start, s, ps-start);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(xid, ps, XML_ATTRIB_NO_CLOSING_QUOTE);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
while ((ps<pe) && !isspace(*ps)) ps++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
return ret;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
int
|
2009-04-20 16:46:39 +00:00
|
|
|
xmlErrorGetNo(const void *id, int clear)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
struct _root_id *rid;
|
|
|
|
|
|
|
|
if (xid->name) rid = xid->root;
|
|
|
|
else rid = (struct _root_id *)xid;
|
|
|
|
|
|
|
|
assert(rid != 0);
|
|
|
|
|
|
|
|
if (rid->info)
|
|
|
|
{
|
|
|
|
struct _xml_error *err = rid->info;
|
|
|
|
|
2009-04-18 22:20:50 +00:00
|
|
|
ret = err->err_no;
|
2009-04-20 16:46:39 +00:00
|
|
|
if (clear) err->err_no = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2009-04-20 16:46:39 +00:00
|
|
|
xmlErrorGetLineNo(const void *id, int clear)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
struct _root_id *rid;
|
|
|
|
|
|
|
|
if (xid->name) rid = xid->root;
|
|
|
|
else rid = (struct _root_id *)xid;
|
|
|
|
|
|
|
|
assert(rid != 0);
|
|
|
|
|
|
|
|
if (rid->info)
|
|
|
|
{
|
|
|
|
struct _xml_error *err = rid->info;
|
|
|
|
char *ps = rid->start;
|
|
|
|
char *pe = err->pos;
|
|
|
|
char *new;
|
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
ret++;
|
2009-04-18 21:25:23 +00:00
|
|
|
while (ps<pe)
|
|
|
|
{
|
|
|
|
new = memchr(ps, '\n', pe-ps);
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
ps = new;
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
ps++;
|
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
|
|
|
|
if (clear) err->err_no = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2009-04-20 16:46:39 +00:00
|
|
|
xmlErrorGetString(const void *id, int clear)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
char *ret = 0;
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
struct _root_id *rid;
|
|
|
|
|
|
|
|
if (xid->name) rid = xid->root;
|
|
|
|
else rid = (struct _root_id *)xid;
|
|
|
|
|
|
|
|
assert(rid != 0);
|
|
|
|
|
|
|
|
if (rid->info)
|
|
|
|
{
|
|
|
|
struct _xml_error *err = rid->info;
|
2009-04-18 22:20:50 +00:00
|
|
|
if (XML_NO_ERROR <= err->err_no && err->err_no < XML_MAX_ERROR)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 22:20:50 +00:00
|
|
|
ret = (char *)__xml_error_str[err->err_no];
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
else
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
ret = "incorrect error number.";
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clear) err->err_no = 0;
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
#ifndef XML_NONVALIDATING
|
2009-04-18 21:25:23 +00:00
|
|
|
static const char *__xml_error_str[XML_MAX_ERROR] =
|
|
|
|
{
|
|
|
|
"no error.",
|
|
|
|
"unable to allocate enough memory.",
|
|
|
|
"unable to open file for reading.",
|
2009-04-20 17:05:03 +00:00
|
|
|
"buffer too small to hold all data, truncating.",
|
2009-04-20 16:46:39 +00:00
|
|
|
"incorrect comment section.",
|
|
|
|
"bad information block.",
|
2009-04-20 17:05:03 +00:00
|
|
|
"unexpected end of section.",
|
2009-04-18 21:25:23 +00:00
|
|
|
"incompatible opening tag for element.",
|
|
|
|
"missing or invalid closing tag for element.",
|
|
|
|
"missing or invalid opening quote for attribute.",
|
|
|
|
"missing or invalid closing quote for attribute."
|
|
|
|
};
|
2009-04-20 16:46:39 +00:00
|
|
|
#endif
|
2009-04-18 21:25:23 +00:00
|
|
|
|
|
|
|
char *
|
2009-04-20 16:46:39 +00:00
|
|
|
__xmlNodeCopy(const char *start, size_t *len, const char **path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
char *node, *p, *ret = 0;
|
|
|
|
size_t rlen, slen;
|
|
|
|
|
|
|
|
rlen = *len;
|
|
|
|
slen = strlen(*path);
|
|
|
|
node = (char *)*path;
|
|
|
|
p = __xmlNodeGetPath(start, &rlen, &node, &slen);
|
|
|
|
if (p && rlen)
|
|
|
|
{
|
|
|
|
ret = malloc(rlen+1);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
memcpy(ret, p, rlen);
|
2009-04-27 11:50:08 +00:00
|
|
|
*(ret+rlen) = '\0';
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlErrorSet(0, 0, XML_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (slen == 0)
|
|
|
|
{
|
|
|
|
*path = node;
|
|
|
|
*len = rlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2009-04-16 19:03:22 +00:00
|
|
|
__xmlNodeGetPath(const char *start, size_t *len, char **name, size_t *plen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
char *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
char *ret = 0;
|
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
assert(start != 0);
|
|
|
|
assert(len != 0);
|
2009-04-20 19:56:09 +00:00
|
|
|
assert(*len != 0);
|
2009-04-20 16:46:39 +00:00
|
|
|
assert(name != 0);
|
|
|
|
assert(*name != 0);
|
|
|
|
assert(plen != 0);
|
|
|
|
assert(*plen != 0);
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-04-20 19:56:09 +00:00
|
|
|
if (*plen > *len) return 0;
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
node = *name;
|
2008-07-20 09:38:53 +00:00
|
|
|
if (*node == '/') node++;
|
|
|
|
if (*node != 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t plen, slen;
|
|
|
|
char *path;
|
2009-03-31 08:06:17 +00:00
|
|
|
size_t num;
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
slen = strlen(node);
|
|
|
|
path = strchr(node, '/');
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
if (!path) plen = slen;
|
|
|
|
else plen = path++ - node;
|
|
|
|
|
2009-04-20 19:56:09 +00:00
|
|
|
num = 0;
|
|
|
|
ret = __xmlNodeGet(start, len, &node, &plen, &num);
|
|
|
|
if (ret && path)
|
2008-07-01 12:15:46 +00:00
|
|
|
{
|
2009-04-20 19:56:09 +00:00
|
|
|
plen = slen - (path - *name);
|
|
|
|
ret = __xmlNodeGetPath(ret, len, &path, &plen);
|
|
|
|
*name = path;
|
|
|
|
}
|
|
|
|
else if (plen == 0)
|
|
|
|
{
|
|
|
|
*name = node;
|
2008-07-01 12:15:46 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2009-04-16 19:03:22 +00:00
|
|
|
__xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *nodenum)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *new, *cur, *ne, *ret = 0;
|
2009-04-16 19:03:22 +00:00
|
|
|
char *element, *start_tag=0;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t restlen, elementlen;
|
2009-04-25 09:54:28 +00:00
|
|
|
size_t return_len = 0;
|
2008-07-19 12:18:05 +00:00
|
|
|
int found, num;
|
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
assert(start != 0);
|
|
|
|
assert(len != 0);
|
|
|
|
assert(*len != 0);
|
|
|
|
assert(name != 0);
|
|
|
|
assert(*name != 0);
|
|
|
|
assert(rlen != 0);
|
|
|
|
assert(*rlen != 0);
|
|
|
|
assert(nodenum != 0);
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
if (*rlen > *len)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
2009-04-20 19:56:09 +00:00
|
|
|
*name = (char *)start;
|
2009-04-20 16:46:39 +00:00
|
|
|
*len = XML_UNEXPECTED_EOF;
|
2008-07-19 12:18:05 +00:00
|
|
|
return 0;
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
found = 0;
|
|
|
|
num = *nodenum;
|
|
|
|
restlen = *len;
|
|
|
|
cur = (char *)start;
|
|
|
|
ne = cur + restlen;
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
/* search for an opening tag */
|
2008-07-19 12:18:05 +00:00
|
|
|
while ((new = memchr(cur, '<', restlen)) != 0)
|
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
size_t len_remaining;
|
|
|
|
char *rptr;
|
|
|
|
|
|
|
|
if (*(new+1) == '/') /* end of section */
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
*len -= restlen-1;
|
2008-07-19 12:18:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
new++;
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (*cur == '!') /* comment */
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
new = __xmlCommentSkip(cur, restlen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_INVALID_COMMENT;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
continue;
|
|
|
|
}
|
2009-04-25 09:54:28 +00:00
|
|
|
else if (*cur == '?') /* info block */
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
new = __xmlInfoProcess(cur, restlen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_INVALID_INFO_BLOCK;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
/*
|
|
|
|
* get element name and a pointer to after the opening tag
|
|
|
|
*/
|
2009-03-31 08:06:17 +00:00
|
|
|
element = *name;
|
2008-07-19 12:18:05 +00:00
|
|
|
elementlen = *rlen;
|
2009-04-25 09:54:28 +00:00
|
|
|
len_remaining = restlen;
|
|
|
|
new = rptr = __xml_memncasecmp(cur, &restlen, &element, &elementlen);
|
|
|
|
if (rptr) /* requested element was found */
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
return_len = elementlen;
|
2009-04-20 16:46:39 +00:00
|
|
|
if (found == num)
|
2009-04-16 19:03:22 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
ret = new;
|
2009-04-20 16:46:39 +00:00
|
|
|
start_tag = element;
|
|
|
|
*rlen = elementlen;
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
else start_tag = 0;
|
2008-07-01 12:15:46 +00:00
|
|
|
}
|
2009-04-25 09:54:28 +00:00
|
|
|
else /* different element name was foud */
|
2008-07-01 12:15:46 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
new = cur + (len_remaining - restlen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (new >= ne)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_UNEXPECTED_EOF;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-03-31 08:06:17 +00:00
|
|
|
element = *name;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (*(new-2) == '/') /* e.g. <test/> */
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
cur = new;
|
|
|
|
if (rptr)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
if (found == num)
|
|
|
|
{
|
|
|
|
*name = start_tag;
|
|
|
|
*len = 0;
|
|
|
|
}
|
|
|
|
found++;
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
/*
|
|
|
|
* get the next xml tag
|
|
|
|
*/
|
2008-07-19 12:18:05 +00:00
|
|
|
/* restlen -= new-cur; not necessary because of __xml_memncasecmp */
|
|
|
|
cur = new;
|
|
|
|
new = memchr(cur, '<', restlen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_ELEMENT_NO_CLOSING_TAG;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-04-26 09:05:22 +00:00
|
|
|
new++;
|
2008-07-19 12:18:05 +00:00
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
2009-04-26 09:05:22 +00:00
|
|
|
if (*cur == '!') /* comment */
|
|
|
|
{
|
|
|
|
new = __xmlCommentSkip(cur, restlen);
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_INVALID_COMMENT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* look for the closing tag of the cascading block
|
|
|
|
*/
|
|
|
|
new = memchr(cur, '<', restlen);
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_ELEMENT_NO_CLOSING_TAG;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
new++;
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cur != '/') /* cascading tag found */
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *node = "*";
|
2009-04-26 09:05:22 +00:00
|
|
|
size_t slen = restlen+1;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t nlen = 1;
|
2009-03-31 08:06:17 +00:00
|
|
|
size_t pos = -1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
/*
|
|
|
|
* recursively walk the xml tree from here
|
|
|
|
*/
|
2009-04-26 09:05:22 +00:00
|
|
|
new = __xmlNodeGet(cur-1, &slen, &node, &nlen, &pos);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (!new)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
if (slen == restlen)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_UNEXPECTED_EOF;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
else new = cur + slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
restlen -= slen;
|
|
|
|
cur = new;
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
/*
|
|
|
|
* look for the closing tag of the cascading block
|
|
|
|
*/
|
2008-07-19 12:18:05 +00:00
|
|
|
new = memchr(cur, '<', restlen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_ELEMENT_NO_CLOSING_TAG;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-26 09:05:22 +00:00
|
|
|
new++;
|
2008-07-19 12:18:05 +00:00
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
}
|
|
|
|
|
2009-04-26 09:05:22 +00:00
|
|
|
if (*cur == '/') /* closing tag found */
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
2009-04-26 09:05:22 +00:00
|
|
|
if (!strncasecmp(new+1, element, elementlen))
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-27 09:45:59 +00:00
|
|
|
if (*(new+elementlen+1) != '>')
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = new+1;
|
|
|
|
*len = XML_ELEMENT_NO_CLOSING_TAG;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
if (found == num)
|
2009-04-16 19:03:22 +00:00
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
if (start_tag)
|
|
|
|
{
|
2009-04-26 09:05:22 +00:00
|
|
|
*len = new-ret-1;
|
2009-04-20 16:46:39 +00:00
|
|
|
*name = start_tag;
|
|
|
|
}
|
|
|
|
else /* report error */
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = new;
|
|
|
|
*len = XML_ELEMENT_NO_OPENING_TAG;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
found++;
|
|
|
|
}
|
2009-04-27 09:45:59 +00:00
|
|
|
/* else proper closing tag not yet found, continue. */
|
|
|
|
/* TODO: could be a bad match to the opening tag though */
|
|
|
|
/* like: <test></teft> */
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
new = memchr(cur, '>', restlen);
|
2009-04-20 16:46:39 +00:00
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
|
|
|
*len = XML_ELEMENT_NO_CLOSING_TAG;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
}
|
2009-04-20 16:46:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*rlen = 0;
|
|
|
|
*name = cur;
|
2009-04-25 09:54:28 +00:00
|
|
|
*len = XML_ELEMENT_NO_CLOSING_TAG;
|
2009-04-20 16:46:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (found == 0)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
*rlen = 0;
|
|
|
|
*name = start_tag;
|
2009-04-25 09:54:28 +00:00
|
|
|
*len = XML_NO_ERROR; /* element not found, no real error */
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
*rlen = return_len;
|
2009-04-20 16:46:39 +00:00
|
|
|
*nodenum = found;
|
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2009-04-16 19:03:22 +00:00
|
|
|
__xmlCommentSkip(const char *start, size_t len)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *cur, *new;
|
|
|
|
|
|
|
|
cur = (char *)start;
|
|
|
|
new = 0;
|
|
|
|
|
|
|
|
if (memcmp(cur, "!--", 3) == 0)
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
if (len < 6) return 0; /* <!-- --> */
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
cur += 3;
|
|
|
|
len -= 3;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
new = memchr(cur, '-', len);
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
len -= new - cur;
|
2008-07-20 09:38:53 +00:00
|
|
|
if ((len > 3) && (memcmp(new, "-->", 3) == 0))
|
2008-06-30 12:00:40 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
new += 3;
|
|
|
|
len -= 3;
|
|
|
|
break;
|
2008-06-30 12:00:40 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
cur = new+1;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-20 09:38:53 +00:00
|
|
|
else break;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
while (new && (len > 2));
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
return new;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
char *
|
2009-04-18 21:25:23 +00:00
|
|
|
__xmlInfoProcess(const char *start, size_t len)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *cur, *new;
|
|
|
|
|
|
|
|
cur = (char *)start;
|
|
|
|
new = 0;
|
|
|
|
|
|
|
|
if (*cur == '?')
|
|
|
|
{
|
2009-04-20 16:46:39 +00:00
|
|
|
if (len < 3) return 0; /* <? ?> */
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
cur++;
|
|
|
|
len--;
|
|
|
|
new = memchr(cur, '?', len);
|
|
|
|
if (!new || *(new+1) != '>') return 0;
|
|
|
|
|
|
|
|
new += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
#define NOCASECMP(a,b) ( ((a)^(b)) & 0xdf )
|
2008-07-06 11:34:50 +00:00
|
|
|
void *
|
2009-03-31 08:06:17 +00:00
|
|
|
__xml_memncasecmp(const char *haystack, size_t *haystacklen,
|
|
|
|
char **needle, size_t *needlelen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
char *rptr = 0;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
if (haystack && needle && needlelen && (*needlelen > 0)
|
2008-07-19 12:18:05 +00:00
|
|
|
&& (*haystacklen >= *needlelen))
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
char *hs = (char *)haystack;
|
2008-07-19 12:18:05 +00:00
|
|
|
char *ns;
|
2008-07-06 11:34:50 +00:00
|
|
|
size_t i;
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
ns = *needle;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
/* search for everything */
|
|
|
|
if ((*ns == '*') && (*needlelen == 1))
|
|
|
|
{
|
2009-04-26 09:05:22 +00:00
|
|
|
char *p, *he = hs + *haystacklen;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
while ((hs < he) && !isspace(*hs) && (*hs != '>')) hs++;
|
2009-04-25 09:54:28 +00:00
|
|
|
if (*(hs-1) == '/') hs--;
|
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
*needle = (char *)haystack;
|
|
|
|
*needlelen = hs - haystack;
|
2009-04-25 09:54:28 +00:00
|
|
|
|
2009-04-26 09:05:22 +00:00
|
|
|
p = hs;
|
2008-07-19 12:18:05 +00:00
|
|
|
while ((hs < he) && (*hs != '>')) hs++;
|
2009-04-25 09:54:28 +00:00
|
|
|
hs++;
|
|
|
|
|
2008-07-06 11:34:50 +00:00
|
|
|
rptr = hs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t nlen = *needlelen;
|
2008-07-19 12:18:05 +00:00
|
|
|
char *he = hs + *haystacklen;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
for (i=0; i<nlen; i++)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
if (NOCASECMP(*hs,*ns) && (*ns != '?')) break;
|
2009-04-25 09:54:28 +00:00
|
|
|
if (isspace(*hs) || (*hs == '/') || (*hs == '>')) break;
|
2008-07-06 11:34:50 +00:00
|
|
|
hs++;
|
|
|
|
ns++;
|
|
|
|
}
|
|
|
|
|
2009-04-25 09:54:28 +00:00
|
|
|
if (i == nlen)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
2009-03-31 08:06:17 +00:00
|
|
|
*needle = (char *)haystack;
|
|
|
|
*needlelen = hs - haystack;
|
2009-04-25 09:54:28 +00:00
|
|
|
|
|
|
|
while ((hs < he) && (*hs != '>')) hs++;
|
|
|
|
hs++;
|
|
|
|
|
|
|
|
rptr = hs;
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
2009-04-25 09:54:28 +00:00
|
|
|
else /* not found */
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
while((hs < he) && !isspace(*hs) && (*hs != '>')) hs++;
|
|
|
|
if (*(hs-1) == '/') hs--;
|
2009-04-20 16:46:39 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
*needle = (char *)haystack;
|
|
|
|
*needlelen = hs - haystack;
|
2009-04-20 16:46:39 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
while ((hs < he) && (*hs != '>')) hs++;
|
2009-04-25 09:54:28 +00:00
|
|
|
hs++;
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
2009-03-31 08:06:17 +00:00
|
|
|
*haystacklen -= hs - haystack;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
return rptr;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 21:25:23 +00:00
|
|
|
#ifndef XML_NONVALIDATING
|
|
|
|
void
|
2009-04-18 22:20:50 +00:00
|
|
|
__xmlErrorSet(const void *id, const char *pos, unsigned int err_no)
|
2009-04-18 21:25:23 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
struct _root_id *rid;
|
|
|
|
|
|
|
|
assert(xid != 0);
|
|
|
|
|
|
|
|
if (xid->name) rid = xid->root;
|
|
|
|
else rid = (struct _root_id *)xid;
|
|
|
|
|
|
|
|
assert(rid != 0);
|
|
|
|
if (rid->info == 0)
|
2009-04-20 16:46:39 +00:00
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
rid->info = malloc(sizeof(struct _xml_error));
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
|
|
|
|
if (rid->info)
|
|
|
|
{
|
|
|
|
struct _xml_error *err = rid->info;
|
|
|
|
|
|
|
|
err->pos = (char *)pos;
|
2009-04-18 22:20:50 +00:00
|
|
|
err->err_no = err_no;
|
2009-04-18 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
/* Source:
|
|
|
|
* https://mollyrocket.com/forums/viewtopic.php?p=2529
|
|
|
|
*/
|
|
|
|
|
|
|
|
void *
|
2009-04-16 19:03:22 +00:00
|
|
|
simple_mmap(int fd, size_t length, SIMPLE_UNMMAP *un)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
HANDLE f;
|
|
|
|
HANDLE m;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
f = (HANDLE)_get_osfhandle(fd);
|
|
|
|
if (!f) return NULL;
|
|
|
|
|
|
|
|
m = CreateFileMapping(f, NULL, PAGE_READONLY, 0, 0, NULL);
|
|
|
|
if (!m) return NULL;
|
|
|
|
|
|
|
|
p = MapViewOfFile(m, FILE_MAP_READ, 0,0,0);
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
CloseHandle(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (un)
|
|
|
|
{
|
|
|
|
un->m = m;
|
|
|
|
un->p = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
simple_unmmap(SIMPLE_UNMMAP *un)
|
|
|
|
{
|
2009-04-18 21:25:23 +00:00
|
|
|
UnmapViewOfFile(un->p);
|
|
|
|
CloseHandle(un->m);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
#endif
|