/** * xmlnode_to_pv: * @node: an xmlNode* object * @do_free: do we need to free the node after the conversion * * Return value: a newly allocated SV/PV or under. */ static SV* xmlnode_to_pv(xmlNode *node, gboolean do_free) { xmlOutputBufferPtr buf; SV *pestring = NULL; if (node == NULL) { return &PL_sv_undef; } buf = xmlAllocOutputBuffer(NULL); if (buf == NULL) { pestring = &PL_sv_undef; } else { xmlNodeDumpOutput(buf, NULL, node, 0, 1, NULL); xmlOutputBufferFlush(buf); if (buf->conv == NULL) { pestring = newSVpv((char*)buf->buffer->content, 0); } else { pestring = newSVpv((char*)buf->conv->content, 0); } xmlOutputBufferClose(buf); } if (do_free) { lasso_release_xml_node(node); } return pestring; }
DocumentImpl* XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet) { // FIXME: For now we serialize and then reparse. It might be more optimal to write a DOM // converter. if (!resultDoc || !sheet) return 0; DocumentImpl* result = 0; xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(NULL); if (outputBuf) { outputBuf->context = this; outputBuf->writecallback = bufferWrite; if (xsltSaveResultTo(outputBuf, resultDoc, sheet) < 0) return 0; // There are three types of output we need to be able to deal with: // HTML (create an HTML document), XML (create an XML document), and text (wrap in a <pre> and // make an XML document). KHTMLView* view = m_sourceDocument->view(); const xmlChar* method; XSLT_GET_IMPORT_PTR(method, sheet, method); if (method == NULL && resultDoc->type == XML_HTML_DOCUMENT_NODE) method = (const xmlChar*)"html"; if (xmlStrEqual(method, (const xmlChar*)"html")) result = m_sourceDocument->implementation()->createHTMLDocument(view); else result = m_sourceDocument->implementation()->createDocument(view); result->attach(); result->setURL(m_sourceDocument->URL()); result->setBaseURL(m_sourceDocument->baseURL()); result->setDecoder(m_sourceDocument->decoder()); // FIXME: Should just be UTF-16. result->docLoader()->setShowAnimations(m_sourceDocument->docLoader()->showAnimations()); result->setTransformSourceDocument(m_sourceDocument); if (xmlStrEqual(method, (const xmlChar*)"text")) { // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing // the text. QString beforeString("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<body>\n<pre>\n<![CDATA["); QString afterString("]]>\n</pre>\n</body>\n</html>\n"); m_resultOutput = beforeString + m_resultOutput + afterString; } // Before parsing, we need to detach the old document completely and get the new document // in place. We have to do this only if we're rendering the result document. if (view) { view->clear(); view->part()->replaceDocImpl(result); } result->open(); result->determineParseMode(m_resultOutput); // Make sure we parse in the correct mode. result->write(m_resultOutput); result->finishParsing(); if (view) view->part()->checkCompleted(); else result->close(); // FIXME: Even viewless docs can load subresources. onload will fire too early. // This is probably a bug in XMLHttpRequestObjects as well. } return result; }
static xmlOutputBufferPtr libxml_create_output_buffer(const char *URI, xmlCharEncodingHandlerPtr encoder, int compression ATTRIBUTE_UNUSED) { ITRACE(1, "libxml_create_output_buffer({}, {}, {})\n", URI, (void*)encoder, compression); Trace::Indent _i; if (URI == nullptr) { return nullptr; } // PHP unescapes the URI here, but that should properly be done by the // wrapper. The wrapper should expect a valid URI, e.g. file:///foo%20bar auto stream = libxml_streams_IO_open_wrapper(URI, "wb", false); if (!stream || stream->isInvalid()) { return nullptr; } // Allocate the Output buffer front-end. xmlOutputBufferPtr ret = xmlAllocOutputBuffer(encoder); if (ret != nullptr) { ret->context = rememberStream(std::move(stream)); ret->writecallback = libxml_streams_IO_write; ret->closecallback = libxml_streams_IO_close; } return ret; }
QString XSL::process(const QString &my_xml) { QString my_xsl; /* Petr Cimprich, Sablot developer: is predefined in HTML but not in XML ... use Unicode numerical entity instead:  */ my_xsl = quote_nbsp(my_xml); xmlDocPtr doc = xmlParseMemory(my_xsl.toUtf8(), my_xsl.toUtf8().length()); if (doc == NULL){ string s; s = static_cast<string>(my_xsl.toLocal8Bit()); log(L_WARN, "Parse XML error: %s", s.c_str()); return QString::null; } const char *params[1]; params[0] = NULL; xmlDocPtr res = xsltApplyStylesheet(d->styleSheet, doc, params); if (res == NULL){ log(L_WARN, "Apply stylesheet errror"); xmlFreeDoc(doc); return QString::null; } xmlFreeDoc(doc); xmlOutputBufferPtr buf = xmlAllocOutputBuffer(NULL); xsltSaveResultTo(buf, res, d->styleSheet); xmlFreeDoc(res); QString result = QString::fromUtf8((char*)(buf->buffer->content)); xmlOutputBufferClose(buf);; return result; }
static gchar * update_apply_xslt (updateJobPtr job) { xsltStylesheetPtr xslt = NULL; xmlOutputBufferPtr buf; xmlDocPtr srcDoc = NULL, resDoc = NULL; gchar *output = NULL; g_assert (NULL != job->result); do { srcDoc = xml_parse (job->result->data, job->result->size, NULL); if (!srcDoc) { g_warning("fatal: parsing request result XML source failed (%s)!", job->request->filtercmd); break; } /* load localization stylesheet */ xslt = xsltParseStylesheetFile (job->request->filtercmd); if (!xslt) { g_warning ("fatal: could not load filter stylesheet \"%s\"!", job->request->filtercmd); break; } resDoc = xsltApplyStylesheet (xslt, srcDoc, NULL); if (!resDoc) { g_warning ("fatal: applying stylesheet \"%s\" failed!", job->request->filtercmd); break; } buf = xmlAllocOutputBuffer (NULL); if (-1 == xsltSaveResultTo (buf, resDoc, xslt)) { g_warning ("fatal: retrieving result of filter stylesheet failed (%s)!", job->request->filtercmd); break; } #ifdef LIBXML2_NEW_BUFFER if (xmlOutputBufferGetSize (buf) > 0) output = xmlCharStrdup (xmlOutputBufferGetContent (buf)); #else if (xmlBufferLength (buf->buffer) > 0) output = xmlCharStrdup (xmlBufferContent (buf->buffer)); #endif xmlOutputBufferClose (buf); } while (FALSE); if (srcDoc) xmlFreeDoc (srcDoc); if (resDoc) xmlFreeDoc (resDoc); if (xslt) xsltFreeStylesheet (xslt); return output; }
void SaveResult(xmlDocPtr doc, xsltStylesheetPtr stylesheet, TBuffer& to) { xmlOutputBufferPtr buf = xmlAllocOutputBuffer(NULL); // NULL means UTF8 xsltSaveResultTo(buf, doc, stylesheet); if (buf->conv != NULL) { to.Assign((const char*)buf->conv->content, buf->conv->use); } else { to.Assign((const char*)buf->buffer->content, buf->buffer->use); } xmlOutputBufferClose(buf); }
static VALUE rxml_node_to_s(int argc, VALUE *argv, VALUE self) { VALUE result = Qnil; VALUE options = Qnil; xmlNodePtr xnode; xmlCharEncodingHandlerPtr encodingHandler; xmlOutputBufferPtr output; int level = 0; int indent = 1; const char *xencoding = "UTF-8"; rb_scan_args(argc, argv, "01", &options); if (!NIL_P(options)) { VALUE rencoding, rindent, rlevel; Check_Type(options, T_HASH); rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding"))); rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent"))); rlevel = rb_hash_aref(options, ID2SYM(rb_intern("level"))); if (rindent == Qfalse) indent = 0; if (rlevel != Qnil) level = NUM2INT(rlevel); if (rencoding != Qnil) { xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding)); if (!xencoding) rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding)); } } encodingHandler = xmlFindCharEncodingHandler(xencoding); output = xmlAllocOutputBuffer(encodingHandler); xnode = rxml_get_xnode(self); xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, xencoding); xmlOutputBufferFlush(output); if (output->conv) result = rxml_new_cstr((const char*) output->conv->content, xencoding); else result = rxml_new_cstr((const char*) output->buffer->content, xencoding); xmlOutputBufferClose(output); return result; }
/* {{{ internalSubset string readonly=yes URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-internalSubset Since: DOM Level 2 */ int dom_documenttype_internal_subset_read(dom_object *obj, zval *retval) { xmlDtdPtr dtdptr = (xmlDtdPtr) dom_object_get_node(obj); xmlDtdPtr intsubset; if (dtdptr == NULL) { php_dom_throw_error(INVALID_STATE_ERR, 0); return FAILURE; } if (dtdptr->doc != NULL && ((intsubset = xmlGetIntSubset(dtdptr->doc)) != NULL)) { smart_str ret_buf = {0}; xmlNodePtr cur = intsubset->children; while (cur != NULL) { xmlOutputBuffer *buff = xmlAllocOutputBuffer(NULL); if (buff != NULL) { xmlNodeDumpOutput (buff, NULL, cur, 0, 0, NULL); xmlOutputBufferFlush(buff); #ifdef LIBXML2_NEW_BUFFER smart_str_appendl(&ret_buf, (const char *) xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff)); #else smart_str_appendl(&ret_buf, (char *) buff->buffer->content, buff->buffer->use); #endif (void)xmlOutputBufferClose(buff); } cur = cur->next; } if (ret_buf.s) { smart_str_0(&ret_buf); ZVAL_NEW_STR(retval, ret_buf.s); return SUCCESS; } } ZVAL_NULL(retval); return SUCCESS; }
static VALUE rxml_node_to_s(int argc, VALUE *argv, VALUE self) { VALUE options = Qnil; xmlNodePtr xnode; xmlCharEncodingHandlerPtr encodingHandler; xmlOutputBufferPtr output; int level = 0; int indent = 1; const char *encoding = "UTF-8"; rb_scan_args(argc, argv, "01", &options); if (!NIL_P(options)) { VALUE rencoding, rindent, rlevel; Check_Type(options, T_HASH); rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding"))); rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent"))); rlevel = rb_hash_aref(options, ID2SYM(rb_intern("level"))); if (rindent == Qfalse) indent = 0; if (rlevel != Qnil) level = NUM2INT(rlevel); if (rencoding != Qnil) encoding = RSTRING_PTR(rxml_input_encoding_to_s(cXMLInput, rencoding)); } encodingHandler = xmlFindCharEncodingHandler(encoding); output = xmlAllocOutputBuffer(encodingHandler); Data_Get_Struct(self, xmlNode, xnode); xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, encoding); xmlOutputBufferFlush(output); if (output->conv) return rb_str_new2((const char*) output->conv->content); else return rb_str_new2((const char*) output->buffer->content); }
int xsltSaveResultToString(xmlChar **doc_txt_ptr, int * doc_txt_len, xmlDocPtr result, xsltStylesheetPtr style) { xmlOutputBufferPtr buf; *doc_txt_ptr = NULL; *doc_txt_len = 0; if (result->children == NULL) return(0); buf = xmlAllocOutputBuffer(NULL); if (buf == NULL) return(-1); xsltSaveResultTo(buf, result, style); if (buf->conv != NULL) { *doc_txt_len = buf->conv->use; *doc_txt_ptr = xmlStrndup(buf->conv->content, *doc_txt_len); } else { *doc_txt_len = buf->buffer->use; *doc_txt_ptr = xmlStrndup(buf->buffer->content, *doc_txt_len); } (void)xmlOutputBufferClose(buf); return 0; }
static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, String& resultString) { xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0); if (!outputBuf) return false; Vector<UChar> resultVector; outputBuf->context = &resultVector; outputBuf->writecallback = writeToVector; int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet); xmlOutputBufferClose(outputBuf); if (retval < 0) return false; // Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: libxslt appends an extra line feed to the result. if (resultVector.size() > 0 && resultVector[resultVector.size() - 1] == '\n') resultVector.removeLast(); resultString = String::adopt(resultVector); return true; }
static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, String& resultString) { xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0); if (!outputBuf) return false; StringBuilder resultBuilder; outputBuf->context = &resultBuilder; outputBuf->writecallback = writeToStringBuilder; int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet); xmlOutputBufferClose(outputBuf); if (retval < 0) return false; // Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: // libxslt appends an extra line feed to the result. if (resultBuilder.length() > 0 && resultBuilder[resultBuilder.length() - 1] == '\n') resultBuilder.resize(resultBuilder.length() - 1); resultString = resultBuilder.toString(); return true; }
void goa_ews_autodiscover (GoaObject *goa_object, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GoaAccount *goa_account; GoaExchange *goa_exchange; GoaPasswordBased *goa_password; GSimpleAsyncResult *simple; AutodiscoverData *data; AutodiscoverAuthData *auth; gchar *url1; gchar *url2; xmlDoc *doc; xmlOutputBuffer *buf; gchar *email; gchar *host; gchar *password = NULL; GError *error = NULL; g_return_if_fail (GOA_IS_OBJECT (goa_object)); goa_account = goa_object_get_account (goa_object); goa_exchange = goa_object_get_exchange (goa_object); goa_password = goa_object_get_password_based (goa_object); email = goa_account_dup_presentation_identity (goa_account); host = goa_exchange_dup_host (goa_exchange); doc = ews_create_autodiscover_xml (email); buf = xmlAllocOutputBuffer (NULL); xmlNodeDumpOutput (buf, doc, xmlDocGetRootElement (doc), 0, 1, NULL); xmlOutputBufferFlush (buf); url1 = g_strdup_printf ( "https://%s/autodiscover/autodiscover.xml", host); url2 = g_strdup_printf ( "https://autodiscover.%s/autodiscover/autodiscover.xml", host); g_free (host); g_free (email); /* http://msdn.microsoft.com/en-us/library/ee332364.aspx says we are * supposed to try $domain and then autodiscover.$domain. But some * people have broken firewalls on the former which drop packets * instead of rejecting connections, and make the request take ages * to time out. So run both queries in parallel and let the fastest * (successful) one win. */ data = g_slice_new0 (AutodiscoverData); data->buf = buf; data->msgs[0] = ews_create_msg_for_url (url1, buf); data->msgs[1] = ews_create_msg_for_url (url2, buf); data->session = soup_session_async_new_with_options ( SOUP_SESSION_USE_NTLM, TRUE, SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, SOUP_SESSION_TIMEOUT, 90, SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE, NULL); if (G_IS_CANCELLABLE (cancellable)) { data->cancellable = g_object_ref (cancellable); data->cancellable_id = g_cancellable_connect ( data->cancellable, G_CALLBACK (ews_autodiscover_cancelled_cb), data, NULL); } simple = g_simple_async_result_new ( G_OBJECT (goa_object), callback, user_data, goa_ews_autodiscover); g_simple_async_result_set_check_cancellable (simple, cancellable); g_simple_async_result_set_op_res_gpointer ( simple, data, (GDestroyNotify) ews_autodiscover_data_free); goa_password_based_call_get_password_sync ( goa_password, "", &password, cancellable, &error); /* Sanity check */ g_return_if_fail ( ((password != NULL) && (error == NULL)) || ((password == NULL) && (error != NULL))); if (error == NULL) { gchar *username; username = goa_account_dup_identity (goa_account); auth = g_slice_new0 (AutodiscoverAuthData); auth->username = username; /* takes ownership */ auth->password = password; /* takes ownership */ g_signal_connect_data ( data->session, "authenticate", G_CALLBACK (ews_authenticate), auth, ews_autodiscover_auth_data_free, 0); soup_session_queue_message ( data->session, data->msgs[0], ews_autodiscover_response_cb, simple); soup_session_queue_message ( data->session, data->msgs[1], ews_autodiscover_response_cb, simple); } else { g_dbus_error_strip_remote_error (error); g_simple_async_result_take_error (simple, error); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); } g_free (url2); g_free (url1); xmlFreeDoc (doc); g_object_unref (goa_account); g_object_unref (goa_exchange); g_object_unref (goa_password); }
String::C xdoc2buf(Request& r, VXdoc& vdoc, XDocOutputOptions& oo, const String* file_spec, bool use_source_charset_to_render_and_client_charset_to_write_to_header=false) { Charset* render=0; Charset* header=0; if(use_source_charset_to_render_and_client_charset_to_write_to_header) { render=&r.charsets.source(); header=&r.charsets.client(); } else { header=render=&charsets.get(oo.encoding->change_case(r.charsets.source(), String::CC_UPPER)); } const char* render_encoding=render->NAME_CSTR(); const char* header_encoding=header->NAME_CSTR(); xmlCharEncodingHandler *renderer=xmlFindCharEncodingHandler(render_encoding); // UTF-8 renderer contains empty input/output converters, // which is wrong for xmlOutputBufferCreateIO // while zero renderer goes perfectly if(render->isUTF8()) renderer=0; xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(renderer)); xsltStylesheet_auto_ptr stylesheet(xsltNewStylesheet()); if(!stylesheet.get()) throw Exception(0, 0, "xsltNewStylesheet failed"); #define OOSTRING2STYLE(name) \ stylesheet->name=oo.name?BAD_CAST xmlMemStrdup((const char*)r.transcode(*oo.name)):0 #define OOBOOL2STYLE(name) \ if(oo.name>=0) stylesheet->name=oo.name OOSTRING2STYLE(method); OOSTRING2STYLE(encoding); OOSTRING2STYLE(mediaType); // OOSTRING2STYLE(doctypeSystem); // OOSTRING2STYLE(doctypePublic); OOBOOL2STYLE(indent); OOSTRING2STYLE(version); OOBOOL2STYLE(standalone); OOBOOL2STYLE(omitXmlDeclaration); xmlDoc& xmldoc=vdoc.get_xmldoc(); xmldoc.encoding=BAD_CAST xmlMemStrdup(render_encoding); if(header_encoding) stylesheet->encoding=BAD_CAST xmlMemStrdup(header_encoding); if(xsltSaveResultTo(outputBuffer.get(), &xmldoc, stylesheet.get())<0 || xmlHaveGenericErrors()) throw XmlException(0, r); // write out result char *gnome_str; size_t gnome_length; #ifdef LIBXML2_NEW_BUFFER if(outputBuffer->conv) { gnome_length=xmlBufUse(outputBuffer->conv); gnome_str=(char *)xmlBufContent(outputBuffer->conv); } else { gnome_length=xmlOutputBufferGetSize(&(*outputBuffer)); gnome_str=(char *)xmlOutputBufferGetContent(&(*outputBuffer)); } #else if(outputBuffer->conv) { gnome_length=outputBuffer->conv->use; gnome_str=(char *)outputBuffer->conv->content; } else { gnome_length=outputBuffer->buffer->use; gnome_str=(char *)outputBuffer->buffer->content; } #endif if(file_spec){ file_write(r.charsets, *file_spec, gnome_str, gnome_length, true/*as_text*/); return String::C(); // actually, we don't need this output at all } else return String::C(gnome_length ? pa_strdup(gnome_str, gnome_length) : 0, gnome_length); }
HRESULT node_transform_node(const xmlnode *This, IXMLDOMNode *stylesheet, BSTR *p) { #ifdef SONAME_LIBXSLT xsltStylesheetPtr xsltSS; xmlnode *sheet; if (!libxslt_handle) return E_NOTIMPL; if (!stylesheet || !p) return E_INVALIDARG; *p = NULL; sheet = get_node_obj(stylesheet); if(!sheet) return E_FAIL; xsltSS = pxsltParseStylesheetDoc(sheet->node->doc); if(xsltSS) { xmlDocPtr result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL); if(result) { const xmlChar *content; if(result->type == XML_HTML_DOCUMENT_NODE) { xmlOutputBufferPtr output = xmlAllocOutputBuffer(NULL); if (output) { htmldoc_dumpcontent(output, result->doc); content = xmlBufferContent(output->buffer); *p = bstr_from_xmlChar(content); xmlOutputBufferClose(output); } } else { xmlBufferPtr buf = xmlBufferCreate(); if (buf) { int size = xmlNodeDump(buf, NULL, (xmlNodePtr)result, 0, 0); if(size > 0) { content = xmlBufferContent(buf); *p = bstr_from_xmlChar(content); } xmlBufferFree(buf); } } xmlFreeDoc(result); } /* libxslt "helpfully" frees the XML document the stylesheet was generated from, too */ xsltSS->doc = NULL; pxsltFreeStylesheet(xsltSS); } if(!*p) *p = SysAllocStringLen(NULL, 0); return S_OK; #else FIXME("libxslt headers were not found at compile time\n"); return E_NOTIMPL; #endif }
/** * gdata_entry_new_from_xmlptr: * @doc: A xml document pointer * @ptr: A xml Node pointer **/ GDataEntry * gdata_entry_new_from_xmlptr (xmlDocPtr doc, xmlNodePtr cur) { GDataEntry *entry; GDataEntryPrivate *priv; xmlChar *value = NULL; xmlOutputBufferPtr buf; gchar *xmlString; g_return_val_if_fail(doc != NULL, NULL); g_return_val_if_fail(cur != NULL, NULL); if (xmlStrcmp(cur->name, (xmlChar *)"entry")) { return NULL; } entry = gdata_entry_new (); priv = GDATA_ENTRY_GET_PRIVATE(entry); buf = xmlAllocOutputBuffer (NULL); if (buf == NULL) { xmlString = NULL; } else { xmlNodeDumpOutput (buf, NULL, cur, 0, 1, NULL); xmlOutputBufferFlush (buf); if (buf->conv == NULL) xmlString = g_strdup ((gchar *)buf->buffer->content); else xmlString = g_strdup ((gchar *)buf->conv->content); xmlOutputBufferClose (buf); } priv->entry_xml = g_strdup (xmlString); cur = cur->xmlChildrenNode; while (cur != NULL) { if (!xmlStrcmp(cur->name, (xmlChar *)"author")) { priv->authors = g_slist_prepend(priv->authors, xmlnode_to_author(doc, cur)); } else if (!xmlStrcmp(cur->name, (xmlChar *)"link")) { priv->links = g_slist_prepend(priv->links, xmlnode_to_link(doc, cur)); } else if (!xmlStrcmp(cur->name, (xmlChar *)"category")) { priv->categories = g_slist_prepend(priv->categories, xmlnode_to_category(doc, cur)); } else if (!xmlStrcmp (cur->name, (xmlChar *)"where")) { priv->location = (gchar *)xmlGetProp (cur, (xmlChar *)"valueString"); } else if (!xmlStrcmp (cur->name, (xmlChar *)"eventStatus")) { priv->status = (gchar *)xmlGetProp (cur, (xmlChar *)"value"); } else if (!xmlStrcmp (cur->name, (xmlChar *)"visibility")) { priv->visibility = (gchar *)xmlNodeListGetString (doc, cur->xmlChildrenNode, 1); } else if (!xmlStrcmp (cur->name, (xmlChar *)"when")) { priv->start_time = (gchar *)xmlGetProp (cur, (xmlChar *)"startTime"); priv->end_time = (gchar *)xmlGetProp (cur, (xmlChar *)"endTime"); } else if (!xmlStrcmp (cur->name, (xmlChar *)"recurrence")) { priv->is_recurrent = TRUE; } else if (!xmlStrcmp (cur->name, (xmlChar *)"who")) { priv->attendees = g_slist_prepend (priv->attendees, xmlnode_to_attendee (doc, cur)); priv->has_attendees = TRUE; } else if (!xmlStrcmp (cur->name, (xmlChar *)"sendEventNotifications")) { priv->send_notification =(gchar *)xmlGetProp (cur, (xmlChar *)"value"); } else if (!xmlStrcmp (cur->name, (xmlChar *)"comments")) { /*FIXME Call _comment_to_xml_node */ } else if (!xmlStrcmp(cur->name, (xmlChar *)"email")) { priv->email_addresses = g_slist_prepend(priv->email_addresses, xmlnode_to_email_address(doc, cur)); } else if (!xmlStrcmp(cur->name, (xmlChar *)"im")) { priv->im_addresses = g_slist_prepend(priv->im_addresses, xmlnode_to_im_address(doc, cur)); } else if (!xmlStrcmp(cur->name, (xmlChar *)"organization")) { priv->organizations = g_slist_prepend(priv->organizations, xmlnode_to_organization(doc, cur)); } else if (!xmlStrcmp(cur->name, (xmlChar *)"phoneNumber")) { priv->phone_numbers = g_slist_prepend(priv->phone_numbers, xmlnode_to_phone_number(doc, cur)); } else if (!xmlStrcmp(cur->name, (xmlChar *)"postalAddress")) { priv->postal_addresses = g_slist_prepend(priv->postal_addresses, xmlnode_to_postal_address(doc, cur)); } else if (!xmlStrcmp (cur->name, (xmlChar *)"deleted")) { priv->is_deleted = TRUE; } else { value = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); g_hash_table_insert(priv->field_table, g_strdup((gchar *)cur->name), g_strdup((gchar *)value)); xmlFree(value); } cur = cur->next; } return entry; }
/** * htmlDocDumpMemory: * @cur: the document * @mem: OUT: the memory pointer * @size: OUT: the memory length * * Dump an HTML document in memory and return the xmlChar * and it's size. * It's up to the caller to free the memory. */ void htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { xmlOutputBufferPtr buf; xmlCharEncodingHandlerPtr handler = NULL; const char *encoding; xmlInitParser(); if ((mem == NULL) || (size == NULL)) return; if (cur == NULL) { *mem = NULL; *size = 0; return; } encoding = (const char *) htmlGetMetaEncoding(cur); if (encoding != NULL) { xmlCharEncoding enc; enc = xmlParseCharEncoding(encoding); if (enc != cur->charset) { if (cur->charset != XML_CHAR_ENCODING_UTF8) { /* * Not supported yet */ *mem = NULL; *size = 0; return; } handler = xmlFindCharEncodingHandler(encoding); if (handler == NULL) { *mem = NULL; *size = 0; return; } } else { handler = xmlFindCharEncodingHandler(encoding); } } /* * Fallback to HTML or ASCII when the encoding is unspecified */ if (handler == NULL) handler = xmlFindCharEncodingHandler("HTML"); if (handler == NULL) handler = xmlFindCharEncodingHandler("ascii"); buf = xmlAllocOutputBuffer(handler); if (buf == NULL) { *mem = NULL; *size = 0; return; } htmlDocContentDumpOutput(buf, cur, NULL); xmlOutputBufferFlush(buf); if (buf->conv != NULL) { *size = buf->conv->use; *mem = xmlStrndup(buf->conv->content, *size); } else { *size = buf->buffer->use; *mem = xmlStrndup(buf->buffer->content, *size); } (void)xmlOutputBufferClose(buf); }