Esempio n. 1
0
bool c_XMLReader::t_movetoattribute(const String& name) {
  if (name.empty()) {
    raise_warning("Attribute Name is required");
    return false;
  }

  if (m_ptr) {
    int ret = xmlTextReaderMoveToAttribute(m_ptr, (xmlChar *)name.data());
    if (ret == 1) {
      return true;
    }
  }
  return false;
}
Esempio n. 2
0
/* reader:move_to_attribute(name|idx) */
static int xmlreader_move_to_attribute(lua_State *L)
{
  xmlreader xr = check_xmlreader(L, 1);
  int ret;

  if (lua_type(L, 2) == LUA_TNUMBER) {
    int n = luaL_checkint(L, 2);
    ret = xmlTextReaderMoveToAttributeNo(xr, n);
  } else {
    const xmlChar *name = (xmlChar*)luaL_checkstring(L, 2);
    ret = xmlTextReaderMoveToAttribute(xr, name);
  }

  BOOL_OR_ERROR(L, ret);
}
Esempio n. 3
0
bool c_XMLReader::t_movetoattribute(CStrRef name) {
  INSTANCE_METHOD_INJECTION_BUILTIN(XMLReader, XMLReader::movetoattribute);
  if (name.empty()) {
    raise_warning("Attribute Name is required");
    return false;
  }

  if (m_ptr) {
    int ret = xmlTextReaderMoveToAttribute(m_ptr, (xmlChar *)name.data());
    if (ret == 1) {
      return true;
    }
  }
  return false;
}
Esempio n. 4
0
bool HHVM_METHOD(XMLReader, moveToAttribute,
                 const String& name) {
  auto* data = Native::data<XMLReader>(this_);
  SYNC_VM_REGS_SCOPED();
  if (name.empty()) {
    raise_warning("Attribute Name is required");
    return false;
  }

  if (data->m_ptr) {
    int ret = xmlTextReaderMoveToAttribute(data->m_ptr, (xmlChar *)name.data());
    if (ret == 1) {
      return true;
    }
  }
  return false;
}
Esempio n. 5
0
/*
 * call-seq:
 *   reader.move_to_attribute(val) -> code
 *
 * Move the position of the current instance to the attribute with the
 * specified index (if +val+ is an integer) or name (if +val+ is a string)
 * relative to the containing element.
 */
static VALUE rxml_reader_move_to_attr(VALUE self, VALUE val)
{
  xmlTextReaderPtr xreader;
  int ret;

  xreader = rxml_text_reader_get(self);

  if (TYPE(val) == T_FIXNUM)
  {
    ret = xmlTextReaderMoveToAttributeNo(xreader, FIX2INT(val));
  }
  else
  {
    ret = xmlTextReaderMoveToAttribute(xreader,
        (const xmlChar *) StringValueCStr(val));
  }

  return INT2FIX(ret);
}
Esempio n. 6
0
const char *xccdf_attribute_get(xmlTextReaderPtr reader, xccdf_attribute_t attr)
{
	bool found = false;
	const struct xccdf_attribute_spec *mapptr = XCCDF_ATTRIBUTE_MAP;

	while (mapptr->id) {
		if (attr == mapptr->id) {
			found = true;
			break;
		}
		++mapptr;
	}

	if (!found)
		return NULL;

	if (xmlTextReaderMoveToAttribute(reader, BAD_CAST mapptr->name) != 1)
		return NULL;
	// do not check the XML namespace for now... maybe a libxml bug?
	// if (strcmp((const char*)xmlTextReaderConstNamespaceUri(reader), BAD_CAST mapptr->ns) != 0) return NULL;

	return (const char *)xmlTextReaderConstValue(reader);
}
Esempio n. 7
0
    /** Parse the 'detailed' Anime fields from HTML
     *
     * 
     */
    std::shared_ptr<Anime> AnimeSerializer::deserialize_details(const std::string& xml) const
    {
        typedef std::unique_ptr<xmlChar, XmlCharDeleter> xmlStringUPtr;
        auto res = std::make_shared<Anime>();
		std::unique_ptr<char[]> cstr(new char[xml.size()]);
		std::memcpy(cstr.get(), xml.c_str(), xml.size());
        std::unique_ptr<xmlDoc, XmlDocDeleter> doc(htmlReadMemory(cstr.get(), xml.size(), "http://myanimelist.net/",
                                                                   nullptr, HTML_PARSE_RECOVER
                                                                   | HTML_PARSE_NOERROR 
                                                                   | HTML_PARSE_NOWARNING
                                                                   | HTML_PARSE_NONET));
		std::unique_ptr<xmlTextReader, xmlTextReaderDeleter> reader(xmlReaderWalker(doc.get()));
		if (!reader) {
			std::cerr << "Error: Couldn't create XML reader" << std::endl;
            std::cerr << "XML follows: " << xml << std::endl;
			return nullptr;
		}
        
        enum { PRIORITY, STORAGE, REWATCHVALUE, DISCUSS, SELECTOR_NONE } selector = SELECTOR_NONE;
        enum { TAGS, COMMENTS, NONE } textarea = NONE;
        std::string textbuf;
        int ret = 1;
		for( ret = xmlTextReaderRead(reader.get()); ret == 1;
		     ret = xmlTextReaderRead(reader.get()) ) {
			const std::string name  = xmlchar_to_str(xmlTextReaderConstName (reader.get()));

            if (name == "input") {
                xmlStringUPtr type(xmlTextReaderGetAttribute(reader.get(), "type"_xml));
                xmlStringUPtr attr_name(xmlTextReaderGetAttribute(reader.get(), "name"_xml));
                xmlStringUPtr attr_value(xmlTextReaderGetAttribute(reader.get(), "value"_xml));
                if (type) {
                    if (xmlStrEqual(type.get(), "text"_xml) || xmlStrEqual(type.get(), "checkbox"_xml)) {
                        if (xmlStrEqual(attr_name.get(), "fansub_group"_xml))
                            res->set_fansub_group(xmlchar_to_str(attr_value.get()));
                        else if (xmlStrEqual(attr_name.get(), "list_downloaded_eps"_xml))
                            res->set_downloaded_items(xmlchar_to_str(attr_value.get()));
                        else if (xmlStrEqual(attr_name.get(), "list_times_watched"_xml))
                            res->set_times_consumed(xmlchar_to_str(attr_value.get()));
                        else if (xmlStrEqual(attr_name.get(), "storageVal"_xml))
                            res->set_storage_value(xmlchar_to_str(attr_value.get()));
                    }
                }
            } else if (name == "textarea" && xmlTextReaderNodeType(reader.get()) == XML_READER_TYPE_ELEMENT) {
                xmlStringUPtr attr_name(xmlTextReaderGetAttribute(reader.get(), "name"_xml));
                if (xmlStrEqual(attr_name.get(), "tags"_xml)) textarea = TAGS;
                else if (xmlStrEqual(attr_name.get(), "list_comments"_xml)) textarea = COMMENTS;
                else textarea = NONE;
                textbuf.clear();
            } else if (name == "textarea" && xmlTextReaderNodeType(reader.get()) == XML_READER_TYPE_END_ELEMENT) {
                if (textarea != NONE) {
                    switch (textarea) {
                        case TAGS:
                            /* Not a 'detailed' field */
                            break;
                        case COMMENTS:
                            res->set_comments(std::string(textbuf));
                            break;
                        case NONE:
                        default:
                            break;
                    }
                    textarea = NONE;
                }
            } else if (name == "#text" && textarea != NONE) {
                textbuf.append(xmlchar_to_str(xmlTextReaderConstValue(reader.get())));
            } else if (name == "select" && xmlTextReaderNodeType(reader.get()) == XML_READER_TYPE_ELEMENT) {
                xmlStringUPtr attr_name(xmlTextReaderGetAttribute(reader.get(), "name"_xml));
                if (xmlStrEqual(attr_name.get(), "priority"_xml)) selector = PRIORITY;
                if (xmlStrEqual(attr_name.get(), "storage"_xml)) selector = STORAGE;
                if (xmlStrEqual(attr_name.get(), "list_rewatch_value"_xml)) selector = REWATCHVALUE;
                if (xmlStrEqual(attr_name.get(), "discuss"_xml)) selector = DISCUSS;                
            } else if (name == "select" && xmlTextReaderNodeType(reader.get()) == XML_READER_TYPE_END_ELEMENT)  {
                selector = SELECTOR_NONE;
            } else if (name == "option" && xmlTextReaderNodeType(reader.get()) == XML_READER_TYPE_ELEMENT) {
                xmlStringUPtr value(xmlTextReaderGetAttribute(reader.get(), "value"_xml));
                if (xmlTextReaderMoveToAttribute(reader.get(), "selected"_xml) == 1) {
                    switch (selector) {
                        case PRIORITY:
                            res->set_priority(xmlchar_to_str(value.get()));
                            break;
                        case STORAGE:
                            res->set_storage_value(xmlchar_to_str(value.get()));
                            break;
                        case REWATCHVALUE:
                            res->set_reconsume_value(xmlchar_to_str(value.get()));
                            break;
                        case DISCUSS:
                            res->set_enable_discussion(xmlchar_to_str(value.get()));
                            break;
                        case SELECTOR_NONE:
                        default:
                            break;
                    }
                }
            }
        }

        if (ret != 0) return nullptr; // Some sort of parsing error
        
        return res;
    }
Esempio n. 8
0
bool sc_xmltv_get_reader_property_value(xmlTextReaderPtr reader, const char *prop, char **dst) {
    if (xmlTextReaderMoveToAttribute(reader, (const xmlChar *) prop) == 1) {
        return sc_xmltv_get_reader_value(reader, dst);
    }
    return false;
}
Esempio n. 9
0
//Parse ac data from conf.xml
void parse_ac_data (char *PprzFolder) {
  xmlTextReaderPtr reader;
  int ret;

  //Create full file path
  char xmlFileName[BUFLEN];
  strcpy(xmlFileName, PprzFolder);
  strcat(xmlFileName, "/conf/conf.xml");

  reader = xmlReaderForFile(xmlFileName, NULL, XML_PARSE_NOWARNING | XML_PARSE_NOERROR); /* Dont validate with the DTD */

  xmlChar *AcName, *AcInd, *FpPath, *AcColor, *name, *AfPath;
  if (reader != NULL) {
    ret = xmlTextReaderRead(reader);
    int AcId;

    while (ret == 1) {
      name = xmlTextReaderName(reader);
      if (name == NULL) {
        name = xmlStrdup(BAD_CAST "--");
      }
      //read waypoint names

      if (xmlStrEqual(name, (const xmlChar *)"aircraft")) {

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"ac_id");
        AcInd = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"name");
        AcName = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"airframe");
        AfPath = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"flight_plan");
        FpPath = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"gui_color");
        AcColor = xmlTextReaderValue(reader);

        //Get Device Id
        AcId = atoi(((char *) AcInd));

        //Save Device Name
        strcpy(DevNames[AcId].name, ((char *) AcName));

        //Save color
        strcpy(DevNames[AcId].color, (char *) AcColor);

        //Save Flight Plan Path
        strcpy(DevNames[AcId].flight_plan_path, "/conf/");
        strcat(DevNames[AcId].flight_plan_path , (char *) FpPath);

        //Save airframe  Path
        strcpy(DevNames[AcId].airframe_path, "/conf/");
        strcat(DevNames[AcId].airframe_path , (char *) AfPath);

        //Save Settings Path
        sprintf(DevNames[AcId].settings_path, "/var/aircrafts/%s/settings.xml", (char *) AcName);

        //parse flight plan file for waypoint and block names
        char FlightPlanPath[BUFLEN];
        strcpy(FlightPlanPath, PprzFolder);
        strcat(FlightPlanPath, DevNames[AcId].flight_plan_path);
        parse_ac_fp(AcId, FlightPlanPath);

        //parse airframe file
        char AirframePath[BUFLEN];
        strcpy(AirframePath, PprzFolder);
        strcat(AirframePath, DevNames[AcId].airframe_path);
        parse_ac_af(AcId, AirframePath);

        //parse dl_settings for launch & kill throttle
        char SettingsPath[BUFLEN];
        strcpy(SettingsPath, PprzFolder);
        strcat(SettingsPath, DevNames[AcId].settings_path);
        parse_dl_settings(AcId, SettingsPath);
      }

      ret = xmlTextReaderRead(reader);
    }

    xmlFreeTextReader(reader);
    if (ret != 0) {
      if (verbose) {
        printf("App Server: failed to parse %s\n", xmlFileName);
        fflush(stdout);
      }
    }
  }
  else{
    if (verbose) {
      printf("App Server: Unable to open %s\n", xmlFileName);
      fflush(stdout);
    }
  }

  return;
} // end of XMLParseDoc function