/* ***********************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 "Sous_Reseau_Autorise.h"
#include "Debug.h"
#include "Macro.h"




gboolean Recherche_Si_Sous_Reseau_Autoriser (gchar * Sous_Reseau)
{
	struct struct_Liste_Sous_Reseau_Autorise *Reseau = NULL;
	gint      Nb_Objet_Liste, i;

	ERROR_if (Sous_Reseau == NULL);
	if ((Sous_Reseau[0] == 0) || (Sous_Reseau[0] == 127))
		return FALSE;
	Nb_Objet_Liste = g_list_length (GList_Sous_Reseau_Autorise);
	for (i = 0; i < Nb_Objet_Liste; i++) {
		Reseau = g_list_nth_data (GList_Sous_Reseau_Autorise, i);
		switch (Reseau->Masque) {
		    case 0:
			    if (Reseau->A == (unsigned char) Sous_Reseau[0])
				    return TRUE;
			    break;
		    case 1:
			    if ((Reseau->A == (unsigned char) Sous_Reseau[0]) && (Reseau->B == (unsigned char) Sous_Reseau[1]))
				    return TRUE;
			    break;
		    case 2:
			    if ((Reseau->A == (unsigned char) Sous_Reseau[0]) && (Reseau->B == (unsigned char) Sous_Reseau[1]) && (Reseau->C == (unsigned char) Sous_Reseau[2]))
				    return TRUE;
			    break;
		}
	}
	return FALSE;	
}

void Ajout_Sous_Reseau_Autorise (gpointer * Donnee)
{
	struct struct_Liste_Sous_Reseau_Autorise *Reseau = NULL, *Donnee_Reseau = (struct struct_Liste_Sous_Reseau_Autorise *) Donnee;

	ERROR_if (Donnee == NULL);
	
	MALLOC(Reseau,sizeof (struct struct_Liste_Sous_Reseau_Autorise));
	Reseau->Masque = Donnee_Reseau->Masque;
	Reseau->A = Donnee_Reseau->A;
	Reseau->B = Donnee_Reseau->B;
	Reseau->C = Donnee_Reseau->C;
	debug_printf (D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Ajout Reseau : Class (%d)   %d.%d.%d", Reseau->Masque, Reseau->A, Reseau->B, Reseau->C);
	G_LIST_APPEND (GList_Sous_Reseau_Autorise, Reseau);
}

void Initialisation_Liste_Sous_Reseau_Autorise (void)
{
	GList_Sous_Reseau_Autorise = NULL;
}
