- Added XML term output to Scyther. This meant in fact that a lot had to
be recoded, avoiding e.g. label="<term ..." constructs. Therefore, many attributes have changes into elements. Beware. - Made bindings implicit to events using <follows> and <after> constructs. Also added a new <choose> for unbound simple variables.
This commit is contained in:
parent
52e38f40e6
commit
d02621c608
266
src/xmlout.c
266
src/xmlout.c
@ -20,6 +20,12 @@
|
|||||||
|
|
||||||
#include "xmlout.h"
|
#include "xmlout.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Externally defined
|
||||||
|
*/
|
||||||
|
extern Protocol INTRUDER; // from arachne.c
|
||||||
|
extern Term TERM_Function; // from termlist.c
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global/static stuff.
|
* Global/static stuff.
|
||||||
*/
|
*/
|
||||||
@ -86,6 +92,90 @@ xmlOutInteger (const char *tag, const int value)
|
|||||||
xmlPrint ("<%s>%i</%s>", tag, value, tag);
|
xmlPrint ("<%s>%i</%s>", tag, value, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Print a term in XML form (iteration inner)
|
||||||
|
void
|
||||||
|
xmlTermPrintInner (const Term term)
|
||||||
|
{
|
||||||
|
if (term != NULL)
|
||||||
|
{
|
||||||
|
if (realTermLeaf(term))
|
||||||
|
{
|
||||||
|
// Variable?
|
||||||
|
if (realTermVariable (term))
|
||||||
|
{
|
||||||
|
Term substbuffer;
|
||||||
|
|
||||||
|
printf ("<var name=\"");
|
||||||
|
if (term->subst == NULL)
|
||||||
|
{
|
||||||
|
// Free variable
|
||||||
|
termPrint (term); // Must be a normal termPrint
|
||||||
|
printf ("\" free=\"true\" />");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Bound variable
|
||||||
|
substbuffer = term->subst; // Temporarily unsubst for printing
|
||||||
|
term->subst = NULL;
|
||||||
|
termPrint (term); // Must be a normal termPrint
|
||||||
|
term->subst = substbuffer;
|
||||||
|
printf ("\">");
|
||||||
|
xmlTermPrintInner (term->subst);
|
||||||
|
printf ("</var>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Constant
|
||||||
|
termPrint (term); // Must be a normal termPrint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Node
|
||||||
|
if (realTermEncrypt(term))
|
||||||
|
{
|
||||||
|
if (isTermLeaf (TermKey (term))
|
||||||
|
&& inTermlist (TermKey (term)->stype, TERM_Function))
|
||||||
|
{
|
||||||
|
/* function application */
|
||||||
|
printf ("<apply><function>");
|
||||||
|
xmlTermPrintInner (TermKey (term));
|
||||||
|
printf ("</function><arg>");
|
||||||
|
xmlTermPrintInner (TermOp (term));
|
||||||
|
printf ("</arg></apply>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("<encrypt><op>");
|
||||||
|
xmlTermPrintInner (TermOp(term));
|
||||||
|
printf ("</op><key>");
|
||||||
|
xmlTermPrintInner (TermKey(term));
|
||||||
|
printf ("</key></encrypt>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Assume tuple
|
||||||
|
printf ("<tuple><op1>");
|
||||||
|
xmlTermPrintInner (TermOp1(term));
|
||||||
|
printf ("</op1><op2>");
|
||||||
|
xmlTermPrintInner (TermOp2(term));
|
||||||
|
printf ("</op2></tuple>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Print a term in XML form (wrapper)
|
||||||
|
void
|
||||||
|
xmlTermPrint (const Term term)
|
||||||
|
{
|
||||||
|
printf ("<term>");
|
||||||
|
xmlTermPrintInner (term);
|
||||||
|
printf ("</term>");
|
||||||
|
}
|
||||||
|
|
||||||
//! Print a term for an element
|
//! Print a term for an element
|
||||||
void
|
void
|
||||||
xmlOutTerm (const char *tag, const Term term)
|
xmlOutTerm (const char *tag, const Term term)
|
||||||
@ -94,7 +184,7 @@ xmlOutTerm (const char *tag, const Term term)
|
|||||||
{
|
{
|
||||||
xmlIndentPrint ();
|
xmlIndentPrint ();
|
||||||
printf ("<%s>", tag);
|
printf ("<%s>", tag);
|
||||||
termPrint (term);
|
xmlTermPrint (term);
|
||||||
printf ("</%s>\n", tag);
|
printf ("</%s>\n", tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +196,7 @@ xmlAttrTerm (const char *tag, const Term term)
|
|||||||
if (term != NULL)
|
if (term != NULL)
|
||||||
{
|
{
|
||||||
printf (" %s=\"", tag);
|
printf (" %s=\"", tag);
|
||||||
termPrint (term);
|
xmlTermPrint (term);
|
||||||
printf ("\"");
|
printf ("\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +215,7 @@ roleTermPrint (const Term t)
|
|||||||
|
|
||||||
typebuffer = t->type;
|
typebuffer = t->type;
|
||||||
t->type = GLOBAL;
|
t->type = GLOBAL;
|
||||||
termPrint (t);
|
xmlTermPrint (t);
|
||||||
t->type = typebuffer;
|
t->type = typebuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,14 +259,10 @@ xmlAgentsOfRunPrint (const System sys, const int run)
|
|||||||
roles = sys->runs[run].protocol->rolenames;
|
roles = sys->runs[run].protocol->rolenames;
|
||||||
while (roles != NULL)
|
while (roles != NULL)
|
||||||
{
|
{
|
||||||
xmlIndentPrint ();
|
xmlPrint ("<role>");
|
||||||
printf ("<");
|
xmlOutTerm ("name", roles->term);
|
||||||
roleTermPrint (roles->term);
|
xmlOutTerm ("agent",deVar(agentOfRunRole (sys, run, roles->term)));
|
||||||
printf (">");
|
xmlPrint ("</role>");
|
||||||
termPrint (agentOfRunRole (sys, run, roles->term));
|
|
||||||
printf ("</");
|
|
||||||
roleTermPrint (roles->term);
|
|
||||||
printf (">\n");
|
|
||||||
roles = roles->next;
|
roles = roles->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +278,15 @@ xmlRunInfo (const System sys, const int run)
|
|||||||
Term oldagent;
|
Term oldagent;
|
||||||
|
|
||||||
xmlOutInteger ("runid", run);
|
xmlOutInteger ("runid", run);
|
||||||
xmlOutTerm ("protocol", sys->runs[run].protocol->nameterm);
|
xmlIndentPrint ();
|
||||||
|
printf ("<protocol");
|
||||||
|
if (sys->runs[run].protocol == INTRUDER)
|
||||||
|
{
|
||||||
|
printf (" intruder=\"true\"");
|
||||||
|
}
|
||||||
|
printf (">");
|
||||||
|
xmlTermPrint (sys->runs[run].protocol->nameterm);
|
||||||
|
printf ("</protocol>\n");
|
||||||
r = sys->runs[run].role;
|
r = sys->runs[run].role;
|
||||||
|
|
||||||
/* undo substitution temporarily to retrieve role name */
|
/* undo substitution temporarily to retrieve role name */
|
||||||
@ -216,13 +310,15 @@ xmlRunInfo (const System sys, const int run)
|
|||||||
//! Show a single event from a run
|
//! Show a single event from a run
|
||||||
/**
|
/**
|
||||||
* run and index will only be output if they are nonnegative.
|
* run and index will only be output if they are nonnegative.
|
||||||
|
* Also prints any bindings, if this events follows some other events
|
||||||
|
* (typically when this is a read).
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xmlOutEvent (const System sys, Roledef rd, const int run, const int index)
|
xmlOutEvent (const System sys, Roledef rd, const int run, const int index)
|
||||||
{
|
{
|
||||||
xmlIndentPrint ();
|
xmlIndentPrint ();
|
||||||
|
|
||||||
printf ("<");
|
printf ("<event type=\"");
|
||||||
switch (rd->type)
|
switch (rd->type)
|
||||||
{
|
{
|
||||||
/* Read or send types are fairly similar.
|
/* Read or send types are fairly similar.
|
||||||
@ -242,31 +338,89 @@ xmlOutEvent (const System sys, Roledef rd, const int run, const int index)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlAttrTerm ("label", rd->label);
|
printf ("\"");
|
||||||
|
printf (" index=\"%i\"", index);
|
||||||
|
printf (">\n");
|
||||||
|
xmlindent++;
|
||||||
|
xmlOutTerm ("label", rd->label);
|
||||||
if (rd->type != CLAIM)
|
if (rd->type != CLAIM)
|
||||||
{
|
{
|
||||||
/* read or send */
|
/* read or send */
|
||||||
xmlAttrTerm ("from", rd->from);
|
xmlOutTerm ("from", rd->from);
|
||||||
xmlAttrTerm ("to", rd->to);
|
xmlOutTerm ("to", rd->to);
|
||||||
xmlAttrTerm ("message", rd->message);
|
xmlOutTerm ("message", rd->message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* claim */
|
/* claim */
|
||||||
xmlAttrTerm ("role", rd->from);
|
xmlOutTerm ("role", rd->from);
|
||||||
xmlAttrTerm ("type", rd->to);
|
xmlOutTerm ("type", rd->to);
|
||||||
xmlAttrTerm ("argument", rd->message);
|
xmlOutTerm ("argument", rd->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (run >= 0)
|
|
||||||
|
// Display any incoming bindings
|
||||||
{
|
{
|
||||||
printf (" run=\"%i\"", run);
|
int incomingArrows;
|
||||||
}
|
|
||||||
if (index >= 0)
|
int xmlBindingState (void *dt)
|
||||||
{
|
{
|
||||||
printf (" index=\"%i\"", index);
|
Binding b;
|
||||||
|
|
||||||
|
void xmlRunIndex (char *desc, const int run, const int index)
|
||||||
|
{
|
||||||
|
xmlPrint ("<%s run=\"%i\" index=\"%i\" />", desc, run, index);
|
||||||
}
|
}
|
||||||
printf (" />\n");
|
|
||||||
|
b = (Binding) dt;
|
||||||
|
if (b->run_to == run && b->ev_to == index)
|
||||||
|
{
|
||||||
|
if (isTermVariable (b->term) && ! b->done)
|
||||||
|
{
|
||||||
|
// Generate from m0
|
||||||
|
xmlPrint ("<choose>");
|
||||||
|
|
||||||
|
xmlindent++;
|
||||||
|
xmlIndentPrint ();
|
||||||
|
xmlTermPrint (b->term);
|
||||||
|
printf ("\n");
|
||||||
|
xmlindent--;
|
||||||
|
|
||||||
|
xmlPrint ("</choose>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Normal binding
|
||||||
|
xmlPrint ("<follows>");
|
||||||
|
|
||||||
|
xmlindent++;
|
||||||
|
if (b->done)
|
||||||
|
xmlRunIndex ("after", b->run_from, b->ev_from);
|
||||||
|
else
|
||||||
|
xmlPrint ("<unbound />");
|
||||||
|
if (b->blocked)
|
||||||
|
printf ("<blocked />");
|
||||||
|
xmlIndentPrint ();
|
||||||
|
xmlTermPrint (b->term);
|
||||||
|
printf ("\n");
|
||||||
|
xmlindent--;
|
||||||
|
|
||||||
|
xmlPrint ("</follows>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlindent++;
|
||||||
|
if (sys->bindings != NULL)
|
||||||
|
{
|
||||||
|
list_iterate (sys->bindings, xmlBindingState);
|
||||||
|
}
|
||||||
|
xmlindent--;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlindent--;
|
||||||
|
xmlPrint ("</event>");
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Display runs
|
//! Display runs
|
||||||
@ -292,7 +446,7 @@ xmlOutRuns (const System sys)
|
|||||||
rd = sys->runs[run].start;
|
rd = sys->runs[run].start;
|
||||||
while (rd != NULL && index < sys->runs[run].step)
|
while (rd != NULL && index < sys->runs[run].step)
|
||||||
{
|
{
|
||||||
xmlOutEvent (sys, rd, -1, index);
|
xmlOutEvent (sys, rd, run, index);
|
||||||
index++;
|
index++;
|
||||||
rd = rd->next;
|
rd = rd->next;
|
||||||
}
|
}
|
||||||
@ -305,46 +459,6 @@ xmlOutRuns (const System sys)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Output list of bindings
|
|
||||||
void
|
|
||||||
xmlOutBindings (const System sys)
|
|
||||||
{
|
|
||||||
int xmlBindingState (void *dt)
|
|
||||||
{
|
|
||||||
Binding b;
|
|
||||||
void xmlRunIndex (char *desc, const int run, const int index)
|
|
||||||
{
|
|
||||||
xmlPrint ("<%s run=\"%i\" index=\"%i\" />", desc, run, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
b = (Binding) dt;
|
|
||||||
xmlIndentPrint ();
|
|
||||||
printf ("<binding term=\"");
|
|
||||||
termPrint (b->term);
|
|
||||||
printf ("\" >\n");
|
|
||||||
xmlindent++;
|
|
||||||
if (b->done)
|
|
||||||
xmlRunIndex ("from", b->run_from, b->ev_from);
|
|
||||||
else
|
|
||||||
xmlPrint ("<unbound />");
|
|
||||||
xmlRunIndex ("to", b->run_to, b->ev_to);
|
|
||||||
if (b->blocked)
|
|
||||||
printf ("<blocked />");
|
|
||||||
xmlindent--;
|
|
||||||
xmlPrint ("</binding>");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlPrint ("<bindinglist>");
|
|
||||||
xmlindent++;
|
|
||||||
if (sys->bindings != NULL)
|
|
||||||
{
|
|
||||||
list_iterate (sys->bindings, xmlBindingState);
|
|
||||||
}
|
|
||||||
xmlindent--;
|
|
||||||
xmlPrint ("</bindinglist>");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -----------------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------------
|
||||||
* Publicly available functions
|
* Publicly available functions
|
||||||
@ -366,23 +480,27 @@ xmlOutSemitrace (const System sys)
|
|||||||
{
|
{
|
||||||
xmlIndentPrint ();
|
xmlIndentPrint ();
|
||||||
printf ("<attack");
|
printf ("<attack");
|
||||||
/* mention the broken claim in the attributes */
|
|
||||||
if (sys->current_claim != NULL)
|
|
||||||
{
|
|
||||||
xmlAttrTerm ("claim", sys->current_claim->type);
|
|
||||||
xmlAttrTerm ("label", sys->current_claim->label);
|
|
||||||
}
|
|
||||||
/* add trace length attribute */
|
/* add trace length attribute */
|
||||||
printf (" tracelength=\"%i\"", get_semitrace_length ());
|
printf (" tracelength=\"%i\"", get_semitrace_length ());
|
||||||
printf (">\n");
|
printf (">\n");
|
||||||
xmlindent++;
|
xmlindent++;
|
||||||
|
|
||||||
|
/* mention the broken claim */
|
||||||
|
if (sys->current_claim != NULL)
|
||||||
|
{
|
||||||
|
xmlPrint ("<broken>");
|
||||||
|
xmlindent++;
|
||||||
|
xmlOutTerm ("claim", sys->current_claim->type);
|
||||||
|
xmlOutTerm ("label", sys->current_claim->label);
|
||||||
|
xmlindent--;
|
||||||
|
xmlPrint ("</broken>");
|
||||||
|
}
|
||||||
/* any global information about the system */
|
/* any global information about the system */
|
||||||
xmlOutSysInfo (sys);
|
xmlOutSysInfo (sys);
|
||||||
/* semitrace */
|
/* semitrace */
|
||||||
xmlPrint ("<semitrace>");
|
xmlPrint ("<semitrace>");
|
||||||
xmlindent++;
|
xmlindent++;
|
||||||
xmlOutRuns (sys);
|
xmlOutRuns (sys);
|
||||||
xmlOutBindings (sys);
|
|
||||||
xmlindent--;
|
xmlindent--;
|
||||||
xmlPrint ("</semitrace>");
|
xmlPrint ("</semitrace>");
|
||||||
xmlindent--;
|
xmlindent--;
|
||||||
|
Loading…
Reference in New Issue
Block a user