Esempio n. 1
0
void cpXmlCmdOutput::Context( const ::std::string& args, const ::std::string& User, const ::std::string& Host )
{
   // Start Context element
   if ( xmlTextWriterStartElement( writer, (xmlChar *) "Context" ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );

   if ( xmlTextWriterStartElement( writer, (xmlChar *) "Environment" ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );
   
   xmlChar* tmp;
   tmp = ConvertInput( (xmlChar*)args.c_str(), encoding );
   if ( xmlTextWriterWriteElement( writer, (xmlChar *) "args", tmp ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );
   if ( tmp != NULL )
      xmlFree( tmp );
   
   tmp = ConvertInput( (xmlChar*)User.c_str(), encoding );
   if ( xmlTextWriterWriteElement( writer, (xmlChar *) "User", tmp ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );
   if ( tmp != NULL )
      xmlFree( tmp );
   
   tmp = ConvertInput( (xmlChar*)Host.c_str(), encoding );
   if ( xmlTextWriterWriteElement( writer, (xmlChar *) "Host", tmp ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );
   if ( tmp != NULL )
      xmlFree( tmp );

   // </Environment>
   xmlTextWriterEndElement( writer );

   // </Context>
   xmlTextWriterEndElement( writer );
}
 int MKTask::writeData(xmlTextWriterPtr writer) {
   PeriodicTask::writeData(writer);
   xmlTextWriterWriteElement(writer, (xmlChar*) "m", STRTOXML(XmlUtils::convertToXML<int>(this->m)));
   xmlTextWriterWriteElement(writer, (xmlChar*) "k", STRTOXML(XmlUtils::convertToXML<int>(this->k)));
   xmlTextWriterWriteElement(writer, (xmlChar*) "spin", STRTOXML(XmlUtils::convertToXML<int>(this->spin)));
   return 0;
 }
Esempio n. 3
0
static void writeDNAComponent(DNAComponent* com) {
	if (!com)
		return;
	xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DNACOMPONENT));
	if (!alreadyProcessed((void *)com)) {
		markProcessed((void *)com);
		xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_ABOUT), xmlCharStrdup(getDNAComponentURI(com)));
		
		// properties
		char* data;
		data = getDNAComponentDisplayID(com);
		if (data)
			xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DISPLAYID), xmlCharStrdup(data));
		data = getDNAComponentName(com);
		if (data)
			xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_NAME), xmlCharStrdup(data));
		data = getDNAComponentDescription(com);
		if (data)
			xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DESCRIPTION), xmlCharStrdup(data));
        data = getDNAComponentType(com);
        if (data) {
            xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_TYPE));
            xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(data));
            xmlTextWriterEndElement(WRITER);
        }
        
        
		// sequence
		if (com->dnaSequence) {
			xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DNASEQUENCE_REF));
			indentMore();
			/// @todo sometimes no contents?
			writeDNASequence(com->dnaSequence);
			markProcessed(com->dnaSequence);
			indentLess();
			xmlTextWriterEndElement(WRITER);
		}
		
		// annotations
		int n;
		int num = getNumSequenceAnnotationsFor(com);
		SequenceAnnotation* ann;
		indentMore();
		if (num>0) {
			for (n=0; n<num; n++) {
				ann = getNthSequenceAnnotationFor(com, n);
				indentMore();
				xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_ANNOTATION));
				writeSequenceAnnotation(ann);
				xmlTextWriterEndElement(WRITER);
				indentLess();
			}
		}
		indentLess();
		
	} else
		xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(getDNAComponentURI(com)));
	xmlTextWriterEndElement(WRITER);
}
Esempio n. 4
0
static void
output_filesystems (xmlTextWriterPtr xo, char *root)
{
  char *str;
  size_t i;

  CLEANUP_FREE_STRING_LIST char **filesystems =
    guestfs_inspect_get_filesystems (g, root);
  if (filesystems == NULL)
    exit (EXIT_FAILURE);

  /* Sort by name so the output is stable. */
  qsort (filesystems, guestfs_int_count_strings (filesystems), sizeof (char *),
         compare_keys);

  XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "filesystems"));

  for (i = 0; filesystems[i] != NULL; ++i) {
    str = guestfs_canonical_device_name (g, filesystems[i]);
    if (!str)
      exit (EXIT_FAILURE);

    XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "filesystem"));
    XMLERROR (-1,
              xmlTextWriterWriteAttribute (xo, BAD_CAST "dev", BAD_CAST str));
    free (str);

    guestfs_push_error_handler (g, NULL, NULL);

    str = guestfs_vfs_type (g, filesystems[i]);
    if (str && str[0])
      XMLERROR (-1,
                xmlTextWriterWriteElement (xo, BAD_CAST "type",
                                           BAD_CAST str));
    free (str);

    str = guestfs_vfs_label (g, filesystems[i]);
    if (str && str[0])
      XMLERROR (-1,
                xmlTextWriterWriteElement (xo, BAD_CAST "label",
                                           BAD_CAST str));
    free (str);

    str = guestfs_vfs_uuid (g, filesystems[i]);
    if (str && str[0])
      XMLERROR (-1,
                xmlTextWriterWriteElement (xo, BAD_CAST "uuid",
                                           BAD_CAST str));
    free (str);

    guestfs_pop_error_handler (g);

    XMLERROR (-1, xmlTextWriterEndElement (xo));
  }

  XMLERROR (-1, xmlTextWriterEndElement (xo));
}
Esempio n. 5
0
//-----------------------------------------
void LegacyWriter::writeMetaNode(xmlTextWriterPtr writer) {
//-----------------------------------------
    /* Do we have to write all these nodes? */
    const bool do_lastmodifieddate = _gexf->getMetaData().getLastModifiedDate().compare("") != 0;
    const bool do_creator = _gexf->getMetaData().getCreator().compare("") != 0;
    const bool do_desc = _gexf->getMetaData().getDescription().compare("") != 0;
    const bool do_kw = _gexf->getMetaData().getKeywords().compare("") != 0;
    const bool do_meta = do_creator || do_desc || do_kw || do_lastmodifieddate;

    if( !do_meta ) return;

    /* Start an element named "meta" as child of gexf. */
    int rc = xmlTextWriterStartElement(writer, BAD_CAST "meta");
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterStartElement");
    }

    /* Add an attribute with name "lastmodifieddate" */
    if( do_lastmodifieddate ) {
        rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "lastmodifieddate", BAD_CAST _gexf->getMetaData().getLastModifiedDate().c_str());
        if (rc < 0) {
            throw FileWriterException( "Error at xmlTextWriterWriteAttribute");
        }
    }

    /* Write a text element named "creator" */
    if( do_creator ) {
        rc = xmlTextWriterWriteElement(writer, BAD_CAST "creator", BAD_CAST _gexf->getMetaData().getCreator().c_str());
        if (rc < 0) {
            throw FileWriterException("Error at xmlTextWriterWriteElement");
        }
    }

    /* Write a text element named "description" */
    if( do_desc ) {
        rc = xmlTextWriterWriteElement(writer, BAD_CAST "description", BAD_CAST _gexf->getMetaData().getDescription().c_str());
        if (rc < 0) {
            throw FileWriterException("Error at xmlTextWriterWriteElement");
        }
    }

    /* Write a text element named "keywords" */
    if( do_kw ) {
        rc = xmlTextWriterWriteElement(writer, BAD_CAST "keywords", BAD_CAST _gexf->getMetaData().getKeywords().c_str());
        if (rc < 0) {
            throw FileWriterException("Error at xmlTextWriterWriteElement");
        }
    }

    /* Close the element named meta. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterEndElement");
    }
}
Esempio n. 6
0
static void
default_fill_writer (ProponoConnection *conn, xmlTextWriter *writer)
{
  if (conn->priv->protocol)
    xmlTextWriterWriteElement (writer, "protocol", conn->priv->protocol);
  xmlTextWriterWriteElement (writer, "name", conn->priv->name);
  xmlTextWriterWriteElement (writer, "host", conn->priv->host);
  xmlTextWriterWriteElement (writer, "username", conn->priv->username ? conn->priv->username : "");
  xmlTextWriterWriteFormatElement (writer, "port", "%d", conn->priv->port);
  xmlTextWriterWriteFormatElement (writer, "fullscreen", "%d", conn->priv->fullscreen);
}
Esempio n. 7
0
static void
default_fill_writer (VinagreConnection *conn, xmlTextWriter *writer)
{
  if (conn->priv->protocol)
    xmlTextWriterWriteElement (writer, BAD_CAST "protocol", BAD_CAST conn->priv->protocol);
  xmlTextWriterWriteElement (writer, BAD_CAST "name", BAD_CAST conn->priv->name);
  xmlTextWriterWriteElement (writer, BAD_CAST "host", BAD_CAST conn->priv->host);
  xmlTextWriterWriteElement (writer, BAD_CAST "username", BAD_CAST (conn->priv->username ? conn->priv->username : ""));
  xmlTextWriterWriteFormatElement (writer, BAD_CAST "port", "%d", conn->priv->port);
  xmlTextWriterWriteFormatElement (writer, BAD_CAST "fullscreen", "%d", conn->priv->fullscreen);
  xmlTextWriterWriteFormatElement (writer, BAD_CAST "width", "%d", conn->priv->width);
  xmlTextWriterWriteFormatElement (writer, BAD_CAST "height", "%d", conn->priv->height);
}
Esempio n. 8
0
void cpXmlCmdOutput::Notes( const char* msg )
{
   xmlChar* tmp = ConvertInput( (xmlChar*)msg, encoding );
   if ( xmlTextWriterWriteElement( writer, (xmlChar *) "Notes", tmp ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );
   if ( tmp != NULL )
      xmlFree( tmp );
}
Esempio n. 9
0
static void writeSequenceAnnotation(SequenceAnnotation* ann) {
	if (!ann)
		return;
	markProcessed((void *)ann);
	xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_SEQUENCEANNOTATION));
	xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_ABOUT), xmlCharStrdup(getSequenceAnnotationURI(ann)));
	
	// precedes
	int n;
	SequenceAnnotation* ann2;
	indentMore();
	for (n=0; n<getNumPrecedes(ann); n++) {
		ann2 = getNthPrecedes(ann, n);
		xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_PRECEDES));
		xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(getSequenceAnnotationURI(ann2)));
		xmlTextWriterEndElement(WRITER);
	}
	indentLess();
	
	// start, end
	int start = getSequenceAnnotationStart(ann);
	int end   = getSequenceAnnotationEnd(ann);
	if (start>0)
		xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_BIOSTART), xmlCharStrdup(intToStr(start)));
	if (end>0)
		xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_BIOEND),  xmlCharStrdup(intToStr(end)));
	
	// subComponent
	char* uri;
	indentMore();
	if (ann->subComponent) {
		uri = getDNAComponentURI(ann->subComponent);
		xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_SUBCOMPONENT));
		if (alreadyProcessed((void *)(ann->subComponent)))
			xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(uri));
		else {
	 		indentMore();
	 		writeDNAComponent(ann->subComponent);
	 		indentLess();
	 	}
		xmlTextWriterEndElement(WRITER);
	}
	indentLess();
	
	xmlTextWriterEndElement(WRITER);
}
void CResource::SerializeToXmlFile(const nstring &file)
{
    xmlTextWriterPtr writer = NULL;

    /* Create a new XmlWriter for uri, with no compression. */
    if((writer = xmlNewTextWriterFilename(file.c_str(), 0)) == NULL)
		NOVA_EXP("CResource::SerializeToXmlFile: Error creating the xml writer", BAD_OPERATION);

	// automatic indentation for readability
	xmlTextWriterSetIndent(writer, 1);

	if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartDocument fail", BAD_OPERATION);

	if(xmlTextWriterStartElement(writer, BAD_CAST "NovaResource") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION);

    if(xmlTextWriterWriteComment(writer, BAD_CAST "Common resource header") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteComment fail", BAD_OPERATION);

	if(xmlTextWriterStartElement(writer, BAD_CAST "ResourceHeader") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION);

	if(xmlTextWriterWriteElement(writer, BAD_CAST "ResourceName", BAD_CAST mName.c_str()) < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteElement fail", BAD_OPERATION);

	if(xmlTextWriterWriteElement(writer, BAD_CAST "ResourceGroup", BAD_CAST mGroup.c_str()) < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteElement fail", BAD_OPERATION);

	if(xmlTextWriterStartElement(writer, BAD_CAST "ResourceData") < 0)
		NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION);

// Resource manager attribute
	if(xmlTextWriterWriteAttribute(writer, BAD_CAST "ResourceFactory", BAD_CAST GetCreator()->GetResourceFactoryName().c_str()) < 0)
		NOVA_EXP("CImage::SerializeToXmlFileImpl: xmlTextWriterWriteAttribute fail", BAD_OPERATION);

	SerializeToXmlFileImpl(writer);

    xmlTextWriterEndDocument(writer);
	xmlFreeTextWriter(writer);
}
Esempio n. 11
0
static void writeCollection(Collection* col) {
	if (!col)
		return;
	xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_COLLECTION));
	if (!alreadyProcessed((void *)col)) {
		markProcessed((void *)col);
		int n;
		int num;
        
        // properties
        if (getCollectionURI(col))
            xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_ABOUT),        xmlCharStrdup(getCollectionURI(col)));
        if(getCollectionDisplayID(col))
            xmlTextWriterWriteElement(WRITER,   xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DISPLAYID),   xmlCharStrdup(getCollectionDisplayID(col)));
        if (getCollectionName(col))
            xmlTextWriterWriteElement(WRITER,   xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_NAME), xmlCharStrdup(getCollectionName(col)));
        if (getCollectionDescription(col))
            xmlTextWriterWriteElement(WRITER,   xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DESCRIPTION), xmlCharStrdup(getCollectionDescription(col)));
		
		// components
		DNAComponent* com;
		num = getNumDNAComponentsIn(col);
		if (num>0) {
			indentMore();
			for (n=0; n<num; n++) {
				xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_COMPONENT));
				com = getNthDNAComponentIn(col, n);
				indentMore();
				writeDNAComponent(com);
				indentLess();
				xmlTextWriterEndElement(WRITER);
			}
			indentLess();
		}
	} else
		xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(getCollectionURI(col)));
	xmlTextWriterEndElement(WRITER);
}
Esempio n. 12
0
//----------------------------------------------------------------------------
// Writes a string keyword
//----------------------------------------------------------------------------
bool CXMLTreeNode::WritePszKeyword(const char* _pszKey, const char* _pszValue)
{
  assert(_pszKey && _pszValue && m_pWriter);

  if (_pszKey && _pszValue && m_pWriter)
  {
    // Write an element
    int rc = xmlTextWriterWriteElement(m_pWriter, BAD_CAST _pszKey, BAD_CAST _pszValue);
    if (rc >= 0)
      return true;
  }

  return false;
}
Esempio n. 13
0
//----------------------------------------------------------------------------
// Writes a float keyword
//----------------------------------------------------------------------------
bool CXMLTreeNode::WriteFloatKeyword(const char* _pszKey, float _fValue)
{
  assert(_pszKey && m_pWriter);

  if (_pszKey && m_pWriter)
  {
    char pszValue[32];
    sprintf_s(pszValue, "%f", _fValue);

    // Write an element
    int rc = xmlTextWriterWriteElement(m_pWriter, BAD_CAST _pszKey, BAD_CAST pszValue);
    if (rc >= 0)
      return true;
  }

  return false;
}
Esempio n. 14
0
//----------------------------------------------------------------------------
// Writes a boolean keyword
//----------------------------------------------------------------------------
bool CXMLTreeNode::WriteBoolKeyword(const char* _pszKey, bool _bValue)
{
  assert(_pszKey && m_pWriter);

  if (_pszKey && m_pWriter)
  {
    char pszValue[32];
    sprintf_s(pszValue, "%s", _bValue ? "true" : "false");

    // Write an element
    int rc = xmlTextWriterWriteElement(m_pWriter, BAD_CAST _pszKey, BAD_CAST pszValue);
    if (rc >= 0)
      return true;
  }

  return false;
}
Esempio n. 15
0
static void writeDNASequence(DNASequence* seq) {
	if (!seq)
		return;
	xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DNASEQUENCE));
	xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_ABOUT), xmlCharStrdup(getDNASequenceURI(seq)));

	// nucleotides
	if (!alreadyProcessed((void *)seq)) {
		char* nt = getDNASequenceNucleotides(seq);
		if (nt) {
		 	xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_NUCLEOTIDES), xmlCharStrdup(nt));
			markProcessed((void *)seq);
		}
		free(nt);
	}
	
	xmlTextWriterEndElement(WRITER);
}
Esempio n. 16
0
//-----------------------------------------
void LegacyWriter::writeAttributeDefaultNode(xmlTextWriterPtr writer, const std::string& default_value) {
//-----------------------------------------
    /* Start an element named "default" as child of attribute. */
    int rc = xmlTextWriterStartElement(writer, BAD_CAST "default");
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterStartElement");
    }

    /* Write a text element named "default" */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "default", BAD_CAST default_value.c_str());
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterWriteElement");
    }

    /* Close the element named default. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterEndElement");
    }
}
Esempio n. 17
0
bool c_XMLWriter::t_writeelement(const String& name,
                                 const String& content /* = null_string */) {
  if (xmlValidateName((xmlChar*)name.data(), 0)) {
    raise_warning("invalid element name: %s", name.data());
    return false;
  }
  int ret = -1;
  if (m_ptr) {
    if (content.isNull()) {
      ret = xmlTextWriterStartElement(m_ptr, (xmlChar*)name.data());
      if (ret == -1) return false;
      ret = xmlTextWriterEndElement(m_ptr);
      if (ret == -1) return false;
    } else {
      ret = xmlTextWriterWriteElement(m_ptr, (xmlChar*)name.data(),
                                      (xmlChar*)content.data());
    }
  }
  return ret != -1;
}
Esempio n. 18
0
//-----------------------------------------
void LegacyWriter::writeAttributeNode(xmlTextWriterPtr writer, const std::string& new_id, const std::string& title, const std::string& type, const std::string& default_value) {
//-----------------------------------------
    /* Start an element named "attribute" as child of attributes. */
    int rc = xmlTextWriterStartElement(writer, BAD_CAST "attribute");
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterStartElement");
    }

    /* Add an attribute with name "id" */
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST new_id.c_str());
    if (rc < 0) {
        throw FileWriterException( "Error at xmlTextWriterWriteAttribute");
    }

    /* Add an attribute with name "title" */
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "title", BAD_CAST title.c_str());
    if (rc < 0) {
        throw FileWriterException( "Error at xmlTextWriterWriteAttribute");
    }

    /* Add an attribute with name "type" */
    const string new_type = ( type == "liststring" ) ? "string" : type;
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST new_type.c_str());
    if (rc < 0) {
        throw FileWriterException( "Error at xmlTextWriterWriteAttribute");
    }

    /* Write a text element named "default" */
    if( !default_value.empty() ) {
        rc = xmlTextWriterWriteElement(writer, BAD_CAST "default", BAD_CAST default_value.c_str());
        if (rc < 0) {
            throw FileWriterException("Error at xmlTextWriterWriteElement");
        }
    }

    /* Close the element named attribute. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        throw FileWriterException("Error at xmlTextWriterEndElement");
    }
}
bool c_XMLWriter::t_writeelement(CStrRef name,
                                 CStrRef content /* = null_string */) {
  INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::writeelement);
  if (xmlValidateName((xmlChar*)name.data(), 0)) {
    raise_warning("invalid element name: %s", name.data());
    return false;
  }
  int ret = -1;
  if (m_ptr) {
    if (content.isNull()) {
      ret = xmlTextWriterStartElement(m_ptr, (xmlChar*)name.data());
      if (ret == -1) return false;
      ret = xmlTextWriterEndElement(m_ptr);
      if (ret == -1) return false;
    } else {
      ret = xmlTextWriterWriteElement(m_ptr, (xmlChar*)name.data(),
                                      (xmlChar*)content.data());
    }
  }
  return ret != -1;
}
Esempio n. 20
0
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;
}
Esempio n. 21
0
int MwsXmlResponseFormatter::writeData(const GenericAnswer* ans,
                                       FILE* output) const {
    const MwsAnswset& answerSet = *((const MwsAnswset*)ans);
    xmlOutputBuffer* outPtr;
    xmlTextWriter* writerPtr;
    size_t qvarNr;
    int ret;
    unsigned int i;
    LocalContext ctxt;

    // Initializing values
    outPtr = nullptr;
    writerPtr = nullptr;
    ret = -1;
    qvarNr = answerSet.qvarNames.size();
    ctxt.file = output;
    ctxt.total_bytes_written = 0;

    if ((outPtr = xmlOutputBufferCreateIO(fileXmlOutputWriteCallback, nullptr,
                                          &ctxt, nullptr)) ==
        nullptr) {
        PRINT_WARN("Error while creating the OutputBuffer\n");
    } else if ((writerPtr = xmlNewTextWriter(outPtr)) == nullptr) {
        PRINT_WARN("Error while creating the TextWriter\n");
    } else if ((ret =
                    xmlTextWriterStartDocument(writerPtr,  // xmlTextWriter
                                               nullptr,   // XML version ("1.0")
                                               nullptr,   // Encoding ("UTF-8")
                                               nullptr))  // Standalone ("yes")
               ==
               -1) {
        PRINT_WARN("Error at xmlTextWriterStartDocument\n");
    } else if ((ret = xmlTextWriterWriteComment(
                    writerPtr,
                    BAD_CAST "MwsAnswset generated by " MWS_BUILD)) ==
               -1) {
        PRINT_WARN("Error at xmlTextWriterStartDocument\n");
    } else if ((ret = xmlTextWriterStartElement(
                    writerPtr, BAD_CAST MWSANSWSET_MAIN_NAME)) ==
               -1) {
        PRINT_WARN("Error at xmlTextWriterStartElement\n");
    } else if ((ret = xmlTextWriterWriteAttribute(
                    writerPtr, BAD_CAST "xmlns:mws",
                    BAD_CAST "http://www.mathweb.org/mws/ns")) ==
               -1) {
        PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
    } else if ((ret = xmlTextWriterWriteAttribute(
                    writerPtr, BAD_CAST "size",
                    BAD_CAST std::to_string(answerSet.answers.size())
                        .c_str())) ==
               -1) {
        PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
    } else if ((ret = xmlTextWriterWriteAttribute(
                    writerPtr, BAD_CAST "total",
                    BAD_CAST std::to_string(answerSet.total).c_str())) ==
               -1) {
        PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
    } else {
        for (auto& answer : answerSet.answers) {
            if ((ret = xmlTextWriterStartElement(
                     writerPtr, BAD_CAST MWSANSWSET_ANSW_NAME)) ==
                -1) {
                PRINT_WARN("Error at xmlTextWriterStartElement\n");
                break;
            } else if ((ret = xmlTextWriterWriteAttribute(
                            writerPtr, BAD_CAST MWSANSWSET_URI_NAME,
                            BAD_CAST answer->uri.c_str())) ==
                       -1) {
                PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
                break;
            } else if ((ret = xmlTextWriterWriteAttribute(
                            writerPtr, BAD_CAST MWSANSWSET_XPATH_NAME,
                            BAD_CAST answer->xpath.c_str())) ==
                       -1) {
                PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
                break;
            } else {
                // Writing the substitutions
                for (i = 0; i < qvarNr; i++) {
                    string qvarXpath = answer->xpath + answerSet.qvarXpaths[i];
                    if ((ret = xmlTextWriterStartElement(
                             writerPtr, BAD_CAST MWSANSWSET_SUBSTPAIR_NAME)) ==
                        -1) {
                        PRINT_WARN("Error at xmlTextWriterStartElement\n");
                        break;
                    } else if ((ret = xmlTextWriterWriteAttribute(
                                    writerPtr, BAD_CAST "qvar",
                                    BAD_CAST answerSet.qvarNames[i].c_str())) ==
                               -1) {
                        PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
                        break;
                    } else if ((ret = xmlTextWriterWriteAttribute(
                                    writerPtr, BAD_CAST "xpath",
                                    BAD_CAST qvarXpath.c_str())) ==
                               -1) {
                        PRINT_WARN("Error at xmlTextWriterWriteAttribute\n");
                        break;
                    } else if ((ret = xmlTextWriterEndElement(writerPtr)) ==
                               -1) {
                        PRINT_WARN("Error at xmlTextWriterEndElement\n");
                        break;
                    }
                }
                // <data> ... </data>
                xmlTextWriterWriteElement(writerPtr, BAD_CAST "data",
                                          BAD_CAST answer->data.c_str());
            }
            if (ret == -1) {
                PRINT_WARN("Error while writing xml substpairs\n");
                break;
            } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) {
                PRINT_WARN("Error at xmlTextWriterEndElement\n");
                break;
            }
        }
    }
    if (ret == -1) {
        PRINT_WARN("Error while writing xml answers\n");
    } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) {
        PRINT_WARN("Error at xmlTextWriterEndElement\n");
    } else if ((ret = xmlTextWriterEndDocument(writerPtr)) == -1) {
        PRINT_WARN("Error at xmlTextWriterEndDocument\n");
    } else if ((ret = xmlTextWriterFlush(writerPtr)) == -1) {
        PRINT_WARN("Error at xmlTextWriterFlush\n");
    } else {
        ret = 0;
    }

    // Cleaning data
    if (writerPtr) {
        // This also cleans the outPtr
        xmlFreeTextWriter(writerPtr);
    } else if (outPtr) {
        xmlOutputBufferClose(outPtr);
    }

    if (ret == 0) {
        return ctxt.total_bytes_written;
    } else {
        return ret;
    }
}
Esempio n. 22
0
/* ========================================================================= */
static int writeDiscreteSwitchingStateContents(xmlTextWriterPtr writer,
                                               ghmm_xmlfile* f, int moNo,
                                               int sNo) {
#define CUR_PROC "writeDiscreteSwitchingStateContents"

  int bgId, cLabel, rc, order, tied;
  char * tmp=NULL;

  /* writing discrete distribution */
  if (0 > xmlTextWriterStartElement(writer, BAD_CAST "discrete")) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (discrete)");
    goto STOP;
  }

  if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST "0")) {
    GHMM_LOG(LERROR, "failed to write alphabet id");
    goto STOP;
  }

  if (f->model.ds[moNo]->s[sNo].fix)
    if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "fixed", BAD_CAST "1")) {
      GHMM_LOG(LERROR, "failed to write fixed attriute");
      goto STOP;
    }

  if ((f->model.ds[moNo]->model_type & GHMM_kHigherOrderEmissions)
      && f->model.ds[moNo]->order[sNo]) {
    order = f->model.ds[moNo]->order[sNo];
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "order", "%d", order)) {
      GHMM_LOG(LERROR, "failed to write order attribute for discrete distribution");
      goto STOP;
    }
  } else
    order = 0;

  tmp = doubleArrayToCSV(f->model.ds[moNo]->s[sNo].b, pow(f->model.ds[moNo]->M, order+1));
  if (tmp) {
    if (0 > xmlTextWriterWriteRaw(writer, BAD_CAST tmp)) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterWriteRaw while writing"
               "discrete distribution CSV");
      m_free(tmp);
      goto STOP;
    }
    m_free(tmp);
  } else {
    GHMM_LOG(LERROR, "converting array to CSV failed for discrete distribution");
    goto STOP;
  }

  /* end discrete distribution */
  if (0 > xmlTextWriterEndElement(writer)) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (discrete)");
    goto STOP;
  }

  /* writing backgroung key */
  if (f->model.ds[moNo]->model_type & GHMM_kBackgroundDistributions) {
    bgId = f->model.ds[moNo]->background_id[sNo];
    if (bgId != GHMM_kNoBackgroundDistribution) {
      if (f->model.ds[moNo]->bp->name[bgId]) {
        rc = xmlTextWriterWriteElement(writer, BAD_CAST "backgroundKey",
                                       BAD_CAST f->model.ds[moNo]->bp->name[bgId]);
        if (rc<0) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (backgroundKey)");
          goto STOP;
        }
      } else {
        GHMM_LOG(LERROR, "background name is NULL pointer, invalid model");
        goto STOP;
      }
    }
  }

  /* writing class label */
  if (f->model.ds[moNo]->model_type & GHMM_kLabeledStates) {
    cLabel = f->model.ds[moNo]->label[sNo];
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "class", "%d", cLabel);
    if (rc<0) {
      GHMM_LOG(LERROR, "failed to write class label");
      goto STOP;
    }
  }

  /* duration (not implemented yet, maybe never */
#if 0
  if (f->model.ds[moNo]->model_type & GHMM_kDurations) {
    if (f->model.ds[moNo]->duration[sNo] > 0) {
      rc = xmlTextWriterWriteElement(writer, BAD_CAST "duration",
                                     BAD_CAST f->model.ds[moNo]->duration[sNo]);
      if (rc<0) {
        GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (duration)");
        goto STOP;
      }
    }
  }
#endif

  /* writing positions */
  if ((f->model.ds[moNo]->s[sNo].xPosition > 0)
      && (f->model.ds[moNo]->s[sNo].xPosition > 0)) {
    if (xmlTextWriterStartElement(writer, BAD_CAST "position") < 0) {
      GHMM_LOG(LERROR, "failed to start position element (position)"); goto STOP;}
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "x", "%d",
                                          f->model.ds[moNo]->s[sNo].xPosition)) {
      GHMM_LOG(LERROR, "failed to write x position"); goto STOP;}
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "y", "%d",
                                          f->model.ds[moNo]->s[sNo].yPosition)) {
      GHMM_LOG(LERROR, "failed to write y position"); goto STOP;}
    if (xmlTextWriterEndElement(writer) < 0) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (position)"); goto STOP;}
  }


  /* writing tied states */
  if (f->model.ds[moNo]->model_type & GHMM_kTiedEmissions) {
    tied = f->model.ds[moNo]->tied_to[sNo];
    if (tied != GHMM_kUntied) {
      rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tiedTo", "%d", tied);
      if (rc<0) {
        GHMM_LOG(LERROR, "failed to write tiedTo element");
        goto STOP;
      }
    }
  }

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Esempio n. 23
0
static void
output_applications (xmlTextWriterPtr xo, char *root)
{
  size_t i;

  /* This returns an empty list if we simply couldn't determine the
   * applications, so if it returns NULL then it's a real error.
   */
  CLEANUP_FREE_APPLICATION2_LIST struct guestfs_application2_list *apps =
    guestfs_inspect_list_applications2 (g, root);
  if (apps == NULL)
    exit (EXIT_FAILURE);

  XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "applications"));

  for (i = 0; i < apps->len; ++i) {
    XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "application"));

    assert (apps->val[i].app2_name && apps->val[i].app2_name[0]);
    XMLERROR (-1,
              xmlTextWriterWriteElement (xo, BAD_CAST "name",
                                         BAD_CAST apps->val[i].app2_name));

    if (apps->val[i].app2_display_name && apps->val[i].app2_display_name[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "display_name",
					   BAD_CAST apps->val[i].app2_display_name));

    if (apps->val[i].app2_epoch != 0) {
      char buf[32];

      snprintf (buf, sizeof buf, "%d", apps->val[i].app2_epoch);

      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "epoch", BAD_CAST buf));
    }

    if (apps->val[i].app2_version && apps->val[i].app2_version[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "version",
					   BAD_CAST apps->val[i].app2_version));
    if (apps->val[i].app2_release && apps->val[i].app2_release[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "release",
					   BAD_CAST apps->val[i].app2_release));
    if (apps->val[i].app2_arch && apps->val[i].app2_arch[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "arch",
					   BAD_CAST apps->val[i].app2_arch));
    if (apps->val[i].app2_install_path && apps->val[i].app2_install_path[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "install_path",
					   BAD_CAST apps->val[i].app2_install_path));
    if (apps->val[i].app2_publisher && apps->val[i].app2_publisher[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "publisher",
					   BAD_CAST apps->val[i].app2_publisher));
    if (apps->val[i].app2_url && apps->val[i].app2_url[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "url",
					   BAD_CAST apps->val[i].app2_url));
    if (apps->val[i].app2_source_package && apps->val[i].app2_source_package[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "source_package",
					   BAD_CAST apps->val[i].app2_source_package));
    if (apps->val[i].app2_summary && apps->val[i].app2_summary[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "summary",
					   BAD_CAST apps->val[i].app2_summary));
    if (apps->val[i].app2_description && apps->val[i].app2_description[0])
      XMLERROR (-1,
		xmlTextWriterWriteElement (xo, BAD_CAST "description",
					   BAD_CAST apps->val[i].app2_description));

    XMLERROR (-1, xmlTextWriterEndElement (xo));
  }

  XMLERROR (-1, xmlTextWriterEndElement (xo));
}
Esempio n. 24
0
/* ========================================================================= */
static int writeTransition(xmlTextWriterPtr writer, ghmm_xmlfile* f, int moNo,
                           int sNo) {
#define CUR_PROC "writeTransition"


  int cos, i, j;
  int out_states, * out_id;
  double * * out_a;
  double * w_out_a;
  char * tmp;

  /* write state contents for different model types */
  switch (f->modelType & PTR_TYPE_MASK) {
  case GHMM_kDiscreteHMM:
    out_states = f->model.d[moNo]->s[sNo].out_states;
    out_id     = f->model.d[moNo]->s[sNo].out_id;
    out_a      = &(f->model.d[moNo]->s[sNo].out_a);
    cos        = 1;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    out_states = f->model.ds[moNo]->s[sNo].out_states;
    out_id     = f->model.ds[moNo]->s[sNo].out_id;
    out_a      = f->model.ds[moNo]->s[sNo].out_a;
    cos        = f->model.ds[moNo]->cos;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*
    out_states = f->model.dp[moNo]->s[sNo].out_states;
    out_id     = f->model.dp[moNo]->s[sNo].out_id;
    out_a      = f->model.dp[moNo]->s[sNo].out_a;
    cos        = f->model.dp[moNo]->cos;
    */
    break;
  case GHMM_kContinuousHMM:
  case (GHMM_kContinuousHMM+GHMM_kTransitionClasses):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses):
    out_states = f->model.c[moNo]->s[sNo].out_states;
    out_id     = f->model.c[moNo]->s[sNo].out_id;
    out_a      = f->model.c[moNo]->s[sNo].out_a;
    cos        = f->model.c[moNo]->cos;
    break;
  default:
    GHMM_LOG(LCRITIC, "invalid modelType");}

  ARRAY_MALLOC(w_out_a, cos);

  for (i=0; i<out_states; i++) {
    if (0 > xmlTextWriterStartElement(writer, BAD_CAST "transition")) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (transition)");
      goto STOP;
    }

    /* write source id (current state attribute */
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "source", "%d", sNo))
      GHMM_LOG(LERROR, "failed to write transition source attribute");

    /* write target id as attribute */
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "target", "%d", out_id[i]))
      GHMM_LOG(LERROR, "failed to write transition target attribute");

    for (j=0; j<cos; j++)
      w_out_a[j] = out_a[j][i];

    tmp = doubleArrayToCSV(w_out_a, cos);
    if (tmp) {
      if (0 > xmlTextWriterWriteElement(writer, BAD_CAST "probability", BAD_CAST tmp)) {
        GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (transition probabilities)");
        m_free(tmp);
        goto STOP;
      }
      m_free(tmp);
    } else {
      GHMM_LOG(LERROR, "converting transition probabilities array to CSV failed");
      goto STOP;
    }

    /* end transition */
    if (0 > xmlTextWriterEndElement(writer)) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (transition)");
      goto STOP;
    }
  }

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Esempio n. 25
0
static void
output_root (xmlTextWriterPtr xo, char *root)
{
  char *str;
  int i, r;
  char buf[32];
  char *canonical_root;
  size_t size;

  XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "operatingsystem"));

  canonical_root = guestfs_canonical_device_name (g, root);
  if (canonical_root == NULL)
    exit (EXIT_FAILURE);
  XMLERROR (-1,
	    xmlTextWriterWriteElement (xo, BAD_CAST "root", BAD_CAST canonical_root));
  free (canonical_root);

  str = guestfs_inspect_get_type (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "name", BAD_CAST str));
  free (str);

  str = guestfs_inspect_get_arch (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "arch", BAD_CAST str));
  free (str);

  str = guestfs_inspect_get_distro (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "distro", BAD_CAST str));
  free (str);

  str = guestfs_inspect_get_product_name (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "product_name", BAD_CAST str));
  free (str);

  str = guestfs_inspect_get_product_variant (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "product_variant", BAD_CAST str));
  free (str);

  i = guestfs_inspect_get_major_version (g, root);
  snprintf (buf, sizeof buf, "%d", i);
  XMLERROR (-1,
	    xmlTextWriterWriteElement (xo, BAD_CAST "major_version", BAD_CAST buf));
  i = guestfs_inspect_get_minor_version (g, root);
  snprintf (buf, sizeof buf, "%d", i);
  XMLERROR (-1,
	    xmlTextWriterWriteElement (xo, BAD_CAST "minor_version", BAD_CAST buf));

  str = guestfs_inspect_get_package_format (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "package_format", BAD_CAST str));
  free (str);

  str = guestfs_inspect_get_package_management (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "package_management",
					 BAD_CAST str));
  free (str);

  /* inspect-get-windows-systemroot will fail with non-windows guests,
   * or if the systemroot could not be determined for a windows guest.
   * Disable error output around this call.
   */
  guestfs_push_error_handler (g, NULL, NULL);
  str = guestfs_inspect_get_windows_systemroot (g, root);
  if (str)
    XMLERROR (-1,
              xmlTextWriterWriteElement (xo, BAD_CAST "windows_systemroot",
                                         BAD_CAST str));
  free (str);
  str = guestfs_inspect_get_windows_current_control_set (g, root);
  if (str)
    XMLERROR (-1,
              xmlTextWriterWriteElement (xo, BAD_CAST "windows_current_control_set",
                                         BAD_CAST str));
  free (str);
  guestfs_pop_error_handler (g);

  str = guestfs_inspect_get_hostname (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "hostname",
					 BAD_CAST str));
  free (str);

  str = guestfs_inspect_get_format (g, root);
  if (!str) exit (EXIT_FAILURE);
  if (STRNEQ (str, "unknown"))
    XMLERROR (-1,
	      xmlTextWriterWriteElement (xo, BAD_CAST "format",
					 BAD_CAST str));
  free (str);

  r = guestfs_inspect_is_live (g, root);
  if (r > 0) {
    XMLERROR (-1,
              xmlTextWriterStartElement (xo, BAD_CAST "live"));
    XMLERROR (-1, xmlTextWriterEndElement (xo));
  }

  r = guestfs_inspect_is_netinst (g, root);
  if (r > 0) {
    XMLERROR (-1,
              xmlTextWriterStartElement (xo, BAD_CAST "netinst"));
    XMLERROR (-1, xmlTextWriterEndElement (xo));
  }

  r = guestfs_inspect_is_multipart (g, root);
  if (r > 0) {
    XMLERROR (-1,
              xmlTextWriterStartElement (xo, BAD_CAST "multipart"));
    XMLERROR (-1, xmlTextWriterEndElement (xo));
  }

  output_mountpoints (xo, root);

  output_filesystems (xo, root);

  output_drive_mappings (xo, root);

  /* We need to mount everything up in order to read out the list of
   * applications and the icon, ie. everything below this point.
   */
  inspect_mount_root (g, root);

  output_applications (xo, root);

  /* Don't return favicon.  RHEL 7 and Fedora have crappy 16x16
   * favicons in the base distro.
   */
  str = guestfs_inspect_get_icon (g, root, &size,
                                  GUESTFS_INSPECT_GET_ICON_FAVICON, 0,
                                  -1);
  if (!str) exit (EXIT_FAILURE);
  if (size > 0) {
    XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "icon"));
    XMLERROR (-1, xmlTextWriterWriteBase64 (xo, str, 0, size));
    XMLERROR (-1, xmlTextWriterEndElement (xo));
  }
  /* Note we must free (str) even if size == 0, because that indicates
   * there was no icon.
   */
  free (str);

  /* Unmount (see inspect_mount_root above). */
  if (guestfs_umount_all (g) == -1)
    exit (EXIT_FAILURE);

  XMLERROR (-1, xmlTextWriterEndElement (xo));
}
Esempio n. 26
0
void struct_recursive_analyze(void *arg_ptr, enum struct_argtype struct_argtype, xmlTextWriterPtr writer) {

  if(arg_ptr == NULL)
    return;
  if(nullfd == 0)
    nullfd = open("/dev/random", O_WRONLY);

  switch(struct_argtype) {
    struct timeval timeval_s;
    struct timeval *timeval_p;

    struct timezone timezone_s;
    struct timezone *timezone_p;

    struct timex timex_s;
    struct timex *timex_p;

    struct tms tms_s;
    struct tms *tms_p;

    struct timespec timespec_s;
    struct timespec *timespec_p;

    struct itimerval itimerval_s;
    struct itimerval *itimerval_p;

    struct sigevent sigevent_s;
    struct sigevent *sigevent_p;

    struct itimerspec itimerspec_s;
    struct itimerspec *itimerspec_p;

    struct sched_param sched_param_s;
    struct sched_param *sched_param_p;

    struct kexec_segment kexec_segment_s;
    struct kexec_segment *kexec_segment_p;

    struct rusage rusage_s;
    struct rusage *rusage_p;

    struct siginfo siginfo_s;
    struct siginfo *siginfo_p;

    struct statfs statfs_s;
    struct statfs *statfs_p;

    struct statfs64 statfs64_s;
    struct statfs64 *statfs64_p;

    struct stat stat_s;
    struct stat *stat_p;

    struct stat64 stat64_s;
    struct stat64 *stat64_p;

    struct io_event io_event_s;
    struct io_event *io_event_p;

    struct iocb iocb_s;
    struct iocb *iocb_p;

    struct utimbuf utimbuf_s;
    struct utimbuf *utimbuf_p;

    struct iovec iovec_s;
    struct iovec *iovec_p;

    struct linux_dirent linux_dirent_s;
    struct linux_dirent *linux_dirent_p;

    struct linux_dirent64 linux_dirent64_s;
    struct linux_dirent64 *linux_dirent64_p;

    struct sockaddr sockaddr_s;
    struct sockaddr *sockaddr_p;

    struct msghdr msghdr_s;
    struct msghdr *msghdr_p;

    struct mmsghdr mmsghdr_s;
    struct mmsghdr *mmsghdr_p;

    struct pollfd pollfd_s;
    struct pollfd *pollfd_p;

    struct sel_arg_struct sel_arg_struct_s;
    struct sel_arg_struct *sel_arg_struct_p;

    struct epoll_event epoll_event_s;
    struct epoll_event *epoll_event_p;

    struct new_utsname new_utsname_s;
    struct new_utsname *new_utsname_p;

    struct rlimit rlimit_s;
    struct rlimit *rlimit_p;

    struct rlimit64 rlimit64_s;
    struct rlimit64 *rlimit64_p;

    struct msgbuf msgbuf_s;
    struct msgbuf *msgbuf_p;

    struct msqid_ds msqid_ds_s;
    struct msqid_ds *msqid_ds_p;

    struct sembuf sembuf_s;
    struct sembuf *sembuf_p;

    struct shmid_ds shmid_ds_s;
    struct shmid_ds *shmid_ds_p;

    struct mq_attr mq_attr_s;
    struct mq_attr *mq_attr_p;

    struct __sysctl_args __sysctl_args_s;
    struct __sysctl_args *__sysctl_args_p;

    struct robust_list_head robust_list_head_s;
    struct robust_list_head *robust_list_head_p;

    struct getcpu_cache getcpu_cache_s;
    struct getcpu_cache *getcpu_cache_p;

    struct perf_event_attr perf_event_attr_s;
    struct perf_event_attr *perf_event_attr_p;

    struct mmap_arg_struct mmap_arg_struct_s;
    struct mmap_arg_struct *mmap_arg_struct_p;

    struct file_handle file_handle_s;
    struct file_handle *file_handle_p;

  case STRUCT_ARG_timeval:
    if(write(nullfd, (void *) arg_ptr, sizeof(timeval_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_timeval", "unmapped");
      return;
    }

    timeval_p = (struct timeval *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_timeval");
    xmlTextWriterWriteBase64(writer, (char *) timeval_p, 0, sizeof(timeval_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_timezone:
    if(write(nullfd, (void *) arg_ptr, sizeof(timezone_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_timezone", "unmapped");
      return;
    }

    timezone_p = (struct timezone *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_timezone");
    xmlTextWriterWriteBase64(writer, (char *) timezone_p, 0, sizeof(timezone_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_timex:
    if(write(nullfd, (void *) arg_ptr, sizeof(timex_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_timex", "unmapped");
      return;
    }

    timex_p = (struct timex *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_timex");
    xmlTextWriterWriteBase64(writer, (char *) timex_p, 0, sizeof(timex_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_tms:
    if(write(nullfd, (void *) arg_ptr, sizeof(tms_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_tms", "unmapped");
      return;
    }

    tms_p = (struct tms *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_tms");
    xmlTextWriterWriteBase64(writer, (char *) tms_p, 0, sizeof(tms_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_timespec:
    if(write(nullfd, (void *) arg_ptr, sizeof(timespec_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_timespec", "unmapped");
      return;
    }

    timespec_p = (struct timespec *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_timespec");
    xmlTextWriterWriteBase64(writer, (char *) timespec_p, 0, sizeof(timespec_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_itimerval:
    if(write(nullfd, (void *) arg_ptr, sizeof(itimerval_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_itimerval", "unmapped");
      return;
    }

    itimerval_p = (struct itimerval *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_itimerval");
    xmlTextWriterWriteBase64(writer, (char *) itimerval_p, 0, sizeof(itimerval_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_sigevent:
    if(write(nullfd, (void *) arg_ptr, sizeof(sigevent_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_sigevent", "unmapped");
      return;
    }

    sigevent_p = (struct sigevent *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_sigevent");
    xmlTextWriterWriteBase64(writer, (char *) sigevent_p, 0, sizeof(sigevent_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_itimerspec:
    if(write(nullfd, (void *) arg_ptr, sizeof(itimerspec_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_itimerspec", "unmapped");
      return;
    }

    itimerspec_p = (struct itimerspec *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_itimerspec");
    xmlTextWriterWriteBase64(writer, (char *) itimerspec_p, 0, sizeof(itimerspec_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_sched_param:
    if(write(nullfd, (void *) arg_ptr, sizeof(sched_param_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_sched_param", "unmapped");
      return;
    }

    sched_param_p = (struct sched_param *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_sched_param");
    xmlTextWriterWriteBase64(writer, (char *) sched_param_p, 0, sizeof(sched_param_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_kexec_segment:
    if(write(nullfd, (void *) arg_ptr, sizeof(kexec_segment_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_kexec_segment", "unmapped");
      return;
    }

    kexec_segment_p = (struct kexec_segment *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_kexec_segment");
    xmlTextWriterWriteBase64(writer, (char *) kexec_segment_p, 0, sizeof(kexec_segment_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_rusage:
    if(write(nullfd, (void *) arg_ptr, sizeof(rusage_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_rusage", "unmapped");
      return;
    }

    rusage_p = (struct rusage *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_rusage");
    xmlTextWriterWriteBase64(writer, (char *) rusage_p, 0, sizeof(rusage_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_siginfo:
    if(write(nullfd, (void *) arg_ptr, sizeof(siginfo_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_siginfo", "unmapped");
      return;
    }

    siginfo_p = (struct siginfo *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_siginfo");
    xmlTextWriterWriteBase64(writer, (char *) siginfo_p, 0, sizeof(siginfo_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_statfs:
    if(write(nullfd, (void *) arg_ptr, sizeof(statfs_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_statfs", "unmapped");
      return;
    }

    statfs_p = (struct statfs *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_statfs");
    xmlTextWriterWriteBase64(writer, (char *) statfs_p, 0, sizeof(statfs_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_statfs64:
    if(write(nullfd, (void *) arg_ptr, sizeof(statfs64_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_statfs64", "unmapped");
      return;
    }

    statfs64_p = (struct statfs64 *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_statfs64");
    xmlTextWriterWriteBase64(writer, (char *) statfs64_p, 0, sizeof(statfs64_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_stat:
    if(write(nullfd, (void *) arg_ptr, sizeof(stat_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_stat", "unmapped");
      return;
    }

    stat_p = (struct stat *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_stat");
    xmlTextWriterWriteBase64(writer, (char *) stat_p, 0, sizeof(stat_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_stat64:
    if(write(nullfd, (void *) arg_ptr, sizeof(stat64_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_stat64", "unmapped");
      return;
    }

    stat64_p = (struct stat64 *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_stat64");
    xmlTextWriterWriteBase64(writer, (char *) stat64_p, 0, sizeof(stat64_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_io_event:
    if(write(nullfd, (void *) arg_ptr, sizeof(io_event_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_io_event", "unmapped");
      return;
    }

    io_event_p = (struct io_event *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_io_event");
    xmlTextWriterWriteBase64(writer, (char *) io_event_p, 0, sizeof(io_event_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_iocb:
    if(write(nullfd, (void *) arg_ptr, sizeof(iocb_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_iocb", "unmapped");
      return;
    }

    iocb_p = (struct iocb *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_iocb");
    xmlTextWriterWriteBase64(writer, (char *) iocb_p, 0, sizeof(iocb_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_utimbuf:
    if(write(nullfd, (void *) arg_ptr, sizeof(utimbuf_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_utimbuf", "unmapped");
      return;
    }

    utimbuf_p = (struct utimbuf *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_utimbuf");
    xmlTextWriterWriteBase64(writer, (char *) utimbuf_p, 0, sizeof(utimbuf_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_iovec:
    if(write(nullfd, (void *) arg_ptr, sizeof(iovec_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_iovec", "unmapped");
      return;
    }

    iovec_p = (struct iovec *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_iovec");
    xmlTextWriterWriteBase64(writer, (char *) iovec_p, 0, sizeof(iovec_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_linux_dirent:
    if(write(nullfd, (void *) arg_ptr, sizeof(linux_dirent_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_linux_dirent", "unmapped");
      return;
    }

    linux_dirent_p = (struct linux_dirent *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_linux_dirent");
    xmlTextWriterWriteBase64(writer, (char *) linux_dirent_p, 0, sizeof(linux_dirent_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_linux_dirent64:
    if(write(nullfd, (void *) arg_ptr, sizeof(linux_dirent64_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_linux_dirent64", "unmapped");
      return;
    }

    linux_dirent64_p = (struct linux_dirent64 *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_linux_dirent64");
    xmlTextWriterWriteBase64(writer, (char *) linux_dirent64_p, 0, sizeof(linux_dirent64_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_sockaddr:
    if(write(nullfd, (void *) arg_ptr, sizeof(sockaddr_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_sockaddr", "unmapped");
      return;
    }

    sockaddr_p = (struct sockaddr *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_sockaddr");
    xmlTextWriterWriteBase64(writer, (char *) sockaddr_p, 0, sizeof(sockaddr_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_msghdr:
    if(write(nullfd, (void *) arg_ptr, sizeof(msghdr_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_msghdr", "unmapped");
      return;
    }

    msghdr_p = (struct msghdr *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_msghdr");
    xmlTextWriterWriteBase64(writer, (char *) msghdr_p, 0, sizeof(msghdr_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_mmsghdr:
    if(write(nullfd, (void *) arg_ptr, sizeof(mmsghdr_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_mmsghdr", "unmapped");
      return;
    }

    mmsghdr_p = (struct mmsghdr *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_mmsghdr");
    xmlTextWriterWriteBase64(writer, (char *) mmsghdr_p, 0, sizeof(mmsghdr_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_pollfd:
    if(write(nullfd, (void *) arg_ptr, sizeof(pollfd_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_pollfd", "unmapped");
      return;
    }

    pollfd_p = (struct pollfd *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_pollfd");
    xmlTextWriterWriteBase64(writer, (char *) pollfd_p, 0, sizeof(pollfd_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_sel_arg_struct:
    if(write(nullfd, (void *) arg_ptr, sizeof(sel_arg_struct_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_sel_arg_struct", "unmapped");
      return;
    }

    sel_arg_struct_p = (struct sel_arg_struct *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_sel_arg_struct");
    xmlTextWriterWriteBase64(writer, (char *) sel_arg_struct_p, 0, sizeof(sel_arg_struct_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_epoll_event:
    if(write(nullfd, (void *) arg_ptr, sizeof(epoll_event_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_epoll_event", "unmapped");
      return;
    }

    epoll_event_p = (struct epoll_event *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_epoll_event");
    xmlTextWriterWriteBase64(writer, (char *) epoll_event_p, 0, sizeof(epoll_event_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_new_utsname:
    if(write(nullfd, (void *) arg_ptr, sizeof(new_utsname_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_new_utsname", "unmapped");
      return;
    }

    new_utsname_p = (struct new_utsname *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_new_utsname");
    xmlTextWriterWriteBase64(writer, (char *) new_utsname_p, 0, sizeof(new_utsname_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_rlimit:
    if(write(nullfd, (void *) arg_ptr, sizeof(rlimit_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_rlimit", "unmapped");
      return;
    }

    rlimit_p = (struct rlimit *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_rlimit");
    xmlTextWriterWriteBase64(writer, (char *) rlimit_p, 0, sizeof(rlimit_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_rlimit64:
    if(write(nullfd, (void *) arg_ptr, sizeof(rlimit64_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_rlimit64", "unmapped");
      return;
    }

    rlimit64_p = (struct rlimit64 *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_rlimit64");
    xmlTextWriterWriteBase64(writer, (char *) rlimit64_p, 0, sizeof(rlimit64_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_msgbuf:
    if(write(nullfd, (void *) arg_ptr, sizeof(msgbuf_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_msgbuf", "unmapped");
      return;
    }

    msgbuf_p = (struct msgbuf *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_msgbuf");
    xmlTextWriterWriteBase64(writer, (char *) msgbuf_p, 0, sizeof(msgbuf_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_msqid_ds:
    if(write(nullfd, (void *) arg_ptr, sizeof(msqid_ds_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_msqid_ds", "unmapped");
      return;
    }

    msqid_ds_p = (struct msqid_ds *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_msqid_ds");
    xmlTextWriterWriteBase64(writer, (char *) msqid_ds_p, 0, sizeof(msqid_ds_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_sembuf:
    if(write(nullfd, (void *) arg_ptr, sizeof(sembuf_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_sembuf", "unmapped");
      return;
    }

    sembuf_p = (struct sembuf *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_sembuf");
    xmlTextWriterWriteBase64(writer, (char *) sembuf_p, 0, sizeof(sembuf_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_shmid_ds:
    if(write(nullfd, (void *) arg_ptr, sizeof(shmid_ds_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_shmid_ds", "unmapped");
      return;
    }

    shmid_ds_p = (struct shmid_ds *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_shmid_ds");
    xmlTextWriterWriteBase64(writer, (char *) shmid_ds_p, 0, sizeof(shmid_ds_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_mq_attr:
    if(write(nullfd, (void *) arg_ptr, sizeof(mq_attr_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_mq_attr", "unmapped");
      return;
    }

    mq_attr_p = (struct mq_attr *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_mq_attr");
    xmlTextWriterWriteBase64(writer, (char *) mq_attr_p, 0, sizeof(mq_attr_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG___sysctl_args:
    if(write(nullfd, (void *) arg_ptr, sizeof(__sysctl_args_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT___sysctl_args", "unmapped");
      return;
    }

    __sysctl_args_p = (struct __sysctl_args *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT___sysctl_args");
    xmlTextWriterWriteBase64(writer, (char *) __sysctl_args_p, 0, sizeof(__sysctl_args_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_robust_list_head:
    if(write(nullfd, (void *) arg_ptr, sizeof(robust_list_head_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_robust_list_head", "unmapped");
      return;
    }

    robust_list_head_p = (struct robust_list_head *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_robust_list_head");
    xmlTextWriterWriteBase64(writer, (char *) robust_list_head_p, 0, sizeof(robust_list_head_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_getcpu_cache:
    if(write(nullfd, (void *) arg_ptr, sizeof(getcpu_cache_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_getcpu_cache", "unmapped");
      return;
    }

    getcpu_cache_p = (struct getcpu_cache *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_getcpu_cache");
    xmlTextWriterWriteBase64(writer, (char *) getcpu_cache_p, 0, sizeof(getcpu_cache_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_perf_event_attr:
    if(write(nullfd, (void *) arg_ptr, sizeof(perf_event_attr_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_perf_event_attr", "unmapped");
      return;
    }

    perf_event_attr_p = (struct perf_event_attr *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_perf_event_attr");
    xmlTextWriterWriteBase64(writer, (char *) perf_event_attr_p, 0, sizeof(perf_event_attr_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_mmap_arg_struct:
    if(write(nullfd, (void *) arg_ptr, sizeof(mmap_arg_struct_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_mmap_arg_struct", "unmapped");
      return;
    }

    mmap_arg_struct_p = (struct mmap_arg_struct *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_mmap_arg_struct");
    xmlTextWriterWriteBase64(writer, (char *) mmap_arg_struct_p, 0, sizeof(mmap_arg_struct_s));
    xmlTextWriterEndElement(writer);

    break;

  case STRUCT_ARG_file_handle:
    if(write(nullfd, (void *) arg_ptr, sizeof(file_handle_s)) < 0) {
      xmlTextWriterWriteElement(writer, "STRUCT_file_handle", "unmapped");
      return;
    }

    file_handle_p = (struct file_handle *) arg_ptr;
    xmlTextWriterStartElement(writer, "STRUCT_file_handle");
    xmlTextWriterWriteBase64(writer, (char *) file_handle_p, 0, sizeof(file_handle_s));
    xmlTextWriterEndElement(writer);

    break;

  default:
    break;
  }
}
static gchar*
rb_disc_recorder_plugin_write_audio_project (const gchar 	*name,
					     GtkTreeModel       *model,
					     GError		**error)
{
        GtkTreeIter iter;
	xmlTextWriter *project;
	xmlDocPtr doc = NULL;
	xmlSaveCtxt *save;
	gint success;
    	gchar *path;
	int fd;
	int use_errno = 0;

        if (! gtk_tree_model_get_iter_first (model, &iter)) {
                g_set_error (error,
                             RB_RECORDER_ERROR,
                             RB_RECORDER_ERROR_GENERAL,
                             _("Unable to build an audio track list"));
                return NULL;
        }

	/* get a temporary path */
	path = g_build_filename (g_get_tmp_dir (), "brasero-tmp-project-XXXXXX",  NULL);
	fd = g_mkstemp (path);
	if (fd == -1) {
		g_set_error (error,
                 	     RB_RECORDER_ERROR,
                     	     RB_RECORDER_ERROR_GENERAL,
                    	     _("Unable to write audio project file %s: %s"),
			     path,
			     g_strerror (errno));
		rb_debug ("g_mkstemp failed");

		g_free (path);
		return NULL;
	}

	project = xmlNewTextWriterDoc (&doc, 0);
	if (!project) {
		g_remove (path);
		g_free (path);
		close (fd);

		g_set_error (error,
                 	     RB_RECORDER_ERROR,
                     	     RB_RECORDER_ERROR_GENERAL,
                    	     _("Unable to write audio project"));

		return NULL;
	}

	xmlTextWriterSetIndent (project, 1);
	xmlTextWriterSetIndentString (project, (xmlChar *) "\t");

	success = xmlTextWriterStartDocument (project,
					      NULL,
					      "UTF8",
					      NULL);
	if (success < 0)
		goto error;

	success = xmlTextWriterStartElement (project, (xmlChar *) "braseroproject");
	if (success < 0)
		goto error;

	/* write the name of the version */
	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "version",
					     (xmlChar *) "0.2");
	if (success < 0)
		goto error;

	if (name) {
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "label",
						     (xmlChar *) name);
		if (success < 0)
			goto error;
	}

	success = xmlTextWriterStartElement (project, (xmlChar *) "track");
	if (success < 0)
		goto error;

        do {
		RhythmDBEntry  *entry;
		const char *str;
		xmlChar *escaped;

		success = xmlTextWriterStartElement (project, (xmlChar *) "audio");
		if (success < 0)
			goto error;

		gtk_tree_model_get (model, &iter, 0, &entry, -1);

		str = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
		escaped = (xmlChar *) g_uri_escape_string (str, NULL, FALSE);
		success = xmlTextWriterWriteElement (project,
						    (xmlChar *) "uri",
						     escaped);
		g_free (escaped);

		if (success == -1)
			goto error;

		/* start of the song always 0 */
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "start",
						     (xmlChar *) "0");
		if (success == -1)
			goto error;

		/* end of the song = duration (in seconds while brasero likes it
		 * in nanoseconds =( ) */
		/* Disable this for the moment and let brasero check the size
		 * itself. In case the user chooses on the fly burning we need
		 * a more precise duration or we'd end up burning the track
		 * incompletely or with a big padding */
		/*
		end = g_strdup_printf ("%"G_GINT64_FORMAT, (gint64) (song->duration * 1000000000LL));
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "end",
						     (xmlChar *) end);

		g_free (end);
		if (success == -1)
			goto error;
		*/

		str = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE);
		if (str) {
			escaped = (xmlChar *) g_uri_escape_string (str, NULL, FALSE);
			success = xmlTextWriterWriteElement (project,
							    (xmlChar *) "title",
							     escaped);
			g_free (escaped);

			if (success == -1)
				goto error;
		}

		str = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST);
		if (str) {
			escaped = (xmlChar *) g_uri_escape_string (str, NULL, FALSE);
			success = xmlTextWriterWriteElement (project,
							    (xmlChar *) "artist",
							     escaped);
			g_free (escaped);

			if (success == -1)
				goto error;
		}

		/*
		if (song->composer) {
			escaped = (unsigned char *) g_uri_escape_string (song->composer, NULL, FALSE);
			success = xmlTextWriterWriteElement (project,
							    (xmlChar *) "composer",
							     escaped);
			g_free (escaped);

			if (success == -1)
				goto error;
		}
		*/

		success = xmlTextWriterEndElement (project); /* audio */
		if (success < 0)
			goto error;
        } while (gtk_tree_model_iter_next (model, &iter));

	success = xmlTextWriterEndElement (project); /* track */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndElement (project); /* braseroproject */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndDocument (project);
	if (success < 0)
		goto end_error;

	xmlFreeTextWriter (project);

	save = xmlSaveToFd (fd, "UTF8", XML_SAVE_FORMAT);
	if (save == NULL)
		goto save_error;

	if (xmlSaveDoc (save, doc) == -1)
		goto save_error;

	if (xmlSaveClose (save) == -1) {
		use_errno = errno;
		rb_debug ("xmlSaveClose failed");
		goto save_error;
	}

	xmlFreeDoc (doc);

	if (close (fd) == -1) {
		use_errno = errno;
		rb_debug ("close() failed");
		goto save_error;
	}

	return path;

error:
	/* cleanup */
	xmlTextWriterEndDocument (project);

end_error:
	xmlFreeTextWriter (project);

save_error:
	if (use_errno != 0) {
		g_set_error (error,
			     RB_RECORDER_ERROR,
			     RB_RECORDER_ERROR_GENERAL,
			     _("Unable to write audio project file %s: %s"),
			     path,
			     g_strerror (use_errno));
	} else {
		g_set_error (error,
			     RB_RECORDER_ERROR,
			     RB_RECORDER_ERROR_GENERAL,
			     _("Unable to write audio project"));
	}

	g_remove (path);
	g_free (path);
	close (fd);

	return NULL;
}
Esempio n. 28
0
static void format_request(LinphoneXmlRpcRequest *request) {
    char si[64];
    belle_sip_list_t *arg_ptr = request->arg_list;
    xmlBufferPtr buf;
    xmlTextWriterPtr writer;
    int err;

    if (request->content != NULL) {
        belle_sip_free(request->content);
        request->content = NULL;
    }

    buf = xmlBufferCreate();
    if (buf == NULL) {
        ms_error("Error creating the XML buffer");
        return;
    }
    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        ms_error("Error creating the XML writer");
        return;
    }

    err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL);
    if (err >= 0) {
        err = xmlTextWriterStartElement(writer, (const xmlChar *)"methodCall");
    }
    if (err >= 0) {
        err = xmlTextWriterWriteElement(writer, (const xmlChar *)"methodName", (const xmlChar *)request->method);
    }
    if (err >= 0) {
        err = xmlTextWriterStartElement(writer, (const xmlChar *)"params");
    }
    while (arg_ptr != NULL) {
        LinphoneXmlRpcArg *arg = (LinphoneXmlRpcArg *)arg_ptr->data;
        if (err >= 0) {
            err = xmlTextWriterStartElement(writer, (const xmlChar *)"param");
        }
        if (err >= 0) {
            err = xmlTextWriterStartElement(writer, (const xmlChar *)"value");
        }
        switch (arg->type) {
        case LinphoneXmlRpcArgNone:
            break;
        case LinphoneXmlRpcArgInt:
            memset(si, 0, sizeof(si));
            snprintf(si, sizeof(si), "%i", arg->data.i);
            err = xmlTextWriterWriteElement(writer, (const xmlChar *)"int", (const xmlChar *)si);
            break;
        case LinphoneXmlRpcArgString:
            err = xmlTextWriterWriteElement(writer, (const xmlChar *)"string", (const xmlChar *)arg->data.s);
            break;
        }
        if (err >= 0) {
            /* Close the "value" element. */
            err = xmlTextWriterEndElement(writer);
        }
        if (err >= 0) {
            /* Close the "param" element. */
            err = xmlTextWriterEndElement(writer);
        }
        arg_ptr = arg_ptr->next;
    }
    if (err >= 0) {
        /* Close the "params" element. */
        err = xmlTextWriterEndElement(writer);
    }
    if (err >= 0) {
        /* Close the "methodCall" element. */
        err = xmlTextWriterEndElement(writer);
    }
    if (err >= 0) {
        err = xmlTextWriterEndDocument(writer);
    }
    if (err > 0) {
        /* xmlTextWriterEndDocument returns the size of the content. */
        request->content = belle_sip_strdup((const char *)buf->content);
    }
    xmlFreeTextWriter(writer);
    xmlBufferFree(buf);
}
static char*
totem_disc_recorder_plugin_write_video_project (TotemDiscRecorderPlugin *pi,
						char **error)
{
	xmlTextWriter *project;
	xmlDocPtr doc = NULL;
	xmlSaveCtxt *save;
	xmlChar *escaped;
	gint success;
	char *title, *path, *uri;
	int fd;

	/* get a temporary path */
	path = g_build_filename (g_get_tmp_dir (), "brasero-tmp-project-XXXXXX",  NULL);
	fd = g_mkstemp (path);
	if (!fd) {
		g_free (path);

		*error = g_strdup (_("Unable to write a project."));
		return NULL;
	}

	project = xmlNewTextWriterDoc (&doc, 0);
	if (!project) {
		g_remove (path);
		g_free (path);
		close (fd);

		*error = g_strdup (_("Unable to write a project."));
		return NULL;
	}

	xmlTextWriterSetIndent (project, 1);
	xmlTextWriterSetIndentString (project, (xmlChar *) "\t");

	success = xmlTextWriterStartDocument (project,
					      NULL,
					      "UTF8",
					      NULL);
	if (success < 0)
		goto error;

	success = xmlTextWriterStartElement (project, (xmlChar *) "braseroproject");
	if (success < 0)
		goto error;

	/* write the name of the version */
	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "version",
					     (xmlChar *) "0.2");
	if (success < 0)
		goto error;

	title = totem_object_get_short_title (pi->priv->totem);
	if (title) {
		success = xmlTextWriterWriteElement (project,
						     (xmlChar *) "label",
						     (xmlChar *) title);
		g_free (title);

		if (success < 0)
			goto error;
	}

	success = xmlTextWriterStartElement (project, (xmlChar *) "track");
	if (success < 0)
		goto error;

	success = xmlTextWriterStartElement (project, (xmlChar *) "video");
	if (success < 0)
		goto error;

	uri = totem_object_get_current_mrl (pi->priv->totem);
	escaped = (unsigned char *) g_uri_escape_string (uri, NULL, FALSE);
	g_free (uri);

	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "uri",
					     escaped);
	g_free (escaped);
	if (success == -1)
		goto error;

	/* start of the song always 0 */
	success = xmlTextWriterWriteElement (project,
					     (xmlChar *) "start",
					     (xmlChar *) "0");
	if (success == -1)
		goto error;

	success = xmlTextWriterEndElement (project); /* video */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndElement (project); /* track */
	if (success < 0)
		goto error;

	success = xmlTextWriterEndElement (project); /* braseroproject */
	if (success < 0)
		goto error;

	xmlTextWriterEndDocument (project);
	xmlFreeTextWriter (project);

	save = xmlSaveToFd (fd, "UTF8", XML_SAVE_FORMAT);
	xmlSaveDoc (save, doc);
	xmlSaveClose (save);

	xmlFreeDoc (doc);
	close (fd);

	return path;

error:

	/* cleanup */
	xmlTextWriterEndDocument (project);
	xmlFreeTextWriter (project);

	g_remove (path);
	g_free (path);
	close (fd);

	*error = g_strdup (_("Unable to write a project."));
	return NULL;
}
Esempio n. 30
0
/**
 * glista_storage_save_all_items: 
 * @all_items: A linked list of all items to save
 * 
 * Save all items to the storage XML file
 */
void 
glista_storage_save_all_items(GList *all_items)
{
	GlistaItem       *item;
	xmlTextWriterPtr  xml;
	int               ret;
	gchar            *storage_file;
	gchar             done_str[2];
	gchar            *remind_at_str;
	
	remind_at_str = g_malloc0(sizeof(gchar) * 20);
	
	// Build storage file path
	storage_file = g_build_filename(gl_globs->configdir, 
									GL_XML_FILENAME, NULL);
	
	// Start XML
	xml = xmlNewTextWriterFilename(storage_file, 0);
	g_free(storage_file);
	
	if (xml == NULL) {
		fprintf(stderr, "Unable to write data to storage XML file\n");
		return;
	}
	
	xmlTextWriterSetIndent(xml, 1);
	xmlTextWriterSetIndentString(xml, BAD_CAST "  ");
	
	ret = xmlTextWriterStartDocument(xml, NULL, GL_XML_ENCODING, "yes");
	ret = xmlTextWriterStartElement(xml, BAD_CAST GL_XNODE_ROOT);

	// Iterate over items, writing them to the XML file
	while (all_items != NULL) {
		item = all_items->data;
		
		g_snprintf((gchar *) &done_str, 2, "%d", item->done);
		
		ret = xmlTextWriterStartElement(xml, BAD_CAST GL_XNODE_ITEM);
		ret = xmlTextWriterWriteElement(xml, BAD_CAST GL_XNODE_TEXT, 
										BAD_CAST item->text);
		ret = xmlTextWriterWriteElement(xml, BAD_CAST GL_XNODE_DONE, 
										BAD_CAST &done_str);
		
		if (item->parent != NULL) {
			ret = xmlTextWriterWriteElement(xml, BAD_CAST GL_XNODE_PRNT, 
											BAD_CAST item->parent);
		}
		
		if (item->note != NULL) {
			ret = xmlTextWriterWriteElement(xml, BAD_CAST GL_XNODE_NOTE, 
			                                BAD_CAST item->note);
		}
		
		if (item->remind_at != -1) {
			remind_at_str = g_strdup_printf("%d", (gint) item->remind_at);
			
			ret = xmlTextWriterWriteElement(xml, BAD_CAST GL_XNODE_RMDR,
			                                BAD_CAST remind_at_str);
		}
		
		ret = xmlTextWriterEndElement(xml);
		
		all_items = all_items->next;
	}
	
	g_free(remind_at_str);
	
	// End XML
	ret = xmlTextWriterEndElement(xml);
	ret = xmlTextWriterEndDocument(xml);
	
	xmlTextWriterFlush(xml);
	xmlFreeTextWriter(xml);
}