2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
|
|
|
* Copyright (C) 2007 Cas Cremers
|
|
|
|
*
|
|
|
|
* 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, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2004-08-27 12:52:43 +01:00
|
|
|
/**
|
|
|
|
* Label info
|
|
|
|
*/
|
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
#include <stdlib.h>
|
2004-08-27 12:52:43 +01:00
|
|
|
#include "term.h"
|
|
|
|
#include "label.h"
|
2004-08-27 13:36:23 +01:00
|
|
|
#include "list.h"
|
|
|
|
#include "system.h"
|
2004-08-27 12:52:43 +01:00
|
|
|
|
2006-04-25 14:58:14 +01:00
|
|
|
//! Retrieve rightmost thing of label
|
|
|
|
Term
|
|
|
|
rightMostTerm (Term t)
|
|
|
|
{
|
|
|
|
if (t != NULL)
|
|
|
|
{
|
|
|
|
t = deVar (t);
|
|
|
|
if (realTermTuple (t))
|
|
|
|
{
|
|
|
|
return rightMostTerm (TermOp2 (t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Create a new labelinfo node
|
2004-11-16 12:07:55 +00:00
|
|
|
Labelinfo
|
|
|
|
label_create (const Term label, const Protocol protocol)
|
2004-08-27 12:52:43 +01:00
|
|
|
{
|
|
|
|
Labelinfo li;
|
2006-04-25 14:58:14 +01:00
|
|
|
Term tl;
|
2004-08-27 12:52:43 +01:00
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
li = (Labelinfo) malloc (sizeof (struct labelinfo));
|
2004-08-27 12:52:43 +01:00
|
|
|
li->label = label;
|
|
|
|
li->protocol = protocol;
|
|
|
|
li->sendrole = NULL;
|
|
|
|
li->readrole = NULL;
|
2006-04-25 14:58:14 +01:00
|
|
|
// Should we ignore it?
|
|
|
|
li->ignore = false;
|
|
|
|
tl = rightMostTerm (label);
|
|
|
|
if (tl != NULL)
|
|
|
|
{
|
|
|
|
if (TermSymb (tl)->text[0] == '!')
|
|
|
|
{
|
|
|
|
li->ignore = true;
|
|
|
|
}
|
|
|
|
}
|
2004-08-27 12:52:43 +01:00
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Destroy a labelinfo node
|
2004-11-16 12:07:55 +00:00
|
|
|
void
|
|
|
|
label_destroy (Labelinfo linfo)
|
2004-08-27 12:52:43 +01:00
|
|
|
{
|
2006-03-08 13:58:46 +00:00
|
|
|
free (linfo);
|
2004-08-27 12:52:43 +01:00
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Given a list of label infos, yield the correct one or NULL
|
2004-11-16 12:07:55 +00:00
|
|
|
Labelinfo
|
|
|
|
label_find (List labellist, const Term label)
|
2004-08-27 13:36:23 +01:00
|
|
|
{
|
|
|
|
Labelinfo linfo;
|
|
|
|
|
2004-08-30 21:08:11 +01:00
|
|
|
int label_find_scan (void *data)
|
2004-11-16 12:07:55 +00:00
|
|
|
{
|
|
|
|
Labelinfo linfo_scan;
|
|
|
|
|
|
|
|
linfo_scan = (Labelinfo) data;
|
|
|
|
if (isTermEqual (label, linfo_scan->label))
|
|
|
|
{
|
|
|
|
linfo = linfo_scan;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
|
|
|
|
linfo = NULL;
|
2004-08-30 21:08:11 +01:00
|
|
|
if (label != NULL)
|
|
|
|
{
|
|
|
|
list_iterate (labellist, label_find_scan);
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
return linfo;
|
|
|
|
}
|