⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlio.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (in->raw) {        xmlBufferFree(in->raw);	in->raw = NULL;    }    if (in->encoder != NULL) {        xmlCharEncCloseFunc(in->encoder);    }    if (in->closecallback != NULL) {	in->closecallback(in->context);    }    if (in->buffer != NULL) {        xmlBufferFree(in->buffer);	in->buffer = NULL;    }    xmlFree(in);}#ifdef LIBXML_OUTPUT_ENABLED/** * xmlOutputBufferClose: * @out:  a buffered output * * flushes and close the output I/O channel * and free up all the associated resources * * Returns the number of byte written or -1 in case of error. */intxmlOutputBufferClose(xmlOutputBufferPtr out){    int written;    int err_rc = 0;    if (out == NULL)        return (-1);    if (out->writecallback != NULL)        xmlOutputBufferFlush(out);    if (out->closecallback != NULL) {        err_rc = out->closecallback(out->context);    }    written = out->written;    if (out->conv) {        xmlBufferFree(out->conv);        out->conv = NULL;    }    if (out->encoder != NULL) {        xmlCharEncCloseFunc(out->encoder);    }    if (out->buffer != NULL) {        xmlBufferFree(out->buffer);        out->buffer = NULL;    }    if (out->error)        err_rc = -1;    xmlFree(out);    return ((err_rc == 0) ? written : err_rc);}#endif /* LIBXML_OUTPUT_ENABLED */xmlParserInputBufferPtr__xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {    xmlParserInputBufferPtr ret;    int i = 0;    void *context = NULL;    if (xmlInputCallbackInitialized == 0)	xmlRegisterDefaultInputCallbacks();    if (URI == NULL) return(NULL);    /*     * Try to find one of the input accept method accepting that scheme     * Go in reverse to give precedence to user defined handlers.     */    if (context == NULL) {	for (i = xmlInputCallbackNr - 1;i >= 0;i--) {	    if ((xmlInputCallbackTable[i].matchcallback != NULL) &&		(xmlInputCallbackTable[i].matchcallback(URI) != 0)) {		context = xmlInputCallbackTable[i].opencallback(URI);		if (context != NULL) {		    break;		}	    }	}    }    if (context == NULL) {	return(NULL);    }    /*     * Allocate the Input buffer front-end.     */    ret = xmlAllocParserInputBuffer(enc);    if (ret != NULL) {	ret->context = context;	ret->readcallback = xmlInputCallbackTable[i].readcallback;	ret->closecallback = xmlInputCallbackTable[i].closecallback;#ifdef HAVE_ZLIB_H	if ((xmlInputCallbackTable[i].opencallback == xmlGzfileOpen) &&		(strcmp(URI, "-") != 0)) {	    if (((z_stream *)context)->avail_in > 4) {	        char *cptr, buff4[4];		cptr = (char *) ((z_stream *)context)->next_in;		if (gzread(context, buff4, 4) == 4) {		    if (strncmp(buff4, cptr, 4) == 0)		        ret->compressed = 0;		    else		        ret->compressed = 1;		    gzrewind(context);		}	    }	}#endif    }    else      xmlInputCallbackTable[i].closecallback (context);    return(ret);}/** * xmlParserInputBufferCreateFilename: * @URI:  a C string containing the URI or filename * @enc:  the charset encoding if known * * Create a buffered parser input for the progressive parsing of a file * If filename is "-' then we use stdin as the input. * Automatic support for ZLIB/Compress compressed document is provided * by default if found at compile-time. * Do an encoding check if enc == XML_CHAR_ENCODING_NONE * * Returns the new parser input or NULL */xmlParserInputBufferPtrxmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {    if ((xmlParserInputBufferCreateFilenameValue)) {		return xmlParserInputBufferCreateFilenameValue(URI, enc);	}	return __xmlParserInputBufferCreateFilename(URI, enc);}#ifdef LIBXML_OUTPUT_ENABLEDxmlOutputBufferPtr__xmlOutputBufferCreateFilename(const char *URI,                              xmlCharEncodingHandlerPtr encoder,                              int compression ATTRIBUTE_UNUSED) {    xmlOutputBufferPtr ret;    xmlURIPtr puri;    int i = 0;    void *context = NULL;    char *unescaped = NULL;#ifdef HAVE_ZLIB_H    int is_file_uri = 1;#endif    if (xmlOutputCallbackInitialized == 0)	xmlRegisterDefaultOutputCallbacks();    if (URI == NULL) return(NULL);    puri = xmlParseURI(URI);    if (puri != NULL) {        if ((puri->scheme != NULL) &&	    (!xmlStrEqual(BAD_CAST puri->scheme, BAD_CAST "file")))#ifdef HAVE_ZLIB_H	    is_file_uri = 0;#endif	/*	 * try to limit the damages of the URI unescaping code.	 */	if (puri->scheme != NULL)	    unescaped = xmlURIUnescapeString(URI, 0, NULL);	xmlFreeURI(puri);    }    /*     * Try to find one of the output accept method accepting that scheme     * Go in reverse to give precedence to user defined handlers.     * try with an unescaped version of the URI     */    if (unescaped != NULL) {#ifdef HAVE_ZLIB_H	if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) {	    context = xmlGzfileOpenW(unescaped, compression);	    if (context != NULL) {		ret = xmlAllocOutputBuffer(encoder);		if (ret != NULL) {		    ret->context = context;		    ret->writecallback = xmlGzfileWrite;		    ret->closecallback = xmlGzfileClose;		}		xmlFree(unescaped);		return(ret);	    }	}#endif	for (i = xmlOutputCallbackNr - 1;i >= 0;i--) {	    if ((xmlOutputCallbackTable[i].matchcallback != NULL) &&		(xmlOutputCallbackTable[i].matchcallback(unescaped) != 0)) {#if defined(LIBXML_HTTP_ENABLED) && defined(HAVE_ZLIB_H)		/*  Need to pass compression parameter into HTTP open calls  */		if (xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch)		    context = xmlIOHTTPOpenW(unescaped, compression);		else#endif		    context = xmlOutputCallbackTable[i].opencallback(unescaped);		if (context != NULL)		    break;	    }	}	xmlFree(unescaped);    }    /*     * If this failed try with a non-escaped URI this may be a strange     * filename     */    if (context == NULL) {#ifdef HAVE_ZLIB_H	if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) {	    context = xmlGzfileOpenW(URI, compression);	    if (context != NULL) {		ret = xmlAllocOutputBuffer(encoder);		if (ret != NULL) {		    ret->context = context;		    ret->writecallback = xmlGzfileWrite;		    ret->closecallback = xmlGzfileClose;		}		return(ret);	    }	}#endif	for (i = xmlOutputCallbackNr - 1;i >= 0;i--) {	    if ((xmlOutputCallbackTable[i].matchcallback != NULL) &&		(xmlOutputCallbackTable[i].matchcallback(URI) != 0)) {#if defined(LIBXML_HTTP_ENABLED) && defined(HAVE_ZLIB_H)		/*  Need to pass compression parameter into HTTP open calls  */		if (xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch)		    context = xmlIOHTTPOpenW(URI, compression);		else#endif		    context = xmlOutputCallbackTable[i].opencallback(URI);		if (context != NULL)		    break;	    }	}    }    if (context == NULL) {	return(NULL);    }    /*     * Allocate the Output buffer front-end.     */    ret = xmlAllocOutputBuffer(encoder);    if (ret != NULL) {	ret->context = context;	ret->writecallback = xmlOutputCallbackTable[i].writecallback;	ret->closecallback = xmlOutputCallbackTable[i].closecallback;    }    return(ret);}/** * xmlOutputBufferCreateFilename: * @URI:  a C string containing the URI or filename * @encoder:  the encoding converter or NULL * @compression:  the compression ration (0 none, 9 max). * * Create a buffered  output for the progressive saving of a file * If filename is "-' then we use stdout as the output. * Automatic support for ZLIB/Compress compressed document is provided * by default if found at compile-time. * TODO: currently if compression is set, the library only support *       writing to a local file. * * Returns the new output or NULL */xmlOutputBufferPtrxmlOutputBufferCreateFilename(const char *URI,                              xmlCharEncodingHandlerPtr encoder,                              int compression ATTRIBUTE_UNUSED) {    if ((xmlOutputBufferCreateFilenameValue)) {		return xmlOutputBufferCreateFilenameValue(URI, encoder, compression);	}	return __xmlOutputBufferCreateFilename(URI, encoder, compression);}#endif /* LIBXML_OUTPUT_ENABLED *//** * xmlParserInputBufferCreateFile: * @file:  a FILE*  * @enc:  the charset encoding if known * * Create a buffered parser input for the progressive parsing of a FILE * * buffered C I/O * * Returns the new parser input or NULL */xmlParserInputBufferPtrxmlParserInputBufferCreateFile(FILE *file, xmlCharEncoding enc) {    xmlParserInputBufferPtr ret;    if (xmlInputCallbackInitialized == 0)	xmlRegisterDefaultInputCallbacks();    if (file == NULL) return(NULL);    ret = xmlAllocParserInputBuffer(enc);    if (ret != NULL) {        ret->context = file;	ret->readcallback = xmlFileRead;	ret->closecallback = xmlFileFlush;    }    return(ret);}#ifdef LIBXML_OUTPUT_ENABLED/** * xmlOutputBufferCreateFile: * @file:  a FILE*  * @encoder:  the encoding converter or NULL * * Create a buffered output for the progressive saving to a FILE * * buffered C I/O * * Returns the new parser output or NULL */xmlOutputBufferPtrxmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) {    xmlOutputBufferPtr ret;    if (xmlOutputCallbackInitialized == 0)	xmlRegisterDefaultOutputCallbacks();    if (file == NULL) return(NULL);    ret = xmlAllocOutputBuffer(encoder);    if (ret != NULL) {        ret->context = file;	ret->writecallback = xmlFileWrite;	ret->closecallback = xmlFileFlush;    }    return(ret);}#endif /* LIBXML_OUTPUT_ENABLED *//** * xmlParserInputBufferCreateFd: * @fd:  a file descriptor number * @enc:  the charset encoding if known * * Create a buffered parser input for the progressive parsing for the input * from a file descriptor * * Returns the new parser input or NULL */xmlParserInputBufferPtrxmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) {    xmlParserInputBufferPtr ret;    if (fd < 0) return(NULL);    ret = xmlAllocParserInputBuffer(enc);    if (ret != NULL) {        ret->context = (void *) (long) fd;	ret->readcallback = xmlFdRead;	ret->closecallback = xmlFdClose;    }    return(ret);}/** * xmlParserInputBufferCreateMem: * @mem:  the memory input * @size:  the length of the memory block * @enc:  the charset encoding if known * * Create a buffered parser input for the progressive parsing for the input * from a memory area. * * Returns the new parser input or NULL */xmlParserInputBufferPtrxmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc) {    xmlParserInputBufferPtr ret;    int errcode;    if (size <= 0) return(NULL);    if (mem == NULL) return(NULL);    ret = xmlAllocParserInputBuffer(enc);    if (ret != NULL) {        ret->context = (void *) mem;	ret->readcallback = (xmlInputReadCallback) xmlNop;	ret->closecallback = NULL;	errcode = xmlBufferAdd(ret->buffer, (const xmlChar *) mem, size);	if (errcode != 0) {	    xmlFree(ret);	    return(NULL);	}    }    return(ret);}/** * xmlParserInputBufferCreateStatic: * @mem:  the memory input * @size:  the length of the memory block * @enc:  the charset encoding if known * * Create a buffered parser input for the progressive parsing for the input * from an immutable memory area. This will not copy the memory area to * the buffer, but the memory is expected to be available until the end of * the parsing, this is useful for example when using mmap'ed file. * * Returns the new parser input or NULL */xmlParserInputBufferPtrxmlParserInputBufferCreateStatic(const char *mem, int size,                                 xmlCharEncoding enc) {    xmlParserInputBufferPtr ret;    if (size <= 0) return(NULL);    if (mem == NULL) return(NULL);    ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer));    if (ret == NULL) {	xmlIOErrMemory("creating input buffer");	return(NULL);    }    memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer));    ret->buffer = xmlBufferCreateStatic((void *)mem, (size_t) size);    if (ret->buffer == NULL) {        xmlFree(ret);	return(NULL);    }    ret->encoder = xmlGetCharEncodingHandler(enc);    if (ret->encoder != NULL)        ret->raw = xmlBufferCreateSize(2 * xmlDefaultBufferSize);    else        ret->raw = NULL;    ret->compressed = -1;    ret->context = (void *) mem;    ret->readcallback = NULL;    ret->closecallback = NULL;    return(ret);}#ifdef LIBXML_OUTPUT_ENABLED/** * xmlOutputBufferCreateFd: * @fd:  a file descriptor number * @encoder:  the encoding converter or NULL * * Create a buffered output for the progressive saving  * to a file descriptor * * Returns the new parser output or NULL */xmlOutputBufferPtrxmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) {    xmlOutputBufferPtr ret;    if (fd < 0) return(NULL);    ret = xmlAllocOutputBuffer(encoder);    if (ret != NULL) {        ret->context = (void *) (long) fd;	ret->writecallback = xmlFdWrite;	ret->closecallback = NULL;    }    return(ret);}#endif /* LIBXML_OUTPUT_ENABLED *//** * xmlParserInputBufferCreateIO: * @ioread:  an I/O read function * @ioclose:  an I/O close function * @ioctx:  an I/O handler * @enc:  the charset encoding if known * * Create a buffered parser input for the progressive parsing for the input * from an I/O handler * * Returns the new parser input or NULL */xmlParserInputBufferPtrxmlParserInputBufferCreateIO(xmlInputReadCallback   ioread,	 xmlInputCloseCallback  ioclose, void *ioctx, xmlCharEncoding enc) {    xmlParserInputBufferPtr ret;    if (ioread == NULL) return(NULL);    ret = xmlAllocParserInputBuffer(enc);    if (ret != NULL) {        ret->context = (void *) ioctx;	ret->readcallback = ioread;	ret->closecallback = ioclose;    }    return(ret);}#ifdef LIBXML_OUTPUT_ENABLED/** * xmlOutputBufferCreateIO: * @iowrite:  an I/O write function * @ioclose:  an I/O close function * @ioctx:  an I/O handler * @encoder:  the charset encoding i

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -