Пример #1
1
struct writer * xml_init(FILE * fh) {

	struct writer * result;
	struct xml_writer_private * priv;

	priv = malloc( sizeof( *priv ) );
	if ( ! priv ) {
		fatalx("out of memory\n");
		return NULL;
	}

	priv->xw = xmlNewTextWriterDoc(&(priv->doc), 0);
	if ( ! priv->xw ) {
		fatalx("cannot create xml writer\n");
		return NULL;
	}

	xmlTextWriterSetIndent(priv->xw, 4);

	if (xmlTextWriterStartDocument(priv->xw, NULL, MY_ENCODING, NULL) < 0 ) {
		fatalx("cannot start xml document\n");
		return NULL;
	}

	result = malloc( sizeof( struct writer ) );
	if ( ! result ) {
		fatalx("out of memory\n");
		return NULL;
	}

	result->priv  = priv;
	result->start = xml_start;
	result->attr  = xml_attr;
	result->data  = xml_data;
	result->end   = xml_end;
	result->finish= xml_finish;

	return result;
}
bool TasksetWriter::write(const std::string& filename, vector<Task*>& taskset) const {
    xmlDocPtr doc;
    tDebug() << "Writing Taskset to XML file: " << filename;

    xmlTextWriterPtr writer;
    writer = xmlNewTextWriterDoc(&doc, 0);
    xmlTextWriterSetIndent(writer, 1);
    if (xmlTextWriterSetIndentString(writer, (const xmlChar*) "  ") != 0) {
        tError() << "Fehler beim Setzen des Einrueckens!";
    }

    xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);

    xmlTextWriterWriteComment(writer, (xmlChar*) "Hier kommen die Tasks");

    xmlTextWriterStartElement(writer, (xmlChar*) "taskset");
    xmlTextWriterWriteAttributeNS(writer, (xmlChar*) "xsi", (xmlChar*) "schemaLocation", (xmlChar*) "http://www.w3.org/2001/XMLSchema-instance", (xmlChar*) "http://www.tmsxmlns.com taskset.xsd");
    xmlTextWriterWriteAttribute(writer, (xmlChar*) "xmlns", (xmlChar*) "http://www.tmsxmlns.com");

    xmlTextWriterWriteRaw(writer, (xmlChar*) "\n");

    for (size_t i = 0; i < taskset.size(); i++) {
        xmlTextWriterWriteRaw(writer, (xmlChar*) "\n");
        //taskset[i]->write(writer);
        taskset[i]->writeToXML(writer);
        xmlTextWriterWriteRaw(writer, (xmlChar*) "\n");
    }

    xmlTextWriterEndElement(writer); // close TaskSet

    xmlTextWriterEndDocument(writer);
    xmlFreeTextWriter(writer);
    xmlSaveFile(filename.c_str(), doc);

    xmlNodePtr cur = xmlDocGetRootElement(doc);
    if (cur == NULL) {
        tError() << "Empty document.";
        xmlFreeDoc(doc);
        return false;
    }
    if (xmlStrcmp(cur->name, (const xmlChar *) "taskset")) {
        tError() << "Document of the wrong type, root node != taskset";
        xmlFreeDoc(doc);
        return false;
    }

    if (isValid(doc) > 0) {
        tDebug() << "Written document is valid";

    } else {
        tError() << "Written document is invalid";
        xmlFreeDoc(doc);
        return false;
    }

    xmlFreeDoc(doc);

    return true;

}
Пример #3
0
int write_volumeindex(opendcp_t *opendcp) {
    xmlIndentTreeOutput = 1;
    xmlDocPtr        doc;
    xmlTextWriterPtr xml;
    int              rc;

    dcp_log(LOG_INFO,"Writing VOLINDEX file %.256s",opendcp->volindex.filename);

    /* create XML document */
    xml = xmlNewTextWriterDoc(&doc,0);

    /* volumeindex XML Start */
    rc = xmlTextWriterStartDocument(xml, NULL, XML_ENCODING, NULL);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterStartDocument failed");
        return DCP_FATAL;
    }

    xmlTextWriterStartElement(xml, BAD_CAST "VolumeIndex");
    xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns", BAD_CAST NS_AM[opendcp->ns]);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Index","%d",1);
    xmlTextWriterEndElement(xml); 

    rc = xmlTextWriterEndDocument(xml);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterEndDocument failed %s",opendcp->volindex.filename);
        return DCP_FATAL;
    }

    xmlFreeTextWriter(xml);
    xmlSaveFormatFile(opendcp->volindex.filename, doc, 1);
    xmlFreeDoc(doc);

    return DCP_SUCCESS;
}
Пример #4
0
char *gen_export_nfe_xml(NFE *nfe){
	int rc, buffersize;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlChar *xmlbuf;

	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
		return NULL;
	xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
	rc = xmlTextWriterStartElement(writer, BAD_CAST "nfeProc");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao",
			BAD_CAST NFE_VERSAO);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteRaw(writer, BAD_CAST nfe->xml);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteRaw(writer, BAD_CAST nfe->protocolo->xml);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	xmlDocDumpMemory(doc, &xmlbuf, &buffersize);
	return (char*)xmlbuf;
}
Пример #5
0
char *generate_xml(NFE *nfe, EVP_PKEY *key, X509 *cert) {
	int rc;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlBufferPtr buf = xmlBufferCreate();

	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
		return NULL;
	xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
	rc = gen_inf_nfe(writer, nfe);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	char *URI = malloc(sizeof(char) * (strlen(nfe->idnfe->chave) +
		strlen(ID_PREFIX) + 2));
	strcpy(URI, "#");
	strcat(URI, ID_PREFIX);
	strcat(URI, nfe->idnfe->chave);
	rc = sign_xml(doc, key, cert, URI);
	if(rc)
		return NULL;
	xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0);
	nfe->xml = strdup((char*)buf->content);
	return (char*)buf->content;
}
Пример #6
0
//----------------------------------------------------------------------------
// Starts a new file and prepares it to be written
//----------------------------------------------------------------------------
bool CXMLTreeNode::StartNewFile(const char* _pszFileName)
{
  assert(_pszFileName);
  
  m_bIsOk = false;
  
  if (_pszFileName)
  {
    m_pszFileName = _pszFileName;

    // Create a new XmlWriter for DOM, with no compression.
    m_pWriter = xmlNewTextWriterDoc(&m_pDoc, 0);
    assert(m_pWriter);

    if (m_pWriter)
    {
      // Start the document with the xml default for the version, encoding ISO 8858-1 and the default for the standalone declaration.
      int rc = xmlTextWriterStartDocument(m_pWriter, NULL, MY_ENCODING, NULL);
      assert(rc >= 0);
      if (rc >= 0) 
      {
        m_bIsOk = true;
        return true;
      }
    }
  }

  Release();

  return false;
}
Пример #7
0
/**
 * Write the xml document out to an xmlDoc, for use in xslt
 * @param   xml The xml document
 * @param   doc A pointer to an xmlDocPtr
 * @return  @c TRUE if successful, @c FALSE if an error occurs.
 * @ingroup EXML_Write_Group
 */
int exml_doc_write( EXML *xml, xmlDocPtr *doc )
{
	xmlTextWriterPtr writer;

	CHECK_PARAM_POINTER_RETURN("xml", xml, FALSE);

	writer = xmlNewTextWriterDoc(doc, 0);

	return _exml_write(xml, writer);
}
Пример #8
0
void xml_new_writer(struct xml_writer_private *priv)
{
	priv->xw = xmlNewTextWriterDoc(&(priv->doc), 0);
	if (!priv->xw)
		fatalx("lldpctl", "cannot create xml writer");

	xmlTextWriterSetIndent(priv->xw, 4);

	if (xmlTextWriterStartDocument(priv->xw, NULL, "UTF-8", NULL) < 0 )
		fatalx("lldpctl", "cannot start xml document");
}
Пример #9
0
/**
 * @brief Saves all the star planets.
 *
 *    @return 0 on success.
 */
int dpl_saveAll (void)
{
    int i;
    /*char file[PATH_MAX];*/
    xmlDocPtr doc;
    xmlTextWriterPtr writer;
    int np;
    const Planet *p;
    const Planet **sorted_p;

    /* Create the writer. */
    writer = xmlNewTextWriterDoc(&doc, 0);
    if (writer == NULL) {
        WARN("testXmlwriterDoc: Error creating the xml writer");
        return -1;
    }

    /* Set the writer parameters. */
    xmlw_setParams( writer );

    /* Start writer. */
    xmlw_start(writer);
    xmlw_startElem( writer, "Assets" );

    /* Sort planets. */
    p        = planet_getAll( &np );
    sorted_p = malloc( sizeof(Planet*) * np );
    for (i=0; i<np; i++)
        sorted_p[i]  = &p[i];
    qsort( sorted_p, np, sizeof(Planet*), dpl_compPlanet );

    /* Write planets. */
    for (i=0; i<np; i++)
        dpl_savePlanet( writer, sorted_p[i] );

    /* Clean up sorted planet.s */
    free(sorted_p);

    /* End writer. */
    xmlw_endElem( writer ); /* "Assets" */
    xmlw_done( writer );

    /* No need for writer anymore. */
    xmlFreeTextWriter( writer );

    /* Write data. */
    xmlSaveFileEnc( "asset.xml", doc, "UTF-8" );

    /* Clean up. */
    xmlFreeDoc(doc);

    return 0;
}
Пример #10
0
char *gen_lote_xml(LOTE *lote, EVP_PKEY *key, X509 *cert){
	int rc;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlBufferPtr buf = xmlBufferCreate();

	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
		return NULL;
	xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
	rc = xmlTextWriterStartElement(writer, BAD_CAST "enviNFe");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
			BAD_CAST "http://www.portalfiscal.inf.br/nfe");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao",
			BAD_CAST NFE_VERSAO);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "idLote",
			"%d", lote->id);
	if (rc < 0)
		return NULL;
	int indSinc = lote->qtd == 1? 1 : 0;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "indSinc",
			"%d", indSinc);
	if (rc < 0)
		return NULL;
	int i;
	LOTE_ITEM *it = lote->nfes;
	for (i = 0; i < lote->qtd; i++){
		char *xml;
		xml = generate_xml(it->nfe, key, cert);
		printf("%s\n", xml);
		rc = xmlTextWriterWriteRaw(writer, BAD_CAST xml);
		if (rc < 0)
			return NULL;
		it = it->next;
	}
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0);
	return (char*)buf->content;
}
Пример #11
0
void ZXMLDoc::begin()
{
	/* Create a new XmlWriter for DOM, with no compression. */
    writer = xmlNewTextWriterDoc(&doc, 0);
    if (writer == NULL) {
        printf("testXmlwriterDoc: Error creating the xml writer\n");
        return;
    }
	
	/* Start the document with the xml default for the version,
     * encoding ISO 8859-1 and the default for the standalone
     * declaration. */
    rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartDocument\n");
        return;
    }
}
Пример #12
0
char *gen_cons_status(int ambiente, int cuf){
	int rc;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlBufferPtr buf = xmlBufferCreate();
	
	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL) {
		printf("Error NewDoc");
		return NULL;
	}
	xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL);
	rc = xmlTextWriterStartElement(writer, BAD_CAST "consStatServ");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
			BAD_CAST "http://www.portalfiscal.inf.br/nfe");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao",
			BAD_CAST NFE_VERSAO);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tpAmb",
			"%d", ambiente);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "cUF",
			"%d", cuf);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "xServ",
			"%s", "STATUS");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0);
	return (char*) buf->content;
}
Пример #13
0
char *gen_cons_nfe(LOTE *lote, int ambiente){
	int rc;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlBufferPtr buf = xmlBufferCreate();
	
	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
		return NULL;
	xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL);
	rc = xmlTextWriterStartElement(writer, BAD_CAST "consReciNFe");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
			BAD_CAST "http://www.portalfiscal.inf.br/nfe");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao",
			BAD_CAST NFE_VERSAO);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tpAmb",
			"%d", ambiente);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "nRec",
			"%s", lote->recibo);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0);
	return (char*)buf->content;
}
Пример #14
0
static void createSBOLWriter() {
	INDENT = 0;
	WRITER = xmlNewTextWriterDoc(&OUTPUT, 0);
	xmlTextWriterSetIndentString(WRITER,xmlCharStrdup("\t"));
	xmlTextWriterSetIndent(WRITER, INDENT);
}
Пример #15
0
/* ========================================================================= */
void ghmm_xmlfile_write(ghmm_xmlfile* f, const char *file) {
#define CUR_PROC "ghmm_xmlfile_write"
  int rc, i;
  xmlTextWriterPtr writer;
  xmlDocPtr doc;

  /*
   * this initialize the library and check potential ABI mismatches
   * between the version it was compiled for and the actual shared
   * library used.
   */
  LIBXML_TEST_VERSION

    xmlSubstituteEntitiesDefault(1);

  /* Create a new XmlWriter for DOM, with no compression. */
  writer = xmlNewTextWriterDoc(&doc, 0);
  if (writer == NULL) {
    GHMM_LOG(LERROR, "can not create the xml writer");
    goto STOP;
  }

  /* indenting writer to circumvent no space between SYSTEM and PUBLIC identifier */
  xmlTextWriterSetIndent(writer, 1);

  /* Start the document with the xml default for the version,
   * encoding ISO 8859-1 and the default for the standalone
   * declaration. */
  rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
  if (rc < 0) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartDocument\n");
    goto STOP;
  }

  /* Set the Document type declaration at the beginning of the document */
  rc = xmlTextWriterWriteDTD(writer, BAD_CAST "mixture",
                             BAD_CAST "-//ghmm.org//DOCUMENT ghmm V"DTD_VERSION"//EN",
                             BAD_CAST "http://ghmm.sourceforge.net/xml/"DTD_VERSION"/ghmm.dtd",
                             NULL);
  if (rc < 0) {
    GHMM_LOG(LERROR, "failed to write the DocType"); goto STOP;}

  /* start real contents */
  if (0 > xmlTextWriterStartElement(writer, BAD_CAST "mixture")) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (mixture)");
    goto STOP;;
  }

  if (xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST DTD_VERSION) < 0) {
    GHMM_LOG(LERROR, "failed to write version 1.0"); goto STOP;}

  if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "noComponents", "%d", f->noModels)) {
    GHMM_LOG(LERROR, "failed to write the number of components"); goto STOP;}

  /* write all models */
  for (i=0; i<f->noModels; i++)
    writeHMM(writer, f, i);

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

  xmlFreeTextWriter(writer);

  xmlSaveFormatFileEnc(file, doc, MY_ENCODING, 1);

STOP:
  xmlFreeDoc(doc);

  /*
   * Cleanup function for the XML library.
   */
  xmlCleanupParser();
  /*
   * this is to debug memory for regression tests
   */
  xmlMemoryDump();
#undef CUR_PROC
}
AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL
axiom_xml_writer_create_for_memory(
    const axutil_env_t * env,
    axis2_char_t * encoding,
    int is_prefix_default,
    int compression,
    int type)
{
    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
        sizeof(axis2_libxml2_writer_wrapper_impl_t));
    if(!writer_impl)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create writer wrapper");
        return NULL;
    }

    writer_impl->encoding = NULL;
    writer_impl->buffer = NULL;
    writer_impl->doc = NULL;
    writer_impl->in_empty_element = AXIS2_FALSE;
    writer_impl->in_start_element = AXIS2_FALSE;
    writer_impl->stack = NULL;
    writer_impl->uri_prefix_map = NULL;
    writer_impl->default_lang_namespace = NULL;
    writer_impl->compression = compression;

    if(AXIS2_XML_PARSER_TYPE_BUFFER == type)
    {
        writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_BUFFER;
        writer_impl->buffer = xmlBufferCreate();
        if(!(writer_impl->buffer))
        {
            axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "No memory. Cannot create a buffer for writer wrapper");
            return NULL;
        }

        writer_impl->xml_writer = xmlNewTextWriterMemory(writer_impl->buffer, 0);
    }
    else if(AXIS2_XML_PARSER_TYPE_DOC == type)
    {
        writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_DOC;
        writer_impl->xml_writer = xmlNewTextWriterDoc(&writer_impl->doc, 0);
    }
    else
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, AXIS2_FAILURE);
        return NULL;
    }

    if(!(writer_impl->xml_writer))
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE);
        return NULL;
    }

    if(encoding)
    {
        writer_impl->encoding = axutil_strdup(env, encoding);
    }
    else
    {
        writer_impl->encoding = axutil_strdup(env, ENCODING);
    }

    writer_impl->uri_prefix_map = axutil_hash_make(env);
    if(!(writer_impl->uri_prefix_map))
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix hash map");
        return NULL;
    }
    writer_impl->stack = axutil_stack_create(env);
    if(!(writer_impl->stack))
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "No memory. Cannot create the stack for writer wrapper");
        return NULL;
    }

    writer_impl->writer.ops = &axiom_xml_writer_ops_var;

    return &(writer_impl->writer);
}
void CSaveSceneView::EngineSetup(void)
{
	Ogre::Root *Root = ((CSaveSceneApp*)AfxGetApp())->m_Engine->GetRoot();
	Ogre::SceneManager *SceneManager = NULL;
	SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "SaveScene");
 
    //
    // Create a render window
    // This window should be the current ChildView window using the externalWindowHandle
    // value pair option.
    //

    Ogre::NameValuePairList parms;
    parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
    parms["vsync"] = "true";

	CRect   rect;
    GetClientRect(&rect);
	Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("SaveScene");

	if (RenderWindow == NULL)
	{
	try
	{
		m_RenderWindow = Root->createRenderWindow("SaveScene", rect.Width(), rect.Height(), false, &parms);
	}
    catch(...)
	{
		MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
		exit(EXIT_SUCCESS);
	}
	}
// Load resources
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Create the camera
    m_Camera = SceneManager->createCamera("Camera");
    m_Camera->setNearClipDistance(0.5);
	m_Camera->setFarClipDistance(5000); 
	m_Camera->setCastShadows(false);
	m_Camera->setUseRenderingDistance(true);
	m_Camera->setPosition(Ogre::Vector3(200.0, 50.0, 100.0));
	Ogre::SceneNode *CameraNode = NULL;
	CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");
	CameraNode->attachObject(m_Camera);

	Ogre::Viewport* Viewport = NULL;
	
	if (0 == m_RenderWindow->getNumViewports())
	{
		Viewport = m_RenderWindow->addViewport(m_Camera);
		Viewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f));
	}

    // Alter the camera aspect ratio to match the viewport
    m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));

	Ogre::Entity *RobotEntity = SceneManager->createEntity("Robot", "robot.mesh");
	Ogre::SceneNode *RobotNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	RobotNode->attachObject(RobotEntity);


	Ogre::AxisAlignedBox Box = RobotEntity->getBoundingBox();
	Ogre::Vector3 Center = Box.getCenter();
	m_Camera->lookAt(Center);

	int rc;

    xmlDocPtr doc;
   // Create a new Xmlm_XmlWriter for DOM, with no compression.
    m_XmlWriter = xmlNewTextWriterDoc(&doc, 0);
   // Start the document with the xml default for the version,
   // encoding ISO 8859-1 and the default for the standalone
   // declaration.
    xmlTextWriterStartDocument(m_XmlWriter, NULL, MY_ENCODING, NULL);
	
	SceneExplore(SceneManager);
   
	xmlTextWriterEndDocument(m_XmlWriter);
	xmlFreeTextWriter(m_XmlWriter);
    xmlSaveFileEnc("1.scene", doc, MY_ENCODING);
    xmlFreeDoc(doc);
}
Пример #18
0
gboolean
analyzer_create_mpeg2video_frame_xml (GstMpegVideoMeta * mpeg_meta,
    gchar * location, gint frame_num, Mpeg2Headers * mpeg2_hdrs)
{
  xmlTextWriterPtr writer;
  xmlDocPtr doc;
  xmlBufferPtr buf;
  xmlChar *tmp;
  gchar *file_name;
  gchar *name;
  int fd, i;
  GstMpegVideoSequenceHdr *sequencehdr = NULL;
  GstMpegVideoSequenceExt *sequenceext = NULL;
  GstMpegVideoSequenceDisplayExt *sequencedispext = NULL;
  GstMpegVideoQuantMatrixExt *quantext = NULL;

  if (!mpeg_meta)
    return FALSE;

  xmlKeepBlanksDefault (0);

  writer = xmlNewTextWriterDoc (&doc, 0);
  if (!writer) {
    GST_ERROR ("Error: creating xml text writer \n");
    return FALSE;
  }

  if (xmlTextWriterStartDocument (writer, NULL, "UTF-8", NULL) < 0) {
    GST_ERROR ("Error: xmlTextWriterStartDocument");
    return FALSE;
  }

  if (xmlTextWriterStartElement (writer, (xmlChar *) "mpeg2") < 0) {
    GST_ERROR ("Error: Failed to start the new element (root element) mpeg2");
    return FALSE;
  }

  if (xmlTextWriterWriteComment (writer,
          (xmlChar *) "Data parssed from the mpeg2 stream") < 0) {
    g_error ("Error: Failed to write the comment \n");
    return FALSE;
  }

  /* Each time we save the gerneral headers, which will get appended for
     each frame xml files */

  /* SequenceHdr */
  if (mpeg_meta->sequencehdr) {
    sequencehdr = mpeg_meta->sequencehdr;

    if (mpeg2_hdrs->sequencehdr)
      g_slice_free (GstMpegVideoSequenceHdr, mpeg2_hdrs->sequencehdr);
    mpeg2_hdrs->sequencehdr =
        g_slice_dup (GstMpegVideoSequenceHdr, mpeg_meta->sequencehdr);

  } else if (mpeg2_hdrs->sequencehdr)
    sequencehdr = mpeg2_hdrs->sequencehdr;

  /* SequenceExtHdr */
  if (mpeg_meta->sequenceext) {
    sequenceext = mpeg_meta->sequenceext;

    if (mpeg2_hdrs->sequenceext)
      g_slice_free (GstMpegVideoSequenceExt, mpeg2_hdrs->sequenceext);
    mpeg2_hdrs->sequenceext =
        g_slice_dup (GstMpegVideoSequenceExt, mpeg_meta->sequenceext);

  } else if (mpeg2_hdrs->sequenceext)
    sequenceext = mpeg2_hdrs->sequenceext;

  /* SequenceDisplayExt */
  if (mpeg_meta->sequencedispext) {
    sequencedispext = mpeg_meta->sequencedispext;

    if (mpeg2_hdrs->sequencedispext)
      g_slice_free (GstMpegVideoSequenceDisplayExt,
          mpeg2_hdrs->sequencedispext);
    mpeg2_hdrs->sequencedispext =
        g_slice_dup (GstMpegVideoSequenceDisplayExt,
        mpeg_meta->sequencedispext);

  } else if (mpeg2_hdrs->sequencedispext)
    sequencedispext = mpeg2_hdrs->sequencedispext;

  /* QuantMatrixExt */
  if (mpeg_meta->quantext) {
    quantext = mpeg_meta->quantext;

    if (mpeg2_hdrs->quantext)
      g_slice_free (GstMpegVideoQuantMatrixExt, mpeg2_hdrs->quantext);
    mpeg2_hdrs->quantext =
        g_slice_dup (GstMpegVideoQuantMatrixExt, mpeg_meta->quantext);

  } else if (mpeg2_hdrs->quantext)
    quantext = mpeg2_hdrs->quantext;

  /*Create xmls for each headers */

  if (sequencehdr)
    if (!create_seq_hdr_xml (writer, sequencehdr))
      return FALSE;

  if (sequenceext) {
    if (!create_seq_ext_xml (writer, sequenceext))
      return FALSE;
  }

  if (mpeg_meta->sequencedispext) {
    if (!create_seq_disp_ext_xml (writer, sequencedispext))
      return FALSE;
  }

  if (quantext) {
    if (!create_quant_ext_xml (writer, quantext))
      return FALSE;
  }
#if 0
  if (mpeg_meta->gophdr) {
    if (!create_gop_hdr_xml (writer, mpeg_meta->gophdr))
      return FALSE;
  }
#endif
  if (mpeg_meta->pichdr) {
    if (!create_pic_hdr_xml (writer, mpeg_meta->pichdr))
      return FALSE;
  }

  if (mpeg_meta->picext) {
    if (!create_pic_ext_xml (writer, mpeg_meta->picext))
      return FALSE;
  }
#if 0
  if (mpeg_meta->slice_info_array) {
    for (i = 0; i < mpeg_meta->slice_info_array->len; i++) {
      GstMpegVideoMetaSliceInfo *slice_info = NULL;
      slice_info =
          &g_array_index (mpeg_meta->slice_info_array,
          GstMpegVideoMetaSliceInfo, i);
      if (!slice_info) {
        g_error ("Failed to get slice details from meta.. \n");
        return FALSE;
      }
      if (!create_slice_hdr_xml (writer, slice_info, i))
        return FALSE;
    }
  }
#endif
  if (xmlTextWriterEndElement (writer) < 0) {
    g_error ("Error: Failed to end mpeg2 root element \n");
    return FALSE;
  }

  if (xmlTextWriterEndDocument (writer) < 0) {
    g_error ("Error: Ending document \n");
    return FALSE;
  }

  xmlFreeTextWriter (writer);

  /* create a new xml file for each frame */
  name = g_strdup_printf ("mpeg2-%d.xml", frame_num);
  file_name = g_build_filename (location, "xml", name, NULL);
  GST_LOG ("Created a New xml file %s to dump the parsed info", file_name);

  xmlSaveFormatFile (file_name, doc, 1);

  if (name)
    g_free (name);
  if (file_name)
    g_free (file_name);

  return TRUE;
}
Пример #19
0
Файл: save.c Проект: isfos/naev
/**
 * @brief Saves the current game.
 *
 *    @return 0 on success.
 */
int save_all (void)
{
   char file[PATH_MAX];
   xmlDocPtr doc;
   xmlTextWriterPtr writer;

   /* Create the writer. */
   writer = xmlNewTextWriterDoc(&doc, conf.save_compress);
   if (writer == NULL) {
      ERR("testXmlwriterDoc: Error creating the xml writer");
      return -1;
   }

   /* Set the writer parameters. */
   xmlTextWriterSetIndentString(writer, (const xmlChar*)" ");
   xmlTextWriterSetIndent(writer, 1);

   /* Start element. */
   xmlw_start(writer);
   xmlw_startElem(writer,"naev_save");

   /* Save the version and such. */
   xmlw_startElem(writer,"version");
   xmlw_elem( writer, "naev", "%d.%d.%d", VMAJOR, VMINOR, VREV );
   xmlw_elem( writer, "data", "%s", ndata_name() );
   xmlw_endElem(writer); /* "version" */

   /* Save the data. */
   if (save_data(writer) < 0) {
      ERR("Trying to save game data");
      goto err_writer;
   }

   /* Finish element. */
   xmlw_endElem(writer); /* "naev_save" */
   xmlw_done(writer);

   /* Write to file. */
   if (nfile_dirMakeExist("%ssaves", nfile_basePath()) < 0) {
      WARN("Aborting save...");
      goto err_writer;
   }
   snprintf(file, PATH_MAX, "%ssaves/%s.ns", nfile_basePath(), player_name);

   /* Back up old savegame. */
   if (nfile_backupIfExists(file) < 0) {
      WARN("Aborting save...");
      goto err_writer;
   }

   /* Critical section, if crashes here player's game gets corrupted.
    * Luckily we have a copy just in case... */
   xmlFreeTextWriter(writer);
   if (xmlSaveFileEnc(file, doc, "UTF-8") < 0) {
      WARN("Failed to write savegame!  You'll most likely have to restore it by copying your backup savegame over your current savegame.");
      goto err;
   }
   xmlFreeDoc(doc);

   return 0;

err_writer:
   xmlFreeTextWriter(writer);
err:
   xmlFreeDoc(doc);
   return -1;
}
Пример #20
0
/**
 * gxml_new_text_writer_doc:
 *
 * Deprecated: 0.15
 */
xmlTextWriterPtr gxml_new_text_writer_doc (xmlDoc** doc)
{
  g_return_val_if_fail (doc != NULL, NULL);
  return xmlNewTextWriterDoc (doc, 0);
}
Пример #21
0
int write_cpl(opendcp_t *opendcp, cpl_t *cpl) {
    int a,r, rc;
    struct stat st;
    xmlIndentTreeOutput = 1;
    xmlDocPtr        doc; 
    xmlTextWriterPtr xml;

    /* create XML document */
    xml = xmlNewTextWriterDoc(&doc,0);

    /* cpl start */
    rc = xmlTextWriterStartDocument(xml, NULL, XML_ENCODING, NULL);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterStartDocument failed");
        return DCP_FATAL;
    }

    xmlTextWriterStartElement(xml, BAD_CAST "CompositionPlaylist");
    xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns", BAD_CAST NS_CPL[opendcp->ns]);
    if (opendcp->xml_signature.sign) {
        xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns:dsig", BAD_CAST DS_DSIG);
    }

    /* cpl attributes */
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",cpl->uuid);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "AnnotationText","%s",cpl->annotation);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "IssueDate","%s",cpl->timestamp);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Creator","%s",cpl->creator);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "ContentTitleText","%s",cpl->title);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "ContentKind","%s",cpl->kind);

    /* content version */
    if (opendcp->ns == XML_NS_SMPTE) {
        xmlTextWriterStartElement(xml, BAD_CAST "ContentVersion"); 
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s_%s","urn:uri:",cpl->uuid,cpl->timestamp);
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "LabelText","%s_%s",cpl->uuid,cpl->timestamp);
        xmlTextWriterEndElement(xml);
    }

    /* rating */
    xmlTextWriterStartElement(xml, BAD_CAST "RatingList");
    if (strcmp(cpl->rating,"")) {
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Agency","%s",RATING_AGENCY[1]);
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Label","%s",cpl->rating);
    }
    xmlTextWriterEndElement(xml);

    /* reel(s) Start */
    xmlTextWriterStartElement(xml, BAD_CAST "ReelList");
    for (r=0;r<cpl->reel_count;r++) {
        reel_t reel = cpl->reel[r];
        xmlTextWriterStartElement(xml, BAD_CAST "Reel");
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",reel.uuid);
        xmlTextWriterStartElement(xml, BAD_CAST "AssetList");

        /* Asset(s) Start */
        for (a=0;a<cpl->reel[r].asset_count;a++) {
            asset_t asset = cpl->reel[r].asset[a];
            if (asset.essence_class == ACT_PICTURE) {
                if (asset.stereoscopic) {
                    xmlTextWriterStartElement(xml, BAD_CAST "msp-cpl:MainStereoscopicPicture");
                    xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns:msp-cpl", BAD_CAST NS_CPL_3D[opendcp->ns]);
                } else {
                    xmlTextWriterStartElement(xml, BAD_CAST "MainPicture");
                }
            }
            if (asset.essence_class == ACT_SOUND) {
                xmlTextWriterStartElement(xml, BAD_CAST "MainSound");
            }
            if (asset.essence_class == ACT_TIMED_TEXT) {
                xmlTextWriterStartElement(xml, BAD_CAST "MainSubtitle");
            }

            xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",asset.uuid);
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "AnnotationText","%s",asset.annotation);
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "EditRate","%s",asset.edit_rate);
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "IntrinsicDuration","%d",asset.intrinsic_duration);
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "EntryPoint","%d",asset.entry_point);
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "Duration","%d",asset.duration);

            if (asset.essence_class == ACT_PICTURE) {
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "FrameRate","%s",asset.frame_rate);
                if (opendcp->ns == XML_NS_SMPTE) {
                    xmlTextWriterWriteFormatElement(xml, BAD_CAST "ScreenAspectRatio","%s",asset.aspect_ratio);
                } else {
                    xmlTextWriterWriteFormatElement(xml, BAD_CAST "ScreenAspectRatio","%s",get_aspect_ratio(asset.aspect_ratio));
                }
            }

            if ( opendcp->xml.digest_flag ) {
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Hash","%s",asset.digest);
            }
            
            xmlTextWriterEndElement(xml); /* end asset */
        }
     
        xmlTextWriterEndElement(xml);     /* end assetlist */
        xmlTextWriterEndElement(xml);     /* end reel */
    }
    xmlTextWriterEndElement(xml);         /* end reel list */

#ifdef XMLSEC
    if (opendcp->xml_signature.sign) {
        write_dsig_template(opendcp, xml);
    }
#endif

    xmlTextWriterEndElement(xml);         /* end compositionplaylist */

    rc = xmlTextWriterEndDocument(xml);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterEndDocument failed %s",cpl->filename);
        return DCP_FATAL;
    }

    xmlFreeTextWriter(xml);
    xmlSaveFormatFile(cpl->filename, doc, 1);
    xmlFreeDoc(doc);

#ifdef XMLSEC
    /* sign the XML file */
    if (opendcp->xml_signature.sign) {
        xml_sign(opendcp, cpl->filename);
    }
#endif

    /* store CPL file size */
    dcp_log(LOG_INFO,"Writing CPL file info");
    stat(cpl->filename, &st);
    sprintf(cpl->size,"%"PRIu64,st.st_size);
    calculate_digest(cpl->filename,cpl->digest);
    
    return DCP_SUCCESS;
}
Пример #22
0
int write_assetmap(opendcp_t *opendcp) {
    xmlIndentTreeOutput = 1;
    xmlDocPtr        doc;
    xmlTextWriterPtr xml;
    int              a,c,r,rc;
    char             uuid_s[40];
    cpl_t            cpl;
    reel_t           reel;

    /* generate assetmap UUID */
    uuid_random(uuid_s);

    dcp_log(LOG_INFO,"Writing ASSETMAP file %.256s",opendcp->assetmap.filename);

    /* create XML document */
    xml = xmlNewTextWriterDoc(&doc,0);

    /* assetmap XML Start */
    rc = xmlTextWriterStartDocument(xml, NULL, XML_ENCODING, NULL);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterStartDocument failed");
        return DCP_FATAL;
    }

    xmlTextWriterStartElement(xml, BAD_CAST "AssetMap");
    xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns", BAD_CAST NS_AM[opendcp->ns]);

    /* assetmap attributes */
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",uuid_s);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Creator","%s",opendcp->xml.creator);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "VolumeCount","%d",1);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "IssueDate","%s",opendcp->xml.timestamp);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Issuer","%s",opendcp->xml.issuer);

    xmlTextWriterStartElement(xml, BAD_CAST "AssetList");

    dcp_log(LOG_INFO,"Writing ASSETMAP PKL");

    /* PKL */
    xmlTextWriterStartElement(xml, BAD_CAST "Asset");
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",opendcp->pkl[0].uuid);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "PackingList","%s","true");
    xmlTextWriterStartElement(xml, BAD_CAST "ChunkList");
    xmlTextWriterStartElement(xml, BAD_CAST "Chunk");
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Path","%s",basename(opendcp->pkl[0].filename));
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "VolumeIndex","%d",1);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Offset","%d",0);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Length","%s",opendcp->pkl[0].size);
    xmlTextWriterEndElement(xml); /* end chunk */
    xmlTextWriterEndElement(xml); /* end chunklist */
    xmlTextWriterEndElement(xml); /* end pkl asset */
  
    dcp_log(LOG_INFO,"Writing ASSETMAP CPLs");

    /* CPL */
    for (c=0;c<opendcp->pkl[0].cpl_count;c++) {
        cpl = opendcp->pkl[0].cpl[c];
        xmlTextWriterStartElement(xml, BAD_CAST "Asset");
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",cpl.uuid);
        xmlTextWriterStartElement(xml, BAD_CAST "ChunkList");
        xmlTextWriterStartElement(xml, BAD_CAST "Chunk");
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Path","%s",basename(cpl.filename));
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "VolumeIndex","%d",1);
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Offset","%d",0);
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Length","%s",cpl.size);
        xmlTextWriterEndElement(xml); /* end chunk */
        xmlTextWriterEndElement(xml); /* end chunklist */
        xmlTextWriterEndElement(xml); /* end cpl asset */

        /* assets(s) start */
        for (r=0;r<cpl.reel_count;r++) {
            reel = cpl.reel[r];
            for (a=0;a<reel.asset_count;a++) {
                asset_t asset = reel.asset[a];
                xmlTextWriterStartElement(xml, BAD_CAST "Asset");
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",asset.uuid);
                xmlTextWriterStartElement(xml, BAD_CAST "ChunkList");
                xmlTextWriterStartElement(xml, BAD_CAST "Chunk");
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Path","%s",basename(asset.filename));
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "VolumeIndex","%d",1);
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Offset","%d",0);
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Length","%s",asset.size);
                xmlTextWriterEndElement(xml); /* end chunk */
                xmlTextWriterEndElement(xml); /* end chunklist */
                xmlTextWriterEndElement(xml); /* end cpl asset */
            }
        }
    }

    xmlTextWriterEndElement(xml); /* end assetlist */
    xmlTextWriterEndElement(xml); /* end assetmap */

    rc = xmlTextWriterEndDocument(xml);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterEndDocument failed %s",opendcp->assetmap.filename);
        return DCP_FATAL;
    }

    xmlFreeTextWriter(xml);
    xmlSaveFormatFile(opendcp->assetmap.filename, doc, 1);
    xmlFreeDoc(doc);

    return DCP_SUCCESS;
}
Пример #23
0
int write_pkl(opendcp_t *opendcp, pkl_t *pkl) {
    int a,r,c,rc;
    struct stat st;
    xmlIndentTreeOutput = 1;
    xmlDocPtr        doc;
    xmlTextWriterPtr xml;

    /* create XML document */
    xml = xmlNewTextWriterDoc(&doc,0);

    /* pkl start */
    rc = xmlTextWriterStartDocument(xml, NULL, XML_ENCODING, NULL);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterStartDocument failed");
        return DCP_FATAL;
    }

    xmlTextWriterStartElement(xml, BAD_CAST "PackingList");
    xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns", BAD_CAST NS_PKL[opendcp->ns]);
    if (opendcp->xml_signature.sign) {
        xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns:dsig", BAD_CAST DS_DSIG);
    }

    /* cpl attributes */
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",pkl->uuid);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "AnnotationText","%s",pkl->annotation);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "IssueDate","%s",opendcp->xml.timestamp);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Issuer","%s",opendcp->xml.issuer);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Creator","%s",opendcp->xml.creator);

    dcp_log(LOG_INFO,"CPLS: %d",pkl->cpl_count);

    /* asset(s) Start */
    xmlTextWriterStartElement(xml, BAD_CAST "AssetList");
    for (c=0;c<pkl->cpl_count;c++) {
        cpl_t cpl = pkl->cpl[c];
        dcp_log(LOG_INFO,"REELS: %d",cpl.reel_count);
        for (r=0;r<cpl.reel_count;r++) {
            reel_t reel = cpl.reel[r];

            for (a=0;a<reel.asset_count;a++) {
                asset_t asset = reel.asset[a];
                xmlTextWriterStartElement(xml, BAD_CAST "Asset");
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",asset.uuid);
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "AnnotationText","%s",asset.annotation);
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Hash","%s",asset.digest);
                xmlTextWriterWriteFormatElement(xml, BAD_CAST "Size","%s",asset.size);
                if (opendcp->ns == XML_NS_SMPTE) {
                    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Type","%s","application/mxf");
                } else {
                    if (asset.essence_class == ACT_PICTURE) {
                        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Type","%s","application/x-smpte-mxf;asdcpKind=Picture");
                    }
                    if (asset.essence_class == ACT_SOUND) {
                        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Type","%s","application/x-smpte-mxf;asdcpKind=Sound");
                    }
                    if (asset.essence_class == ACT_TIMED_TEXT) {
                        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Type","%s","application/x-smpte-mxf;asdcpKind=Subtitle");
                    }
                }
                xmlTextWriterEndElement(xml);      /* end asset */
            }
        }

        /* cpl */
        xmlTextWriterStartElement(xml, BAD_CAST "Asset");
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Id","%s%s","urn:uuid:",cpl.uuid);
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Hash","%s",cpl.digest);
        xmlTextWriterWriteFormatElement(xml, BAD_CAST "Size","%s",cpl.size);
        if (opendcp->ns == XML_NS_SMPTE) {
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "Type","%s","text/xml");
        } else {
            xmlTextWriterWriteFormatElement(xml, BAD_CAST "Type","%s","text/xml;asdcpKind=CPL");
        }
        xmlTextWriterEndElement(xml);      /* end cpl asset */
    }
    xmlTextWriterEndElement(xml);      /* end assetlist */

#ifdef XMLSEC
    if (opendcp->xml_signature.sign) {
        write_dsig_template(opendcp, xml);
    }
#endif

    xmlTextWriterEndElement(xml);      /* end packinglist */

    rc = xmlTextWriterEndDocument(xml);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterEndDocument failed %s",pkl->filename);
        return DCP_FATAL;
    }

    xmlFreeTextWriter(xml);
    xmlSaveFormatFile(pkl->filename, doc, 1);
    xmlFreeDoc(doc);

#ifdef XMLSEC
    /* sign the XML file */
    if (opendcp->xml_signature.sign) {
        xml_sign(opendcp, pkl->filename);
    }
#endif

    /* store PKL file size */
    stat(pkl->filename, &st);
    sprintf(pkl->size,"%"PRIu64,st.st_size);

    return DCP_SUCCESS;
}
Пример #24
0
/**
 * @brief Saves selected systems as a map outfit file.
 *
 *    @return 0 on success.
 */
int dsys_saveMap (StarSystem **uniedit_sys, int uniedit_nsys)
{
   int i, j, k;
   xmlDocPtr doc;
   xmlTextWriterPtr writer;
   StarSystem *s;
   char file[PATH_MAX], *cleanName;

   /* Create the writer. */
   writer = xmlNewTextWriterDoc(&doc, 0);
   if (writer == NULL) {
      WARN("testXmlwriterDoc: Error creating the xml writer");
      return -1;
   }

   /* Set the writer parameters. */
   xmlw_setParams( writer );

   /* Start writer. */
   xmlw_start(writer);
   xmlw_startElem( writer, "outfit" );

   /* Attributes. */
   xmlw_attr( writer, "name", "Editor-generated Map" );

   /* General. */
   xmlw_startElem( writer, "general" );
   xmlw_elem( writer, "mass", "%d", 0 );
   xmlw_elem( writer, "price", "%d", 1000 );
   xmlw_elem( writer, "description", "%s", "This map has been created by the universe editor." );
   xmlw_elem( writer, "gfx_store", "%s", "map" );
   xmlw_endElem( writer ); /* "general" */

   xmlw_startElem( writer, "specific" );
   xmlw_attr( writer, "type", "map" );

   /* Iterate over all selected systems. Save said systems and any NORMAL jumps they might share. */
   for (i = 0; i < uniedit_nsys; i++) {
      s = uniedit_sys[i];
      xmlw_startElem( writer, "sys" );
      xmlw_attr( writer, "name", "%s", s->name );

      /* Iterate jumps and see if they lead to any other systems in our array. */
      for (j = 0; j < s->njumps; j++) {
         /* Ignore hidden and exit-only jumps. */
         if (jp_isFlag(&s->jumps[j], JP_EXITONLY ))
            continue;
         if (jp_isFlag(&s->jumps[j], JP_HIDDEN))
            continue;
         /* This is a normal jump. */
         for (k = 0; k < uniedit_nsys; k++) {
            if (s->jumps[j].target == uniedit_sys[k]) {
               xmlw_elem( writer, "jump", "%s", uniedit_sys[k]->name );
               break;
            }
         }
      }

      /* Iterate assets and add them */
      for (j = 0; j < s->nplanets; j++) {
         if (s->planets[j]->real)
            xmlw_elem( writer, "asset", "%s", s->planets[j]->name );
      }

      xmlw_endElem( writer ); /* "sys" */
   }

   xmlw_endElem( writer ); /* "specific" */
   xmlw_endElem( writer ); /* "outfit" */
   xmlw_done(writer);

   /* No need for writer anymore. */
   xmlFreeTextWriter(writer);

   /* Write data. */
   cleanName = uniedit_nameFilter( "saved map" );
   nsnprintf( file, sizeof(file), "%s/%s.xml", conf.dev_save_map, cleanName );
   xmlSaveFileEnc( file, doc, "UTF-8" );

   /* Clean up. */
   xmlFreeDoc(doc);
   free(cleanName);

   return 0;
}
Пример #25
0
/**
 * @brief Saves a star system.
 *
 *    @param writer Write to use for saving the star system.
 *    @param sys Star system to save.
 *    @return 0 on success.
 */
int dsys_saveSystem( StarSystem *sys )
{
   int i;
   xmlDocPtr doc;
   xmlTextWriterPtr writer;
   const Planet **sorted_planets;
   const JumpPoint **sorted_jumps, *jp;
   char file[PATH_MAX], *cleanName;

   /* Reconstruct jumps so jump pos are updated. */
   system_reconstructJumps(sys);

   /* Create the writer. */
   writer = xmlNewTextWriterDoc(&doc, 0);
   if (writer == NULL) {
      WARN("testXmlwriterDoc: Error creating the xml writer");
      return -1;
   }

   /* Set the writer parameters. */
   xmlw_setParams( writer );

   /* Start writer. */
   xmlw_start(writer);
   xmlw_startElem( writer, "ssys" );

   /* Attributes. */
   xmlw_attr( writer, "name", "%s", sys->name );

   /* General. */
   xmlw_startElem( writer, "general" );
   if (sys->background != NULL)
      xmlw_elem( writer, "background", "%s", sys->background );
   xmlw_elem( writer, "radius", "%f", sys->radius );
   xmlw_elem( writer, "stars", "%d", sys->stars );
   xmlw_elem( writer, "interference", "%f", sys->interference );
   xmlw_startElem( writer, "nebula" );
   xmlw_attr( writer, "volatility", "%f", sys->nebu_volatility );
   xmlw_str( writer, "%f", sys->nebu_density );
   xmlw_endElem( writer ); /* "nebula" */
   xmlw_endElem( writer ); /* "general" */

   /* Position. */
   xmlw_startElem( writer, "pos" );
   xmlw_elem( writer, "x", "%f", sys->pos.x );
   xmlw_elem( writer, "y", "%f", sys->pos.y );
   xmlw_endElem( writer ); /* "pos" */

   /* Planets. */
   sorted_planets = malloc( sizeof(Planet*) * sys->nplanets);
   memcpy( sorted_planets, sys->planets, sizeof(Planet*) * sys->nplanets );
   qsort( sorted_planets, sys->nplanets, sizeof(Planet*), dsys_compPlanet );
   xmlw_startElem( writer, "assets" );
   for (i=0; i<sys->nplanets; i++)
      xmlw_elem( writer, "asset", "%s", sorted_planets[i]->name );
   xmlw_endElem( writer ); /* "assets" */
   free(sorted_planets);

   /* Jumps. */
   sorted_jumps = malloc( sizeof(JumpPoint*) * sys->njumps );
   for (i=0; i<sys->njumps; i++)
      sorted_jumps[i] = &sys->jumps[i];
   qsort( sorted_jumps, sys->njumps, sizeof(JumpPoint*), dsys_compJump );
   xmlw_startElem( writer, "jumps" );
   for (i=0; i<sys->njumps; i++) {
      jp = sorted_jumps[i];
      xmlw_startElem( writer, "jump" );
      xmlw_attr( writer, "target", "%s", jp->target->name );
      /* Position. */
      if (!jp_isFlag( jp, JP_AUTOPOS )) {
         xmlw_startElem( writer, "pos" );
         xmlw_attr( writer, "x", "%f", jp->pos.x );
         xmlw_attr( writer, "y", "%f", jp->pos.y );
         xmlw_endElem( writer ); /* "pos" */
      }
      else
         xmlw_elemEmpty( writer, "autopos" );
      /* Radius and misc properties. */
      if (jp->radius != 200.)
         xmlw_elem( writer, "radius", "%f", jp->radius );
      /* More flags. */
      if (jp_isFlag( jp, JP_HIDDEN ))
         xmlw_elemEmpty( writer, "hidden" );
      if (jp_isFlag( jp, JP_EXITONLY ))
         xmlw_elemEmpty( writer, "exitonly" );
      xmlw_elem( writer, "hide", "%f", sqrt(jp->hide) );
      xmlw_endElem( writer ); /* "jump" */
   }
   xmlw_endElem( writer ); /* "jumps" */
   free(sorted_jumps);

   xmlw_endElem( writer ); /** "ssys" */
   xmlw_done(writer);

   /* No need for writer anymore. */
   xmlFreeTextWriter(writer);

   /* Write data. */
   cleanName = uniedit_nameFilter( sys->name );
   nsnprintf( file, sizeof(file), "%s/%s.xml", conf.dev_save_sys, cleanName );
   xmlSaveFileEnc( file, doc, "UTF-8" );

   /* Clean up. */
   xmlFreeDoc(doc);
   free(cleanName);

   return 0;
}
Пример #26
0
static isc_result_t
generatexml(ns_server_t *server, int *buflen, xmlChar **buf) {
	char boottime[sizeof "yyyy-mm-ddThh:mm:ssZ"];
	char nowstr[sizeof "yyyy-mm-ddThh:mm:ssZ"];
	isc_time_t now;
	xmlTextWriterPtr writer = NULL;
	xmlDocPtr doc = NULL;
	int xmlrc;
	dns_view_t *view;
	stats_dumparg_t dumparg;
	dns_stats_t *cachestats;
	isc_uint64_t nsstat_values[dns_nsstatscounter_max];
	isc_uint64_t resstat_values[dns_resstatscounter_max];
	isc_uint64_t zonestat_values[dns_zonestatscounter_max];
	isc_uint64_t sockstat_values[isc_sockstatscounter_max];
	isc_result_t result;

	isc_time_now(&now);
	isc_time_formatISO8601(&ns_g_boottime, boottime, sizeof boottime);
	isc_time_formatISO8601(&now, nowstr, sizeof nowstr);

	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
		goto error;
	TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL));
	TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet",
			ISC_XMLCHAR "type=\"text/xsl\" href=\"/bind9.xsl\""));
	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "isc"));
	TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version",
					 ISC_XMLCHAR "1.0"));

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "bind"));
	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "statistics"));
	TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version",
					 ISC_XMLCHAR "2.2"));

	/* Set common fields for statistics dump */
	dumparg.type = statsformat_xml;
	dumparg.arg = writer;

	/*
	 * Start by rendering the views we know of here.  For each view we
	 * know of, call its rendering function.
	 */
	view = ISC_LIST_HEAD(server->viewlist);
	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "views"));
	while (view != NULL) {
		TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "view"));

		TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"));
		TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR view->name));
		TRY0(xmlTextWriterEndElement(writer));

		TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "zones"));
		result = dns_zt_apply(view->zonetable, ISC_TRUE, zone_xmlrender,
				      writer);
		if (result != ISC_R_SUCCESS)
			goto error;
		TRY0(xmlTextWriterEndElement(writer));

		if (view->resquerystats != NULL) {
			dumparg.result = ISC_R_SUCCESS;
			dns_rdatatypestats_dump(view->resquerystats,
						rdtypestat_dump, &dumparg, 0);
			if (dumparg.result != ISC_R_SUCCESS)
				goto error;
		}

		if (view->resstats != NULL) {
			result = dump_counters(view->resstats, statsformat_xml,
					       writer, "resstat",
					       resstats_xmldesc,
					       dns_resstatscounter_max,
					       resstats_index, resstat_values,
					       ISC_STATSDUMP_VERBOSE);
			if (result != ISC_R_SUCCESS)
				goto error;
		}

		cachestats = dns_db_getrrsetstats(view->cachedb);
		if (cachestats != NULL) {
			TRY0(xmlTextWriterStartElement(writer,
						       ISC_XMLCHAR "cache"));
			TRY0(xmlTextWriterWriteAttribute(writer,
					 ISC_XMLCHAR "name",
					 ISC_XMLCHAR
					 dns_cache_getname(view->cache)));
			dumparg.result = ISC_R_SUCCESS;
			dns_rdatasetstats_dump(cachestats, rdatasetstats_dump,
					       &dumparg, 0);
			if (dumparg.result != ISC_R_SUCCESS)
				goto error;
			TRY0(xmlTextWriterEndElement(writer)); /* cache */
		}

		TRY0(xmlTextWriterEndElement(writer)); /* view */

		view = ISC_LIST_NEXT(view, link);
	}
	TRY0(xmlTextWriterEndElement(writer)); /* views */

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socketmgr"));
	isc_socketmgr_renderxml(ns_g_socketmgr, writer);
	TRY0(xmlTextWriterEndElement(writer)); /* socketmgr */

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "taskmgr"));
	isc_taskmgr_renderxml(ns_g_taskmgr, writer);
	TRY0(xmlTextWriterEndElement(writer)); /* taskmgr */

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "server"));
	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "boot-time"));
	TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR boottime));
	TRY0(xmlTextWriterEndElement(writer));
	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "current-time"));
	TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR nowstr));
	TRY0(xmlTextWriterEndElement(writer));

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "requests"));
	dumparg.result = ISC_R_SUCCESS;
	dns_opcodestats_dump(server->opcodestats, opcodestat_dump, &dumparg,
			     0);
	if (dumparg.result != ISC_R_SUCCESS)
		goto error;
	TRY0(xmlTextWriterEndElement(writer)); /* requests */

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "queries-in"));
	dumparg.result = ISC_R_SUCCESS;
	dns_rdatatypestats_dump(server->rcvquerystats, rdtypestat_dump,
				&dumparg, 0);
	if (dumparg.result != ISC_R_SUCCESS)
		goto error;
	TRY0(xmlTextWriterEndElement(writer)); /* queries-in */

	result = dump_counters(server->nsstats, statsformat_xml, writer,
			       "nsstat", nsstats_xmldesc,
				dns_nsstatscounter_max,
				nsstats_index, nsstat_values,
				ISC_STATSDUMP_VERBOSE);
	if (result != ISC_R_SUCCESS)
		goto error;

	result = dump_counters(server->zonestats, statsformat_xml, writer,
			       "zonestat", zonestats_xmldesc,
			       dns_zonestatscounter_max, zonestats_index,
			       zonestat_values, ISC_STATSDUMP_VERBOSE);
	if (result != ISC_R_SUCCESS)
		goto error;

	/*
	 * Most of the common resolver statistics entries are 0, so we don't
	 * use the verbose dump here.
	 */
	result = dump_counters(server->resolverstats, statsformat_xml, writer,
			       "resstat", resstats_xmldesc,
			       dns_resstatscounter_max, resstats_index,
			       resstat_values, 0);
	if (result != ISC_R_SUCCESS)
		goto error;

	result = dump_counters(server->sockstats, statsformat_xml, writer,
			       "sockstat", sockstats_xmldesc,
			       isc_sockstatscounter_max, sockstats_index,
			       sockstat_values, ISC_STATSDUMP_VERBOSE);
	if (result != ISC_R_SUCCESS)
		goto error;

	TRY0(xmlTextWriterEndElement(writer)); /* server */

	TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "memory"));
	isc_mem_renderxml(writer);
	TRY0(xmlTextWriterEndElement(writer)); /* memory */

	TRY0(xmlTextWriterEndElement(writer)); /* statistics */
	TRY0(xmlTextWriterEndElement(writer)); /* bind */
	TRY0(xmlTextWriterEndElement(writer)); /* isc */

	TRY0(xmlTextWriterEndDocument(writer));

	xmlFreeTextWriter(writer);

	xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 1);
	xmlFreeDoc(doc);
	return (ISC_R_SUCCESS);

 error:
	if (writer != NULL)
		xmlFreeTextWriter(writer);
	if (doc != NULL)
		xmlFreeDoc(doc);
	return (ISC_R_FAILURE);
}
Пример #27
0
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;
}
/**
 * testXmlwriterDoc:
 * @file: the output file
 *
 * test the xmlWriter interface when creating a new document
 */
void
testXmlwriterDoc(const char *file)
{
    int rc;
    xmlTextWriterPtr writer;
    xmlChar *tmp;
    xmlDocPtr doc;


    /* Create a new XmlWriter for DOM, with no compression. */
    writer = xmlNewTextWriterDoc(&doc, 0);
    if (writer == NULL) {
        printf("testXmlwriterDoc: Error creating the xml writer\n");
        return;
    }

    /* Start the document with the xml default for the version,
     * encoding ISO 8859-1 and the default for the standalone
     * declaration. */
    rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartDocument\n");
        return;
    }

    /* Start an element named "EXAMPLE". Since thist is the first
     * element, this will be the root element of the document. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write a comment as child of EXAMPLE.
     * Please observe, that the input to the xmlTextWriter functions
     * HAS to be in UTF-8, even if the output XML is encoded
     * in iso-8859-1 */
    tmp = ConvertInput("This is a comment with special chars: <äöü>",
                       MY_ENCODING);
    rc = xmlTextWriterWriteComment(writer, tmp);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteComment\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Start an element named "ORDER" as child of EXAMPLE. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Add an attribute with name "version" and value "1.0" to ORDER. */
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
                                     BAD_CAST "1.0");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteAttribute\n");
        return;
    }

    /* Add an attribute with name "xml:lang" and value "de" to ORDER. */
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
                                     BAD_CAST "de");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteAttribute\n");
        return;
    }

    /* Write a comment as child of ORDER */
    tmp = ConvertInput("<äöü>", MY_ENCODING);
    rc = xmlTextWriterWriteFormatComment(writer,
		 "This is another comment with special chars: %s",
		                         tmp);
    if (rc < 0) {
        printf
            ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatComment\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Start an element named "HEADER" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "X_ORDER_ID" as child of HEADER. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID",
                                         "%010d", 53535);
    if (rc < 0) {
        printf
            ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Write an element named "CUSTOMER_ID" as child of HEADER. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID",
                                         "%d", 1010);
    if (rc < 0) {
        printf
            ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Write an element named "NAME_1" as child of HEADER. */
    tmp = ConvertInput("Müller", MY_ENCODING);
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Write an element named "NAME_2" as child of HEADER. */
    tmp = ConvertInput("Jörg", MY_ENCODING);
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Close the element named HEADER. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Start an element named "ENTRIES" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Start an element named "ENTRY" as child of ENTRIES. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "ARTICLE" as child of ENTRY. */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
                                   BAD_CAST "<Test>");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Write an element named "ENTRY_NO" as child of ENTRY. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
                                         10);
    if (rc < 0) {
        printf
            ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Close the element named ENTRY. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Start an element named "ENTRY" as child of ENTRIES. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "ARTICLE" as child of ENTRY. */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
                                   BAD_CAST "<Test 2>");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Write an element named "ENTRY_NO" as child of ENTRY. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
                                         20);
    if (rc < 0) {
        printf
            ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Close the element named ENTRY. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Close the element named ENTRIES. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Start an element named "FOOTER" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "TEXT" as child of FOOTER. */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT",
                                   BAD_CAST "This is a text.");
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Close the element named FOOTER. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Here we could close the elements ORDER and EXAMPLE using the
     * function xmlTextWriterEndElement, but since we do not want to
     * write any other elements, we simply call xmlTextWriterEndDocument,
     * which will do all the work. */
    rc = xmlTextWriterEndDocument(writer);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterEndDocument\n");
        return;
    }

    xmlFreeTextWriter(writer);

    xmlSaveFileEnc(file, doc, MY_ENCODING);

    xmlFreeDoc(doc);
}
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;
}
Пример #30
0
void writeCurrentPatchToFile(const char *file) {
    int rc, chord_index, note_index;
    xmlTextWriterPtr writer;
    xmlChar *tmp;
    xmlDocPtr doc;

    /* Create a new XmlWriter for DOM, with no compression. */
    writer = xmlNewTextWriterDoc(&doc, 0);
    if (writer == NULL) {
        printf("writeCurrentPatchToFile: Error creating the xml writer\n");
        return;
    }

    /* Start the document with the xml default for the version,
     * encoding UTF-8 and the default for the standalone
     * declaration. */
    rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterStartDocument\n");
        return;
    }

    /* Start an element named "patch". Since thist is the first
     * element, this will be the root element of the document. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "patch");
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
        return;
    }

		/* Add an attribute with name "velocity" and value chord[i].note.velocity to note. */
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "midi_channel", "%d", midi_channel);
		if (rc < 0) {
			printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
			return;
		}

    /* Start an element named "chords". */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "chords");
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
        return;
    }

	
	for (chord_index = 0; chord_index < ALL_COLOR_COMBINATIONS; chord_index++) {
		if (chord[chord_index].size > 0) {
			/* Start an element named "chord" as child of patch. */
			rc = xmlTextWriterStartElement(writer, BAD_CAST "chord");
			if (rc < 0) {
				printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
				return;
			}

			if (chord_index & GREEN) {

				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "green", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & RED) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "red", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & YELLOW) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "yellow", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & BLUE) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "blue", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & ORANGE) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "orange", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}

			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "number_of_notes", "%d", chord[chord_index].size);
			if (rc < 0) {
				printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
				return;
			}

			for (note_index = 0; note_index < chord[chord_index].size; note_index++) {
				/* Start an element named "note" as child of chord. */
				rc = xmlTextWriterStartElement(writer, BAD_CAST "note");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
					return;
				}

				/* Add an attribute with name "note_number" and value chord[i].note.note_number to note. */
				rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "note_number", "%d", chord[chord_index].note[note_index].note_number);
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}

				/* Add an attribute with name "velocity" and value chord[i].note.velocity to note. */
				rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "velocity", "%d", chord[chord_index].note[note_index].velocity);
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
				if (chord[chord_index].note[note_index].delay != 0) {
					/* Add an attribute with name "delay" and value chord[i].note.delay to note. */
					rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "delay", "%d", chord[chord_index].note[note_index].delay);
					if (rc < 0) {
						printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
						return;
					}
				}

				/* Close the element named note. */
				rc = xmlTextWriterEndElement(writer);
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterEndElement\n");
					return;
				}
			}
			/* Close the element named chord. */
			rc = xmlTextWriterEndElement(writer);
			if (rc < 0) {
				printf("writeCurrentPatchToFile: Error at xmlTextWriterEndElement\n");
				return;
			}

		}
	}

    /* Here we could close the elements ORDER and EXAMPLE using the
     * function xmlTextWriterEndElement, but since we do not want to
     * write any other elements, we simply call xmlTextWriterEndDocument,
     * which will do all the work. */
    rc = xmlTextWriterEndDocument(writer);
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterEndDocument\n");
        return;
    }

    xmlFreeTextWriter(writer);

    xmlSaveFileEnc(file, doc, MY_ENCODING);

    xmlFreeDoc(doc);
}