/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License.
 *
 *
 *                      ********************
 *
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **************************************************************************************/
#include "Enregistrement.h"
#include "Equipement.h"
#include "Equipement_Port.h"
#include "Equipement_Historique.h"
#include "Settings_Signature.h"
#include "Add_Network_Subnet.h"
#include "Reseau.h"
#include "Debug.h"
#include "Objet.h"
#include "Snmp.h"
#include "config.h"
#include "Macro.h"

extern struct Struct_Modele_Objet Liste_Modele_Objet[];
extern struct Struct_Liste_Port_UDP Liste_Port_UDP[];


static void Write_xml_Snmp_Equipement (xmlNodePtr xmlnode, struct Struct_Equipement *Equipement)
{
	xmlNodePtr newxml = NULL;
	gchar    *tmp = NULL;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Equipement == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Snmp", NULL);
	xmlSetProp (newxml, "Info_Device", Equipement->Snmp_Info_Device); 
	xmlSetProp (newxml, "System_Name", Equipement->Snmp.System_Name);
	xmlSetProp (newxml, "Description", Equipement->Snmp.Description);
	xmlSetProp (newxml, "Contact", Equipement->Snmp.Contact);
	xmlSetProp (newxml, "Location", Equipement->Snmp.Location);
	xmlSetProp (newxml, "Uptime", Equipement->Snmp.Uptime);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Ram);
	xmlSetProp (newxml, "Ram", tmp);
	MYFREE (tmp);
	xmlSetProp (newxml, "Ip_Forwarding", Equipement->Snmp.Ip_Forwarding);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Default_TTL);
	xmlSetProp (newxml, "Default_TTL", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Reassembly_Timeout);
	xmlSetProp (newxml, "Reassembly_Timeout", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Need_To_Be_Reassembled);
	xmlSetProp (newxml, "Need_To_Be_Reassembled", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Reassembled);
	xmlSetProp (newxml, "Reassembled", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Reassembly_Failures);
	xmlSetProp (newxml, "Reassembly_Failures", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Successfully_Fragmented);
	xmlSetProp (newxml, "Successfully_Fragmented", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Fragmentation_Failures);
	xmlSetProp (newxml, "Fragmentation_Failures", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Created_Fragments);
	xmlSetProp (newxml, "Created_Fragments", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Discarded_Routing_Entries);
	xmlSetProp (newxml, "Discarded_Routing_Entries", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.All);
	xmlSetProp (newxml, "All", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Forwarded);
	xmlSetProp (newxml, "Forwarded", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Delivered);
	xmlSetProp (newxml, "Delivered", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Header_Errors);
	xmlSetProp (newxml, "Header_Errors", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Address_Errors);
	xmlSetProp (newxml, "Address_Errors", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Unknown_Protocol);
	xmlSetProp (newxml, "Unknown_Protocol", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Input_Buffer_Errors);
	xmlSetProp (newxml, "Input_Buffer_Errors", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Requested);
	xmlSetProp (newxml, "Requested", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Output_Buffer_Errors);
	xmlSetProp (newxml, "Output_Buffer_Errors", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Snmp.Not_Routed);
	xmlSetProp (newxml, "Not_Routed", tmp);
	MYFREE (tmp);
}


static void Write_xml_Port_Equipement (xmlNodePtr xmlnode, struct Struct_Port *Port)
{
	xmlNodePtr newxml = NULL;
	gchar    *Port_Char = NULL;
	gchar     Date[30];

	ERROR_if (xmlnode == NULL);
	ERROR_if (Port == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Port", NULL);
	Port_Char = g_strdup_printf ("%d", Port->Num_Port);
	xmlSetProp (newxml, "Num", Port_Char);
	MYFREE (Port_Char);
	if (Port->Notification_En_Cours)
		xmlSetProp (newxml, "Notification", "1");
	else
		xmlSetProp (newxml, "Notification", "0");
	ctime_r (&Port->Derniere_Modification_Etat_Port, Date);
	Date[strlen (Date) - 1] = '\0';
	xmlSetProp (newxml, "Last_State_Change", Date);
}

static void Write_xml_Port_Equipement_FFW (xmlNodePtr xmlnode, struct Struct_Port_Fermer_Firewall *Port)
{
	xmlNodePtr newxml = NULL;
	gchar    *Port_Char = NULL;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Port == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Port", NULL);
	Port_Char = g_strdup_printf ("%d", Port->Num_Port);
	xmlSetProp (newxml, "Num", Port_Char);
	MYFREE (Port_Char);
}

static void Write_xml_Signature_Equipement (xmlNodePtr xmlnode, struct Struct_Equipement *Equipement)
{
	xmlNodePtr newxml = NULL;
	struct Struct_Signature *Signature = NULL;
	
	ERROR_if (xmlnode == NULL);
	ERROR_if (Equipement == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "FingerPrinting", NULL);
	xmlSetProp (newxml, "MD5", Equipement->Md5_Signature);
	xmlSetProp (newxml, "MD5_W", Equipement->Md5_Signature_W);
	xmlSetProp (newxml, "Header_FTP", Equipement->Entete_FTP);
	xmlSetProp (newxml, "Header_HTTP", Equipement->Entete_HTTP);
	xmlSetProp (newxml, "Header_IMAP", Equipement->Entete_IMAP);
	xmlSetProp (newxml, "Header_SMTP",Equipement->Entete_SMTP);
	xmlSetProp (newxml, "Header_SSH",Equipement->Entete_SSH);
	xmlSetProp (newxml, "Header_TELNET", Equipement->Entete_TELNET);
		
	xmlSetProp (newxml, "Debug", Equipement->Debug_Signature);

	Signature = Equipement->Signature;
	if (Signature!=NULL){
		xmlSetProp (newxml, "System_name", Signature->System_Name);
		xmlSetProp (newxml, "Type", Liste_Modele_Objet[Equipement->Signature->Equipment_Type].Texte_Defaut);	
	}
	
}


static void Write_xml_Historique_Equipement (xmlNodePtr xmlnode, struct Struct_Historique *Historique)
{
	xmlNodePtr newxml = NULL;
	gchar    *Niveau_Historique = NULL;
	gchar     Date[30];

	ERROR_if (xmlnode == NULL);
	ERROR_if (Historique == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "History", NULL);
	ctime_r (&Historique->Date, Date);
	Date[strlen (Date) - 1] = '\0';
	xmlSetProp (newxml, "Date", Date);
	Niveau_Historique = g_strdup_printf ("%d", Historique->Niveau_Historique);
	xmlSetProp (newxml, "Level", Niveau_Historique);
	MYFREE (Niveau_Historique);
	xmlSetProp (newxml, "Text", Historique->Historique);
}


static void Write_xml_Nessus_Equipement (xmlNodePtr xmlnode, struct Struct_Nessus *Nessus)
{
	xmlNodePtr newxml = NULL;
	gchar    *Niveau_Nessus = NULL;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Nessus == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Nessus", NULL);
	Niveau_Nessus = g_strdup_printf ("%d", Nessus->Niveau_Nessus);
	xmlSetProp (newxml, "Level", Niveau_Nessus);
	MYFREE (Niveau_Nessus);
	xmlSetProp (newxml, "Info", Nessus->Info);
	xmlSetProp (newxml, "Text", Nessus->Texte);
}


static void Write_xml_Samba_Equipement (xmlNodePtr xmlnode, struct Struct_Equipement *Equipement, gint i)
{
	xmlNodePtr newxml = NULL;
	gchar    *tmp = NULL;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Equipement == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Registration", NULL);
	tmp = g_strdup_printf ("%d", Equipement->Smb.Smb_Registration[i].Numero);
	xmlSetProp (newxml, "Number", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Smb.Smb_Registration[i].Type);
	xmlSetProp (newxml, "Type", tmp);
	MYFREE (tmp);
	xmlSetProp (newxml, "Name", Equipement->Smb.Smb_Registration[i].Name);
}


static void Write_xml_Subnet (xmlNodePtr xmlnode, struct Struct_Subnet *Subnet)
{
	xmlNodePtr newxml = NULL;
	gchar    *tmp = NULL;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Subnet == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Subnet", NULL);
	tmp = g_strdup_printf ("%d", Subnet->Masque);
	xmlSetProp (newxml, "Masque", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Subnet->A);
	xmlSetProp (newxml, "A", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Subnet->B);
	xmlSetProp (newxml, "B", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Subnet->C);
	xmlSetProp (newxml, "C", tmp);
	MYFREE (tmp);
}


static void Write_xml (xmlNodePtr xmlnode, struct Struct_Equipement *Equipement)
{
	xmlNodePtr newxml = NULL, newxml_Rep = NULL, newxml_Port = NULL, newxml_Port_Udp = NULL;
	struct Struct_Port *Port = NULL;
	struct Struct_Port_Fermer_Firewall *Port_FFW = NULL;
	struct Struct_Historique *Historique = NULL;
	struct Struct_Nessus *Nessus = NULL;
	struct Struct_Modele_Objet *Objet = NULL;
	GtkTreePath *path = NULL;
	GtkTreeModel *model = NULL;


	gchar    *tmp = NULL;
	gchar     Date[30];
	guint     Nb_Objet_Liste, i;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Equipement == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "Equipment", NULL);


	xmlSetProp (newxml, "Address_IP", Equipement->Adresse_Ip_Char);
	xmlSetProp (newxml, "Address_MAC", Equipement->Adresse_MAC_Char);
	xmlSetProp (newxml, "Localisation", Equipement->Localisation);
	xmlSetProp (newxml, "Admin_Email", Equipement->Contact_Admin);
	xmlSetProp (newxml, "Dns", Equipement->Nom_DNS_Complet);
	xmlSetProp (newxml, "Alias", Equipement->Alias);
	xmlSetProp (newxml, "Serial_Number", Equipement->Num_Serie);
	xmlSetProp (newxml, "Serial_Number_Display", Equipement->Num_Serie_Ecran);
	xmlSetProp (newxml, "Serial_Number_Printer", Equipement->Num_Serie_Imprimante);
	xmlSetProp (newxml, "Serial_Number_OS", Equipement->Num_Serie_OS);
	xmlSetProp (newxml, "Serial_Number_Office_Suite", Equipement->Num_Serie_Office_Suite);
	xmlSetProp (newxml, "Processor", Equipement->Processeur);
	xmlSetProp (newxml, "Memory", Equipement->Memoire);
	xmlSetProp (newxml, "Disk", Equipement->Disque);
	xmlSetProp (newxml, "Contact", Equipement->Contact);
	xmlSetProp (newxml, "Tel_Contact", Equipement->Tel_Contact);
	xmlSetProp (newxml, "Notes", Equipement->Notes);

	if (Equipement->Agent_AutoScan)
		xmlSetProp (newxml, "Agent_AutoScan", "1");
	else
		xmlSetProp (newxml, "Agent_AutoScan", "0");

	if (Equipement->Notification_En_Cours)
		xmlSetProp (newxml, "Notification", "1");
	else
		xmlSetProp (newxml, "Notification", "0");

	if (Equipement->GateWay)
		xmlSetProp (newxml, "Gateway", "1");
	else
		xmlSetProp (newxml, "Gateway", "0");

	if (Equipement->Routage)
		xmlSetProp (newxml, "Routage", "1");
	else
		xmlSetProp (newxml, "Routage", "0");
	
	if (Equipement->Snmp_Ouvert)
		xmlSetProp (newxml, "Snmp_Open", "1");
	else
		xmlSetProp (newxml, "Snmp_Open", "0");
	


	if (!Reseau_Selectionner->Mode_Liste_Detaille) {
	
		Objet = Equipement->Objet_Liste_Par_Type;
		Objet = Objet->Objet_Pere;
		if (Objet != NULL) {
		
			model = gtk_tree_view_get_model (GTK_TREE_VIEW (Reseau_Selectionner->Liste_Equipement_Type));
		
		
			path = gtk_tree_model_get_path (model, &Objet->ID_Arbre_Ligne);
		
		
			if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (Reseau_Selectionner->Liste_Equipement_Type), path)) {
				xmlSetProp (newxml, "Expand", "1");
			
			}
			else {
				xmlSetProp (newxml, "Expand", "0");
			
			}
		}
		else
			xmlSetProp (newxml, "Expand", "0");
	}
	else {
		if (Equipement->Deplier) {
			xmlSetProp (newxml, "Expand", "1");
		
		}
		else {
			xmlSetProp (newxml, "Expand", "0");
		
		}
	}
	ctime_r (&Equipement->Derniere_Modification_Etat_Equipement, Date);
	Date[strlen (Date) - 1] = '\0';
	xmlSetProp (newxml, "Last_State_Change", Date);


	Write_xml_Signature_Equipement (newxml, Equipement);
	


	newxml_Rep = xmlNewChild (newxml, NULL, "Ports", NULL);
	tmp = g_strdup_printf ("%d", Equipement->Nb_Port_Ouvert);
	xmlSetProp (newxml_Rep, "Open", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Nb_Port_Total_Scanner);
	xmlSetProp (newxml_Rep, "Total", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Nb_Port_Firewaller);
	xmlSetProp (newxml_Rep, "firewalled", tmp);
	MYFREE (tmp);
	tmp = g_strdup_printf ("%d", Equipement->Nb_Port_Fermer);
	xmlSetProp (newxml_Rep, "Close", tmp);
	MYFREE (tmp);
	
	


	newxml_Port = xmlNewChild (newxml_Rep, NULL, "Open", NULL);
	Nb_Objet_Liste = g_list_length (Equipement->GList_Port);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Port = g_list_nth_data (Equipement->GList_Port, i);
		Write_xml_Port_Equipement (newxml_Port, Port);
	}

	newxml_Port = xmlNewChild (newxml_Rep, NULL, "Close", NULL);
	Nb_Objet_Liste = g_list_length (Equipement->GList_Port_Fermer);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Port_FFW = g_list_nth_data (Equipement->GList_Port_Fermer, i);
		Write_xml_Port_Equipement_FFW(newxml_Port, Port_FFW);
	}

	newxml_Port = xmlNewChild (newxml_Rep, NULL, "Firewall", NULL);
	Nb_Objet_Liste = g_list_length (Equipement->GList_Port_Firewall);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Port_FFW = g_list_nth_data (Equipement->GList_Port_Firewall, i);
		Write_xml_Port_Equipement_FFW(newxml_Port, Port_FFW);
	}

	newxml_Port = xmlNewChild (newxml_Rep, NULL, "UDP", NULL);
	for (i = 0; i < NB_PORT_UDP; i++){
		newxml_Port_Udp = xmlNewChild (newxml_Port, NULL, "Port", NULL);
		tmp = g_strdup_printf ("%d", Liste_Port_UDP[i].Num_Port_UDP);
		xmlSetProp (newxml_Port_Udp, "Num", tmp);
		MYFREE (tmp);
		tmp = g_strdup_printf ("%d", Equipement->Liste_Etat_Udp[i]);
		xmlSetProp (newxml_Port_Udp, "State", tmp);
		MYFREE (tmp);		
	}
	


	newxml_Rep = xmlNewChild (newxml, NULL, "History", NULL);
	Nb_Objet_Liste = g_list_length (Equipement->GList_Historique);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Historique = g_list_nth_data (Equipement->GList_Historique, i);
		Write_xml_Historique_Equipement (newxml_Rep, Historique);
	}
	


	newxml_Rep = xmlNewChild (newxml, NULL, "Smb", NULL);
	xmlSetProp (newxml_Rep, "Host_Name", Equipement->Smb.HostName);
	xmlSetProp (newxml_Rep, "Domain_Name", Equipement->Smb.DomainName);
	xmlSetProp (newxml_Rep, "User", Equipement->Smb.Utilisateur);
	xmlSetProp (newxml_Rep, "User_Smb", Equipement->User_Smb);
	xmlSetProp (newxml_Rep, "Password_Smb", Equipement->Password_Smb);

	i = 0;
	while ((i < NUM_MAX_REGISTRATION) && (Equipement->Smb.Smb_Registration[i].Type != 0)) {
		Write_xml_Samba_Equipement (newxml_Rep, Equipement, i);
		i++;
	}
	


	newxml_Rep = xmlNewChild (newxml, NULL, "Nessus", NULL);
	Nb_Objet_Liste = g_list_length (Equipement->GList_Nessus);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Nessus = g_list_nth_data (Equipement->GList_Nessus, i);
		Write_xml_Nessus_Equipement (newxml_Rep, Nessus);
	}
	


	Write_xml_Snmp_Equipement (newxml, Equipement);

}


static gboolean write_xml (char *fname)
{
	xmlDocPtr doc = NULL;
	struct Struct_Equipement *Equipement = NULL;
	struct Struct_Modele_Objet *Objet = NULL;
	struct Struct_Subnet *Subnet;
	gchar	*tmp;
	guint     Nb_Objet_Liste, i;
	xmlNodePtr newxml_Rep = NULL;
	xmlNodePtr nStylesheet = NULL;       
	xmlNode  *root_element = NULL;

	ERROR_if (fname == NULL);




	doc = xmlNewDoc (BAD_CAST "1.0");
	root_element = xmlNewNode (NULL, BAD_CAST "AutoScan_V2");
	xmlDocSetRootElement (doc, root_element);


  	nStylesheet = xmlNewPI (BAD_CAST "xml-stylesheet", BAD_CAST "type=\"text/xsl\" href=\"" DESTDIR "/usr/share/apps/autoscan-network/Stylesheet.xsl\"");
  	xmlAddPrevSibling (root_element, nStylesheet);

	xmlAddChild (root_element, xmlNewDocComment (doc, "Copyright (c) Lagarde thierry. \nThis Database is available for free use by open source software under the terms of the GNU General Public License.\nContact <tlagarde@users.sourceforge.net>  for more information"));


	xmlSetProp (root_element, "Network", Reseau_Selectionner->Nom_Reseau);
	xmlSetProp (root_element, "Interface", Reseau_Selectionner->Interface);
	xmlSetProp (root_element, "Ip", Reseau_Selectionner->Ip);
	xmlSetProp (root_element, "Ip_Agent", Reseau_Selectionner->Ip_Agent);
	tmp = g_strdup_printf ("%d", Reseau_Selectionner->Port_Agent);
	xmlSetProp (root_element, "Port_Agent", tmp);
	MYFREE (tmp);
	xmlSetProp (root_element, "Communaute_Snmp", Reseau_Selectionner->Communaute_Snmp);
	xmlSetProp (root_element, "Icon", Reseau_Selectionner->Icone_Reseau);
	if (Reseau_Selectionner->Alert_Intrusion)
		xmlSetProp (root_element, "Intrusion_Alert", "1");
	else
		xmlSetProp (root_element, "Intrusion_Alert", "0");

	if (Reseau_Selectionner->Mode_Liste_Detaille)
		xmlSetProp (root_element, "Mode_IP", "1");
	else
		xmlSetProp (root_element, "Mode_IP", "0");
	
	if (Reseau_Selectionner->Ip_Dynamic)
		xmlSetProp (root_element, "Ip_Dynamic", "1");
	else
		xmlSetProp (root_element, "Ip_Dynamic", "0");

	newxml_Rep = xmlNewChild (root_element, NULL, "Subnet", NULL);
	Nb_Objet_Liste = g_list_length (Reseau_Selectionner->Glist_Subnet_Equipement);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Subnet = g_list_nth_data (Reseau_Selectionner->Glist_Subnet_Equipement, i);
		Write_xml_Subnet (newxml_Rep, Subnet);
	}


	Nb_Objet_Liste = g_list_length (Reseau_Selectionner->GList_Liste_Equipement);

	for (i = 0; i < Nb_Objet_Liste; i++) {
		Objet = g_list_nth_data (Reseau_Selectionner->GList_Liste_Equipement, i);
	
		if (Objet->Nb_Enfant == 0) {
			Equipement = (struct Struct_Equipement *) Objet->Pointeur_Attacher;
			if (!Equipement->Equipement_Erase)
				Write_xml (root_element, Equipement);
		}
	}
	if (xmlSaveFile (fname, doc) == -1) {
		xmlFreeDoc (doc);
		debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "impossible d'enregistrer le fichier xml");
		return FALSE;
	}
	xmlFreeDoc (doc);
	return TRUE;
}




void Enregistrement (gchar * Chemin_Fichier)
{
	ERROR_if (Chemin_Fichier == NULL);
	debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Save : [%s]", Chemin_Fichier);
	write_xml (Chemin_Fichier);
}
