diff --git a/src/util/include/dds/util/ut_xmlparser.h b/src/util/include/dds/util/ut_xmlparser.h index 2b9c7be..9db5aea 100644 --- a/src/util/include/dds/util/ut_xmlparser.h +++ b/src/util/include/dds/util/ut_xmlparser.h @@ -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); diff --git a/src/util/src/ut_xmlparser.c b/src/util/src/ut_xmlparser.c index 92f8676..fa8fc5f 100644 --- a/src/util/src/ut_xmlparser.c +++ b/src/util/src/ut_xmlparser.c @@ -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;