3 # wireshark_gen.py (part of idl2wrs)
5 # Author : Frank Singleton (frank.singleton@ericsson.com)
7 # Copyright (C) 2001 Frank Singleton, Ericsson Inc.
9 # This file is a backend to "omniidl", used to generate "Wireshark"
10 # dissectors from CORBA IDL descriptions. The output language generated
11 # is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
13 # Please see packet-giop.h in Wireshark distro for API description.
14 # Wireshark is available at https://www.wireshark.org/
16 # Omniidl is part of the OmniOrb distribution, and is available at
17 # http://omniorb.sourceforge.net
19 # SPDX-License-Identifier: GPL-2.0-or-later
24 # Omniidl Back-end which parses an IDL list of "Operation" nodes
25 # passed from wireshark_be2.py and generates "C" code for compiling
26 # as a dissector for Wireshark.
29 # Strategy (sneaky but ...)
31 # problem: I don't know what variables to declare until AFTER the helper functions
32 # have been built, so ...
34 # There are 2 passes through genHelpers, the first one is there just to
35 # make sure the fn_hash data struct is populated properly.
36 # The second pass is the real thing, generating code and declaring
37 # variables (from the 1st pass) properly.
40 """Wireshark IDL compiler back-end."""
42 from __future__
import print_function
49 from omniidl
import idlast
, idltype
, idlutil
, output
52 # Output class, generates "C" src code for the sub-dissector
59 # node - a reference to an Operations object.
60 # name - scoped name (Module::Module::Interface:: .. ::Operation
66 # 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved]
67 # 2. add item instead of add_text() [done]
68 # 3. sequence handling [done]
69 # 4. User Exceptions [done]
70 # 5. Fix arrays, and structs containing arrays [done]
72 # 7. Exception can be common to many operations, so handle them outside the
73 # operation helper functions [done]
74 # 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
75 # For example, mutlidimensional arrays.
76 # 9. wchar and wstring handling [giop API needs improving]
77 # 10. Support Fixed [done]
78 # 11. Support attributes (get/set) [started, needs language mapping option, perhaps wireshark GUI option
79 # to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
80 # eg: attribute string apple => _get_apple and _set_apple
82 # 12. Implement IDL "union" code [done]
83 # 13. Implement support for plugins [done]
84 # 14. Don't generate code for empty operations (cf: exceptions without members)
85 # 15. Generate code to display Enums numerically and symbolically [done]
86 # 16. Place structs/unions in subtrees [done]
87 # 17. Recursive struct and union handling [done]
88 # 18. Improve variable naming for display (eg: structs, unions etc) [done]
90 # Also test, Test, TEST
94 # For every operation and attribute do
95 # For return val and all parameters do
96 # find basic IDL type for each parameter
98 # output exception handling code
99 # output attribute handling code
102 class wireshark_gen_C
:
104 # Some string constants for our templates
105 c_u_octet8
= "uint64_t u_octet8;"
106 c_s_octet8
= "int64_t s_octet8;"
107 c_u_octet4
= "uint32_t u_octet4;"
108 c_s_octet4
= "int32_t s_octet4;"
109 c_u_octet2
= "uint16_t u_octet2;"
110 c_s_octet2
= "int16_t s_octet2;"
111 c_u_octet1
= "uint8_t u_octet1;"
112 c_s_octet1
= "int8_t s_octet1;"
114 c_float
= "float my_float;"
115 c_double
= "double my_double;"
117 c_seq
= "const char *seq = NULL;" # pointer to buffer of chars
118 c_i
= "uint32_t i_" # loop index
119 c_i_lim
= "uint32_t u_octet4_loop_" # loop limit
120 c_u_disc
= "uint32_t disc_u_" # unsigned int union discriminant variable name (enum)
121 c_s_disc
= "int32_t disc_s_" # signed int union discriminant variable name (other cases, except Enum)
123 def __init__(self
, st
, protocol_name
, dissector_name
, description
, debug
=False, aggressive
=False):
125 self
.AGGRESSIVE
= aggressive
127 self
.st
= output
.Stream(tempfile
.TemporaryFile(mode
="w"), 4) # for first pass only
129 self
.st_save
= st
# where 2nd pass should go
130 self
.protoname
= protocol_name
# Protocol Name (eg: ECHO)
131 self
.dissname
= dissector_name
# Dissector name (eg: echo)
132 self
.description
= description
# Detailed Protocol description (eg: Echo IDL Example)
133 self
.exlist
= [] # list of exceptions used in operations.
134 #self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
135 self
.fn_hash
= {} # top level hash to contain key = function/exception and val = list of variable declarations
137 self
.fn_hash_built
= 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
138 # populated with operations/vars and exceptions/vars
140 def genCode(self
, oplist
, atlist
, enlist
, stlist
, unlist
): # operation, attribute, enums, struct and union lists
141 """Main entry point, controls sequence of generated code."""
143 # sneaky .. call it now, to populate the fn_hash
144 # so when I come to that exception later, I have the variables to
147 # need to reverse the lists, so that the functions of the current IDL
148 # is properly processed, otherwise the first name wise declaration of
149 # an include is taken for the function generation. Same counts for
150 # structs and unions.
151 oplist
= oplist
[::-1]
152 stlist
= stlist
[::-1]
153 enlist
= enlist
[::-1]
154 unlist
= unlist
[::-1]
157 self
.genHelpers(oplist
, stlist
, unlist
)
158 self
.genExceptionHelpers(oplist
)
159 self
.genAttributeHelpers(atlist
)
161 self
.fn_hash_built
= 1 # DONE, so now I know , see genOperation()
163 self
.st
= self
.st_save
164 self
.genHeader() # initial dissector comments
165 self
.genWrsCopyright()
170 self
.genDeclares(oplist
, atlist
, enlist
, stlist
, unlist
)
172 self
.genAtList(atlist
) # string constant declares for Attributes
174 self
.genEnList(enlist
) # string constant declares for Enums
176 self
.genUnList(unlist
)
178 self
.genExceptionHelpers(oplist
) # helper function to decode user exceptions that have members
179 self
.genExceptionDelegator(oplist
) # finds the helper function to decode a user exception
181 self
.genAttributeHelpers(atlist
) # helper function to decode "attributes"
183 self
.genHelpers(oplist
, stlist
, unlist
) # operation, struct and union decode helper functions
185 self
.genMainEntryStart(oplist
)
186 self
.genOpDelegator(oplist
)
187 self
.genAtDelegator(atlist
)
188 self
.genMainEntryEnd()
190 self
.gen_proto_register(oplist
, atlist
, stlist
, unlist
)
191 self
.gen_proto_reg_handoff(oplist
)
192 # All the dissectors are now built-in
193 #self.gen_plugin_register()
195 self
.dumpvars() # debug
199 """Generate Standard Wireshark Header Comments"""
200 self
.st
.out(self
.template_Header
, dissector_name
=self
.dissname
)
202 print("//XXX genHeader")
204 def genWrsCopyright(self
):
206 print("//XXX genWrsCopyright")
207 self
.st
.out(self
.template_wireshark_copyright
)
209 def genModelines(self
):
211 print("//XXX genModelines")
213 self
.st
.out(self
.template_Modelines
)
217 print("//XXX genGPL")
219 self
.st
.out(self
.template_GPL
)
221 def genIncludes(self
):
223 print("//XXX genIncludes")
225 self
.st
.out(self
.template_Includes
)
227 def genOpDeclares(self
, op
):
228 """" Generate hf variables for operation filters
230 in: opnode ( an operation node)
234 print("//XXX genOpDeclares")
235 print("//XXX return type = ", op
.returnType().kind())
237 sname
= self
.namespace(op
, "_")
240 if rt
.kind() != idltype
.tk_void
:
241 if rt
.kind() == idltype
.tk_alias
: # a typedef return val possibly ?
242 #self.get_CDR_alias(rt, rt.name())
243 if rt
.unalias().kind() == idltype
.tk_sequence
:
244 self
.st
.out(self
.template_hf
, name
=sname
+ "_return_loop")
245 if self
.isSeqNativeType(rt
.unalias().seqType()) or self
.AGGRESSIVE
:
246 self
.st
.out(self
.template_hf
, name
=sname
+ "_return")
247 elif (rt
.unalias().kind() != idltype
.tk_struct
and
248 rt
.unalias().kind() != idltype
.tk_objref
and
249 rt
.unalias().kind() != idltype
.tk_any
):
250 self
.st
.out(self
.template_hf
, name
=sname
+ "_return")
252 elif (rt
.kind() != idltype
.tk_struct
and
253 rt
.kind() != idltype
.tk_objref
and
254 rt
.kind() != idltype
.tk_union
and
255 rt
.kind() != idltype
.tk_any
):
256 self
.st
.out(self
.template_hf
, name
=sname
+ "_return")
258 for p
in op
.parameters():
259 if p
.paramType().unalias().kind() == idltype
.tk_sequence
:
260 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + p
.identifier() + "_loop")
261 if (self
.isSeqNativeType(p
.paramType().unalias().seqType())) or self
.AGGRESSIVE
:
262 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + p
.identifier())
263 elif (p
.paramType().unalias().kind() != idltype
.tk_any
and
264 p
.paramType().unalias().kind() != idltype
.tk_struct
and
265 p
.paramType().unalias().kind() != idltype
.tk_objref
and
266 p
.paramType().unalias().kind() != idltype
.tk_union
):
267 if p
.paramType().unalias().kind() == idltype
.tk_wchar
:
268 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + p
.identifier() + "_len")
269 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + p
.identifier())
271 def genAtDeclares(self
, at
):
272 """Generate hf variables for attributes
274 in: at ( an attribute)
278 print("//XXX genAtDeclares")
280 for decl
in at
.declarators():
281 sname
= self
.namespace(decl
, "_")
283 self
.st
.out(self
.template_hf
, name
="get" + "_" + sname
+ "_" + decl
.identifier())
285 self
.st
.out(self
.template_hf
, name
="get" + "_" + sname
+ "_" + decl
.identifier()+"_loop")
286 if not at
.readonly():
287 self
.st
.out(self
.template_hf
, name
="set" + "_" + sname
+ "_" + decl
.identifier())
289 self
.st
.out(self
.template_hf
, name
="set" + "_" + sname
+ "_" + decl
.identifier()+"_loop")
291 def genStDeclares(self
, st
):
292 """Generate hf variables for structs
298 print("//XXX genStDeclares")
300 sname
= self
.namespace(st
, "_")
302 for m
in st
.members():
303 if (self
.isSeqNativeType(m
.memberType())
304 or m
.memberType().unalias().kind() == idltype
.tk_sequence
305 or m
.memberType().unalias().kind() == idltype
.tk_alias
):
306 for decl
in m
.declarators():
307 if m
.memberType().unalias().kind() == idltype
.tk_sequence
:
308 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier() + "_loop")
309 if (self
.isSeqNativeType(m
.memberType().unalias().seqType())) or self
.AGGRESSIVE
:
310 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier())
312 if m
.memberType().unalias().kind() == idltype
.tk_wchar
:
313 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier() + "_len")
314 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier())
316 def genExDeclares(self
, ex
):
317 """Generate hf variables for user exception filters
319 in: exnode ( an exception node)
323 print("//XXX genExDeclares")
325 sname
= self
.namespace(ex
, "_")
327 for m
in ex
.members():
328 for decl
in m
.declarators():
329 if m
.memberType().unalias().kind() == idltype
.tk_sequence
:
330 if self
.isSeqNativeType(m
.memberType().unalias().seqType()):
331 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier())
332 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier() + "_loop")
333 elif m
.memberType().unalias().kind() != idltype
.tk_struct
:
334 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + decl
.identifier())
336 def genUnionDeclares(self
, un
):
337 """Generate hf variables for union filters
343 print("//XXX genUnionDeclares")
345 sname
= self
.namespace(un
, "_")
346 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + un
.identifier())
348 for uc
in un
.cases(): # for all UnionCase objects in this union
349 # TODO: Is this loop necessary? cl is not used
350 for cl
in uc
.labels(): # for all Caselabel objects in this UnionCase
351 if uc
.caseType().unalias().kind() == idltype
.tk_sequence
:
352 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + uc
.declarator().identifier() + "_loop")
353 if self
.isSeqNativeType(uc
.caseType().unalias().seqType()):
354 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + uc
.declarator().identifier())
355 elif self
.isSeqNativeType(uc
.caseType()):
356 if uc
.caseType().unalias().kind() == idltype
.tk_wchar
:
357 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + uc
.declarator().identifier() + "_len")
358 self
.st
.out(self
.template_hf
, name
=sname
+ "_" + uc
.declarator().identifier())
360 def genExpertInfoDeclares(self
):
361 """Generate ei variables for expert info filters"""
363 print("//XXX genExpertInfoDeclares")
365 self
.st
.out(self
.template_proto_register_ei_filters
, dissector_name
=self
.dissname
)
367 def genDeclares(self
, oplist
, atlist
, enlist
, stlist
, unlist
):
368 """generate function prototypes if required
370 Currently this is used for struct and union helper function declarations.
374 print("//XXX genDeclares")
376 # prototype for operation filters
377 self
.st
.out(self
.template_hf_operations
)
379 # operation specific filters
381 self
.st
.out(self
.template_proto_register_op_filter_comment
)
383 self
.genOpDeclares(op
)
387 self
.st
.out(self
.template_proto_register_at_filter_comment
)
389 self
.genAtDeclares(at
)
393 self
.st
.out(self
.template_proto_register_st_filter_comment
)
395 self
.genStDeclares(st
)
397 # exception List filters
398 exlist
= self
.get_exceptionList(oplist
) # grab list of exception nodes
400 self
.st
.out(self
.template_proto_register_ex_filter_comment
)
402 if ex
.members(): # only if has members
403 self
.genExDeclares(ex
)
407 self
.st
.out(self
.template_proto_register_un_filter_comment
)
409 self
.genUnionDeclares(un
)
411 # expert info filters
412 self
.genExpertInfoDeclares()
414 # prototype for start_dissecting()
416 self
.st
.out(self
.template_prototype_start_dissecting
)
421 self
.st
.out(self
.template_prototype_struct_start
)
424 sname
= self
.namespace(st
, "_")
425 self
.st
.out(self
.template_prototype_struct_body
, stname
=st
.repoId(), name
=sname
)
427 self
.st
.out(self
.template_prototype_struct_end
)
431 self
.st
.out(self
.template_prototype_union_start
)
433 sname
= self
.namespace(un
, "_")
434 self
.st
.out(self
.template_prototype_union_body
, unname
=un
.repoId(), name
=sname
)
435 self
.st
.out(self
.template_prototype_union_end
)
437 def genPrototype(self
):
438 self
.st
.out(self
.template_prototype
, dissector_name
=self
.dissname
)
440 def genProtocol(self
):
441 self
.st
.out(self
.template_protocol
, dissector_name
=self
.dissname
)
442 self
.st
.out(self
.template_init_boundary
)
445 def genMainEntryStart(self
, oplist
):
446 self
.st
.out(self
.template_main_dissector_start
, dissname
=self
.dissname
, disprot
=self
.protoname
)
448 self
.st
.out(self
.template_main_dissector_switch_msgtype_start
)
449 self
.st
.out(self
.template_main_dissector_switch_msgtype_start_request_reply
)
452 def genMainEntryEnd(self
):
454 self
.st
.out(self
.template_main_dissector_switch_msgtype_end_request_reply
)
456 self
.st
.out(self
.template_main_dissector_switch_msgtype_all_other_msgtype
)
458 self
.st
.out(self
.template_main_dissector_end
)
461 # NOTE: Mapping of attributes to operation(function) names is tricky.
463 # The actual accessor function names are language-mapping specific. The attribute name
464 # is subject to OMG IDL's name scoping rules; the accessor function names are
465 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
469 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
470 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
474 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
475 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
477 # TODO: Implement some language dependent templates to handle naming conventions
478 # language <=> attribute. for C, C++. Java etc
480 # OR, just add a runtime GUI option to select language binding for attributes -- FS
482 def genAtList(self
, atlist
):
485 out: C code for IDL attribute declarations.
487 ie: def genAtlist(self,atlist,language)
490 self
.st
.out(self
.template_comment_attributes_start
)
493 for i
in n
.declarators(): #
494 sname
= self
.namespace(i
, "_")
495 atname
= i
.identifier()
496 self
.st
.out(self
.template_attributes_declare_Java_get
, sname
=sname
, atname
=atname
)
498 self
.st
.out(self
.template_attributes_declare_Java_set
, sname
=sname
, atname
=atname
)
500 self
.st
.out(self
.template_comment_attributes_end
)
502 def genEnList(self
, enlist
):
505 out: C code for IDL Enum declarations using "static const value_string" template
508 self
.st
.out(self
.template_comment_enums_start
)
511 sname
= self
.namespace(enum
, "_")
513 self
.st
.out(self
.template_comment_enum_comment
, ename
=enum
.repoId())
514 self
.st
.out(self
.template_value_string_start
, valstringname
=sname
)
515 for enumerator
in enum
.enumerators():
516 self
.st
.out(self
.template_value_string_entry
,
517 intval
=str(self
.valFromEnum(enum
, enumerator
)),
518 description
=enumerator
.identifier())
520 #atname = n.identifier()
521 self
.st
.out(self
.template_value_string_end
, valstringname
=sname
)
523 self
.st
.out(self
.template_comment_enums_end
)
525 def genUnList(self
, unlist
):
528 out: C code for IDL Union declarations using "static const value_string template
533 if un
.switchType().kind() == idltype
.tk_enum
:
534 continue # skip enums since they already have value-strings
535 sname
= self
.namespace(un
, "_")
536 self
.st
.out(self
.template_value_string_start
, valstringname
=sname
)
537 for uc
in un
.cases():
538 for cl
in uc
.labels():
540 self
.st
.out(self
.template_value_string_entry
,
542 description
=uc
.declarator().identifier())
543 self
.st
.out(self
.template_value_string_end
, valstringname
=sname
)
548 def genExceptionDelegator(self
, oplist
):
551 out: C code for User exception delegator
554 self
.st
.out(self
.template_main_exception_delegator_start
)
557 exlist
= self
.get_exceptionList(oplist
) # grab list of ALL UNIQUE exception nodes
561 print("//XXX Exception ", ex
.repoId())
562 print("//XXX Exception Identifier", ex
.identifier())
563 print("//XXX Exception Scoped Name", ex
.scopedName())
565 if ex
.members(): # only if has members
566 sname
= self
.namespace(ex
, "_")
567 self
.st
.out(self
.template_ex_delegate_code
, sname
=sname
, exname
=ex
.repoId())
570 self
.st
.out(self
.template_main_exception_delegator_end
)
572 def genAttributeHelpers(self
, atlist
):
573 """Generate private helper functions to decode Attributes.
577 For readonly attribute - generate get_xxx()
578 If NOT readonly attribute - also generate set_xxx()
582 print("//XXX genAttributeHelpers: atlist = ", atlist
)
584 self
.st
.out(self
.template_attribute_helpers_start
)
586 for attrib
in atlist
:
587 for decl
in attrib
.declarators():
588 self
.genAtHelper(attrib
, decl
, "get") # get accessor
589 if not attrib
.readonly():
590 self
.genAtHelper(attrib
, decl
, "set") # set accessor
592 self
.st
.out(self
.template_attribute_helpers_end
)
594 def genAtHelper(self
, attrib
, decl
, order
):
595 """Generate private helper functions to decode an attribute
597 in: at - attribute node
598 in: decl - declarator belonging to this attribute
599 in: order - to generate a "get" or "set" helper
603 print("//XXX genAtHelper")
605 sname
= order
+ "_" + self
.namespace(decl
, "_") # must use set or get prefix to avoid collision
606 self
.curr_sname
= sname
# update current opnode/exnode scoped name
608 if not self
.fn_hash_built
:
609 self
.fn_hash
[sname
] = [] # init empty list as val for this sname key
610 # but only if the fn_hash is not already built
612 self
.st
.out(self
.template_attribute_helper_function_start
, sname
=sname
, atname
=decl
.repoId())
614 attr_type
= attrib
.attrType()
616 print("//XXX attrib = ", attrib
)
617 print("//XXX attrib.attrType.unalias.kind = ", attr_type
.unalias().kind())
619 if self
.isItemVarType(attr_type
):
620 self
.st
.out(self
.template_proto_item
)
622 if len(self
.fn_hash
[sname
]) > 0:
623 self
.st
.out(self
.template_helper_function_vars_start
)
624 self
.dumpCvars(sname
)
625 self
.st
.out(self
.template_helper_function_vars_end_item
)
627 self
.getCDR(attr_type
, sname
+ "_" + decl
.identifier())
630 self
.st
.out(self
.template_attribute_helper_function_end
)
632 def genExceptionHelpers(self
, oplist
):
633 """Generate private helper functions to decode Exceptions used
639 exlist
= self
.get_exceptionList(oplist
) # grab list of exception nodes
641 print("//XXX genExceptionHelpers: exlist = ", exlist
)
643 self
.st
.out(self
.template_exception_helpers_start
)
645 if ex
.members(): # only if has members
646 #print("//XXX Exception = " + ex.identifier())
649 self
.st
.out(self
.template_exception_helpers_end
)
651 def genExHelper(self
, ex
):
652 """Generate private helper functions to decode User Exceptions
654 in: exnode ( an exception node)
658 print("//XXX genExHelper")
660 # check to see if we need an item
662 for m
in ex
.members():
663 if self
.isItemVarType(m
.memberType()):
667 sname
= self
.namespace(ex
, "_")
668 self
.curr_sname
= sname
# update current opnode/exnode scoped name
669 if not self
.fn_hash_built
:
670 self
.fn_hash
[sname
] = [] # init empty list as val for this sname key
671 # but only if the fn_hash is not already built
673 self
.st
.out(self
.template_exception_helper_function_start
, sname
=sname
, exname
=ex
.repoId())
676 self
.st
.out(self
.template_proto_item
)
678 if len(self
.fn_hash
[sname
]) > 0:
679 self
.st
.out(self
.template_helper_function_vars_start
)
680 self
.dumpCvars(sname
)
682 self
.st
.out(self
.template_helper_function_vars_end_item
)
684 self
.st
.out(self
.template_helper_function_vars_end
)
686 for m
in ex
.members():
688 print("//XXX genExhelper, member = ", m
, "member type = ", m
.memberType())
690 for decl
in m
.declarators():
692 print("//XXX genExhelper, d = ", decl
)
694 if decl
.sizes(): # an array
695 arr_nonce
= ''.join(random
.SystemRandom().choice(string
.ascii_letters
+ string
.digits
) for _
in range(12))
696 indices
= self
.get_indices_from_sizes(decl
.sizes())
697 string_indices
= '%i ' % indices
# convert int to string
698 self
.st
.out(self
.template_get_CDR_array_comment
, aname
=decl
.identifier(), asize
=string_indices
)
699 self
.st
.out(self
.template_get_CDR_array_start
, nonce
=arr_nonce
, aname
=decl
.identifier(), aval
=string_indices
)
701 self
.addvar(self
.c_i
+ decl
.identifier() + ";")
704 self
.getCDR(m
.memberType(), sname
+ "_" + decl
.identifier())
708 self
.st
.out(self
.template_get_CDR_array_end
, nonce
=arr_nonce
)
711 self
.getCDR(m
.memberType(), sname
+ "_" + decl
.identifier())
714 self
.st
.out(self
.template_exception_helper_function_end
)
716 def genHelpers(self
, oplist
, stlist
, unlist
):
717 """Generate private helper functions
719 Generate private helper functions for each IDL operation.
720 Generate private helper functions for each IDL struct.
721 Generate private helper functions for each IDL union.
724 in: oplist, stlist, unlist
728 self
.genOperation(op
)
730 self
.genStructHelper(st
)
732 self
.genUnionHelper(un
)
734 def genOperation(self
, opnode
):
735 """Generate private helper functions for a specific IDL operation.
741 print("//XXX genOperation called")
742 print("//opnode =", opnode
)
743 print("//repoid =", opnode
.repoId())
745 sname
= self
.namespace(opnode
, "_")
746 if not self
.fn_hash_built
:
747 self
.fn_hash
[sname
] = [] # init empty list as val for this sname key
748 # but only if the fn_hash is not already built
750 self
.curr_sname
= sname
# update current opnode's scoped name
751 opname
= opnode
.identifier()
753 self
.st
.out(self
.template_helper_function_comment
, repoid
=opnode
.repoId())
755 self
.st
.out(self
.template_helper_function_start
, sname
=sname
)
758 if len(self
.fn_hash
[sname
]) > 0:
759 self
.st
.out(self
.template_helper_function_vars_start
)
760 self
.dumpCvars(sname
)
761 self
.st
.out(self
.template_helper_function_vars_end_item
)
763 self
.st
.out(self
.template_helper_switch_msgtype_start
)
765 self
.st
.out(self
.template_helper_switch_msgtype_request_start
)
767 self
.genOperationRequest(opnode
)
768 self
.st
.out(self
.template_helper_switch_msgtype_request_end
)
771 self
.st
.out(self
.template_helper_switch_msgtype_reply_start
)
774 self
.st
.out(self
.template_helper_switch_rep_status_start
)
776 self
.st
.out(self
.template_helper_switch_msgtype_reply_no_exception_start
)
778 self
.genOperationReply(opnode
)
779 self
.st
.out(self
.template_helper_switch_msgtype_reply_no_exception_end
)
782 self
.st
.out(self
.template_helper_switch_msgtype_reply_user_exception_start
)
784 self
.genOpExceptions(opnode
)
785 self
.st
.out(self
.template_helper_switch_msgtype_reply_user_exception_end
)
788 self
.st
.out(self
.template_helper_switch_msgtype_reply_default_start
, dissector_name
=self
.dissname
)
789 self
.st
.out(self
.template_helper_switch_msgtype_reply_default_end
)
791 self
.st
.out(self
.template_helper_switch_rep_status_end
)
795 self
.st
.out(self
.template_helper_switch_msgtype_default_start
, dissector_name
=self
.dissname
)
796 self
.st
.out(self
.template_helper_switch_msgtype_default_end
)
798 self
.st
.out(self
.template_helper_switch_msgtype_end
)
801 self
.st
.out(self
.template_helper_function_end
, sname
=sname
)
803 def genOperationRequest(self
, opnode
):
804 """Decode function parameters for a GIOP request message"""
805 for p
in opnode
.parameters():
808 print("//XXX parameter = ", p
)
809 print("//XXX parameter type = ", p
.paramType())
810 print("//XXX parameter type kind = ", p
.paramType().kind())
812 self
.getCDR(p
.paramType(), self
.curr_sname
+ "_" + p
.identifier())
814 def genOperationReply(self
, opnode
):
815 """Decode function parameters for a GIOP reply message"""
816 rt
= opnode
.returnType() # get return type
818 print("//XXX genOperationReply")
819 print("//XXX opnode = ", opnode
)
820 print("//XXX return type = ", rt
)
821 print("//XXX return type.unalias = ", rt
.unalias())
822 print("//XXX return type.kind() = ", rt
.kind())
824 sname
= self
.namespace(opnode
, "_")
826 if rt
.kind() == idltype
.tk_alias
: # a typdef return val possibly ?
827 #self.getCDR(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
828 self
.get_CDR_alias(rt
, sname
+ "_return")
829 #self.get_CDR_alias(rt, rt.name())
832 self
.getCDR(rt
, sname
+ "_return") # return value is NOT an alias
834 for p
in opnode
.parameters():
835 if p
.is_out(): # out or inout
836 self
.getCDR(p
.paramType(), self
.curr_sname
+ "_" + p
.identifier())
838 #self.st.dec_indent()
840 # TODO: this method seems unnecessary
841 def genOpExceptions(self
, opnode
):
842 for ex
in opnode
.raises():
845 for m
in ex
.members():
847 #print m.memberType(), m.memberType().kind()
849 def genOpDelegator(self
, oplist
):
850 """Delegator for Operations"""
852 self
.st
.out(self
.template_no_ops_to_delegate
)
854 iname
= "/".join(op
.scopedName()[:-1])
855 opname
= op
.identifier()
856 sname
= self
.namespace(op
, "_")
857 self
.st
.out(self
.template_op_delegate_code
, interface
=iname
, sname
=sname
, opname
=opname
)
859 def genAtDelegator(self
, atlist
):
860 """Delegator for Attributes"""
862 for i
in a
.declarators():
863 sname
= self
.namespace(i
, "_")
864 self
.st
.out(self
.template_at_delegate_code_get
, sname
=sname
)
866 self
.st
.out(self
.template_at_delegate_code_set
, sname
=sname
)
868 def addvar(self
, var
):
869 """Add a variable declaration to the hash of list"""
870 if var
not in self
.fn_hash
[self
.curr_sname
]:
871 self
.fn_hash
[self
.curr_sname
].append(var
)
874 """Print the variable declaration from the hash of list"""
875 for fn
in self
.fn_hash
.keys():
877 for v
in self
.fn_hash
[fn
]:
880 def dumpCvars(self
, sname
):
881 """Print the "C" variable declaration from the hash of list
882 for a given scoped operation name (eg: tux_penguin_eat)"""
883 for v
in self
.fn_hash
[sname
]:
886 def valFromEnum(self
, enumNode
, enumeratorNode
):
887 """Given an enum node, and a enumerator node, return the enumerator's numerical value.
889 eg: enum Color {red,green,blue} should return
894 print("//XXX valFromEnum, enumNode = ", enumNode
, " from ", enumNode
.repoId())
895 print("//XXX valFromEnum, enumeratorNode = ", enumeratorNode
, " from ", enumeratorNode
.repoId())
897 if isinstance(enumeratorNode
, idlast
.Enumerator
):
898 value
= enumNode
.enumerators().index(enumeratorNode
)
934 # tk_abstract_interface = 32
936 def isSeqNativeType(self
, type):
937 """Return true for "native" datatypes that will generate a direct proto_tree_add_xxx
938 call for a sequence. Used to determine if a separate hf variable is needed for
939 the loop over the sequence"""
941 pt
= type.unalias().kind() # param CDR type
944 print("//XXX isSeqNativeType: kind = ", pt
)
946 if pt
== idltype
.tk_ulong
:
948 elif pt
== idltype
.tk_longlong
:
950 elif pt
== idltype
.tk_ulonglong
:
952 elif pt
== idltype
.tk_short
:
954 elif pt
== idltype
.tk_long
:
956 elif pt
== idltype
.tk_ushort
:
958 elif pt
== idltype
.tk_float
:
960 elif pt
== idltype
.tk_double
:
962 elif pt
== idltype
.tk_boolean
:
964 elif pt
== idltype
.tk_octet
:
966 elif pt
== idltype
.tk_enum
:
968 elif pt
== idltype
.tk_string
:
970 elif pt
== idltype
.tk_wstring
:
972 elif pt
== idltype
.tk_wchar
:
974 elif pt
== idltype
.tk_char
:
979 def isItemVarType(self
, type):
981 pt
= type.unalias().kind() # param CDR type
984 print("//XXX isItemVarType: kind = ", pt
)
986 if pt
in [idltype
.tk_struct
, idltype
.tk_fixed
, idltype
.tk_any
]:
988 elif pt
== idltype
.tk_alias
:
989 inner_pt
= type.decl().alias().aliasType().unalias().kind()
990 elif pt
== idltype
.tk_sequence
:
991 inner_pt
= type.unalias().seqType().unalias().kind()
992 elif pt
== idltype
.tk_array
:
993 inner_pt
== type.decl().alias().aliasType().unalias().kind()
994 if inner_pt
is not None and inner_pt
in \
995 [idltype
.tk_struct
, idltype
.tk_fixed
, idltype
.tk_any
]:
997 elif inner_pt
in [idltype
.tk_alias
, idltype
.tk_sequence
,\
999 return self
.isItemVarType(inner_pt
)
1002 def getCDR(self
, type, name
="fred"):
1003 """This is the main "iterator" function. It takes a node, and tries to output
1004 a get_CDR_XXX accessor method(s). It can call itself multiple times
1005 if it finds nested structures etc."""
1007 pt
= type.unalias().kind() # param CDR type
1008 pn
= name
# param name
1011 print("//XXX getCDR: kind = ", pt
)
1012 print("//XXX getCDR: name = ", pn
)
1014 if pt
== idltype
.tk_ulong
:
1015 self
.get_CDR_ulong(pn
)
1016 elif pt
== idltype
.tk_longlong
:
1017 self
.get_CDR_longlong(pn
)
1018 elif pt
== idltype
.tk_ulonglong
:
1019 self
.get_CDR_ulonglong(pn
)
1020 elif pt
== idltype
.tk_void
:
1021 self
.get_CDR_void(pn
)
1022 elif pt
== idltype
.tk_short
:
1023 self
.get_CDR_short(pn
)
1024 elif pt
== idltype
.tk_long
:
1025 self
.get_CDR_long(pn
)
1026 elif pt
== idltype
.tk_ushort
:
1027 self
.get_CDR_ushort(pn
)
1028 elif pt
== idltype
.tk_float
:
1029 self
.get_CDR_float(pn
)
1030 elif pt
== idltype
.tk_double
:
1031 self
.get_CDR_double(pn
)
1032 elif pt
== idltype
.tk_fixed
:
1033 self
.get_CDR_fixed(type.unalias(), pn
)
1034 elif pt
== idltype
.tk_boolean
:
1035 self
.get_CDR_boolean(pn
)
1036 elif pt
== idltype
.tk_char
:
1037 self
.get_CDR_char(pn
)
1038 elif pt
== idltype
.tk_octet
:
1039 self
.get_CDR_octet(pn
)
1040 elif pt
== idltype
.tk_any
:
1041 self
.get_CDR_any(pn
)
1042 elif pt
== idltype
.tk_string
:
1043 self
.get_CDR_string(pn
)
1044 elif pt
== idltype
.tk_wstring
:
1045 self
.get_CDR_wstring(pn
)
1046 elif pt
== idltype
.tk_wchar
:
1047 self
.get_CDR_wchar(pn
)
1048 elif pt
== idltype
.tk_enum
:
1050 self
.get_CDR_enum(pn
, type)
1051 #self.get_CDR_enum(pn)
1053 elif pt
== idltype
.tk_struct
:
1054 self
.get_CDR_struct(type, pn
)
1055 elif pt
== idltype
.tk_TypeCode
: # will I ever get here ?
1056 self
.get_CDR_TypeCode(pn
)
1057 elif pt
== idltype
.tk_sequence
:
1058 if type.unalias().seqType().kind() == idltype
.tk_octet
:
1059 self
.get_CDR_sequence_octet(type, pn
)
1061 self
.get_CDR_sequence(type, pn
)
1062 elif pt
== idltype
.tk_objref
:
1063 self
.get_CDR_objref(type, pn
)
1064 elif pt
== idltype
.tk_array
:
1065 pass # Supported elsewhere
1066 elif pt
== idltype
.tk_union
:
1067 self
.get_CDR_union(type, pn
)
1068 elif pt
== idltype
.tk_alias
:
1070 print("//XXXXX Alias type XXXXX ", type)
1071 self
.get_CDR_alias(type, pn
)
1073 self
.genWARNING("Unknown typecode = " + '%i ' % pt
) # put comment in source code
1075 def get_CDR_ulong(self
, pn
):
1076 self
.st
.out(self
.template_get_CDR_ulong
, hfname
=pn
)
1078 def get_CDR_short(self
, pn
):
1079 self
.st
.out(self
.template_get_CDR_short
, hfname
=pn
)
1081 def get_CDR_void(self
, pn
):
1082 self
.st
.out(self
.template_get_CDR_void
, hfname
=pn
)
1084 def get_CDR_long(self
, pn
):
1085 self
.st
.out(self
.template_get_CDR_long
, hfname
=pn
)
1087 def get_CDR_ushort(self
, pn
):
1088 self
.st
.out(self
.template_get_CDR_ushort
, hfname
=pn
)
1090 def get_CDR_float(self
, pn
):
1091 self
.st
.out(self
.template_get_CDR_float
, hfname
=pn
)
1093 def get_CDR_double(self
, pn
):
1094 self
.st
.out(self
.template_get_CDR_double
, hfname
=pn
)
1096 def get_CDR_longlong(self
, pn
):
1097 self
.st
.out(self
.template_get_CDR_longlong
, hfname
=pn
)
1099 def get_CDR_ulonglong(self
, pn
):
1100 self
.st
.out(self
.template_get_CDR_ulonglong
, hfname
=pn
)
1102 def get_CDR_boolean(self
, pn
):
1103 self
.st
.out(self
.template_get_CDR_boolean
, hfname
=pn
)
1105 def get_CDR_fixed(self
, type, pn
):
1107 print("//XXXX calling get_CDR_fixed, type = ", type)
1108 print("//XXXX calling get_CDR_fixed, type.digits() = ", type.digits())
1109 print("//XXXX calling get_CDR_fixed, type.scale() = ", type.scale())
1111 string_digits
= '%i ' % type.digits() # convert int to string
1112 string_scale
= '%i ' % type.scale() # convert int to string
1113 string_length
= '%i ' % self
.dig_to_len(type.digits()) # how many octets to highlight for a number of digits
1115 self
.st
.out(self
.template_get_CDR_fixed
, hfname
=pn
, digits
=string_digits
, scale
=string_scale
, length
=string_length
)
1116 self
.addvar(self
.c_seq
)
1118 def get_CDR_char(self
, pn
):
1119 self
.st
.out(self
.template_get_CDR_char
, hfname
=pn
)
1121 def get_CDR_octet(self
, pn
):
1122 self
.st
.out(self
.template_get_CDR_octet
, hfname
=pn
)
1124 def get_CDR_any(self
, pn
):
1125 self
.st
.out(self
.template_get_CDR_any
, varname
=pn
)
1127 def get_CDR_enum(self
, pn
, type):
1128 #self.st.out(self.template_get_CDR_enum, hfname=pn)
1129 sname
= self
.namespace(type.unalias(), "_")
1130 self
.st
.out(self
.template_get_CDR_enum_symbolic
, valstringarray
=sname
, hfname
=pn
)
1131 self
.addvar(self
.c_u_octet4
)
1133 def get_CDR_string(self
, pn
):
1134 self
.st
.out(self
.template_get_CDR_string
, hfname
=pn
)
1136 def get_CDR_wstring(self
, pn
):
1137 self
.st
.out(self
.template_get_CDR_wstring
, hfname
=pn
)
1138 self
.addvar(self
.c_u_octet4
)
1139 self
.addvar(self
.c_seq
)
1141 def get_CDR_wchar(self
, pn
):
1142 self
.st
.out(self
.template_get_CDR_wchar
, hfname
=pn
)
1143 self
.addvar(self
.c_s_octet1
)
1144 self
.addvar(self
.c_seq
)
1146 def get_CDR_TypeCode(self
, pn
):
1147 self
.st
.out(self
.template_get_CDR_TypeCode
, varname
=pn
)
1148 self
.addvar(self
.c_u_octet4
)
1150 def get_CDR_objref(self
, type, pn
):
1151 self
.st
.out(self
.template_get_CDR_object
)
1153 def get_CDR_union(self
, type, pn
):
1155 print("//XXX Union type =", type, " pn = ", pn
)
1156 print("//XXX Union type.decl()", type.decl())
1157 print("//XXX Union Scoped Name", type.scopedName())
1159 # If I am a typedef union {..}; node then find the union node
1161 if isinstance(type.decl(), idlast
.Declarator
):
1162 ntype
= type.decl().alias().aliasType().decl()
1164 ntype
= type.decl() # I am a union node
1167 print("//XXX Union ntype =", ntype
)
1169 sname
= self
.namespace(ntype
, "_")
1170 self
.st
.out(self
.template_union_start
, name
=sname
)
1172 # Output a call to the union helper function so I can handle recursive union also.
1174 self
.st
.out(self
.template_decode_union
, name
=sname
)
1176 self
.st
.out(self
.template_union_end
, name
=sname
)
1178 def getCDR_hf(self
, type, desc
, filter, hf_name
="fred", value_str
=None):
1179 """This takes a node, and tries to output the appropriate item for the
1181 pt
= type.unalias().kind() # param CDR type
1182 pn
= hf_name
# param name
1185 print("//XXX getCDR_hf: kind = ", pt
)
1186 print("//XXX getCDR_hf: name = ", pn
)
1188 if pt
== idltype
.tk_ulong
:
1189 self
.get_CDR_ulong_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1190 elif pt
== idltype
.tk_longlong
:
1191 self
.get_CDR_longlong_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1192 elif pt
== idltype
.tk_ulonglong
:
1193 self
.get_CDR_ulonglong_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1194 elif pt
== idltype
.tk_void
:
1195 pass # no hf_ variables needed
1196 elif pt
== idltype
.tk_short
:
1197 self
.get_CDR_short_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1198 elif pt
== idltype
.tk_long
:
1199 self
.get_CDR_long_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1200 elif pt
== idltype
.tk_ushort
:
1201 self
.get_CDR_ushort_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1202 elif pt
== idltype
.tk_float
:
1203 self
.get_CDR_float_hf(pn
, desc
, filter, self
.dissname
)
1204 elif pt
== idltype
.tk_double
:
1205 self
.get_CDR_double_hf(pn
, desc
, filter, self
.dissname
)
1206 elif pt
== idltype
.tk_fixed
:
1207 self
.get_CDR_fixed_hf(pn
, desc
, filter, self
.dissname
)
1208 elif pt
== idltype
.tk_boolean
:
1209 self
.get_CDR_boolean_hf(pn
, desc
, filter, self
.dissname
)
1210 elif pt
== idltype
.tk_char
:
1211 self
.get_CDR_char_hf(pn
, desc
, filter, self
.dissname
, value_str
)
1212 elif pt
== idltype
.tk_octet
:
1213 self
.get_CDR_octet_hf(pn
, desc
, filter, self
.dissname
)
1214 elif pt
== idltype
.tk_any
:
1215 pass # no hf_ variables needed
1216 elif pt
== idltype
.tk_string
:
1217 self
.get_CDR_string_hf(pn
, desc
, filter, self
.dissname
)
1218 elif pt
== idltype
.tk_wstring
:
1219 self
.get_CDR_wstring_hf(pn
, desc
, filter, self
.dissname
)
1220 elif pt
== idltype
.tk_wchar
:
1221 self
.get_CDR_wchar_hf(pn
, desc
, filter, self
.dissname
)
1222 elif pt
== idltype
.tk_enum
:
1223 self
.get_CDR_enum_hf(pn
, type, desc
, filter, self
.dissname
)
1224 elif pt
== idltype
.tk_struct
:
1225 pass # no hf_ variables needed (should be already contained in struct members)
1226 elif pt
== idltype
.tk_TypeCode
: # will I ever get here ?
1227 self
.get_CDR_TypeCode_hf(pn
, desc
, filter, self
.dissname
)
1228 elif pt
== idltype
.tk_sequence
:
1229 if type.unalias().seqType().kind() == idltype
.tk_octet
:
1230 self
.get_CDR_sequence_octet_hf(type, pn
, desc
, filter, self
.dissname
)
1232 self
.get_CDR_sequence_hf(type, pn
, desc
, filter, self
.dissname
)
1233 elif pt
== idltype
.tk_objref
:
1234 pass # no object specific hf_ variables used, use generic ones from giop dissector
1235 elif pt
== idltype
.tk_array
:
1236 pass # Supported elsewhere
1237 elif pt
== idltype
.tk_union
:
1238 pass # no hf_ variables needed (should be already contained in union members)
1239 elif pt
== idltype
.tk_alias
:
1241 print("//XXXXX Alias type hf //XXXXX ", type)
1242 self
.get_CDR_alias_hf(type, desc
, filter, pn
)
1244 self
.genWARNING("Unknown typecode = " + '%i ' % pt
) # put comment in source code
1246 def get_CDR_ulong_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1248 self
.st
.out(self
.template_get_CDR_ulong_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1250 self
.st
.out(self
.template_get_CDR_ulong_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1252 def get_CDR_short_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1254 self
.st
.out(self
.template_get_CDR_short_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1256 self
.st
.out(self
.template_get_CDR_short_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1258 def get_CDR_long_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1260 self
.st
.out(self
.template_get_CDR_long_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1262 self
.st
.out(self
.template_get_CDR_long_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1264 def get_CDR_ushort_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1266 self
.st
.out(self
.template_get_CDR_ushort_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1268 self
.st
.out(self
.template_get_CDR_ushort_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1270 def get_CDR_float_hf(self
, pn
, desc
, filter, diss
):
1271 self
.st
.out(self
.template_get_CDR_float_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1273 def get_CDR_double_hf(self
, pn
, desc
, filter, diss
):
1274 self
.st
.out(self
.template_get_CDR_double_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1276 def get_CDR_fixed_hf(self
, pn
, desc
, filter, diss
):
1277 self
.st
.out(self
.template_get_CDR_fixed_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1279 def get_CDR_longlong_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1281 self
.st
.out(self
.template_get_CDR_longlong_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1283 self
.st
.out(self
.template_get_CDR_longlong_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1285 def get_CDR_ulonglong_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1287 self
.st
.out(self
.template_get_CDR_ulonglong_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1289 self
.st
.out(self
.template_get_CDR_ulonglong_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1291 def get_CDR_boolean_hf(self
, pn
, desc
, filter, diss
):
1292 self
.st
.out(self
.template_get_CDR_boolean_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1294 def get_CDR_char_hf(self
, pn
, desc
, filter, diss
, value_str
=None):
1296 self
.st
.out(self
.template_get_CDR_char_symbolic_hf
, valstringarray
=value_str
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1298 self
.st
.out(self
.template_get_CDR_char_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1300 def get_CDR_octet_hf(self
, pn
, desc
, filter, diss
):
1301 self
.st
.out(self
.template_get_CDR_octet_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1303 def get_CDR_enum_hf(self
, pn
, type, desc
, filter, diss
):
1304 sname
= self
.namespace(type.unalias(), "_")
1305 self
.st
.out(self
.template_get_CDR_enum_symbolic_hf
, valstringarray
=sname
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1307 def get_CDR_string_hf(self
, pn
, desc
, filter, diss
):
1308 self
.st
.out(self
.template_get_CDR_string_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1310 def get_CDR_wstring_hf(self
, pn
, desc
, filter, diss
):
1311 self
.st
.out(self
.template_get_CDR_wstring_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1312 # self.addvar(self.c_u_octet4)
1313 # self.addvar(self.c_seq)
1315 def get_CDR_wchar_hf(self
, pn
, desc
, filter, diss
):
1316 self
.st
.out(self
.template_get_CDR_wchar_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1317 # self.addvar(self.c_s_octet1)
1318 # self.addvar(self.c_seq)
1320 def get_CDR_TypeCode_hf(self
, pn
, desc
, filter, diss
):
1321 self
.st
.out(self
.template_get_CDR_TypeCode_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1323 def get_CDR_sequence_octet_hf(self
, type, pn
, desc
, filter, diss
):
1324 self
.st
.out(self
.template_get_CDR_sequence_octet_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1326 def get_CDR_sequence_hf(self
,type,pn
,desc
,filter,diss
):
1327 self
.st
.out(self
.template_get_CDR_sequence_hf
, hfname
=pn
, dissector_name
=diss
, descname
=desc
, filtername
=filter)
1328 if self
.isSeqNativeType(type.unalias().seqType()):
1329 self
.getCDR_hf(type.unalias().seqType(), desc
, filter, pn
)
1331 def get_CDR_alias_hf(self
, type, desc
, filter, pn
):
1333 print("//XXX get_CDR_alias_hf, type = ", type, " pn = ", pn
)
1334 print("//XXX get_CDR_alias_hf, type.decl() = ", type.decl())
1335 print("//XXX get_CDR_alias_hf, type.decl().alias() = ", type.decl().alias())
1337 decl
= type.decl() # get declarator object
1339 if decl
.sizes(): # a typedef array
1340 #indices = self.get_indices_from_sizes(decl.sizes())
1341 #string_indices = '%i ' % indices # convert int to string
1342 #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1344 #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1345 #self.addvar(self.c_i + pn + ";")
1346 #self.st.inc_indent()
1347 self
.getCDR_hf(type.decl().alias().aliasType(), desc
, filter, pn
)
1349 #self.st.dec_indent()
1350 #self.st.out(self.template_get_CDR_array_end)
1352 else: # a simple typdef
1354 print("//XXX get_CDR_alias_hf, type = ", type, " pn = ", pn
)
1355 print("//XXX get_CDR_alias_hf, type.decl() = ", type.decl())
1357 #self.getCDR_hf(type.unalias(), desc, filter, decl.identifier() )
1358 self
.getCDR_hf(type.unalias(), desc
, filter, pn
)
1360 def genUnionHelper(self
, un
):
1361 """Code to generate Union Helper functions
1363 in: un - a union node
1367 print("//XXX genUnionHelper called")
1368 print("//XXX Union type =", un
)
1369 print("//XXX Union type.switchType()", un
.switchType())
1370 print("//XXX Union Scoped Name", un
.scopedName())
1371 print("//XXX Union switchType.unalias", un
.switchType().unalias())
1372 print("//XXX Union switchType.unalias.kind", un
.switchType().unalias().kind())
1374 # check to see if we need an item
1375 un_need_item
= False
1376 if un
.switchType().unalias().kind() == idltype
.tk_enum
:
1377 for uc
in un
.cases(): # for all UnionCase objects in this union
1379 print("//XXX checking", uc
)
1380 if self
.isItemVarType(uc
.caseType()):
1381 if uc
.caseType().unalias().kind() == idltype
.tk_sequence
:
1382 if uc
.caseType().unalias().seqType().kind() == idltype
.tk_struct
:
1390 print("//XXX need_item =", un_need_item
)
1392 sname
= self
.namespace(un
, "_")
1393 self
.curr_sname
= sname
# update current opnode/exnode/stnode/unnode scoped name
1394 if not self
.fn_hash_built
:
1395 self
.fn_hash
[sname
] = [] # init empty list as val for this sname key
1396 # but only if the fn_hash is not already built
1399 self
.st
.out(self
.template_union_helper_function_start_with_item
, sname
=sname
, unname
=un
.repoId())
1401 self
.st
.out(self
.template_union_helper_function_start
, sname
=sname
, unname
=un
.repoId())
1402 self
.st
.inc_indent()
1404 if len(self
.fn_hash
[sname
]) > 0:
1405 self
.st
.out(self
.template_helper_function_vars_start
)
1406 self
.dumpCvars(sname
)
1407 self
.st
.out(self
.template_helper_function_vars_end_item
)
1409 st
= un
.switchType().unalias() # may be typedef switch type, so find real type
1411 self
.st
.out(self
.template_comment_union_code_start
, uname
=un
.repoId())
1413 self
.getCDR(st
, sname
+ "_" + un
.identifier())
1415 # Depending on what kind of discriminant I come across (enum,integer,char,
1416 # short, boolean), make sure I cast the return value of the get_XXX accessor
1417 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1418 # return an integer, or an Enumerator object that is then converted to its
1419 # integer equivalent.
1422 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1425 if st
.kind() == idltype
.tk_enum
:
1427 self
.st
.out(self
.template_comment_union_code_discriminant
, uname
=std
.repoId())
1429 # count the number of cases to ensure variable is needed
1432 for uc
in un
.cases(): # for all UnionCase objects in this union
1433 num
+= len(uc
.labels())
1434 for cl
in uc
.labels():
1438 if num
!= 1 or num_defaults
!= 1:
1439 self
.st
.out(self
.template_union_code_save_discriminant_enum
, discname
=un
.identifier())
1440 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1442 elif st
.kind() == idltype
.tk_long
:
1443 self
.st
.out(self
.template_union_code_save_discriminant_long
, discname
=un
.identifier())
1444 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1446 elif st
.kind() == idltype
.tk_ulong
:
1447 self
.st
.out(self
.template_union_code_save_discriminant_ulong
, discname
=un
.identifier())
1448 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1450 elif st
.kind() == idltype
.tk_short
:
1451 self
.st
.out(self
.template_union_code_save_discriminant_short
, discname
=un
.identifier())
1452 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1454 elif st
.kind() == idltype
.tk_ushort
:
1455 self
.st
.out(self
.template_union_code_save_discriminant_ushort
, discname
=un
.identifier())
1456 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1458 elif st
.kind() == idltype
.tk_boolean
:
1459 self
.st
.out(self
.template_union_code_save_discriminant_boolean
, discname
=un
.identifier())
1460 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1462 elif st
.kind() == idltype
.tk_char
:
1463 self
.st
.out(self
.template_union_code_save_discriminant_char
, discname
=un
.identifier())
1464 self
.addvar(self
.c_s_disc
+ un
.identifier() + ";")
1467 print("//XXX Unknown st.kind() = ", st
.kind())
1469 # Loop over all cases in this union
1471 for uc
in un
.cases(): # for all UnionCase objects in this union
1472 for cl
in uc
.labels(): # for all Caselabel objects in this UnionCase
1474 # get integer value, even if discriminant is
1475 # an Enumerator node
1477 if isinstance(cl
.value(), idlast
.Enumerator
):
1479 print("//XXX clv.identifier()", cl
.value().identifier())
1480 print("//XXX clv.repoId()", cl
.value().repoId())
1481 print("//XXX clv.scopedName()", cl
.value().scopedName())
1483 # find index of enumerator in enum declaration
1484 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1486 clv
= self
.valFromEnum(std
, cl
.value())
1491 #print "//XXX clv = ",clv
1493 # if char, don't convert to int, but put inside single quotes so that it is understood by C.
1494 # eg: if (disc == 'b')..
1496 # TODO : handle \xxx chars generically from a function or table lookup rather than
1497 # a whole bunch of "if" statements. -- FS
1499 if st
.kind() == idltype
.tk_char
:
1501 string_clv
= "'\\n'"
1503 string_clv
= "'\\t'"
1505 string_clv
= "'" + clv
+ "'"
1507 string_clv
= '%i ' % clv
1509 # If default case, then skp comparison with discriminator
1511 if not cl
.default():
1512 self
.st
.out(self
.template_comment_union_code_label_compare_start
,
1513 discname
=un
.identifier(), labelval
=string_clv
)
1514 self
.st
.inc_indent()
1516 self
.st
.out(self
.template_comment_union_code_label_default_start
)
1518 self
.getCDR(uc
.caseType(), sname
+ "_" + uc
.declarator().identifier())
1520 if not cl
.default():
1521 self
.st
.dec_indent()
1522 self
.st
.out(self
.template_comment_union_code_label_compare_end
)
1524 self
.st
.out(self
.template_comment_union_code_label_default_end
)
1526 self
.st
.dec_indent()
1527 self
.st
.out(self
.template_union_helper_function_end
)
1529 def get_CDR_alias(self
, type, pn
):
1530 """Currently, get_CDR_alias is geared to finding typedef"""
1532 print("//XXX get_CDR_alias, type = ", type, " pn = ", pn
)
1533 print("//XXX get_CDR_alias, type.decl() = ", type.decl())
1534 print("//XXX get_CDR_alias, type.decl().alias() = ", type.decl().alias())
1536 decl
= type.decl() # get declarator object
1538 if decl
.sizes(): # a typedef array
1539 indices
= self
.get_indices_from_sizes(decl
.sizes())
1540 string_indices
= '%i ' % indices
# convert int to string
1541 self
.st
.out(self
.template_get_CDR_array_comment
, aname
=pn
, asize
=string_indices
)
1543 arr_nonce
= ''.join(random
.SystemRandom().choice(string
.ascii_letters
+ string
.digits
) for _
in range(12))
1544 self
.st
.out(self
.template_get_CDR_array_start
, nonce
=arr_nonce
, aname
=pn
, aval
=string_indices
)
1545 self
.st
.inc_indent()
1546 self
.addvar(self
.c_i
+ pn
+ ";")
1547 self
.st
.inc_indent()
1548 self
.getCDR(type.decl().alias().aliasType(), pn
)
1550 self
.st
.dec_indent()
1551 self
.st
.dec_indent()
1552 self
.st
.out(self
.template_get_CDR_array_end
, nonce
=arr_nonce
)
1554 else: # a simple typdef
1556 print("//XXX type", type.__dict
__)
1557 print("//XXX type.unalias()", type.unalias().__dict
__)
1558 print("//XXX type.unalias().kind()", type.unalias().kind())
1559 print("//XXX type.decl()", type.decl().__dict
__)
1560 self
.getCDR(type.unalias(), pn
)
1562 def get_CDR_struct(self
, type, pn
):
1563 """Handle structs, including recursive"""
1565 # If I am a typedef struct {..}; node then find the struct node
1567 if isinstance(type.decl(), idlast
.Declarator
):
1568 ntype
= type.decl().alias().aliasType().decl()
1570 ntype
= type.decl() # I am a struct node
1572 sname
= self
.namespace(ntype
, "_")
1573 self
.st
.out(self
.template_structure_start
, name
=sname
)
1575 # Output a call to the struct helper function so I can handle recursive structs also.
1577 self
.st
.out(self
.template_decode_struct
, name
=sname
)
1579 self
.st
.out(self
.template_structure_end
, name
=sname
)
1581 def genStructHelper(self
, st
):
1582 """Generate private helper functions to decode a struct
1584 in: stnode ( a struct node)
1588 print("//XXX genStructHelper")
1590 sname
= self
.namespace(st
, "_")
1591 self
.curr_sname
= sname
# update current opnode/exnode/stnode scoped name
1592 if not self
.fn_hash_built
:
1593 self
.fn_hash
[sname
] = [] # init empty list as val for this sname key
1594 # but only if the fn_hash is not already built
1596 self
.st
.out(self
.template_struct_helper_function_start
, sname
=sname
, stname
=st
.repoId())
1597 self
.st
.inc_indent()
1599 if len(self
.fn_hash
[sname
]) > 0:
1600 self
.st
.out(self
.template_helper_function_vars_start
)
1601 self
.dumpCvars(sname
)
1602 self
.st
.out(self
.template_helper_function_vars_end_item
)
1604 for m
in st
.members():
1605 for decl
in m
.declarators():
1606 if decl
.sizes(): # an array
1607 arr_nonce
= ''.join(random
.SystemRandom().choice(string
.ascii_letters
+ string
.digits
) for _
in range(12))
1608 indices
= self
.get_indices_from_sizes(decl
.sizes())
1609 string_indices
= '%i ' % indices
# convert int to string
1610 self
.st
.out(self
.template_get_CDR_array_comment
, aname
=decl
.identifier(), asize
=string_indices
)
1611 self
.st
.out(self
.template_get_CDR_array_start
, nonce
=arr_nonce
, aname
=decl
.identifier(), aval
=string_indices
)
1612 self
.st
.inc_indent()
1613 self
.addvar(self
.c_i
+ decl
.identifier() + ";")
1615 self
.st
.inc_indent()
1616 self
.getCDR(m
.memberType(), sname
+ "_" + decl
.identifier())
1617 self
.st
.dec_indent()
1618 self
.st
.dec_indent()
1619 self
.st
.out(self
.template_get_CDR_array_end
, nonce
=arr_nonce
)
1622 self
.getCDR(m
.memberType(), sname
+ "_" + decl
.identifier())
1624 self
.st
.dec_indent()
1625 self
.st
.out(self
.template_struct_helper_function_end
)
1627 def get_CDR_sequence(self
,type,pn
):
1628 """Generate code to access a sequence of a type"""
1630 print("//XXX get_CDR_sequence")
1631 self
.st
.out(self
.template_get_CDR_sequence_length
, seqname
=pn
)
1632 seq_nonce
= ''.join(random
.SystemRandom().choice(string
.ascii_letters
+ string
.digits
) for _
in range(12))
1633 self
.st
.out(self
.template_get_CDR_sequence_loop_start
, nonce
=seq_nonce
, seqname
=pn
)
1634 self
.addvar(self
.c_i_lim
+ pn
+ ";")
1635 self
.addvar(self
.c_i
+ pn
+ ";")
1637 self
.st
.inc_indent()
1638 self
.st
.inc_indent()
1639 self
.getCDR(type.unalias().seqType(), pn
) # and start all over with the type
1640 self
.st
.dec_indent()
1641 self
.st
.dec_indent()
1643 self
.st
.out(self
.template_get_CDR_sequence_loop_end
, nonce
=seq_nonce
)
1645 def get_CDR_sequence_octet(self
, type, pn
):
1646 """Generate code to access a sequence of octet"""
1648 print("//XXX get_CDR_sequence_octet")
1650 self
.st
.out(self
.template_get_CDR_sequence_length
, seqname
=pn
)
1651 self
.st
.out(self
.template_get_CDR_sequence_octet
, seqname
=pn
)
1652 self
.addvar(self
.c_i_lim
+ pn
+ ";")
1653 self
.addvar("const uint8_t * binary_seq_" + pn
+ ";")
1654 self
.addvar("char * text_seq_" + pn
+ ";")
1657 def namespace(node
, sep
):
1660 out - scoped operation name, using sep character instead of "::"
1662 eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1665 sname
= idlutil
.ccolonName(node
.scopedName()).replace('::', sep
)
1666 #print("//XXX namespace: sname = " + sname)
1669 def gen_plugin_register(self
):
1670 """generate code for plugin initialisation"""
1671 self
.st
.out(self
.template_plugin_register
, description
=self
.description
,
1672 protocol_name
=self
.protoname
, dissector_name
=self
.dissname
)
1674 # TODO - make this a command line option
1679 def gen_proto_reg_handoff(self
, oplist
):
1680 """generate register_giop_user_module code, and register only
1681 unique interfaces that contain operations. Also output
1682 a heuristic register in case we want to use that."""
1684 self
.st
.out(self
.template_proto_reg_handoff_start
, dissector_name
=self
.dissname
)
1685 self
.st
.inc_indent()
1687 for iname
in self
.get_intlist(oplist
):
1688 self
.st
.out(self
.template_proto_reg_handoff_body
, dissector_name
=self
.dissname
,
1689 protocol_name
=self
.protoname
, interface
=iname
)
1691 self
.st
.out(self
.template_proto_reg_handoff_heuristic
, dissector_name
=self
.dissname
,
1692 protocol_name
=self
.protoname
)
1693 self
.st
.dec_indent()
1695 self
.st
.out(self
.template_proto_reg_handoff_end
)
1697 def genOp_hf(self
, op
):
1698 """generate hf_ array element for operation, attribute, enums, struct and union lists"""
1699 sname
= self
.namespace(op
, "_")
1700 opname
= sname
[sname
.find("_")+1:]
1701 opname
= opname
[:opname
.find("_")]
1702 rt
= op
.returnType()
1704 if rt
.kind() != idltype
.tk_void
:
1705 if rt
.kind() == idltype
.tk_alias
: # a typdef return val possibly ?
1706 self
.getCDR_hf(rt
, rt
.name(),
1707 opname
+ "." + op
.identifier() + ".return", sname
+ "_return")
1709 self
.getCDR_hf(rt
, "Return value",
1710 opname
+ "." + op
.identifier() + ".return", sname
+ "_return")
1712 for p
in op
.parameters():
1713 self
.getCDR_hf(p
.paramType(),
1715 opname
+ "." + op
.identifier() + "." + p
.identifier(),
1716 sname
+ "_" + p
.identifier())
1718 def genAt_hf(self
, at
):
1719 for decl
in at
.declarators():
1720 sname
= self
.namespace(decl
, "_")
1721 atname
= sname
[sname
.find("_")+1:]
1722 atname
= atname
[:atname
.find("_")]
1724 self
.getCDR_hf(at
.attrType(), decl
.identifier(),
1725 atname
+ "." + decl
.identifier() + ".get", "get" + "_" + sname
+ "_" + decl
.identifier())
1726 if not at
.readonly():
1727 self
.getCDR_hf(at
.attrType(), decl
.identifier(),
1728 atname
+ "." + decl
.identifier() + ".set", "set" + "_" + sname
+ "_" + decl
.identifier())
1730 def genSt_hf(self
, st
):
1731 sname
= self
.namespace(st
, "_")
1732 stname
= sname
[sname
.find("_")+1:]
1733 stname
= stname
[:stname
.find("_")]
1734 for m
in st
.members():
1735 for decl
in m
.declarators():
1736 self
.getCDR_hf(m
.memberType(), st
.identifier() + "_" + decl
.identifier(),
1737 st
.identifier() + "." + decl
.identifier(), sname
+ "_" + decl
.identifier())
1739 def genEx_hf(self
, ex
):
1740 sname
= self
.namespace(ex
, "_")
1741 exname
= sname
[sname
.find("_")+1:]
1742 exname
= exname
[:exname
.find("_")]
1743 for m
in ex
.members():
1744 for decl
in m
.declarators():
1745 self
.getCDR_hf(m
.memberType(), ex
.identifier() + "_" + decl
.identifier(),
1746 exname
+ "." + ex
.identifier() + "_" + decl
.identifier(), sname
+ "_" + decl
.identifier())
1748 def genUnion_hf(self
, un
):
1749 sname
= self
.namespace(un
, "_")
1750 unname
= sname
[:sname
.rfind("_")]
1751 unname
= unname
.replace("_", ".")
1753 print("//XXX genUnion_hf")
1754 print("// sname =", sname
)
1755 print("// uname =", unname
)
1757 self
.getCDR_hf(un
.switchType().unalias(), un
.identifier(),
1758 unname
+ "." + un
.identifier(), sname
+ "_" + un
.identifier(), sname
)
1760 for uc
in un
.cases(): # for all UnionCase objects in this union
1761 # TODO: is this loop necessary?
1762 for cl
in uc
.labels(): # for all Caselabel objects in this UnionCase
1763 self
.getCDR_hf(uc
.caseType(), un
.identifier() + "_" + uc
.declarator().identifier(),
1764 unname
+ "." + un
.identifier() + "." + uc
.declarator().identifier(),
1765 sname
+ "_" + uc
.declarator().identifier())
1767 def gen_proto_register(self
, oplist
, atlist
, stlist
, unlist
):
1768 """generate proto_register_<protoname> code,
1770 in - oplist[], atlist[], stline[], unlist[]
1773 self
.st
.out(self
.template_proto_register_start
, dissector_name
=self
.dissname
)
1775 # operation specific filters
1776 self
.st
.out(self
.template_proto_register_op_filter_comment
)
1781 self
.st
.out(self
.template_proto_register_at_filter_comment
)
1786 self
.st
.out(self
.template_proto_register_st_filter_comment
)
1788 if st
.members(): # only if has members
1791 # exception List filters
1792 exlist
= self
.get_exceptionList(oplist
) # grab list of exception nodes
1793 self
.st
.out(self
.template_proto_register_ex_filter_comment
)
1795 if ex
.members(): # only if has members
1799 self
.st
.out(self
.template_proto_register_un_filter_comment
)
1801 self
.genUnion_hf(un
)
1803 self
.st
.out(self
.template_proto_register_end
, description
=self
.description
,
1804 protocol_name
=self
.protoname
, dissector_name
=self
.dissname
)
1807 def get_intlist(oplist
):
1810 out - a list of unique interface names. This will be used in
1811 register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1812 name must be removed from the scope. And we also only want unique interfaces.
1815 int_hash
= {} # holds a hash of unique interfaces
1817 sc
= op
.scopedName() # eg: penguin,tux,bite
1819 sn
= idlutil
.slashName(sc1
) # penguin/tux
1820 if sn
not in int_hash
:
1821 int_hash
[sn
] = 0 # dummy val, but at least key is unique
1822 ret
= list(int_hash
.keys())
1826 def get_exceptionList(self
, oplist
):
1829 out - a list of exception nodes (unique). This will be used in
1830 to generate dissect_exception_XXX functions.
1833 ex_hash
= collections
.OrderedDict() # holds a hash of unique exceptions.
1835 for ex
in op
.raises():
1836 if ex
not in ex_hash
:
1837 ex_hash
[ex
] = 0 # dummy val, but at least key is unique
1839 print("//XXX Exception = " + ex
.identifier())
1840 ret
= list(ex_hash
.keys())
1844 def get_indices_from_sizes(sizelist
):
1845 """Simple function to take a list of array sizes and find the total number of elements
1848 eg: temp[4][3] = 12 elements
1858 def dig_to_len(dignum
):
1859 """Determine how many octets contain requested number
1860 of digits for an "fixed" IDL type "on the wire" """
1861 return (dignum
/2) + 1
1863 def genTODO(self
, message
):
1864 self
.st
.out(self
.template_debug_TODO
, message
=message
)
1866 def genWARNING(self
, message
):
1867 self
.st
.out(self
.template_debug_WARNING
, message
=message
)
1870 # Templates for C code
1872 template_helper_function_comment
= """\
1876 template_helper_function_vars_start
= """\
1877 /* Operation specific Variable declarations Begin */"""
1879 template_helper_function_vars_end
= """\
1880 /* Operation specific Variable declarations End */
1882 template_helper_function_vars_end_item
= """\
1883 /* Operation specific Variable declarations End */
1886 template_helper_function_start
= """\
1888 decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const char *operation _U_, bool stream_is_big_endian _U_)
1891 template_helper_function_end
= """\
1895 template_proto_reg_handoff_start
= """\
1896 /* register me as handler for these interfaces */
1897 void proto_reg_handoff_giop_@dissector_name@(void)
1900 template_proto_reg_handoff_body
= """\
1901 /* Register for Explicit Dissection */
1902 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
1905 template_proto_reg_handoff_heuristic
= """\
1906 /* Register for Heuristic Dissection */
1907 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
1910 template_proto_reg_handoff_end
= """\
1914 template_prototype
= """
1915 void proto_register_giop_@dissector_name@(void);
1916 void proto_reg_handoff_giop_@dissector_name@(void);"""
1918 # Initialize the protocol
1920 # template_protocol = """
1921 #/* Initialise the protocol and subtree pointers */
1922 #static int proto_@dissector_name@;
1923 #static int ett_@dissector_name@;
1925 template_protocol
= """
1926 /* Initialise the protocol and subtree pointers */
1927 static int proto_@dissector_name@;
1928 static int ett_@dissector_name@;
1929 static int ett_giop_struct;
1930 static int ett_giop_sequence;
1931 static int ett_giop_array;
1932 static int ett_giop_union;
1935 template_init_boundary
= """
1936 /* Initialise the initial Alignment */
1937 static uint32_t boundary = GIOP_HEADER_SIZE; /* initial value */"""
1939 # plugin_register and plugin_reg_handoff templates
1941 template_plugin_register
= """
1944 WS_DLL_PUBLIC_DEF void
1945 plugin_register(void)
1947 if (proto_@dissector_name@ <= 0) {
1948 proto_register_giop_@dissector_name@();
1952 WS_DLL_PUBLIC_DEF void
1953 plugin_reg_handoff(void){
1954 proto_register_handoff_giop_@dissector_name@();
1959 template_proto_register_start
= """
1960 /* Register the protocol with Wireshark */
1961 void proto_register_giop_@dissector_name@(void)
1963 /* setup list of header fields */
1964 static hf_register_info hf[] = {
1965 /* field that indicates the currently ongoing request/reply exchange */
1966 {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
1968 template_proto_register_end
= """
1971 static ei_register_info ei[] = {
1972 { &ei_@dissector_name@_unknown_giop_msg, { "giop-@dissector_name@.unknown_giop_msg", PI_PROTOCOL, PI_WARN, "Unknown GIOP message", EXPFILL }},
1973 { &ei_@dissector_name@_unknown_exception, { "giop-@dissector_name@.unknown_exception", PI_PROTOCOL, PI_WARN, "Unknown exception", EXPFILL }},
1974 { &ei_@dissector_name@_unknown_reply_status, { "giop-@dissector_name@.unknown_reply_status", PI_PROTOCOL, PI_WARN, "Unknown reply status", EXPFILL }},
1977 /* setup protocol subtree array */
1979 static int *ett[] = {
1980 &ett_@dissector_name@,
1987 expert_module_t* expert_@dissector_name@;
1990 /* Register the protocol name and description */
1991 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"GIOP/@protocol_name@\", \"giop-@dissector_name@\" );
1992 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
1993 proto_register_subtree_array(ett, array_length(ett));
1995 expert_@dissector_name@ = expert_register_protocol(proto_@dissector_name@);
1996 expert_register_field_array(expert_@dissector_name@, ei, array_length(ei));
2000 template_proto_register_op_filter_comment
= """\
2001 /* Operation filters */"""
2003 template_proto_register_at_filter_comment
= """\
2004 /* Attribute filters */"""
2006 template_proto_register_st_filter_comment
= """\
2007 /* Struct filters */"""
2009 template_proto_register_ex_filter_comment
= """\
2010 /* User exception filters */"""
2012 template_proto_register_un_filter_comment
= """\
2013 /* Union filters */"""
2015 template_proto_register_ei_filters
= """\
2016 /* Expert info filters */
2017 static expert_field ei_@dissector_name@_unknown_giop_msg;
2018 static expert_field ei_@dissector_name@_unknown_exception;
2019 static expert_field ei_@dissector_name@_unknown_reply_status;
2022 # template for delegation code
2024 template_op_delegate_code
= """\
2025 if (strcmp(operation, "@opname@") == 0
2026 && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
2027 item = process_RequestOperation(tvb, pinfo, ptree, header, operation); /* fill-up Request_Operation field & info column */
2028 tree = start_dissecting(tvb, pinfo, ptree, offset);
2029 decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
2033 template_no_ops_to_delegate
= """\
2034 // NOTE: this should only appear if your IDL has absolutely no operations
2039 # Templates for the helper functions
2041 template_helper_switch_msgtype_start
= """\
2042 switch(header->message_type) {"""
2044 template_helper_switch_msgtype_default_start
= """\
2046 /* Unknown GIOP Message */
2047 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2049 template_helper_switch_msgtype_default_end
= """\
2052 template_helper_switch_msgtype_end
= """\
2053 } /* switch(header->message_type) */"""
2055 template_helper_switch_msgtype_request_start
= """\
2058 template_helper_switch_msgtype_request_end
= """\
2061 template_helper_switch_msgtype_reply_start
= """\
2064 template_helper_switch_msgtype_reply_no_exception_start
= """\
2065 case NO_EXCEPTION:"""
2067 template_helper_switch_msgtype_reply_no_exception_end
= """\
2070 template_helper_switch_msgtype_reply_user_exception_start
= """\
2071 case USER_EXCEPTION:"""
2073 template_helper_switch_msgtype_reply_user_exception_end
= """\
2076 template_helper_switch_msgtype_reply_default_start
= """\
2078 /* Unknown Exception */
2079 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_exception, "Unknown exception %d", header->rep_status);"""
2081 template_helper_switch_msgtype_reply_default_end
= """\
2084 template_helper_switch_msgtype_reply_end
= """\
2087 template_helper_switch_rep_status_start
= """\
2088 switch(header->rep_status) {"""
2090 template_helper_switch_rep_status_default_start
= """\
2092 /* Unknown Reply Status */
2093 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_reply_status, "Unknown reply status %d", header->rep_status);"""
2095 template_helper_switch_rep_status_default_end
= """\
2098 template_helper_switch_rep_status_end
= """\
2099 } /* switch(header->rep_status) */
2103 # Templates for get_CDR_xxx accessors
2105 template_get_CDR_ulong
= """\
2106 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
2108 template_get_CDR_short
= """\
2109 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
2111 template_get_CDR_void
= """\
2112 /* Function returns void */
2114 template_get_CDR_long
= """\
2115 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
2117 template_get_CDR_ushort
= """\
2118 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
2120 template_get_CDR_float
= """\
2121 proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
2123 template_get_CDR_double
= """\
2124 proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
2126 template_get_CDR_longlong
= """\
2127 proto_tree_add_int64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
2129 template_get_CDR_ulonglong
= """\
2130 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
2132 template_get_CDR_boolean
= """\
2133 proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
2135 template_get_CDR_char
= """\
2136 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
2138 template_get_CDR_octet
= """\
2139 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
2141 template_get_CDR_any
= """\
2142 get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
2144 template_get_CDR_fixed
= """\
2145 get_CDR_fixed(tvb, pinfo, item, &seq, offset, @digits@, @scale@);
2146 proto_tree_add_string_format_value(tree, hf_@hfname@, tvb, *offset-@length@, @length@, seq, "< @digits@, @scale@> = %s", seq);
2148 template_get_CDR_enum_symbolic
= """\
2149 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2150 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
2152 template_get_CDR_string
= """\
2153 giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, hf_@hfname@);
2155 template_get_CDR_wstring
= """\
2156 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2157 proto_tree_add_string(tree, hf_@hfname@, tvb, *offset-u_octet4, u_octet4, (u_octet4 > 0) ? seq : \"\");
2159 template_get_CDR_wchar
= """\
2160 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2163 proto_tree_add_uint(tree, hf_@hfname@_len, tvb, *offset-1-s_octet1, 1, s_octet1);
2166 s_octet1 = -s_octet1;
2169 proto_tree_add_string(tree, hf_@hfname@, tvb, *offset-s_octet1, s_octet1, seq);
2172 template_get_CDR_TypeCode
= """\
2173 u_octet4 = get_CDR_typeCode(tvb, pinfo, tree, offset, stream_is_big_endian, boundary, header);
2176 template_get_CDR_object
= """\
2177 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2180 template_get_CDR_sequence_length
= """\
2181 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2182 proto_tree_add_uint(tree, hf_@seqname@_loop, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2184 template_get_CDR_sequence_length_item
= """\
2185 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2186 item = proto_tree_add_uint(tree, hf_@seqname@_loop, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2188 template_get_CDR_sequence_loop_start
= """\
2190 proto_tree *tree_bak_@nonce@ = tree;
2191 tree = proto_tree_add_subtree(tree, tvb, *offset, -1, ett_giop_sequence, NULL, "sequence @seqname@");
2192 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2194 template_get_CDR_sequence_loop_end
= """\
2196 tree = tree_bak_@nonce@;
2200 template_get_CDR_sequence_octet
= """\
2201 if (u_octet4_loop_@seqname@ > 0 && tree) {
2202 get_CDR_octet_seq(pinfo->pool, tvb, &binary_seq_@seqname@, offset,
2203 u_octet4_loop_@seqname@);
2204 text_seq_@seqname@ = make_printable_string(pinfo->pool, binary_seq_@seqname@,
2205 u_octet4_loop_@seqname@);
2206 proto_tree_add_bytes_format_value(tree, hf_@seqname@, tvb, *offset - u_octet4_loop_@seqname@,
2207 u_octet4_loop_@seqname@, binary_seq_@seqname@, \"%s\", text_seq_@seqname@);
2210 template_get_CDR_array_start
= """\
2212 proto_tree *tree_bak_@nonce@ = tree;
2213 tree = proto_tree_add_subtree(tree, tvb, *offset, -1, ett_giop_array, NULL, "array @aname@");
2214 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2216 template_get_CDR_array_end
= """\
2218 tree = tree_bak_@nonce@;
2221 template_get_CDR_array_comment
= """\
2222 /* Array: @aname@[ @asize@] */
2224 template_structure_start
= """\
2225 { /* Begin struct \"@name@\" */
2226 proto_tree *struct_tree = proto_tree_add_subtree(tree, tvb, *offset, -1, ett_giop_struct, NULL, "struct @name@");
2228 template_structure_end
= """\
2229 } /* End struct \"@name@\" */"""
2231 template_union_start
= """\
2232 { /* Begin union \"@name@\" */
2233 proto_tree *union_tree = proto_tree_add_subtree(tree, tvb, *offset, -1, ett_giop_union, NULL, "union @name@");
2235 template_union_end
= """\
2236 } /* End union \"@name@\" */"""
2238 # Templates for get_CDR_xxx_hf accessors
2240 template_get_CDR_ulong_hf
= """\
2241 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2243 template_get_CDR_ulong_symbolic_hf
= """\
2244 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2246 template_get_CDR_short_hf
= """\
2247 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2249 template_get_CDR_short_symbolic_hf
= """\
2250 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2252 template_get_CDR_long_hf
= """\
2253 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2255 template_get_CDR_long_symbolic_hf
= """\
2256 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2258 template_get_CDR_ushort_hf
= """\
2259 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2261 template_get_CDR_ushort_symbolic_hf
= """\
2262 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2264 template_get_CDR_float_hf
= """\
2265 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2267 template_get_CDR_double_hf
= """\
2268 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2270 template_get_CDR_fixed_hf
= """\
2271 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2273 template_get_CDR_longlong_hf
= """\
2274 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2276 template_get_CDR_longlong_symbolic_hf
= """\
2277 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2279 template_get_CDR_ulonglong_hf
= """\
2280 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2282 template_get_CDR_ulonglong_symbolic_hf
= """\
2283 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2285 template_get_CDR_boolean_hf
= """\
2286 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""
2288 template_get_CDR_char_hf
= """\
2289 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2291 template_get_CDR_char_symbolic_hf
= """\
2292 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2294 template_get_CDR_octet_hf
= """\
2295 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2297 template_get_CDR_enum_symbolic_hf
= """\
2298 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2300 template_get_CDR_string_hf
= """\
2301 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2303 template_get_CDR_wstring_hf
= """\
2304 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2306 template_get_CDR_wchar_hf
= """\
2307 {&hf_@hfname@_len, {"@descname@ Length","giop-@dissector_name@.@filtername@.len",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},
2308 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2310 template_get_CDR_TypeCode_hf
= """\
2311 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2313 template_get_CDR_sequence_hf
= """\
2314 {&hf_@hfname@_loop, {"Seq length of @descname@","giop-@dissector_name@.@filtername@.size",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2316 template_get_CDR_sequence_octet_hf
= """\
2317 {&hf_@hfname@_loop, {"Seq length of @descname@","giop-@dissector_name@.@filtername@.size",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},
2318 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BYTES,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2320 template_Header
= """\
2321 /* packet-@dissector_name@.c
2323 * Routines for IDL dissection
2325 * Autogenerated from idl2wrs
2326 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2331 template_wireshark_copyright
= """\
2333 * Wireshark - Network traffic analyzer
2334 * By Gerald Combs <gerald@@wireshark.org>
2335 * Copyright 1998 Gerald Combs
2341 * SPDX-License-Identifier: GPL-2.0-or-later
2345 template_Modelines
= """\
2347 * Editor modelines - https://www.wireshark.org/tools/modelines.html
2352 * indent-tabs-mode: nil
2355 * ex: set shiftwidth=4 tabstop=8 expandtab:
2356 * :indentSize=4:tabSize=8:noTabs=true:
2359 template_Includes
= """\
2364 #include <epan/packet.h>
2365 #include <epan/proto.h>
2366 #include "packet-giop.h"
2367 #include <epan/expert.h>
2368 #include <wsutil/array.h>
2370 #include "ws_diag_control.h"
2371 #include "ws_compiler_tests.h"
2374 /* disable warning: "unreference local variable" */
2375 #pragma warning(disable:4101)
2378 /* XXX this should be autogenerated, or the warnings fixed in the generator */
2379 DIAG_OFF(unused-function)
2380 DIAG_OFF(unused-variable)
2381 #if WS_IS_AT_LEAST_GNUC_VERSION(6,0)
2382 DIAG_OFF(unused-const-variable)
2385 template_main_dissector_start
= """\
2387 * Called once we accept the packet as being for us; it sets the
2388 * Protocol and Info columns and creates the top-level protocol
2392 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
2395 proto_item *ti = NULL;
2396 proto_tree *tree = NULL; /* init later, inside if(tree) */
2398 col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2401 * Do not clear COL_INFO, as nothing is being written there by
2402 * this dissector yet. So leave it as is from the GIOP dissector.
2403 * TODO: add something useful to COL_INFO
2404 * col_clear(pinfo->cinfo, COL_INFO);
2408 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, tvb_reported_length_remaining(tvb, *offset), ENC_NA);
2409 tree = proto_item_add_subtree(ti, ett_@dissname@);
2415 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const char *operation)
2418 if(header->message_type == Reply) {
2419 /* fill-up info column */
2420 col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
2422 /* fill-up the field */
2423 pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
2424 proto_item_set_generated(pi);
2429 dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const char *operation, char *idlname)
2431 proto_item *item _U_;
2432 proto_tree *tree _U_;
2433 bool stream_is_big_endian = is_big_endian(header); /* get endianess */
2435 /* If we have a USER Exception, then decode it and return */
2436 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2437 return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
2441 template_main_dissector_switch_msgtype_start
= """\
2442 switch(header->message_type) {
2444 template_main_dissector_switch_msgtype_start_request_reply
= """\
2448 template_main_dissector_switch_msgtype_end_request_reply
= """\
2451 template_main_dissector_switch_msgtype_all_other_msgtype
= """\
2455 case CloseConnection:
2458 return false; /* not handled yet */
2461 return false; /* not handled yet */
2465 template_main_dissector_end
= """\
2469 } /* End of main dissector */
2473 #-------------------------------------------------------------#
2474 # Exception handling templates #
2475 #-------------------------------------------------------------#
2477 template_exception_helpers_start
= """\
2478 /* Begin Exception Helper Functions */
2481 template_exception_helpers_end
= """\
2483 /* End Exception Helper Functions */
2486 template_main_exception_delegator_start
= """\
2488 * Main delegator for exception handling
2492 decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, const char *operation _U_, bool stream_is_big_endian _U_)
2494 proto_tree *tree _U_;
2496 if (!header->exception_id)
2500 template_ex_delegate_code
= """\
2501 if (strcmp(header->exception_id, "@exname@") == 0) {
2502 tree = start_dissecting(tvb, pinfo, ptree, offset);
2503 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian); /* @exname@ */
2508 template_main_exception_delegator_end
= """
2509 return false; /* user exception not found */
2513 template_exception_helper_function_start
= """\
2514 /* Exception = @exname@ */
2516 decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_)
2520 template_exception_helper_function_end
= """\
2524 template_struct_helper_function_start
= """\
2525 /* Struct = @stname@ */
2527 decode_@sname@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_)
2531 template_struct_helper_function_end
= """\
2535 template_union_helper_function_start
= """\
2536 /* Union = @unname@ */
2538 decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_)
2542 template_union_helper_function_start_with_item
= """\
2543 /* Union = @unname@ */
2545 decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_)
2547 proto_item* item = NULL;
2550 template_union_helper_function_end
= """\
2554 #-------------------------------------------------------------#
2555 # Value string templates #
2556 #-------------------------------------------------------------#
2558 template_value_string_start
= """\
2559 static const value_string @valstringname@[] = {
2561 template_value_string_entry
= """\
2562 { @intval@, \"@description@\" },"""
2564 template_value_string_end
= """\
2569 #-------------------------------------------------------------#
2570 # Enum handling templates #
2571 #-------------------------------------------------------------#
2573 template_comment_enums_start
= """\
2578 template_comment_enums_end
= """\
2583 template_comment_enum_comment
= """\
2588 #-------------------------------------------------------------#
2589 # Attribute handling templates #
2590 #-------------------------------------------------------------#
2592 template_comment_attributes_start
= """\
2594 * IDL Attributes Start
2598 # get/set accessor method names are language mapping dependent.
2600 template_attributes_declare_Java_get
= """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2601 template_attributes_declare_Java_set
= """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2603 template_comment_attributes_end
= """
2605 * IDL Attributes End
2610 # template for Attribute delegation code
2612 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2613 # Note: _set_xxx() should only be called for Request
2615 template_at_delegate_code_get
= """\
2616 if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2617 tree = start_dissecting(tvb, pinfo, ptree, offset);
2618 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2622 template_at_delegate_code_set
= """\
2623 if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
2624 tree = start_dissecting(tvb, pinfo, ptree, offset);
2625 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2629 template_attribute_helpers_start
= """\
2630 /* Begin Attribute Helper Functions */
2632 template_attribute_helpers_end
= """\
2634 /* End Attribute Helper Functions */
2637 template_attribute_helper_function_start
= """\
2639 /* Attribute = @atname@ */
2641 decode_@sname@_at(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_)
2645 template_attribute_helper_function_end
= """\
2649 #-------------------------------------------------------------#
2650 # Debugging templates #
2651 #-------------------------------------------------------------#
2653 # Template for outputting TODO "C" comments
2654 # so user know I need to improve something.
2656 template_debug_TODO
= """\
2658 /* TODO - @message@ */
2660 # Template for outputting WARNING "C" comments
2661 # so user know if I have found a problem.
2663 template_debug_WARNING
= """\
2664 /* WARNING - @message@ */
2667 #-------------------------------------------------------------#
2668 # IDL Union templates #
2669 #-------------------------------------------------------------#
2671 template_comment_union_code_start
= """\
2673 * IDL Union Start - @uname@
2676 template_comment_union_code_end
= """
2678 * IDL union End - @uname@
2681 template_comment_union_code_discriminant
= """\
2683 * IDL Union - Discriminant - @uname@
2687 # Cast Unions types to something appropriate
2688 # Enum value cast to uint32_t, all others cast to int32_t
2689 # as omniidl accessor returns integer or Enum.
2691 template_union_code_save_discriminant_enum
= """\
2692 disc_s_@discname@ = (int32_t) u_octet4; /* save Enum Value discriminant and cast to int32_t */
2694 template_union_code_save_discriminant_long
= """\
2695 *offset -= 4; // rewind
2696 disc_s_@discname@ = (int32_t) get_CDR_long(tvb,offset,stream_is_big_endian, boundary); /* save int32_t discriminant and cast to int32_t */
2699 template_union_code_save_discriminant_ulong
= """\
2700 *offset -= 4; // rewind
2701 disc_s_@discname@ = (int32_t) get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary); /* save uint32_t discriminant and cast to int32_t */
2703 template_union_code_save_discriminant_short
= """\
2704 *offset -= 2; // rewind
2705 disc_s_@discname@ = (int32_t) get_CDR_short(tvb,offset,stream_is_big_endian, boundary); /* save int16_t discriminant and cast to int32_t */
2708 template_union_code_save_discriminant_ushort
= """\
2709 *offset -= 2; // rewind
2710 disc_s_@discname@ = (int32_t) get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary); /* save int16_t discriminant and cast to int32_t */
2712 template_union_code_save_discriminant_char
= """\
2713 *offset -= 1; // rewind
2714 disc_s_@discname@ = (int32_t) get_CDR_char(tvb,offset); /* save uint8_t discriminant and cast to int32_t */
2716 template_union_code_save_discriminant_boolean
= """\
2717 *offset -= 1; // rewind
2718 disc_s_@discname@ = (int32_t) get_CDR_boolean(tvb, offset); /* save uint8_t discriminant and cast to int32_t */
2720 template_comment_union_code_label_compare_start
= """\
2721 if (disc_s_@discname@ == @labelval@) {
2723 template_comment_union_code_label_compare_end
= """\
2724 return; /* End Compare for this discriminant type */
2728 template_comment_union_code_label_default_start
= """
2729 /* Default Union Case Start */
2731 template_comment_union_code_label_default_end
= """\
2732 /* Default Union Case End */
2735 # Templates for function prototypes.
2736 # This is used in genDeclares() for declaring function prototypes
2737 # for structs and union helper functions.
2739 template_hf_operations
= """
2740 static int hf_operationrequest;/* Request_Operation field */
2744 static int hf_@name@;"""
2746 template_prototype_start_dissecting
= """
2747 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
2750 template_prototype_struct_start
= """\
2751 /* Struct prototype declaration Start */
2753 template_prototype_struct_end
= """\
2754 /* Struct prototype declaration End */
2756 template_prototype_struct_body
= """\
2757 /* Struct = @stname@ */
2758 static void decode_@name@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_);
2760 template_decode_struct
= """\
2761 decode_@name@_st(tvb, pinfo, struct_tree, item, offset, header, operation, stream_is_big_endian);"""
2763 template_prototype_union_start
= """\
2764 /* Union prototype declaration Start */"""
2766 template_prototype_union_end
= """\
2767 /* Union prototype declaration End */"""
2769 template_prototype_union_body
= """
2770 /* Union = @unname@ */
2771 static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const char *operation _U_, bool stream_is_big_endian _U_);
2773 template_decode_union
= """\
2774 decode_@name@_un(tvb, pinfo, union_tree, offset, header, operation, stream_is_big_endian);
2776 template_proto_item
= """\
2777 proto_item *item = wmem_new0(pinfo->pool, proto_item);
2781 # Editor modelines - https://www.wireshark.org/tools/modelines.html
2785 # indent-tabs-mode: nil
2788 # vi: set shiftwidth=4 expandtab:
2789 # :indentSize=4:noTabs=true: