give XML parser an option to ignore junk at the end
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
431f70a2e9
commit
f65d07fb14
2 changed files with 9 additions and 1 deletions
|
@ -38,6 +38,7 @@ extern "C" {
|
|||
|
||||
DDS_EXPORT struct ut_xmlpState *ut_xmlpNewFile (FILE *fp, void *varg, const struct ut_xmlpCallbacks *cb);
|
||||
DDS_EXPORT struct ut_xmlpState *ut_xmlpNewString (const char *string, void *varg, const struct ut_xmlpCallbacks *cb);
|
||||
DDS_EXPORT void ut_xmlpSetRequireEOF (struct ut_xmlpState *st, int require_eof);
|
||||
DDS_EXPORT void ut_xmlpFree (struct ut_xmlpState *st);
|
||||
DDS_EXPORT int ut_xmlpParse (struct ut_xmlpState *st);
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ struct ut_xmlpState {
|
|||
size_t tpescp; /* still escape sequences in tpescp .. tpp */
|
||||
int nest; /* current nesting level */
|
||||
void *varg; /* user argument to callback functions */
|
||||
int require_eof; /* if false, junk may follow top-level closing tag */
|
||||
struct ut_xmlpCallbacks cb; /* user-supplied callbacks (or stubs) */
|
||||
};
|
||||
|
||||
|
@ -107,6 +108,7 @@ static void ut_xmlpNewCommon (struct ut_xmlpState *st)
|
|||
st->peekpayload = NULL;
|
||||
st->nest = 0;
|
||||
st->error = 0;
|
||||
st->require_eof = 1;
|
||||
}
|
||||
|
||||
static void ut_xmlpNewSetCB (struct ut_xmlpState *st, void *varg, const struct ut_xmlpCallbacks *cb)
|
||||
|
@ -146,6 +148,11 @@ struct ut_xmlpState *ut_xmlpNewString (const char *string, void *varg, const str
|
|||
return st;
|
||||
}
|
||||
|
||||
void ut_xmlpSetRequireEOF (struct ut_xmlpState *st, int require_eof)
|
||||
{
|
||||
st->require_eof = require_eof;
|
||||
}
|
||||
|
||||
void ut_xmlpFree (struct ut_xmlpState *st)
|
||||
{
|
||||
if (st->fp != NULL) {
|
||||
|
@ -697,7 +704,7 @@ int ut_xmlpParse (struct ut_xmlpState *st)
|
|||
return 0;
|
||||
} else {
|
||||
int ret = parse_element (st, 0);
|
||||
if (ret < 0 || next_token (st, NULL) == TOK_EOF) {
|
||||
if (ret < 0|| !st->require_eof || next_token (st, NULL) == TOK_EOF ) {
|
||||
return ret;
|
||||
} else {
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue