Пример #1
0
/* call-seq:
 *    XML::Parser::Context.io(io) -> XML::Parser::Context
 *
 * Creates a new parser context based on the specified io object.
 *
 * Parameters:
 *
 *  io - A ruby IO object.
*/
static VALUE rxml_parser_context_io(VALUE klass, VALUE io)
{
  xmlParserCtxtPtr ctxt;
  xmlParserInputBufferPtr input;
  xmlParserInputPtr stream;

  input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
                                       (void*)io, XML_CHAR_ENCODING_NONE);
    
  ctxt = xmlNewParserCtxt();
  if (!ctxt)
  {
    xmlFreeParserInputBuffer(input);
    rxml_raise(&xmlLastError);
  }

  stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);

  if (!stream)
  {
    xmlFreeParserInputBuffer(input);
    xmlFreeParserCtxt(ctxt);
    rxml_raise(&xmlLastError);
  }
  inputPush(ctxt, stream);
  return rxml_parser_context_wrap(ctxt);
}
Пример #2
0
xmlParserCtxtPtr
RS_XML_xmlCreateConnectionParserCtxt(USER_OBJECT_ con)
{
      xmlParserInputBufferPtr buf;
      xmlParserCtxtPtr ctx = NULL;

#ifdef LIBXML2
      ctx = xmlNewParserCtxt();
#ifndef LIBXML2_NEW_BUFFER  // < 2.9.1
      ctx->_private = (USER_OBJECT_) con;
                                      /* R_chk_calloc */
      buf = (xmlParserInputBufferPtr) calloc(1, sizeof(xmlParserInputBuffer));
      buf->readcallback = RS_XML_readConnectionInput;
      buf->context = (void*) ctx;
      buf->raw = NULL; /* buf->buffer; */
      xmlBufferPtr tmp = xmlBufferCreate();
      buf->buffer = tmp;
#else
    RFunCtxData *userData = (RFunCtxData *) R_alloc(sizeof(RFunCtxData), 1);
    userData->fun = con;
    userData->ctx = ctx;
    buf = xmlParserInputBufferCreateIO(RS_XML_readConnectionInput, NULL, userData, XML_CHAR_ENCODING_NONE);
#endif

      xmlParserInputPtr input = xmlNewIOInputStream(ctx, buf, XML_CHAR_ENCODING_NONE);
      if(!input) {
	  PROBLEM "can't create new IOInputStream"
	      ERROR;
      }
      inputPush(ctx, input);
#endif
      return(ctx);
}
Пример #3
0
EPUB3_XML_BEGIN_NAMESPACE

InputBuffer::InputBuffer()
{
    _buf = xmlParserInputBufferCreateIO(InputBuffer::read_cb, InputBuffer::close_cb, this, XML_CHAR_ENCODING_NONE);
    if ( _buf == NULL )
        throw InternalError("Failed to create xml input buffer");
}
Пример #4
0
/**
 * _rsvg_xml_input_buffer_new_from_stream:
 * @context: a #xmlParserCtxtPtr
 * @input_stream: a #GInputStream
 *
 * Returns: a new #xmlParserInputPtr wrapping @input_stream
 */
xmlParserInputBufferPtr
_rsvg_xml_input_buffer_new_from_stream (GInputStream   *stream,
                                        GCancellable   *cancellable,
                                        xmlCharEncoding enc,
                                        GError        **error)

{
    RsvgXmlInputStreamContext *context;

    g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
    g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
    g_return_val_if_fail (error != NULL, NULL);

    context = g_slice_new (RsvgXmlInputStreamContext);
    context->stream = g_object_ref (stream);
    context->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
    context->error = error;

    return xmlParserInputBufferCreateIO ((xmlInputReadCallback) context_read,
                                         (xmlInputCloseCallback) context_close,
                                         context,
                                         enc);
}
Пример #5
0
/**
 * Parse an Index from tape and populate the vol->index->root virtual dentry tree
 * with the nodes found during the scanning.
 * If a file mark is encountered at the end of the Index, the tape is positioned before
 * the file mark.
 * @param eod_pos EOD block position for the current partition, or 0 to assume EOD will not be
 *                encountered during parsing.
 * @param vol LTFS volume.
 * @return 0 on success, 1 if parsing succeeded but no file mark was encountered,
 *         or a negative value on error.
 */
int xml_schema_from_tape(uint64_t eod_pos, struct ltfs_volume *vol)
{
	int ret;
	struct tc_position current_pos;
	struct xml_input_tape *ctx;
	xmlParserInputBufferPtr read_buf;
	xmlTextReaderPtr reader;
	xmlDocPtr doc;

	CHECK_ARG_NULL(vol, -LTFS_NULL_ARG);

	ret = tape_get_position(vol->device, &current_pos);
	if (ret < 0) {
		ltfsmsg(LTFS_ERR, "17013E", ret);
		return ret;
	}

	/* Create output callback context data structure. */
	ctx = malloc(sizeof(struct xml_input_tape));
	if (! ctx) {
		ltfsmsg(LTFS_ERR, "10001E", "xml_schema_from_tape: ctx");
		return -LTFS_NO_MEMORY;
	}
	ctx->buf = malloc(vol->label->blocksize + LTFS_CRC_SIZE);
	if (! ctx->buf) {
		ltfsmsg(LTFS_ERR, "10001E", "xml_schema_from_tape: ctx->buf");
		free(ctx);
		return -LTFS_NO_MEMORY;
	}
	ctx->vol = vol;
	ctx->current_pos = current_pos.block;
	ctx->eod_pos = eod_pos;
	ctx->saw_small_block = false;
	ctx->saw_file_mark = false;
	ctx->buf_size = vol->label->blocksize;
	ctx->buf_start = 0;
	ctx->buf_used = 0;

	/* Create input buffer pointer. */
	read_buf = xmlParserInputBufferCreateIO(xml_input_tape_read_callback,
											xml_input_tape_close_callback,
											ctx, XML_CHAR_ENCODING_NONE);
	if (! read_buf) {
		ltfsmsg(LTFS_ERR, "17014E");
		free(ctx->buf);
		free(ctx);
		return -LTFS_LIBXML2_FAILURE;
	}

	/* Create XML reader. */
	reader = xmlNewTextReader(read_buf, NULL);
	if (! reader) {
		ltfsmsg(LTFS_ERR, "17015E");
		xmlFreeParserInputBuffer(read_buf);
		return -LTFS_LIBXML2_FAILURE;
	}

	/* Workaround for old libxml2 version on OS X 10.5. See comment in xml_schema_from_file()
	 * for details. */
	doc = xmlTextReaderCurrentDoc(reader);

	/* Generate the Index. */
	ret = _xml_parse_schema(reader, vol->index, vol);
	if (ret < 0) {
		ltfsmsg(LTFS_ERR, "17016E");
		if ((ret != -LTFS_UNSUPPORTED_INDEX_VERSION)&&( ret != -LTFS_SYMLINK_CONFLICT)) {
			if (ret == -LTFS_NO_MEMORY)
				ret = -LTFS_NO_MEMORY;
			else
				ret = -LTFS_INDEX_INVALID;
		}
	} else if (ret == 0) {
		if( ! ctx->saw_file_mark)
			ret = 1;
	}
	if (doc)
		xmlFreeDoc(doc);
	xmlFreeTextReader(reader);
	xmlFreeParserInputBuffer(read_buf);

#ifdef DEBUG
	/* dump the tree if it isn't too large */
	if (ret >= 0 && vol->index->file_count < 1000)
		fs_dump_tree(vol->index->root);
#endif

	return ret;
}