static xmlNodePtr
make_conf_path(char *path) {
  xmlNodePtr start, tmp;
  char fullpath[1024], *tok, *brk;
  if(!path || strlen(path) < 1) return NULL;
  snprintf(fullpath, sizeof(fullpath), "%s", path+1);
  fullpath[strlen(fullpath)-1] = '\0';
  start = noit_conf_get_section(NULL, "/noit/filtersets");
  if(!start) return NULL;
  for (tok = strtok_r(fullpath, "/", &brk);
       tok;
       tok = strtok_r(NULL, "/", &brk)) {
    if(!xmlValidateNameValue((xmlChar *)tok)) return NULL;
    if(!strcmp(tok, "filterset")) return NULL;
    for (tmp = start->children; tmp; tmp = tmp->next) {
      if(!strcmp((char *)tmp->name, tok)) break;
    }
    if(!tmp) {
      tmp = xmlNewNode(NULL, (xmlChar *)tok);
      xmlAddChild(start, tmp);
      CONF_DIRTY(tmp);
    }
    start = tmp;
  }
  return start;
}
Example #2
0
ReturnCode genericAddTextAttribute(xmlDocPtr xmlDocument, const char* elementPath,
                                   const char* attributeName, const char* attributeValue)
{
  ReturnCode error = -1;
  xmlXPathObjectPtr xpathObject = NULL;
  xmlNodePtr parent = NULL;
  xmlAttrPtr attributePtr = NULL;

  if (!attributeName) {
    printMsg(MESSAGETYPE_ERROR, "Error:  No attribute name specified.\n");
    return NO_ATTRIBUTE_NAME;
  }

  if (!xmlValidateNameValue((xmlChar*) attributeName)) {
    printMsg(MESSAGETYPE_ERROR, "Error: Invalid element name \"%s\"\n", attributeName);
    return INVALID_XML_NAME;
  }

  error = checkElement(xmlDocument, elementPath, &parent, &xpathObject);
  if (!error) {
    attributePtr = xmlSetProp(parent, (xmlChar*) attributeName, (xmlChar*) attributeValue);

    if (!attributePtr) {
      printMsg(MESSAGETYPE_ERROR,
               "Error: Failed to add attribute \"%s\" to element \"%s\".\n",
               attributeName, attributeValue);
      xmlXPathFreeObject(xpathObject);
      return FAILED;
    }
    xmlXPathFreeObject(xpathObject);
    return SUCCESS;
  }
  else {
    return error;
  }
}
Example #3
0
bool Tellico::XML::validXMLElementName(const QString& name_) {
  return xmlValidateNameValue((xmlChar *)name_.toUtf8().data());
}