5 # wireshark_gen.py (part of idl2wrs)
7 # Author : Frank Singleton (frank.singleton@ericsson.com)
9 # Copyright (C) 2001 Frank Singleton, Ericsson Inc.
11 # This file is a backend to "omniidl", used to generate "Wireshark"
12 # dissectors from CORBA IDL descriptions. The output language generated
13 # is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
15 # Please see packet-giop.h in Wireshark distro for API description.
16 # Wireshark is available at http://www.wireshark.org/
18 # Omniidl is part of the OmniOrb distribution, and is available at
19 # http://omniorb.sourceforge.net
21 # This program is free software; you can redistribute it and/or modify it
22 # under the terms of the GNU General Public License as published by
23 # the Free Software Foundation; either version 2 of the License, or
24 # (at your option) any later version.
26 # This program is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 # General Public License for more details.
31 # You should have received a copy of the GNU General Public License
32 # along with this program; if not, write to the Free Software
33 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
38 # Omniidl Back-end which parses an IDL list of "Operation" nodes
39 # passed from wireshark_be2.py and generates "C" code for compiling
40 # as a plugin for the Wireshark IP Protocol Analyser.
43 # Strategy (sneaky but ...)
45 # problem: I dont know what variables to declare until AFTER the helper functions
46 # have been built, so ...
48 # There are 2 passes through genHelpers, the first one is there just to
49 # make sure the fn_hash data struct is populated properly.
50 # The second pass is the real thing, generating code and declaring
51 # variables (from the 1st pass) properly.
55 """Wireshark IDL compiler back-end."""
57 from omniidl import idlast, idltype, idlutil, output
62 # Output class, generates "C" src code for the sub-dissector
69 # node - a reference to an Operations object.
70 # name - scoped name (Module::Module::Interface:: .. ::Operation
78 # 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved]
79 # 2. add item instead of add_text() [done]
80 # 3. sequence handling [done]
81 # 4. User Exceptions [done]
82 # 5. Fix arrays, and structs containing arrays [done]
84 # 7. Exception can be common to many operations, so handle them outside the
85 # operation helper functions [done]
86 # 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
87 # For example, mutlidimensional arrays.
88 # 9. wchar and wstring handling [giop API needs improving]
89 # 10. Support Fixed [done]
90 # 11. Support attributes (get/set) [started, needs language mapping option, perhaps wireshark GUI option
91 # to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
92 # eg: attribute string apple => _get_apple and _set_apple
94 # 12. Implement IDL "union" code [done]
95 # 13. Implement support for plugins [done]
96 # 14. Dont generate code for empty operations (cf: exceptions without members)
97 # 15. Generate code to display Enums numerically and symbolically [done]
98 # 16. Place structs/unions in subtrees
99 # 17. Recursive struct and union handling [done]
100 # 18. Improve variable naming for display (eg: structs, unions etc) [done]
102 # Also test, Test, TEST
109 # For every operation and attribute do
110 # For return val and all parameters do
111 # find basic IDL type for each parameter
113 # output exception handling code
114 # output attribute handling code
118 class wireshark_gen_C:
122 # Turn DEBUG stuff on/off
128 # Some string constants for our templates
130 c_u_octet8 = "guint64 u_octet8;"
131 c_s_octet8 = "gint64 s_octet8;"
132 c_u_octet4 = "guint32 u_octet4;"
133 c_s_octet4 = "gint32 s_octet4;"
134 c_u_octet2 = "guint16 u_octet2;"
135 c_s_octet2 = "gint16 s_octet2;"
136 c_u_octet1 = "guint8 u_octet1;"
137 c_s_octet1 = "gint8 s_octet1;"
139 c_float = "gfloat my_float;"
140 c_double = "gdouble my_double;"
142 c_seq = "gchar *seq = NULL;" # pointer to buffer of gchars
143 c_i = "guint32 i_"; # loop index
144 c_i_lim = "guint32 u_octet4_loop_"; # loop limit
145 c_u_disc = "guint32 disc_u_"; # unsigned int union discriminant variable name (enum)
146 c_s_disc = "gint32 disc_s_"; # signed int union discriminant variable name (other cases, except Enum)
152 def __init__(self, st, protocol_name, dissector_name ,description):
153 self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only
155 self.st_save = st # where 2nd pass should go
156 self.protoname = protocol_name # Protocol Name (eg: ECHO)
157 self.dissname = dissector_name # Dissector name (eg: echo)
158 self.description = description # Detailed Protocol description (eg: Echo IDL Example)
159 self.exlist = [] # list of exceptions used in operations.
160 #self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
161 self.fn_hash = {} # top level hash to contain key = function/exception and val = list of variable declarations
163 self.fn_hash_built = 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
164 # populated with operations/vars and exceptions/vars
170 # Main entry point, controls sequence of
175 def genCode(self,oplist, atlist, enlist, stlist, unlist): # operation,attribute,enums,struct and union lists
178 self.genHelpers(oplist,stlist,unlist) # sneaky .. call it now, to populate the fn_hash
179 # so when I come to that operation later, I have the variables to
182 self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
183 # so when I come to that exception later, I have the variables to
186 self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
187 # so when I come to that exception later, I have the variables to
191 self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
193 self.st = self.st_save
194 self.genHeader() # initial dissector comments
195 self.genEthCopyright() # Wireshark Copyright comments.
196 self.genGPL() # GPL license
199 self.genDeclares(oplist,atlist,enlist,stlist,unlist)
200 if (len(atlist) > 0):
201 self.genAtList(atlist) # string constant declares for Attributes
202 if (len(enlist) > 0):
203 self.genEnList(enlist) # string constant declares for Enums
206 self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
207 self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
208 if (len(atlist) > 0):
209 self.genAttributeHelpers(atlist) # helper function to decode "attributes"
211 self.genHelpers(oplist,stlist,unlist) # operation, struct and union decode helper functions
213 self.genMainEntryStart(oplist)
214 self.genOpDelegator(oplist)
215 self.genAtDelegator(atlist)
216 self.genMainEntryEnd()
218 self.gen_proto_register(oplist, atlist, stlist, unlist)
219 self.gen_proto_reg_handoff(oplist)
220 # All the dissectors are now built-in
221 #self.gen_plugin_register()
223 #self.dumpvars() # debug
230 # Generate Standard Wireshark Header Comments
235 self.st.out(self.template_Header,dissector_name=self.dissname)
237 print "XXX genHeader"
245 # Wireshark Copyright Info
249 def genEthCopyright(self):
251 print "XXX genEthCopyright"
252 self.st.out(self.template_wireshark_copyright)
266 self.st.out(self.template_GPL)
275 def genIncludes(self):
277 print "XXX genIncludes"
279 self.st.out(self.template_Includes)
284 # Generate hf variables for operation filters
286 # in: opnode ( an operation node)
289 def genOpDeclares(self, op):
291 print "XXX genOpDeclares"
292 print "XXX return type = " , op.returnType().kind()
294 sname = self.namespace(op, "_")
297 if (rt.kind() != idltype.tk_void):
298 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
299 #self.get_CDR_alias(rt, rt.name() )
300 self.st.out(self.template_hf, name=sname + "_return")
302 self.st.out(self.template_hf, name=sname + "_return")
304 for p in op.parameters():
305 self.st.out(self.template_hf, name=sname + "_" + p.identifier())
310 # Generate hf variables for attributes
312 # in: at ( an attribute)
315 def genAtDeclares(self, at):
317 print "XXX genAtDeclares"
319 for decl in at.declarators():
320 sname = self.namespace(decl, "_")
322 self.st.out(self.template_hf, name="get" + "_" + sname + "_" + decl.identifier())
323 if not at.readonly():
324 self.st.out(self.template_hf, name="set" + "_" + sname + "_" + decl.identifier())
329 # Generate hf variables for structs
334 def genStDeclares(self, st):
336 print "XXX genStDeclares"
338 sname = self.namespace(st, "_")
340 for m in st.members():
341 for decl in m.declarators():
342 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
347 # Generate hf variables for user exception filters
349 # in: exnode ( an exception node)
352 def genExDeclares(self,ex):
354 print "XXX genExDeclares"
356 sname = self.namespace(ex, "_")
358 for m in ex.members():
359 for decl in m.declarators():
360 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
365 # Generate hf variables for union filters
370 def genUnionDeclares(self,un):
372 print "XXX genUnionDeclares"
374 sname = self.namespace(un, "_")
375 self.st.out(self.template_hf, name=sname + "_" + un.identifier())
377 for uc in un.cases(): # for all UnionCase objects in this union
378 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
379 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
384 # generate function prototypes if required
386 # Currently this is used for struct and union helper function declarations.
390 def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
392 print "XXX genDeclares"
394 # prototype for operation filters
395 self.st.out(self.template_hf_operations)
397 #operation specific filters
398 if (len(oplist) > 0):
399 self.st.out(self.template_proto_register_op_filter_comment)
401 self.genOpDeclares(op)
404 if (len(atlist) > 0):
405 self.st.out(self.template_proto_register_at_filter_comment)
407 self.genAtDeclares(at)
410 if (len(stlist) > 0):
411 self.st.out(self.template_proto_register_st_filter_comment)
413 self.genStDeclares(st)
415 # exception List filters
416 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
417 if (len(exlist) > 0):
418 self.st.out(self.template_proto_register_ex_filter_comment)
420 if (ex.members()): # only if has members
421 self.genExDeclares(ex)
424 if (len(unlist) > 0):
425 self.st.out(self.template_proto_register_un_filter_comment)
427 self.genUnionDeclares(un)
429 # prototype for start_dissecting()
431 self.st.out(self.template_prototype_start_dissecting)
436 self.st.out(self.template_prototype_struct_start)
439 sname = self.namespace(st, "_")
440 self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
442 self.st.out(self.template_prototype_struct_end)
446 self.st.out(self.template_prototype_union_start)
448 sname = self.namespace(un, "_")
449 self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
450 self.st.out(self.template_prototype_union_end)
458 def genProtocol(self):
459 self.st.out(self.template_protocol, dissector_name=self.dissname)
460 self.st.out(self.template_init_boundary)
466 def genMainEntryStart(self,oplist):
467 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
469 self.st.out(self.template_main_dissector_switch_msgtype_start)
470 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
478 def genMainEntryEnd(self):
480 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
482 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
484 self.st.out(self.template_main_dissector_end)
492 # out: C code for IDL attribute decalarations.
494 # NOTE: Mapping of attributes to operation(function) names is tricky.
496 # The actual accessor function names are language-mapping specific. The attribute name
497 # is subject to OMG IDL's name scoping rules; the accessor function names are
498 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
502 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
503 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
507 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
508 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
510 # TODO: Implement some language dependant templates to handle naming conventions
511 # language <=> attribute. for C, C++. Java etc
513 # OR, just add a runtime GUI option to select language binding for attributes -- FS
517 # ie: def genAtlist(self,atlist,language)
522 def genAtList(self,atlist):
523 self.st.out(self.template_comment_attributes_start)
526 for i in n.declarators(): #
527 sname = self.namespace(i, "_")
528 atname = i.identifier()
529 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
531 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
533 self.st.out(self.template_comment_attributes_end)
541 # out: C code for IDL Enum decalarations using "static const value_string" template
546 def genEnList(self,enlist):
548 self.st.out(self.template_comment_enums_start)
551 sname = self.namespace(enum, "_")
553 self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
554 self.st.out(self.template_value_string_start, valstringname=sname)
555 for enumerator in enum.enumerators():
556 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
559 #atname = n.identifier()
560 self.st.out(self.template_value_string_end, valstringname=sname)
562 self.st.out(self.template_comment_enums_end)
574 # genExceptionDelegator
578 # out: C code for User exception delegator
584 def genExceptionDelegator(self,oplist):
586 self.st.out(self.template_main_exception_delegator_start)
589 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
593 print "XXX Exception " , ex.repoId()
594 print "XXX Exception Identifier" , ex.identifier()
595 print "XXX Exception Scoped Name" , ex.scopedName()
597 if (ex.members()): # only if has members
598 sname = self.namespace(ex, "_")
600 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
603 self.st.out(self.template_main_exception_delegator_end)
607 # genAttribueHelpers()
609 # Generate private helper functions to decode Attributes.
613 # For readonly attribute - generate get_xxx()
614 # If NOT readonly attribute - also generate set_xxx()
617 def genAttributeHelpers(self,atlist):
619 print "XXX genAttributeHelpers: atlist = ", atlist
621 self.st.out(self.template_attribute_helpers_start)
623 for attrib in atlist:
624 for decl in attrib.declarators():
625 self.genAtHelper(attrib,decl,"get") # get accessor
626 if not attrib.readonly():
627 self.genAtHelper(attrib,decl,"set") # set accessor
629 self.st.out(self.template_attribute_helpers_end)
634 # Generate private helper functions to decode an attribute
636 # in: at - attribute node
637 # in: decl - declarator belonging to this attribute
638 # in: order - to generate a "get" or "set" helper
640 def genAtHelper(self,attrib,decl,order):
642 print "XXX genAtHelper"
644 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
645 self.curr_sname = sname # update current opnode/exnode scoped name
647 if not self.fn_hash_built:
648 self.fn_hash[sname] = [] # init empty list as val for this sname key
649 # but only if the fn_hash is not already built
651 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
654 if (len(self.fn_hash[sname]) > 0):
655 self.st.out(self.template_helper_function_vars_start)
656 self.dumpCvars(sname)
657 self.st.out(self.template_helper_function_vars_end )
659 self.getCDR(attrib.attrType(), sname + "_" + decl.identifier() )
662 self.st.out(self.template_attribute_helper_function_end)
667 # genExceptionHelpers()
669 # Generate private helper functions to decode Exceptions used
676 def genExceptionHelpers(self,oplist):
677 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
679 print "XXX genExceptionHelpers: exlist = ", exlist
681 self.st.out(self.template_exception_helpers_start)
683 if (ex.members()): # only if has members
684 #print "XXX Exception = " + ex.identifier()
687 self.st.out(self.template_exception_helpers_end)
693 # Generate private helper functions to decode User Exceptions
695 # in: exnode ( an exception node)
698 def genExHelper(self,ex):
700 print "XXX genExHelper"
702 sname = self.namespace(ex, "_")
703 self.curr_sname = sname # update current opnode/exnode scoped name
704 if not self.fn_hash_built:
705 self.fn_hash[sname] = [] # init empty list as val for this sname key
706 # but only if the fn_hash is not already built
708 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
711 if (len(self.fn_hash[sname]) > 0):
712 self.st.out(self.template_helper_function_vars_start)
713 self.dumpCvars(sname)
714 self.st.out(self.template_helper_function_vars_end )
716 for m in ex.members():
718 print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
720 for decl in m.declarators():
722 print "XXX genExhelper, d = ", decl
724 if decl.sizes(): # an array
725 indices = self.get_indices_from_sizes(decl.sizes())
726 string_indices = '%i ' % indices # convert int to string
727 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
728 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
729 self.addvar(self.c_i + decl.identifier() + ";")
732 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
735 self.st.out(self.template_get_CDR_array_end)
739 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
742 self.st.out(self.template_exception_helper_function_end)
748 # Generate private helper functions for each IDL operation.
749 # Generate private helper functions for each IDL struct.
750 # Generate private helper functions for each IDL union.
753 # in: oplist, stlist, unlist
757 def genHelpers(self,oplist,stlist,unlist):
759 self.genOperation(op)
761 self.genStructHelper(st)
763 self.genUnionHelper(un)
768 # Generate private helper functions for a specificIDL operation.
773 def genOperation(self,opnode):
775 print "XXX genOperation called"
777 sname = self.namespace(opnode, "_")
778 if not self.fn_hash_built:
779 self.fn_hash[sname] = [] # init empty list as val for this sname key
780 # but only if the fn_hash is not already built
782 self.curr_sname = sname # update current opnode's scoped name
783 opname = opnode.identifier()
785 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
787 self.st.out(self.template_helper_function_start, sname=sname)
790 if (len(self.fn_hash[sname]) > 0):
791 self.st.out(self.template_helper_function_vars_start)
792 self.dumpCvars(sname)
793 self.st.out(self.template_helper_function_vars_end )
795 self.st.out(self.template_helper_switch_msgtype_start)
797 self.st.out(self.template_helper_switch_msgtype_request_start)
799 self.genOperationRequest(opnode)
800 self.st.out(self.template_helper_switch_msgtype_request_end)
803 self.st.out(self.template_helper_switch_msgtype_reply_start)
806 self.st.out(self.template_helper_switch_rep_status_start)
809 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
811 self.genOperationReply(opnode)
812 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
815 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
817 self.genOpExceptions(opnode)
818 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
821 self.st.out(self.template_helper_switch_msgtype_reply_default_start)
822 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
824 self.st.out(self.template_helper_switch_rep_status_end)
828 self.st.out(self.template_helper_switch_msgtype_default_start)
829 self.st.out(self.template_helper_switch_msgtype_default_end)
831 self.st.out(self.template_helper_switch_msgtype_end)
835 self.st.out(self.template_helper_function_end, sname=sname)
841 # Decode function parameters for a GIOP request message
845 def genOperationRequest(self,opnode):
846 for p in opnode.parameters():
849 print "XXX parameter = " ,p
850 print "XXX parameter type = " ,p.paramType()
851 print "XXX parameter type kind = " ,p.paramType().kind()
853 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
857 # Decode function parameters for a GIOP reply message
861 def genOperationReply(self,opnode):
863 rt = opnode.returnType() # get return type
865 print "XXX genOperationReply"
866 print "XXX opnode = " , opnode
867 print "XXX return type = " , rt
868 print "XXX return type.unalias = " , rt.unalias()
869 print "XXX return type.kind() = " , rt.kind();
871 sname = self.namespace(opnode, "_")
873 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
874 #self.getCDR(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
875 self.get_CDR_alias(rt, sname + "_return" )
876 #self.get_CDR_alias(rt, rt.name() )
879 self.getCDR(rt, sname + "_return") # return value is NOT an alias
881 for p in opnode.parameters():
882 if p.is_out(): # out or inout
883 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
885 #self.st.dec_indent()
887 def genOpExceptions(self,opnode):
888 for ex in opnode.raises():
891 for m in ex.members():
893 #print m.memberType(), m.memberType().kind()
895 # Delegator for Operations
898 def genOpDelegator(self,oplist):
900 iname = "/".join(op.scopedName()[:-1])
901 opname = op.identifier()
902 sname = self.namespace(op, "_")
903 self.st.out(self.template_op_delegate_code, interface=iname, sname=sname, opname=opname)
906 # Delegator for Attributes
909 def genAtDelegator(self,atlist):
911 for i in a.declarators():
912 atname = i.identifier()
913 sname = self.namespace(i, "_")
914 self.st.out(self.template_at_delegate_code_get, sname=sname)
916 self.st.out(self.template_at_delegate_code_set, sname=sname)
920 # Add a variable declaration to the hash of list
923 def addvar(self, var):
924 if not ( var in self.fn_hash[self.curr_sname] ):
925 self.fn_hash[self.curr_sname].append(var)
928 # Print the variable declaration from the hash of list
933 for fn in self.fn_hash.keys():
935 for v in self.fn_hash[fn]:
938 # Print the "C" variable declaration from the hash of list
939 # for a given scoped operation name (eg: tux_penguin_eat)
943 def dumpCvars(self, sname):
944 for v in self.fn_hash[sname]:
949 # Given an enum node, and a enumerator node, return
950 # the enumerator's numerical value.
952 # eg: enum Color {red,green,blue} should return
956 def valFromEnum(self,enumNode, enumeratorNode):
958 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
959 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
961 if isinstance(enumeratorNode,idlast.Enumerator):
962 value = enumNode.enumerators().index(enumeratorNode)
991 ## tk_longdouble = 25
998 ## tk_abstract_interface = 32
1004 # This is the main "iterator" function. It takes a node, and tries to output
1005 # a get_CDR_XXX accessor method(s). It can call itself multiple times
1006 # if I find nested structures etc.
1009 def getCDR(self,type,name="fred"):
1011 pt = type.unalias().kind() # param CDR type
1012 pn = name # param name
1015 print "XXX getCDR: kind = " , pt
1016 print "XXX getCDR: name = " , pn
1018 if pt == idltype.tk_ulong:
1019 self.get_CDR_ulong(pn)
1020 elif pt == idltype.tk_longlong:
1021 self.get_CDR_longlong(pn)
1022 elif pt == idltype.tk_ulonglong:
1023 self.get_CDR_ulonglong(pn)
1024 elif pt == idltype.tk_void:
1025 self.get_CDR_void(pn)
1026 elif pt == idltype.tk_short:
1027 self.get_CDR_short(pn)
1028 elif pt == idltype.tk_long:
1029 self.get_CDR_long(pn)
1030 elif pt == idltype.tk_ushort:
1031 self.get_CDR_ushort(pn)
1032 elif pt == idltype.tk_float:
1033 self.get_CDR_float(pn)
1034 elif pt == idltype.tk_double:
1035 self.get_CDR_double(pn)
1036 elif pt == idltype.tk_fixed:
1037 self.get_CDR_fixed(type.unalias(),pn)
1038 elif pt == idltype.tk_boolean:
1039 self.get_CDR_boolean(pn)
1040 elif pt == idltype.tk_char:
1041 self.get_CDR_char(pn)
1042 elif pt == idltype.tk_octet:
1043 self.get_CDR_octet(pn)
1044 elif pt == idltype.tk_any:
1045 self.get_CDR_any(pn)
1046 elif pt == idltype.tk_string:
1047 self.get_CDR_string(pn)
1048 elif pt == idltype.tk_wstring:
1049 self.get_CDR_wstring(pn)
1050 elif pt == idltype.tk_wchar:
1051 self.get_CDR_wchar(pn)
1052 elif pt == idltype.tk_enum:
1054 self.get_CDR_enum(pn,type)
1055 #self.get_CDR_enum(pn)
1057 elif pt == idltype.tk_struct:
1058 self.get_CDR_struct(type,pn)
1059 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1060 self.get_CDR_TypeCode(pn)
1061 elif pt == idltype.tk_sequence:
1062 if type.unalias().seqType().kind() == idltype.tk_octet:
1063 self.get_CDR_sequence_octet(type,pn)
1065 self.get_CDR_sequence(type,pn)
1066 elif pt == idltype.tk_objref:
1067 self.get_CDR_objref(type,pn)
1068 elif pt == idltype.tk_array:
1069 pn = pn # Supported elsewhere
1070 elif pt == idltype.tk_union:
1071 self.get_CDR_union(type,pn)
1072 elif pt == idltype.tk_alias:
1074 print "XXXXX Alias type XXXXX " , type
1075 self.get_CDR_alias(type,pn)
1077 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1081 # get_CDR_XXX methods are here ..
1086 def get_CDR_ulong(self,pn):
1087 self.st.out(self.template_get_CDR_ulong, hfname=pn)
1089 def get_CDR_short(self,pn):
1090 self.st.out(self.template_get_CDR_short, hfname=pn)
1092 def get_CDR_void(self,pn):
1093 self.st.out(self.template_get_CDR_void, hfname=pn)
1095 def get_CDR_long(self,pn):
1096 self.st.out(self.template_get_CDR_long, hfname=pn)
1098 def get_CDR_ushort(self,pn):
1099 self.st.out(self.template_get_CDR_ushort, hfname=pn)
1101 def get_CDR_float(self,pn):
1102 self.st.out(self.template_get_CDR_float, hfname=pn)
1104 def get_CDR_double(self,pn):
1105 self.st.out(self.template_get_CDR_double, hfname=pn)
1107 def get_CDR_longlong(self,pn):
1108 self.st.out(self.template_get_CDR_longlong, hfname=pn)
1110 def get_CDR_ulonglong(self,pn):
1111 self.st.out(self.template_get_CDR_ulonglong, hfname=pn)
1113 def get_CDR_boolean(self,pn):
1114 self.st.out(self.template_get_CDR_boolean, hfname=pn)
1116 def get_CDR_fixed(self,type,pn):
1118 print "XXXX calling get_CDR_fixed, type = ", type
1119 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1120 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1122 string_digits = '%i ' % type.digits() # convert int to string
1123 string_scale = '%i ' % type.scale() # convert int to string
1124 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
1126 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1127 self.addvar(self.c_seq)
1130 def get_CDR_char(self,pn):
1131 self.st.out(self.template_get_CDR_char, hfname=pn)
1133 def get_CDR_octet(self,pn):
1134 self.st.out(self.template_get_CDR_octet, hfname=pn)
1136 def get_CDR_any(self,pn):
1137 self.st.out(self.template_get_CDR_any, varname=pn)
1139 def get_CDR_enum(self,pn,type):
1140 #self.st.out(self.template_get_CDR_enum, hfname=pn)
1141 sname = self.namespace(type.unalias(), "_")
1142 self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname,hfname=pn)
1143 self.addvar(self.c_u_octet4)
1145 def get_CDR_string(self,pn):
1146 self.st.out(self.template_get_CDR_string, hfname=pn)
1148 def get_CDR_wstring(self,pn):
1149 self.st.out(self.template_get_CDR_wstring, varname=pn)
1150 self.addvar(self.c_u_octet4)
1151 self.addvar(self.c_seq)
1153 def get_CDR_wchar(self,pn):
1154 self.st.out(self.template_get_CDR_wchar, varname=pn)
1155 self.addvar(self.c_s_octet1)
1156 self.addvar(self.c_seq)
1158 def get_CDR_TypeCode(self,pn):
1159 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1160 self.addvar(self.c_u_octet4)
1162 def get_CDR_objref(self,type,pn):
1163 self.st.out(self.template_get_CDR_object)
1165 def get_CDR_sequence_len(self,pn):
1166 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1169 def get_CDR_union(self,type,pn):
1171 print "XXX Union type =" , type, " pn = ",pn
1172 print "XXX Union type.decl()" , type.decl()
1173 print "XXX Union Scoped Name" , type.scopedName()
1175 # If I am a typedef union {..}; node then find the union node
1177 if isinstance(type.decl(), idlast.Declarator):
1178 ntype = type.decl().alias().aliasType().decl()
1180 ntype = type.decl() # I am a union node
1183 print "XXX Union ntype =" , ntype
1185 sname = self.namespace(ntype, "_")
1186 self.st.out(self.template_union_start, name=sname )
1188 # Output a call to the union helper function so I can handle recursive union also.
1190 self.st.out(self.template_decode_union,name=sname)
1192 self.st.out(self.template_union_end, name=sname )
1197 # This takes a node, and tries to output the appropriate item for the
1201 def getCDR_hf(self,type,desc,filter,hf_name="fred"):
1203 pt = type.unalias().kind() # param CDR type
1204 pn = hf_name # param name
1207 print "XXX getCDR_hf: kind = " , pt
1208 print "XXX getCDR_hf: name = " , pn
1210 if pt == idltype.tk_ulong:
1211 self.get_CDR_ulong_hf(pn, desc, filter, self.dissname)
1212 elif pt == idltype.tk_longlong:
1213 self.get_CDR_longlong_hf(pn, desc, filter, self.dissname)
1214 elif pt == idltype.tk_ulonglong:
1215 self.get_CDR_ulonglong_hf(pn, desc, filter, self.dissname)
1216 elif pt == idltype.tk_void:
1217 pt = pt # no hf_ variables needed
1218 elif pt == idltype.tk_short:
1219 self.get_CDR_short_hf(pn, desc, filter, self.dissname)
1220 elif pt == idltype.tk_long:
1221 self.get_CDR_long_hf(pn, desc, filter, self.dissname)
1222 elif pt == idltype.tk_ushort:
1223 self.get_CDR_ushort_hf(pn, desc, filter, self.dissname)
1224 elif pt == idltype.tk_float:
1225 self.get_CDR_float_hf(pn, desc, filter, self.dissname)
1226 elif pt == idltype.tk_double:
1227 self.get_CDR_double_hf(pn, desc, filter, self.dissname)
1228 elif pt == idltype.tk_fixed:
1229 pt = pt # no hf_ variables needed
1230 elif pt == idltype.tk_boolean:
1231 self.get_CDR_boolean_hf(pn, desc, filter, self.dissname)
1232 elif pt == idltype.tk_char:
1233 self.get_CDR_char_hf(pn, desc, filter, self.dissname)
1234 elif pt == idltype.tk_octet:
1235 self.get_CDR_octet_hf(pn, desc, filter, self.dissname)
1236 elif pt == idltype.tk_any:
1237 pt = pt # no hf_ variables needed
1238 elif pt == idltype.tk_string:
1239 self.get_CDR_string_hf(pn, desc, filter, self.dissname)
1240 elif pt == idltype.tk_wstring:
1241 self.get_CDR_wstring_hf(pn, desc, filter, self.dissname)
1242 elif pt == idltype.tk_wchar:
1243 self.get_CDR_wchar_hf(pn, desc, filter, self.dissname)
1244 elif pt == idltype.tk_enum:
1245 self.get_CDR_enum_hf(pn, type, desc, filter, self.dissname)
1246 elif pt == idltype.tk_struct:
1247 pt = pt # no hf_ variables needed (should be already contained in struct members)
1248 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1249 self.get_CDR_TypeCode_hf(pn, desc, filter, self.dissname)
1250 elif pt == idltype.tk_sequence:
1251 if type.unalias().seqType().kind() == idltype.tk_octet:
1252 self.get_CDR_sequence_octet_hf(type, pn, desc, filter, self.dissname)
1254 self.get_CDR_sequence_hf(type, pn, desc, filter, self.dissname)
1255 elif pt == idltype.tk_objref:
1256 pt = pt # no object specific hf_ variables used, use generic ones from giop dissector
1257 elif pt == idltype.tk_array:
1258 pt = pt # Supported elsewhere
1259 elif pt == idltype.tk_union:
1260 pt = pt # no hf_ variables needed (should be already contained in union members)
1261 elif pt == idltype.tk_alias:
1263 print "XXXXX Alias type hf XXXXX " , type
1264 self.get_CDR_alias_hf(type,pn)
1266 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1269 # get_CDR_XXX_hf methods are here ..
1274 def get_CDR_ulong_hf(self,pn,desc,filter,diss):
1275 self.st.out(self.template_get_CDR_ulong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1277 def get_CDR_short_hf(self,pn,desc,filter,diss):
1278 self.st.out(self.template_get_CDR_short_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1280 def get_CDR_long_hf(self,pn,desc,filter,diss):
1281 self.st.out(self.template_get_CDR_long_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1283 def get_CDR_ushort_hf(self,pn,desc,filter,diss):
1284 self.st.out(self.template_get_CDR_ushort_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1286 def get_CDR_float_hf(self,pn,desc,filter,diss):
1287 self.st.out(self.template_get_CDR_float_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1289 def get_CDR_double_hf(self,pn,desc,filter,diss):
1290 self.st.out(self.template_get_CDR_double_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1292 def get_CDR_longlong_hf(self,pn,desc,filter,diss):
1293 self.st.out(self.template_get_CDR_longlong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1295 def get_CDR_ulonglong_hf(self,pn,desc,filter,diss):
1296 self.st.out(self.template_get_CDR_ulonglong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1298 def get_CDR_boolean_hf(self,pn,desc,filter,diss):
1299 self.st.out(self.template_get_CDR_boolean_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1301 def get_CDR_char_hf(self,pn,desc,filter,diss):
1302 self.st.out(self.template_get_CDR_char_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1304 def get_CDR_octet_hf(self,pn,desc,filter,diss):
1305 self.st.out(self.template_get_CDR_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1307 def get_CDR_enum_hf(self,pn,type,desc,filter,diss):
1308 sname = self.namespace(type.unalias(), "_")
1309 self.st.out(self.template_get_CDR_enum_symbolic_hf, valstringarray=sname,hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1311 def get_CDR_string_hf(self,pn,desc,filter,diss):
1312 self.st.out(self.template_get_CDR_string_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1314 def get_CDR_wstring_hf(self,pn,desc,filter,diss):
1315 self.st.out(self.template_get_CDR_wstring_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1316 # self.addvar(self.c_u_octet4)
1317 # self.addvar(self.c_seq)
1319 def get_CDR_wchar_hf(self,pn,desc,filter,diss):
1320 self.st.out(self.template_get_CDR_wchar_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1321 # self.addvar(self.c_s_octet1)
1322 # self.addvar(self.c_seq)
1324 def get_CDR_TypeCode_hf(self,pn,desc,filter,diss):
1325 self.st.out(self.template_get_CDR_TypeCode_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1327 def get_CDR_sequence_octet_hf(self,type,pn,desc,filter,diss):
1328 self.st.out(self.template_get_CDR_sequence_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1330 def get_CDR_sequence_hf(self,type,pn,desc,filter,diss):
1331 self.st.out(self.template_get_CDR_sequence_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1333 def get_CDR_alias_hf(self,type,pn):
1335 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1336 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1337 print "XXX get_CDR_alias_hf, type.decl().alias() = " ,type.decl().alias()
1339 decl = type.decl() # get declarator object
1341 if (decl.sizes()): # a typedef array
1342 #indices = self.get_indices_from_sizes(decl.sizes())
1343 #string_indices = '%i ' % indices # convert int to string
1344 #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1346 #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1347 #self.addvar(self.c_i + pn + ";")
1348 #self.st.inc_indent()
1349 self.getCDR_hf(type.decl().alias().aliasType(), pn )
1351 #self.st.dec_indent()
1352 #self.st.out(self.template_get_CDR_array_end)
1355 else: # a simple typdef
1357 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1358 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1360 self.getCDR_hf(type, decl.identifier() )
1364 # Code to generate Union Helper functions
1366 # in: un - a union node
1371 def genUnionHelper(self,un):
1373 print "XXX genUnionHelper called"
1374 print "XXX Union type =" , un
1375 print "XXX Union type.switchType()" , un.switchType()
1376 print "XXX Union Scoped Name" , un.scopedName()
1378 sname = self.namespace(un, "_")
1379 self.curr_sname = sname # update current opnode/exnode/stnode/unnode scoped name
1380 if not self.fn_hash_built:
1381 self.fn_hash[sname] = [] # init empty list as val for this sname key
1382 # but only if the fn_hash is not already built
1384 self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
1385 self.st.inc_indent()
1387 if (len(self.fn_hash[sname]) > 0):
1388 self.st.out(self.template_helper_function_vars_start)
1389 self.dumpCvars(sname)
1390 self.st.out(self.template_helper_function_vars_end )
1392 st = un.switchType().unalias() # may be typedef switch type, so find real type
1394 self.st.out(self.template_comment_union_code_start, uname=un.repoId() )
1396 self.getCDR(st, sname + "_" + un.identifier());
1398 # Depending on what kind of discriminant I come accross (enum,integer,char,
1399 # short, boolean), make sure I cast the return value of the get_XXX accessor
1400 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1401 # return an integer, or an Enumerator object that is then converted to its
1402 # integer equivalent.
1405 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1408 if (st.kind() == idltype.tk_enum):
1410 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1411 self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
1412 self.addvar(self.c_s_disc + un.identifier() + ";")
1414 elif (st.kind() == idltype.tk_long):
1415 self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
1416 self.addvar(self.c_s_disc + un.identifier() + ";")
1418 elif (st.kind() == idltype.tk_ulong):
1419 self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
1420 self.addvar(self.c_s_disc + un.identifier() + ";")
1422 elif (st.kind() == idltype.tk_short):
1423 self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
1424 self.addvar(self.c_s_disc + un.identifier() + ";")
1426 elif (st.kind() == idltype.tk_ushort):
1427 self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
1428 self.addvar(self.c_s_disc + un.identifier() + ";")
1430 elif (st.kind() == idltype.tk_boolean):
1431 self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier() )
1432 self.addvar(self.c_s_disc + un.identifier() + ";")
1434 elif (st.kind() == idltype.tk_char):
1435 self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
1436 self.addvar(self.c_s_disc + un.identifier() + ";")
1439 print "XXX Unknown st.kind() = ", st.kind()
1442 # Loop over all cases in this union
1445 for uc in un.cases(): # for all UnionCase objects in this union
1446 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1448 # get integer value, even if discriminant is
1449 # an Enumerator node
1451 if isinstance(cl.value(),idlast.Enumerator):
1453 print "XXX clv.identifier()", cl.value().identifier()
1454 print "XXX clv.repoId()", cl.value().repoId()
1455 print "XXX clv.scopedName()", cl.value().scopedName()
1457 # find index of enumerator in enum declaration
1458 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1460 clv = self.valFromEnum(std,cl.value())
1465 #print "XXX clv = ",clv
1468 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1469 # eg: if (disc == 'b')..
1471 # TODO : handle \xxx chars generically from a function or table lookup rather than
1472 # a whole bunch of "if" statements. -- FS
1475 if (st.kind() == idltype.tk_char):
1476 if (clv == '\n'): # newline
1477 string_clv = "'\\n'"
1478 elif (clv == '\t'): # tab
1479 string_clv = "'\\t'"
1481 string_clv = "'" + clv + "'"
1483 string_clv = '%i ' % clv
1486 # If default case, then skp comparison with discriminator
1489 if not cl.default():
1490 self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
1491 self.st.inc_indent()
1493 self.st.out(self.template_comment_union_code_label_default_start )
1496 self.getCDR(uc.caseType(),sname + "_" + uc.declarator().identifier())
1498 if not cl.default():
1499 self.st.dec_indent()
1500 self.st.out(self.template_comment_union_code_label_compare_end )
1502 self.st.out(self.template_comment_union_code_label_default_end )
1504 self.st.dec_indent()
1505 self.st.out(self.template_union_helper_function_end)
1510 # Currently, get_CDR_alias is geared to finding typdef
1513 def get_CDR_alias(self,type,pn):
1515 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1516 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1517 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1519 decl = type.decl() # get declarator object
1521 if (decl.sizes()): # a typedef array
1522 indices = self.get_indices_from_sizes(decl.sizes())
1523 string_indices = '%i ' % indices # convert int to string
1524 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1526 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1527 self.addvar(self.c_i + pn + ";")
1528 self.st.inc_indent()
1529 self.getCDR(type.decl().alias().aliasType(), pn )
1531 self.st.dec_indent()
1532 self.st.out(self.template_get_CDR_array_end)
1535 else: # a simple typdef
1537 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1538 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1540 self.getCDR(type, pn )
1548 # Handle structs, including recursive
1551 def get_CDR_struct(self,type,pn):
1553 # If I am a typedef struct {..}; node then find the struct node
1555 if isinstance(type.decl(), idlast.Declarator):
1556 ntype = type.decl().alias().aliasType().decl()
1558 ntype = type.decl() # I am a struct node
1560 sname = self.namespace(ntype, "_")
1561 self.st.out(self.template_structure_start, name=sname )
1563 # Output a call to the struct helper function so I can handle recursive structs also.
1565 self.st.out(self.template_decode_struct,name=sname)
1567 self.st.out(self.template_structure_end, name=sname )
1572 # Generate private helper functions to decode a struct
1574 # in: stnode ( a struct node)
1577 def genStructHelper(self,st):
1579 print "XXX genStructHelper"
1581 sname = self.namespace(st, "_")
1582 self.curr_sname = sname # update current opnode/exnode/stnode scoped name
1583 if not self.fn_hash_built:
1584 self.fn_hash[sname] = [] # init empty list as val for this sname key
1585 # but only if the fn_hash is not already built
1587 self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
1588 self.st.inc_indent()
1590 if (len(self.fn_hash[sname]) > 0):
1591 self.st.out(self.template_helper_function_vars_start)
1592 self.dumpCvars(sname)
1593 self.st.out(self.template_helper_function_vars_end )
1595 for m in st.members():
1596 for decl in m.declarators():
1597 if decl.sizes(): # an array
1598 indices = self.get_indices_from_sizes(decl.sizes())
1599 string_indices = '%i ' % indices # convert int to string
1600 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1601 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1602 self.addvar(self.c_i + decl.identifier() + ";")
1604 self.st.inc_indent()
1605 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1606 self.st.dec_indent()
1607 self.st.out(self.template_get_CDR_array_end)
1611 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1613 self.st.dec_indent()
1614 self.st.out(self.template_struct_helper_function_end)
1621 # Generate code to access a sequence of a type
1625 def get_CDR_sequence(self,type, pn):
1626 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1627 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1628 self.addvar(self.c_i_lim + pn + ";" )
1629 self.addvar(self.c_i + pn + ";")
1631 self.st.inc_indent()
1632 self.getCDR(type.unalias().seqType(), pn ) # and start all over with the type
1633 self.st.dec_indent()
1635 self.st.out(self.template_get_CDR_sequence_loop_end)
1639 # Generate code to access a sequence of octet
1642 def get_CDR_sequence_octet(self,type, pn):
1643 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1644 self.st.out(self.template_get_CDR_sequence_octet, seqname=pn)
1645 self.addvar(self.c_i_lim + pn + ";")
1646 self.addvar("gchar * binary_seq_" + pn + ";")
1647 self.addvar("gchar * text_seq_" + pn + ";")
1655 # out - scoped operation name, using sep character instead of "::"
1657 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1661 def namespace(self,node,sep):
1662 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1663 #print "XXX namespace: sname = " + sname
1668 # generate code for plugin initialisation
1671 def gen_plugin_register(self):
1672 self.st.out(self.template_plugin_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1675 # generate register_giop_user_module code, and register only
1676 # unique interfaces that contain operations. Also output
1677 # a heuristic register in case we want to use that.
1679 # TODO - make this a command line option
1687 def gen_proto_reg_handoff(self, oplist):
1689 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1690 self.st.inc_indent()
1692 for iname in self.get_intlist(oplist):
1693 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1695 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1696 self.st.dec_indent()
1698 self.st.out(self.template_proto_reg_handoff_end)
1701 # generate hf_ array element for operation, attribute, enums, struct and union lists
1704 def genOp_hf(self,op):
1705 sname = self.namespace(op, "_")
1706 opname = sname[string.find(sname, "_")+1:]
1707 opname = opname[:string.find(opname, "_")]
1708 rt = op.returnType()
1710 if (rt.kind() != idltype.tk_void):
1711 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
1712 self.getCDR_hf(rt, rt.name(),\
1713 opname + "." + op.identifier() + ".return", sname + "_return")
1715 self.getCDR_hf(rt, "Return value",\
1716 opname + "." + op.identifier() + ".return", sname + "_return")
1718 for p in op.parameters():
1719 self.getCDR_hf(p.paramType(), p.identifier(),\
1720 opname + "." + op.identifier() + "." + p.identifier(), sname + "_" + p.identifier())
1722 def genAt_hf(self,at):
1723 for decl in at.declarators():
1724 sname = self.namespace(decl, "_")
1725 atname = sname[string.find(sname, "_")+1:]
1726 atname = atname[:string.find(atname, "_")]
1728 self.getCDR_hf(at.attrType(), decl.identifier(),\
1729 atname + "." + decl.identifier() + ".get", "get" + "_" + sname + "_" + decl.identifier())
1730 if not at.readonly():
1731 self.getCDR_hf(at.attrType(), decl.identifier(),\
1732 atname + "." + decl.identifier() + ".set", "set" + "_" + sname + "_" + decl.identifier())
1734 def genSt_hf(self,st):
1735 sname = self.namespace(st, "_")
1736 stname = sname[string.find(sname, "_")+1:]
1737 stname = stname[:string.find(stname, "_")]
1738 for m in st.members():
1739 for decl in m.declarators():
1740 self.getCDR_hf(m.memberType(), st.identifier() + "_" + decl.identifier(),\
1741 st.identifier() + "." + decl.identifier(), sname + "_" + decl.identifier())
1743 def genEx_hf(self,ex):
1744 sname = self.namespace(ex, "_")
1745 exname = sname[string.find(sname, "_")+1:]
1746 exname = exname[:string.find(exname, "_")]
1747 for m in ex.members():
1748 for decl in m.declarators():
1749 self.getCDR_hf(m.memberType(), ex.identifier() + "_" + decl.identifier(),\
1750 exname + "." + ex.identifier() + "_" + decl.identifier(), sname + "_" + decl.identifier())
1752 def genUnion_hf(self,un):
1753 sname = self.namespace(un, "_")
1754 unname = sname[:string.rfind(sname, "_")]
1755 unname = string.replace(unname, "_", ".")
1757 self.getCDR_hf(un.switchType().unalias(), un.identifier(),\
1758 unname + "." + un.identifier(), sname + "_" + un.identifier())
1760 for uc in un.cases(): # for all UnionCase objects in this union
1761 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1762 self.getCDR_hf(uc.caseType(), un.identifier() + "_" + uc.declarator().identifier(),\
1763 unname + "." + un.identifier() + "." + uc.declarator().identifier(),\
1764 sname + "_" + uc.declarator().identifier())
1767 # generate proto_register_<protoname> code,
1769 # in - oplist[], atlist[], stline[], unlist[]
1773 def gen_proto_register(self, oplist, atlist, stlist, unlist):
1774 self.st.out(self.template_proto_register_start, dissector_name=self.dissname)
1776 #operation specific filters
1777 self.st.out(self.template_proto_register_op_filter_comment)
1782 self.st.out(self.template_proto_register_at_filter_comment)
1787 self.st.out(self.template_proto_register_st_filter_comment)
1789 if (st.members()): # only if has members
1792 # exception List filters
1793 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
1794 self.st.out(self.template_proto_register_ex_filter_comment)
1796 if (ex.members()): # only if has members
1800 self.st.out(self.template_proto_register_un_filter_comment)
1802 self.genUnion_hf(un)
1804 self.st.out(self.template_proto_register_end, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
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 def get_intlist(self,oplist):
1816 int_hash = {} # holds a hash of unique interfaces
1818 sc = op.scopedName() # eg: penguin,tux,bite
1819 sc1 = sc[:-1] # drop last entry
1820 sn = idlutil.slashName(sc1) # penguin/tux
1821 if not int_hash.has_key(sn):
1822 int_hash[sn] = 0; # dummy val, but at least key is unique
1823 ret = int_hash.keys()
1832 # out - a list of exception nodes (unique). This will be used in
1833 # to generate dissect_exception_XXX functions.
1838 def get_exceptionList(self,oplist):
1839 ex_hash = {} # holds a hash of unique exceptions.
1841 for ex in op.raises():
1842 if not ex_hash.has_key(ex):
1843 ex_hash[ex] = 0; # dummy val, but at least key is unique
1845 print "XXX Exception = " + ex.identifier()
1846 ret = ex_hash.keys()
1853 # Simple function to take a list of array sizes and find the
1854 # total number of elements
1857 # eg: temp[4][3] = 12 elements
1860 def get_indices_from_sizes(self,sizelist):
1868 # Determine how many octets contain requested number
1869 # of digits for an "fixed" IDL type "on the wire"
1872 def dig_to_len(self,dignum):
1873 return (dignum/2) + 1
1878 # Output some TODO comment
1882 def genTODO(self,message):
1883 self.st.out(self.template_debug_TODO, message=message)
1886 # Output some WARNING comment
1890 def genWARNING(self,message):
1891 self.st.out(self.template_debug_WARNING, message=message)
1894 # Templates for C code
1897 template_helper_function_comment = """\
1901 template_helper_function_vars_start = """\
1902 /* Operation specific Variable declarations Begin */"""
1904 template_helper_function_vars_end = """\
1905 /* Operation specific Variable declarations End */
1907 (void)item; /* Avoid coverity param_set_but_unused parse warning */
1910 template_helper_function_start = """\
1912 decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
1915 template_helper_function_end = """\
1919 # proto_reg_handoff() templates
1922 template_proto_reg_handoff_start = """\
1923 /* register me as handler for these interfaces */
1924 void proto_reg_handoff_giop_@dissector_name@(void)
1927 template_proto_reg_handoff_body = """
1928 /* Register for Explicit Dissection */
1929 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */"""
1931 template_proto_reg_handoff_heuristic = """
1932 /* Register for Heuristic Dissection */
1933 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */"""
1935 template_proto_reg_handoff_end = """\
1940 # Initialize the protocol
1943 template_protocol = """
1944 /* Initialise the protocol and subtree pointers */
1945 static int proto_@dissector_name@ = -1;
1946 static gint ett_@dissector_name@ = -1;
1949 # Initialize the boundary Alignment
1952 template_init_boundary = """
1953 /* Initialise the initial Alignment */
1954 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */"""
1957 # plugin_register and plugin_reg_handoff templates
1960 template_plugin_register = """
1963 WS_DLL_PUBLIC_NOEXTERN void
1964 plugin_register(void)
1966 if (proto_@dissector_name@ == -1) {
1967 proto_register_giop_@dissector_name@();
1971 WS_DLL_PUBLIC_NOEXTERN void
1972 plugin_reg_handoff(void){
1973 proto_register_handoff_giop_@dissector_name@();
1978 # proto_register_<dissector name>(void) templates
1981 template_proto_register_start = """
1982 /* Register the protocol with Wireshark */
1983 void proto_register_giop_@dissector_name@(void)
1985 /* setup list of header fields */
1986 static hf_register_info hf[] = {
1987 /* field that indicates the currently ongoing request/reply exchange */
1988 {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
1990 template_proto_register_end = """
1993 /* setup protocol subtree array */
1995 static gint *ett[] = {
1996 &ett_@dissector_name@,
1999 /* Register the protocol name and description */
2000 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
2001 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
2002 proto_register_subtree_array(ett,array_length(ett));
2006 template_proto_register_op_filter_comment = """\
2007 /* Operation filters */"""
2009 template_proto_register_at_filter_comment = """\
2010 /* Attribute filters */"""
2012 template_proto_register_st_filter_comment = """\
2013 /* Struct filters */"""
2015 template_proto_register_ex_filter_comment = """\
2016 /* User exception filters */"""
2018 template_proto_register_un_filter_comment = """\
2019 /* Union filters */"""
2023 # template for delegation code
2026 template_op_delegate_code = """\
2027 if (strcmp(operation, "@opname@") == 0
2028 && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
2029 item = process_RequestOperation(tvb, pinfo, ptree, header, operation); /* fill-up Request_Operation field & info column */
2030 tree = start_dissecting(tvb, pinfo, ptree, offset);
2031 decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
2036 # 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, PI_MALFORMED, PI_ERROR, "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, PI_MALFORMED, PI_ERROR, "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_msgtype_default_start = """\
2089 /* Unknown GIOP Message */
2090 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Unknown GIOP message %d", header->message_type);"""
2092 template_helper_switch_msgtype_default_end = """\
2095 template_helper_switch_rep_status_start = """\
2096 switch(header->rep_status) {"""
2098 template_helper_switch_rep_status_default_start = """\
2100 /* Unknown Reply Status */
2101 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Unknown reply status %d", header->rep_status);"""
2103 template_helper_switch_rep_status_default_end = """\
2106 template_helper_switch_rep_status_end = """\
2107 } /* switch(header->rep_status) */
2112 # Templates for get_CDR_xxx accessors
2115 template_get_CDR_ulong = """\
2116 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
2118 template_get_CDR_short = """\
2119 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
2121 template_get_CDR_void = """\
2122 /* Function returns void */
2124 template_get_CDR_long = """\
2125 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
2127 template_get_CDR_ushort = """\
2128 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
2130 template_get_CDR_float = """\
2131 proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
2133 template_get_CDR_double = """\
2134 proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
2136 template_get_CDR_longlong = """\
2137 proto_tree_add_int64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
2139 template_get_CDR_ulonglong = """\
2140 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
2142 template_get_CDR_boolean = """\
2143 proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
2145 template_get_CDR_char = """\
2146 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
2148 template_get_CDR_octet = """\
2149 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
2151 template_get_CDR_any = """\
2152 get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
2154 template_get_CDR_fixed = """\
2155 get_CDR_fixed(tvb, pinfo, item, &seq, offset, @digits@, @scale@);
2156 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
2158 template_get_CDR_enum_symbolic = """\
2159 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2160 /* coverity[returned_pointer] */
2161 item = proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
2163 template_get_CDR_string = """\
2164 giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, hf_@hfname@);
2166 template_get_CDR_wstring = """\
2167 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2168 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ (%u) = %s",
2169 u_octet4, (u_octet4 > 0) ? seq : \"\");
2171 template_get_CDR_wchar = """\
2172 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2175 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
2178 s_octet1 = -s_octet1;
2181 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
2184 template_get_CDR_TypeCode = """\
2185 u_octet4 = get_CDR_typeCode(tvb, pinfo, tree, offset, stream_is_big_endian, boundary, header);
2188 template_get_CDR_object = """\
2189 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2192 template_get_CDR_sequence_length = """\
2193 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2194 /* coverity[returned_pointer] */
2195 item = proto_tree_add_uint(tree, hf_@seqname@, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2197 template_get_CDR_sequence_loop_start = """\
2198 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2200 template_get_CDR_sequence_loop_end = """\
2204 template_get_CDR_sequence_octet = """\
2205 if (u_octet4_loop_@seqname@ > 0 && tree) {
2206 get_CDR_octet_seq(tvb, &binary_seq_@seqname@, offset,
2207 u_octet4_loop_@seqname@);
2208 text_seq_@seqname@ = make_printable_string(binary_seq_@seqname@,
2209 u_octet4_loop_@seqname@);
2210 proto_tree_add_text(tree, tvb, *offset - u_octet4_loop_@seqname@,
2211 u_octet4_loop_@seqname@, \"@seqname@: %s\", text_seq_@seqname@);
2214 template_get_CDR_array_start = """\
2215 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2217 template_get_CDR_array_end = """\
2220 template_get_CDR_array_comment = """\
2221 /* Array: @aname@[ @asize@] */
2223 template_structure_start = """\
2224 /* Begin struct \"@name@\" */"""
2226 template_structure_end = """\
2227 /* End struct \"@name@\" */"""
2229 template_union_start = """\
2230 /* Begin union \"@name@\" */"""
2232 template_union_end = """\
2233 /* End union \"@name@\" */"""
2236 # Templates for get_CDR_xxx_hf accessors
2239 template_get_CDR_ulong_hf = """\
2240 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2242 template_get_CDR_short_hf = """\
2243 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2245 template_get_CDR_long_hf = """\
2246 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2248 template_get_CDR_ushort_hf = """\
2249 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2251 template_get_CDR_float_hf = """\
2252 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2254 template_get_CDR_double_hf = """\
2255 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2257 template_get_CDR_longlong_hf = """\
2258 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2260 template_get_CDR_ulonglong_hf = """\
2261 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2263 template_get_CDR_boolean_hf = """\
2264 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""
2266 template_get_CDR_char_hf = """\
2267 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2269 template_get_CDR_octet_hf = """\
2270 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2272 template_get_CDR_enum_symbolic_hf = """\
2273 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2275 template_get_CDR_string_hf = """\
2276 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2278 template_get_CDR_wstring_hf = """\
2279 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2281 template_get_CDR_wchar_hf = """\
2282 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2284 template_get_CDR_TypeCode_hf = """\
2285 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2287 template_get_CDR_sequence_hf = """\
2288 {&hf_@hfname@, {"Seq length of @descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2290 template_get_CDR_sequence_octet_hf = """\
2291 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2294 # Program Header Template
2297 template_Header = """\
2298 /* packet-@dissector_name@.c
2302 * Routines for IDL dissection
2304 * Autogenerated from idl2wrs
2305 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2310 template_wireshark_copyright = """\
2312 * Wireshark - Network traffic analyzer
2314 * Copyright 1999 - 2012 Gerald Combs
2327 * This program is free software; you can redistribute it and/or
2328 * modify it under the terms of the GNU General Public License
2329 * as published by the Free Software Foundation; either version 2
2330 * of the License, or (at your option) any later version.
2332 * This program is distributed in the hope that it will be useful,
2333 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2334 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2335 * GNU General Public License for more details.
2337 * You should have received a copy of the GNU General Public License
2338 * along with this program; if not, write to the Free Software
2339 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2347 template_Includes = """\
2351 #include <gmodule.h>
2355 #include <epan/packet.h>
2356 #include <epan/proto.h>
2357 #include <epan/dissectors/packet-giop.h>
2358 #include <epan/expert.h>
2360 /* plugins are DLLs */
2361 #define WS_BUILD_DLL
2362 #include "ws_symbol_export.h"
2365 /* disable warning: "unreference local variable" */
2366 #pragma warning(disable:4101)
2372 # Main dissector entry templates
2375 template_main_dissector_start = """\
2377 * Called once we accept the packet as being for us; it sets the
2378 * Protocol and Info columns and creates the top-level protocol
2382 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
2385 proto_item *ti = NULL;
2386 proto_tree *tree = NULL; /* init later, inside if(tree) */
2388 col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2391 * Do not clear COL_INFO, as nothing is being written there by
2392 * this dissector yet. So leave it as is from the GIOP dissector.
2393 * TODO: add something useful to COL_INFO
2394 * col_clear(pinfo->cinfo, COL_INFO);
2398 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, -1, ENC_NA);
2399 tree = proto_item_add_subtree(ti, ett_@dissname@);
2405 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const gchar *operation)
2408 if(header->message_type == Reply) {
2409 /* fill-up info column */
2410 col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
2412 /* fill-up the field */
2413 pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
2414 PROTO_ITEM_SET_GENERATED(pi);
2419 dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const gchar *operation, gchar *idlname)
2421 proto_item *item _U_;
2422 proto_tree *tree _U_;
2423 gboolean stream_is_big_endian = is_big_endian(header); /* get endianess */
2425 /* If we have a USER Exception, then decode it and return */
2426 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2427 return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
2431 template_main_dissector_switch_msgtype_start = """\
2432 switch(header->message_type) {
2434 template_main_dissector_switch_msgtype_start_request_reply = """\
2438 template_main_dissector_switch_msgtype_end_request_reply = """\
2441 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2445 case CloseConnection:
2448 return FALSE; /* not handled yet */
2451 return FALSE; /* not handled yet */
2455 template_main_dissector_end = """\
2459 } /* End of main dissector */
2468 #-------------------------------------------------------------#
2469 # Exception handling templates #
2470 #-------------------------------------------------------------#
2478 template_exception_helpers_start = """\
2479 /* Begin Exception Helper Functions */
2482 template_exception_helpers_end = """\
2484 /* End Exception Helper Functions */
2490 # template for Main delegator for exception handling
2493 template_main_exception_delegator_start = """\
2495 * Main delegator for exception handling
2499 decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2501 proto_tree *tree _U_;
2503 if (!header->exception_id)
2509 # template for exception delegation code body
2511 template_ex_delegate_code = """\
2512 if (strcmp(header->exception_id, "@exname@") == 0) {
2513 tree = start_dissecting(tvb, pinfo, ptree, offset);
2514 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian); /* @exname@ */
2521 # End of Main delegator for exception handling
2524 template_main_exception_delegator_end = """
2525 return FALSE; /* user exception not found */
2530 # template for exception helper code
2534 template_exception_helper_function_start = """\
2535 /* Exception = @exname@ */
2537 decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2539 proto_item *item _U_;
2542 template_exception_helper_function_end = """\
2548 # template for struct helper code
2552 template_struct_helper_function_start = """\
2553 /* Struct = @stname@ */
2555 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 gchar *operation _U_, gboolean stream_is_big_endian _U_)
2559 template_struct_helper_function_end = """\
2564 # template for union helper code
2568 template_union_helper_function_start = """\
2569 /* Union = @unname@ */
2571 decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2573 proto_item* item _U_;
2576 template_union_helper_function_end = """\
2582 #-------------------------------------------------------------#
2583 # Value string templates #
2584 #-------------------------------------------------------------#
2586 template_value_string_start = """\
2587 static const value_string @valstringname@[] = {
2589 template_value_string_entry = """\
2590 { @intval@, \"@description@\" },"""
2592 template_value_string_end = """\
2599 #-------------------------------------------------------------#
2600 # Enum handling templates #
2601 #-------------------------------------------------------------#
2603 template_comment_enums_start = """\
2608 template_comment_enums_end = """\
2613 template_comment_enum_comment = """\
2620 #-------------------------------------------------------------#
2621 # Attribute handling templates #
2622 #-------------------------------------------------------------#
2625 template_comment_attributes_start = """\
2627 * IDL Attributes Start
2632 # get/set accessor method names are language mapping dependant.
2635 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2636 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2638 template_comment_attributes_end = """
2640 * IDL Attributes End
2646 # template for Attribute delegation code
2648 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2649 # Note: _set_xxx() should only be called for Request
2653 template_at_delegate_code_get = """\
2654 if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2655 tree = start_dissecting(tvb, pinfo, ptree, offset);
2656 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2660 template_at_delegate_code_set = """\
2661 if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
2662 tree = start_dissecting(tvb, pinfo, ptree, offset);
2663 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2667 template_attribute_helpers_start = """\
2668 /* Begin Attribute Helper Functions */
2670 template_attribute_helpers_end = """\
2672 /* End Attribute Helper Functions */
2676 # template for attribute helper code
2680 template_attribute_helper_function_start = """\
2682 /* Attribute = @atname@ */
2684 decode_@sname@_at(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2686 proto_item* item _U_;
2689 template_attribute_helper_function_end = """\
2694 #-------------------------------------------------------------#
2695 # Debugging templates #
2696 #-------------------------------------------------------------#
2699 # Template for outputting TODO "C" comments
2700 # so user know I need ti improve something.
2703 template_debug_TODO = """\
2705 /* TODO - @message@ */
2708 # Template for outputting WARNING "C" comments
2709 # so user know if I have found a problem.
2712 template_debug_WARNING = """\
2713 /* WARNING - @message@ */
2718 #-------------------------------------------------------------#
2719 # IDL Union templates #
2720 #-------------------------------------------------------------#
2722 template_comment_union_code_start = """\
2724 * IDL Union Start - @uname@
2727 template_comment_union_code_end = """
2729 * IDL union End - @uname@
2732 template_comment_union_code_discriminant = """\
2734 * IDL Union - Discriminant - @uname@
2738 # Cast Unions types to something appropriate
2739 # Enum value cast to guint32, all others cast to gint32
2740 # as omniidl accessor returns integer or Enum.
2743 template_union_code_save_discriminant_enum = """\
2744 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2746 template_union_code_save_discriminant_long = """\
2747 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2750 template_union_code_save_discriminant_ulong = """\
2751 disc_s_@discname@ = (gint32) u_octet4; /* save guint32 discriminant and cast to gint32 */
2753 template_union_code_save_discriminant_short = """\
2754 disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
2757 template_union_code_save_discriminant_ushort = """\
2758 disc_s_@discname@ = (gint32) u_octet2; /* save guint16 discriminant and cast to gint32 */
2760 template_union_code_save_discriminant_char = """\
2761 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2763 template_union_code_save_discriminant_boolean = """\
2764 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2766 template_comment_union_code_label_compare_start = """\
2767 if (disc_s_@discname@ == @labelval@) {
2769 template_comment_union_code_label_compare_end = """\
2770 return; /* End Compare for this discriminant type */
2775 template_comment_union_code_label_default_start = """
2776 /* Default Union Case Start */
2778 template_comment_union_code_label_default_end = """\
2779 /* Default Union Case End */
2783 # Templates for function prototypes.
2784 # This is used in genDeclares() for declaring function prototypes
2785 # for structs and union helper functions.
2788 template_hf_operations = """
2789 static int hf_operationrequest = -1;/* Request_Operation field */
2793 static int hf_@name@ = -1;"""
2795 template_prototype_start_dissecting = """
2796 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
2799 template_prototype_struct_start = """\
2800 /* Struct prototype declaration Start */
2802 template_prototype_struct_end = """\
2803 /* Struct prototype declaration End */
2805 template_prototype_struct_body = """\
2806 /* Struct = @stname@ */
2807 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 gchar *operation _U_, gboolean stream_is_big_endian _U_);
2809 template_decode_struct = """\
2810 decode_@name@_st(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);"""
2812 template_prototype_union_start = """\
2813 /* Union prototype declaration Start */"""
2815 template_prototype_union_end = """\
2816 /* Union prototype declaration End */"""
2818 template_prototype_union_body = """
2819 /* Union = @unname@ */
2820 static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
2822 template_decode_union = """
2823 decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);