diff --git a/HTMLparser.c b/HTMLparser.c index 06aa098b..a331581f 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -5847,7 +5847,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data, return(NULL); encoding = xmlGetCharEncodingName(enc); - input = xmlInputCreatePush(filename, chunk, size); + input = xmlNewPushInput(filename, chunk, size); if (input == NULL) { htmlFreeParserCtxt(ctxt); return(NULL); diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index e8869090..2e857751 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -521,6 +521,10 @@ Interfaces, constants and types related to the XML parser Daniel Veillard + + + + @@ -718,10 +722,16 @@ + + + + + + @@ -799,10 +809,6 @@ - - - - @@ -833,12 +839,6 @@ - - - - - - @@ -3969,13 +3969,13 @@ Macro to extract the line number of an element node. - + - + - + - + A namespace declaration node. @@ -6980,7 +6980,7 @@ crash if you try to modify the tree)'/> defined(LIBXML_HTML_ENABLED) - Parse an HTML file from the filesystem, the network or a user-defined resource loader. See xmlNewInputURL and htmlCtxtUseOptions for details. + Parse an HTML file from the filesystem, the network or a user-defined resource loader. See htmlCtxtUseOptions for details. @@ -6989,7 +6989,7 @@ crash if you try to modify the tree)'/> defined(LIBXML_HTML_ENABLED) - Parse an HTML document from I/O functions and source and build a tree. See xmlNewInputIO and htmlCtxtUseOptions for details. + Parse an HTML document from I/O functions and source and build a tree. See htmlCtxtUseOptions for details. @@ -7163,7 +7163,7 @@ crash if you try to modify the tree)'/> defined(LIBXML_HTML_ENABLED) - Allocate and initialize a new HTML parser context. This can be used to parse HTML documents into DOM trees with functions like xmlCtxtReadFile or xmlCtxtReadMemory. See htmlCtxtUseOptions for parser options. See xmlCtxtSetErrorHandler for advanced error handling. See xmlNewInputURL, xmlNewInputMemory, xmlNewInputIO and similar functions for advanced input control. See htmlNewSAXParserCtxt for custom SAX parsers. + Allocate and initialize a new HTML parser context. This can be used to parse HTML documents into DOM trees with functions like xmlCtxtReadFile or xmlCtxtReadMemory. See htmlCtxtUseOptions for parser options. See xmlCtxtSetErrorHandler for advanced error handling. See htmlNewSAXParserCtxt for custom SAX parsers. @@ -7268,7 +7268,7 @@ crash if you try to modify the tree)'/> defined(LIBXML_HTML_ENABLED) - Parse an HTML file and build a tree. See xmlNewInputURL for details. + Parse an HTML file and build a tree. @@ -10010,44 +10010,6 @@ crash if you try to modify the tree)'/> - - Creates a new parser input to read from a zero-terminated string. @url is used as base to resolve external entities and for error reporting. @fd is closed after parsing has finished. Available since 2.14.0. - - - - - - - Creates a new parser input to read from input callbacks and cintext. @url is used as base to resolve external entities and for error reporting. @ioRead is called to read new data into a provided buffer. It must return the number of bytes written into the buffer ot a negative xmlParserErrors code on failure. @ioClose is called after parsing has finished. @ioCtxt is an opaque pointer passed to the callbacks. Available since 2.14.0. - - - - - - - - - Creates a new parser input to read from a memory area. @url is used as base to resolve external entities and for error reporting. If the XML_INPUT_BUF_STATIC flag is set, the memory area must stay unchanged until parsing has finished. This can avoid temporary copies. If the XML_INPUT_BUF_ZERO_TERMINATED flag is set, the memory area must contain a zero byte after the buffer at position @size. This can avoid temporary copies. Available since 2.14.0. - - - - - - - - Creates a new parser input to read from a zero-terminated string. @url is used as base to resolve external entities and for error reporting. If the XML_INPUT_BUF_STATIC flag is set, the string must stay unchanged until parsing has finished. This can avoid temporary copies. Available since 2.14.0. - - - - - - - Create a new input stream based on a file or a URL. The flag XML_INPUT_UNZIP allows decompression. The flag XML_INPUT_NETWORK allows network access. The following resource loaders will be called if they were registered (in order of precedence): - the per-thread xmlParserInputBufferCreateFilenameFunc set with xmlParserInputBufferCreateFilenameDefault (deprecated) - the default loader which will return - the result from a matching global input callback set with xmlRegisterInputCallbacks (deprecated) - a HTTP resource if support is compiled in. - a file opened from the filesystem, with automatic detection of compressed files if support is compiled in. Available since 2.14.0. - - - - - Callback used in the I/O Input API to detect if the current handler can provide input functionality for this resource. @@ -10065,7 +10027,7 @@ crash if you try to modify the tree)'/> - + Use encoding handler to decode input data. Closes the handler on error. @@ -10778,14 +10740,52 @@ crash if you try to modify the tree)'/> + + Creates a new parser input to read from a zero-terminated string. @url is used as base to resolve external entities and for error reporting. @fd is closed after parsing has finished. Available since 2.14.0. + + + + + - DEPRECATED: Use xmlInputCreateUrl. Create a new input stream based on a file or an URL. + DEPRECATED: Use xmlNewInputFromUrl. Create a new input stream based on a file or an URL. + + Creates a new parser input to read from input callbacks and cintext. @url is used as base to resolve external entities and for error reporting. @ioRead is called to read new data into a provided buffer. It must return the number of bytes written into the buffer ot a negative xmlParserErrors code on failure. @ioClose is called after parsing has finished. @ioCtxt is an opaque pointer passed to the callbacks. Available since 2.14.0. + + + + + + + + + Creates a new parser input to read from a memory area. @url is used as base to resolve external entities and for error reporting. If the XML_INPUT_BUF_STATIC flag is set, the memory area must stay unchanged until parsing has finished. This can avoid temporary copies. If the XML_INPUT_BUF_ZERO_TERMINATED flag is set, the memory area must contain a zero byte after the buffer at position @size. This can avoid temporary copies. Available since 2.14.0. + + + + + + + + Creates a new parser input to read from a zero-terminated string. @url is used as base to resolve external entities and for error reporting. If the XML_INPUT_BUF_STATIC flag is set, the string must stay unchanged until parsing has finished. This can avoid temporary copies. Available since 2.14.0. + + + + + + + Create a new input stream based on a file or a URL. The flag XML_INPUT_UNZIP allows decompression. The flag XML_INPUT_NETWORK allows network access. The following resource loaders will be called if they were registered (in order of precedence): - the per-thread xmlParserInputBufferCreateFilenameFunc set with xmlParserInputBufferCreateFilenameDefault (deprecated) - the default loader which will return - the result from a matching global input callback set with xmlRegisterInputCallbacks (deprecated) - a HTTP resource if support is compiled in. - a file opened from the filesystem, with automatic detection of compressed files if support is compiled in. Available since 2.14.0. + + + + + - DEPRECATED: Use xmlInputCreateUrl or similar functions. Create a new input stream structure. + DEPRECATED: Use xmlNewInputFromUrl or similar functions. Create a new input stream structure. @@ -10862,7 +10862,7 @@ crash if you try to modify the tree)'/> - DEPRECATED: Use xmlInputCreateString. Create a new input stream based on a memory buffer. + DEPRECATED: Use xmlNewInputFromString. Create a new input stream based on a memory buffer. diff --git a/fuzz/fuzz.c b/fuzz/fuzz.c index 82c9fcbf..1b7ae0cd 100644 --- a/fuzz/fuzz.c +++ b/fuzz/fuzz.c @@ -413,9 +413,9 @@ xmlFuzzResourceLoader(void *data ATTRIBUTE_UNUSED, const char *URL, if (entity == NULL) return(XML_IO_ENOENT); - input = xmlInputCreateMemory(URL, entity->data, entity->size, - XML_INPUT_BUF_STATIC | - XML_INPUT_BUF_ZERO_TERMINATED); + input = xmlNewInputFromMemory(URL, entity->data, entity->size, + XML_INPUT_BUF_STATIC | + XML_INPUT_BUF_ZERO_TERMINATED); if (input == NULL) return(XML_ERR_NO_MEMORY); diff --git a/fuzz/genSeed.c b/fuzz/genSeed.c index 958860c0..55c3ab60 100644 --- a/fuzz/genSeed.c +++ b/fuzz/genSeed.c @@ -64,7 +64,7 @@ fuzzResourceRecorder(void *data ATTRIBUTE_UNUSED, const char *URL, *out = NULL; - code = xmlInputCreateUrl(URL, flags, &in); + code = xmlNewInputFromUrl(URL, flags, &in); if (code != XML_ERR_OK) return(code); @@ -94,7 +94,7 @@ fuzzResourceRecorder(void *data ATTRIBUTE_UNUSED, const char *URL, xmlHashAddEntry(globalData.entities, (const xmlChar *) URL, globalData.entities); - return(xmlInputCreateUrl(URL, flags, out)); + return(xmlNewInputFromUrl(URL, flags, out)); } static void diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 7baa9a9d..9308617c 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -1518,6 +1518,31 @@ XMLPUBFUN xmlDocPtr const char *encoding, int options); +/** + * New input API + */ + +#define XML_INPUT_BUF_STATIC (1 << 1) +#define XML_INPUT_BUF_ZERO_TERMINATED (1 << 2) +#define XML_INPUT_UNZIP (1 << 3) +#define XML_INPUT_NETWORK (1 << 4) + +XMLPUBFUN int +xmlNewInputFromUrl(const char *url, int flags, xmlParserInputPtr *out); +XMLPUBFUN xmlParserInputPtr +xmlNewInputFromMemory(const char *url, const void *mem, size_t size, + int flags); +XMLPUBFUN xmlParserInputPtr +xmlNewInputFromString(const char *url, const char *str, int flags); +XMLPUBFUN xmlParserInputPtr +xmlNewInputFromFd(const char *url, int fd, int flags); +XMLPUBFUN xmlParserInputPtr +xmlNewInputFromIO(const char *url, xmlInputReadCallback ioRead, + xmlInputCloseCallback ioClose, void *ioCtxt, int flags); +XMLPUBFUN int +xmlInputSetEncodingHandler(xmlParserInputPtr input, + xmlCharEncodingHandlerPtr handler); + /* * Library wide options */ diff --git a/include/libxml/parserInternals.h b/include/libxml/parserInternals.h index e540747f..0566e0d4 100644 --- a/include/libxml/parserInternals.h +++ b/include/libxml/parserInternals.h @@ -354,31 +354,6 @@ XMLPUBFUN xmlParserInputPtr XMLPUBFUN xmlParserInputPtr xmlNewInputStream (xmlParserCtxtPtr ctxt); -/** - * New input API - */ - -#define XML_INPUT_BUF_STATIC (1 << 1) -#define XML_INPUT_BUF_ZERO_TERMINATED (1 << 2) -#define XML_INPUT_UNZIP (1 << 3) -#define XML_INPUT_NETWORK (1 << 4) - -XMLPUBFUN int -xmlInputCreateUrl(const char *url, int flags, xmlParserInputPtr *out); -XMLPUBFUN xmlParserInputPtr -xmlInputCreateMemory(const char *url, const void *mem, size_t size, - int flags); -XMLPUBFUN xmlParserInputPtr -xmlInputCreateString(const char *url, const char *str, int flags); -XMLPUBFUN xmlParserInputPtr -xmlInputCreateFd(const char *url, int fd, int flags); -XMLPUBFUN xmlParserInputPtr -xmlInputCreateIO(const char *url, xmlInputReadCallback ioRead, - xmlInputCloseCallback ioClose, void *ioCtxt, int flags); -XMLPUBFUN int -xmlInputSetEncodingHandler(xmlParserInputPtr input, - xmlCharEncodingHandlerPtr handler); - /** * Namespaces. */ diff --git a/include/private/parser.h b/include/private/parser.h index 0118d56a..6b585200 100644 --- a/include/private/parser.h +++ b/include/private/parser.h @@ -115,7 +115,7 @@ xmlCtxtNewInputFromIO(xmlParserCtxtPtr ctxt, const char *url, void *ioCtxt, const char *encoding, int flags); XML_HIDDEN xmlParserInputPtr -xmlInputCreatePush(const char *url, const char *chunk, int size); +xmlNewPushInput(const char *url, const char *chunk, int size); XML_HIDDEN xmlChar * xmlExpandEntitiesInAttValue(xmlParserCtxtPtr ctxt, const xmlChar *str, diff --git a/parser.c b/parser.c index 9b7889f2..1d6b3ea9 100644 --- a/parser.c +++ b/parser.c @@ -11696,7 +11696,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, ctxt->options &= ~XML_PARSE_NODICT; ctxt->dictNames = 1; - input = xmlInputCreatePush(filename, chunk, size); + input = xmlNewPushInput(filename, chunk, size); if (input == NULL) { xmlFreeParserCtxt(ctxt); return(NULL); @@ -13461,7 +13461,7 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk, xmlCtxtReset(ctxt); - input = xmlInputCreatePush(filename, chunk, size); + input = xmlNewPushInput(filename, chunk, size); if (input == NULL) return(1); diff --git a/parserInternals.c b/parserInternals.c index 92691a1c..6d962c6f 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1682,7 +1682,7 @@ xmlFreeInputStream(xmlParserInputPtr input) { * xmlNewInputStream: * @ctxt: an XML parser context * - * DEPRECATED: Use xmlInputCreateUrl or similar functions. + * DEPRECATED: Use xmlNewInputFromUrl or similar functions. * * Create a new input stream structure. * @@ -1773,7 +1773,7 @@ xmlNewInputInternal(xmlParserInputBufferPtr buf, const char *filename) { } /** - * xmlInputCreateMemory: + * xmlNewInputFromMemory: * @url: base URL (optional) * @mem: pointer to char array * @size: size of array @@ -1797,8 +1797,8 @@ xmlNewInputInternal(xmlParserInputBufferPtr buf, const char *filename) { * Returns a new parser input or NULL if a memory allocation failed. */ xmlParserInputPtr -xmlInputCreateMemory(const char *url, const void *mem, size_t size, - int flags) { +xmlNewInputFromMemory(const char *url, const void *mem, size_t size, + int flags) { xmlParserInputBufferPtr buf; if (mem == NULL) @@ -1831,7 +1831,7 @@ xmlCtxtNewInputFromMemory(xmlParserCtxtPtr ctxt, const char *url, if ((ctxt == NULL) || (mem == NULL)) return(NULL); - input = xmlInputCreateMemory(url, mem, size, flags); + input = xmlNewInputFromMemory(url, mem, size, flags); if (input == NULL) { xmlCtxtErrMemory(ctxt); return(NULL); @@ -1844,7 +1844,7 @@ xmlCtxtNewInputFromMemory(xmlParserCtxtPtr ctxt, const char *url, } /** - * xmlInputCreateString: + * xmlNewInputFromString: * @url: base URL (optional) * @str: zero-terminated string * @flags: optimization hints @@ -1863,7 +1863,7 @@ xmlCtxtNewInputFromMemory(xmlParserCtxtPtr ctxt, const char *url, * Returns a new parser input or NULL if a memory allocation failed. */ xmlParserInputPtr -xmlInputCreateString(const char *url, const char *str, int flags) { +xmlNewInputFromString(const char *url, const char *str, int flags) { xmlParserInputBufferPtr buf; if (str == NULL) @@ -1894,7 +1894,7 @@ xmlCtxtNewInputFromString(xmlParserCtxtPtr ctxt, const char *url, if ((ctxt == NULL) || (str == NULL)) return(NULL); - input = xmlInputCreateString(url, str, flags); + input = xmlNewInputFromString(url, str, flags); if (input == NULL) { xmlCtxtErrMemory(ctxt); return(NULL); @@ -1907,7 +1907,7 @@ xmlCtxtNewInputFromString(xmlParserCtxtPtr ctxt, const char *url, } /** - * xmlInputCreateFd: + * xmlNewInputFromFd: * @url: base URL (optional) * @fd: file descriptor * @flags: unused, pass 0 @@ -1924,7 +1924,7 @@ xmlCtxtNewInputFromString(xmlParserCtxtPtr ctxt, const char *url, * Returns a new parser input or NULL if a memory allocation failed. */ xmlParserInputPtr -xmlInputCreateFd(const char *url, int fd, int flags ATTRIBUTE_UNUSED) { +xmlNewInputFromFd(const char *url, int fd, int flags ATTRIBUTE_UNUSED) { xmlParserInputBufferPtr buf; if (fd < 0) @@ -1955,7 +1955,7 @@ xmlCtxtNewInputFromFd(xmlParserCtxtPtr ctxt, const char *url, if ((ctxt == NULL) || (fd < 0)) return(NULL); - input = xmlInputCreateFd(url, fd, flags); + input = xmlNewInputFromFd(url, fd, flags); if (input == NULL) { xmlCtxtErrMemory(ctxt); return(NULL); @@ -1968,7 +1968,7 @@ xmlCtxtNewInputFromFd(xmlParserCtxtPtr ctxt, const char *url, } /** - * xmlInputCreateIO: + * xmlNewInputFromIO: * @url: base URL (optional) * @ioRead: read callback * @ioClose: close callback (optional) @@ -1994,9 +1994,9 @@ xmlCtxtNewInputFromFd(xmlParserCtxtPtr ctxt, const char *url, * Returns a new parser input or NULL if a memory allocation failed. */ xmlParserInputPtr -xmlInputCreateIO(const char *url, xmlInputReadCallback ioRead, - xmlInputCloseCallback ioClose, void *ioCtxt, - int flags ATTRIBUTE_UNUSED) { +xmlNewInputFromIO(const char *url, xmlInputReadCallback ioRead, + xmlInputCloseCallback ioClose, void *ioCtxt, + int flags ATTRIBUTE_UNUSED) { xmlParserInputBufferPtr buf; if (ioRead == NULL) @@ -2038,7 +2038,7 @@ xmlCtxtNewInputFromIO(xmlParserCtxtPtr ctxt, const char *url, if ((ctxt == NULL) || (ioRead == NULL)) return(NULL); - input = xmlInputCreateIO(url, ioRead, ioClose, ioCtxt, flags); + input = xmlNewInputFromIO(url, ioRead, ioClose, ioCtxt, flags); if (input == NULL) { xmlCtxtErrMemory(ctxt); return(NULL); @@ -2051,7 +2051,7 @@ xmlCtxtNewInputFromIO(xmlParserCtxtPtr ctxt, const char *url, } /** - * xmlInputCreatePush: + * xmlNewPushInput: * @url: base URL (optional) * @chunk: pointer to char array * @size: size of array @@ -2061,7 +2061,7 @@ xmlCtxtNewInputFromIO(xmlParserCtxtPtr ctxt, const char *url, * Returns a new parser input or NULL if a memory allocation failed. */ xmlParserInputPtr -xmlInputCreatePush(const char *url, const char *chunk, int size) { +xmlNewPushInput(const char *url, const char *chunk, int size) { xmlParserInputBufferPtr buf; xmlParserInputPtr input; @@ -2170,7 +2170,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr ent) { * @ctxt: an XML parser context * @buffer: an memory buffer * - * DEPRECATED: Use xmlInputCreateString. + * DEPRECATED: Use xmlNewInputFromString. * * Create a new input stream based on a memory buffer. * @@ -2357,7 +2357,7 @@ xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) { } /** - * xmlInputCreateUrl: + * xmlNewInputFromUrl: * @filename: the filename to use as entity * @flags: XML_INPUT flags * @out: pointer to new parser input @@ -2385,7 +2385,7 @@ xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) { * Returns an xmlParserErrors code. */ int -xmlInputCreateUrl(const char *filename, int flags, xmlParserInputPtr *out) { +xmlNewInputFromUrl(const char *filename, int flags, xmlParserInputPtr *out) { xmlParserInputBufferPtr buf; xmlParserInputPtr input; int code = XML_ERR_OK; @@ -2429,7 +2429,7 @@ xmlInputCreateUrl(const char *filename, int flags, xmlParserInputPtr *out) { * @ctxt: an XML parser context * @filename: the filename to use as entity * - * DEPRECATED: Use xmlInputCreateUrl. + * DEPRECATED: Use xmlNewInputFromUrl. * * Create a new input stream based on a file or an URL. * @@ -2449,7 +2449,7 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { if ((ctxt->options & XML_PARSE_NONET) == 0) flags |= XML_INPUT_NETWORK; - code = xmlInputCreateUrl(filename, flags, &input); + code = xmlNewInputFromUrl(filename, flags, &input); if (code != XML_ERR_OK) { xmlCtxtErrIO(ctxt, code, filename); return(NULL); diff --git a/runsuite.c b/runsuite.c index 40aaf132..c92b818e 100644 --- a/runsuite.c +++ b/runsuite.c @@ -122,14 +122,14 @@ testResourceLoader(void *vctxt ATTRIBUTE_UNUSED, const char *URL, for (i = 0; i < nb_entities; i++) { if (!strcmp(testEntitiesName[i], URL)) { - *out = xmlInputCreateString(testEntitiesName[i], + *out = xmlNewInputFromString(testEntitiesName[i], testEntitiesValue[i], XML_INPUT_BUF_STATIC); return(XML_ERR_OK); } } - return(xmlInputCreateUrl(URL, 0, out)); + return(xmlNewInputFromUrl(URL, 0, out)); } /* diff --git a/runtest.c b/runtest.c index 799329ba..6f50303b 100644 --- a/runtest.c +++ b/runtest.c @@ -2105,7 +2105,7 @@ testParseContent(xmlParserCtxtPtr ctxt, xmlDocPtr doc, const char *filename) { content = dumpNodeList(root->children); - input = xmlInputCreateString(NULL, content, XML_INPUT_BUF_STATIC); + input = xmlNewInputFromString(NULL, content, XML_INPUT_BUF_STATIC); list = xmlCtxtParseContent(ctxt, input, root, 0); roundTrip = dumpNodeList(list); if (strcmp(content, roundTrip) != 0) { diff --git a/testapi.c b/testapi.c index 6e4ddf62..438acfbc 100644 --- a/testapi.c +++ b/testapi.c @@ -12846,6 +12846,45 @@ test_xmlInitParserCtxt(void) { } +static int +test_xmlInputSetEncodingHandler(void) { + int test_ret = 0; + + int mem_base; + int ret_val; + xmlParserInputPtr input; /* the input stream */ + int n_input; + xmlCharEncodingHandlerPtr handler; /* the encoding handler */ + int n_handler; + + for (n_input = 0;n_input < gen_nb_xmlParserInputPtr;n_input++) { + for (n_handler = 0;n_handler < gen_nb_xmlCharEncodingHandlerPtr;n_handler++) { + mem_base = xmlMemBlocks(); + input = gen_xmlParserInputPtr(n_input, 0); + handler = gen_xmlCharEncodingHandlerPtr(n_handler, 1); + + ret_val = xmlInputSetEncodingHandler(input, handler); + desret_int(ret_val); + call_tests++; + des_xmlParserInputPtr(n_input, input, 0); + des_xmlCharEncodingHandlerPtr(n_handler, handler, 1); + xmlResetLastError(); + if (mem_base != xmlMemBlocks()) { + printf("Leak of %d blocks found in xmlInputSetEncodingHandler", + xmlMemBlocks() - mem_base); + test_ret++; + printf(" %d", n_input); + printf(" %d", n_handler); + printf("\n"); + } + } + } + function_tests++; + + return(test_ret); +} + + static int test_xmlKeepBlanksDefault(void) { int test_ret = 0; @@ -13003,6 +13042,168 @@ test_xmlNewIOInputStream(void) { } +static int +test_xmlNewInputFromFd(void) { + int test_ret = 0; + + int mem_base; + xmlParserInputPtr ret_val; + const char * url; /* base URL (optional) */ + int n_url; + int fd; /* file descriptor */ + int n_fd; + int flags; /* unused, pass 0 */ + int n_flags; + + for (n_url = 0;n_url < gen_nb_filepath;n_url++) { + for (n_fd = 0;n_fd < gen_nb_int;n_fd++) { + for (n_flags = 0;n_flags < gen_nb_int;n_flags++) { + mem_base = xmlMemBlocks(); + url = gen_filepath(n_url, 0); + fd = gen_int(n_fd, 1); + flags = gen_int(n_flags, 2); + + ret_val = xmlNewInputFromFd(url, fd, flags); + desret_xmlParserInputPtr(ret_val); + call_tests++; + des_filepath(n_url, url, 0); + des_int(n_fd, fd, 1); + des_int(n_flags, flags, 2); + xmlResetLastError(); + if (mem_base != xmlMemBlocks()) { + printf("Leak of %d blocks found in xmlNewInputFromFd", + xmlMemBlocks() - mem_base); + test_ret++; + printf(" %d", n_url); + printf(" %d", n_fd); + printf(" %d", n_flags); + printf("\n"); + } + } + } + } + function_tests++; + + return(test_ret); +} + + +static int +test_xmlNewInputFromIO(void) { + int test_ret = 0; + + + /* missing type support */ + return(test_ret); +} + + +static int +test_xmlNewInputFromMemory(void) { + int test_ret = 0; + + + /* missing type support */ + return(test_ret); +} + + +static int +test_xmlNewInputFromString(void) { + int test_ret = 0; + + int mem_base; + xmlParserInputPtr ret_val; + const char * url; /* base URL (optional) */ + int n_url; + const char * str; /* zero-terminated string */ + int n_str; + int flags; /* optimization hints */ + int n_flags; + + for (n_url = 0;n_url < gen_nb_filepath;n_url++) { + for (n_str = 0;n_str < gen_nb_const_char_ptr;n_str++) { + for (n_flags = 0;n_flags < gen_nb_int;n_flags++) { + mem_base = xmlMemBlocks(); + url = gen_filepath(n_url, 0); + str = gen_const_char_ptr(n_str, 1); + flags = gen_int(n_flags, 2); + + ret_val = xmlNewInputFromString(url, str, flags); + desret_xmlParserInputPtr(ret_val); + call_tests++; + des_filepath(n_url, url, 0); + des_const_char_ptr(n_str, str, 1); + des_int(n_flags, flags, 2); + xmlResetLastError(); + if (mem_base != xmlMemBlocks()) { + printf("Leak of %d blocks found in xmlNewInputFromString", + xmlMemBlocks() - mem_base); + test_ret++; + printf(" %d", n_url); + printf(" %d", n_str); + printf(" %d", n_flags); + printf("\n"); + } + } + } + } + function_tests++; + + return(test_ret); +} + + +#define gen_nb_xmlParserInputPtr_ptr 1 +#define gen_xmlParserInputPtr_ptr(no, nr) NULL +#define des_xmlParserInputPtr_ptr(no, val, nr) + +static int +test_xmlNewInputFromUrl(void) { + int test_ret = 0; + + int mem_base; + int ret_val; + const char * filename; /* the filename to use as entity */ + int n_filename; + int flags; /* XML_INPUT flags */ + int n_flags; + xmlParserInputPtr * out; /* pointer to new parser input */ + int n_out; + + for (n_filename = 0;n_filename < gen_nb_filepath;n_filename++) { + for (n_flags = 0;n_flags < gen_nb_int;n_flags++) { + for (n_out = 0;n_out < gen_nb_xmlParserInputPtr_ptr;n_out++) { + mem_base = xmlMemBlocks(); + filename = gen_filepath(n_filename, 0); + flags = gen_int(n_flags, 1); + out = gen_xmlParserInputPtr_ptr(n_out, 2); + + ret_val = xmlNewInputFromUrl(filename, flags, out); + desret_int(ret_val); + call_tests++; + des_filepath(n_filename, filename, 0); + des_int(n_flags, flags, 1); + des_xmlParserInputPtr_ptr(n_out, out, 2); + xmlResetLastError(); + if (mem_base != xmlMemBlocks()) { + printf("Leak of %d blocks found in xmlNewInputFromUrl", + xmlMemBlocks() - mem_base); + test_ret++; + printf(" %d", n_filename); + printf(" %d", n_flags); + printf(" %d", n_out); + printf("\n"); + } + } + } + } + function_tests++; + + return(test_ret); +} + + static int test_xmlNewParserCtxt(void) { int test_ret = 0; @@ -15134,7 +15335,7 @@ static int test_parser(void) { int test_ret = 0; - if (quiet == 0) printf("Testing parser : 82 of 96 functions ...\n"); + if (quiet == 0) printf("Testing parser : 86 of 102 functions ...\n"); test_ret += test_xmlByteConsumed(); test_ret += test_xmlCleanupGlobals(); test_ret += test_xmlClearNodeInfoSeq(); @@ -15171,10 +15372,16 @@ test_parser(void) { test_ret += test_xmlInitNodeInfoSeq(); test_ret += test_xmlInitParser(); test_ret += test_xmlInitParserCtxt(); + test_ret += test_xmlInputSetEncodingHandler(); test_ret += test_xmlKeepBlanksDefault(); test_ret += test_xmlLineNumbersDefault(); test_ret += test_xmlLoadExternalEntity(); test_ret += test_xmlNewIOInputStream(); + test_ret += test_xmlNewInputFromFd(); + test_ret += test_xmlNewInputFromIO(); + test_ret += test_xmlNewInputFromMemory(); + test_ret += test_xmlNewInputFromString(); + test_ret += test_xmlNewInputFromUrl(); test_ret += test_xmlNewParserCtxt(); test_ret += test_xmlNewSAXParserCtxt(); test_ret += test_xmlParseBalancedChunkMemory(); @@ -15787,207 +15994,6 @@ test_xmlCurrentChar(void) { } -static int -test_xmlInputCreateFd(void) { - int test_ret = 0; - - int mem_base; - xmlParserInputPtr ret_val; - const char * url; /* base URL (optional) */ - int n_url; - int fd; /* file descriptor */ - int n_fd; - int flags; /* unused, pass 0 */ - int n_flags; - - for (n_url = 0;n_url < gen_nb_fileoutput;n_url++) { - for (n_fd = 0;n_fd < gen_nb_int;n_fd++) { - for (n_flags = 0;n_flags < gen_nb_int;n_flags++) { - mem_base = xmlMemBlocks(); - url = gen_fileoutput(n_url, 0); - fd = gen_int(n_fd, 1); - flags = gen_int(n_flags, 2); - - ret_val = xmlInputCreateFd(url, fd, flags); - desret_xmlParserInputPtr(ret_val); - call_tests++; - des_fileoutput(n_url, url, 0); - des_int(n_fd, fd, 1); - des_int(n_flags, flags, 2); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlInputCreateFd", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_url); - printf(" %d", n_fd); - printf(" %d", n_flags); - printf("\n"); - } - } - } - } - function_tests++; - - return(test_ret); -} - - -static int -test_xmlInputCreateIO(void) { - int test_ret = 0; - - - /* missing type support */ - return(test_ret); -} - - -static int -test_xmlInputCreateMemory(void) { - int test_ret = 0; - - - /* missing type support */ - return(test_ret); -} - - -static int -test_xmlInputCreateString(void) { - int test_ret = 0; - - int mem_base; - xmlParserInputPtr ret_val; - const char * url; /* base URL (optional) */ - int n_url; - const char * str; /* zero-terminated string */ - int n_str; - int flags; /* optimization hints */ - int n_flags; - - for (n_url = 0;n_url < gen_nb_fileoutput;n_url++) { - for (n_str = 0;n_str < gen_nb_const_char_ptr;n_str++) { - for (n_flags = 0;n_flags < gen_nb_int;n_flags++) { - mem_base = xmlMemBlocks(); - url = gen_fileoutput(n_url, 0); - str = gen_const_char_ptr(n_str, 1); - flags = gen_int(n_flags, 2); - - ret_val = xmlInputCreateString(url, str, flags); - desret_xmlParserInputPtr(ret_val); - call_tests++; - des_fileoutput(n_url, url, 0); - des_const_char_ptr(n_str, str, 1); - des_int(n_flags, flags, 2); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlInputCreateString", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_url); - printf(" %d", n_str); - printf(" %d", n_flags); - printf("\n"); - } - } - } - } - function_tests++; - - return(test_ret); -} - - -#define gen_nb_xmlParserInputPtr_ptr 1 -#define gen_xmlParserInputPtr_ptr(no, nr) NULL -#define des_xmlParserInputPtr_ptr(no, val, nr) - -static int -test_xmlInputCreateUrl(void) { - int test_ret = 0; - - int mem_base; - int ret_val; - const char * filename; /* the filename to use as entity */ - int n_filename; - int flags; /* XML_INPUT flags */ - int n_flags; - xmlParserInputPtr * out; /* pointer to new parser input */ - int n_out; - - for (n_filename = 0;n_filename < gen_nb_fileoutput;n_filename++) { - for (n_flags = 0;n_flags < gen_nb_int;n_flags++) { - for (n_out = 0;n_out < gen_nb_xmlParserInputPtr_ptr;n_out++) { - mem_base = xmlMemBlocks(); - filename = gen_fileoutput(n_filename, 0); - flags = gen_int(n_flags, 1); - out = gen_xmlParserInputPtr_ptr(n_out, 2); - - ret_val = xmlInputCreateUrl(filename, flags, out); - desret_int(ret_val); - call_tests++; - des_fileoutput(n_filename, filename, 0); - des_int(n_flags, flags, 1); - des_xmlParserInputPtr_ptr(n_out, out, 2); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlInputCreateUrl", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_filename); - printf(" %d", n_flags); - printf(" %d", n_out); - printf("\n"); - } - } - } - } - function_tests++; - - return(test_ret); -} - - -static int -test_xmlInputSetEncodingHandler(void) { - int test_ret = 0; - - int mem_base; - int ret_val; - xmlParserInputPtr input; /* the input stream */ - int n_input; - xmlCharEncodingHandlerPtr handler; /* the encoding handler */ - int n_handler; - - for (n_input = 0;n_input < gen_nb_xmlParserInputPtr;n_input++) { - for (n_handler = 0;n_handler < gen_nb_xmlCharEncodingHandlerPtr;n_handler++) { - mem_base = xmlMemBlocks(); - input = gen_xmlParserInputPtr(n_input, 0); - handler = gen_xmlCharEncodingHandlerPtr(n_handler, 1); - - ret_val = xmlInputSetEncodingHandler(input, handler); - desret_int(ret_val); - call_tests++; - des_xmlParserInputPtr(n_input, input, 0); - des_xmlCharEncodingHandlerPtr(n_handler, handler, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlInputSetEncodingHandler", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_input); - printf(" %d", n_handler); - printf("\n"); - } - } - } - function_tests++; - - return(test_ret); -} - - static int test_xmlIsLetter(void) { int test_ret = 0; @@ -16702,7 +16708,7 @@ static int test_parserInternals(void) { int test_ret = 0; - if (quiet == 0) printf("Testing parserInternals : 36 of 85 functions ...\n"); + if (quiet == 0) printf("Testing parserInternals : 32 of 79 functions ...\n"); test_ret += test_inputPop(); test_ret += test_inputPush(); test_ret += test_namePop(); @@ -16718,12 +16724,6 @@ test_parserInternals(void) { test_ret += test_xmlCreateURLParserCtxt(); test_ret += test_xmlCtxtErrMemory(); test_ret += test_xmlCurrentChar(); - test_ret += test_xmlInputCreateFd(); - test_ret += test_xmlInputCreateIO(); - test_ret += test_xmlInputCreateMemory(); - test_ret += test_xmlInputCreateString(); - test_ret += test_xmlInputCreateUrl(); - test_ret += test_xmlInputSetEncodingHandler(); test_ret += test_xmlIsLetter(); test_ret += test_xmlNewEntityInputStream(); test_ret += test_xmlNewInputFromFile(); diff --git a/testparser.c b/testparser.c index 12d5dba3..11008dbb 100644 --- a/testparser.c +++ b/testparser.c @@ -174,8 +174,8 @@ testCtxtParseContent(void) { for (j = 0; j < 2; j++) { if (j == 0) { - input = xmlInputCreateString(NULL, content, - XML_INPUT_BUF_STATIC); + input = xmlNewInputFromString(NULL, content, + XML_INPUT_BUF_STATIC); list = xmlCtxtParseContent(ctxt, input, node, 0); } else { xmlParseInNodeContext(node, content, strlen(content), 0, diff --git a/xmllint.c b/xmllint.c index a6795827..feec6e63 100644 --- a/xmllint.c +++ b/xmllint.c @@ -234,7 +234,7 @@ xmllintResourceLoader(void *ctxt ATTRIBUTE_UNUSED, const char *URL, if (defaultResourceLoader != NULL) code = defaultResourceLoader(NULL, URL, ID, type, flags, out); else - code = xmlInputCreateUrl(URL, flags, out); + code = xmlNewInputFromUrl(URL, flags, out); if (code != XML_IO_ENOENT) { if ((load_trace) && (code == XML_ERR_OK)) { fprintf(ERR_STREAM, "Loaded URL=\"%s\" ID=\"%s\"\n", @@ -254,7 +254,7 @@ xmllintResourceLoader(void *ctxt ATTRIBUTE_UNUSED, const char *URL, code = defaultResourceLoader(NULL, (const char *) newURL, ID, type, flags, out); else - code = xmlInputCreateUrl((const char *) newURL, flags, out); + code = xmlNewInputFromUrl((const char *) newURL, flags, out); if (code != XML_IO_ENOENT) { if ((load_trace) && (code == XML_ERR_OK)) { fprintf(ERR_STREAM, "Loaded URL=\"%s\" ID=\"%s\"\n",