TileMapParseStatus TileMapLayer_parse_data(xmlTextReaderPtr reader, TileMap *map, TileMapLayer *layer) { TileMapParseStatus status = TILEMAP_PARSE_OK; while (xmlTextReaderMoveToNextAttribute(reader)) { xmlChar *attrName = xmlTextReaderName(reader); xmlChar *attrVal = xmlTextReaderValue(reader); if (streq(attrName, "encoding")) { check(streq(attrVal, "base64"), "Incorrect layer data encoding"); } else if (streq(attrName, "compression")) { check(streq(attrVal, "gzip"), "Incorrect layer data compression"); } } while (xmlTextReaderRead(reader)) { xmlChar *childName = xmlTextReaderName(reader); if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL && streq(childName, "data")) { break; } else if (xmlTextReaderNodeType(reader) == XML_TEXT_NODE) { int tile_count = 0; extract_gids_from_encoded_data(xmlTextReaderValue(reader), &(layer->tile_gids), &tile_count); check(tile_count == map->rows * map->cols, "Inconsistent layer size"); layer->gid_count = tile_count; } } return status; error: return TILEMAP_PARSE_INVALID_FORMAT; }
static int parse_properties(xmlTextReaderPtr reader, tmx_property **prop_headadr) { tmx_property *res; int curr_depth; const char *name; curr_depth = xmlTextReaderDepth(reader); /* Parse each child */ do { if (xmlTextReaderRead(reader) != 1) return 0; /* error_handler has been called */ if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { name = (char*)xmlTextReaderConstName(reader); if (!strcmp(name, "property")) { if (!(res = alloc_prop())) return 0; res->next = *prop_headadr; *prop_headadr = res; if (!parse_property(reader, res)) return 0; } else { /* Unknow element, skip its tree */ if (xmlTextReaderNext(reader) != 1) return 0; } } } while (xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT || xmlTextReaderDepth(reader) != curr_depth); return 1; }
static void cxActionRootLoadCodesWithReader(cxAny pav,xmlTextReaderPtr reader) { cxActionRoot this = pav; cxReaderAttrInfo *info = cxReaderAttrInfoMake(reader, pav, pav); while(xmlTextReaderRead(reader) && !this->isError){ if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(!ELEMENT_IS_TYPE(cxActionRoot)){ continue; } cxObjectReadAttrRun(info); break; } while(xmlTextReaderRead(reader)){ CX_CONTINUE(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT); cxConstChars id = cxXMLAttr(reader, "id"); CX_CONTINUE(id == NULL); cxString code = cxXMLReaderReadOuterXml(reader); cxHashSet(this->codes, cxHashStrKey(id), code); } }
static int xmlconfig_load_node( xmlTextReaderPtr reader ) { int ret; const xmlChar *name; ret = xmlTextReaderRead( reader ); while ( ret == 1 ) { name = xmlTextReaderConstName( reader ); if ( name && (XML_READER_TYPE_END_ELEMENT != xmlTextReaderNodeType( reader )) && ( 0 == xmlStrncmp( name, (const xmlChar *)"Node", 7 ) ) ) { const xmlChar *id = xmlTextReaderGetAttribute( reader, (const xmlChar*)"id" ); const xmlChar *nname = xmlTextReaderGetAttribute( reader, (const xmlChar*)"name" ); const xmlChar *type = xmlTextReaderGetAttribute( reader, (const xmlChar*)"type" ); SYSLOG_DEBUG( "xmlconfig_load_node: Name=%s Id=%s Type=%s", nname, id, type ); ret = zw_node_set_label( atoi((const char*)id), (char *)nname ); if ( ret ) SYSLOG_DEBUG( "xmlconfig_load_node: set label for node(%d) failed %d", atoi((const char*)id), ret ); } if ( (XML_READER_TYPE_END_ELEMENT == xmlTextReaderNodeType( reader )) && (0 == xmlStrncmp(name, (const xmlChar *)"NodeConfig", 10))) break; ret = xmlTextReaderRead( reader ); } return ret; }
static char *parse_text_element(xmlTextReaderPtr reader, char *name) { char *string = NULL; __attribute__nonnull__(reader); __attribute__nonnull__(name); // parse string element attributes here (like xml:lang) while (xmlTextReaderNextNode(reader)) { if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT && !xmlStrcmp(xmlTextReaderConstLocalName(reader), BAD_CAST name)) { return string; } switch (xmlTextReaderNodeType(reader)) { case XML_READER_TYPE_TEXT: string = (char *)xmlTextReaderValue(reader); break; default: oscap_seterr(OSCAP_EFAMILY_OSCAP, "Unknown XML element in platform"); break; } } return string; }
static void processNode(xmlTextReaderPtr reader, struct osmdata_t *osmdata) { xmlChar *name; name = xmlTextReaderName(reader); if (name == NULL) name = xmlStrdup(BAD_CAST "--"); switch(xmlTextReaderNodeType(reader)) { case XML_READER_TYPE_ELEMENT: StartElement(reader, name, osmdata); if (xmlTextReaderIsEmptyElement(reader)) EndElement(name, osmdata); /* No end_element for self closing tags! */ break; case XML_READER_TYPE_END_ELEMENT: EndElement(name, osmdata); break; case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: /* Ignore */ break; default: fprintf(stderr, "Unknown node type %d\n", xmlTextReaderNodeType(reader)); break; } xmlFree(name); }
static int xmlTextReaderAdvanceToNextStartOrEndElement(xmlTextReaderPtr reader) { int status = xmlTextReaderRead(reader); while (status && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT && xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) { status = xmlTextReaderRead(reader); } return status; }
static int xmlTextReaderSkipElement(xmlTextReaderPtr reader) { int status = xmlTextReaderNext(reader); while (status && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT && xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) { status = xmlTextReaderRead(reader); } return status; }
static int openioc_parse_indicator(xmlTextReaderPtr reader, struct openioc_hash ** elems) { const xmlChar * name; int rc = CL_SUCCESS; while (1) { name = openioc_read(reader); if (name == NULL) return rc; if (xmlStrEqual(name, (const xmlChar *)"Indicator") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { rc = openioc_parse_indicator(reader, elems); if (rc != CL_SUCCESS) { cli_dbgmsg("openioc_parse: openioc_parse_indicator recursion error.\n"); break; } } else if (xmlStrEqual(name, (const xmlChar *)"IndicatorItem") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { rc = openioc_parse_indicatoritem(reader, elems); if (rc != CL_SUCCESS) { break; } } else if (xmlStrEqual(name, (const xmlChar *)"Indicator") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { break; } } return rc; }
static int openioc_parse_indicatoritem(xmlTextReaderPtr reader, struct openioc_hash ** elems) { const xmlChar * name; int rc = CL_SUCCESS; int context_hash = 0; while (1) { name = openioc_read(reader); if (name == NULL) break; if (xmlStrEqual(name, (const xmlChar *)"Context") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { context_hash = openioc_is_context_hash(reader); } else if (xmlStrEqual(name, (const xmlChar *)"Content") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { rc = openioc_parse_content(reader, elems, context_hash); if (rc != CL_SUCCESS) { break; } } else if (xmlStrEqual(name, (const xmlChar *)"IndicatorItem") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { break; } } return rc; }
static int xmlconfig_load_timer( xmlTextReaderPtr reader ) { int ret; const xmlChar *name; ret = xmlTextReaderRead( reader ); while ( ret == 1 ) { name = xmlTextReaderConstName( reader ); if ( name && (XML_READER_TYPE_END_ELEMENT != xmlTextReaderNodeType( reader )) && ( 0 == xmlStrncmp( name, (const xmlChar *)"Timer", 7 ) ) ) { const xmlChar *nodeid = xmlTextReaderGetAttribute( reader, (const xmlChar*)"node" ); const xmlChar *tname = xmlTextReaderGetAttribute( reader, (const xmlChar*)"name" ); const xmlChar *on = xmlTextReaderGetAttribute( reader, (const xmlChar*)"on" ); const xmlChar *off = xmlTextReaderGetAttribute( reader, (const xmlChar*)"off" ); SYSLOG_DEBUG( "xmlconfig_load_timer: Name=%s Id=%s ON=%s, OFF=%s", tname, nodeid, on, off ); } if ( (XML_READER_TYPE_END_ELEMENT == xmlTextReaderNodeType( reader )) && (0 == xmlStrncmp(name, (const xmlChar *)"TimerConfig", 11))) break; ret = xmlTextReaderRead( reader ); } return ret; }
static GWeatherTimezone * parse_timezone (GWeatherParser *parser) { GWeatherTimezone *zone = NULL; char *id = NULL; char *name = NULL; int offset = 0, dst_offset = 0; gboolean has_dst = FALSE; id = (char *) xmlTextReaderGetAttribute (parser->xml, (xmlChar *) "id"); if (!id) { xmlTextReaderNext (parser->xml); return NULL; } if (!xmlTextReaderIsEmptyElement (parser->xml)) { if (xmlTextReaderRead (parser->xml) != 1) { xmlFree (id); return NULL; } while (xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_END_ELEMENT) { if (xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_ELEMENT) { if (xmlTextReaderRead (parser->xml) != 1) break; continue; } if (!strcmp ((const char *) xmlTextReaderConstName (parser->xml), "name")) name = _gweather_parser_get_localized_value (parser); else { if (xmlTextReaderNext (parser->xml) != 1) break; } } } if (parse_tzdata (id, parser->year_start, parser->year_end, &offset, &has_dst, &dst_offset)) { zone = g_slice_new0 (GWeatherTimezone); zone->ref_count = 1; zone->id = g_strdup (id); zone->name = name; zone->offset = offset; zone->has_dst = has_dst; zone->dst_offset = dst_offset; g_hash_table_insert (parser->timezone_cache, zone->id, zone); name = NULL; } g_free (name); xmlFree (id); return zone; }
const char *oscap_element_string_get(xmlTextReaderPtr reader) { if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT || xmlTextReaderNodeType(reader) == XML_READER_TYPE_ATTRIBUTE) xmlTextReaderRead(reader); if (xmlTextReaderHasValue(reader)) return (const char *)xmlTextReaderConstValue(reader); return NULL; }
/** * processNode: * @reader: the xmlReader * * Dump information about the current node */ static void processNode(xmlTextReaderPtr reader) { int depth, type; type = xmlTextReaderNodeType(reader); if ((type == XML_ELEMENT_DECL) || (type == XML_DTD_NODE)) return; depth = xmlTextReaderDepth(reader); if ((type == XML_ELEMENT_NODE) && (depth == 2)) printf("\n"); if (2 == depth) printf("\t"); else if (3 == depth) printf("\t\t"); xmlNodePtr node = xmlTextReaderCurrentNode(reader); if (xmlTextReaderNodeType(reader) == XML_ELEMENT_NODE && node && node->properties) { xmlAttr *attribute = node->properties; while (attribute && attribute->name && attribute->children) { tag = xmlNodeListGetString(node->doc, attribute->children, 1); printf ("%s%c", tag, (depth == 2) ? '\n' : ':'); bdaddr = strtoba((const char *)tag); if (bdaddr) add_remote_device(bdaddr); attribute = attribute->next; /* tag name is what we need */ break; } } if (xmlTextReaderNodeType(reader) == XML_TEXT_NODE) { if (xmlStrstr((xmlChar *)"Service", tag)) parse_services(reader); else if (xmlStrstr((xmlChar *)"HidDescriptor", tag)) parse_hid_descriptor(reader); else if (xmlStrstr((xmlChar *)"HogpRpt", tag)) parse_hogp(reader); else if (xmlStrstr((xmlChar *)"GattAttrs", tag)) parse_gatt_attribute(reader); else if (xmlStrstr((xmlChar *)"DevClass", tag)) parse_dev_class(reader); else if (xmlStrstr((xmlChar *)"Timestamp", tag)) parse_timestamp(reader); else if (xmlStrstr((xmlChar *)"Address", tag)) parse_bdaddr(reader); else parse_text_node(reader); } }
/* xar_process_subdocument - check TOC for xml subdocument. If found, extract and scan in memory. Parameters: reader - xmlTextReaderPtr ctx - pointer to cli_ctx Returns: CL_SUCCESS - subdoc found and clean scan (or virus found and SCAN_ALL), or no subdocument other - error return code from cli_mem_scandesc() */ static int xar_scan_subdocuments(xmlTextReaderPtr reader, cli_ctx *ctx) { int rc = CL_SUCCESS, subdoc_len, fd; xmlChar * subdoc; const xmlChar *name; char * tmpname; while (xmlTextReaderRead(reader) == 1) { name = xmlTextReaderConstLocalName(reader); if (name == NULL) { cli_dbgmsg("cli_scanxar: xmlTextReaderConstLocalName() no name.\n"); rc = CL_EFORMAT; break; } if (xmlStrEqual(name, (const xmlChar *)"toc") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) return CL_SUCCESS; if (xmlStrEqual(name, (const xmlChar *)"subdoc") && xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { subdoc = xmlTextReaderReadInnerXml(reader); if (subdoc == NULL) { cli_dbgmsg("cli_scanxar: no content in subdoc element.\n"); xmlTextReaderNext(reader); continue; } subdoc_len = xmlStrlen(subdoc); cli_dbgmsg("cli_scanxar: in-memory scan of xml subdocument, len %i.\n", subdoc_len); rc = cli_mem_scandesc(subdoc, subdoc_len, ctx); if (rc == CL_VIRUS && SCAN_ALL) rc = CL_SUCCESS; /* make a file to leave if --leave-temps in effect */ if(ctx->engine->keeptmp) { if ((rc = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &fd)) != CL_SUCCESS) { cli_dbgmsg("cli_scanxar: Can't create temporary file for subdocument.\n"); } else { cli_dbgmsg("cli_scanxar: Writing subdoc to temp file %s.\n", tmpname); if (cli_writen(fd, subdoc, subdoc_len) < 0) { cli_dbgmsg("cli_scanxar: cli_writen error writing subdoc temporary file.\n"); rc = CL_EWRITE; } rc = xar_cleanup_temp_file(ctx, fd, tmpname); } } xmlFree(subdoc); if (rc != CL_SUCCESS) return rc; xmlTextReaderNext(reader); } } return rc; }
cxBool cxHashRootLoadWithReader(cxHashRoot root,xmlTextReaderPtr reader) { cxBool ret = false; while(xmlTextReaderRead(reader)){ if(root->isError){ break; } if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(ELEMENT_IS_TYPE(cxHashRoot)){ ret = true; break; } } CX_RETURN(!ret,false); cxAutoPoolPush(); while(xmlTextReaderRead(reader)){ if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(ELEMENT_IS_TYPE(cxDBEnv)){ cxHashRootReadDBEnv(root,reader); continue; } cxConstChars sid = cxXMLAttr(reader, "id"); if(sid == NULL){ CX_WARN("element %s:not set id,data not save to hash table",temp); continue; } cxAny object = NULL; if(ELEMENT_IS_TYPE(cxString)){ //cxTypesString object = cxHashRootReadString(root,reader); }else if(ELEMENT_IS_TYPE(cxHash)){ //cxTypesHash object = cxHashRootReadHash(root,reader); }else if(ELEMENT_IS_TYPE(cxArray)){ //cxTypesArray object = cxHashRootReadArray(root,reader); }else{ //cxTypesNumber object = cxHashRootReadNumber(root, temp, reader); } if(object != NULL){ cxHashSet(root->items, cxHashStrKey(sid), object); } } cxAutoPoolPop(); return ret; }
// Return value: true if next node has a sub-tree bool XMLReader::nextTypeContainsChildren(xmlTextReaderPtr &reader, const string §ion_name, string &name, string &value, bool &state_end_found, int &depth) { state_end_found = false; depth = -1; int r = 1; bool done=false, subtree_found=false; while ( (r==1) && (!state_end_found) && (!done) ) { xmlChar *localName=xmlTextReaderLocalName(reader), *localValue=NULL; depth = xmlTextReaderDepth(reader); switch ( xmlTextReaderNodeType( reader ) ) { case 15: state_end_found = (xmlStrEqual(localName, BAD_CAST section_name.c_str()) != 0); break; case 1: r = xmlTextReaderRead(reader); if (r==1) { switch ( xmlTextReaderNodeType(reader) ) { case 3: if (!xmlTextReaderHasValue(reader)) throw std::runtime_error("Huh?! Expected a value now. This xml should maybe not be valid?!"); localValue = xmlTextReaderValue(reader); name = string((char *)localName); value = string((char *)localValue); r = xmlTextReaderRead(reader); done = true; break; case 14: if (!xmlTextReaderHasValue(reader)) throw std::runtime_error("Huh?! Expected a value now. This xml should maybe not be valid?!"); localValue = xmlTextReaderValue(reader); name = string((char *)localName); value = string((char *)localValue); r = xmlTextReaderRead(reader); done = true; subtree_found = true; } } } // end of switch (type) xmlFree(localName); if (localValue!=NULL) xmlFree(localValue); if (!done) r=xmlTextReaderRead(reader); } if (r==0) state_end_found = true; // If r==0, it makes no sense to scan for more stuff... return subtree_found; }
void Table::RTTraiteTuple(int & etat, SetOfInt & tmpSetOfInt) { // on recupere le reader xmlTextReaderPtr reader = getXmlReader(); if ((xmlTextReaderNodeType(reader) == baliseOuvrante) && (xmlStrcmp(xmlTextReaderName(reader), xmlCharStrdup("Item")) == 0)) etat = RTItem; if ((xmlTextReaderNodeType(reader) == baliseFermante) && (xmlStrcmp(xmlTextReaderName(reader), xmlCharStrdup("Tuple")) == 0)) etat = RTFin; // on réinitialise le reader setXmlReader(reader); }
static response_element_t * parse_propfind_response (xmlTextReaderPtr reader) { parser_strings_t strings; response_element_t *elements; /* get internalized versions of some strings to avoid strcmp while * parsing */ strings.multistatus = xmlTextReaderConstString (reader, BAD_CAST "multistatus"); strings.dav = xmlTextReaderConstString (reader, BAD_CAST "DAV:"); strings.href = xmlTextReaderConstString (reader, BAD_CAST "href"); strings.response = xmlTextReaderConstString (reader, BAD_CAST "response"); strings.propstat = xmlTextReaderConstString (reader, BAD_CAST "propstat"); strings.prop = xmlTextReaderConstString (reader, BAD_CAST "prop"); strings.getetag = xmlTextReaderConstString (reader, BAD_CAST "getetag"); while (xmlTextReaderRead (reader) == 1 && xmlTextReaderNodeType (reader) != XML_READER_TYPE_ELEMENT) { } if (xmlTextReaderConstLocalName (reader) != strings.multistatus || xmlTextReaderConstNamespaceUri (reader) != strings.dav) { g_warning ("webdav PROPFIND result is not <DAV:multistatus>"); return NULL; } elements = NULL; /* parse all DAV:response tags */ while (xmlTextReaderRead (reader) == 1 && xmlTextReaderDepth (reader) > 0) { response_element_t *element; if (xmlTextReaderNodeType (reader) != XML_READER_TYPE_ELEMENT) continue; if (xmlTextReaderConstLocalName (reader) != strings.response || xmlTextReaderConstNamespaceUri (reader) != strings.dav) continue; element = parse_response_tag (&strings, reader); if (element == NULL) continue; element->next = elements; elements = element; } return elements; }
TileMapParseStatus TileMap_parse_map(xmlTextReaderPtr reader, Engine *engine, TileMap *map) { TileMapParseStatus status = TILEMAP_PARSE_OK; xmlChar *name = xmlTextReaderName(reader); if (!(streq(name, "map") && xmlTextReaderNodeType(reader) == XML_ELEMENT_NODE)) { return TILEMAP_PARSE_INVALID_FORMAT; } while (xmlTextReaderMoveToNextAttribute(reader)) { xmlChar *attrName = xmlTextReaderName(reader); xmlChar *attrVal = xmlTextReaderValue(reader); if (streq(attrName, "orientation")) { if (!streq(attrVal, "orthogonal")) { return TILEMAP_PARSE_INVALID_ORIENTATION; } } else if (streq(attrName, "width")) { map->cols = atoi((const char *)attrVal); } else if (streq(attrName, "height")) { map->rows = atoi((const char *)attrVal); } else if (streq(attrName, "tilewidth")) { map->tile_size.w = atoi((const char *)attrVal); } else if (streq(attrName, "tileheight")) { map->tile_size.h = atoi((const char *)attrVal); } } while (xmlTextReaderRead(reader)) { xmlChar *childName = xmlTextReaderName(reader); if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL && streq(childName, "map")) { break; } else if (streq(childName, "tileset")) { Tileset *tileset = NULL; status = TileMap_parse_tileset(reader, engine, map, &tileset); if (status != TILEMAP_PARSE_OK) return status; DArray_push(map->tilesets, tileset); } else if (streq(childName, "layer")) { TileMapLayer *layer = NULL; status = TileMap_parse_layer(reader, map, &layer); if (status != TILEMAP_PARSE_OK) return status; DArray_push(map->layers, layer); } } return status; }
void Table::ICTraiteListItems(int & etat, int & cpt) { // on recupere le reader xmlTextReaderPtr reader = getXmlReader(); // balise = <Item> if ((xmlTextReaderNodeType(reader) == baliseOuvrante) && (xmlStrcmp(xmlTextReaderName(reader), xmlCharStrdup("Item")) == 0)) etat = ICItem; if ((xmlTextReaderNodeType(reader) == baliseFermante) && (xmlStrcmp(xmlTextReaderName(reader), xmlCharStrdup("ListItems")) == 0)) etat = ICFin; // on réinitialise le reader setXmlReader(reader); }
/* * _gweather_parser_get_value: * @parser: a #GWeatherParser * * Gets the text of the element whose start tag @parser is pointing to. * Leaves @parser pointing at the next node after the element's end tag. * * Return value: the text of the current node, as a libxml-allocated * string, or %NULL if the node is empty. **/ char * _gweather_parser_get_value (GWeatherParser *parser) { char *value; /* check for null node */ if (xmlTextReaderIsEmptyElement (parser->xml)) return NULL; /* the next "node" is the text node containing the value we want to get */ if (xmlTextReaderRead (parser->xml) != 1) return NULL; value = (char *) xmlTextReaderValue (parser->xml); /* move on to the end of this node */ while (xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_END_ELEMENT) { if (xmlTextReaderRead (parser->xml) != 1) { xmlFree (value); return NULL; } } /* consume the end element too */ if (xmlTextReaderRead (parser->xml) != 1) { xmlFree (value); return NULL; } return value; }
// Return value: -1 if "state end found", otherwise depth of node int XMLReader::gobbleUntilStartElement(xmlTextReaderPtr &reader, const string &name) { bool state_begin_found = false; bool state_end_found = false; int depth = -1; int r = xmlTextReaderRead(reader); while ( (r==1) && (!state_begin_found) && (!state_end_found) ) { const int type = xmlTextReaderNodeType( reader ); depth = xmlTextReaderDepth(reader); xmlChar *localName = xmlTextReaderLocalName(reader); if (type==1) { state_begin_found = (xmlStrEqual(localName, BAD_CAST name.c_str()) != 0); if (state_begin_found) state_end_found = (xmlTextReaderIsEmptyElement(reader) != 0); } else if (type==15) { state_end_found = (xmlStrEqual(localName, BAD_CAST name.c_str()) != 0); } xmlFree(localName); r=xmlTextReaderRead(reader); } if ( r==0) state_end_found = true; // It makes no sense to have gotten to the beginning with r==0 at the same time return state_begin_found && (!state_end_found) ? depth : -1; }
static int expect_element_end ( xmlTextReaderPtr reader, char *exp_name) { xmlChar *name; /* maybe we are already on the end element ... lets see */ if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT){ xmlChar *temp; xmlChar *temp2; temp = xmlTextReaderName(reader); temp2 = (xmlChar*)sprintf_alloc("/%s", temp); name = xmlStrdup(temp2); xmlFree(temp); free(temp2); } else { name = get_xml_element(reader); } if (name == NULL) return -1; if (xmlStrcasecmp(name+1,(xmlChar *)exp_name) != 0 || name[0] != '/'){ rrd_set_error("line %d: expected </%s> end element but found <%s>", xmlTextReaderGetParserLineNumber(reader),exp_name,name); xmlFree(name); return -1; } xmlFree(name); return 0; } /* expect_element_end */
static void handle_keyword_char_class_element (ParserState *parser_state) { xmlChar *char_class; int ret, type; g_return_if_fail (parser_state->error == NULL); if (parser_state->ctx_data == NULL) return; do { ret = xmlTextReaderRead (parser_state->reader); g_assert (ret == 1); type = xmlTextReaderNodeType (parser_state->reader); } while (type != XML_READER_TYPE_TEXT && type != XML_READER_TYPE_CDATA); char_class = xmlTextReaderValue (parser_state->reader); g_free (parser_state->opening_delimiter); g_free (parser_state->closing_delimiter); parser_state->opening_delimiter = g_strdup_printf ("(?!<%s)(?=%s)", char_class, char_class); parser_state->closing_delimiter = g_strdup_printf ("(?<=%s)(?!%s)", char_class, char_class); xmlFree (char_class); }
char * xccdf_detect_version(const char* file) { const struct xccdf_version_info *ver_info; char *doc_version; xmlTextReaderPtr reader = xmlReaderForFile(file, NULL, 0); if (!reader) { oscap_seterr(OSCAP_EFAMILY_GLIBC, "Unable to open file: '%s'", file); return NULL; } xmlTextReaderSetErrorHandler(reader, &libxml_error_handler, NULL); while (xmlTextReaderRead(reader) == 1 && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT); ver_info = xccdf_detect_version_parser(reader); if(!ver_info) { xmlFreeTextReader(reader); return NULL; } doc_version = strdup(xccdf_version_info_get_version(ver_info)); xmlFreeTextReader(reader); return doc_version; }
static void gpdata_op_base_check_cb(GPDataOPBase *base, xmlTextReader *reader, GError **error) { if (reader == NULL) { } else if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) { } else { GPDataOPBasePrivate *privat = GPDATA_OP_BASE_GET_PRIVATE(base); if (privat != NULL) { // const xmlChar *a = xmlTextReaderConstValue(reader); // xmlChar *b = xmlCharStrdup(privat->xml_name); // // if (!xmlStrEqual(a,b)) // { // } // // free(b); } } }
static void process_bijiben_node (BijiLazyDeserializer *self) { int type; const xmlChar *name ; BijiLazyDeserializerPrivate *priv = self->priv; type = xmlTextReaderNodeType (priv->inner); name = xmlTextReaderConstName (priv->inner); if (name == NULL) name = BAD_CAST "(NULL)"; switch (type) { case XML_ELEMENT_NODE: process_bijiben_start_elem (self); break; case XML_ELEMENT_DECL: process_bijiben_end_elem (self); break; case XML_TEXT_NODE: case XML_DTD_NODE: process_bijiben_text_elem (self); break; } }
/** * processNode: * @reader: the xmlReader * * Dump information about the current node */ static void processNode(xmlTextReaderPtr reader) { const xmlChar *name, *value; name = xmlTextReaderConstName(reader); if (name == NULL) name = BAD_CAST "--"; value = xmlTextReaderConstValue(reader); printf("Depth: %d; Type: %d; Name: %s; %d|%d", xmlTextReaderDepth(reader), xmlTextReaderNodeType(reader), name, xmlTextReaderIsEmptyElement(reader), xmlTextReaderHasValue(reader)); if (value == NULL) printf("\n"); else { if (xmlStrlen(value) > 40) printf("|-> %.40s...\n", value); else printf(" %s\n", value); } }
static void handle_styles_element (ParserState *parser_state) { int type; const xmlChar *tag_name; g_return_if_fail (parser_state->error == NULL); while (parser_state->error == NULL) { /* FIXME: is xmlTextReaderIsValid call needed here or * error func will be called? */ xmlTextReaderRead (parser_state->reader); xmlTextReaderIsValid (parser_state->reader); if (parser_state->error != NULL) break; tag_name = xmlTextReaderConstName (parser_state->reader); type = xmlTextReaderNodeType (parser_state->reader); /* End at the closing </styles> tag */ if (tag_name && type == XML_READER_TYPE_END_ELEMENT && !xmlStrcmp (BAD_CAST "styles", tag_name)) break; /* Skip nodes that aren't <style> elements */ if (tag_name == NULL || xmlStrcmp (BAD_CAST "style", tag_name)) continue; /* Handle <style> elements */ parse_style (parser_state); } }