static void writeElement(Serialization *serialization, DFNode *element, int depth) { const TagDecl *tagDecl = DFNameMapNameForTag(serialization->doc->map,element->tag); assert(tagDecl != NULL); const NamespaceDecl *nsDecl = DFNameMapNamespaceForID(serialization->doc->map,tagDecl->namespaceID); assert(nsDecl != NULL); const xmlChar *prefix = (const xmlChar *)nsDecl->prefix; const xmlChar *localName = (const xmlChar *)tagDecl->localName; if (serialization->indent && (element->parent != element->doc->docNode)) xmlTextWriterWriteRawLen(serialization->writer,INDENT,1+depth); if (serialization->html || (tagDecl->namespaceID == serialization->defaultNS)) xmlTextWriterStartElement(serialization->writer,localName); else xmlTextWriterStartElementNS(serialization->writer,prefix,localName,NULL); if ((element->parent == serialization->doc->docNode) && !serialization->html) writeNamespaceDeclarations(serialization,element); writeAttributes(serialization,element); // Check if all children are text nodes. If this is true; we should treat them as if they are a single text // node, and not do any indentation. int allChildrenText = 1; for (DFNode *child = element->first; child != NULL; child = child->next) { if (child->tag != DOM_TEXT) allChildrenText = 0; } if (allChildrenText) { int oldIndent = serialization->indent; serialization->indent = 0; for (DFNode *child = element->first; child != NULL; child = child->next) writeNode(serialization,child,depth+2); serialization->indent = oldIndent; } else { for (DFNode *child = element->first; child != NULL; child = child->next) writeNode(serialization,child,depth+2); } if (serialization->indent && (element->first != NULL) && !allChildrenText) { if ((element->first != element->last) || (element->first->tag != DOM_TEXT)) xmlTextWriterWriteRawLen(serialization->writer,INDENT,1+depth); } if (serialization->html && (element->first == NULL) && HTML_requiresCloseTag(element->tag)) { xmlTextWriterWriteString(serialization->writer,(xmlChar *)""); } xmlTextWriterEndElement(serialization->writer); }
static void writeNode(Serialization *serialization, DFNode *node, int depth) { switch (node->tag) { case DOM_DOCUMENT: { if (!serialization->html) xmlTextWriterStartDocument(serialization->writer,"1.0","UTF-8","yes"); if (serialization->html) xmlTextWriterWriteDTD(serialization->writer,(xmlChar *)"html",NULL,NULL,NULL); // xmlTextWriterWriteDTD(writer, // (xmlChar *)"html", // (xmlChar *)"-//W3C//DTD XHTML 1.0 Strict//EN", // (xmlChar *)"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", // NULL); for (DFNode *child = node->first; child != NULL; child = child->next) writeNode(serialization,child,0); xmlTextWriterEndDocument(serialization->writer); break; } case DOM_TEXT: { if (serialization->indent && ((node->prev != NULL) || (node->next != NULL))) xmlTextWriterWriteRawLen(serialization->writer,INDENT,1+depth); if (serialization->html && (node->parent != NULL) && (node->parent->tag == HTML_STYLE)) { xmlTextWriterWriteRaw(serialization->writer,(const xmlChar *)node->value); } else { xmlTextWriterWriteString(serialization->writer,(const xmlChar *)node->value); } break; } case DOM_COMMENT: { xmlTextWriterWriteComment(serialization->writer,(const xmlChar *)node->value); break; } case DOM_CDATA: { xmlTextWriterWriteCDATA(serialization->writer,(const xmlChar *)node->value); break; } case DOM_PROCESSING_INSTRUCTION: { xmlTextWriterWritePI(serialization->writer, (const xmlChar *)node->target, (const xmlChar *)node->value); break; } default: { if (node->parent == serialization->doc->docNode) writeElement(serialization,node,0); else writeElement(serialization,node,depth); break; } } }
/** * xml_writer_write_string: * @writer: A #XmlWriter * @value: a string * * Writes @string to the output */ void xml_writer_write_string (XmlWriter *writer, const gchar *value) { XmlWriterPrivate *priv; g_return_if_fail (XML_IS_WRITER (writer)); priv = writer->priv; if (priv->writer) xmlTextWriterWriteString (priv->writer, CHAR_TO_XML (value)); }
static void rdtypestat_dump(dns_rdatastatstype_t type, isc_uint64_t val, void *arg) { char typebuf[64]; const char *typestr; stats_dumparg_t *dumparg = arg; FILE *fp; #ifdef HAVE_LIBXML2 xmlTextWriterPtr writer; int xmlrc; #endif if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_OTHERTYPE) == 0) { dns_rdatatype_format(DNS_RDATASTATSTYPE_BASE(type), typebuf, sizeof(typebuf)); typestr = typebuf; } else typestr = "Others"; switch (dumparg->type) { case statsformat_file: fp = dumparg->arg; fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n", val, typestr); break; case statsformat_xml: #ifdef HAVE_LIBXML2 writer = dumparg->arg; TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "rdtype")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR typestr)); TRY0(xmlTextWriterEndElement(writer)); /* name */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counter")); TRY0(xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u", val)); TRY0(xmlTextWriterEndElement(writer)); /* counter */ TRY0(xmlTextWriterEndElement(writer)); /* rdtype */ #endif break; } return; #ifdef HAVE_LIBXML2 error: dumparg->result = ISC_R_FAILURE; return; #endif }
static void opcodestat_dump(dns_opcode_t code, isc_uint64_t val, void *arg) { FILE *fp; isc_buffer_t b; char codebuf[64]; stats_dumparg_t *dumparg = arg; #ifdef HAVE_LIBXML2 xmlTextWriterPtr writer; int xmlrc; #endif isc_buffer_init(&b, codebuf, sizeof(codebuf) - 1); dns_opcode_totext(code, &b); codebuf[isc_buffer_usedlength(&b)] = '\0'; switch (dumparg->type) { case statsformat_file: fp = dumparg->arg; fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n", val, codebuf); break; case statsformat_xml: #ifdef HAVE_LIBXML2 writer = dumparg->arg; TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "opcode")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR codebuf)); TRY0(xmlTextWriterEndElement(writer)); /* name */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counter")); TRY0(xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u", val)); TRY0(xmlTextWriterEndElement(writer)); /* counter */ TRY0(xmlTextWriterEndElement(writer)); /* opcode */ #endif break; } return; #ifdef HAVE_LIBXML2 error: dumparg->result = ISC_R_FAILURE; return; #endif }
void queryMacroList::saveList(xmlTextWriterPtr writer) { size_t i; for (i = 0; i < macros.GetCount(); i++) { xmlTextWriterStartElement(writer, XML_STR("macro")); xmlTextWriterWriteAttribute(writer, XML_STR("key"), XML_FROM_WXSTRING(macros.Item(i)->GetKey())); xmlTextWriterWriteAttribute(writer, XML_STR("name"), XML_FROM_WXSTRING(macros.Item(i)->GetName())); xmlTextWriterWriteString(writer, XML_FROM_WXSTRING(macros.Item(i)->GetQuery())); xmlTextWriterEndElement(writer); } }
static void output_drive_mappings (xmlTextWriterPtr xo, char *root) { CLEANUP_FREE_STRING_LIST char **drive_mappings = NULL; char *str; size_t i; guestfs_push_error_handler (g, NULL, NULL); drive_mappings = guestfs_inspect_get_drive_mappings (g, root); guestfs_pop_error_handler (g); if (drive_mappings == NULL) return; if (drive_mappings[0] == NULL) return; /* Sort by key. */ qsort (drive_mappings, guestfs_int_count_strings (drive_mappings) / 2, 2 * sizeof (char *), compare_keys_nocase); XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "drive_mappings")); for (i = 0; drive_mappings[i] != NULL; i += 2) { str = guestfs_canonical_device_name (g, drive_mappings[i+1]); if (!str) exit (EXIT_FAILURE); XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "drive_mapping")); XMLERROR (-1, xmlTextWriterWriteAttribute (xo, BAD_CAST "name", BAD_CAST drive_mappings[i])); XMLERROR (-1, xmlTextWriterWriteString (xo, BAD_CAST str)); XMLERROR (-1, xmlTextWriterEndElement (xo)); free (str); } XMLERROR (-1, xmlTextWriterEndElement (xo)); }
axis2_status_t AXIS2_CALL axis2_libxml2_writer_wrapper_write_characters( axiom_xml_writer_t * writer, const axutil_env_t * env, axis2_char_t * text) { axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; int status = 0; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE); writer_impl = AXIS2_INTF_TO_IMPL(writer); status = xmlTextWriterWriteString(writer_impl->xml_writer, BAD_CAST text); if(status < 0) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE); return AXIS2_FAILURE; } return AXIS2_SUCCESS; }
static void writeElement(Serialization *serialization, DFNode *element, int depth) { const TagDecl *tagDecl = DFNameMapNameForTag(serialization->doc->map,element->tag); assert(tagDecl != NULL); const NamespaceDecl *nsDecl = DFNameMapNamespaceForID(serialization->doc->map,tagDecl->namespaceID); assert(nsDecl != NULL); const xmlChar *prefix = (const xmlChar *)nsDecl->prefix; const xmlChar *localName = (const xmlChar *)tagDecl->localName; if (serialization->indent && (element->parent != element->doc->docNode)) xmlTextWriterWriteRawLen(serialization->writer,INDENT,1+depth); if (serialization->html || (tagDecl->namespaceID == serialization->defaultNS)) xmlTextWriterStartElement(serialization->writer,localName); else xmlTextWriterStartElementNS(serialization->writer,prefix,localName,NULL); if ((element->parent == serialization->doc->docNode) && !serialization->html) writeNamespaceDeclarations(serialization,element); writeAttributes(serialization,element); for (DFNode *child = element->first; child != NULL; child = child->next) writeNode(serialization,child,depth+2); if (serialization->indent && (element->first != NULL)) { if ((element->first != element->last) || (element->first->tag != DOM_TEXT)) xmlTextWriterWriteRawLen(serialization->writer,INDENT,1+depth); } if (serialization->html && (element->first == NULL) && HTML_requiresCloseTag(element->tag)) { xmlTextWriterWriteString(serialization->writer,(xmlChar *)""); } xmlTextWriterEndElement(serialization->writer); }
void queryFavouriteFolder::saveFolder(xmlTextWriterPtr writer) { size_t i; for (i = 0; i < favourites.GetCount(); i++) { if (favourites.Item(i)->GetId() == -2) { queryFavouriteFolder *subfolder = (queryFavouriteFolder *)favourites.Item(i); xmlTextWriterStartElement(writer, XML_STR("folder")); xmlTextWriterWriteAttribute(writer, XML_STR("title"), XML_FROM_WXSTRING(subfolder->title)); subfolder->saveFolder(writer); xmlTextWriterEndElement(writer); } else { xmlTextWriterStartElement(writer, XML_STR("favourite")); xmlTextWriterWriteAttribute(writer, XML_STR("title"), XML_FROM_WXSTRING(favourites.Item(i)->GetTitle())); xmlTextWriterWriteString(writer, XML_FROM_WXSTRING(favourites.Item(i)->GetContents())); xmlTextWriterEndElement(writer); } } }
void create_file(char *to, char *from, char *msg){ int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlNodePtr node, root; xmlChar *tmp; if(doc = xmlParseFile(to)){ root = xmlDocGetRootElement(doc); xmlNodePtr pNode = xmlNewNode(0, (xmlChar*)"mes"); //xmlSetProp(pNode, (const xmlChar*) "id", (const xmlChar*) "val"); xmlSetProp(pNode, (const xmlChar*) "from", (const xmlChar*) from); xmlNodeSetContent(pNode, (xmlChar*)msg); xmlAddChild(root, pNode); xmlSaveFileEnc(to, doc, MY_ENCODING); xmlFreeDoc(doc); }else{ doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); node = xmlNewDocNode(doc, NULL, BAD_CAST "inbox", NULL); xmlDocSetRootElement(doc, node); writer = xmlNewTextWriterTree(doc, node, 0); rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); rc = xmlTextWriterStartElement(writer, BAD_CAST "mes"); //rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST "1"); rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "from", BAD_CAST from); rc = xmlTextWriterEndAttribute(writer); rc = xmlTextWriterWriteString(writer, (const xmlChar*) msg); rc = xmlTextWriterEndElement(writer); rc = xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); xmlSaveFileEnc(to, doc, MY_ENCODING); xmlFreeDoc(doc); } }
int output_log_xml_process(struct event *evt, void *obj) { struct output_log_xml_priv *priv = obj; struct event_reg_info *evt_info = event_get_info(evt); xmlBufferPtr buff = xmlBufferCreate(); if (!buff) { pomlog(POMLOG_ERR "Error while creating the xml buffer"); return POM_ERR; } xmlTextWriterPtr writer = xmlNewTextWriterMemory(buff, 0); if (!writer) { pomlog(POMLOG_ERR "Error while creating the xmlTextWriter"); xmlBufferFree(buff); return POM_ERR; } // <event name="event_name"> char timestamp[21] = { 0 }; snprintf(timestamp, 20, "%"PRIu64, (uint64_t) event_get_timestamp(evt)); if (xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "event") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->name) < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "timestamp", BAD_CAST timestamp) < 0) goto err; struct data *evt_data = event_get_data(evt); int i; for (i = 0; i < evt_info->data_reg->data_count; i++) { if (evt_info->data_reg->items[i].flags & DATA_REG_FLAG_LIST) { // Got a data_list if (!evt_data[i].items) continue; // <data_list name="data_name"> if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "data_list") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->data_reg->items[i].name) < 0) goto err; // <value key="key1"> struct data_item *itm = evt_data[i].items; for (; itm; itm = itm->next) { if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t\t") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "value") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "key", BAD_CAST itm->key) < 0) goto err; char *value = ptype_print_val_alloc(itm->value, NULL); if (!value) goto err; if (xmlTextWriterWriteString(writer, BAD_CAST value) < 0) { free(value); goto err; } free(value); // </value> if (xmlTextWriterEndElement(writer) < 0) goto err; } // </data_list> if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 || xmlTextWriterEndElement(writer) < 0) goto err; } else { // Got a single data if (!data_is_set(evt_data[i])) continue; // <data name="data_name"> if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "data") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->data_reg->items[i].name) < 0) goto err; if (evt_data[i].value) { char *value = ptype_print_val_alloc(evt_data[i].value, NULL); if (!value) goto err; if (xmlTextWriterWriteString(writer, BAD_CAST value) < 0) { free(value); goto err; } free(value); } // </data> if (xmlTextWriterEndElement(writer) < 0) goto err; } } // </event> if (xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0 || xmlTextWriterEndElement(writer) < 0 || xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0) goto err; xmlFreeTextWriter(writer); if (pom_write(priv->fd, buff->content, buff->use) != POM_OK) { pomlog(POMLOG_ERR "Error while writing to the log file"); xmlBufferFree(buff); return POM_ERR; } xmlBufferFree(buff); if (priv->perf_events) registry_perf_inc(priv->perf_events, 1); return POM_OK; err: pomlog(POMLOG_ERR "An error occured while processing the event"); xmlFreeTextWriter(writer); xmlBufferFree(buff); return POM_ERR; }
void xml_data(struct writer * w, const char * data) { struct xml_writer_private * p = w->priv; if (xmlTextWriterWriteString(p->xw, BAD_CAST data) < 0 ) LLOG_WARNX("cannot add '%s' as data to element", data); }
bool XmlWriter::WriteString(StringPiece const &v_utf8) { return (xmlTextWriterWriteString(libxml_stuff->writer, (unsigned char const*)v_utf8.data()) != -1); }
void xml_writer::text(const std::string &t) { if (xmlTextWriterWriteString(pimpl->writer, BAD_CAST t.c_str()) < 0) { throw write_error("cannot write text string."); } }
void xml_data(struct writer * w, const char * data) { struct xml_writer_private * p = w->priv; if (xmlTextWriterWriteString(p->xw, BAD_CAST data) < 0 ) log_warnx("lldpctl", "cannot add '%s' as data to element", data); }
/** * Writes a Persona to XML. * * @param writer The XML writer. * @param _persona The Persona to write. * @return The total bytes written, or -1 on error; */ static int xmlTextWriterWritePersonaPersonaType(xmlTextWriterPtr writer, struct ifyouwannabecool_persona_persona *_persona) { int status, totalBytes = 0, i; xmlChar *binaryData; if (_persona->id != NULL) { status = xmlTextWriterStartElementNS(writer, NULL, BAD_CAST "id", NULL); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write start element {}id. status: %i\n", status); #endif return status; } totalBytes += status; #if DEBUG_ENUNCIATE > 1 printf("writing type {http://www.w3.org/2001/XMLSchema}string for element {}id...\n"); #endif status = xmlTextWriterWriteXsStringType(writer, (_persona->id)); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write type {http://www.w3.org/2001/XMLSchema}string for element {}id. status: %i\n", status); #endif return status; } totalBytes += status; status = xmlTextWriterEndElement(writer); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write end element {}id. status: %i\n", status); #endif return status; } totalBytes += status; } if (_persona->email != NULL) { status = xmlTextWriterStartElementNS(writer, NULL, BAD_CAST "email", NULL); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write start element {}email. status: %i\n", status); #endif return status; } totalBytes += status; #if DEBUG_ENUNCIATE > 1 printf("writing type {http://www.w3.org/2001/XMLSchema}string for element {}email...\n"); #endif status = xmlTextWriterWriteXsStringType(writer, (_persona->email)); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write type {http://www.w3.org/2001/XMLSchema}string for element {}email. status: %i\n", status); #endif return status; } totalBytes += status; status = xmlTextWriterEndElement(writer); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write end element {}email. status: %i\n", status); #endif return status; } totalBytes += status; } if (_persona->alias != NULL) { status = xmlTextWriterStartElementNS(writer, NULL, BAD_CAST "alias", NULL); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write start element {}alias. status: %i\n", status); #endif return status; } totalBytes += status; #if DEBUG_ENUNCIATE > 1 printf("writing type {http://www.w3.org/2001/XMLSchema}string for element {}alias...\n"); #endif status = xmlTextWriterWriteXsStringType(writer, (_persona->alias)); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write type {http://www.w3.org/2001/XMLSchema}string for element {}alias. status: %i\n", status); #endif return status; } totalBytes += status; status = xmlTextWriterEndElement(writer); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write end element {}alias. status: %i\n", status); #endif return status; } totalBytes += status; } if (_persona->name != NULL) { status = xmlTextWriterStartElementNS(writer, NULL, BAD_CAST "name", NULL); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write start element {}name. status: %i\n", status); #endif return status; } totalBytes += status; #if DEBUG_ENUNCIATE > 1 printf("writing type {http://api.ifyouwannabecool.com/persona}name for element {}name...\n"); #endif status = xmlTextWriterWritePersonaNameType(writer, (_persona->name)); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write type {http://api.ifyouwannabecool.com/persona}name for element {}name. status: %i\n", status); #endif return status; } totalBytes += status; status = xmlTextWriterEndElement(writer); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write end element {}name. status: %i\n", status); #endif return status; } totalBytes += status; } if (_persona->picture != NULL) { status = xmlTextWriterStartElementNS(writer, NULL, BAD_CAST "picture", NULL); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write start element {}picture. status: %i\n", status); #endif return status; } totalBytes += status; #if DEBUG_ENUNCIATE > 1 printf("writing binary data for element {}picture...\n"); #endif binaryData = _encode_base64(_persona->picture, _persona->_sizeof_picture); status = xmlTextWriterWriteString(writer, binaryData); free(binaryData); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write binary data for element {}picture. status: %i\n", status); #endif return status; } totalBytes += status; status = xmlTextWriterEndElement(writer); if (status < 0) { #if DEBUG_ENUNCIATE printf("Failed to write end element {}picture. status: %i\n", status); #endif return status; } totalBytes += status; } return totalBytes; }
void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* element ) { static daeChar atomicTypeBuf[TYPE_BUFFER_SIZE]; if (element == NULL) return; if ( attr->getCount(element) == 0 ) { //we don't have a value if its required print it empty else just skip if ( attr->getIsRequired() ) { xmlTextWriterStartAttribute( writer, (xmlChar*)(daeString)attr->getName() ); xmlTextWriterEndAttribute( writer ); } return; } else if ( attr->getCount(element) == 1 ) { //single value or an array of a single value char* elemMem = attr->get(element, 0); // !!!GAC recoded the suppression logic so you could enable suppressions individually if(!attr->getIsRequired()) { // This attribute was not required and might get suppressed int typeSize = attr->getType()->getSize(); if(attr->getDefault() != NULL) { #if 1 // The attribute has a default, convert the default to binary and suppress // output of the attribute if the value matches the default. // DISABLE THIS CODE IF YOU WANT DEFAULT VALUES TO ALWAYS EXPORT if(typeSize >= TYPE_BUFFER_SIZE) { fprintf(stderr, "daeMetaAttribute::print() - buffer too small for default value of %s in %s\n", (daeString)attr->getName(),(daeString)attr->getContainer()->getName()); fflush(stderr); return; } attr->getType()->stringToMemory((daeChar*)attr->getDefault(),atomicTypeBuf); if(memcmp(atomicTypeBuf,elemMem,typeSize) == 0) return; #endif } else { #if 1 // The attribute does not have a default, suppress it if its value is all zeros (binary) // DISABLE THIS CODE IF YOU WANT OPTIONAL ATTRIBUTES THAT HAVE A VALUE OF ZERO TO EXPORT // Disabling this code may cause some unused attributes to be exported if _isValid is not // enabled and properly used. int i; for(i=0; i<typeSize;i++) { if(elemMem[i] != 0) break; } if(i == typeSize && attr->getContainer()->getValueAttribute() != attr && attr->getType()->getTypeEnum() != daeAtomicType::BoolType && attr->getType()->getTypeEnum() != daeAtomicType::EnumType ) return; #endif } } // Convert the attribute to a string if (attr->getType()->memoryToString(elemMem, atomicTypeBuf, TYPE_BUFFER_SIZE)== false) { fprintf(stderr, "daeMetaAttribute::print() - buffer too small for %s in %s\n", (daeString)attr->getName(),(daeString)attr->getContainer()->getName()); fflush(stderr); } // Suppress attributes that convert to an empty string. if (strlen(atomicTypeBuf) == 0) return; // Is this a value attribute or something else? if (attr->getContainer()->getValueAttribute() == attr) { // Always export value attributes xmlTextWriterWriteString( writer, (xmlChar*)atomicTypeBuf); } else { // Suppress attributes not marked as containing valid values // DO NOT TURN THIS ON TILL ALL USER CODE HAS BEEN CHANGED TO SET _isValid OR // ATTRIBUTES THAT WERE CREATED/SET BY USER CODE MAY NOT EXPORT. #if 0 // NOTE: even if a value is marked REQUIRED by the schema, if _isValid isn't true it means // the value in this parameter was never set and may be garbage, so we suppress it even though it is required. // To change this add && !_isRequired to the expression below. if(!attr->getIsValid() ) return; #endif // Export the attribute name and value xmlTextWriterWriteAttribute( writer, (xmlChar*)(daeString)attr->getName(), (xmlChar*)atomicTypeBuf); } } else { if (attr->getContainer()->getValueAttribute() != attr) { xmlTextWriterStartAttribute( writer, (xmlChar*)(daeString)attr->getName() ); } for( int i = 0; i < attr->getCount(element); i++ ) { char* elemMem = attr->get(element, i); if (attr->getType()->memoryToString(elemMem, atomicTypeBuf, TYPE_BUFFER_SIZE)== false) { fprintf(stderr, "daeMetaArrayAttribute::print() - buffer too small for %s in %s\n", (daeString)attr->getName(),(daeString)attr->getContainer()->getName()); fflush(stderr); } xmlTextWriterWriteFormatString( writer, "%s ", (xmlChar*)atomicTypeBuf ); } if (attr->getContainer()->getValueAttribute() != attr) { xmlTextWriterEndAttribute( writer ); } } }
static isc_result_t dump_counters(isc_stats_t *stats, statsformat_t type, void *arg, const char *category, const char **desc, int ncounters, int *indices, isc_uint64_t *values, int options) { int i, index; isc_uint64_t value; stats_dumparg_t dumparg; FILE *fp; #ifdef HAVE_LIBXML2 xmlTextWriterPtr writer; int xmlrc; #endif #ifndef HAVE_LIBXML2 UNUSED(category); #endif dumparg.type = type; dumparg.ncounters = ncounters; dumparg.counterindices = indices; dumparg.countervalues = values; memset(values, 0, sizeof(values[0]) * ncounters); isc_stats_dump(stats, generalstat_dump, &dumparg, options); for (i = 0; i < ncounters; i++) { index = indices[i]; value = values[index]; switch (dumparg.type) { case statsformat_file: fp = arg; fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n", value, desc[index]); break; case statsformat_xml: #ifdef HAVE_LIBXML2 writer = arg; if (category != NULL) { TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR category)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR desc[index])); TRY0(xmlTextWriterEndElement(writer)); /* name */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counter")); } else { TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR desc[index])); } TRY0(xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u", value)); TRY0(xmlTextWriterEndElement(writer)); /* counter */ if (category != NULL) TRY0(xmlTextWriterEndElement(writer)); /* category */ #endif break; } } return (ISC_R_SUCCESS); #ifdef HAVE_LIBXML2 error: return (ISC_R_FAILURE); #endif }
xmlChar *get_uri(fsp_link *link, fs_rid rid) { if (cache[rid & CACHE_MASK].rid == rid) { return (xmlChar *) cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); return (xmlChar *) resource.lex; } xmlChar *get_attr(fsp_link *link, fs_rid rid) { if (attr_cache[rid & CACHE_MASK].rid == rid) { return (xmlChar *) attr_cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); memcpy(&attr_cache[rid & ATTR_CACHE_MASK], &resource, sizeof(fs_resource)); return (xmlChar *) resource.lex; } xmlChar *get_literal(fsp_link *link, fs_rid rid, fs_rid *attr) { if (cache[rid & CACHE_MASK].rid == rid) { *attr = cache[rid & CACHE_MASK].attr; return (xmlChar *) cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); *attr = resource.attr; return (xmlChar *) resource.lex; } void resolve_triples(fsp_link *link, fs_rid_vector **rids) { int quads = rids[0]->length; fs_rid_vector *todo[segments]; fs_segment segment; for (segment = 0; segment < segments; ++segment) { todo[segment] = fs_rid_vector_new(0); } for (int c = 0; c < 3; ++c) { for (int k = 0; k < quads; ++k) { const fs_rid rid = rids[c]->data[k]; if (FS_IS_BNODE(rid) || cache[rid & CACHE_MASK].rid == rid) continue; fs_rid_vector_append(todo[FS_RID_SEGMENT(rid, segments)], rid); cache[rid & CACHE_MASK].rid = rid; /* well, it will be soon */ } } int length[segments]; fs_resource *resources[segments]; for (segment = 0; segment < segments; ++segment) { length[segment] = todo[segment]->length; resources[segment] = calloc(length[segment], sizeof(fs_resource)); } fsp_resolve_all(link, todo, resources); for (segment = 0; segment < segments; ++segment) { fs_resource *res = resources[segment]; for (int k = 0; k < length[segment]; ++k) { free(cache[res[k].rid & CACHE_MASK].lex); memcpy(&cache[res[k].rid & CACHE_MASK], &res[k], sizeof(fs_resource)); } fs_rid_vector_free(todo[segment]); free(resources[segment]); } } void dump_model(fsp_link *link, fs_rid model, xmlTextWriterPtr xml) { fs_rid_vector none = { .length = 0, .size = 0, .data = 0 }; fs_rid_vector one = { .length = 1, .size = 1, .data = &model }; fs_rid_vector **results; double then; /* for time keeping */ then = fs_time(); fsp_bind_first_all(link, BIND_SPO, &one, &none, &none, &none, &results, QUAD_LIMIT); time_bind_first += (fs_time() - then); while (results != NULL) { long length = results[0]->length; if (length == 0) break; then = fs_time(); resolve_triples(link, results); time_resolving += (fs_time() - then); then = fs_time(); for (int k = 0; k < length; ++k) { xmlTextWriterStartElement(xml, (xmlChar *) "triple"); for (int r = 0; r < 3; ++r) { fs_rid rid = results[r]->data[k]; if (FS_IS_BNODE(rid)) { unsigned long long node = FS_BNODE_NUM(rid); xmlTextWriterWriteFormatElement(xml, (xmlChar *) "id", "%llu", node); } else if (FS_IS_URI(rid)) { xmlChar *uri = get_uri(link, rid); xmlTextWriterWriteElement(xml, (xmlChar *) "uri", uri); } else if (FS_IS_LITERAL(rid)) { fs_rid attr; xmlChar *lex = get_literal(link, rid, &attr); if (attr == fs_c.empty) { xmlTextWriterWriteElement(xml, (xmlChar *) "plainLiteral", lex); } else if (FS_IS_URI(attr)) { xmlChar *type = get_uri(link, attr); xmlTextWriterStartElement(xml, (xmlChar *) "typedLiteral"); xmlTextWriterWriteString(xml, (xmlChar *) lex); xmlTextWriterWriteAttribute(xml, (xmlChar *) "datatype", type); xmlTextWriterEndElement(xml); } else if (FS_IS_LITERAL(attr)) { xmlChar *lang = get_attr(link, attr); xmlTextWriterStartElement(xml, (xmlChar *) "plainLiteral"); xmlTextWriterWriteAttribute(xml, (xmlChar *) "xml:lang", lang); xmlTextWriterWriteString(xml, (xmlChar *) lex); xmlTextWriterEndElement(xml); } } } xmlTextWriterEndElement(xml); xmlTextWriterWriteString(xml, (xmlChar *) "\n"); } time_write_out += (fs_time() - then); fs_rid_vector_free(results[0]); fs_rid_vector_free(results[1]); fs_rid_vector_free(results[2]); free(results); then = fs_time(); fsp_bind_next_all(link, BIND_SPO, &results, QUAD_LIMIT); time_bind_next += (fs_time() - then); } fsp_bind_done_all(link); } void dump_trix(fsp_link *link, xmlTextWriterPtr xml) { fs_rid_vector **models; fs_rid_vector none = { .length = 0, .size = 0, .data = 0 }; fsp_bind_all(link, FS_BIND_DISTINCT | FS_BIND_MODEL | FS_BIND_BY_SUBJECT, &none, &none, &none, &none, &models); fs_rid_vector_sort(models[0]); fs_rid_vector_uniq(models[0], 1); long length = models[0]->length; for (int k = 0; k < length; ++k) { fs_rid model = models[0]->data[k]; xmlChar *model_uri = get_uri(link, model); xmlTextWriterStartElement(xml, (xmlChar *) "graph"); if (FS_IS_URI(model)) { xmlTextWriterWriteElement(xml, (xmlChar *) "uri", model_uri); } else { fs_error(LOG_WARNING, "model %lld is not a URI", model); } dump_model(link, model, xml); xmlTextWriterEndElement(xml); xmlTextWriterWriteString(xml, (xmlChar *) "\n"); printf("%5d/%ld: %4.5f %4.5f %4.5f %4.5f\n", k + 1, length, time_resolving, time_bind_first, time_bind_next, time_write_out); } } void dump_file(fsp_link *link, char *filename) { xmlTextWriterPtr xml = xmlNewTextWriterFilename(filename, TRUE); if (!xml) { fs_error(LOG_ERR, "Couldn't write output file, giving up"); exit(4); } xmlTextWriterStartDocument(xml, NULL, NULL, NULL); xmlTextWriterStartElement(xml, (xmlChar *) "TriX"); dump_trix(link, xml); xmlTextWriterEndDocument(xml); /* also closes TriX */ xmlFreeTextWriter(xml); } int main(int argc, char *argv[]) { char *password = fsp_argv_password(&argc, argv); if (argc != 3) { fprintf(stderr, "%s revision %s\n", argv[0], FS_FRONTEND_VER); fprintf(stderr, "Usage: %s <kbname> <uri>\n", argv[0]); exit(1); } fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RO); if (!link) { fs_error (LOG_ERR, "couldn't connect to ā%sā", argv[1]); exit(2); } fs_hash_init(fsp_hash_type(link)); segments = fsp_link_segments(link); dump_file(link, argv[2]); fsp_close_link(link); }
int XmlWriter::write_char_entity(gunichar ch) { Glib::ustring unistring(1, (gunichar)ch); DBG_OUT("write entity %s", unistring.c_str()); return xmlTextWriterWriteString(m_writer, (const xmlChar*)unistring.c_str()); }
int XmlWriter::write_string(const std::string & s) { return xmlTextWriterWriteString(m_writer, (const xmlChar*)s.c_str()); }
bool XmlWriter::WriteString(WStringPiece const &v) { conv_buf.Alloc(v.size() * 3); unsigned char *tail = cpcl::ConvertUTF16_UTF8(v.data(), v.size(), conv_buf.Data(), conv_buf.Size() - 1); // shrink *tail = 0; return (xmlTextWriterWriteString(libxml_stuff->writer, conv_buf.Data()) != -1); }
int write_config(void) { int rc, result = 0; char *config_name = ".internet_icon"; xmlTextWriterPtr writer; #ifdef MEMORY int fd; xmlBufferPtr buf; /* Create a new XML buffer, to which the XML document will be * written */ buf = xmlBufferCreate(); if (buf == NULL) { return 0; } /* Create a new XmlWriter for memory, with no compression. * Remark: there is no compression for this kind of xmlTextWriter */ writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { xmlBufferFree(buf); return 0; } #else // create the file writer = xmlNewTextWriterFilename(config_name, 0); if (writer == NULL) return 0; #endif // start the document rc = xmlTextWriterStartDocument(writer, NULL, NULL, NULL); if (rc < 0) goto finish; // root element rc = xmlTextWriterStartElement(writer, BAD_CAST "internet_icon"); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; ///////////////////////////////////// // timeout char *tm = mysprintf ("%d", cfg.timeout_seconds); rc = xmlTextWriterWriteElement(writer, BAD_CAST "timeout", BAD_CAST tm); free (tm); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // test_ip rc = xmlTextWriterWriteElement(writer, BAD_CAST "test_ip", BAD_CAST cfg.test_ip); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // the port char *port = mysprintf ("%d", cfg.test_port); rc = xmlTextWriterWriteElement(writer, BAD_CAST "test_port", BAD_CAST port); free (port); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // operating mode rc = xmlTextWriterWriteElement(writer, BAD_CAST "opmode", BAD_CAST flag_value[cfg.op_mode]); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // wan ip page rc = xmlTextWriterWriteElement(writer, BAD_CAST "wan_ip_page", BAD_CAST cfg.wanip_page); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // wan ip page rc = xmlTextWriterWriteElement(writer, BAD_CAST "user_agent", BAD_CAST cfg.user_agent); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n"); if (rc < 0) goto finish; /* Close the start element. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) goto finish; ///////////////////////////////////// /* Close all. */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) goto finish; #ifdef MEMORY xmlFreeTextWriter(writer); writer = NULL; remove(config_name); fd = open(config_name, O_CREAT | O_RDWR | O_TRUNC, 0600); if (fd < 0) goto finish; write(fd, (const void *) buf->content, strlen((const char *)buf->content)); close(fd); #endif result = 1; finish: if (writer) xmlFreeTextWriter(writer); #ifdef MEMORY xmlBufferFree(buf); #endif return result; }
static isc_result_t generatexml(ns_server_t *server, int *buflen, xmlChar **buf) { char boottime[sizeof "yyyy-mm-ddThh:mm:ssZ"]; char nowstr[sizeof "yyyy-mm-ddThh:mm:ssZ"]; isc_time_t now; xmlTextWriterPtr writer = NULL; xmlDocPtr doc = NULL; int xmlrc; dns_view_t *view; stats_dumparg_t dumparg; dns_stats_t *cachestats; isc_uint64_t nsstat_values[dns_nsstatscounter_max]; isc_uint64_t resstat_values[dns_resstatscounter_max]; isc_uint64_t zonestat_values[dns_zonestatscounter_max]; isc_uint64_t sockstat_values[isc_sockstatscounter_max]; isc_result_t result; isc_time_now(&now); isc_time_formatISO8601(&ns_g_boottime, boottime, sizeof boottime); isc_time_formatISO8601(&now, nowstr, sizeof nowstr); writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) goto error; TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL)); TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet", ISC_XMLCHAR "type=\"text/xsl\" href=\"/bind9.xsl\"")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "isc")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version", ISC_XMLCHAR "1.0")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "bind")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "statistics")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version", ISC_XMLCHAR "2.2")); /* Set common fields for statistics dump */ dumparg.type = statsformat_xml; dumparg.arg = writer; /* * Start by rendering the views we know of here. For each view we * know of, call its rendering function. */ view = ISC_LIST_HEAD(server->viewlist); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "views")); while (view != NULL) { TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "view")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR view->name)); TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "zones")); result = dns_zt_apply(view->zonetable, ISC_TRUE, zone_xmlrender, writer); if (result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); if (view->resquerystats != NULL) { dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(view->resquerystats, rdtypestat_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; } if (view->resstats != NULL) { result = dump_counters(view->resstats, statsformat_xml, writer, "resstat", resstats_xmldesc, dns_resstatscounter_max, resstats_index, resstat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; } cachestats = dns_db_getrrsetstats(view->cachedb); if (cachestats != NULL) { TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "cache")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "name", ISC_XMLCHAR dns_cache_getname(view->cache))); dumparg.result = ISC_R_SUCCESS; dns_rdatasetstats_dump(cachestats, rdatasetstats_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* cache */ } TRY0(xmlTextWriterEndElement(writer)); /* view */ view = ISC_LIST_NEXT(view, link); } TRY0(xmlTextWriterEndElement(writer)); /* views */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socketmgr")); isc_socketmgr_renderxml(ns_g_socketmgr, writer); TRY0(xmlTextWriterEndElement(writer)); /* socketmgr */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "taskmgr")); isc_taskmgr_renderxml(ns_g_taskmgr, writer); TRY0(xmlTextWriterEndElement(writer)); /* taskmgr */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "server")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "boot-time")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR boottime)); TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "current-time")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR nowstr)); TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "requests")); dumparg.result = ISC_R_SUCCESS; dns_opcodestats_dump(server->opcodestats, opcodestat_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* requests */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "queries-in")); dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(server->rcvquerystats, rdtypestat_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* queries-in */ result = dump_counters(server->nsstats, statsformat_xml, writer, "nsstat", nsstats_xmldesc, dns_nsstatscounter_max, nsstats_index, nsstat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; result = dump_counters(server->zonestats, statsformat_xml, writer, "zonestat", zonestats_xmldesc, dns_zonestatscounter_max, zonestats_index, zonestat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; /* * Most of the common resolver statistics entries are 0, so we don't * use the verbose dump here. */ result = dump_counters(server->resolverstats, statsformat_xml, writer, "resstat", resstats_xmldesc, dns_resstatscounter_max, resstats_index, resstat_values, 0); if (result != ISC_R_SUCCESS) goto error; result = dump_counters(server->sockstats, statsformat_xml, writer, "sockstat", sockstats_xmldesc, isc_sockstatscounter_max, sockstats_index, sockstat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* server */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "memory")); isc_mem_renderxml(writer); TRY0(xmlTextWriterEndElement(writer)); /* memory */ TRY0(xmlTextWriterEndElement(writer)); /* statistics */ TRY0(xmlTextWriterEndElement(writer)); /* bind */ TRY0(xmlTextWriterEndElement(writer)); /* isc */ TRY0(xmlTextWriterEndDocument(writer)); xmlFreeTextWriter(writer); xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 1); xmlFreeDoc(doc); return (ISC_R_SUCCESS); error: if (writer != NULL) xmlFreeTextWriter(writer); if (doc != NULL) xmlFreeDoc(doc); return (ISC_R_FAILURE); }
void isc_taskmgr_renderxml(isc_taskmgr_t *mgr, xmlTextWriterPtr writer) { isc_task_t *task; LOCK(&mgr->lock); /* * Write out the thread-model, and some details about each depending * on which type is enabled. */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "thread-model"); #ifdef ISC_PLATFORM_USETHREADS xmlTextWriterStartElement(writer, ISC_XMLCHAR "type"); xmlTextWriterWriteString(writer, ISC_XMLCHAR "threaded"); xmlTextWriterEndElement(writer); /* type */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "worker-threads"); xmlTextWriterWriteFormatString(writer, "%d", mgr->workers); xmlTextWriterEndElement(writer); /* worker-threads */ #else /* ISC_PLATFORM_USETHREADS */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "type"); xmlTextWriterWriteString(writer, ISC_XMLCHAR "non-threaded"); xmlTextWriterEndElement(writer); /* type */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"); xmlTextWriterWriteFormatString(writer, "%d", mgr->refs); xmlTextWriterEndElement(writer); /* references */ #endif /* ISC_PLATFORM_USETHREADS */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "default-quantum"); xmlTextWriterWriteFormatString(writer, "%d", mgr->default_quantum); xmlTextWriterEndElement(writer); /* default-quantum */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-running"); xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_running); xmlTextWriterEndElement(writer); /* tasks-running */ xmlTextWriterEndElement(writer); /* thread-model */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks"); task = ISC_LIST_HEAD(mgr->tasks); while (task != NULL) { LOCK(&task->lock); xmlTextWriterStartElement(writer, ISC_XMLCHAR "task"); if (task->name[0] != 0) { xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"); xmlTextWriterWriteFormatString(writer, "%s", task->name); xmlTextWriterEndElement(writer); /* name */ } xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"); xmlTextWriterWriteFormatString(writer, "%d", task->references); xmlTextWriterEndElement(writer); /* references */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"); xmlTextWriterWriteFormatString(writer, "%p", task); xmlTextWriterEndElement(writer); /* id */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "state"); xmlTextWriterWriteFormatString(writer, "%s", statenames[task->state]); xmlTextWriterEndElement(writer); /* state */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "quantum"); xmlTextWriterWriteFormatString(writer, "%d", task->quantum); xmlTextWriterEndElement(writer); /* quantum */ xmlTextWriterEndElement(writer); UNLOCK(&task->lock); task = ISC_LIST_NEXT(task, link); } xmlTextWriterEndElement(writer); /* tasks */ UNLOCK(&mgr->lock); }
static void generatexml(ns_server_t *server, int *buflen, xmlChar **buf) { char boottime[sizeof "yyyy-mm-ddThh:mm:ssZ"]; char nowstr[sizeof "yyyy-mm-ddThh:mm:ssZ"]; isc_time_t now; xmlTextWriterPtr writer; xmlDocPtr doc; int xmlrc; dns_view_t *view; stats_dumparg_t dumparg; dns_stats_t *cachestats; isc_time_now(&now); isc_time_formatISO8601(&ns_g_boottime, boottime, sizeof boottime); isc_time_formatISO8601(&now, nowstr, sizeof nowstr); writer = xmlNewTextWriterDoc(&doc, 0); TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL)); TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet", ISC_XMLCHAR "type=\"text/xsl\" href=\"/bind9.xsl\"")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "isc")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version", ISC_XMLCHAR "1.0")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "bind")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "statistics")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version", ISC_XMLCHAR "1.0")); /* Set common fields for statistics dump */ dumparg.type = statsformat_xml; dumparg.arg = writer; /* * Start by rendering the views we know of here. For each view we * know of, call its rendering function. */ view = ISC_LIST_HEAD(server->viewlist); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "views")); while (view != NULL) { xmlTextWriterStartElement(writer, ISC_XMLCHAR "view"); xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"); xmlTextWriterWriteString(writer, ISC_XMLCHAR view->name); xmlTextWriterEndElement(writer); xmlTextWriterStartElement(writer, ISC_XMLCHAR "zones"); dns_zt_apply(view->zonetable, ISC_FALSE, zone_xmlrender, writer); xmlTextWriterEndElement(writer); if (view->resquerystats != NULL) { dns_rdatatypestats_dump(view->resquerystats, rdtypestat_dump, &dumparg, 0); } if (view->resstats != NULL) { xmlTextWriterStartElement(writer, ISC_XMLCHAR "resstats"); dumparg.ncounters = dns_resstatscounter_max; dumparg.desc = resstats_xmldesc; /* auto-generated */ dns_generalstats_dump(view->resstats, generalstat_dump, &dumparg, DNS_STATSDUMP_VERBOSE); xmlTextWriterEndElement(writer); /* resstats */ } cachestats = dns_db_getrrsetstats(view->cachedb); if (cachestats != NULL) { xmlTextWriterStartElement(writer, ISC_XMLCHAR "cache"); dns_rdatasetstats_dump(cachestats, rdatasetstats_dump, &dumparg, 0); xmlTextWriterEndElement(writer); /* cache */ } xmlTextWriterEndElement(writer); /* view */ view = ISC_LIST_NEXT(view, link); } TRY0(xmlTextWriterEndElement(writer)); /* views */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socketmgr")); isc_socketmgr_renderxml(ns_g_socketmgr, writer); TRY0(xmlTextWriterEndElement(writer)); /* socketmgr */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "taskmgr")); isc_taskmgr_renderxml(ns_g_taskmgr, writer); TRY0(xmlTextWriterEndElement(writer)); /* taskmgr */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "server")); xmlTextWriterStartElement(writer, ISC_XMLCHAR "boot-time"); xmlTextWriterWriteString(writer, ISC_XMLCHAR boottime); xmlTextWriterEndElement(writer); xmlTextWriterStartElement(writer, ISC_XMLCHAR "current-time"); xmlTextWriterWriteString(writer, ISC_XMLCHAR nowstr); xmlTextWriterEndElement(writer); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "requests")); dns_opcodestats_dump(server->opcodestats, opcodestat_dump, &dumparg, 0); xmlTextWriterEndElement(writer); /* requests */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "queries-in")); dns_rdatatypestats_dump(server->rcvquerystats, rdtypestat_dump, &dumparg, 0); xmlTextWriterEndElement(writer); /* queries-in */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "nsstats")); dumparg.desc = nsstats_xmldesc; /* auto-generated in bind9.xsl.h */ dumparg.ncounters = dns_nsstatscounter_max; dns_generalstats_dump(server->nsstats, generalstat_dump, &dumparg, DNS_STATSDUMP_VERBOSE); xmlTextWriterEndElement(writer); /* nsstats */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "zonestats")); dumparg.desc = zonestats_xmldesc; /* auto-generated in bind9.xsl.h */ dumparg.ncounters = dns_zonestatscounter_max; dns_generalstats_dump(server->zonestats, generalstat_dump, &dumparg, DNS_STATSDUMP_VERBOSE); xmlTextWriterEndElement(writer); /* zonestats */ xmlTextWriterStartElement(writer, ISC_XMLCHAR "resstats"); dumparg.ncounters = dns_resstatscounter_max; dumparg.desc = resstats_xmldesc; dns_generalstats_dump(server->resolverstats, generalstat_dump, &dumparg, DNS_STATSDUMP_VERBOSE); xmlTextWriterEndElement(writer); /* resstats */ xmlTextWriterEndElement(writer); /* server */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "memory")); isc_mem_renderxml(writer); TRY0(xmlTextWriterEndElement(writer)); /* memory */ TRY0(xmlTextWriterEndElement(writer)); /* statistics */ TRY0(xmlTextWriterEndElement(writer)); /* bind */ TRY0(xmlTextWriterEndElement(writer)); /* isc */ TRY0(xmlTextWriterEndDocument(writer)); xmlFreeTextWriter(writer); xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 1); xmlFreeDoc(doc); }