To make output more useful fields from the protocol should have additional information like description, name, type and so on. List of attributes added: - ws_desc, just a simple description; - ws allow to specify a description and a name. Useful as easier to type instead of using two attributes; - ws_type allows to override type detected, for instance to specify is a boolean instead of an int; - ws_base like ws_type but for base (hexadecimal instead of decimal) These bases are the based defined in epan/proto.h, currently: NONE, DEC, HEX, OCT, DEC_HEX and HEX_DEC; - ws_txt and ws_txt_n allows to specify formatting. The difference between formatting and description is that description is static while these new attributes contain a formatting string as first argument followed by arguments representing fields or the special value "INDEX" for the index if we are dumping a structure contained in an array. The distinction between ws_txt and ws_txt_n is whether the item is contained in an array or not; - ws_inline, this is tricky attribute. It allows to embed structure dissecting in the same function. This allows format string and other fields (for instance switch or array sizes) to be seen by the function currently being generated; - ws_as, dissect this structure as another type. Useful to avoid changing the protocol but show a slightly modified version. This is used for instance to show two fields like x and y as a single point. Could also be used to dump a binary data with more detail but avoid to change marshalling/demarshalling. This is also used to dump binary data in wireshark with more details without changing the current marshalling/demarshalling code (eg agent messages or QUIC image data). These attributes required some changes in the parser as previously arguments could be only integers and identifiers while they require string and multiple identifiers (like "this.that"). In wireshark names are important as they can be used to do queries about packet with specific features. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- python_modules/ptypes.py | 27 +++++++++++++++++++++++++-- python_modules/spice_parser.py | 13 +++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py index c1eb756..7216b17 100644 --- a/python_modules/ptypes.py +++ b/python_modules/ptypes.py @@ -108,6 +108,24 @@ valid_attributes=set([ # for a switch this indicates that on network # it will occupy always the same size (maximum size required for all members) 'fixedsize', + + # description + 'ws_desc', + # combine description + name + # name will be used for filtering + 'ws', + # type (BOOLEAN, STRINGZ) + 'ws_type', + # force wireshark base + 'ws_base', + # text to use for format, you can specify parameters + 'ws_txt', + 'ws_txt_n', + # put structure not in a separate function + # used to be able to retrieve fields from parent + 'ws_inline', + # handle this container as another type + 'ws_as', ]) attributes_with_arguments=set([ @@ -119,6 +137,13 @@ attributes_with_arguments=set([ 'minor', 'bytes_count', 'virtual', + 'ws', + 'ws_desc', + 'ws_type', + 'ws_base', + 'ws_txt', + 'ws_txt_n', + 'ws_as', ]) def fix_attributes(attribute_list): @@ -131,8 +156,6 @@ def fix_attributes(attribute_list): if not name in attributes_with_arguments: if len(lst) > 0: raise Exception("Attribute %s specified with options" % name) - elif len(lst) > 1: - raise Exception("Attribute %s has more than 1 argument" % name) attrs[name] = lst return attrs diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py index 97af8b2..a0f969a 100644 --- a/python_modules/spice_parser.py +++ b/python_modules/spice_parser.py @@ -3,7 +3,7 @@ import six try: from pyparsing import Literal, CaselessLiteral, Word, OneOrMore, ZeroOrMore, \ Forward, delimitedList, Group, Optional, Combine, alphas, nums, restOfLine, cStyleComment, \ - alphanums, ParseException, ParseResults, Keyword, StringEnd, replaceWith + alphanums, ParseException, ParseResults, Keyword, StringEnd, replaceWith, QuotedString except ImportError: six.print_("Module pyparsing not found.") exit(1) @@ -77,20 +77,29 @@ def SPICE_BNF(): switch_ = Keyword("switch") default_ = Keyword("default") case_ = Keyword("case") + ws_ = Keyword("@ws") + ws_txt_ = Keyword("@ws_txt") | Keyword("@ws_txt_n") + ws_desc_ = Keyword("@ws_desc") identifier = Word( alphas, alphanums + "_" ) + multi_identifier = Word( alphas, alphanums + "_." ) enumname = Word( alphanums + "_" ) integer = ( Combine( CaselessLiteral("0x") + Word( nums+"abcdefABCDEF" ) ) | Word( nums+"+-", nums ) ).setName("int").setParseAction(cvtInt) + string = QuotedString(quoteChar='"', escChar='\\') + typename = identifier.copy().setParseAction(lambda toks : ptypes.TypeRef(str(toks[0]))) # This is just normal "types", i.e. not channels or messages typeSpec = Forward() attributeValue = integer ^ identifier - attribute = Group(Combine ("@" + identifier) + Optional(lparen + delimitedList(attributeValue) + rparen)) + ws = ws_ + lparen + string + comma + multi_identifier + rparen + ws_desc = ws_desc_ + lparen + string + rparen + ws_txt = ws_txt_ + lparen + string + ZeroOrMore(comma + multi_identifier) + rparen + attribute = Group(ws | ws_desc | ws_txt | (Combine ("@" + identifier) + Optional(lparen + delimitedList(attributeValue) + rparen))) attributes = Group(ZeroOrMore(attribute)) arraySizeSpecImage = Group(image_size_ + lparen + integer + comma + identifier + comma + identifier + rparen) arraySizeSpecBytes = Group(bytes_ + lparen + identifier + comma + identifier + rparen) -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel