示例#1
0
int cXmlDoc::write(const char* filename, bool indent, const char* encoding) {
    if (!m_doc)
        throw eXmlInvalid("Tried to write bad document");

    if (indent) {
        return xmlSaveFormatFileEnc(filename, m_doc.get(), encoding, 1);
    } else {
        return xmlSaveFileEnc(filename, m_doc.get(), encoding);
    }
}
示例#2
0
//----------------------------------------------------------------------------
// Finished a file and saves it
//----------------------------------------------------------------------------
void CXMLTreeNode::EndNewFile ()
{
  assert(m_pWriter && m_pDoc && m_pszFileName);

  if (m_pWriter && m_pDoc && m_pszFileName)
  {
    xmlFreeTextWriter(m_pWriter);
    m_pWriter = NULL;

    xmlSaveFileEnc(m_pszFileName, m_pDoc, MY_ENCODING);
  }
}
示例#3
0
文件: dev_planet.c 项目: br0k3/naev
/**
 * @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;
}
示例#4
0
void create_file(char *to, char *from, char *msg){
	int rc;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlNodePtr node, root;
	xmlChar *tmp;

	if(doc = xmlParseFile(to)){
		root = xmlDocGetRootElement(doc);

		xmlNodePtr pNode = xmlNewNode(0, (xmlChar*)"mes");
		//xmlSetProp(pNode, (const xmlChar*) "id", (const xmlChar*) "val");
		xmlSetProp(pNode, (const xmlChar*) "from", (const xmlChar*) from);
		xmlNodeSetContent(pNode, (xmlChar*)msg);
		xmlAddChild(root, pNode);

		xmlSaveFileEnc(to, doc, MY_ENCODING);
		xmlFreeDoc(doc);
	}else{
		doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
		node = xmlNewDocNode(doc, NULL, BAD_CAST "inbox", NULL);
		xmlDocSetRootElement(doc, node);
		writer = xmlNewTextWriterTree(doc, node, 0);
		rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
		rc = xmlTextWriterStartElement(writer, BAD_CAST "mes");
		//rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST "1");
		rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "from", BAD_CAST from);
		rc = xmlTextWriterEndAttribute(writer);
		rc = xmlTextWriterWriteString(writer, (const xmlChar*) msg);
		rc = xmlTextWriterEndElement(writer);
		rc = xmlTextWriterEndDocument(writer);
		xmlFreeTextWriter(writer);
		xmlSaveFileEnc(to, doc, MY_ENCODING);
		xmlFreeDoc(doc);
	}
}
示例#5
0
// Save current memory XML Doc into file
int ermXmlSave(erManifest *pCtx)
{
    if (NULL == pCtx->szFileName)
    {
        TRACE("pCtx->szFileName pointer is empty!\n");
        return RET_ERR;
    }
    if (0 >= strlen(pCtx->szFileName))
    {
        TRACE("length of pCtx->szFileName is zero!\n");
        return RET_ERR;
    }

    int n = xmlSaveFileEnc(pCtx->szFileName, pCtx->pDoc, DEFAULT_ENCODING);
    sync();
    return (n >= 0) ? RET_OK : RET_ERR;
}
示例#6
0
void xml_finish(struct writer * w) {
	struct xml_writer_private * p = w->priv;
	int failed = 0;

	if (xmlTextWriterEndDocument(p->xw) < 0 ) {
		LLOG_WARNX("cannot finish document");
		failed = 1;
	}

	xmlFreeTextWriter(p->xw);
	
	if ( ! failed )
		xmlSaveFileEnc("-", p->doc, MY_ENCODING);

	xmlFreeDoc(p->doc);

	free( w->priv );
	free( w );
}
示例#7
0
void TrackerConfig::save()
{
    AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO,
            "Saving tracker configuration to " << m_sFilename << ".");

    if (m_Doc) {
        if (fileExists(m_sFilename)) {
            string sBakFile = m_sFilename + ".bak";
            unlink(sBakFile.c_str());
            if (rename(m_sFilename.c_str(), sBakFile.c_str())) {
                AVG_LOG_WARNING("Cannot create tracker config backup. Backing "
                        "it up on current workdir.");
                copyFile(m_sFilename, "avgtrackerrc.bak");
            }
        }
        xmlSaveFileEnc(m_sFilename.c_str(), m_Doc, "utf-8");
    } else
        throw (Exception(AVG_ERR_FILEIO, 
                    "save(): tracker configuration not initialized"));
}
示例#8
0
int
main(int argc, char* argv[])
{
	int rc;
	xmlTextWriterPtr writer;
	xmlChar *tmp;
	xmlDocPtr doc;
	const char* file;

	/* Check usage and assign out default filename. */
	if (argc != 2)
	{
		usage(argc, argv);
	}
	file = argv[1];

	/* Create a new XmlWrite for DOM, no compression. */
	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
	{
		printf("Error creating XML DOM 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, DEFAULT_ENCODING, NULL);
	if (rc < 0)
	{
		printf("Error at xmlTextWriterStartDocument.\n");
		return;
	}

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

	/* Add attributes to the OME element. */
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:bf",
			BAD_CAST "http://www.openmicroscopy.org/Schemas/BinaryFile/2008-09");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['xmlns:bf']\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ome",
			BAD_CAST "http://www.openmicroscopy.org/Schemas/OME/2008-09");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['xmlns:ome']\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xsi",
			BAD_CAST "http://www.w3.org/2001/XMLSchema-instance");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['xmlns:xsi']\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xsi:schemaLocation",
			BAD_CAST "http://www.openmicroscopy.org/Schemas/OME/2008-09 http://www.openmicroscopy.org/Schemas/OME/2008-09/ome.xsd");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['xsi:schemaLocation']\n");
		return;
	}

	/* Start the Image element. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "ome:Image");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterStartElement['ome:Image'].\n");
		return;
	}

	/* Add attributes to the Image element. */
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID",
			BAD_CAST "Image:1");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Image.ID']\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Name",
			BAD_CAST "Name92");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Image.Name'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DefaultPixels",
			BAD_CAST "Pixels:1");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Image.DefaultPixels']\n");
		return;
	}

	/* Write the CreationDate element with CDATA. */
	rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ome:CreationDate",
			"%s", "2006-05-04T18:13:51.0Z");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterFormatElement['ome:CreationDate'].\n");
		return;
	}

	/* Start the Pixels element. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "ome:Pixels");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterStartElement['ome:Pixels'].\n");
		return;
	}

	/* Add attributes to the Pixels element. */
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID",
			BAD_CAST "Pixels:1");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.ID'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DimensionOrder",
			BAD_CAST "XYZCT");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.DimensionOrder'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PixelType",
			BAD_CAST "int8");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.PixelType'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "BigEndian",
			BAD_CAST "false");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.BigEndian'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeX",
			BAD_CAST "2");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.SizeX'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeY",
			BAD_CAST "2");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.SizeY'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeZ",
			BAD_CAST "2");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.SizeZ'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeC",
			BAD_CAST "2");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.SizeC'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeT",
			BAD_CAST "2");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['Pixels.SizeT'\n");
		return;
	}

	/* Start the BinData element. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "bf:BinData");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterStartElement['bf:BinData']\n");
		return;
	}

	/* Add attributes and Base64 CDATA to the BinData element. */
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Compression",
			BAD_CAST "none");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['BinData.Compression'\n");
		return;
	}
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Length",
			BAD_CAST "10");
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteAttribute['BinData.Length'\n");
		return;
	}
	rc = xmlTextWriterWriteBase64(writer, BAD_CAST "default", 0, 7);
	if (rc < 0)
	{
		printf("Error at xmlTextWriterWriteBase64['BinData']\n");
		return;
	}

	/* Close the Pixels, Image and OME elements using xmlTextWriterEndDocument
	 * instead of calling xmlTextWriterEndElement on each to save some work. */
	rc = xmlTextWriterEndDocument(writer);
	if (rc < 0)
	{
		printf("Error at xmlTextWriterEndDocument.\n");
		return;
	}

	xmlFreeTextWriter(writer);
	xmlSaveFileEnc(file, doc, DEFAULT_ENCODING);
	xmlFreeDoc(doc);
}
示例#9
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;
}
示例#10
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;
}
示例#11
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;
}
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);
}
/**
 * testXmlwriterTree:
 * @file: the output file
 *
 * test the xmlWriter interface when writing to a subtree
 */
void
testXmlwriterTree(const char *file)
{
    int rc;
    xmlTextWriterPtr writer;
    xmlDocPtr doc;
    xmlNodePtr node;
    xmlChar *tmp;

    /* Create a new XML DOM tree, to which the XML document will be
     * written */
    doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
    if (doc == NULL) {
        printf
            ("testXmlwriterTree: Error creating the xml document tree\n");
        return;
    }

    /* Create a new XML node, to which the XML document will be
     * appended */
    node = xmlNewDocNode(doc, NULL, BAD_CAST "EXAMPLE", NULL);
    if (node == NULL) {
        printf("testXmlwriterTree: Error creating the xml node\n");
        return;
    }

    /* Make ELEMENT the root node of the tree */
    xmlDocSetRootElement(doc, node);

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

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

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

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

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

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

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

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

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

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

    xmlFreeTextWriter(writer);

    xmlSaveFileEnc(file, doc, MY_ENCODING);

    xmlFreeDoc(doc);
}
示例#14
0
文件: sds.c 项目: radzy/openscap
int ds_sds_compose_from_xccdf(const char* xccdf_file, const char* target_datastream)
{
	xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
	xmlNodePtr root = xmlNewNode(NULL, BAD_CAST "data-stream-collection");
	xmlDocSetRootElement(doc, root);

	xmlNsPtr ds_ns = xmlNewNs(root, BAD_CAST datastream_ns_uri, BAD_CAST "ds");
	xmlSetNs(root, ds_ns);

	// we will need this namespace later when creating xlink:href attr in
	// component-ref
	xmlNewNs(root, BAD_CAST xlink_ns_uri, BAD_CAST "xlink");

	char* mangled_xccdf_file = ds_sds_mangle_filepath(xccdf_file);
	char* collection_id = oscap_sprintf("scap_org.open-scap_collection_from_xccdf_%s", mangled_xccdf_file);
	xmlSetProp(root, BAD_CAST "id", BAD_CAST collection_id);
	oscap_free(collection_id);

	xmlSetProp(root, BAD_CAST "schematron-version", BAD_CAST "1.0");

	// we will need this namespace later when creating component-ref
	// dependency catalog
	xmlNewNs(root, BAD_CAST cat_ns_uri, BAD_CAST "cat");

	xmlNodePtr datastream = xmlNewNode(ds_ns, BAD_CAST "data-stream");
	xmlAddChild(root, datastream);

	char* datastream_id = oscap_sprintf("scap_org.open-scap_datastream_from_xccdf_%s", mangled_xccdf_file);
	xmlSetProp(datastream, BAD_CAST "id", BAD_CAST datastream_id);
	oscap_free(datastream_id);

	xmlSetProp(datastream, BAD_CAST "scap-version", BAD_CAST "1.2");

	xmlSetProp(datastream, BAD_CAST "use-case", BAD_CAST "OTHER");

	xmlNodePtr dictionaries = xmlNewNode(ds_ns, BAD_CAST "dictionaries");
	xmlAddChild(datastream, dictionaries);

	xmlNodePtr checklists = xmlNewNode(ds_ns, BAD_CAST "checklists");
	xmlAddChild(datastream, checklists);

	xmlNodePtr checks = xmlNewNode(ds_ns, BAD_CAST "checks");
	xmlAddChild(datastream, checks);

	xmlNodePtr extended_components = xmlNewNode(ds_ns, BAD_CAST "extended-components");
	xmlAddChild(datastream, extended_components);

	char* cref_id = oscap_sprintf("scap_org.open-scap_cref_%s", mangled_xccdf_file);
	if (ds_sds_compose_add_component_with_ref(doc, datastream, xccdf_file, cref_id) != 0)
	{
		// oscap_seterr already called
		oscap_free(cref_id);
		oscap_free(mangled_xccdf_file);
		return -1;
	}
	oscap_free(cref_id);

	// the XSD of source data stream enforces that the collection elements are
	// not empty if they are there, we will therefore now removes collections
	// where nothing has been added

	if (dictionaries->children == NULL)
	{
		xmlUnlinkNode(dictionaries);
		xmlFreeNode(dictionaries);
	}
	if (checklists->children == NULL)
	{
		xmlUnlinkNode(checklists);
		xmlFreeNode(checklists);
	}
	if (checks->children == NULL)
	{
		xmlUnlinkNode(checks);
		xmlFreeNode(checks);
	}
	if (extended_components->children == NULL)
	{
		xmlUnlinkNode(extended_components);
		xmlFreeNode(extended_components);
	}

	oscap_free(mangled_xccdf_file);

	if (xmlSaveFileEnc(target_datastream, doc, "utf-8") == -1)
	{
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "Error saving source datastream to '%s'.", target_datastream);
		xmlFreeDoc(doc);
		return -1;
	}

	xmlFreeDoc(doc);
	return 0;
}
示例#15
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);
}
示例#16
0
// 8. LOAD_CONFIG_FILE
// test: HTTP://192.168.1.155/cgi-bin/Flash2AppREMOTEM_load_config_file.cgi?path=/upload/input.xml
static void proc_cmd_load_config_file(struct mg_connection* conn, const struct mg_request_info* request_info)
{
	char configXmlPath[200];
	char inputXmlPath[200];
	char str_file_path[200];
	char *address = 0, *netmask = 0, *gateway = 0;
	int dhcp = 0;
	char* broadcast_xml_field;
	char*rec_pre_xml_field;

	int found = 0;
	int isNetUpdate = 0;

	get_qsvar(request_info, "path", str_file_path, sizeof(str_file_path));
	if (strlen(str_file_path) == 0)
	{
		mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nerrno=%d\r\n", INPUT_PARAM_NOT_SPECIFIED);
		return;
	}

	sprintf(inputXmlPath, "%s%s", ODI_HOME, str_file_path);
	sprintf(configXmlPath, "%s", ODI_CONFIG_XML);

	logger_remotem("load_config_file: merge XML Config File: from %s to %s", inputXmlPath, ODI_CONFIG_XML);

	struct my_file xmlfile = MY_STRUCT_FILE_INITIALIZER;
	if (!my_file_stat(inputXmlPath, &xmlfile))
	{
		logger_remotem("No Input Config file to Load  %s", inputXmlPath);
		send_http_error(conn, 404, "No Input Config file to Load ", "%s not found", inputXmlPath);
		goto leave;
	}

	if (!my_file_stat(ODI_CONFIG_XML, &xmlfile))
	{
		logger_remotem("No destination Config file to Merge  %s", ODI_CONFIG_XML);
		send_http_error(conn, 404,
			"No original config file to compare for merge ",
			"%s not found", ODI_CONFIG_XML);
		goto leave;
	}

	// read network file
	logger_remotem("Start merge XML Config File: %s", inputXmlPath);

	xmlDocPtr inputXmlDocumentPointer = xmlParseFile(inputXmlPath);
	if (inputXmlDocumentPointer == 0)
	{
		logger_remotem("LOAD_CONFIG_FILE: input XML not well formed %s", inputXmlPath);
		mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nInputXML file is not well-formed.\r\n");
		return;
	}
	xmlDocPtr configXmlDocumentPointer = xmlParseFile(ODI_CONFIG_XML);
	if (configXmlDocumentPointer == 0)
	{
		logger_remotem("LOAD_CONFIG_FILE: config XML not well formed %s", ODI_CONFIG_XML);
		mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nConfiguration XML file is not well-formed.\r\n");
		return;
	}

	// doc check
	xmlNodePtr cur = xmlDocGetRootElement(inputXmlDocumentPointer);

	if (cur == NULL)
	{
		logger_remotem("LOAD_CONFIG_FILE: input XML is empty");
		xmlFreeDoc(configXmlDocumentPointer);
		xmlFreeDoc(inputXmlDocumentPointer);
		goto leave;
	}

	// config-meta check
	if (xmlStrcmp(cur->name, (const xmlChar*)"config-metadata"))
	{
		logger_remotem("LOAD_CONFIG_FILE: config-metadata tag not found");
		xmlFreeDoc(configXmlDocumentPointer);
		xmlFreeDoc(inputXmlDocumentPointer);
		goto leave;
	}

	xmlNodePtr destParent = xmlDocGetRootElement(configXmlDocumentPointer);

	//node not found
	if (destParent == NULL)
	{
		logger_remotem("LOAD_CONFIG_FILE: empty doc");
		xmlFreeDoc(configXmlDocumentPointer);
		xmlFreeDoc(inputXmlDocumentPointer);
		goto leave;
	}

	if (xmlStrcmp(destParent->name, (const xmlChar*)"config-metadata"))
	{
		logger_remotem("LOAD_CONFIG_FILE:  root node != config-metadata");
		xmlFreeDoc(configXmlDocumentPointer);
		xmlFreeDoc(inputXmlDocumentPointer);
		goto leave;
	}

	destParent = destParent->xmlChildrenNode;
	while (destParent)
	{
		if ((!xmlStrcmp(destParent->name, (const xmlChar*)"config")))
		{
			found = 1;

			//Parse child content for field that need reboot
			xmlNodePtr info = destParent->xmlChildrenNode;
			while (info != NULL)
			{
				if (!xmlStrcmp(info->name, (const xmlChar*)"remotem_broadcast_ip"))
				{
					//    logger_info("Tag 1: %s", info->name);
					//    logger_info("Content: %s", (char *)xmlNodeGetContent(info));
					broadcast_xml_field = (char*)xmlNodeGetContent(info);
				}
				else if (!xmlStrcmp(info->name, (const xmlChar *) "rec_pre"))
				{
					//    logger_info("Tag 2: %s", info->name);
					//    logger_info("Content: %s", (char *)xmlNodeGetContent(info));
					rec_pre_xml_field = (char*)xmlNodeGetContent(info);
				}
				info = info->next;
			}
			break;
		}
		destParent = destParent->next;
	}

	if (!found)
	{
		logger_remotem("LOAD_CONFIG_FILE: config tag not found in %s", configXmlPath);
		xmlFreeDoc(configXmlDocumentPointer);
		xmlFreeDoc(inputXmlDocumentPointer);
		goto leave;
	}

	cur = cur->xmlChildrenNode;
	xmlNodePtr child = NULL;
	char *new_date = 0, *new_time = 0, *new_tz = 0;
	char str_comm[200];
	unsigned int config_change_reboot = 0;
	while (cur != NULL)
	{
		if ((!xmlStrcmp(cur->name, (const xmlChar*)"config")))
		{
			child = cur->xmlChildrenNode;
			while (child != NULL)
			{
				if (!(xmlStrcmp(child->name, (const xmlChar*)"text")))
				{
					;
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"dvr_id")))
				{
					// cannot change DVR ID
					;
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"dts_date")))
				{
					new_date = (char*)xmlNodeGetContent(child);
					if (strlen(new_date) == 10)   // Check for valid date
					{
						logger_remotem("LOAD_CONFIG_FILE: setting date %s", new_date);
						modifytree(&destParent, child);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"dts_time")))
				{
					new_time = (char*)xmlNodeGetContent(child);
					if (strlen(new_time) == 8)   // Check for valid time
					{
						logger_remotem("LOAD_CONFIG_FILE: setting time %s", new_time);
						modifytree(&destParent, child);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"dvr_name")))
				{
					char* str = (char*)xmlNodeGetContent(child);
					if (strlen(str) > 1)
					{
						logger_remotem("LOAD_CONFIG_FILE: setting dvr_name %s", str);
						modifytree(&destParent, child);
						set_dvr_name(str);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"ops_carnum")))
				{
					char* str = (char*)xmlNodeGetContent(child);
					if (strlen(str) > 1)   // Check for valid time
					{
						logger_remotem("LOAD_CONFIG_FILE: setting ops_carnum %s", str);
						modifytree(&destParent, child);
						set_dvr_name(str);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"usb_login")))
				{
					char* str = (char*)xmlNodeGetContent(child);
					if (strlen(str) > 1)   // Check for valid time
					{
						logger_remotem("LOAD_CONFIG_FILE: setting usb_login %s", str);
						modifytree(&destParent, child);
						set_assignable(str);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"dts_tz")))
				{
					new_tz = (char*)xmlNodeGetContent(child);
					modifytree(&destParent, child);

					char ptr[strlen(new_tz) + 1];
					int i, j = 0;

					for (i = 0; new_tz[i] != ' '; i++)
					{
						// skip till space
					}
					i++; // move up from the space
					for (i; new_tz[i] != '\0'; i++)
					{
						ptr[j++] = new_tz[i];
					}
					ptr[j] = '\0';

					memset(str_comm, 0, 200);
					sprintf(str_comm, "export TZ=%s", ptr);
					system(str_comm);

				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_dhcp")))
				{
					isNetUpdate = 1;
					if (!(xmlStrcmp((const xmlChar*)xmlNodeGetContent(child), (const xmlChar*)"true")))
					{
						dhcp = 1;
						logger_remotem("LOAD_CONFIG_FILE: change to DHCP");
					}
					else
					{
						dhcp = 0;
						logger_remotem("LOAD_CONFIG_FILE: DHCP is static");
					}
					modifytree(&destParent, child);
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_addr")))
				{
					address = (char *)xmlNodeGetContent(child);
					if (address != NULL && strlen(address) > 7)
					{
						isNetUpdate = 1;
						modifytree(&destParent, child);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_mask")))
				{
					netmask = (char*)xmlNodeGetContent(child);
					if (netmask != NULL && strlen(netmask) > 7)
					{
						isNetUpdate = 1;
						modifytree(&destParent, child);
					}
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_gate")))
				{
					gateway = (char*)xmlNodeGetContent(child);
					if (gateway != NULL && strlen(gateway) > 7)
					{
						isNetUpdate = 1;
						modifytree(&destParent, child);
					}
					// Set flag for config update item need to reboot to apply change
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"remotem_broadcast_ip")))
				{
					logger_info("New: %s Old: %s", xmlNodeGetContent(child), broadcast_xml_field);
					if (strcmp((char*)xmlNodeGetContent(child), broadcast_xml_field))
					{
						config_change_reboot = 1;
					}
					modifytree(&destParent, child);
				}
				else if (!(xmlStrcmp(child->name, (const xmlChar*)"rec_pre")))
				{
					if (rec_pre_xml_field == NULL)
					{
						config_change_reboot = 1;
					}
					else if (strcmp((char*)xmlNodeGetContent(child), rec_pre_xml_field))
					{
						if (strncmp(get_hw_version(), "3", 1)) // Only update when >= v4.0
						{
							config_change_reboot = 1;
						}
					}
					modifytree(&destParent, child);
				}
				else
				{
					if (modifytree(&destParent, child) == -1)
					{
						logger_remotem("LOAD_CONFIG_FILE: %s doesn't contain %s tag", configXmlPath, (char*)child->name);
					}
				}
				child = child->next;
			}
		}
		cur = cur->next;
	} // end while loop until NULL all elements processed

	if (new_date == NULL && new_time == NULL)
	{
		logger_remotem("%s: date and time are null", __FUNCTION__);
	}
	else
	{
		set_sys_clock(new_date, new_time);
	}

	mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nerrno=0\r\n");
	if (isNetUpdate)
	{
		update_network(dhcp, address, netmask, gateway);
	}

	logger_remotem("LOAD_CONFIG_FILE: saving new config, size=%d",
		xmlSaveFileEnc(configXmlPath, configXmlDocumentPointer, "UTF-8"));

leave:
	if (inputXmlDocumentPointer)
	{
		xmlFreeDoc(inputXmlDocumentPointer);
	}

	if (configXmlDocumentPointer)
	{
		xmlFreeDoc(configXmlDocumentPointer);
	}

	if (config_change_reboot == 1)
	{
		logger_info("Config item change need system reboot");
		//        write_command_to_serial_port("RST\r\n");
		//        sleep(1);
		system("reboot");
	}
}
示例#17
0
int Repository::build_index(string server_url, string server_name, bool rebuild)
{
	if (rebuild) server_name=server_url;  // Temp warning workaround
	pkgDupeNames.clear();
	unlink("index.log");
	unlink("dupes.log");
	unlink("legacy.log");
	pkgcounter=0;
	
	__doc = xmlNewDoc((const xmlChar *)"1.0");
	if (__doc == NULL) {
		mDebug("_root == NULL");
	} else {
		mDebug("_root != NULL");
	}
	_rootNode = xmlNewNode(NULL, (const xmlChar *)"repository");
	if (_rootNode == NULL) {
		mDebug("_rootNode == NULL");
	} else {
		mDebug("_rootNode != NULL");
	}
	xmlDocSetRootElement(__doc, _rootNode);
	if (_rootNode == NULL) {
		mDebug("[2]_rootNode == NULL");
	} else {
		mDebug("[2]_rootNode != NULL");
	}

#ifdef DEBUG
	printf("OMFGDUMP\n");
	mDebug("Saving repo xml dump");
	FILE *__xmlDump = fopen("/tmp/xmldump-repo.xml", "w");
    if (xmlDocDump(__xmlDump, __doc) != -1) {
		fclose(__xmlDump);
		mDebug("Xml dump saved");
	} else {
		fclose(__xmlDump);
		mDebug("Xml dump failed");
	}
#endif
    	
	// Next, run thru files and extract data.
	// We consider that repository root is current directory. So, what we need to do:
	// Enter each sub-dir, get each file which name ends with .tgz, extracts xml (and other) data from them, 
	// and build an XML tree for whole repository, then write it to ./packages.xml
	
	
	// for the first, let's calculate the package count
	pkgcount_ftw=0;
	ftw(".", countPackage,600);
	ftw(".", ProcessPackage, 600);
	// Finally, write our XML tree to file
	xmlSaveFileEnc("packages.xml", __doc, "UTF-8");
	// Compress file
	mDebug("Compressing files");
	say("Compressing files\n");
	if (/*system("gzip -f filelist.xml")==0 && */system("gzip -f packages.xml")==0)
	       say("\n-------------SUMMARY------------------\nTotal: %d packages\n\nRepository index created successfully\n",pkgcounter);
	else mError("Error creating repository index!");
	return 0;
}