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.wiresharl.org/
18 # Omniidl is part of the OmniOrb distribution, and is available at
19 # http://www.uk.research.att.com/omniORB/omniORB.html
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?)
79 # 2. add item instead of add_text()
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)
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
198 self.genDeclares(oplist,atlist,enlist,stlist,unlist)
200 self.genRegisteredFields()
201 if (len(atlist) > 0):
202 self.genAtList(atlist) # string constant declares for Attributes
203 if (len(enlist) > 0):
204 self.genEnList(enlist) # string constant declares for Enums
207 self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
208 self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
209 if (len(atlist) > 0):
210 self.genAttributeHelpers(atlist) # helper function to decode "attributes"
212 self.genHelpers(oplist,stlist,unlist) # operation, struct and union decode helper functions
214 self.genMainEntryStart(oplist)
215 self.genOpDelegator(oplist)
216 self.genAtDelegator(atlist)
217 self.genMainEntryEnd()
219 self.gen_proto_register(oplist, atlist, stlist, unlist)
220 self.gen_proto_reg_handoff(oplist)
221 # All the dissectors are now built-in
222 #self.gen_plugin_register()
224 #self.dumpvars() # debug
231 # Generate Standard Wireshark Header Comments
236 self.st.out(self.template_Header,dissector_name=self.dissname)
238 print "XXX genHeader"
246 # Wireshark Copyright Info
250 def genEthCopyright(self):
252 print "XXX genEthCopyright"
253 self.st.out(self.template_wireshark_copyright)
267 self.st.out(self.template_GPL)
276 def genIncludes(self):
278 print "XXX genIncludes"
280 self.st.out(self.template_Includes)
285 # Generate hf variables for operation filters
287 # in: opnode ( an operation node)
290 def genOpDeclares(self, op):
292 print "XXX genOpDeclares"
293 print "XXX return type = " , op.returnType().kind()
295 sname = self.namespace(op, "_")
298 if (rt.kind() != idltype.tk_void):
299 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
300 #self.get_CDR_alias(rt, rt.name() )
301 self.st.out(self.template_hf, name=sname + "_return")
303 self.st.out(self.template_hf, name=sname + "_return")
305 for p in op.parameters():
306 self.st.out(self.template_hf, name=sname + "_" + p.identifier())
311 # Generate hf variables for attributes
313 # in: at ( an attribute)
316 def genAtDeclares(self, at):
318 print "XXX genAtDeclares"
320 for decl in at.declarators():
321 sname = self.namespace(decl, "_")
323 self.st.out(self.template_hf, name="get" + "_" + sname + "_" + decl.identifier())
324 if not at.readonly():
325 self.st.out(self.template_hf, name="set" + "_" + sname + "_" + decl.identifier())
330 # Generate hf variables for structs
335 def genStDeclares(self, st):
337 print "XXX genStDeclares"
339 sname = self.namespace(st, "_")
341 for m in st.members():
342 for decl in m.declarators():
343 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
348 # Generate hf variables for user exception filters
350 # in: exnode ( an exception node)
353 def genExDeclares(self,ex):
355 print "XXX genExDeclares"
357 sname = self.namespace(ex, "_")
359 for m in ex.members():
360 for decl in m.declarators():
361 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
366 # Generate hf variables for union filters
371 def genUnionDeclares(self,un):
373 print "XXX genUnionDeclares"
375 sname = self.namespace(un, "_")
376 self.st.out(self.template_hf, name=sname + "_" + un.identifier())
378 for uc in un.cases(): # for all UnionCase objects in this union
379 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
380 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
385 # generate function prototypes if required
387 # Currently this is used for struct and union helper function declarations.
391 def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
393 print "XXX genDeclares"
395 # prototype for operation filters
396 self.st.out(self.template_hf_operations)
398 #operation specific filters
399 if (len(oplist) > 0):
400 self.st.out(self.template_proto_register_op_filter_comment)
402 self.genOpDeclares(op)
405 if (len(atlist) > 0):
406 self.st.out(self.template_proto_register_at_filter_comment)
408 self.genAtDeclares(at)
411 if (len(stlist) > 0):
412 self.st.out(self.template_proto_register_st_filter_comment)
414 self.genStDeclares(st)
416 # exception List filters
417 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
418 if (len(exlist) > 0):
419 self.st.out(self.template_proto_register_ex_filter_comment)
421 if (ex.members()): # only if has members
422 self.genExDeclares(ex)
425 if (len(unlist) > 0):
426 self.st.out(self.template_proto_register_un_filter_comment)
428 self.genUnionDeclares(un)
430 # prototype for start_dissecting()
432 self.st.out(self.template_prototype_start_dissecting)
437 self.st.out(self.template_prototype_struct_start)
440 sname = self.namespace(st, "_")
441 self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
443 self.st.out(self.template_prototype_struct_end)
447 self.st.out(self.template_prototype_union_start)
449 sname = self.namespace(un, "_")
450 self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
451 self.st.out(self.template_prototype_union_end)
459 def genProtocol(self):
460 self.st.out(self.template_protocol, dissector_name=self.dissname)
461 self.st.out(self.template_init_boundary)
465 # genProtoAndRegisteredFields
469 def genRegisteredFields(self):
470 self.st.out(self.template_registered_fields )
478 def genMainEntryStart(self,oplist):
479 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
481 self.st.out(self.template_main_dissector_switch_msgtype_start)
482 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
490 def genMainEntryEnd(self):
492 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
494 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
496 self.st.out(self.template_main_dissector_end)
504 # out: C code for IDL attribute decalarations.
506 # NOTE: Mapping of attributes to operation(function) names is tricky.
508 # The actual accessor function names are language-mapping specific. The attribute name
509 # is subject to OMG IDL's name scoping rules; the accessor function names are
510 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
514 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
515 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
519 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
520 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
522 # TODO: Implement some language dependant templates to handle naming conventions
523 # language <=> attribute. for C, C++. Java etc
525 # OR, just add a runtime GUI option to select language binding for attributes -- FS
529 # ie: def genAtlist(self,atlist,language)
534 def genAtList(self,atlist):
535 self.st.out(self.template_comment_attributes_start)
538 for i in n.declarators(): #
539 sname = self.namespace(i, "_")
540 atname = i.identifier()
541 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
543 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
545 self.st.out(self.template_comment_attributes_end)
553 # out: C code for IDL Enum decalarations using "static const value_string" template
558 def genEnList(self,enlist):
560 self.st.out(self.template_comment_enums_start)
563 sname = self.namespace(enum, "_")
565 self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
566 self.st.out(self.template_value_string_start, valstringname=sname)
567 for enumerator in enum.enumerators():
568 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
571 #atname = n.identifier()
572 self.st.out(self.template_value_string_end, valstringname=sname)
574 self.st.out(self.template_comment_enums_end)
586 # genExceptionDelegator
590 # out: C code for User exception delegator
596 def genExceptionDelegator(self,oplist):
598 self.st.out(self.template_main_exception_delegator_start)
601 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
605 print "XXX Exception " , ex.repoId()
606 print "XXX Exception Identifier" , ex.identifier()
607 print "XXX Exception Scoped Name" , ex.scopedName()
609 if (ex.members()): # only if has members
610 sname = self.namespace(ex, "_")
612 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
615 self.st.out(self.template_main_exception_delegator_end)
619 # genAttribueHelpers()
621 # Generate private helper functions to decode Attributes.
625 # For readonly attribute - generate get_xxx()
626 # If NOT readonly attribute - also generate set_xxx()
629 def genAttributeHelpers(self,atlist):
631 print "XXX genAttributeHelpers: atlist = ", atlist
633 self.st.out(self.template_attribute_helpers_start)
635 for attrib in atlist:
636 for decl in attrib.declarators():
637 self.genAtHelper(attrib,decl,"get") # get accessor
638 if not attrib.readonly():
639 self.genAtHelper(attrib,decl,"set") # set accessor
641 self.st.out(self.template_attribute_helpers_end)
646 # Generate private helper functions to decode an attribute
648 # in: at - attribute node
649 # in: decl - declarator belonging to this attribute
650 # in: order - to generate a "get" or "set" helper
652 def genAtHelper(self,attrib,decl,order):
654 print "XXX genAtHelper"
656 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
657 self.curr_sname = sname # update current opnode/exnode scoped name
659 if not self.fn_hash_built:
660 self.fn_hash[sname] = [] # init empty list as val for this sname key
661 # but only if the fn_hash is not already built
663 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
666 if (len(self.fn_hash[sname]) > 0):
667 self.st.out(self.template_helper_function_vars_start)
668 self.dumpCvars(sname)
669 self.st.out(self.template_helper_function_vars_end )
671 self.getCDR(attrib.attrType(), sname + "_" + decl.identifier() )
674 self.st.out(self.template_attribute_helper_function_end)
679 # genExceptionHelpers()
681 # Generate private helper functions to decode Exceptions used
688 def genExceptionHelpers(self,oplist):
689 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
691 print "XXX genExceptionHelpers: exlist = ", exlist
693 self.st.out(self.template_exception_helpers_start)
695 if (ex.members()): # only if has members
696 #print "XXX Exception = " + ex.identifier()
699 self.st.out(self.template_exception_helpers_end)
705 # Generate private helper functions to decode User Exceptions
707 # in: exnode ( an exception node)
710 def genExHelper(self,ex):
712 print "XXX genExHelper"
714 sname = self.namespace(ex, "_")
715 self.curr_sname = sname # update current opnode/exnode scoped name
716 if not self.fn_hash_built:
717 self.fn_hash[sname] = [] # init empty list as val for this sname key
718 # but only if the fn_hash is not already built
720 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
723 if (len(self.fn_hash[sname]) > 0):
724 self.st.out(self.template_helper_function_vars_start)
725 self.dumpCvars(sname)
726 self.st.out(self.template_helper_function_vars_end )
728 for m in ex.members():
729 #print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
732 for decl in m.declarators():
733 #print "XXX genExhelper, d = ", decl
734 if decl.sizes(): # an array
735 indices = self.get_indices_from_sizes(decl.sizes())
736 string_indices = '%i ' % indices # convert int to string
737 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
738 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
739 self.addvar(self.c_i + decl.identifier() + ";")
742 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
745 self.st.out(self.template_get_CDR_array_end)
749 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
752 self.st.out(self.template_exception_helper_function_end)
758 # Generate private helper functions for each IDL operation.
759 # Generate private helper functions for each IDL struct.
760 # Generate private helper functions for each IDL union.
763 # in: oplist, stlist, unlist
767 def genHelpers(self,oplist,stlist,unlist):
769 self.genOperation(op)
771 self.genStructHelper(st)
773 self.genUnionHelper(un)
778 # Generate private helper functions for a specificIDL operation.
783 def genOperation(self,opnode):
785 print "XXX genOperation called"
787 sname = self.namespace(opnode, "_")
788 if not self.fn_hash_built:
789 self.fn_hash[sname] = [] # init empty list as val for this sname key
790 # but only if the fn_hash is not already built
792 self.curr_sname = sname # update current opnode's scoped name
793 opname = opnode.identifier()
795 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
797 self.st.out(self.template_helper_function_start, sname=sname)
800 if (len(self.fn_hash[sname]) > 0):
801 self.st.out(self.template_helper_function_vars_start)
802 self.dumpCvars(sname)
803 self.st.out(self.template_helper_function_vars_end )
805 self.st.out(self.template_helper_switch_msgtype_start)
807 self.st.out(self.template_helper_switch_msgtype_request_start)
809 self.genOperationRequest(opnode)
810 self.st.out(self.template_helper_switch_msgtype_request_end)
813 self.st.out(self.template_helper_switch_msgtype_reply_start)
816 self.st.out(self.template_helper_switch_rep_status_start)
819 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
821 self.genOperationReply(opnode)
822 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
825 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
827 self.genOpExceptions(opnode)
828 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
831 self.st.out(self.template_helper_switch_msgtype_reply_default_start)
832 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
834 self.st.out(self.template_helper_switch_rep_status_end)
838 self.st.out(self.template_helper_switch_msgtype_default_start)
839 self.st.out(self.template_helper_switch_msgtype_default_end)
841 self.st.out(self.template_helper_switch_msgtype_end)
845 self.st.out(self.template_helper_function_end, sname=sname)
851 # Decode function parameters for a GIOP request message
855 def genOperationRequest(self,opnode):
856 for p in opnode.parameters():
859 print "XXX parameter = " ,p
860 print "XXX parameter type = " ,p.paramType()
861 print "XXX parameter type kind = " ,p.paramType().kind()
863 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
867 # Decode function parameters for a GIOP reply message
871 def genOperationReply(self,opnode):
873 rt = opnode.returnType() # get return type
875 print "XXX genOperationReply"
876 print "XXX opnode = " , opnode
877 print "XXX return type = " , rt
878 print "XXX return type.unalias = " , rt.unalias()
879 print "XXX return type.kind() = " , rt.kind();
881 sname = self.namespace(opnode, "_")
883 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
884 #self.getCDR(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
885 self.get_CDR_alias(rt, sname + "_return" )
886 #self.get_CDR_alias(rt, rt.name() )
889 self.getCDR(rt, sname + "_return") # return value is NOT an alias
891 for p in opnode.parameters():
892 if p.is_out(): # out or inout
893 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
895 #self.st.dec_indent()
897 def genOpExceptions(self,opnode):
898 for ex in opnode.raises():
901 for m in ex.members():
903 #print m.memberType(), m.memberType().kind()
905 # Delegator for Operations
908 def genOpDelegator(self,oplist):
910 iname = "/".join(op.scopedName()[:-1])
911 opname = op.identifier()
912 sname = self.namespace(op, "_")
913 self.st.out(self.template_op_delegate_code, interface=iname, sname=sname, opname=opname)
916 # Delegator for Attributes
919 def genAtDelegator(self,atlist):
921 for i in a.declarators():
922 atname = i.identifier()
923 sname = self.namespace(i, "_")
924 self.st.out(self.template_at_delegate_code_get, sname=sname)
926 self.st.out(self.template_at_delegate_code_set, sname=sname)
930 # Add a variable declaration to the hash of list
933 def addvar(self, var):
934 if not ( var in self.fn_hash[self.curr_sname] ):
935 self.fn_hash[self.curr_sname].append(var)
938 # Print the variable declaration from the hash of list
943 for fn in self.fn_hash.keys():
945 for v in self.fn_hash[fn]:
948 # Print the "C" variable declaration from the hash of list
949 # for a given scoped operation name (eg: tux_penguin_eat)
953 def dumpCvars(self, sname):
954 for v in self.fn_hash[sname]:
959 # Given an enum node, and a enumerator node, return
960 # the enumerator's numerical value.
962 # eg: enum Color {red,green,blue} should return
966 def valFromEnum(self,enumNode, enumeratorNode):
968 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
969 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
971 if isinstance(enumeratorNode,idlast.Enumerator):
972 value = enumNode.enumerators().index(enumeratorNode)
1000 ## tk_ulonglong = 24
1001 ## tk_longdouble = 25
1006 ## tk_value_box = 30
1008 ## tk_abstract_interface = 32
1014 # This is the main "iterator" function. It takes a node, and tries to output
1015 # a get_CDR_XXX accessor method(s). It can call itself multiple times
1016 # if I find nested structures etc.
1019 def getCDR(self,type,name="fred"):
1021 pt = type.unalias().kind() # param CDR type
1022 pn = name # param name
1025 print "XXX getCDR: kind = " , pt
1026 print "XXX getCDR: name = " , pn
1028 if pt == idltype.tk_ulong:
1029 self.get_CDR_ulong(pn)
1030 elif pt == idltype.tk_longlong:
1031 self.get_CDR_longlong(pn)
1032 elif pt == idltype.tk_ulonglong:
1033 self.get_CDR_ulonglong(pn)
1034 elif pt == idltype.tk_void:
1035 self.get_CDR_void(pn)
1036 elif pt == idltype.tk_short:
1037 self.get_CDR_short(pn)
1038 elif pt == idltype.tk_long:
1039 self.get_CDR_long(pn)
1040 elif pt == idltype.tk_ushort:
1041 self.get_CDR_ushort(pn)
1042 elif pt == idltype.tk_float:
1043 self.get_CDR_float(pn)
1044 elif pt == idltype.tk_double:
1045 self.get_CDR_double(pn)
1046 elif pt == idltype.tk_fixed:
1047 self.get_CDR_fixed(type.unalias(),pn)
1048 elif pt == idltype.tk_boolean:
1049 self.get_CDR_boolean(pn)
1050 elif pt == idltype.tk_char:
1051 self.get_CDR_char(pn)
1052 elif pt == idltype.tk_octet:
1053 self.get_CDR_octet(pn)
1054 elif pt == idltype.tk_any:
1055 self.get_CDR_any(pn)
1056 elif pt == idltype.tk_string:
1057 self.get_CDR_string(pn)
1058 elif pt == idltype.tk_wstring:
1059 self.get_CDR_wstring(pn)
1060 elif pt == idltype.tk_wchar:
1061 self.get_CDR_wchar(pn)
1062 elif pt == idltype.tk_enum:
1064 self.get_CDR_enum(pn,type)
1065 #self.get_CDR_enum(pn)
1067 elif pt == idltype.tk_struct:
1068 self.get_CDR_struct(type,pn)
1069 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1070 self.get_CDR_TypeCode(pn)
1071 elif pt == idltype.tk_sequence and \
1072 type.unalias().seqType().kind() == idltype.tk_octet:
1073 self.get_CDR_sequence_octet(type,pn)
1074 elif pt == idltype.tk_sequence:
1075 self.get_CDR_sequence(type,pn)
1076 elif pt == idltype.tk_objref:
1077 self.get_CDR_objref(type,pn)
1078 elif pt == idltype.tk_array:
1079 self.get_CDR_array(type,pn)
1080 elif pt == idltype.tk_union:
1081 self.get_CDR_union(type,pn)
1082 elif pt == idltype.tk_alias:
1084 print "XXXXX Alias type XXXXX " , type
1085 self.get_CDR_alias(type,pn)
1087 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1091 # get_CDR_XXX methods are here ..
1096 def get_CDR_ulong(self,pn):
1097 self.st.out(self.template_get_CDR_ulong, hfname=pn)
1099 def get_CDR_short(self,pn):
1100 self.st.out(self.template_get_CDR_short, hfname=pn)
1102 def get_CDR_void(self,pn):
1103 self.st.out(self.template_get_CDR_void, hfname=pn)
1105 def get_CDR_long(self,pn):
1106 self.st.out(self.template_get_CDR_long, hfname=pn)
1108 def get_CDR_ushort(self,pn):
1109 self.st.out(self.template_get_CDR_ushort, hfname=pn)
1111 def get_CDR_float(self,pn):
1112 self.st.out(self.template_get_CDR_float, hfname=pn)
1114 def get_CDR_double(self,pn):
1115 self.st.out(self.template_get_CDR_double, hfname=pn)
1117 def get_CDR_longlong(self,pn):
1118 self.st.out(self.template_get_CDR_longlong, hfname=pn)
1120 def get_CDR_ulonglong(self,pn):
1121 self.st.out(self.template_get_CDR_ulonglong, hfname=pn)
1123 def get_CDR_boolean(self,pn):
1124 self.st.out(self.template_get_CDR_boolean, hfname=pn)
1126 def get_CDR_fixed(self,type,pn):
1128 print "XXXX calling get_CDR_fixed, type = ", type
1129 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1130 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1132 string_digits = '%i ' % type.digits() # convert int to string
1133 string_scale = '%i ' % type.scale() # convert int to string
1134 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
1136 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1137 self.addvar(self.c_seq)
1140 def get_CDR_char(self,pn):
1141 self.st.out(self.template_get_CDR_char, hfname=pn)
1143 def get_CDR_octet(self,pn):
1144 self.st.out(self.template_get_CDR_octet, hfname=pn)
1146 def get_CDR_any(self,pn):
1147 self.st.out(self.template_get_CDR_any, varname=pn)
1149 def get_CDR_enum(self,pn,type):
1150 #self.st.out(self.template_get_CDR_enum, hfname=pn)
1151 sname = self.namespace(type.unalias(), "_")
1152 self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname,hfname=pn)
1153 self.addvar(self.c_u_octet4)
1155 def get_CDR_string(self,pn):
1156 self.st.out(self.template_get_CDR_string, varname=pn)
1158 def get_CDR_wstring(self,pn):
1159 self.st.out(self.template_get_CDR_wstring, varname=pn)
1160 self.addvar(self.c_u_octet4)
1161 self.addvar(self.c_seq)
1163 def get_CDR_wchar(self,pn):
1164 self.st.out(self.template_get_CDR_wchar, varname=pn)
1165 self.addvar(self.c_s_octet1)
1166 self.addvar(self.c_seq)
1168 def get_CDR_TypeCode(self,pn):
1169 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1170 self.addvar(self.c_u_octet4)
1172 def get_CDR_objref(self,type,pn):
1173 self.st.out(self.template_get_CDR_object)
1175 def get_CDR_sequence_len(self,pn):
1176 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1179 def get_CDR_union(self,type,pn):
1181 print "XXX Union type =" , type, " pn = ",pn
1182 print "XXX Union type.decl()" , type.decl()
1183 print "XXX Union Scoped Name" , type.scopedName()
1185 # If I am a typedef union {..}; node then find the union node
1187 if isinstance(type.decl(), idlast.Declarator):
1188 ntype = type.decl().alias().aliasType().decl()
1190 ntype = type.decl() # I am a union node
1193 print "XXX Union ntype =" , ntype
1195 sname = self.namespace(ntype, "_")
1196 self.st.out(self.template_union_start, name=sname )
1198 # Output a call to the union helper function so I can handle recursive union also.
1200 self.st.out(self.template_decode_union,name=sname)
1202 self.st.out(self.template_union_end, name=sname )
1207 # This takes a node, and tries to output the appropriate item for the
1211 def getCDR_hf(self,type,desc,filter,hf_name="fred",):
1213 pt = type.unalias().kind() # param CDR type
1214 pn = hf_name # param name
1217 print "XXX getCDR_hf: kind = " , pt
1218 print "XXX getCDR_hf: name = " , pn
1220 if pt == idltype.tk_ulong:
1221 self.get_CDR_ulong_hf(pn, desc, filter, self.dissname)
1222 elif pt == idltype.tk_longlong:
1223 self.get_CDR_longlong_hf(pn, desc, filter, self.dissname)
1224 elif pt == idltype.tk_ulonglong:
1225 self.get_CDR_ulonglong_hf(pn, desc, filter, self.dissname)
1226 elif pt == idltype.tk_void:
1227 pt = pt # do nothing
1228 elif pt == idltype.tk_short:
1229 self.get_CDR_short_hf(pn, desc, filter, self.dissname)
1230 elif pt == idltype.tk_long:
1231 self.get_CDR_long_hf(pn, desc, filter, self.dissname)
1232 elif pt == idltype.tk_ushort:
1233 self.get_CDR_ushort_hf(pn, desc, filter, self.dissname)
1234 elif pt == idltype.tk_float:
1235 self.get_CDR_float_hf(pn, desc, filter, self.dissname)
1236 elif pt == idltype.tk_double:
1237 self.get_CDR_double_hf(pn, desc, filter, self.dissname)
1238 elif pt == idltype.tk_fixed:
1239 pt = pt # XXX - do nothing (for now)
1240 #self.get_CDR_fixed(type.unalias(),pn)
1241 elif pt == idltype.tk_boolean:
1242 self.get_CDR_boolean_hf(pn, desc, filter, self.dissname)
1243 elif pt == idltype.tk_char:
1244 self.get_CDR_char_hf(pn, desc, filter, self.dissname)
1245 elif pt == idltype.tk_octet:
1246 self.get_CDR_octet_hf(pn, desc, filter, self.dissname)
1247 elif pt == idltype.tk_any:
1248 pt = pt # XXX - do nothing (for now)
1249 #self.get_CDR_any(pn)
1250 elif pt == idltype.tk_string:
1251 self.get_CDR_string_hf(pn, desc, filter, self.dissname)
1252 elif pt == idltype.tk_wstring:
1253 self.get_CDR_wstring_hf(pn, desc, filter, self.dissname)
1254 elif pt == idltype.tk_wchar:
1255 self.get_CDR_wchar_hf(pn, desc, filter, self.dissname)
1256 elif pt == idltype.tk_enum:
1257 self.get_CDR_enum_hf(pn, type, desc, filter, self.dissname)
1258 elif pt == idltype.tk_struct:
1259 pt = pt # XXX - do nothing (for now)
1260 #self.get_CDR_struct(type,pn)
1261 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1262 self.get_CDR_TypeCode_hf(pn, desc, filter, self.dissname)
1263 elif pt == idltype.tk_sequence:
1264 if type.unalias().seqType().kind() == idltype.tk_octet:
1265 self.get_CDR_sequence_octet_hf(type, pn, desc, filter, self.dissname)
1267 self.get_CDR_sequence_hf(type, pn, desc, filter, self.dissname)
1268 elif pt == idltype.tk_objref:
1269 pt = pt # XXX - do nothing (for now)
1270 #self.get_CDR_objref(type,pn)
1271 elif pt == idltype.tk_array:
1272 pt = pt # XXX - do nothing (for now)
1273 #self.get_CDR_array(type,pn)
1274 elif pt == idltype.tk_union:
1275 pt = pt # XXX - do nothing (for now)
1276 #self.get_CDR_union(type,pn)
1277 elif pt == idltype.tk_alias:
1279 print "XXXXX Alias type hf XXXXX " , type
1280 self.get_CDR_alias_hf(type,pn)
1282 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1285 # get_CDR_XXX_hf methods are here ..
1290 def get_CDR_ulong_hf(self,pn,desc,filter,diss):
1291 self.st.out(self.template_get_CDR_ulong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1293 def get_CDR_short_hf(self,pn,desc,filter,diss):
1294 self.st.out(self.template_get_CDR_short_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1296 def get_CDR_long_hf(self,pn,desc,filter,diss):
1297 self.st.out(self.template_get_CDR_long_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1299 def get_CDR_ushort_hf(self,pn,desc,filter,diss):
1300 self.st.out(self.template_get_CDR_ushort_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1302 def get_CDR_float_hf(self,pn,desc,filter,diss):
1303 self.st.out(self.template_get_CDR_float_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1305 def get_CDR_double_hf(self,pn,desc,filter,diss):
1306 self.st.out(self.template_get_CDR_double_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1308 def get_CDR_longlong_hf(self,pn,desc,filter,diss):
1309 self.st.out(self.template_get_CDR_longlong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1311 def get_CDR_ulonglong_hf(self,pn,desc,filter,diss):
1312 self.st.out(self.template_get_CDR_ulonglong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1314 def get_CDR_boolean_hf(self,pn,desc,filter,diss):
1315 self.st.out(self.template_get_CDR_boolean_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1317 def get_CDR_char_hf(self,pn,desc,filter,diss):
1318 self.st.out(self.template_get_CDR_char_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1320 def get_CDR_octet_hf(self,pn,desc,filter,diss):
1321 self.st.out(self.template_get_CDR_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1323 def get_CDR_enum_hf(self,pn,type,desc,filter,diss):
1324 #self.st.out(self.template_get_CDR_enum_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1325 sname = self.namespace(type.unalias(), "_")
1326 self.st.out(self.template_get_CDR_enum_symbolic_hf, valstringarray=sname,hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1327 # self.addvar(self.c_u_octet4)
1329 def get_CDR_string_hf(self,pn,desc,filter,diss):
1330 self.st.out(self.template_get_CDR_string_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1332 def get_CDR_wstring_hf(self,pn,desc,filter,diss):
1333 self.st.out(self.template_get_CDR_wstring_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1334 # self.addvar(self.c_u_octet4)
1335 # self.addvar(self.c_seq)
1337 def get_CDR_wchar_hf(self,pn,desc,filter,diss):
1338 self.st.out(self.template_get_CDR_wchar_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1339 # self.addvar(self.c_s_octet1)
1340 # self.addvar(self.c_seq)
1342 def get_CDR_TypeCode_hf(self,pn,desc,filter,diss):
1343 self.st.out(self.template_get_CDR_TypeCode_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1344 # self.addvar(self.c_u_octet4)
1346 def get_CDR_sequence_octet_hf(self,type,pn,desc,filter,diss):
1347 self.st.out(self.template_get_CDR_sequence_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1349 def get_CDR_sequence_hf(self,type,pn,desc,filter,diss):
1350 self.st.out(self.template_get_CDR_sequence_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1352 def get_CDR_alias_hf(self,type,pn):
1354 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1355 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1356 print "XXX get_CDR_alias_hf, type.decl().alias() = " ,type.decl().alias()
1358 decl = type.decl() # get declarator object
1360 if (decl.sizes()): # a typedef array
1361 #indices = self.get_indices_from_sizes(decl.sizes())
1362 #string_indices = '%i ' % indices # convert int to string
1363 #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1365 #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1366 #self.addvar(self.c_i + pn + ";")
1367 #self.st.inc_indent()
1368 self.getCDR_hf(type.decl().alias().aliasType(), pn )
1370 #self.st.dec_indent()
1371 #self.st.out(self.template_get_CDR_array_end)
1374 else: # a simple typdef
1376 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1377 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1379 self.getCDR_hf(type, decl.identifier() )
1383 # Code to generate Union Helper functions
1385 # in: un - a union node
1390 def genUnionHelper(self,un):
1392 print "XXX genUnionHelper called"
1393 print "XXX Union type =" , un
1394 print "XXX Union type.switchType()" , un.switchType()
1395 print "XXX Union Scoped Name" , un.scopedName()
1397 sname = self.namespace(un, "_")
1398 self.curr_sname = sname # update current opnode/exnode/stnode/unnode scoped name
1399 if not self.fn_hash_built:
1400 self.fn_hash[sname] = [] # init empty list as val for this sname key
1401 # but only if the fn_hash is not already built
1403 self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
1404 self.st.inc_indent()
1406 if (len(self.fn_hash[sname]) > 0):
1407 self.st.out(self.template_helper_function_vars_start)
1408 self.dumpCvars(sname)
1409 self.st.out(self.template_helper_function_vars_end )
1411 st = un.switchType().unalias() # may be typedef switch type, so find real type
1413 self.st.out(self.template_comment_union_code_start, uname=un.repoId() )
1415 self.getCDR(st, sname + "_" + un.identifier());
1417 # Depending on what kind of discriminant I come accross (enum,integer,char,
1418 # short, boolean), make sure I cast the return value of the get_XXX accessor
1419 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1420 # return an integer, or an Enumerator object that is then converted to its
1421 # integer equivalent.
1424 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1427 if (st.kind() == idltype.tk_enum):
1429 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1430 self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
1431 self.addvar(self.c_s_disc + un.identifier() + ";")
1433 elif (st.kind() == idltype.tk_long):
1434 self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
1435 self.addvar(self.c_s_disc + un.identifier() + ";")
1437 elif (st.kind() == idltype.tk_ulong):
1438 self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
1439 self.addvar(self.c_s_disc + un.identifier() + ";")
1441 elif (st.kind() == idltype.tk_short):
1442 self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
1443 self.addvar(self.c_s_disc + un.identifier() + ";")
1445 elif (st.kind() == idltype.tk_ushort):
1446 self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
1447 self.addvar(self.c_s_disc + un.identifier() + ";")
1449 elif (st.kind() == idltype.tk_boolean):
1450 self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier() )
1451 self.addvar(self.c_s_disc + un.identifier() + ";")
1453 elif (st.kind() == idltype.tk_char):
1454 self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
1455 self.addvar(self.c_s_disc + un.identifier() + ";")
1458 print "XXX Unknown st.kind() = ", st.kind()
1461 # Loop over all cases in this union
1464 for uc in un.cases(): # for all UnionCase objects in this union
1465 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1467 # get integer value, even if discriminant is
1468 # an Enumerator node
1470 if isinstance(cl.value(),idlast.Enumerator):
1472 print "XXX clv.identifier()", cl.value().identifier()
1473 print "XXX clv.repoId()", cl.value().repoId()
1474 print "XXX clv.scopedName()", cl.value().scopedName()
1476 # find index of enumerator in enum declaration
1477 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1479 clv = self.valFromEnum(std,cl.value())
1484 #print "XXX clv = ",clv
1487 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1488 # eg: if (disc == 'b')..
1490 # TODO : handle \xxx chars generically from a function or table lookup rather than
1491 # a whole bunch of "if" statements. -- FS
1494 if (st.kind() == idltype.tk_char):
1495 if (clv == '\n'): # newline
1496 string_clv = "'\\n'"
1497 elif (clv == '\t'): # tab
1498 string_clv = "'\\t'"
1500 string_clv = "'" + clv + "'"
1502 string_clv = '%i ' % clv
1505 # If default case, then skp comparison with discriminator
1508 if not cl.default():
1509 self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
1510 self.st.inc_indent()
1512 self.st.out(self.template_comment_union_code_label_default_start )
1515 self.getCDR(uc.caseType(),sname + "_" + uc.declarator().identifier())
1517 if not cl.default():
1518 self.st.dec_indent()
1519 self.st.out(self.template_comment_union_code_label_compare_end )
1521 self.st.out(self.template_comment_union_code_label_default_end )
1523 self.st.dec_indent()
1524 self.st.out(self.template_union_helper_function_end)
1529 # Currently, get_CDR_alias is geared to finding typdef
1532 def get_CDR_alias(self,type,pn):
1534 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1535 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1536 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1538 decl = type.decl() # get declarator object
1540 if (decl.sizes()): # a typedef array
1541 indices = self.get_indices_from_sizes(decl.sizes())
1542 string_indices = '%i ' % indices # convert int to string
1543 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1545 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
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.out(self.template_get_CDR_array_end)
1554 else: # a simple typdef
1556 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1557 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1559 self.getCDR(type, pn )
1567 # Handle structs, including recursive
1570 def get_CDR_struct(self,type,pn):
1572 # If I am a typedef struct {..}; node then find the struct node
1574 if isinstance(type.decl(), idlast.Declarator):
1575 ntype = type.decl().alias().aliasType().decl()
1577 ntype = type.decl() # I am a struct node
1579 sname = self.namespace(ntype, "_")
1580 self.st.out(self.template_structure_start, name=sname )
1582 # Output a call to the struct helper function so I can handle recursive structs also.
1584 self.st.out(self.template_decode_struct,name=sname)
1586 self.st.out(self.template_structure_end, name=sname )
1591 # Generate private helper functions to decode a struct
1593 # in: stnode ( a struct node)
1596 def genStructHelper(self,st):
1598 print "XXX genStructHelper"
1600 sname = self.namespace(st, "_")
1601 self.curr_sname = sname # update current opnode/exnode/stnode scoped name
1602 if not self.fn_hash_built:
1603 self.fn_hash[sname] = [] # init empty list as val for this sname key
1604 # but only if the fn_hash is not already built
1606 self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
1607 self.st.inc_indent()
1609 if (len(self.fn_hash[sname]) > 0):
1610 self.st.out(self.template_helper_function_vars_start)
1611 self.dumpCvars(sname)
1612 self.st.out(self.template_helper_function_vars_end )
1614 for m in st.members():
1615 for decl in m.declarators():
1616 if decl.sizes(): # an array
1617 indices = self.get_indices_from_sizes(decl.sizes())
1618 string_indices = '%i ' % indices # convert int to string
1619 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1620 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1621 self.addvar(self.c_i + decl.identifier() + ";")
1623 self.st.inc_indent()
1624 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1625 self.st.dec_indent()
1626 self.st.out(self.template_get_CDR_array_end)
1630 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1632 self.st.dec_indent()
1633 self.st.out(self.template_struct_helper_function_end)
1640 # Generate code to access a sequence of a type
1644 def get_CDR_sequence(self,type, pn):
1645 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1646 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1647 self.addvar(self.c_i_lim + pn + ";" )
1648 self.addvar(self.c_i + pn + ";")
1650 self.st.inc_indent()
1651 self.getCDR(type.unalias().seqType(), pn ) # and start all over with the type
1652 self.st.dec_indent()
1654 self.st.out(self.template_get_CDR_sequence_loop_end)
1658 # Generate code to access a sequence of octet
1661 def get_CDR_sequence_octet(self,type, pn):
1662 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1663 self.st.out(self.template_get_CDR_sequence_octet, seqname=pn)
1664 self.addvar(self.c_i_lim + pn + ";")
1665 self.addvar("gchar * binary_seq_" + pn + ";")
1666 self.addvar("gchar * text_seq_" + pn + ";")
1670 # Generate code to access arrays,
1672 # This is handled elsewhere. Arrays are either typedefs or in
1675 # TODO - Remove this
1678 def get_CDR_array(self,type, decl):
1680 print "XXX get_CDR_array called "
1681 print "XXX array size = " ,decl.sizes()
1689 # out - scoped operation name, using sep character instead of "::"
1691 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1695 def namespace(self,node,sep):
1696 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1697 #print "XXX namespace: sname = " + sname
1702 # generate code for plugin initialisation
1705 def gen_plugin_register(self):
1706 self.st.out(self.template_plugin_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1709 # generate register_giop_user_module code, and register only
1710 # unique interfaces that contain operations. Also output
1711 # a heuristic register in case we want to use that.
1713 # TODO - make this a command line option
1721 def gen_proto_reg_handoff(self, oplist):
1723 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1724 self.st.inc_indent()
1726 for iname in self.get_intlist(oplist):
1727 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1729 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1730 self.st.dec_indent()
1732 self.st.out(self.template_proto_reg_handoff_end)
1735 # generate hf_ array element for operation, attribute, enums, struct and union lists
1738 def genOp_hf(self,op):
1739 sname = self.namespace(op, "_")
1740 opname = sname[string.find(sname, "_")+1:]
1741 opname = opname[:string.find(opname, "_")]
1742 rt = op.returnType()
1744 if (rt.kind() != idltype.tk_void):
1745 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
1746 self.getCDR_hf(rt, rt.name(),\
1747 opname + "." + op.identifier() + ".return", sname + "_return")
1749 self.getCDR_hf(rt, "Return value",\
1750 opname + "." + op.identifier() + ".return", sname + "_return")
1752 for p in op.parameters():
1753 self.getCDR_hf(p.paramType(), p.identifier(),\
1754 opname + "." + op.identifier() + "." + p.identifier(), sname + "_" + p.identifier())
1756 def genAt_hf(self,at):
1757 for decl in at.declarators():
1758 sname = self.namespace(decl, "_")
1759 atname = sname[string.find(sname, "_")+1:]
1760 atname = atname[:string.find(atname, "_")]
1762 self.getCDR_hf(at.attrType(), decl.identifier(),\
1763 atname + "." + decl.identifier() + ".get", "get" + "_" + sname + "_" + decl.identifier())
1764 if not at.readonly():
1765 self.getCDR_hf(at.attrType(), decl.identifier(),\
1766 atname + "." + decl.identifier() + ".set", "set" + "_" + sname + "_" + decl.identifier())
1768 def genSt_hf(self,st):
1769 sname = self.namespace(st, "_")
1770 stname = sname[string.find(sname, "_")+1:]
1771 stname = stname[:string.find(stname, "_")]
1772 for m in st.members():
1773 for decl in m.declarators():
1774 self.getCDR_hf(m.memberType(), st.identifier() + "_" + decl.identifier(),\
1775 st.identifier() + "." + decl.identifier(), sname + "_" + decl.identifier())
1777 def genEx_hf(self,ex):
1778 sname = self.namespace(ex, "_")
1779 exname = sname[string.find(sname, "_")+1:]
1780 exname = exname[:string.find(exname, "_")]
1781 for m in ex.members():
1782 for decl in m.declarators():
1783 self.getCDR_hf(m.memberType(), ex.identifier() + "_" + decl.identifier(),\
1784 exname + "." + ex.identifier() + "_" + decl.identifier(), sname + "_" + decl.identifier())
1786 def genUnion_hf(self,un):
1787 sname = self.namespace(un, "_")
1788 unname = sname[:string.rfind(sname, "_")]
1789 unname = string.replace(unname, "_", ".")
1791 self.getCDR_hf(un.switchType().unalias(), un.identifier(),\
1792 unname + "." + un.identifier(), sname + "_" + un.identifier())
1794 for uc in un.cases(): # for all UnionCase objects in this union
1795 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1796 self.getCDR_hf(uc.caseType(), un.identifier() + "_" + uc.declarator().identifier(),\
1797 unname + "." + un.identifier() + "." + uc.declarator().identifier(),\
1798 sname + "_" + uc.declarator().identifier())
1801 # generate proto_register_<protoname> code,
1803 # in - oplist[], atlist[], stline[], unlist[]
1807 def gen_proto_register(self, oplist, atlist, stlist, unlist):
1808 self.st.out(self.template_proto_register_start, dissector_name=self.dissname)
1810 #operation specific filters
1811 self.st.out(self.template_proto_register_op_filter_comment)
1816 self.st.out(self.template_proto_register_at_filter_comment)
1821 self.st.out(self.template_proto_register_st_filter_comment)
1823 if (st.members()): # only if has members
1826 # exception List filters
1827 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
1828 self.st.out(self.template_proto_register_ex_filter_comment)
1830 if (ex.members()): # only if has members
1834 self.st.out(self.template_proto_register_un_filter_comment)
1836 self.genUnion_hf(un)
1838 self.st.out(self.template_proto_register_end, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1844 # out - a list of unique interface names. This will be used in
1845 # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1846 # name must be removed from the scope. And we also only want unique interfaces.
1849 def get_intlist(self,oplist):
1850 int_hash = {} # holds a hash of unique interfaces
1852 sc = op.scopedName() # eg: penguin,tux,bite
1853 sc1 = sc[:-1] # drop last entry
1854 sn = idlutil.slashName(sc1) # penguin/tux
1855 if not int_hash.has_key(sn):
1856 int_hash[sn] = 0; # dummy val, but at least key is unique
1857 ret = int_hash.keys()
1866 # out - a list of exception nodes (unique). This will be used in
1867 # to generate dissect_exception_XXX functions.
1872 def get_exceptionList(self,oplist):
1873 ex_hash = {} # holds a hash of unique exceptions.
1875 for ex in op.raises():
1876 if not ex_hash.has_key(ex):
1877 ex_hash[ex] = 0; # dummy val, but at least key is unique
1879 print "XXX Exception = " + ex.identifier()
1880 ret = ex_hash.keys()
1887 # Simple function to take a list of array sizes and find the
1888 # total number of elements
1891 # eg: temp[4][3] = 12 elements
1894 def get_indices_from_sizes(self,sizelist):
1902 # Determine how many octets contain requested number
1903 # of digits for an "fixed" IDL type "on the wire"
1906 def dig_to_len(self,dignum):
1907 return (dignum/2) + 1
1912 # Output some TODO comment
1916 def genTODO(self,message):
1917 self.st.out(self.template_debug_TODO, message=message)
1920 # Output some WARNING comment
1924 def genWARNING(self,message):
1925 self.st.out(self.template_debug_WARNING, message=message)
1928 # Templates for C code
1931 template_helper_function_comment = """\
1935 template_helper_function_vars_start = """\
1936 /* Operation specific Variable declarations Begin */"""
1938 template_helper_function_vars_end = """\
1939 /* Operation specific Variable declarations End */
1942 template_helper_function_start = """\
1944 decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, gchar *operation _U_, gboolean stream_is_big_endian _U_)
1947 template_helper_function_end = """\
1951 # proto_reg_handoff() templates
1954 template_proto_reg_handoff_start = """
1955 /* register me as handler for these interfaces */
1957 void proto_reg_handoff_giop_@dissector_name@(void) {
1960 template_proto_reg_handoff_body = """
1961 /* Register for Explicit Dissection */
1963 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
1965 template_proto_reg_handoff_heuristic = """
1966 /* Register for Heuristic Dissection */
1968 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
1970 template_proto_reg_handoff_end = """
1975 # Initialize the protocol
1978 template_protocol = """
1979 /* Initialise the protocol and subtree pointers */
1980 static int proto_@dissector_name@ = -1;
1981 static gint ett_@dissector_name@ = -1;
1984 # Initialize the boundary Alignment
1987 template_init_boundary = """
1988 /* Initialise the initial Alignment */
1989 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */
1992 # Initialize the Registered fields
1995 template_registered_fields = """
1997 /* Initialise the Registered fields */
1999 /* TODO - Use registered fields */
2002 # plugin_register and plugin_reg_handoff templates
2005 template_plugin_register = """
2008 G_MODULE_EXPORT void
2009 plugin_register(void)
2011 if (proto_@dissector_name@ == -1) {
2012 proto_register_giop_@dissector_name@();
2016 G_MODULE_EXPORT void
2017 plugin_reg_handoff(void){
2018 proto_register_handoff_giop_@dissector_name@();
2023 # proto_register_<dissector name>(void) templates
2026 template_proto_register_start = """
2028 /* Register the protocol with Wireshark */
2030 void proto_register_giop_@dissector_name@(void) {
2032 /* setup list of header fields */
2034 static hf_register_info hf[] = {
2035 /* field that indicates the currently ongoing request/reply exchange */
2036 {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2038 template_proto_register_end = """
2041 /* setup protocol subtree array */
2043 static gint *ett[] = {
2044 &ett_@dissector_name@,
2047 /* Register the protocol name and description */
2049 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
2051 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
2053 proto_register_subtree_array(ett,array_length(ett));
2058 template_proto_register_op_filter_comment = """\
2059 /* Operation filters */"""
2061 template_proto_register_at_filter_comment = """\
2062 /* Attribute filters */"""
2064 template_proto_register_st_filter_comment = """\
2065 /* Struct filters */"""
2067 template_proto_register_ex_filter_comment = """\
2068 /* User exception filters */"""
2070 template_proto_register_un_filter_comment = """\
2071 /* Union filters */"""
2075 # template for delegation code
2078 template_op_delegate_code = """\
2079 if (strcmp(operation, "@opname@") == 0
2080 && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
2081 item = process_RequestOperation(tvb, pinfo, ptree, header, operation); /* fill-up Request_Operation field & info column */
2082 tree = start_dissecting(tvb, pinfo, ptree, offset);
2083 decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
2088 # Templates for the helper functions
2093 template_helper_switch_msgtype_start = """\
2095 switch(header->message_type) {
2097 template_helper_switch_msgtype_default_start = """\
2100 /* Unknown GIOP Message */
2101 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Unknown GIOP message %d", header->message_type);
2104 template_helper_switch_msgtype_default_end = """\
2107 template_helper_switch_msgtype_end = """\
2108 } /* switch(header->message_type) */
2110 template_helper_switch_msgtype_request_start = """\
2113 template_helper_switch_msgtype_request_end = """\
2116 template_helper_switch_msgtype_reply_start = """\
2119 template_helper_switch_msgtype_reply_no_exception_start = """\
2122 template_helper_switch_msgtype_reply_no_exception_end = """\
2125 template_helper_switch_msgtype_reply_user_exception_start = """\
2126 case USER_EXCEPTION:
2128 template_helper_switch_msgtype_reply_user_exception_end = """\
2131 template_helper_switch_msgtype_reply_default_start = """\
2134 /* Unknown Exception */
2135 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Unknown exception %d", header->rep_status);
2138 template_helper_switch_msgtype_reply_default_end = """\
2141 template_helper_switch_msgtype_reply_end = """\
2144 template_helper_switch_msgtype_default_start = """\
2147 /* Unknown GIOP Message */
2148 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Unknown GIOP message %d", header->message_type);
2151 template_helper_switch_msgtype_default_end = """\
2154 template_helper_switch_rep_status_start = """\
2155 switch(header->rep_status) {
2157 template_helper_switch_rep_status_default_start = """\
2161 /* Unknown Reply Status */
2162 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Unknown reply status %d", header->rep_status);
2166 template_helper_switch_rep_status_default_end = """\
2169 template_helper_switch_rep_status_end = """\
2171 } /* switch(header->message_type) */
2177 # Templates for get_CDR_xxx accessors
2180 template_get_CDR_ulong = """\
2181 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
2183 template_get_CDR_short = """\
2184 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
2186 template_get_CDR_void = """\
2187 /* Function returns void */
2189 template_get_CDR_long = """\
2190 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
2192 template_get_CDR_ushort = """\
2193 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
2195 template_get_CDR_float = """\
2196 proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
2198 template_get_CDR_double = """\
2199 proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
2201 template_get_CDR_longlong = """\
2202 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
2204 template_get_CDR_ulonglong = """\
2205 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
2207 template_get_CDR_boolean = """\
2208 proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
2210 template_get_CDR_char = """\
2211 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
2213 template_get_CDR_octet = """\
2214 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
2216 template_get_CDR_any = """\
2217 get_CDR_any(tvb,tree,offset,stream_is_big_endian, boundary, header);
2219 template_get_CDR_fixed = """\
2220 get_CDR_fixed(tvb, &seq, offset, @digits@, @scale@);
2221 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
2223 template_get_CDR_enum_symbolic = """\
2225 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2226 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
2228 template_get_CDR_string = """\
2229 giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, "@varname@");
2231 template_get_CDR_wstring = """\
2232 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2233 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ (%u) = %s",
2234 u_octet4, (u_octet4 > 0) ? seq : \"\");
2236 template_get_CDR_wchar = """\
2237 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2240 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
2243 s_octet1 = -s_octet1;
2246 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
2249 template_get_CDR_TypeCode = """\
2250 u_octet4 = get_CDR_typeCode(tvb, tree, offset, stream_is_big_endian, boundary, header);
2254 template_get_CDR_object = """\
2255 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2258 template_get_CDR_sequence_length = """\
2259 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2260 proto_tree_add_uint(tree, hf_@seqname@, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2262 template_get_CDR_sequence_loop_start = """\
2263 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2265 template_get_CDR_sequence_loop_end = """\
2269 template_get_CDR_sequence_octet = """\
2270 if (u_octet4_loop_@seqname@ > 0 && tree) {
2271 get_CDR_octet_seq(tvb, &binary_seq_@seqname@, offset,
2272 u_octet4_loop_@seqname@);
2273 text_seq_@seqname@ = make_printable_string(binary_seq_@seqname@,
2274 u_octet4_loop_@seqname@);
2275 proto_tree_add_text(tree, tvb, *offset - u_octet4_loop_@seqname@,
2276 u_octet4_loop_@seqname@, \"@seqname@: %s\", text_seq_@seqname@);
2279 template_get_CDR_array_start = """\
2280 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2282 template_get_CDR_array_end = """\
2285 template_get_CDR_array_comment = """\
2286 /* Array: @aname@[ @asize@] */
2288 template_structure_start = """\
2289 /* Begin struct \"@name@\" */"""
2291 template_structure_end = """\
2292 /* End struct \"@name@\" */"""
2294 template_union_start = """\
2295 /* Begin union \"@name@\" */"""
2297 template_union_end = """\
2298 /* End union \"@name@\" */"""
2301 # Templates for get_CDR_xxx_hf accessors
2304 template_get_CDR_ulong_hf = """\
2305 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2307 template_get_CDR_short_hf = """\
2308 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2310 template_get_CDR_long_hf = """\
2311 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2313 template_get_CDR_ushort_hf = """\
2314 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2316 template_get_CDR_float_hf = """\
2317 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2319 template_get_CDR_double_hf = """\
2320 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2322 template_get_CDR_longlong_hf = """\
2323 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2325 template_get_CDR_ulonglong_hf = """\
2326 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2328 template_get_CDR_boolean_hf = """\
2329 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""
2331 template_get_CDR_char_hf = """\
2332 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2334 template_get_CDR_octet_hf = """\
2335 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2337 template_get_CDR_enum_symbolic_hf = """\
2338 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2340 template_get_CDR_string_hf = """\
2341 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2343 template_get_CDR_wstring_hf = """\
2344 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2346 template_get_CDR_wchar_hf = """\
2347 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2349 template_get_CDR_TypeCode_hf = """\
2350 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2352 template_get_CDR_sequence_hf = """\
2353 {&hf_@hfname@, {"Seq length of @descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2355 template_get_CDR_sequence_octet_hf = """\
2356 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2359 # Program Header Template
2362 template_Header = """\
2363 /* packet-@dissector_name@.c
2367 * Routines for IDL dissection
2369 * Autogenerated from idl2wrs
2370 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2375 template_wireshark_copyright = """\
2377 * Wireshark - Network traffic analyzer
2379 * Copyright 1999 - 2012 Gerald Combs
2392 * This program is free software; you can redistribute it and/or
2393 * modify it under the terms of the GNU General Public License
2394 * as published by the Free Software Foundation; either version 2
2395 * of the License, or (at your option) any later version.
2397 * This program is distributed in the hope that it will be useful,
2398 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2399 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2400 * GNU General Public License for more details.
2402 * You should have received a copy of the GNU General Public License
2403 * along with this program; if not, write to the Free Software
2404 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2412 template_Includes = """\
2416 #include <gmodule.h>
2420 #include <epan/packet.h>
2421 #include <epan/proto.h>
2422 #include <epan/dissectors/packet-giop.h>
2423 #include <epan/expert.h>
2426 /* disable warning: "unreference local variable" */
2427 #pragma warning(disable:4101)
2433 # Main dissector entry templates
2436 template_main_dissector_start = """\
2438 * Called once we accept the packet as being for us; it sets the
2439 * Protocol and Info columns and creates the top-level protocol
2443 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
2446 proto_item *ti = NULL;
2447 proto_tree *tree = NULL; /* init later, inside if(tree) */
2449 col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2452 * Do not clear COL_INFO, as nothing is being written there by
2453 * this dissector yet. So leave it as is from the GIOP dissector.
2454 * TODO: add something useful to COL_INFO
2455 * col_clear(pinfo->cinfo, COL_INFO);
2459 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, -1, ENC_NA);
2460 tree = proto_item_add_subtree(ti, ett_@dissname@);
2466 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, gchar *operation)
2469 if(header->message_type == Reply) {
2470 /* fill-up info column */
2471 col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
2473 /* fill-up the field */
2474 pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
2475 PROTO_ITEM_SET_GENERATED(pi);
2480 dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname)
2483 gboolean stream_is_big_endian; /* big endianess */
2484 proto_item *item _U_;
2485 proto_tree *tree _U_;
2487 stream_is_big_endian = is_big_endian(header); /* get endianess */
2489 /* If we have a USER Exception, then decode it and return */
2491 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2493 return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
2497 template_main_dissector_switch_msgtype_start = """\
2498 switch(header->message_type) {
2500 template_main_dissector_switch_msgtype_start_request_reply = """\
2504 template_main_dissector_switch_msgtype_end_request_reply = """\
2508 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2512 case CloseConnection:
2515 return FALSE; /* not handled yet */
2518 return FALSE; /* not handled yet */
2522 template_main_dissector_end = """\
2526 } /* End of main dissector */
2535 #-------------------------------------------------------------#
2536 # Exception handling templates #
2537 #-------------------------------------------------------------#
2545 template_exception_helpers_start = """\
2546 /* Begin Exception Helper Functions */
2549 template_exception_helpers_end = """\
2551 /* End Exception Helper Functions */
2557 # template for Main delegator for exception handling
2560 template_main_exception_delegator_start = """\
2562 * Main delegator for exception handling
2566 decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, gchar *operation _U_, gboolean stream_is_big_endian _U_)
2569 proto_tree *tree _U_;
2571 if (!header->exception_id)
2577 # template for exception delegation code body
2579 template_ex_delegate_code = """\
2580 if (strcmp(header->exception_id, "@exname@") == 0) {
2581 tree = start_dissecting(tvb, pinfo, ptree, offset);
2582 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian); /* @exname@ */
2589 # End of Main delegator for exception handling
2592 template_main_exception_delegator_end = """\
2595 return FALSE; /* user exception not found */
2601 # template for exception helper code
2605 template_exception_helper_function_start = """\
2606 /* Exception = @exname@ */
2608 decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_, gboolean stream_is_big_endian _U_)
2612 template_exception_helper_function_end = """\
2618 # template for struct helper code
2622 template_struct_helper_function_start = """\
2623 /* Struct = @stname@ */
2625 decode_@sname@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_, gboolean stream_is_big_endian _U_)
2629 template_struct_helper_function_end = """\
2634 # template for union helper code
2638 template_union_helper_function_start = """\
2639 /* Union = @unname@ */
2641 decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_, gboolean stream_is_big_endian _U_)
2645 template_union_helper_function_end = """\
2651 #-------------------------------------------------------------#
2652 # Value string templates #
2653 #-------------------------------------------------------------#
2655 template_value_string_start = """\
2656 static const value_string @valstringname@[] = {
2658 template_value_string_entry = """\
2659 { @intval@, \"@description@\" },"""
2661 template_value_string_end = """\
2668 #-------------------------------------------------------------#
2669 # Enum handling templates #
2670 #-------------------------------------------------------------#
2672 template_comment_enums_start = """\
2677 template_comment_enums_end = """\
2682 template_comment_enum_comment = """\
2689 #-------------------------------------------------------------#
2690 # Attribute handling templates #
2691 #-------------------------------------------------------------#
2694 template_comment_attributes_start = """\
2696 * IDL Attributes Start
2701 # get/set accessor method names are language mapping dependant.
2704 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2705 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2707 template_comment_attributes_end = """
2709 * IDL Attributes End
2715 # template for Attribute delegation code
2717 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2718 # Note: _set_xxx() should only be called for Request
2722 template_at_delegate_code_get = """\
2723 if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2724 tree = start_dissecting(tvb, pinfo, ptree, offset);
2725 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2729 template_at_delegate_code_set = """\
2730 if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
2731 tree = start_dissecting(tvb, pinfo, ptree, offset);
2732 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2736 template_attribute_helpers_start = """\
2737 /* Begin Attribute Helper Functions */
2739 template_attribute_helpers_end = """\
2741 /* End Attribute Helper Functions */
2745 # template for attribute helper code
2749 template_attribute_helper_function_start = """\
2751 /* Attribute = @atname@ */
2753 decode_@sname@_at(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_, gboolean stream_is_big_endian _U_)
2757 template_attribute_helper_function_end = """\
2762 #-------------------------------------------------------------#
2763 # Debugging templates #
2764 #-------------------------------------------------------------#
2767 # Template for outputting TODO "C" comments
2768 # so user know I need ti improve something.
2771 template_debug_TODO = """\
2773 /* TODO - @message@ */
2776 # Template for outputting WARNING "C" comments
2777 # so user know if I have found a problem.
2780 template_debug_WARNING = """\
2781 /* WARNING - @message@ */
2786 #-------------------------------------------------------------#
2787 # IDL Union templates #
2788 #-------------------------------------------------------------#
2790 template_comment_union_code_start = """\
2792 * IDL Union Start - @uname@
2795 template_comment_union_code_end = """
2797 * IDL union End - @uname@
2800 template_comment_union_code_discriminant = """\
2802 * IDL Union - Discriminant - @uname@
2806 # Cast Unions types to something appropriate
2807 # Enum value cast to guint32, all others cast to gint32
2808 # as omniidl accessor returns integer or Enum.
2811 template_union_code_save_discriminant_enum = """\
2812 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2814 template_union_code_save_discriminant_long = """\
2815 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2818 template_union_code_save_discriminant_ulong = """\
2819 disc_s_@discname@ = (gint32) u_octet4; /* save guint32 discriminant and cast to gint32 */
2821 template_union_code_save_discriminant_short = """\
2822 disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
2825 template_union_code_save_discriminant_ushort = """\
2826 disc_s_@discname@ = (gint32) u_octet2; /* save guint16 discriminant and cast to gint32 */
2828 template_union_code_save_discriminant_char = """\
2829 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2831 template_union_code_save_discriminant_boolean = """\
2832 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2834 template_comment_union_code_label_compare_start = """\
2835 if (disc_s_@discname@ == @labelval@) {
2837 template_comment_union_code_label_compare_end = """\
2838 return; /* End Compare for this discriminant type */
2843 template_comment_union_code_label_default_start = """
2844 /* Default Union Case Start */
2846 template_comment_union_code_label_default_end = """\
2847 /* Default Union Case End */
2851 # Templates for function prototypes.
2852 # This is used in genDeclares() for declaring function prototypes
2853 # for structs and union helper functions.
2856 template_hf_operations = """
2857 static int hf_operationrequest = -1;/* Request_Operation field */
2861 static int hf_@name@ = -1;"""
2863 template_prototype_start_dissecting = """
2864 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
2867 template_prototype_struct_start = """
2868 /* Struct prototype declaration Start */
2870 template_prototype_struct_end = """
2871 /* Struct prototype declaration End */
2873 template_prototype_struct_body = """
2874 /* Struct = @stname@ */
2875 static void decode_@name@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_, gboolean stream_is_big_endian _U_);
2877 template_decode_struct = """\
2878 decode_@name@_st(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);"""
2880 template_prototype_union_start = """\
2881 /* Union prototype declaration Start */"""
2883 template_prototype_union_end = """\
2884 /* Union prototype declaration End */"""
2886 template_prototype_union_body = """
2887 /* Union = @unname@ */
2888 static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_, gboolean stream_is_big_endian _U_);
2890 template_decode_union = """
2891 decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);