diff options
author | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2008-02-07 11:45:30 +0000 |
---|---|---|
committer | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2008-02-07 11:45:30 +0000 |
commit | 542913de9d73b6fd6ac348d66c5ff9e7b6dec419 (patch) | |
tree | 9b6e8af32d533ea314825489881d697a8c559ba0 /print.c | |
parent | 609bb570975ae71db1518e4d057718ffe1080227 (diff) |
When generating PDML, insert a fake protocol wrapper around top-level field items. This is to help preserve the PDML schema, and is discussed in bug 2226.
svn path=/trunk/; revision=24281
Diffstat (limited to 'print.c')
-rw-r--r-- | print.c | 36 |
1 files changed, 33 insertions, 3 deletions
@@ -262,10 +262,29 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data) int chop_len; int i; + /* Will wrap up top-level field items inside a fake protocol wrapper to + preserve the PDML schema */ + gboolean wrap_in_fake_protocol = + (((fi->hfinfo->type != FT_PROTOCOL) || + (fi->hfinfo->id == proto_data)) && + (pdata->level == 0)); + + /* Indent to the correct level */ for (i = -1; i < pdata->level; i++) { fputs(" ", pdata->fh); } + if (wrap_in_fake_protocol) { + /* Open fake protocol wrapper */ + fputs("<proto name=\"fake-field-wrapper\">\n", pdata->fh); + + /* Indent to increased level before writint out field */ + pdata->level++; + for (i = -1; i < pdata->level; i++) { + fputs(" ", pdata->fh); + } + } + /* Text label. It's printed as a field with no name. */ if (fi->hfinfo->id == hf_text_only) { /* Get the text */ @@ -294,16 +313,15 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data) fputs("\"/>\n", pdata->fh); } } + /* Uninterpreted data, i.e., the "Data" protocol, is * printed as a field instead of a protocol. */ else if (fi->hfinfo->id == proto_data) { + /* Write out field with data */ fputs("<field name=\"data\" value=\"", pdata->fh); - write_pdml_field_hex_value(pdata, fi); - fputs("\"/>\n", pdata->fh); - } /* Normal protocols and fields */ else { @@ -421,10 +439,17 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data) pdata->level--; } + /* Take back the extra level we added for fake wrapper protocol */ + if (wrap_in_fake_protocol) { + pdata->level--; + } + if (node->first_child != NULL) { + /* Indent to correct level */ for (i = -1; i < pdata->level; i++) { fputs(" ", pdata->fh); } + /* Close off current element */ if (fi->hfinfo->id != proto_data) { /* Data protocol uses simple tags */ if (fi->hfinfo->type == FT_PROTOCOL) { fputs("</proto>\n", pdata->fh); @@ -434,6 +459,11 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data) } } } + + /* Close off fake wrapper protocol */ + if (wrap_in_fake_protocol) { + fputs("</proto>\n", pdata->fh); + } } /* Print info for a 'geninfo' pseudo-protocol. This is required by |