Beispiel #1
0
void queryMacroFileProvider::SaveMacros(queryMacroList *macros)
{
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename((const char *)settings->GetMacrosFile().mb_str(wxConvUTF8), 0);
	if (!writer)
	{
		wxMessageBox(_("Failed to open macros file!"));
		return;
	}
	xmlTextWriterSetIndent(writer, 1);

	if ((xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) ||
	        (xmlTextWriterStartElement(writer, XML_STR("macros")) < 0))
	{
		wxMessageBox(_("Failed to write to macros file!"));
		xmlFreeTextWriter(writer);
		return;
	}

	((queryMacroList *)macros)->saveList(writer);

	if (xmlTextWriterEndDocument(writer) < -1)
	{
		wxMessageBox(_("Failed to write to macros file!"));
	}

	xmlFreeTextWriter(writer);
}
Beispiel #2
0
AEResult AEXMLWriter::CreateXML(const std::wstring& file, bool inMemory)
{
	if (m_IsReady)
	{
		AETODO("Better return code");
		return AEResult::Fail;
	}

	if (file.empty())
	{
		return AEResult::EmptyFilename;
	}

	if (inMemory)
	{
		m_XMLBuffer = xmlBufferCreate();
		if (xmlBufferCreate == nullptr) 
		{
			AETODO("Better return code");
			return AEResult::Fail;
		}

		m_XMLWriter = xmlNewTextWriterMemory(m_XMLBuffer, 0);
		if (m_XMLWriter == NULL)
		{
			CleanUp();

			AETODO("Better return code");
			return AEResult::Fail;
		}

		m_InMemory = true;
	}
	else
	{
		std::string fileStr = AE_Base::WideStr2String(file);

		m_XMLWriter = xmlNewTextWriterFilename(fileStr.c_str(), 0);
		if (m_XMLWriter == NULL)
		{
			AETODO("Better return code");
			return AEResult::Fail;
		}
	}

	int ret = xmlTextWriterStartDocument(m_XMLWriter, NULL, AE_XML_ENCODING, NULL);
	if (ret < 0)
	{
		CleanUp();

		AETODO("Better return code");
		return AEResult::Fail;
	}

	m_Filename = file;

	m_IsReady = true;

	return AEResult::Ok;
}
Beispiel #3
0
/* Private exporting functions cpe_*<structure>*_export( xmlTextWriterPtr )
 * More info in representive header file.
 * returns the type of <structure>
 */
void cpe_lang_model_export_xml(const struct cpe_lang_model *spec, const char *file)
{

	__attribute__nonnull__(spec);
	__attribute__nonnull__(file);

	// TODO: ad macro to check return value from xmlTextWriter* functions
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename(file, 0);
	if (writer == NULL) {
		oscap_setxmlerr(xmlGetLastError());
		return;
	}
	// Set properties of writer TODO: make public function to edit this ??
	xmlTextWriterSetIndent(writer, 1);
	xmlTextWriterSetIndentString(writer, BAD_CAST "    ");

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

	cpe_lang_export(spec, writer);
	xmlTextWriterEndDocument(writer);
	xmlFreeTextWriter(writer);
	if (xmlGetLastError() != NULL)
		oscap_setxmlerr(xmlGetLastError());
}
Beispiel #4
0
 void ResultWriter::InitWriter(const char * uri) {
   /* Create a new XmlWriter for uri, with no compression. */
   writer_ = xmlNewTextWriterFilename(uri, 0);
   if (writer_ == nullptr) {
     printf("testXmlwriterFilename: Error creating the xml writer\n");
     return;
   }
   int rc;
   rc = xmlTextWriterSetIndent(writer_, 1);
   if (rc < 0) {
     printf
     ("testXmlwriterFilename: Error at xmlTextWriterSetIndent\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_, nullptr, MY_ENCODING, nullptr);
   if (rc < 0) {
     printf
     ("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n");
     return;
   }
   rc = xmlTextWriterStartElement(writer_, BAD_CAST "dag");
   if (rc < 0) {
     printf
     ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
     return;
   }
 }
Beispiel #5
0
void queryFavouriteFileProvider::SaveFavourites(queryFavouriteFolder *favourites)
{
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename((const char *)settings->GetFavouritesFile().mb_str(wxConvUTF8), 0);
	if (!writer)
	{
		wxMessageBox(_("Failed to write to favourites file!"));
		return;
	}
	xmlTextWriterSetIndent(writer, 1);

	if ((xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) ||
	        (xmlTextWriterStartElement(writer, XML_STR("favourites")) < 0))
	{
		wxMessageBox(_("Failed to write to favourites file!"));
		xmlFreeTextWriter(writer);
		return;
	}

	((queryFavouriteFolder *)favourites)->saveFolder(writer);

	if (xmlTextWriterEndDocument(writer) < 0)
	{
		wxMessageBox(_("Failed to write to favourites file!"));
	}

	xmlFreeTextWriter(writer);
}
Beispiel #6
0
int generate_report(char dst_dir[DIR_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) {
	// for the xml writer, refer to http://xmlsoft.org/html/libxml-xmlwriter.html 
	
	char dst_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = "";
	strcat(dst_file, dst_dir);
	strcat(dst_file, filename);
	
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename(dst_file, 0);
	
	// set the output format of the XML file 
	xmlTextWriterSetIndent(writer, 1);
	xmlTextWriterSetIndentString(writer, "	");

	xmlTextWriterStartDocument(writer, NULL, NULL, NULL);

    /* Write an element named "X_ORDER_ID" as child of HEADER. */
   xmlTextWriterWriteFormatElement(writer, "COMMENT           ", "	in this output file, %d means NOT_PROCESSED; %d means NO_FILE; %d means ERROR; %d means OK	", MODULE_NOT_PROCESSED, NO_FILE, MODULE_ERROR, MODULE_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_GET_OPT       ", "	%d	", get_opt_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_DETECT_FILE   ", "	%d	", detect_file_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_PARSE_FILENAME", "	%d	", parse_filename_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_CREATE_DIR    ", "	%d	", create_dir_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_PARSE_XML     ", "	%d	", parse_XML_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_SAVE_XML      ", "	%d	", save_XML_OK);
//	xmlTextWriterWriteFormatElement(writer, "OCG_CALL_EMU      ", "	%d	", call_emu_OK);

	xmlTextWriterEndDocument(writer);

	xmlFreeTextWriter(writer);

	LOG_I(OCG, "A report of OCG is generated in directory \"%s\"\n\n", dst_dir);
	return MODULE_OK;
}
Beispiel #7
0
/**
 * xml_writer_set_file:
 * @writer: A #XmlWriter
 * @file: A valid local filename
 * @error: A location for a GError*
 *
 * Sets the current state of the writer to use @file.  The current state
 * must be new or cleared with xml_writer_clear().
 *
 * Return value: TRUE if the operation was successful. @error will be
 *   set in the case of an error.
 */
gboolean
xml_writer_set_file (XmlWriter    *writer,
                     const gchar  *file,
                     GError      **error)
{
  XmlWriterPrivate *priv;
  
  g_return_val_if_fail (XML_IS_WRITER (writer), FALSE);
  
  priv = writer->priv;
  
  if (writer->priv->writer)
    {
      g_set_error (error, XML_WRITER_ERROR,
                   XML_WRITER_ERROR_INVALID,
                   "Writer is not clear");
      
      return FALSE;
    }
  
  writer->priv->writer = xmlNewTextWriterFilename (file, 0);
  
  /* TODO: Check the result for a proper error message */
  
  return (writer->priv->writer != NULL);
}
AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL
axiom_xml_writer_create(
    const axutil_env_t * env,
    axis2_char_t * filename,
    axis2_char_t * encoding,
    int is_prefix_default,
    int compression)
{
    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 an XML writer wrapper");
        return NULL;
    }
    writer_impl->xml_writer = xmlNewTextWriterFilename(filename, compression);

    if(!(writer_impl->xml_writer))
    {
        AXIS2_FREE(env->allocator, writer_impl);
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE);
        return NULL;
    }
    writer_impl->buffer = NULL;
    writer_impl->encoding = NULL;
    writer_impl->compression = 0;
    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->writer_type = AXIS2_XML_PARSER_TYPE_FILE;
    writer_impl->compression = compression;

    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->writer.ops = &axiom_xml_writer_ops_var;
    return &(writer_impl->writer);
}
xmlTextWriterPtr openXMLFile(const wchar_t *_pstFilename, const wchar_t* _pstLibName)
{
    int iLen;
    xmlTextWriterPtr pWriter = NULL;;
    char *pstFilename = wide_string_to_UTF8(_pstFilename);
    char *pstLibName = wide_string_to_UTF8(_pstLibName);


    //create a writer
    pWriter = xmlNewTextWriterFilename(pstFilename, 0);
    if (pWriter == NULL)
    {
        FREE(pstFilename);
        FREE(pstLibName);
        return NULL;
    }

    //setup indentation
    xmlTextWriterSetIndent (pWriter, 1);
    xmlTextWriterSetIndentString (pWriter, (xmlChar*)"  ");

    //create a new document
    iLen = xmlTextWriterStartDocument(pWriter, NULL, DEFAULT_ENCODING, "no");
    if (iLen < 0)
    {
        closeXMLFile(pWriter);
        FREE(pstFilename);
        FREE(pstLibName);
        return NULL;
    }

    //add a node "scilablib"
    iLen = xmlTextWriterStartElement(pWriter, (xmlChar*)"scilablib");
    if (iLen < 0)
    {
        closeXMLFile(pWriter);
        FREE(pstFilename);
        FREE(pstLibName);
        return NULL;
    }

    //Add attribute "name"
    iLen = xmlTextWriterWriteAttribute(pWriter, (xmlChar*)"name", (xmlChar*)pstLibName);
    if (iLen < 0)
    {
        closeXMLFile(pWriter);
        FREE(pstFilename);
        FREE(pstLibName);
        return NULL;
    }

    FREE(pstFilename);
    FREE(pstLibName);

    return pWriter;
}
Beispiel #10
0
static void writexml(const char *name)
{
	mode = 'w';
	writer = xmlNewTextWriterFilename(name, 0);
	xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
	startnode("root");
	all_decl();
	endnode();
	xmlFreeTextWriter(writer);
}
Beispiel #11
0
/**
 * Write the xml document out to a file
 * @param   xml The xml document
 * @param   filename The xml output filename
 * @return  @c TRUE if successful, @c FALSE if an error occurs.
 * @ingroup EXML_Write_Group
 */
int exml_file_write(EXML *xml, char *filename)
{
	xmlTextWriterPtr writer;

	CHECK_PARAM_POINTER_RETURN("xml", xml, FALSE);

	writer = xmlNewTextWriterFilename(filename, 0);

	return _exml_write(xml, writer);
}
Beispiel #12
0
XMLBBoxWriter::XMLBBoxWriter(const char* filename):frameCount(0)
{
	open_success=true;
	writer = xmlNewTextWriterFilename(filename, 0);
	if (writer == NULL) {
		printf("testXmlwriterFilename: Error creating the xml writer\n");
		open_success=false;
	}
	rc=xmlTextWriterStartDocument(writer,NULL,ENCODING,NULL);
	rc=xmlTextWriterStartElement(writer, BAD_CAST "dataset");
}
Beispiel #13
0
xml_writer::xml_writer(const std::string &file_name, bool indent)
    : pimpl(new pimpl_()) {
  // allocate the text writer "object"
  pimpl->writer = xmlNewTextWriterFilename(file_name.c_str(), 0);

  // check the return value
  if (pimpl->writer == NULL) {
    throw std::runtime_error("error creating xml writer.");
  }

  init(indent);
}
Beispiel #14
0
// SAX save settings
short int settingsXmlSave(const char *filename) {

    int rc;
    xmlTextWriterPtr writer;

    // Create a new XmlWriter with no compression
    writer = xmlNewTextWriterFilename(filename, 0);
    if (writer == NULL) return 1;

    // Start document with xml default encoding ISO 8859-1
    rc = xmlTextWriterStartDocument(writer, NULL, XML_ENCODING, NULL);
    if (rc < 0) return 2;

    // Start root node "settings"
    rc = xmlTextWriterStartElement(writer, BAD_CAST "settings");
    if (rc < 0) return 2;

	// Create child node "xap"
    rc = xmlTextWriterStartElement(writer, BAD_CAST "xap");
    if (rc < 0) return 2;
    
	// Write <xap> elements
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "iface", "%s", hubConfig->interfacename);
	if (rc < 0) return 4;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "instance", "%s", hubConfig->xap_addr.instance);
	if (rc < 0) return 4;
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "hbeatf", "%d", hubConfig->xap_hbeat);
    if (rc < 0) return 4;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "uid", "%s", hubConfig->xap_uid);
    if (rc < 0) return 4;
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "port", "%d", hubConfig->xap_port);
    if (rc < 0) return 4;        
    
    // Close node "xap"
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) return 5;
    
    // Close the rest nodes pending to close
    rc = xmlTextWriterEndDocument(writer);
	if (rc < 0) return 5;

	// Free the writer
    xmlFreeTextWriter(writer);
    
    // Cleanup function for the XML library.
    xmlCleanupParser();
    
    // this is to debug memory for regression tests
    xmlMemoryDump();
    
    return 0;
}
Beispiel #15
0
int save_gpx(const char *fname,GList *save_list)
{
  time_t t=time(NULL);
  struct tm tm;
  GList *l;
  xmlTextWriterPtr writer;
  writer=xmlNewTextWriterFilename(fname,0);
  if (!writer)
    return 0;
  xmlTextWriterStartDocument(writer,NULL,"UTF-8",NULL);
  xmlTextWriterStartElement(writer,(xmlChar *)"gpx");
  xmlTextWriterWriteAttribute(writer,(xmlChar *)"version",(xmlChar *)"1.0");
  xmlTextWriterWriteAttribute(writer,(xmlChar *)"creator",(xmlChar *)PACKAGE " " VERSION);
  xmlTextWriterWriteAttribute(writer,(xmlChar *)"xmlns:xsi",(xmlChar *)"http://www.w3.org/2001/XMLSchema-instance");
  xmlTextWriterWriteAttribute(writer,(xmlChar *)"xmlns",
			      (xmlChar *)"http://www.topografix.com/GPX/1/0");
  xmlTextWriterWriteAttribute(writer,(xmlChar *)"xsi:schemaLocation",(xmlChar *)"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd");
  tm=*gmtime(&t);
  xmlTextWriterWriteFormatElement(writer,(xmlChar *)"time","%04d-%02d-%02dT%02d:%02d:%02d",
			    tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,
			    tm.tm_hour,tm.tm_min,tm.tm_sec);
  xmlTextWriterStartElement(writer,(xmlChar *)"trk");
  xmlTextWriterStartElement(writer,(xmlChar *)"trkseg");
  for(l=g_list_first(save_list);l;l=g_list_next(l)) {
    struct t_punkt32 *p=(struct t_punkt32 *)l->data;
    xmlTextWriterStartElement(writer,(xmlChar *)"trkpt");
    xmlTextWriterWriteFormatAttribute(writer,(xmlChar *)"lat","%f",
				      p->latt);
    xmlTextWriterWriteFormatAttribute(writer,(xmlChar *)"lon","%f",
				      p->longg);
    if (p->time) {
      t=p->time;
      tm=*gmtime(&t);
      xmlTextWriterWriteFormatElement(writer,(xmlChar*)"time",
				"%04d-%02d-%02dT%02d:%02d:%02d",
				tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,
				tm.tm_hour,tm.tm_min,tm.tm_sec);
    }
    if (p->speed>0)
      xmlTextWriterWriteFormatElement(writer,(xmlChar *)"speed","%f",p->speed*1.852/3.6);
    xmlTextWriterEndElement(writer); /* /trkpt */
    
  }
  xmlTextWriterEndElement(writer); /*trkseg */
  xmlTextWriterEndElement(writer); /* trk */
  xmlTextWriterEndElement(writer); /* gpx */
  xmlTextWriterEndDocument(writer);
  xmlFreeTextWriter(writer);
  return 1;
}
Beispiel #16
0
daeInt daeLIBXMLPlugin::write(daeURI *name, daeDocument *document, daeBool replace)
{
	// Make sure database and document are both set
	if (!database)
		return DAE_ERR_INVALID_CALL;
	if(!document)
		return DAE_ERR_COLLECTION_DOES_NOT_EXIST;

	// Extract just the file path from the URI
	daeFixedName finalname;
	if (!name->getPath(finalname,sizeof(finalname)))
	{
		printf( "can't get path in write\n" );
		return DAE_ERR_BACKEND_IO;
	}

	// If replace=false, don't replace existing files
	if(!replace)
	{
		// Using "stat" would be better, but it's not available on all platforms
		FILE *tempfd = fopen(finalname,"r");
		if(tempfd != NULL)
		{
			// File exists, return error
			fclose(tempfd);
			return DAE_ERR_BACKEND_FILE_EXISTS;
		}
	}

	// Open the file we will write to
	writer = xmlNewTextWriterFilename(name->getURI(), 0);
	if ( !writer ) {
		printf( "no libxml2 writer\n" );
		return DAE_ERR_BACKEND_IO;
	}
	xmlChar indentString[10] = "    ";
	xmlTextWriterSetIndentString( writer, indentString );
	xmlTextWriterSetIndent( writer, 1 );
	xmlTextWriterStartDocument( writer, NULL, NULL, NULL );
	
	writeElement( document->getDomRoot() );
	
	xmlTextWriterEndDocument( writer );
	xmlTextWriterFlush( writer );
	xmlFreeTextWriter( writer );
	return DAE_OK;
}
//-----------------------------------------
void LegacyWriter::write() {
//-----------------------------------------
    #ifndef LIBXML_READER_ENABLED
    throw FileWriterException( "LIBXML NOT FOUND" );
    #endif

    cout << "INFO Start writing the file (gexf v1.0).." << endl;

    /*
     * 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

    /* Create a new XmlWriter for _filepath, with no compression. */
    xmlTextWriterPtr writer = xmlNewTextWriterFilename(_filepath.c_str(), 0);
    if (writer == NULL) {
        throw FileWriterException( "Error creating the xml LegacyWriter" );
    }

    /* Start the document with the xml default for the version,
     * encoding _ENCODING and the default for the standalone
     * declaration. */
    int rc = xmlTextWriterStartDocument(writer, NULL, _ENCODING, NULL);
    if (rc < 0) {
        throw FileWriterException( "Error at xmlTextWriterStartDocument" );
    }

    this->writeGexfNode(writer);
    
    /* 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) {
        throw FileWriterException( "Error at xmlTextWriterEndDocument" );
    }

    /* Close file and free memory buffers */
    xmlFreeTextWriter(writer);
    xmlCleanupParser();

    cout << "INFO File written." << endl;
}
Beispiel #18
0
int createDatabase(){
	time_t now;
	struct tm * timeinfo;
	int rc;
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename(db_uri, 0);
	if(writer == NULL){
		printf("Error creating the xml writer\n");
		return 1;
	}

	rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, NULL);
	if(rc < 0){
		printf("Error starting the document\n");
		return 1;
	}

	rc = xmlTextWriterStartElement(writer, BAD_CAST "remendo_db");
	if(rc < 0){
		printf("Error creating the root element in the XML file\n");
		return 1;
	}

	now = time(0);
	timeinfo = localtime (&now);
	xmlChar string_date [80];
	strftime(string_date,80,"%s",timeinfo);
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "creation", string_date);
	if(rc < 0){
		printf("Error creating attribute of root element\n");
		return 1;
	}

	rc = xmlTextWriterEndElement(writer);
	if(rc < 0){
		printf("Error ending the XML file\n");
		return 1;
	}

	xmlFreeTextWriter(writer);
	xmlCleanupParser();
	return 0;
}
Beispiel #19
0
cpXmlCmdOutput::cpXmlCmdOutput( const char* ResultDocumentFileName )
   : encoding( (const xmlChar*) "ISO-8859-1" )
   , cpXmlCmdNamespace( (const xmlChar*) "http://www.XmlCommandLine.org/cpXmlCmd/1.0" )
{
   /* Create a new XmlWriter for uri, with no compression. */
   writer = xmlNewTextWriterFilename( ResultDocumentFileName, 0 );
   if ( writer == NULL )
      throw ::std::runtime_error( "Error creating the xml writer" );

   /* Start the document with the xml default for the version,
    * encoding ISO 8859-1 and the default for the standalone
    * declaration. */
   if ( xmlTextWriterStartDocument( writer, NULL, (const char*)encoding, NULL ) < 0 )
      throw ::std::runtime_error( "Error starting the output document" );

   // Start root element
   if ( xmlTextWriterStartElementNS( writer, NULL, (xmlChar *) "cpXmlCmdLog", cpXmlCmdNamespace ) < 0 )
      throw ::std::runtime_error( "Error writing to the output document" );
}
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);
}
Beispiel #21
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;
}
Beispiel #22
0
 XmlWriter::XmlWriter(const std::string & filename)
   : m_buf(NULL)
 {
   m_writer = xmlNewTextWriterFilename(filename.c_str(), 0);
 }
Beispiel #23
0
 SDOXSDFileWriter::SDOXSDFileWriter(const char* xsdFile)
 {
     setWriter(xmlNewTextWriterFilename(xsdFile, 0));
 }
Beispiel #24
0
void write_config()
{
	const char *uri=config_path;
	int rc;
	char str_ip[IP6_STR_SIZE];
	xmlTextWriterPtr writer;
	router_list_t *tmp = routers;
#ifdef _COUNTERMEASURES_
	char config_kill_illegitimate_router[CM_GUARD_REPRESENTATION_SIZE];
	char config_kill_wrong_prefix[CM_GUARD_REPRESENTATION_SIZE];
	char config_propagate_router_params[CM_GUARD_REPRESENTATION_SIZE];
	char config_indicate_ndpmon_presence[CM_GUARD_REPRESENTATION_SIZE];
#endif

	printf("Writing config...\n");
	print_routers(routers);

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

	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)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n");
		return;
	}

	xmlTextWriterStartDTD	(writer, (xmlChar*)"config_ndpmon", NULL, (xmlChar*)dtd_config_path);
	xmlTextWriterEndDTD (writer);

	/* Give the stylesheet for display in the web interface */
	xmlTextWriterWriteRaw(writer, (xmlChar*)"<?xml-stylesheet type=\"text/xsl\" href=\"config.xsl\" ?>\n");

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

	/* Attribute ignor_autoconf */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ignor_autoconf", "%d", ignor_autoconf);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}
	
	/* Attribute syslog_facility */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "syslog_facility", "%s", syslog_facility);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	/* Attribute admin_mail */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "admin_mail", "%s", admin_mail);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}


	/* Elements of actions_low_pri */
	rc =  xmlTextWriterStartElement(writer, BAD_CAST "actions_low_pri");
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	/* Attribute sendmail */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "sendmail", "%d", action_low_pri.sendmail);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	/* Attribute syslog */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "syslog", "%d", action_low_pri.syslog);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	
	/* Attribute exec_pipe_program */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "exec_pipe_program", "%s", action_low_pri.exec_pipe_program);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}


	/* Close  actions_low_pri  */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
		return;
	}


	/* Elements of actions_high_pri */
	rc =  xmlTextWriterStartElement(writer, BAD_CAST "actions_high_pri");
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	/* Attribute sendmail */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "sendmail", "%d", action_high_pri.sendmail);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	/* Attribute syslog */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "syslog", "%d", action_high_pri.syslog);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	
	/* Attribute exec_pipe_program */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "exec_pipe_program", "%s", action_high_pri.exec_pipe_program);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}


	/* Close  actions_high_pri  */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
		return;
	}


	/* Attribute use_reverse_hostlookups */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "use_reverse_hostlookups", "%d", use_reverse_hostlookups);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
		return;
	}

	

	/* Start an element named routers containing the routers' definition */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "routers");
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
		return;
	}


	/*for each router a new neighbor with its attributes is created in the file */
	while(tmp != NULL)
	{
		address_t *tmp_address = tmp->addresses;
		prefix_t *tmp_prefix   = tmp->prefixes;
		ipv6_ntoa(str_ip, tmp->lla);

		/* Start an element named "router" as child of routers. */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "router");
		if (rc < 0) goto start_element_error;
		/* Element mac */
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mac", "%s", ether_ntoa(&(tmp->mac)));
		if (rc < 0) goto format_element_error;
		/* Element lla */
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "lla", "%s", str_ip);
		if (rc < 0) goto format_element_error;
		/* Elements for Router Advertisement Parameters: */
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_curhoplimit", "%u", tmp->param_curhoplimit);
		if (rc < 0) goto format_element_error;
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_flags_reserved", "%u", tmp->param_flags_reserved);
		if (rc < 0) goto format_element_error;
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_router_lifetime", "%u", tmp->param_router_lifetime);
		if (rc < 0) goto format_element_error;
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_reachable_timer", "%u", tmp->param_reachable_timer);
		if (rc < 0) goto format_element_error;
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_retrans_timer", "%u", tmp->param_retrans_timer);
		if (rc < 0) goto format_element_error;
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_mtu", "%u", tmp->param_mtu);
		if (rc < 0) goto format_element_error;
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "params_volatile", "%i", tmp->params_volatile);
		if (rc < 0) goto format_element_error;

		/* Start an element named prefixes */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "prefixes");
		if (rc < 0) goto start_element_error;
		while(tmp_prefix != NULL)
		{
			ipv6_ntoa(str_ip, tmp_prefix->prefix);
			rc = xmlTextWriterStartElement(writer, BAD_CAST "prefix");
			if (rc < 0) goto start_element_error;
			/* Elements for prefix address and mask:*/
			rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "address", "%s", str_ip);
			if (rc < 0) goto format_element_error;		
			rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mask", "%i", tmp_prefix->mask);
			if (rc < 0) goto format_element_error;		
                        /* Elements for prefix parameters:*/
			rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_flags_reserved", "%u", tmp_prefix->param_flags_reserved);
			if (rc < 0) goto format_element_error;		
			rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_valid_time", "%u", tmp_prefix->param_valid_time);
			if (rc < 0) goto format_element_error;		
			rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_preferred_time", "%u", tmp_prefix->param_preferred_time);
			if (rc < 0) goto format_element_error;
			rc = xmlTextWriterEndElement(writer);
			if (rc < 0) goto end_element_error;
                        /* Fetch next prefix:*/
			tmp_prefix = tmp_prefix->next;
		}   

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0) goto end_element_error;

		/* Addresses */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "addresses");
		if (rc < 0) goto start_element_error;

		while(tmp_address != NULL)
		{
			ipv6_ntoa(str_ip, tmp_address->address);
			/*Element for address.*/
			rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "address", "%s", str_ip);
			if (rc < 0) goto format_element_error;
			tmp_address = tmp_address->next;
		}    

		/* close addresses */
		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}

		/* close router */
		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}

		tmp = tmp->next;
	}

	/* Close routers  */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
		return;
	}

#ifdef _COUNTERMEASURES_
	cm_guard_all_to_representation(
		config_kill_illegitimate_router,
		config_kill_wrong_prefix,
		config_propagate_router_params,
		config_indicate_ndpmon_presence
	);

	/* Start an element named countermeasures containing the counter measures configuration. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "countermeasures");
	if (rc < 0) goto start_element_error;

	/* Write guard configurations. */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "kill_illegitimate_router", "%s", config_kill_illegitimate_router);
	if (rc < 0) goto format_element_error;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "kill_wrong_prefix", "%s", config_kill_wrong_prefix);
	if (rc < 0) goto format_element_error;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "propagate_router_params", "%s", config_propagate_router_params);
	if (rc < 0) goto format_element_error;
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "indicate_ndpmon_presence", "%s", config_indicate_ndpmon_presence);
	if (rc < 0) goto format_element_error;

	/* Close countermeasures  */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0) goto end_element_error;
#endif

	/* Close config_ndpmon */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
		return;
	}

	xmlFreeTextWriter(writer);
	return;

	format_element_error:
	printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
	xmlFreeTextWriter(writer);
	return;
        start_element_error:
	printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
	xmlFreeTextWriter(writer);
	return;
        end_element_error:
	printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
	xmlFreeTextWriter(writer);
	return;
}
Beispiel #25
0
void write_cache()
{
	const char *uri=cache_path;
	int rc;
	char str_ip[IP6_STR_SIZE];
	xmlTextWriterPtr writer;
	neighbor_list_t *tmp = neighbors;
	FILE *dat = NULL;

	printf("Writing cache...\n");

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

	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)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n");
		return;
	}

	xmlTextWriterStartDTD	(writer, (xmlChar*)"neighbor_list", NULL, (xmlChar*)dtd_path);
	xmlTextWriterEndDTD (writer);	

	/* Give the stylesheet for display in the web interface */
	xmlTextWriterWriteRaw(writer, (xmlChar*)"<?xml-stylesheet type=\"text/xsl\" href=\"neighbor.xsl\" ?>\n");

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

	/*for each neighbor in the cache a new neighbor element with its 
	 *attributes is created in the file */
	while(tmp != NULL)
	{
		address_t *atmp = tmp->addresses;
		ethernet_t *etmp = tmp->old_mac;
		/* to format the time */
		time_t timep;
		char time_str[27];
		char vlan_str[10];

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

		snprintf(vlan_str,9,"%d",(int) tmp->vlan_id);
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "vlan_id", "%s", vlan_str);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		/* Attribute mac */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "mac");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}
#ifdef _MACRESOLUTION_
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "vendor", "%s", tmp->vendor);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
		}
#endif
		rc = xmlTextWriterWriteRaw(writer, BAD_CAST ether_ntoa(&(tmp->mac)));
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}
		/*
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mac", "%s", ether_ntoa(&(tmp->mac)));
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}
		*/

		/* Attribute lla */
		ipv6_ntoa(str_ip, tmp->lla);
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "lla", "%s", str_ip);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		/* element time */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "time");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

#if 0
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "time", "%d",tmp->timer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}
#endif

		/* convert to str representation in order to display it in the web interface */
		timep = tmp->timer;
		strcpy(time_str, ctime(&timep));
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "timestr", "%s", time_str);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
		}

		/* the content */
		snprintf(time_str,27,"%d",(int) tmp->timer);
		rc = xmlTextWriterWriteRaw(writer, BAD_CAST time_str);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}

		/* Addresses */
		/* rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "adresses", NULL, NULL); */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "addresses");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		while(atmp != NULL)
		{
			/* to store a char * version of the int + \O */
			ipv6_ntoa(str_ip, atmp->address);

			/* the address element */
			rc = xmlTextWriterStartElement(writer, BAD_CAST "address");
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}

			/* lastseen timer */
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "lastseen", "%d", (int)atmp->lastseen);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* convert to str representation in order to display it in the web interface */
			timep = atmp->lastseen;
			strcpy(time_str, ctime(&timep));
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "lastseenstr", "%s", time_str);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* firstseen timer */
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "firstseen", "%d", (int)atmp->firstseen);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* convert to str representation in order to display it in the web interface */
			timep = atmp->firstseen;
			strcpy(time_str, ctime(&timep));
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "firstseenstr", "%s", time_str);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* the content */
			rc = xmlTextWriterWriteRaw(writer, BAD_CAST str_ip);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}
	
			rc = xmlTextWriterEndElement(writer);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
				return;
			}

			atmp = atmp->next;
		}    

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}


		/* Old Mac */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "old_mac");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		while(etmp != NULL)
		{
			rc = xmlTextWriterStartElement(writer, BAD_CAST "mac");
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}
			if(!MEMCMP(&(etmp->mac),&(tmp->previous_mac), sizeof(struct ether_addr)))
			{
				rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "last", "%s", "true");
				if (rc < 0)
				{
					printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
				}
			}
#ifdef _MACRESOLUTION_
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "vendor", "%s", etmp->vendor);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}
#endif
			rc = xmlTextWriterWriteRaw(writer, BAD_CAST ether_ntoa(&(etmp->mac)));
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}

			rc = xmlTextWriterEndElement(writer);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
				return;
			}

			etmp = etmp->next;
		}    

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}

		/* Close neighbor */
		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}
		tmp = tmp->next;
	}

	/* Close neighbor_list */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
		return;
	}

	xmlFreeTextWriter(writer);

	/* Write in discovery_history.dat the number of neighbors in the cache for statistics */
	if( (dat = fopen(discovery_history_path,"a")) != NULL)
	{
		fprintf(dat,"%d %d\n", (int)time(NULL), nb_neighbor(neighbors) );
		fclose(dat);
	}

}
Beispiel #26
0
int main ( int argc, char *argv[] ) {
  xmlTextReaderPtr reader;
  xmlTextWriterPtr writer;
  int status;
  struct api_shapes_circle *circle;
  struct api_shapes_triangle *triangle;
  struct api_shapes_rectangle *rectangle;
  struct api_animals_cat *cat;
  struct api_draw_canvas *canvas;
  struct api_structures_house *house;
  struct api_vehicles_bus *bus;
  if (argc != 4) {
    printf("Usage: %s [cat|canvas|house|bus|circle|triangle|rectangle] [infile] [outfile]", argv[0]);
    return 1;
  }

  reader = xmlReaderForFile(argv[2], NULL, 0);
  writer = xmlNewTextWriterFilename(argv[3], 0);
  if (strcmp("circle", argv[1]) == 0) {
    circle = xml_read_api_shapes_circle(reader);
    status = xml_write_api_shapes_circle(writer, circle);
    if (status < 0) {
      //panic
      printf("Problem writing circle.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the circle with status: %i\n", status);
    }
#endif

    free_api_shapes_circle(circle); //free the circle.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the circle from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("triangle", argv[1]) == 0) {
    triangle = xml_read_api_shapes_triangle(reader);
    status = xml_write_api_shapes_triangle(writer, triangle);
    if (status < 0) {
      //panic
      printf("Problem writing triangle.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the triangle with status: %i\n", status);
    }
#endif

    free_api_shapes_triangle(triangle); //free the triangle.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the triangle from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("rectangle", argv[1]) == 0) {
    rectangle = xml_read_api_shapes_rectangle(reader);
    status = xml_write_api_shapes_rectangle(writer, rectangle);
    if (status < 0) {
      //panic
      printf("Problem writing rectangle.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the rectangle with status: %i\n", status);
    }
#endif

    free_api_shapes_rectangle(rectangle); //free the rectangle.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the rectangle from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("cat", argv[1]) == 0) {
    cat = xml_read_api_animals_cat(reader);
    status = xml_write_api_animals_cat(writer, cat);
    if (status < 0) {
      //panic
      printf("Problem writing cat.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the cat with status: %i\n", status);
    }
#endif

    free_api_animals_cat(cat); //free the cat.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the cat from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("canvas", argv[1]) == 0) {
    canvas = xml_read_api_draw_canvas(reader);
    status = xml_write_api_draw_canvas(writer, canvas);
    if (status < 0) {
      //panic
      printf("Problem writing canvas.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the canvas with status: %i\n", status);
    }
#endif

    free_api_draw_canvas(canvas); //free the canvas.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the canvas from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("house", argv[1]) == 0) {
    house = xml_read_api_structures_house(reader);
    house->style = xml_convert_known_api_structures_houseStyle(xml_get_known_api_structures_houseStyle(house->style));
    house->type = xml_convert_known_api_structures_houseType(xml_get_known_api_structures_houseType(house->type));
    status = xml_write_api_structures_house(writer, house);
    if (status < 0) {
      //panic
      printf("Problem writing house.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the house with status: %i\n", status);
    }
#endif

    free_api_structures_house(house); //free the house.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the house from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("bus", argv[1]) == 0) {
    bus = xml_read_api_vehicles_bus(reader);
    status = xml_write_api_vehicles_bus(writer, bus);
    if (status < 0) {
      //panic
      printf("Problem writing bus.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the bus with status: %i\n", status);
    }
#endif

    free_api_vehicles_bus(bus); //free the bus.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the bus from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else {
    printf("Unrecognized xml type: %s\nUsage: %s [cat|canvas|house|bus||circle|triangle|rectangle] [infile] [outfile]", argv[1], argv[0]);
    return 1;
  }

  return 0;
}
Beispiel #27
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);
}
/**
 * testXmlwriterFilename:
 * @uri: the output URI
 *
 * test the xmlWriter interface when writing to a new file
 */
void
testXmlwriterFilename(const char *uri)
{
    int rc;
    xmlTextWriterPtr writer;
    xmlChar *tmp;

    /* Create a new XmlWriter for uri, with no compression. */
    writer = xmlNewTextWriterFilename(uri, 0);
    if (writer == NULL) {
        printf("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

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

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

    /* Start an element named "ENTRY" as child of ENTRIES. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
    if (rc < 0) {
        printf
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

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

    /* Start an element named "ENTRY" as child of ENTRIES. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
    if (rc < 0) {
        printf
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

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

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

    /* Start an element named "FOOTER" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
    if (rc < 0) {
        printf
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Close the element named FOOTER. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf
            ("testXmlwriterFilename: 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
            ("testXmlwriterFilename: Error at xmlTextWriterEndDocument\n");
        return;
    }

    xmlFreeTextWriter(writer);
}
Beispiel #29
0
void
dt_styles_save_to_file(const char *style_name,const char *filedir,gboolean overwrite)
{
  int rc = 0;
  char stylename[520];
  sqlite3_stmt *stmt;

  snprintf(stylename,512,"%s/%s.dtstyle",filedir,style_name);

  // check if file exists
  if( g_file_test(stylename, G_FILE_TEST_EXISTS) == TRUE )
  {
    if(overwrite)
    {
      if(unlink(stylename))
      {
        dt_control_log(_("failed to overwrite style file for %s"),style_name);
        return;
      }
    }
    else
    {
      dt_control_log(_("style file for %s exists"),style_name);
      return;
    }
  }

  if ( !dt_styles_exists (style_name) ) return;

  xmlTextWriterPtr writer = xmlNewTextWriterFilename(stylename, 0);
  if (writer == NULL)
  {
    fprintf(stderr,"[dt_styles_save_to_file] Error creating the xml writer\n, path: %s", stylename);
    return;
  }
  rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
  if (rc < 0)
  {
    fprintf(stderr,"[dt_styles_save_to_file]: Error on encoding setting");
    return;
  }
  xmlTextWriterStartElement(writer, BAD_CAST "darktable_style");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0");

  xmlTextWriterStartElement(writer, BAD_CAST "info");
  xmlTextWriterWriteFormatElement(writer, BAD_CAST "name", "%s", style_name);
  xmlTextWriterWriteFormatElement(writer, BAD_CAST "description", "%s", dt_styles_get_description(style_name));
  xmlTextWriterEndElement(writer);

  xmlTextWriterStartElement(writer, BAD_CAST "style");
  DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name from style_items where styleid =?1",-1, &stmt,NULL);
  DT_DEBUG_SQLITE3_BIND_INT(stmt,1,dt_styles_get_id_by_name(style_name));
  while (sqlite3_step (stmt) == SQLITE_ROW)
  {
    xmlTextWriterStartElement(writer, BAD_CAST "plugin");
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "num", "%d", sqlite3_column_int(stmt,0));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "module", "%d", sqlite3_column_int(stmt,1));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "operation", "%s", sqlite3_column_text(stmt,2));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "op_params", "%s", dt_style_encode(stmt,3));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "enabled", "%d", sqlite3_column_int(stmt,4));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "blendop_params", "%s", dt_style_encode(stmt,5));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "blendop_version", "%d", sqlite3_column_int(stmt,6));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "multi_priority", "%d", sqlite3_column_int(stmt,7));
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "multi_name", "%s", sqlite3_column_text(stmt,8));
    xmlTextWriterEndElement(writer);
  }
  sqlite3_finalize(stmt);
  xmlTextWriterEndDocument(writer);
  xmlFreeTextWriter(writer);
}
Beispiel #30
0
bool ddDatabaseDesign::writeXmlModel(wxString file)
{
	int rc;

	xmlWriter = xmlNewTextWriterFilename(file.mb_str(wxConvUTF8), 0);
	if (xmlWriter == NULL)
	{
		wxMessageBox(_("Failed to write the model file!"), _("Error"), wxICON_ERROR);
		return false;
	}
	rc = xmlTextWriterStartDocument(xmlWriter, NULL, "UTF-8" , NULL);
	if(rc < 0)
	{
		wxMessageBox(_("Failed to write the model file!"), _("Error"), wxICON_ERROR);
		return false;
	}
	else
	{
		ddXmlStorage::StartModel(xmlWriter, this);
		//initialize IDs of tables
		mappingNameToId.clear();
		hdIteratorBase *iterator = editor->modelFiguresEnumerator();
		hdIFigure *tmp;
		ddTableFigure *table;
		int nextID = 10;

		while(iterator->HasNext())
		{
			tmp = (hdIFigure *)iterator->Next();
			if(tmp->getKindId() == DDTABLEFIGURE)
			{
				table = (ddTableFigure *)tmp;
				mappingNameToId[table->getTableName()] = wxString::Format(wxT("TID%d"), nextID);
				nextID += 10;
			}
		}
		delete iterator;


		//Create table xml info
		iterator = editor->modelFiguresEnumerator();
		while(iterator->HasNext())
		{
			tmp = (hdIFigure *)iterator->Next();
			if(tmp->getKindId() == DDTABLEFIGURE)
			{
				table = (ddTableFigure *)tmp;
				ddXmlStorage::Write(xmlWriter, table);
			}
		}
		delete iterator;


		//Create relationships xml info
		ddRelationshipFigure *relationship;
		iterator = editor->modelFiguresEnumerator();
		while(iterator->HasNext())
		{
			tmp = (hdIFigure *)iterator->Next();
			if(tmp->getKindId() == DDRELATIONSHIPFIGURE)
			{
				relationship = (ddRelationshipFigure *)tmp;
				ddXmlStorage::Write(xmlWriter, relationship);
			}
		}
		delete iterator;

		//Create Diagrams xml info

		ddXmlStorage::StarDiagrams(xmlWriter);

		iterator = editor->diagramsEnumerator();
		hdDrawing *tmpDiagram;

		while(iterator->HasNext())
		{
			tmpDiagram = (hdDrawing *)iterator->Next();
			ddXmlStorage::WriteLocal(xmlWriter, tmpDiagram);
		}
		delete iterator;

		ddXmlStorage::EndDiagrams(xmlWriter);

		//End model xml info
		ddXmlStorage::EndModel(xmlWriter);
		xmlTextWriterEndDocument(xmlWriter);
		xmlFreeTextWriter(xmlWriter);
		return true;
	}
	return false;
}