[Spice-devel] [PATCH 11/33] Generate some definition for dissector
Frediano Ziglio
fziglio at redhat.com
Wed Jul 1 10:10:03 PDT 2015
Generate global definitions.
Generate function to registers various dissector components.
For the moment the field array is empty bu we save some global to
be able to register new ones.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
python_modules/dissector.py | 69 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 90ba498..d9d8a87 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -1,8 +1,75 @@
from . import codegen
+hf_writer = None
+hf_defs = None
+
+
+def write_parser_helpers(writer):
+ if writer.is_generated("helper", "demarshaller"):
+ return
+
+ writer.set_is_generated("helper", "demarshaller")
+
+ writer = writer.function_helper()
+
+ writer.begin_block("typedef struct GlobalInfo")
+ writer.variable_def("tvbuff_t *", "tvb")
+ writer.variable_def("packet_info *", "pinfo")
+ writer.variable_def("proto_item *", "msgtype_item")
+ writer.variable_def("guint32", "message_offset")
+ writer.variable_def("guint32", "message_end")
+ writer.end_block(newline=False)
+ writer.writeln(' GlobalInfo;')
+
+ writer.newline()
+ writer.statement('static expert_field ei_spice_unknown_message = EI_INIT')
+
+ writer.newline()
+ writer.statement('typedef guint32 (*parse_msg_func_t)(GlobalInfo *glb, proto_tree *tree, guint32 offset)')
+ writer.statement('typedef guint32 (*spice_dissect_func_t)(guint16 message_type, GlobalInfo *glb, proto_tree *tree, guint32 offset)')
+
+ writer.newline()
+ writer.writeln('#ifndef _U_')
+ writer.writeln('#define _U_')
+ writer.writeln('#endif')
+ writer.newline()
+
+
+def write_protocol_definitions(writer):
+ global hf_defs
+
+ writer.newline()
+ writer.function('spice_register_fields', 'void', 'int proto, expert_module_t* expert_proto')
+
+ writer.write("static hf_register_info hf[] = ")
+ writer.begin_block()
+ hf_defs = writer.get_subwriter()
+ hf_defs.fields = {}
+ writer.end_block(semicolon = True)
+ writer.newline()
+
+ writer.write('static ei_register_info ei[] =')
+ writer.begin_block()
+ writer.writeln('{ &ei_spice_unknown_message, { "spice.unknown_message", PI_UNDECODED, PI_WARN, "Unknown message - cannot dissect", EXPFILL }},')
+ writer.end_block(semicolon = True)
+ writer.newline()
+
+ writer.statement('proto_register_field_array(proto, hf, array_length(hf))')
+ writer.statement('expert_register_field_array(expert_proto, ei, array_length(ei))')
+ writer.end_block()
+
+
def write_protocol_parser(writer, proto):
- pass
+ global hf_writer
+
+ write_parser_helpers(writer)
+
+ # put fields declaration first
+ hf_writer = writer.get_subwriter()
+
+ # put fields definition at last
+ write_protocol_definitions(writer)
def write_includes(writer):
writer.newline()
--
2.1.0
More information about the Spice-devel
mailing list