/* * Create buffer for progressive parsing */ static xmlParserInputBufferPtr js_buffer_create (js_session_t *jsp, xmlCharEncoding enc) { xmlParserInputBufferPtr ret; if (jsp == NULL) return NULL; ret = xmlAllocParserInputBuffer(enc); if (ret != NULL) { ret->context = (void *) jsp; ret->readcallback = js_buffer_read; ret->closecallback = js_buffer_close; } return ret; }
static xmlParserInputBufferPtr libxml_create_input_buffer(const char* URI, xmlCharEncoding enc) { ITRACE(1, "libxml_create_input_buffer({}, {})\n", URI, static_cast<int>(enc)); Trace::Indent _i; if (tl_libxml_request_data->m_entity_loader_disabled || !URI) return nullptr; auto stream = libxml_streams_IO_open_wrapper(URI, "rb", true); if (!stream || stream->isInvalid()) return nullptr; // Allocate the Input buffer front-end. xmlParserInputBufferPtr ret = xmlAllocParserInputBuffer(enc); if (ret != nullptr) { ret->context = rememberStream(std::move(stream)); ret->readcallback = libxml_streams_IO_read; ret->closecallback = libxml_streams_IO_close; } return ret; }
/* * call-seq: * XML::Dtd.new("DTD string") -> dtd * XML::Dtd.new("public", "system") -> dtd * XML::Dtd.new("name", "public", "system", document) -> external subset dtd * XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd * XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd * * Create a new Dtd from the specified public and system * identifiers. */ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self) { VALUE external, system, dtd_string; xmlParserInputBufferPtr buffer; xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; xmlChar *new_string; xmlDtdPtr xdtd; // 1 argument -- string --> parsujeme jako dtd // 2 arguments -- public, system --> bude se hledat // 3 arguments -- public, system, name --> creates an external subset (any parameter may be nil) // 4 arguments -- public, system, name, doc --> creates an external subset (any parameter may be nil) // 5 arguments -- public, system, name, doc, true --> creates an internal subset (all but last parameter may be nil) switch (argc) { case 3: case 4: case 5: { VALUE name, doc, internal; const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL; xmlDocPtr xdoc = NULL; rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal); if (external != Qnil) { Check_Type(external, T_STRING); xpublic = (const xmlChar*) StringValuePtr(external); } if (system != Qnil) { Check_Type(system, T_STRING); xsystem = (const xmlChar*) StringValuePtr(system); } if (name != Qnil) { Check_Type(name, T_STRING); xname = (const xmlChar*) StringValuePtr(name); } if (doc != Qnil) { if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse) rb_raise(rb_eTypeError, "Must pass an XML::Document object"); Data_Get_Struct(doc, xmlDoc, xdoc); } if (internal == Qnil || internal == Qfalse) xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem); else xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem); if (xdtd == NULL) rxml_raise(&xmlLastError); /* Document will free this dtd now. */ RDATA(self)->dfree = NULL; DATA_PTR(self) = xdtd; xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc); } break; case 2: rb_scan_args(argc, argv, "20", &external, &system); Check_Type(external, T_STRING); Check_Type(system, T_STRING); xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system)); if (xdtd == NULL) rxml_raise(&xmlLastError); DATA_PTR(self) = xdtd; xmlSetTreeDoc((xmlNodePtr) xdtd, NULL); break; case 1: rb_scan_args(argc, argv, "10", &dtd_string); Check_Type(dtd_string, T_STRING); /* Note that buffer is freed by xmlParserInputBufferPush*/ buffer = xmlAllocParserInputBuffer(enc); new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string)); xmlParserInputBufferPush(buffer, xmlStrlen(new_string), (const char*) new_string); xdtd = xmlIOParseDTD(NULL, buffer, enc); if (xdtd == NULL) rxml_raise(&xmlLastError); xmlFree(new_string); DATA_PTR(self) = xdtd; break; default: rb_raise(rb_eArgError, "wrong number of arguments"); } return self; }