/* ***********************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 <gtk/gtk.h>
#include "Settings_Signature.h"
#include "Settings.h"
#include "Interface/Settings_Interface.h"
#include "Interface/Update_Interface.h"
#include "Interface/Demarrage_Interface.h"
#include "Interface/Maemo.h"
#include "Debug.h"
#include "Objet.h"
#include "Image.h"
#include "main.h"
#include "Declaration_Constante.h"
#include "Macro.h"



void Liste_Signature_Efface_Champs (void)
{
	Liste_Signatures_Modification_Interface = TRUE;
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_System_name), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Md5), "");
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_Liste_Signature_Open_Port), -1);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_Liste_Signature_Close_Port), -1);
	
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Type), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_FTP), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_HTTP), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_HTTPS), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_IMAP), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SMTP), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SSH), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Telnet), 0);
	
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_NAME), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_DEVICE), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_DESCRIPTION), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_GATEWAY), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_ROUTAGE), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Snmp), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Smb), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Sip), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Printer), 0);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_JetDirect), 0);




	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton_Liste_Signature_Firewall), FALSE);

	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_MAC), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_FTP), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_HTTP), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_HTTPS), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_IMAP), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_SMTP), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_SSH), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Header_TELNET), "");
	
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_UDP), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_SNMP_NAME), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_SNMP_DEVICE), "");
	gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_SNMP_DESCRIPTION), "");
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature), -1);
	Liste_Signatures_Modification_Interface = FALSE;
}

void Liste_Signature_Sensible (gboolean bool)
{
	gtk_widget_set_sensitive (entry_Liste_Signature_System_name, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_Type, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Md5, FALSE);
	gtk_widget_set_sensitive (entry_Liste_Signature_MAC, bool);
	gtk_widget_set_sensitive (spinbutton_Liste_Signature_Open_Port, bool);
	gtk_widget_set_sensitive (spinbutton_Liste_Signature_Close_Port, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_FTP, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_FTP, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_HTTP, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_HTTP, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_HTTPS, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_HTTPS, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_IMAP, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_IMAP, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_SMTP, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_SMTP, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_SSH, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_SSH, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_Telnet, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_Header_TELNET, bool);
	
	gtk_widget_set_sensitive (entry_Liste_Signature_UDP, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_SNMP_NAME, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_SNMP_DEVICE, bool);
	gtk_widget_set_sensitive (entry_Liste_Signature_SNMP_DESCRIPTION, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_SNMP_NAME, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_SNMP_DEVICE, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_SNMP_DESCRIPTION, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_GATEWAY, bool);	
	gtk_widget_set_sensitive (combobox_Liste_Signature_ROUTAGE, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_Snmp, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_Smb, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_Sip, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_Printer, bool);
	gtk_widget_set_sensitive (combobox_Liste_Signature_JetDirect, bool);
	




	gtk_widget_set_sensitive (checkbutton_Liste_Signature_Firewall, bool);
}

void Initialisation_Liste_Signature (void)
{
	Liste_Signature_Sensible (FALSE);
	gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature), -1);
	gtk_widget_set_sensitive (button_Liste_Signature_Ok, FALSE);
	gtk_widget_set_sensitive (button_Liste_Signature_Add, TRUE);
	gtk_widget_set_sensitive (button_Liste_Signature_Delete, FALSE);
	gtk_widget_set_sensitive (button_Liste_Signature_Cancel, FALSE);
	Liste_Signatures_Modification_Interface = FALSE;
	Signature_Modification = NULL;
	Signature_Selectionner = NULL;
}

void Affiche_Signature (struct Struct_Signature *Signature, struct Struct_Signature *Signature_Pere)
{
	GtkTreeModel *model = NULL;
	GtkTreeIter Ligne;

	ERROR_if (Signature == NULL);
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Liste_Signature));
	if (Signature_Pere != NULL)
		gtk_tree_store_append (GTK_TREE_STORE (model), &Ligne, &Signature_Pere->ID_Arbre_Ligne);
	else
		gtk_tree_store_append (GTK_TREE_STORE (model), &Ligne, NULL);
	Signature->ID_Arbre_Ligne = Ligne;
	gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, COL_NAME, Signature->System_Name, COL_MD5, Signature->Md5_Signature, POINTER, Signature, -1);
}

void Afficher_Liste_Signature_Debug (void)
{
	struct Struct_Signature *Signature = NULL, *Signature_Pere = NULL;
	guint     Nb_Objet_Liste, i, rangPere;

	Nb_Objet_Liste = g_list_length (Settings->GList_Signature);
	printf("Affiche Liste Signature (%d)***************\n", Nb_Objet_Liste);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Signature = g_list_nth_data (Settings->GList_Signature, i);
		Signature_Pere = (struct Struct_Signature *) Signature->Signature_Pere;
		rangPere = g_list_position (Settings->GList_Signature, g_list_find (Settings->GList_Signature, Signature_Pere));
		printf("%d : [%s] [%s]  pere [%d]\n", i, Signature->System_Name, Signature->Md5_Signature, rangPere);
	}
	printf("Fin Liste ****************\n");
}

void Afficher_Liste_Signature (void)
{
	struct Struct_Signature *Signature = NULL, *Signature_Pere = NULL;
	guint     Nb_Objet_Liste, i, rangPere;

	Nb_Objet_Liste = g_list_length (Settings->GList_Signature);

	for (i = 0; i < Nb_Objet_Liste; i++) {
		Signature = g_list_nth_data (Settings->GList_Signature, i);
		Signature_Pere = (struct Struct_Signature *) Signature->Signature_Pere;
		rangPere = g_list_position (Settings->GList_Signature, g_list_find (Settings->GList_Signature, Signature_Pere));
	
		Affiche_Signature (Signature, Signature_Pere);
	}

}

struct Struct_Signature *Liste_Signature_Recherche_Orphelin (gchar * Md5_Signature)
{
	struct Struct_Signature *Signature = NULL;
	guint     Nb_Objet_Liste, i;

	ERROR_if (Md5_Signature == NULL);
	Nb_Objet_Liste = g_list_length (Settings->GList_Signature);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Signature = g_list_nth_data (Settings->GList_Signature, i);
		if ((Signature->Signature_Pere == NULL) && (strcmp (Signature->Md5_Signature, Md5_Signature) == 0))
			return Signature;
	}
	return NULL;
}

void Supprime_Signature_liste (struct Struct_Signature *Signature)
{
	struct Struct_Signature *Signature_Pere = NULL;
	GtkTreeModel *model = NULL;

	ERROR_if (Signature == NULL);
	G_LIST_REMOVE (Settings->GList_Signature, Signature);
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Liste_Signature));
	gtk_tree_store_remove (GTK_TREE_STORE (model), &Signature->ID_Arbre_Ligne);
	Signature_Pere = (struct Struct_Signature *) Signature->Signature_Pere;









	if (Signature_Pere != NULL) {
		Signature_Pere->Nb_Fils--;
		if (Signature_Pere->Nb_Fils == 0)
			Supprime_Signature_liste (Signature_Pere);
	}
}

struct Struct_Signature *Creer_Pere_Signature (struct Struct_Signature *Signature_Orphelin, gchar * Md5_Signature)
{
	struct Struct_Signature *Pere = NULL;
	GtkTreeModel *model = NULL;

	ERROR_if (Signature_Orphelin == NULL);
	ERROR_if (Md5_Signature == NULL);


	G_LIST_REMOVE (Settings->GList_Signature, Signature_Orphelin);
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Liste_Signature));
	gtk_tree_store_remove (GTK_TREE_STORE (model), &Signature_Orphelin->ID_Arbre_Ligne);

	MALLOC (Pere, sizeof (struct Struct_Signature));
	Pere->System_Name = g_strdup ("New");
	Pere->Md5_Signature = g_strdup (Md5_Signature);
	G_LIST_APPEND (Settings->GList_Signature, Pere);
	Pere->Nb_Fils++;
	Affiche_Signature (Pere, NULL);

	G_LIST_APPEND (Settings->GList_Signature, Signature_Orphelin);
	Signature_Orphelin->Signature_Pere = (gpointer *) Pere;
	Affiche_Signature (Signature_Orphelin, Pere);
	return Pere;
}

struct Struct_Signature *Modifie_Ajouter_Signature_Dans_Glist (struct Struct_Signature *Pere)
{
	struct Struct_Signature *Signature = NULL;

	if (Signature_Modification == NULL) {
		MALLOC (Signature, sizeof (struct Struct_Signature));
	}
	else
		Signature = Signature_Modification;

	free_gchar_if_no_null (Signature->System_Name);
	Signature->System_Name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_System_name)));
	if ((strlen (Signature->System_Name) != 0) && (Signature->Nb_Fils == 0)) {
		free_gchar_if_no_null (Signature->Md5_Signature);
		Signature->Md5_Signature = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Md5)));
		free_gchar_if_no_null (Signature->Icon);
		Signature->Icon = g_strdup_printf ("%sEquipment/%s", PATH_ICONE, Recuperation_Texte_Combo (combobox_Liste_Signature));
		if ((Signature->Icon != NULL) && (strlen (Signature->Icon) != 0)) {
		
			Signature->icone = Chargement_Image (Signature->Icon, COULEUR);
			Signature->icone_grise = Chargement_Image (Signature->Icon, NOIR_ET_BLANC);
		}
		Signature->Equipment_Type = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_Type));
		Signature->Open_Port = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton_Liste_Signature_Open_Port));
		Signature->Close_Port = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton_Liste_Signature_Close_Port));
		
		Signature->Firewall = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_Liste_Signature_Firewall));
	
		Signature->Etat_FTP = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_FTP));
		Signature->Etat_HTTP = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_HTTP));
		Signature->Etat_HTTPS = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_HTTPS));
		Signature->Etat_IMAP = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_IMAP));
		Signature->Etat_SMTP = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_SMTP));
		Signature->Etat_SSH	= gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_SSH));
		Signature->Etat_TELNET = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_Telnet));


		Signature->Etat_Snmp_Name = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_NAME));
		Signature->Etat_Snmp_Description = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_DESCRIPTION));
		Signature->Etat_Snmp_Device = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_DEVICE));
		Signature->GateWay = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_GATEWAY));
		Signature->Routage = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_ROUTAGE));
		Signature->Snmp = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_Snmp));
		Signature->Smb = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_Smb));
		Signature->Sip = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_Sip));
		Signature->Printer = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_Printer));
		Signature->JetDirect = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox_Liste_Signature_JetDirect));

		free_gchar_if_no_null (Signature->MAC);
		Signature->MAC = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_MAC)));
		free_gchar_if_no_null (Signature->UDP);
		Signature->UDP = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_UDP)));
		free_gchar_if_no_null (Signature->Snmp_Name);
		Signature->Snmp_Name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_SNMP_NAME)));
		free_gchar_if_no_null (Signature->Snmp_Description);
		Signature->Snmp_Description = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_SNMP_DESCRIPTION)));
		free_gchar_if_no_null (Signature->Snmp_Device);
		Signature->Snmp_Device = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_SNMP_DEVICE)));
				
		free_gchar_if_no_null (Signature->Header_FTP);
		Signature->Header_FTP = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_FTP)));
		free_gchar_if_no_null (Signature->Header_HTTP);
		Signature->Header_HTTP = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_HTTP)));
		free_gchar_if_no_null (Signature->Header_HTTPS);
		Signature->Header_HTTPS = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_HTTPS)));
		free_gchar_if_no_null (Signature->Header_IMAP);
		Signature->Header_IMAP = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_IMAP)));
		free_gchar_if_no_null (Signature->Header_SMTP);
		Signature->Header_SMTP = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_SMTP)));
		free_gchar_if_no_null (Signature->Header_SSH);
		Signature->Header_SSH = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_SSH)));
		free_gchar_if_no_null (Signature->Header_TELNET);
		Signature->Header_TELNET = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Header_TELNET)));
		Signature->Nb_Fils = 0;
		if (Signature_Modification == NULL) {
			G_LIST_APPEND (Settings->GList_Signature, Signature);
			Signature->Signature_Pere = (gpointer *) Pere;
			if (Pere != NULL)
				Pere->Nb_Fils++;
		}
	}
	else
		return NULL;
	return Signature;
}

void Modifie_Ajoute_Nouvelle_Signature (void)
{
	struct Struct_Signature *Signature = NULL, *Signature_Frere = NULL, *Signature_Pere = NULL;
	GtkTreeModel *model = NULL;
	
	if (Signature_Modification != NULL) {
		Modifie_Ajouter_Signature_Dans_Glist (NULL);
		model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Liste_Signature));
		gtk_tree_store_set (GTK_TREE_STORE (model), &Signature_Modification->ID_Arbre_Ligne, COL_NAME, Signature_Modification->System_Name, -1);
		return;
	}

	Signature_Frere = Liste_Signature_Recherche_Orphelin ((gchar *) gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Md5)));
	if (Signature_Frere == NULL) {
	
		Signature = Modifie_Ajouter_Signature_Dans_Glist (NULL);
		Affiche_Signature (Signature, NULL);
	}
	else {
	
		if (Signature_Frere->Nb_Fils != 0) {
		
			Signature = Modifie_Ajouter_Signature_Dans_Glist (Signature_Frere);
			Affiche_Signature (Signature, Signature_Frere);
			return;
		}
		else {
		
			Signature_Pere = Creer_Pere_Signature (Signature_Frere, (gchar *) gtk_entry_get_text (GTK_ENTRY (entry_Liste_Signature_Md5)));
			Signature = Modifie_Ajouter_Signature_Dans_Glist (Signature_Pere);
			Affiche_Signature (Signature, Signature_Pere);
		
		}
	}

}


struct Struct_Signature *Rajouter_Signature_Dans_Glist (struct Struct_Signature *Pere, gchar * Nom, gchar * Signature_Md5, gint Type, gchar * icon, gchar * Entete_FTP, gchar * Entete_HTTP, gchar * Entete_HTTPS, gchar * Entete_IMAP, gchar * Entete_SMTP, gchar * Entete_SSH, gchar * Entete_TELNET, gboolean GateWay, gboolean Routage)
{
	struct Struct_Signature *Signature = NULL;

	ERROR_if (Nom == NULL);
	ERROR_if (Signature_Md5 == NULL);







    
	MALLOC (Signature, sizeof (struct Struct_Signature));

	Signature->System_Name = g_strdup (Nom);
	if (strlen (Signature->System_Name) != 0) {
		Signature->Md5_Signature = g_strdup (Signature_Md5);
		Signature->Icon = g_strdup (icon);
		if ((Signature->Icon != NULL) && (strlen (Signature->Icon) != 0)) {
		
			Signature->icone = Chargement_Image (Signature->Icon, COULEUR);
		}
		Signature->Equipment_Type = Type;
		Signature->Open_Port = -1;
		Signature->Close_Port = -1;
		Signature->Etat_FTP = INDIFFERENT;
		Signature->Etat_HTTP = INDIFFERENT;
		Signature->Etat_HTTPS = INDIFFERENT;
		Signature->Etat_IMAP = INDIFFERENT;
		Signature->Etat_SMTP = INDIFFERENT;
		Signature->Etat_SSH = INDIFFERENT;
		Signature->Etat_TELNET = INDIFFERENT;
		Signature->Etat_Snmp_Name = SNMP_INDIFFERENT;
		Signature->Etat_Snmp_Description = SNMP_INDIFFERENT;
		Signature->Etat_Snmp_Device = SNMP_INDIFFERENT;
		if (Entete_FTP != NULL)
			Signature->Header_FTP = g_strdup (Entete_FTP);
		if (Entete_HTTP != NULL)
			Signature->Header_HTTP = g_strdup (Entete_HTTP);
	
		if (Entete_IMAP != NULL)
			Signature->Header_IMAP = g_strdup (Entete_IMAP);
		if (Entete_SMTP != NULL)
			Signature->Header_SMTP = g_strdup (Entete_SMTP);
		if (Entete_SSH != NULL)
			Signature->Header_SSH = g_strdup (Entete_SSH);
		if (Entete_TELNET != NULL)
			Signature->Header_TELNET = g_strdup (Entete_TELNET);
		Signature->GateWay = (gint)GateWay;
		Signature->Routage = (gint)Routage;		
		Signature->Nb_Fils = 0;
		G_LIST_APPEND (Settings->GList_Signature, Signature);
		Signature->Signature_Pere = (gpointer *) Pere;
		if (Pere != NULL)
			Pere->Nb_Fils++;
	}
	return Signature;
}


void Rajouter_Nouvelle_Signature (gchar * Nom, gchar * Signature_Md5, gint Type, gchar * icon, gchar * Entete_FTP, gchar * Entete_HTTP,gchar * Entete_HTTPS, gchar * Entete_IMAP, gchar * Entete_SMTP, gchar * Entete_SSH, gchar * Entete_TELNET, gboolean GateWay, gboolean Routage)
{
	struct Struct_Signature *Signature = NULL, *Signature_Frere = NULL, *Signature_Pere = NULL;

	ERROR_if (Nom == NULL);
	ERROR_if (Signature_Md5 == NULL);







    
	Signature_Frere = Liste_Signature_Recherche_Orphelin (Signature_Md5);
	if (Signature_Frere == NULL) {
	
		Signature = Rajouter_Signature_Dans_Glist (NULL, Nom, Signature_Md5, Type, icon, Entete_FTP, Entete_HTTP, Entete_HTTPS, Entete_IMAP, Entete_SMTP, Entete_SSH, Entete_TELNET, GateWay, Routage);
		Affiche_Signature (Signature, NULL);
	}
	else {
	
		if (Signature_Frere->Nb_Fils != 0) {
		
			Signature = Rajouter_Signature_Dans_Glist (Signature_Frere, Nom, Signature_Md5, Type, icon, Entete_FTP, Entete_HTTP, Entete_HTTPS, Entete_IMAP, Entete_SMTP, Entete_SSH, Entete_TELNET, GateWay, Routage);
			Affiche_Signature (Signature, Signature_Frere);
		}
		else {
		
			Signature_Pere = Creer_Pere_Signature (Signature_Frere, Signature_Md5);
			Signature = Rajouter_Signature_Dans_Glist (Signature_Pere, Nom, Signature_Md5, Type, icon, Entete_FTP, Entete_HTTP, Entete_HTTPS, Entete_IMAP, Entete_SMTP, Entete_SSH, Entete_TELNET, GateWay, Routage);
			Affiche_Signature (Signature, Signature_Pere);
		
		}
	}
	Enregistrement_Donnee_Xml_Signature ();
}

static void write_signature_to_xml (xmlNodePtr xmlnode, struct Struct_Signature *Signature)
{
	struct Struct_Signature *Signature_Fils = NULL;
	xmlNodePtr newxml = NULL;
	gchar    *Num = NULL;
	guint     Nb_Objet_Liste, i;

	ERROR_if (xmlnode == NULL);
	ERROR_if (Signature == NULL);
	newxml = xmlNewChild (xmlnode, NULL, "OS_FingerPrinting", NULL);
	xmlSetProp (newxml, "System_Name", Signature->System_Name);
	xmlSetProp (newxml, "Md5_Signature", Signature->Md5_Signature);
	if ((Signature->Icon!=NULL)&&(strlen(DESTDIR)!=0)&&(strncmp(Signature->Icon,DESTDIR,strlen(DESTDIR))==0))
		xmlSetProp (newxml, "Icon", Signature->Icon+strlen(DESTDIR)); 
	else
		xmlSetProp (newxml, "Icon", Signature->Icon);
	
	if (Signature->Firewall)
		xmlSetProp (newxml, "Firewall", "1");
	else
		xmlSetProp (newxml, "Firewall", "0");
	
	/*if (Signature->Snmp)
		xmlSetProp (newxml, "Snmp", "1");
	else
		xmlSetProp (newxml, "Snmp", "0");*/
	
/*	if (Signature->Smb)
		xmlSetProp (newxml, "Smb", "1");
	else
		xmlSetProp (newxml, "Smb", "0");
	if (Signature->Sip)
		xmlSetProp (newxml, "Sip", "1");
	else
		xmlSetProp (newxml, "Sip", "0");
	if (Signature->Printer)
		xmlSetProp (newxml, "Printer", "1");
	else
		xmlSetProp (newxml, "Printer", "0");
	if (Signature->JetDirect)
		xmlSetProp (newxml, "JetDirect", "1");
	else
		xmlSetProp (newxml, "JetDirect", "0");	*/

	
	Num = g_strdup_printf ("%d", Signature->GateWay);
	xmlSetProp (newxml, "GateWay", Num);
	MYFREE (Num);
	
	Num = g_strdup_printf ("%d", Signature->Routage);
	xmlSetProp (newxml, "Routage", Num);
	MYFREE (Num);
	
	Num = g_strdup_printf ("%d", Signature->Snmp);
	xmlSetProp (newxml, "Snmp", Num);
	MYFREE (Num);

	Num = g_strdup_printf ("%d", Signature->Smb);
	xmlSetProp (newxml, "Smb", Num);
	MYFREE (Num);
	
	Num = g_strdup_printf ("%d", Signature->Sip);
	xmlSetProp (newxml, "Sip", Num);
	MYFREE (Num);
	
	Num = g_strdup_printf ("%d", Signature->Printer);
	xmlSetProp (newxml, "Printer", Num);
	MYFREE (Num);
		
	Num = g_strdup_printf ("%d", Signature->JetDirect);
	xmlSetProp (newxml, "JetDirect", Num);
	MYFREE (Num);
	
/*	if (Signature->GateWay)
		xmlSetProp (newxml, "GateWay", "1");
	else
		xmlSetProp (newxml, "GateWay", "0");
	if (Signature->Routage)
		xmlSetProp (newxml, "Routage", "1");
	else
		xmlSetProp (newxml, "Routage", "0");*/
		
	Num = g_strdup_printf ("%d", Signature->Equipment_Type);
	xmlSetProp (newxml, "Equipment_Type", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Open_Port);
	xmlSetProp (newxml, "Open_port", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Close_Port);
	xmlSetProp (newxml, "Close_port", Num);
	MYFREE (Num);	
	Num = g_strdup_printf ("%d", Signature->Etat_FTP);
	xmlSetProp (newxml, "FTP_State", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Etat_HTTP);
	xmlSetProp (newxml, "HTTP_State", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Etat_HTTPS);
	xmlSetProp (newxml, "HTTPS_State", Num);
	MYFREE (Num);	
	Num = g_strdup_printf ("%d", Signature->Etat_IMAP);
	xmlSetProp (newxml, "IMAP_State", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Etat_SMTP);
	xmlSetProp (newxml, "SMTP_State", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Etat_SSH);
	xmlSetProp (newxml, "SSH_State", Num);
	MYFREE (Num);
	Num = g_strdup_printf ("%d", Signature->Etat_TELNET);
	xmlSetProp (newxml, "TELNET_State", Num);
	MYFREE (Num);
	xmlSetProp (newxml, "MAC", Signature->MAC);
	xmlSetProp (newxml, "UDP", Signature->UDP);
	xmlSetProp (newxml, "Snmp_Name", Signature->Snmp_Name);
	Num = g_strdup_printf ("%d", Signature->Etat_Snmp_Name);
	xmlSetProp (newxml, "Snmp_Name_State", Num);
	MYFREE (Num);
	xmlSetProp (newxml, "Snmp_Description", Signature->Snmp_Description);
	Num = g_strdup_printf ("%d", Signature->Etat_Snmp_Description);
	xmlSetProp (newxml, "Snmp_Description_State", Num);
	MYFREE (Num);
	xmlSetProp (newxml, "Snmp_Device", Signature->Snmp_Device);
	Num = g_strdup_printf ("%d", Signature->Etat_Snmp_Device);
	xmlSetProp (newxml, "Snmp_Device_State", Num);
	MYFREE (Num);
	xmlSetProp (newxml, "Header_FTP", Signature->Header_FTP);
	xmlSetProp (newxml, "Header_HTTP", Signature->Header_HTTP);
	xmlSetProp (newxml, "Header_HTTPS", Signature->Header_HTTPS);
	xmlSetProp (newxml, "Header_Imap", Signature->Header_IMAP);
	xmlSetProp (newxml, "Header_SMTP", Signature->Header_SMTP);
	xmlSetProp (newxml, "Header_SSH", Signature->Header_SSH);
	xmlSetProp (newxml, "Header_Telnet", Signature->Header_TELNET);
	if (Signature->Nb_Fils != 0) {
		Nb_Objet_Liste = g_list_length (Settings->GList_Signature);
		for (i = 0; i < Nb_Objet_Liste; i++) {
			Signature_Fils = g_list_nth_data (Settings->GList_Signature, i);
			if (Signature_Fils->Signature_Pere == (gpointer *) Signature)
				write_signature_to_xml (newxml, Signature_Fils);
		}
	}
}


static gboolean write_xml_file (char *fname)
{
	struct Struct_Signature *Signature = NULL;
	xmlDocPtr doc = NULL;
	guint     Nb_Objet_Liste, i;
	xmlNode  *root_element = NULL;

	ERROR_if (fname == NULL);
	doc = xmlNewDoc (BAD_CAST "1.0");
	root_element = xmlNewNode (NULL, BAD_CAST "OS_FingerPrinting_AutoScan");
	xmlDocSetRootElement (doc, root_element);

	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 GPL Version 2.\nContact <thierry@autoscan-network.com>  for more information"));
	Nb_Objet_Liste = g_list_length (Settings->GList_Signature);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Signature = g_list_nth_data (Settings->GList_Signature, i);
		if (Signature->Signature_Pere == NULL)
			write_signature_to_xml (root_element, Signature);
	}
	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_Donnee_Xml_Signature (void)
{
	gchar    *Chemin = NULL;

	Chemin = g_strdup_printf ("%s/.autoscan-network/config/" FILE_XML_FINGER_PRINTING , Info_User->pw_dir);
	write_xml_file (Chemin);
	MYFREE (Chemin);
}



void Lit_Donnee_Xml_Signature (xmlNodePtr xmlnode, struct Struct_Signature *Signature_Pere)
{
	struct Struct_Signature *Signature = NULL;
	char     *Num_Port = NULL, *Type = NULL, *Etat_Port = NULL, *Case = NULL;
	gint      Nb_Fils;

	ERROR_if (xmlnode == NULL);
	Nb_Signature++;	

	if (!xmlnode->name || g_strcasecmp (xmlnode->name, "OS_FingerPrinting") != 0)
		return;

	MALLOC (Signature, sizeof (struct Struct_Signature));

	Nb_Fils = 0;
	Signature->System_Name = xmlGetProp (xmlnode, "System_Name");
	if (Signature->System_Name) {
		Signature->Md5_Signature = xmlGetProp (xmlnode, "Md5_Signature");
		Signature->Icon = xmlGetProp (xmlnode, "Icon");
	
		/*if ((Signature->Icon != NULL) && (strlen (Signature->Icon) != 0)) {
		 * Signature->icone = Chargement_Image (Signature->Icon, COULEUR);
		 * Signature->icone_grise = Chargement_Image (Signature->Icon, NOIR_ET_BLANC);
		 * } */
		Type = xmlGetProp (xmlnode, "Equipment_Type");
		if (sscanf (Type, "%d", &Signature->Equipment_Type) != 1)
			Signature->Equipment_Type = -1;
		MYFREE (Type);
		if ((NB_TYPE_EQUIPEMENT<Signature->Equipment_Type) || (Signature->Equipment_Type<0)){
			Change_Etat_Barre_Demarrage("File corrupt (" FILE_XML_FINGER_PRINTING ")",1);
			printf("File corrupt (" FILE_XML_FINGER_PRINTING ") Type equipement (%d) %s\n", Signature->Equipment_Type,Signature->System_Name);
			sleep(3);
			exit(-1);
		}
		Num_Port = xmlGetProp (xmlnode, "Open_port");
		if (sscanf (Num_Port, "%d", &Signature->Open_Port) != 1)
			Signature->Open_Port = -1;
		MYFREE (Num_Port);
		Num_Port = xmlGetProp (xmlnode, "Close_port");
		if ((Num_Port==NULL) || (sscanf (Num_Port, "%d", &Signature->Close_Port) != 1))
			Signature->Close_Port = -1;
		MYFREE (Num_Port);		
		
		Case = xmlGetProp (xmlnode, "Snmp");
		if (sscanf (Case, "%d", &Signature->Snmp) != 1)
			Signature->Snmp = -1;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "Firewall");
		if (sscanf (Case, "%d", &Signature->Firewall) != 1)
			Signature->Firewall = FALSE;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "Smb");
		if (sscanf (Case, "%d", &Signature->Smb) != 1)
			Signature->Smb = -1;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "Sip");
		if (sscanf (Case, "%d", &Signature->Sip) != 1)
			Signature->Sip = -1;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "Printer");
		if (sscanf (Case, "%d", &Signature->Printer) != 1)
			Signature->Printer = -1;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "JetDirect");
		if (sscanf (Case, "%d", &Signature->JetDirect) != 1)
			Signature->JetDirect = -1;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "GateWay");
		if (sscanf (Case, "%d", &Signature->GateWay) != 1)
			Signature->GateWay = -1;
		MYFREE (Case);
		Case = xmlGetProp (xmlnode, "Routage");
		if (sscanf (Case, "%d", &Signature->Routage) != 1)
			Signature->Routage = -1;
		MYFREE (Case);		
		
		Etat_Port = xmlGetProp (xmlnode, "FTP_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_FTP) != 1)
			Signature->Etat_FTP = -1;
		MYFREE (Etat_Port);
		Etat_Port = xmlGetProp (xmlnode, "HTTP_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_HTTP) != 1)
			Signature->Etat_HTTP = -1;
		MYFREE (Etat_Port);
		Etat_Port = xmlGetProp (xmlnode, "HTTPS_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_HTTPS) != 1)
			Signature->Etat_HTTPS = -1;
		MYFREE (Etat_Port);	
		Etat_Port = xmlGetProp (xmlnode, "IMAP_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_IMAP) != 1)
			Signature->Etat_IMAP = -1;
		MYFREE (Etat_Port);
		Etat_Port = xmlGetProp (xmlnode, "SMTP_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_SMTP) != 1)
			Signature->Etat_SMTP = -1;
		MYFREE (Etat_Port);
		Etat_Port = xmlGetProp (xmlnode, "SSH_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_SSH) != 1)
			Signature->Etat_SSH = -1;
		MYFREE (Etat_Port);
		Etat_Port = xmlGetProp (xmlnode, "TELNET_State");
		if (sscanf (Etat_Port, "%d", &Signature->Etat_TELNET) != 1)
			Signature->Etat_TELNET = -1;
		MYFREE (Etat_Port);
		

		Signature->MAC = Lire_Info_Cle_Xml_Chaine (xmlnode, "MAC");
		Signature->UDP = Lire_Info_Cle_Xml_Chaine (xmlnode, "UDP");
		Signature->Snmp_Name = Lire_Info_Cle_Xml_Chaine (xmlnode, "Snmp_Name");
		Etat_Port = xmlGetProp (xmlnode, "Snmp_Name_State");
		if (Etat_Port!=NULL){
			if (sscanf (Etat_Port, "%d", &Signature->Etat_Snmp_Name) != 1)
				Signature->Etat_Snmp_Name = -1;
			MYFREE (Etat_Port);
		}
		Signature->Snmp_Description = Lire_Info_Cle_Xml_Chaine (xmlnode, "Snmp_Description");
		Etat_Port = xmlGetProp (xmlnode, "Snmp_Description_State");
		if (Etat_Port!=NULL){
			if (sscanf (Etat_Port, "%d", &Signature->Etat_Snmp_Description) != 1)
				Signature->Etat_Snmp_Description = -1;
			MYFREE (Etat_Port);
		}
		Signature->Snmp_Device = Lire_Info_Cle_Xml_Chaine (xmlnode, "Snmp_Device");		
		Etat_Port = xmlGetProp (xmlnode, "Snmp_Device_State");
		if (Etat_Port!=NULL){
			if (sscanf (Etat_Port, "%d", &Signature->Etat_Snmp_Device) != 1)
				Signature->Etat_Snmp_Device = -1;
			MYFREE (Etat_Port);
		}
		Signature->Header_FTP = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_FTP");
		Signature->Header_HTTP = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_HTTP");
		Signature->Header_HTTPS = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_HTTPS");
		Signature->Header_IMAP = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_Imap");
		Signature->Header_SMTP = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_SMTP");
		Signature->Header_SSH = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_SSH");
		Signature->Header_TELNET = Lire_Info_Cle_Xml_Chaine (xmlnode, "Header_Telnet");
		G_LIST_APPEND (Settings->GList_Signature, Signature);
		Signature->Signature_Pere = (gpointer *) Signature_Pere;
	}
	else {
		MYFREE (Signature);
		debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Nom du System_name Vide");
		return;
	}
	xmlnode = xmlnode->children;
	while (xmlnode) {
		if (xmlnode->type == XML_ELEMENT_NODE) {
			Lit_Donnee_Xml_Signature (xmlnode, Signature);
			Nb_Fils++;
		}
		xmlnode = xmlnode->next;
	}
	Signature->Nb_Fils = Nb_Fils;
	if (Nb_Fils != 0)
		Nb_Signature--;
}


void Lit_Xml_Signature (xmlDocPtr doc)
{
	xmlNodePtr node = NULL;
	xmlNode  *root_element = NULL;

	ERROR_if (doc == NULL);

	root_element = xmlDocGetRootElement (doc);
	for (node = root_element->children; node != NULL; node = node->next) {
		if (node->type == XML_ELEMENT_NODE) {
		
			Lit_Donnee_Xml_Signature (node, NULL);
		}
	}
}


gboolean Lit_Xml_Signature_Fichier (char *fname)
{
	xmlDocPtr doc = NULL;
	xmlNode  *root_element = NULL;

	ERROR_if (fname == NULL);
	Nb_Signature = 0;
	if (!g_file_test (fname, G_FILE_TEST_EXISTS)) {
#ifndef         __MAEMO
		gtk_widget_hide (win_Demarrage);
#else
		gtk_widget_hide (banner_maemo_Demarrage);
#endif
		create_window_Update ();
	
		gtk_widget_show (window_Update);
		gtk_main ();
	}

	doc = xmlParseFile (fname);
	if (!doc) {
		debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Error reading file : [%s]", fname);
		return FALSE;
	}
	root_element = xmlDocGetRootElement (doc);

	if (!root_element || !root_element->name || g_strcasecmp (root_element->name, "OS_FingerPrinting_AutoScan") != 0) {
		if (!root_element)
			debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "l'element n'est pas root");
		debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Fichier XML Signature mal formaté : [%s]", fname);
		xmlFreeDoc (doc);
		return FALSE;
	}

	Lit_Xml_Signature (doc);

	xmlFreeDoc (doc);
	return TRUE;
}


gint sort_func_Croissant (GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data)
{
	gchar    *name_a = NULL, *name_b = NULL;
	int       ret;

	gtk_tree_model_get (model, a, COL_NAME, &name_a, -1);
	gtk_tree_model_get (model, b, COL_NAME, &name_b, -1);
	ret = g_utf8_collate (name_a, name_b);
	MYFREE (name_a);
	MYFREE (name_b);
	return ret;
}



	
gboolean Selectionne_Signature (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
{
	struct Struct_Signature *Signature = NULL;
	GtkTreeModel *model = NULL;
	GtkTreePath *path = NULL;
	GtkTreeIter iter;
	gint      x, y;

	if (event->type == GDK_BUTTON_PRESS) {
		GdkEventButton *bev = (GdkEventButton *) event;

		model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
		gdk_window_get_pointer (event->window, &x, &y, NULL);
		if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, &path, NULL, NULL, NULL)) {
			return FALSE;
		}
		gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
		gtk_tree_model_get (model, &iter, POINTER, &Signature, -1);
		switch (bev->button) {
		    case 1:
			    Signature_Selectionner = Signature;
			    if (Signature->Nb_Fils == 0) {
				    Liste_Signatures_Modification_Interface = TRUE;
				    gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_System_name), Signature->System_Name);
				    gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_Md5), Signature->Md5_Signature);
				    gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_Liste_Signature_Open_Port), (gfloat) Signature->Open_Port);
				    gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton_Liste_Signature_Close_Port), (gfloat) Signature->Close_Port);
				    
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Type), Signature->Equipment_Type);
				    gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_FTP), Signature->Etat_FTP);
				    gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_HTTP), Signature->Etat_HTTP);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_HTTPS), Signature->Etat_HTTPS);
				    gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_IMAP), Signature->Etat_IMAP);
				    gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SMTP), Signature->Etat_SMTP);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SSH), Signature->Etat_SSH);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Telnet), Signature->Etat_TELNET);
				    
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_NAME), Signature->Etat_Snmp_Name);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_DEVICE),Signature->Etat_Snmp_Device);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_SNMP_DESCRIPTION), Signature->Etat_Snmp_Description);
					
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_GATEWAY), Signature->GateWay);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_ROUTAGE), Signature->Routage);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Snmp), Signature->Snmp);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Smb), Signature->Smb);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Sip), Signature->Sip);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_Printer), Signature->Printer);
					gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_Liste_Signature_JetDirect), Signature->JetDirect);
					
				
				
				
				
				
					gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton_Liste_Signature_Firewall), Signature->Firewall);
					
					
					Afficher_Info_Entree_Texte(entry_Liste_Signature_MAC, Signature->MAC);
					Afficher_Info_Entree_Texte(entry_Liste_Signature_UDP, Signature->UDP);					
				    Afficher_Info_Entree_Texte(entry_Liste_Signature_SNMP_NAME, Signature->Snmp_Name);	
				    Afficher_Info_Entree_Texte(entry_Liste_Signature_SNMP_DESCRIPTION, Signature->Snmp_Description);	
					Afficher_Info_Entree_Texte(entry_Liste_Signature_SNMP_DEVICE, Signature->Snmp_Device);	
					
					Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_FTP, Signature->Header_FTP);
				    Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_HTTP, Signature->Header_HTTP);
					Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_HTTPS, Signature->Header_HTTPS);
				    Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_IMAP, Signature->Header_IMAP);
 					Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_SMTP, Signature->Header_SMTP);
 					Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_SSH, Signature->Header_SSH);
				    Afficher_Info_Entree_Texte(entry_Liste_Signature_Header_TELNET, Signature->Header_TELNET);
				    
					Active_Combo_Correspondant (combobox_Liste_Signature, Signature->Icon);
				    Liste_Signatures_Modification_Interface = FALSE;
				    Liste_Signature_Sensible (TRUE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Ok, FALSE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Add, TRUE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Cancel, FALSE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Delete, TRUE);
			    }
			    else {
				    Liste_Signature_Sensible (FALSE);
				    Liste_Signature_Efface_Champs ();
				    Liste_Signatures_Modification_Interface = TRUE;
				    gtk_widget_set_sensitive (entry_Liste_Signature_System_name, TRUE);
				    gtk_entry_set_text (GTK_ENTRY (entry_Liste_Signature_System_name), Signature->System_Name);
				    Liste_Signatures_Modification_Interface = FALSE;
				    gtk_widget_set_sensitive (button_Liste_Signature_Ok, FALSE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Cancel, FALSE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Add, TRUE);
				    gtk_widget_set_sensitive (button_Liste_Signature_Delete, FALSE);
			    }
			    break;
		    default:
			    debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Pas d'actions pour cette combinaison  (%d)", bev->button);
		}
	}
	return FALSE;
}


void Create_Liste_Signature (void)
{
	GtkTreeModel *model = NULL;
	GtkTreeViewColumn *col = NULL;
	GtkCellRenderer *texte = NULL;
	GtkTreeSelection *selection = NULL;
	GtkTreeStore *store = NULL;

	store = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
	gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store), sort_func_Croissant, NULL, NULL);
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
	model = GTK_TREE_MODEL (store);

	treeview_Liste_Signature = gtk_tree_view_new_with_model (model);
	gtk_widget_show (treeview_Liste_Signature);
	g_object_unref (model);	
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview_Liste_Signature), TRUE);
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview_Liste_Signature), TRUE);
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_Liste_Signature));
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);


	col = gtk_tree_view_column_new ();
	gtk_tree_view_column_set_title (col, "System Name");
	texte = gtk_cell_renderer_text_new ();
	gtk_tree_view_column_pack_start (col, texte, FALSE);
	gtk_tree_view_column_set_attributes (col, texte, "text", COL_NAME, NULL);

	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview_Liste_Signature), col);

	col = gtk_tree_view_column_new ();
	gtk_tree_view_column_set_title (col, "Os FingerPrinting");
	texte = gtk_cell_renderer_text_new ();
	gtk_tree_view_column_pack_start (col, texte, FALSE);
	gtk_tree_view_column_set_attributes (col, texte, "text", COL_MD5, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview_Liste_Signature), col);

	gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview_Liste_Signature), COL_MD5);
	g_signal_connect ((gpointer) treeview_Liste_Signature, "button-press-event", G_CALLBACK (Selectionne_Signature), treeview_Liste_Signature);
}
