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
200 self.genDeclares(oplist,atlist,enlist,stlist,unlist)
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
232 # Generate Standard Wireshark Header Comments
237 self.st.out(self.template_Header,dissector_name=self.dissname)
239 print "XXX genHeader"
247 # Wireshark Copyright Info
251 def genEthCopyright(self):
253 print "XXX genEthCopyright"
254 self.st.out(self.template_wireshark_copyright)
264 def genModelines(self):
266 print "XXX genModelines"
268 self.st.out(self.template_Modelines)
282 self.st.out(self.template_GPL)
291 def genIncludes(self):
293 print "XXX genIncludes"
295 self.st.out(self.template_Includes)
300 # Generate hf variables for operation filters
302 # in: opnode ( an operation node)
305 def genOpDeclares(self, op):
307 print "XXX genOpDeclares"
308 print "XXX return type = " , op.returnType().kind()
310 sname = self.namespace(op, "_")
313 if (rt.kind() != idltype.tk_void):
314 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
315 #self.get_CDR_alias(rt, rt.name() )
316 self.st.out(self.template_hf, name=sname + "_return")
318 self.st.out(self.template_hf, name=sname + "_return")
320 for p in op.parameters():
321 self.st.out(self.template_hf, name=sname + "_" + p.identifier())
326 # Generate hf variables for attributes
328 # in: at ( an attribute)
331 def genAtDeclares(self, at):
333 print "XXX genAtDeclares"
335 for decl in at.declarators():
336 sname = self.namespace(decl, "_")
338 self.st.out(self.template_hf, name="get" + "_" + sname + "_" + decl.identifier())
339 if not at.readonly():
340 self.st.out(self.template_hf, name="set" + "_" + sname + "_" + decl.identifier())
345 # Generate hf variables for structs
350 def genStDeclares(self, st):
352 print "XXX genStDeclares"
354 sname = self.namespace(st, "_")
356 for m in st.members():
357 for decl in m.declarators():
358 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
363 # Generate hf variables for user exception filters
365 # in: exnode ( an exception node)
368 def genExDeclares(self,ex):
370 print "XXX genExDeclares"
372 sname = self.namespace(ex, "_")
374 for m in ex.members():
375 for decl in m.declarators():
376 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
381 # Generate hf variables for union filters
386 def genUnionDeclares(self,un):
388 print "XXX genUnionDeclares"
390 sname = self.namespace(un, "_")
391 self.st.out(self.template_hf, name=sname + "_" + un.identifier())
393 for uc in un.cases(): # for all UnionCase objects in this union
394 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
395 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
399 # genExpertInfoDeclares()
401 # Generate ei variables for expert info filters
404 def genExpertInfoDeclares(self):
406 print "XXX genExpertInfoDeclares"
408 self.st.out(self.template_proto_register_ei_filters, dissector_name=self.dissname)
413 # generate function prototypes if required
415 # Currently this is used for struct and union helper function declarations.
419 def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
421 print "XXX genDeclares"
423 # prototype for operation filters
424 self.st.out(self.template_hf_operations)
426 #operation specific filters
427 if (len(oplist) > 0):
428 self.st.out(self.template_proto_register_op_filter_comment)
430 self.genOpDeclares(op)
433 if (len(atlist) > 0):
434 self.st.out(self.template_proto_register_at_filter_comment)
436 self.genAtDeclares(at)
439 if (len(stlist) > 0):
440 self.st.out(self.template_proto_register_st_filter_comment)
442 self.genStDeclares(st)
444 # exception List filters
445 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
446 if (len(exlist) > 0):
447 self.st.out(self.template_proto_register_ex_filter_comment)
449 if (ex.members()): # only if has members
450 self.genExDeclares(ex)
453 if (len(unlist) > 0):
454 self.st.out(self.template_proto_register_un_filter_comment)
456 self.genUnionDeclares(un)
459 self.genExpertInfoDeclares()
461 # prototype for start_dissecting()
463 self.st.out(self.template_prototype_start_dissecting)
468 self.st.out(self.template_prototype_struct_start)
471 sname = self.namespace(st, "_")
472 self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
474 self.st.out(self.template_prototype_struct_end)
478 self.st.out(self.template_prototype_union_start)
480 sname = self.namespace(un, "_")
481 self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
482 self.st.out(self.template_prototype_union_end)
490 def genPrototype(self):
491 self.st.out(self.template_prototype, dissector_name=self.dissname)
498 def genProtocol(self):
499 self.st.out(self.template_protocol, dissector_name=self.dissname)
500 self.st.out(self.template_init_boundary)
506 def genMainEntryStart(self,oplist):
507 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
509 self.st.out(self.template_main_dissector_switch_msgtype_start)
510 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
518 def genMainEntryEnd(self):
520 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
522 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
524 self.st.out(self.template_main_dissector_end)
532 # out: C code for IDL attribute decalarations.
534 # NOTE: Mapping of attributes to operation(function) names is tricky.
536 # The actual accessor function names are language-mapping specific. The attribute name
537 # is subject to OMG IDL's name scoping rules; the accessor function names are
538 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
542 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
543 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
547 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
548 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
550 # TODO: Implement some language dependant templates to handle naming conventions
551 # language <=> attribute. for C, C++. Java etc
553 # OR, just add a runtime GUI option to select language binding for attributes -- FS
557 # ie: def genAtlist(self,atlist,language)
562 def genAtList(self,atlist):
563 self.st.out(self.template_comment_attributes_start)
566 for i in n.declarators(): #
567 sname = self.namespace(i, "_")
568 atname = i.identifier()
569 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
571 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
573 self.st.out(self.template_comment_attributes_end)
581 # out: C code for IDL Enum decalarations using "static const value_string" template
586 def genEnList(self,enlist):
588 self.st.out(self.template_comment_enums_start)
591 sname = self.namespace(enum, "_")
593 self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
594 self.st.out(self.template_value_string_start, valstringname=sname)
595 for enumerator in enum.enumerators():
596 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
599 #atname = n.identifier()
600 self.st.out(self.template_value_string_end, valstringname=sname)
602 self.st.out(self.template_comment_enums_end)
614 # genExceptionDelegator
618 # out: C code for User exception delegator
624 def genExceptionDelegator(self,oplist):
626 self.st.out(self.template_main_exception_delegator_start)
629 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
633 print "XXX Exception " , ex.repoId()
634 print "XXX Exception Identifier" , ex.identifier()
635 print "XXX Exception Scoped Name" , ex.scopedName()
637 if (ex.members()): # only if has members
638 sname = self.namespace(ex, "_")
640 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
643 self.st.out(self.template_main_exception_delegator_end)
647 # genAttribueHelpers()
649 # Generate private helper functions to decode Attributes.
653 # For readonly attribute - generate get_xxx()
654 # If NOT readonly attribute - also generate set_xxx()
657 def genAttributeHelpers(self,atlist):
659 print "XXX genAttributeHelpers: atlist = ", atlist
661 self.st.out(self.template_attribute_helpers_start)
663 for attrib in atlist:
664 for decl in attrib.declarators():
665 self.genAtHelper(attrib,decl,"get") # get accessor
666 if not attrib.readonly():
667 self.genAtHelper(attrib,decl,"set") # set accessor
669 self.st.out(self.template_attribute_helpers_end)
674 # Generate private helper functions to decode an attribute
676 # in: at - attribute node
677 # in: decl - declarator belonging to this attribute
678 # in: order - to generate a "get" or "set" helper
680 def genAtHelper(self,attrib,decl,order):
682 print "XXX genAtHelper"
684 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
685 self.curr_sname = sname # update current opnode/exnode scoped name
687 if not self.fn_hash_built:
688 self.fn_hash[sname] = [] # init empty list as val for this sname key
689 # but only if the fn_hash is not already built
691 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
694 if (len(self.fn_hash[sname]) > 0):
695 self.st.out(self.template_helper_function_vars_start)
696 self.dumpCvars(sname)
697 self.st.out(self.template_helper_function_vars_end )
699 self.getCDR(attrib.attrType(), sname + "_" + decl.identifier() )
702 self.st.out(self.template_attribute_helper_function_end)
707 # genExceptionHelpers()
709 # Generate private helper functions to decode Exceptions used
716 def genExceptionHelpers(self,oplist):
717 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
719 print "XXX genExceptionHelpers: exlist = ", exlist
721 self.st.out(self.template_exception_helpers_start)
723 if (ex.members()): # only if has members
724 #print "XXX Exception = " + ex.identifier()
727 self.st.out(self.template_exception_helpers_end)
733 # Generate private helper functions to decode User Exceptions
735 # in: exnode ( an exception node)
738 def genExHelper(self,ex):
740 print "XXX genExHelper"
742 sname = self.namespace(ex, "_")
743 self.curr_sname = sname # update current opnode/exnode scoped name
744 if not self.fn_hash_built:
745 self.fn_hash[sname] = [] # init empty list as val for this sname key
746 # but only if the fn_hash is not already built
748 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
751 if (len(self.fn_hash[sname]) > 0):
752 self.st.out(self.template_helper_function_vars_start)
753 self.dumpCvars(sname)
754 self.st.out(self.template_helper_function_vars_end )
756 for m in ex.members():
758 print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
760 for decl in m.declarators():
762 print "XXX genExhelper, d = ", decl
764 if decl.sizes(): # an array
765 indices = self.get_indices_from_sizes(decl.sizes())
766 string_indices = '%i ' % indices # convert int to string
767 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
768 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
769 self.addvar(self.c_i + decl.identifier() + ";")
772 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
775 self.st.out(self.template_get_CDR_array_end)
779 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
782 self.st.out(self.template_exception_helper_function_end)
788 # Generate private helper functions for each IDL operation.
789 # Generate private helper functions for each IDL struct.
790 # Generate private helper functions for each IDL union.
793 # in: oplist, stlist, unlist
797 def genHelpers(self,oplist,stlist,unlist):
799 self.genOperation(op)
801 self.genStructHelper(st)
803 self.genUnionHelper(un)
808 # Generate private helper functions for a specificIDL operation.
813 def genOperation(self,opnode):
815 print "XXX genOperation called"
817 sname = self.namespace(opnode, "_")
818 if not self.fn_hash_built:
819 self.fn_hash[sname] = [] # init empty list as val for this sname key
820 # but only if the fn_hash is not already built
822 self.curr_sname = sname # update current opnode's scoped name
823 opname = opnode.identifier()
825 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
827 self.st.out(self.template_helper_function_start, sname=sname)
830 if (len(self.fn_hash[sname]) > 0):
831 self.st.out(self.template_helper_function_vars_start)
832 self.dumpCvars(sname)
833 self.st.out(self.template_helper_function_vars_end )
835 self.st.out(self.template_helper_switch_msgtype_start)
837 self.st.out(self.template_helper_switch_msgtype_request_start)
839 self.genOperationRequest(opnode)
840 self.st.out(self.template_helper_switch_msgtype_request_end)
843 self.st.out(self.template_helper_switch_msgtype_reply_start)
846 self.st.out(self.template_helper_switch_rep_status_start)
849 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
851 self.genOperationReply(opnode)
852 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
855 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
857 self.genOpExceptions(opnode)
858 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
861 self.st.out(self.template_helper_switch_msgtype_reply_default_start, dissector_name=self.dissname)
862 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
864 self.st.out(self.template_helper_switch_rep_status_end)
868 self.st.out(self.template_helper_switch_msgtype_default_start, dissector_name=self.dissname)
869 self.st.out(self.template_helper_switch_msgtype_default_end)
871 self.st.out(self.template_helper_switch_msgtype_end)
875 self.st.out(self.template_helper_function_end, sname=sname)
881 # Decode function parameters for a GIOP request message
885 def genOperationRequest(self,opnode):
886 for p in opnode.parameters():
889 print "XXX parameter = " ,p
890 print "XXX parameter type = " ,p.paramType()
891 print "XXX parameter type kind = " ,p.paramType().kind()
893 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
897 # Decode function parameters for a GIOP reply message
901 def genOperationReply(self,opnode):
903 rt = opnode.returnType() # get return type
905 print "XXX genOperationReply"
906 print "XXX opnode = " , opnode
907 print "XXX return type = " , rt
908 print "XXX return type.unalias = " , rt.unalias()
909 print "XXX return type.kind() = " , rt.kind();
911 sname = self.namespace(opnode, "_")
913 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
914 #self.getCDR(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
915 self.get_CDR_alias(rt, sname + "_return" )
916 #self.get_CDR_alias(rt, rt.name() )
919 self.getCDR(rt, sname + "_return") # return value is NOT an alias
921 for p in opnode.parameters():
922 if p.is_out(): # out or inout
923 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
925 #self.st.dec_indent()
927 def genOpExceptions(self,opnode):
928 for ex in opnode.raises():
931 for m in ex.members():
933 #print m.memberType(), m.memberType().kind()
935 # Delegator for Operations
938 def genOpDelegator(self,oplist):
940 iname = "/".join(op.scopedName()[:-1])
941 opname = op.identifier()
942 sname = self.namespace(op, "_")
943 self.st.out(self.template_op_delegate_code, interface=iname, sname=sname, opname=opname)
946 # Delegator for Attributes
949 def genAtDelegator(self,atlist):
951 for i in a.declarators():
952 atname = i.identifier()
953 sname = self.namespace(i, "_")
954 self.st.out(self.template_at_delegate_code_get, sname=sname)
956 self.st.out(self.template_at_delegate_code_set, sname=sname)
960 # Add a variable declaration to the hash of list
963 def addvar(self, var):
964 if not ( var in self.fn_hash[self.curr_sname] ):
965 self.fn_hash[self.curr_sname].append(var)
968 # Print the variable declaration from the hash of list
973 for fn in self.fn_hash.keys():
975 for v in self.fn_hash[fn]:
978 # Print the "C" variable declaration from the hash of list
979 # for a given scoped operation name (eg: tux_penguin_eat)
983 def dumpCvars(self, sname):
984 for v in self.fn_hash[sname]:
989 # Given an enum node, and a enumerator node, return
990 # the enumerator's numerical value.
992 # eg: enum Color {red,green,blue} should return
996 def valFromEnum(self,enumNode, enumeratorNode):
998 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
999 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
1001 if isinstance(enumeratorNode,idlast.Enumerator):
1002 value = enumNode.enumerators().index(enumeratorNode)
1019 ## tk_Principal = 13
1030 ## tk_ulonglong = 24
1031 ## tk_longdouble = 25
1036 ## tk_value_box = 30
1038 ## tk_abstract_interface = 32
1044 # This is the main "iterator" function. It takes a node, and tries to output
1045 # a get_CDR_XXX accessor method(s). It can call itself multiple times
1046 # if I find nested structures etc.
1049 def getCDR(self,type,name="fred"):
1051 pt = type.unalias().kind() # param CDR type
1052 pn = name # param name
1055 print "XXX getCDR: kind = " , pt
1056 print "XXX getCDR: name = " , pn
1058 if pt == idltype.tk_ulong:
1059 self.get_CDR_ulong(pn)
1060 elif pt == idltype.tk_longlong:
1061 self.get_CDR_longlong(pn)
1062 elif pt == idltype.tk_ulonglong:
1063 self.get_CDR_ulonglong(pn)
1064 elif pt == idltype.tk_void:
1065 self.get_CDR_void(pn)
1066 elif pt == idltype.tk_short:
1067 self.get_CDR_short(pn)
1068 elif pt == idltype.tk_long:
1069 self.get_CDR_long(pn)
1070 elif pt == idltype.tk_ushort:
1071 self.get_CDR_ushort(pn)
1072 elif pt == idltype.tk_float:
1073 self.get_CDR_float(pn)
1074 elif pt == idltype.tk_double:
1075 self.get_CDR_double(pn)
1076 elif pt == idltype.tk_fixed:
1077 self.get_CDR_fixed(type.unalias(),pn)
1078 elif pt == idltype.tk_boolean:
1079 self.get_CDR_boolean(pn)
1080 elif pt == idltype.tk_char:
1081 self.get_CDR_char(pn)
1082 elif pt == idltype.tk_octet:
1083 self.get_CDR_octet(pn)
1084 elif pt == idltype.tk_any:
1085 self.get_CDR_any(pn)
1086 elif pt == idltype.tk_string:
1087 self.get_CDR_string(pn)
1088 elif pt == idltype.tk_wstring:
1089 self.get_CDR_wstring(pn)
1090 elif pt == idltype.tk_wchar:
1091 self.get_CDR_wchar(pn)
1092 elif pt == idltype.tk_enum:
1094 self.get_CDR_enum(pn,type)
1095 #self.get_CDR_enum(pn)
1097 elif pt == idltype.tk_struct:
1098 self.get_CDR_struct(type,pn)
1099 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1100 self.get_CDR_TypeCode(pn)
1101 elif pt == idltype.tk_sequence:
1102 if type.unalias().seqType().kind() == idltype.tk_octet:
1103 self.get_CDR_sequence_octet(type,pn)
1105 self.get_CDR_sequence(type,pn)
1106 elif pt == idltype.tk_objref:
1107 self.get_CDR_objref(type,pn)
1108 elif pt == idltype.tk_array:
1109 pn = pn # Supported elsewhere
1110 elif pt == idltype.tk_union:
1111 self.get_CDR_union(type,pn)
1112 elif pt == idltype.tk_alias:
1114 print "XXXXX Alias type XXXXX " , type
1115 self.get_CDR_alias(type,pn)
1117 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1121 # get_CDR_XXX methods are here ..
1126 def get_CDR_ulong(self,pn):
1127 self.st.out(self.template_get_CDR_ulong, hfname=pn)
1129 def get_CDR_short(self,pn):
1130 self.st.out(self.template_get_CDR_short, hfname=pn)
1132 def get_CDR_void(self,pn):
1133 self.st.out(self.template_get_CDR_void, hfname=pn)
1135 def get_CDR_long(self,pn):
1136 self.st.out(self.template_get_CDR_long, hfname=pn)
1138 def get_CDR_ushort(self,pn):
1139 self.st.out(self.template_get_CDR_ushort, hfname=pn)
1141 def get_CDR_float(self,pn):
1142 self.st.out(self.template_get_CDR_float, hfname=pn)
1144 def get_CDR_double(self,pn):
1145 self.st.out(self.template_get_CDR_double, hfname=pn)
1147 def get_CDR_longlong(self,pn):
1148 self.st.out(self.template_get_CDR_longlong, hfname=pn)
1150 def get_CDR_ulonglong(self,pn):
1151 self.st.out(self.template_get_CDR_ulonglong, hfname=pn)
1153 def get_CDR_boolean(self,pn):
1154 self.st.out(self.template_get_CDR_boolean, hfname=pn)
1156 def get_CDR_fixed(self,type,pn):
1158 print "XXXX calling get_CDR_fixed, type = ", type
1159 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1160 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1162 string_digits = '%i ' % type.digits() # convert int to string
1163 string_scale = '%i ' % type.scale() # convert int to string
1164 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
1166 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1167 self.addvar(self.c_seq)
1170 def get_CDR_char(self,pn):
1171 self.st.out(self.template_get_CDR_char, hfname=pn)
1173 def get_CDR_octet(self,pn):
1174 self.st.out(self.template_get_CDR_octet, hfname=pn)
1176 def get_CDR_any(self,pn):
1177 self.st.out(self.template_get_CDR_any, varname=pn)
1179 def get_CDR_enum(self,pn,type):
1180 #self.st.out(self.template_get_CDR_enum, hfname=pn)
1181 sname = self.namespace(type.unalias(), "_")
1182 self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname,hfname=pn)
1183 self.addvar(self.c_u_octet4)
1185 def get_CDR_string(self,pn):
1186 self.st.out(self.template_get_CDR_string, hfname=pn)
1188 def get_CDR_wstring(self,pn):
1189 self.st.out(self.template_get_CDR_wstring, varname=pn)
1190 self.addvar(self.c_u_octet4)
1191 self.addvar(self.c_seq)
1193 def get_CDR_wchar(self,pn):
1194 self.st.out(self.template_get_CDR_wchar, varname=pn)
1195 self.addvar(self.c_s_octet1)
1196 self.addvar(self.c_seq)
1198 def get_CDR_TypeCode(self,pn):
1199 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1200 self.addvar(self.c_u_octet4)
1202 def get_CDR_objref(self,type,pn):
1203 self.st.out(self.template_get_CDR_object)
1205 def get_CDR_sequence_len(self,pn):
1206 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1209 def get_CDR_union(self,type,pn):
1211 print "XXX Union type =" , type, " pn = ",pn
1212 print "XXX Union type.decl()" , type.decl()
1213 print "XXX Union Scoped Name" , type.scopedName()
1215 # If I am a typedef union {..}; node then find the union node
1217 if isinstance(type.decl(), idlast.Declarator):
1218 ntype = type.decl().alias().aliasType().decl()
1220 ntype = type.decl() # I am a union node
1223 print "XXX Union ntype =" , ntype
1225 sname = self.namespace(ntype, "_")
1226 self.st.out(self.template_union_start, name=sname )
1228 # Output a call to the union helper function so I can handle recursive union also.
1230 self.st.out(self.template_decode_union,name=sname)
1232 self.st.out(self.template_union_end, name=sname )
1237 # This takes a node, and tries to output the appropriate item for the
1241 def getCDR_hf(self,type,desc,filter,hf_name="fred"):
1243 pt = type.unalias().kind() # param CDR type
1244 pn = hf_name # param name
1247 print "XXX getCDR_hf: kind = " , pt
1248 print "XXX getCDR_hf: name = " , pn
1250 if pt == idltype.tk_ulong:
1251 self.get_CDR_ulong_hf(pn, desc, filter, self.dissname)
1252 elif pt == idltype.tk_longlong:
1253 self.get_CDR_longlong_hf(pn, desc, filter, self.dissname)
1254 elif pt == idltype.tk_ulonglong:
1255 self.get_CDR_ulonglong_hf(pn, desc, filter, self.dissname)
1256 elif pt == idltype.tk_void:
1257 pt = pt # no hf_ variables needed
1258 elif pt == idltype.tk_short:
1259 self.get_CDR_short_hf(pn, desc, filter, self.dissname)
1260 elif pt == idltype.tk_long:
1261 self.get_CDR_long_hf(pn, desc, filter, self.dissname)
1262 elif pt == idltype.tk_ushort:
1263 self.get_CDR_ushort_hf(pn, desc, filter, self.dissname)
1264 elif pt == idltype.tk_float:
1265 self.get_CDR_float_hf(pn, desc, filter, self.dissname)
1266 elif pt == idltype.tk_double:
1267 self.get_CDR_double_hf(pn, desc, filter, self.dissname)
1268 elif pt == idltype.tk_fixed:
1269 pt = pt # no hf_ variables needed
1270 elif pt == idltype.tk_boolean:
1271 self.get_CDR_boolean_hf(pn, desc, filter, self.dissname)
1272 elif pt == idltype.tk_char:
1273 self.get_CDR_char_hf(pn, desc, filter, self.dissname)
1274 elif pt == idltype.tk_octet:
1275 self.get_CDR_octet_hf(pn, desc, filter, self.dissname)
1276 elif pt == idltype.tk_any:
1277 pt = pt # no hf_ variables needed
1278 elif pt == idltype.tk_string:
1279 self.get_CDR_string_hf(pn, desc, filter, self.dissname)
1280 elif pt == idltype.tk_wstring:
1281 self.get_CDR_wstring_hf(pn, desc, filter, self.dissname)
1282 elif pt == idltype.tk_wchar:
1283 self.get_CDR_wchar_hf(pn, desc, filter, self.dissname)
1284 elif pt == idltype.tk_enum:
1285 self.get_CDR_enum_hf(pn, type, desc, filter, self.dissname)
1286 elif pt == idltype.tk_struct:
1287 pt = pt # no hf_ variables needed (should be already contained in struct members)
1288 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1289 self.get_CDR_TypeCode_hf(pn, desc, filter, self.dissname)
1290 elif pt == idltype.tk_sequence:
1291 if type.unalias().seqType().kind() == idltype.tk_octet:
1292 self.get_CDR_sequence_octet_hf(type, pn, desc, filter, self.dissname)
1294 self.get_CDR_sequence_hf(type, pn, desc, filter, self.dissname)
1295 elif pt == idltype.tk_objref:
1296 pt = pt # no object specific hf_ variables used, use generic ones from giop dissector
1297 elif pt == idltype.tk_array:
1298 pt = pt # Supported elsewhere
1299 elif pt == idltype.tk_union:
1300 pt = pt # no hf_ variables needed (should be already contained in union members)
1301 elif pt == idltype.tk_alias:
1303 print "XXXXX Alias type hf XXXXX " , type
1304 self.get_CDR_alias_hf(type,pn)
1306 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1309 # get_CDR_XXX_hf methods are here ..
1314 def get_CDR_ulong_hf(self,pn,desc,filter,diss):
1315 self.st.out(self.template_get_CDR_ulong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1317 def get_CDR_short_hf(self,pn,desc,filter,diss):
1318 self.st.out(self.template_get_CDR_short_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1320 def get_CDR_long_hf(self,pn,desc,filter,diss):
1321 self.st.out(self.template_get_CDR_long_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1323 def get_CDR_ushort_hf(self,pn,desc,filter,diss):
1324 self.st.out(self.template_get_CDR_ushort_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1326 def get_CDR_float_hf(self,pn,desc,filter,diss):
1327 self.st.out(self.template_get_CDR_float_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1329 def get_CDR_double_hf(self,pn,desc,filter,diss):
1330 self.st.out(self.template_get_CDR_double_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1332 def get_CDR_longlong_hf(self,pn,desc,filter,diss):
1333 self.st.out(self.template_get_CDR_longlong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1335 def get_CDR_ulonglong_hf(self,pn,desc,filter,diss):
1336 self.st.out(self.template_get_CDR_ulonglong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1338 def get_CDR_boolean_hf(self,pn,desc,filter,diss):
1339 self.st.out(self.template_get_CDR_boolean_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1341 def get_CDR_char_hf(self,pn,desc,filter,diss):
1342 self.st.out(self.template_get_CDR_char_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1344 def get_CDR_octet_hf(self,pn,desc,filter,diss):
1345 self.st.out(self.template_get_CDR_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1347 def get_CDR_enum_hf(self,pn,type,desc,filter,diss):
1348 sname = self.namespace(type.unalias(), "_")
1349 self.st.out(self.template_get_CDR_enum_symbolic_hf, valstringarray=sname,hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1351 def get_CDR_string_hf(self,pn,desc,filter,diss):
1352 self.st.out(self.template_get_CDR_string_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1354 def get_CDR_wstring_hf(self,pn,desc,filter,diss):
1355 self.st.out(self.template_get_CDR_wstring_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1356 # self.addvar(self.c_u_octet4)
1357 # self.addvar(self.c_seq)
1359 def get_CDR_wchar_hf(self,pn,desc,filter,diss):
1360 self.st.out(self.template_get_CDR_wchar_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1361 # self.addvar(self.c_s_octet1)
1362 # self.addvar(self.c_seq)
1364 def get_CDR_TypeCode_hf(self,pn,desc,filter,diss):
1365 self.st.out(self.template_get_CDR_TypeCode_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1367 def get_CDR_sequence_octet_hf(self,type,pn,desc,filter,diss):
1368 self.st.out(self.template_get_CDR_sequence_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1370 def get_CDR_sequence_hf(self,type,pn,desc,filter,diss):
1371 self.st.out(self.template_get_CDR_sequence_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1373 def get_CDR_alias_hf(self,type,pn):
1375 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1376 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1377 print "XXX get_CDR_alias_hf, type.decl().alias() = " ,type.decl().alias()
1379 decl = type.decl() # get declarator object
1381 if (decl.sizes()): # a typedef array
1382 #indices = self.get_indices_from_sizes(decl.sizes())
1383 #string_indices = '%i ' % indices # convert int to string
1384 #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1386 #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1387 #self.addvar(self.c_i + pn + ";")
1388 #self.st.inc_indent()
1389 self.getCDR_hf(type.decl().alias().aliasType(), pn )
1391 #self.st.dec_indent()
1392 #self.st.out(self.template_get_CDR_array_end)
1395 else: # a simple typdef
1397 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1398 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1400 self.getCDR_hf(type, decl.identifier() )
1404 # Code to generate Union Helper functions
1406 # in: un - a union node
1411 def genUnionHelper(self,un):
1413 print "XXX genUnionHelper called"
1414 print "XXX Union type =" , un
1415 print "XXX Union type.switchType()" , un.switchType()
1416 print "XXX Union Scoped Name" , un.scopedName()
1418 sname = self.namespace(un, "_")
1419 self.curr_sname = sname # update current opnode/exnode/stnode/unnode scoped name
1420 if not self.fn_hash_built:
1421 self.fn_hash[sname] = [] # init empty list as val for this sname key
1422 # but only if the fn_hash is not already built
1424 self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
1425 self.st.inc_indent()
1427 if (len(self.fn_hash[sname]) > 0):
1428 self.st.out(self.template_helper_function_vars_start)
1429 self.dumpCvars(sname)
1430 self.st.out(self.template_helper_function_vars_end )
1432 st = un.switchType().unalias() # may be typedef switch type, so find real type
1434 self.st.out(self.template_comment_union_code_start, uname=un.repoId() )
1436 self.getCDR(st, sname + "_" + un.identifier());
1438 # Depending on what kind of discriminant I come accross (enum,integer,char,
1439 # short, boolean), make sure I cast the return value of the get_XXX accessor
1440 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1441 # return an integer, or an Enumerator object that is then converted to its
1442 # integer equivalent.
1445 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1448 if (st.kind() == idltype.tk_enum):
1450 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1451 self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
1452 self.addvar(self.c_s_disc + un.identifier() + ";")
1454 elif (st.kind() == idltype.tk_long):
1455 self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
1456 self.addvar(self.c_s_disc + un.identifier() + ";")
1458 elif (st.kind() == idltype.tk_ulong):
1459 self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
1460 self.addvar(self.c_s_disc + un.identifier() + ";")
1462 elif (st.kind() == idltype.tk_short):
1463 self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
1464 self.addvar(self.c_s_disc + un.identifier() + ";")
1466 elif (st.kind() == idltype.tk_ushort):
1467 self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
1468 self.addvar(self.c_s_disc + un.identifier() + ";")
1470 elif (st.kind() == idltype.tk_boolean):
1471 self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier() )
1472 self.addvar(self.c_s_disc + un.identifier() + ";")
1474 elif (st.kind() == idltype.tk_char):
1475 self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
1476 self.addvar(self.c_s_disc + un.identifier() + ";")
1479 print "XXX Unknown st.kind() = ", st.kind()
1482 # Loop over all cases in this union
1485 for uc in un.cases(): # for all UnionCase objects in this union
1486 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1488 # get integer value, even if discriminant is
1489 # an Enumerator node
1491 if isinstance(cl.value(),idlast.Enumerator):
1493 print "XXX clv.identifier()", cl.value().identifier()
1494 print "XXX clv.repoId()", cl.value().repoId()
1495 print "XXX clv.scopedName()", cl.value().scopedName()
1497 # find index of enumerator in enum declaration
1498 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1500 clv = self.valFromEnum(std,cl.value())
1505 #print "XXX clv = ",clv
1508 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1509 # eg: if (disc == 'b')..
1511 # TODO : handle \xxx chars generically from a function or table lookup rather than
1512 # a whole bunch of "if" statements. -- FS
1515 if (st.kind() == idltype.tk_char):
1516 if (clv == '\n'): # newline
1517 string_clv = "'\\n'"
1518 elif (clv == '\t'): # tab
1519 string_clv = "'\\t'"
1521 string_clv = "'" + clv + "'"
1523 string_clv = '%i ' % clv
1526 # If default case, then skp comparison with discriminator
1529 if not cl.default():
1530 self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
1531 self.st.inc_indent()
1533 self.st.out(self.template_comment_union_code_label_default_start )
1536 self.getCDR(uc.caseType(),sname + "_" + uc.declarator().identifier())
1538 if not cl.default():
1539 self.st.dec_indent()
1540 self.st.out(self.template_comment_union_code_label_compare_end )
1542 self.st.out(self.template_comment_union_code_label_default_end )
1544 self.st.dec_indent()
1545 self.st.out(self.template_union_helper_function_end)
1550 # Currently, get_CDR_alias is geared to finding typdef
1553 def get_CDR_alias(self,type,pn):
1555 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1556 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1557 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1559 decl = type.decl() # get declarator object
1561 if (decl.sizes()): # a typedef array
1562 indices = self.get_indices_from_sizes(decl.sizes())
1563 string_indices = '%i ' % indices # convert int to string
1564 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1566 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1567 self.addvar(self.c_i + pn + ";")
1568 self.st.inc_indent()
1569 self.getCDR(type.decl().alias().aliasType(), pn )
1571 self.st.dec_indent()
1572 self.st.out(self.template_get_CDR_array_end)
1575 else: # a simple typdef
1577 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1578 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1580 self.getCDR(type, pn )
1588 # Handle structs, including recursive
1591 def get_CDR_struct(self,type,pn):
1593 # If I am a typedef struct {..}; node then find the struct node
1595 if isinstance(type.decl(), idlast.Declarator):
1596 ntype = type.decl().alias().aliasType().decl()
1598 ntype = type.decl() # I am a struct node
1600 sname = self.namespace(ntype, "_")
1601 self.st.out(self.template_structure_start, name=sname )
1603 # Output a call to the struct helper function so I can handle recursive structs also.
1605 self.st.out(self.template_decode_struct,name=sname)
1607 self.st.out(self.template_structure_end, name=sname )
1612 # Generate private helper functions to decode a struct
1614 # in: stnode ( a struct node)
1617 def genStructHelper(self,st):
1619 print "XXX genStructHelper"
1621 sname = self.namespace(st, "_")
1622 self.curr_sname = sname # update current opnode/exnode/stnode scoped name
1623 if not self.fn_hash_built:
1624 self.fn_hash[sname] = [] # init empty list as val for this sname key
1625 # but only if the fn_hash is not already built
1627 self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
1628 self.st.inc_indent()
1630 if (len(self.fn_hash[sname]) > 0):
1631 self.st.out(self.template_helper_function_vars_start)
1632 self.dumpCvars(sname)
1633 self.st.out(self.template_helper_function_vars_end )
1635 for m in st.members():
1636 for decl in m.declarators():
1637 if decl.sizes(): # an array
1638 indices = self.get_indices_from_sizes(decl.sizes())
1639 string_indices = '%i ' % indices # convert int to string
1640 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1641 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1642 self.addvar(self.c_i + decl.identifier() + ";")
1644 self.st.inc_indent()
1645 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1646 self.st.dec_indent()
1647 self.st.out(self.template_get_CDR_array_end)
1651 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1653 self.st.dec_indent()
1654 self.st.out(self.template_struct_helper_function_end)
1661 # Generate code to access a sequence of a type
1665 def get_CDR_sequence(self,type, pn):
1666 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1667 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1668 self.addvar(self.c_i_lim + pn + ";" )
1669 self.addvar(self.c_i + pn + ";")
1671 self.st.inc_indent()
1672 self.getCDR(type.unalias().seqType(), pn ) # and start all over with the type
1673 self.st.dec_indent()
1675 self.st.out(self.template_get_CDR_sequence_loop_end)
1679 # Generate code to access a sequence of octet
1682 def get_CDR_sequence_octet(self,type, pn):
1683 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1684 self.st.out(self.template_get_CDR_sequence_octet, seqname=pn)
1685 self.addvar(self.c_i_lim + pn + ";")
1686 self.addvar("gchar * binary_seq_" + pn + ";")
1687 self.addvar("gchar * text_seq_" + pn + ";")
1695 # out - scoped operation name, using sep character instead of "::"
1697 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1701 def namespace(self,node,sep):
1702 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1703 #print "XXX namespace: sname = " + sname
1708 # generate code for plugin initialisation
1711 def gen_plugin_register(self):
1712 self.st.out(self.template_plugin_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1715 # generate register_giop_user_module code, and register only
1716 # unique interfaces that contain operations. Also output
1717 # a heuristic register in case we want to use that.
1719 # TODO - make this a command line option
1727 def gen_proto_reg_handoff(self, oplist):
1729 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1730 self.st.inc_indent()
1732 for iname in self.get_intlist(oplist):
1733 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1735 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1736 self.st.dec_indent()
1738 self.st.out(self.template_proto_reg_handoff_end)
1741 # generate hf_ array element for operation, attribute, enums, struct and union lists
1744 def genOp_hf(self,op):
1745 sname = self.namespace(op, "_")
1746 opname = sname[string.find(sname, "_")+1:]
1747 opname = opname[:string.find(opname, "_")]
1748 rt = op.returnType()
1750 if (rt.kind() != idltype.tk_void):
1751 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
1752 self.getCDR_hf(rt, rt.name(),\
1753 opname + "." + op.identifier() + ".return", sname + "_return")
1755 self.getCDR_hf(rt, "Return value",\
1756 opname + "." + op.identifier() + ".return", sname + "_return")
1758 for p in op.parameters():
1759 self.getCDR_hf(p.paramType(), p.identifier(),\
1760 opname + "." + op.identifier() + "." + p.identifier(), sname + "_" + p.identifier())
1762 def genAt_hf(self,at):
1763 for decl in at.declarators():
1764 sname = self.namespace(decl, "_")
1765 atname = sname[string.find(sname, "_")+1:]
1766 atname = atname[:string.find(atname, "_")]
1768 self.getCDR_hf(at.attrType(), decl.identifier(),\
1769 atname + "." + decl.identifier() + ".get", "get" + "_" + sname + "_" + decl.identifier())
1770 if not at.readonly():
1771 self.getCDR_hf(at.attrType(), decl.identifier(),\
1772 atname + "." + decl.identifier() + ".set", "set" + "_" + sname + "_" + decl.identifier())
1774 def genSt_hf(self,st):
1775 sname = self.namespace(st, "_")
1776 stname = sname[string.find(sname, "_")+1:]
1777 stname = stname[:string.find(stname, "_")]
1778 for m in st.members():
1779 for decl in m.declarators():
1780 self.getCDR_hf(m.memberType(), st.identifier() + "_" + decl.identifier(),\
1781 st.identifier() + "." + decl.identifier(), sname + "_" + decl.identifier())
1783 def genEx_hf(self,ex):
1784 sname = self.namespace(ex, "_")
1785 exname = sname[string.find(sname, "_")+1:]
1786 exname = exname[:string.find(exname, "_")]
1787 for m in ex.members():
1788 for decl in m.declarators():
1789 self.getCDR_hf(m.memberType(), ex.identifier() + "_" + decl.identifier(),\
1790 exname + "." + ex.identifier() + "_" + decl.identifier(), sname + "_" + decl.identifier())
1792 def genUnion_hf(self,un):
1793 sname = self.namespace(un, "_")
1794 unname = sname[:string.rfind(sname, "_")]
1795 unname = string.replace(unname, "_", ".")
1797 self.getCDR_hf(un.switchType().unalias(), un.identifier(),\
1798 unname + "." + un.identifier(), sname + "_" + un.identifier())
1800 for uc in un.cases(): # for all UnionCase objects in this union
1801 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1802 self.getCDR_hf(uc.caseType(), un.identifier() + "_" + uc.declarator().identifier(),\
1803 unname + "." + un.identifier() + "." + uc.declarator().identifier(),\
1804 sname + "_" + uc.declarator().identifier())
1807 # generate proto_register_<protoname> code,
1809 # in - oplist[], atlist[], stline[], unlist[]
1813 def gen_proto_register(self, oplist, atlist, stlist, unlist):
1814 self.st.out(self.template_proto_register_start, dissector_name=self.dissname)
1816 #operation specific filters
1817 self.st.out(self.template_proto_register_op_filter_comment)
1822 self.st.out(self.template_proto_register_at_filter_comment)
1827 self.st.out(self.template_proto_register_st_filter_comment)
1829 if (st.members()): # only if has members
1832 # exception List filters
1833 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
1834 self.st.out(self.template_proto_register_ex_filter_comment)
1836 if (ex.members()): # only if has members
1840 self.st.out(self.template_proto_register_un_filter_comment)
1842 self.genUnion_hf(un)
1844 self.st.out(self.template_proto_register_end, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1850 # out - a list of unique interface names. This will be used in
1851 # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1852 # name must be removed from the scope. And we also only want unique interfaces.
1855 def get_intlist(self,oplist):
1856 int_hash = {} # holds a hash of unique interfaces
1858 sc = op.scopedName() # eg: penguin,tux,bite
1859 sc1 = sc[:-1] # drop last entry
1860 sn = idlutil.slashName(sc1) # penguin/tux
1861 if not int_hash.has_key(sn):
1862 int_hash[sn] = 0; # dummy val, but at least key is unique
1863 ret = int_hash.keys()
1872 # out - a list of exception nodes (unique). This will be used in
1873 # to generate dissect_exception_XXX functions.
1878 def get_exceptionList(self,oplist):
1879 ex_hash = {} # holds a hash of unique exceptions.
1881 for ex in op.raises():
1882 if not ex_hash.has_key(ex):
1883 ex_hash[ex] = 0; # dummy val, but at least key is unique
1885 print "XXX Exception = " + ex.identifier()
1886 ret = ex_hash.keys()
1893 # Simple function to take a list of array sizes and find the
1894 # total number of elements
1897 # eg: temp[4][3] = 12 elements
1900 def get_indices_from_sizes(self,sizelist):
1908 # Determine how many octets contain requested number
1909 # of digits for an "fixed" IDL type "on the wire"
1912 def dig_to_len(self,dignum):
1913 return (dignum/2) + 1
1918 # Output some TODO comment
1922 def genTODO(self,message):
1923 self.st.out(self.template_debug_TODO, message=message)
1926 # Output some WARNING comment
1930 def genWARNING(self,message):
1931 self.st.out(self.template_debug_WARNING, message=message)
1934 # Templates for C code
1937 template_helper_function_comment = """\
1941 template_helper_function_vars_start = """\
1942 /* Operation specific Variable declarations Begin */"""
1944 template_helper_function_vars_end = """\
1945 /* Operation specific Variable declarations End */
1947 (void)item; /* Avoid coverity param_set_but_unused parse warning */
1950 template_helper_function_start = """\
1952 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_)
1955 template_helper_function_end = """\
1959 # proto_reg_handoff() templates
1962 template_proto_reg_handoff_start = """\
1963 /* register me as handler for these interfaces */
1964 void proto_reg_handoff_giop_@dissector_name@(void)
1967 template_proto_reg_handoff_body = """\
1968 /* Register for Explicit Dissection */
1969 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
1972 template_proto_reg_handoff_heuristic = """\
1973 /* Register for Heuristic Dissection */
1974 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
1977 template_proto_reg_handoff_end = """\
1985 template_prototype = """
1986 void proto_register_giop_@dissector_name@(void);
1987 void proto_reg_handoff_giop_@dissector_name@(void);"""
1990 # Initialize the protocol
1993 template_protocol = """
1994 /* Initialise the protocol and subtree pointers */
1995 static int proto_@dissector_name@ = -1;
1996 static gint ett_@dissector_name@ = -1;
1999 # Initialize the boundary Alignment
2002 template_init_boundary = """
2003 /* Initialise the initial Alignment */
2004 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */"""
2007 # plugin_register and plugin_reg_handoff templates
2010 template_plugin_register = """
2013 WS_DLL_PUBLIC_DEF void
2014 plugin_register(void)
2016 if (proto_@dissector_name@ == -1) {
2017 proto_register_giop_@dissector_name@();
2021 WS_DLL_PUBLIC_DEF void
2022 plugin_reg_handoff(void){
2023 proto_register_handoff_giop_@dissector_name@();
2028 # proto_register_<dissector name>(void) templates
2031 template_proto_register_start = """
2032 /* Register the protocol with Wireshark */
2033 void proto_register_giop_@dissector_name@(void)
2035 /* setup list of header fields */
2036 static hf_register_info hf[] = {
2037 /* field that indicates the currently ongoing request/reply exchange */
2038 {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2040 template_proto_register_end = """
2043 static ei_register_info ei[] = {
2044 { &ei_@dissector_name@_unknown_giop_msg, { "giop-@dissector_name@.unknown_giop_msg", PI_PROTOCOL, PI_WARN, "Unknown GIOP message", EXPFILL }},
2045 { &ei_@dissector_name@_unknown_exception, { "giop-@dissector_name@.unknown_exception", PI_PROTOCOL, PI_WARN, "Unknown exception", EXPFILL }},
2046 { &ei_@dissector_name@_unknown_reply_status, { "giop-@dissector_name@.unknown_reply_status", PI_PROTOCOL, PI_WARN, "Unknown reply status", EXPFILL }},
2049 /* setup protocol subtree array */
2051 static gint *ett[] = {
2052 &ett_@dissector_name@,
2055 expert_module_t* expert_@dissector_name@;
2058 /* Register the protocol name and description */
2059 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
2060 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
2061 proto_register_subtree_array(ett, array_length(ett));
2063 expert_@dissector_name@ = expert_register_protocol(proto_@dissector_name@);
2064 expert_register_field_array(expert_@dissector_name@, ei, array_length(ei));
2068 template_proto_register_op_filter_comment = """\
2069 /* Operation filters */"""
2071 template_proto_register_at_filter_comment = """\
2072 /* Attribute filters */"""
2074 template_proto_register_st_filter_comment = """\
2075 /* Struct filters */"""
2077 template_proto_register_ex_filter_comment = """\
2078 /* User exception filters */"""
2080 template_proto_register_un_filter_comment = """\
2081 /* Union filters */"""
2083 template_proto_register_ei_filters = """\
2084 /* Expert info filters */
2085 static expert_field ei_@dissector_name@_unknown_giop_msg = EI_INIT;
2086 static expert_field ei_@dissector_name@_unknown_exception = EI_INIT;
2087 static expert_field ei_@dissector_name@_unknown_reply_status = EI_INIT;
2091 # template for delegation code
2094 template_op_delegate_code = """\
2095 if (strcmp(operation, "@opname@") == 0
2096 && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
2097 item = process_RequestOperation(tvb, pinfo, ptree, header, operation); /* fill-up Request_Operation field & info column */
2098 tree = start_dissecting(tvb, pinfo, ptree, offset);
2099 decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
2104 # Templates for the helper functions
2109 template_helper_switch_msgtype_start = """\
2110 switch(header->message_type) {"""
2112 template_helper_switch_msgtype_default_start = """\
2114 /* Unknown GIOP Message */
2115 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2117 template_helper_switch_msgtype_default_end = """\
2120 template_helper_switch_msgtype_end = """\
2121 } /* switch(header->message_type) */"""
2123 template_helper_switch_msgtype_request_start = """\
2126 template_helper_switch_msgtype_request_end = """\
2129 template_helper_switch_msgtype_reply_start = """\
2132 template_helper_switch_msgtype_reply_no_exception_start = """\
2133 case NO_EXCEPTION:"""
2135 template_helper_switch_msgtype_reply_no_exception_end = """\
2138 template_helper_switch_msgtype_reply_user_exception_start = """\
2139 case USER_EXCEPTION:"""
2141 template_helper_switch_msgtype_reply_user_exception_end = """\
2144 template_helper_switch_msgtype_reply_default_start = """\
2146 /* Unknown Exception */
2147 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_exception, "Unknown exception %d", header->rep_status);"""
2149 template_helper_switch_msgtype_reply_default_end = """\
2152 template_helper_switch_msgtype_reply_end = """\
2155 template_helper_switch_msgtype_default_start = """\
2157 /* Unknown GIOP Message */
2158 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2160 template_helper_switch_msgtype_default_end = """\
2163 template_helper_switch_rep_status_start = """\
2164 switch(header->rep_status) {"""
2166 template_helper_switch_rep_status_default_start = """\
2168 /* Unknown Reply Status */
2169 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_reply_status, "Unknown reply status %d", header->rep_status);"""
2171 template_helper_switch_rep_status_default_end = """\
2174 template_helper_switch_rep_status_end = """\
2175 } /* switch(header->rep_status) */
2180 # Templates for get_CDR_xxx accessors
2183 template_get_CDR_ulong = """\
2184 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
2186 template_get_CDR_short = """\
2187 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
2189 template_get_CDR_void = """\
2190 /* Function returns void */
2192 template_get_CDR_long = """\
2193 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
2195 template_get_CDR_ushort = """\
2196 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
2198 template_get_CDR_float = """\
2199 proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
2201 template_get_CDR_double = """\
2202 proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
2204 template_get_CDR_longlong = """\
2205 proto_tree_add_int64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
2207 template_get_CDR_ulonglong = """\
2208 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
2210 template_get_CDR_boolean = """\
2211 proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
2213 template_get_CDR_char = """\
2214 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
2216 template_get_CDR_octet = """\
2217 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
2219 template_get_CDR_any = """\
2220 get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
2222 template_get_CDR_fixed = """\
2223 get_CDR_fixed(tvb, pinfo, item, &seq, offset, @digits@, @scale@);
2224 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
2226 template_get_CDR_enum_symbolic = """\
2227 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2228 /* coverity[returned_pointer] */
2229 item = proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
2231 template_get_CDR_string = """\
2232 giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, hf_@hfname@);
2234 template_get_CDR_wstring = """\
2235 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2236 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ (%u) = %s",
2237 u_octet4, (u_octet4 > 0) ? seq : \"\");
2239 template_get_CDR_wchar = """\
2240 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2243 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
2246 s_octet1 = -s_octet1;
2249 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
2252 template_get_CDR_TypeCode = """\
2253 u_octet4 = get_CDR_typeCode(tvb, pinfo, tree, offset, stream_is_big_endian, boundary, header);
2256 template_get_CDR_object = """\
2257 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2260 template_get_CDR_sequence_length = """\
2261 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2262 /* coverity[returned_pointer] */
2263 item = proto_tree_add_uint(tree, hf_@seqname@, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2265 template_get_CDR_sequence_loop_start = """\
2266 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2268 template_get_CDR_sequence_loop_end = """\
2272 template_get_CDR_sequence_octet = """\
2273 if (u_octet4_loop_@seqname@ > 0 && tree) {
2274 get_CDR_octet_seq(tvb, &binary_seq_@seqname@, offset,
2275 u_octet4_loop_@seqname@);
2276 text_seq_@seqname@ = make_printable_string(binary_seq_@seqname@,
2277 u_octet4_loop_@seqname@);
2278 proto_tree_add_text(tree, tvb, *offset - u_octet4_loop_@seqname@,
2279 u_octet4_loop_@seqname@, \"@seqname@: %s\", text_seq_@seqname@);
2282 template_get_CDR_array_start = """\
2283 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2285 template_get_CDR_array_end = """\
2288 template_get_CDR_array_comment = """\
2289 /* Array: @aname@[ @asize@] */
2291 template_structure_start = """\
2292 /* Begin struct \"@name@\" */"""
2294 template_structure_end = """\
2295 /* End struct \"@name@\" */"""
2297 template_union_start = """\
2298 /* Begin union \"@name@\" */"""
2300 template_union_end = """\
2301 /* End union \"@name@\" */"""
2304 # Templates for get_CDR_xxx_hf accessors
2307 template_get_CDR_ulong_hf = """\
2308 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2310 template_get_CDR_short_hf = """\
2311 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2313 template_get_CDR_long_hf = """\
2314 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2316 template_get_CDR_ushort_hf = """\
2317 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2319 template_get_CDR_float_hf = """\
2320 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2322 template_get_CDR_double_hf = """\
2323 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2325 template_get_CDR_longlong_hf = """\
2326 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2328 template_get_CDR_ulonglong_hf = """\
2329 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2331 template_get_CDR_boolean_hf = """\
2332 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""
2334 template_get_CDR_char_hf = """\
2335 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2337 template_get_CDR_octet_hf = """\
2338 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2340 template_get_CDR_enum_symbolic_hf = """\
2341 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2343 template_get_CDR_string_hf = """\
2344 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2346 template_get_CDR_wstring_hf = """\
2347 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2349 template_get_CDR_wchar_hf = """\
2350 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2352 template_get_CDR_TypeCode_hf = """\
2353 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2355 template_get_CDR_sequence_hf = """\
2356 {&hf_@hfname@, {"Seq length of @descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2358 template_get_CDR_sequence_octet_hf = """\
2359 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2362 # Program Header Template
2365 template_Header = """\
2366 /* packet-@dissector_name@.c
2370 * Routines for IDL dissection
2372 * Autogenerated from idl2wrs
2373 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2378 template_wireshark_copyright = """\
2380 * Wireshark - Network traffic analyzer
2382 * Copyright 1999 - 2012 Gerald Combs
2395 * This program is free software; you can redistribute it and/or
2396 * modify it under the terms of the GNU General Public License
2397 * as published by the Free Software Foundation; either version 2
2398 * of the License, or (at your option) any later version.
2400 * This program is distributed in the hope that it will be useful,
2401 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2402 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2403 * GNU General Public License for more details.
2405 * You should have received a copy of the GNU General Public License
2406 * along with this program; if not, write to the Free Software
2407 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2412 # Modelines Template
2416 template_Modelines = """\
2423 * indent-tabs-mode: nil
2426 * ex: set shiftwidth=4 tabstop=8 expandtab:
2427 * :indentSize=4:tabSize=8:noTabs=true:
2434 template_Includes = """\
2438 #include <gmodule.h>
2442 #include <epan/packet.h>
2443 #include <epan/proto.h>
2444 #include <epan/dissectors/packet-giop.h>
2445 #include <epan/expert.h>
2448 /* disable warning: "unreference local variable" */
2449 #pragma warning(disable:4101)
2452 #if defined(__GNUC__)
2453 #pragma GCC diagnostic ignored "-Wunused-function"
2454 #pragma GCC diagnostic ignored "-Wunused-variable"
2459 # Main dissector entry templates
2462 template_main_dissector_start = """\
2464 * Called once we accept the packet as being for us; it sets the
2465 * Protocol and Info columns and creates the top-level protocol
2469 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
2472 proto_item *ti = NULL;
2473 proto_tree *tree = NULL; /* init later, inside if(tree) */
2475 col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2478 * Do not clear COL_INFO, as nothing is being written there by
2479 * this dissector yet. So leave it as is from the GIOP dissector.
2480 * TODO: add something useful to COL_INFO
2481 * col_clear(pinfo->cinfo, COL_INFO);
2485 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, -1, ENC_NA);
2486 tree = proto_item_add_subtree(ti, ett_@dissname@);
2492 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const gchar *operation)
2495 if(header->message_type == Reply) {
2496 /* fill-up info column */
2497 col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
2499 /* fill-up the field */
2500 pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
2501 PROTO_ITEM_SET_GENERATED(pi);
2506 dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const gchar *operation, gchar *idlname)
2508 proto_item *item _U_;
2509 proto_tree *tree _U_;
2510 gboolean stream_is_big_endian = is_big_endian(header); /* get endianess */
2512 /* If we have a USER Exception, then decode it and return */
2513 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2514 return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
2518 template_main_dissector_switch_msgtype_start = """\
2519 switch(header->message_type) {
2521 template_main_dissector_switch_msgtype_start_request_reply = """\
2525 template_main_dissector_switch_msgtype_end_request_reply = """\
2528 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2532 case CloseConnection:
2535 return FALSE; /* not handled yet */
2538 return FALSE; /* not handled yet */
2542 template_main_dissector_end = """\
2546 } /* End of main dissector */
2555 #-------------------------------------------------------------#
2556 # Exception handling templates #
2557 #-------------------------------------------------------------#
2565 template_exception_helpers_start = """\
2566 /* Begin Exception Helper Functions */
2569 template_exception_helpers_end = """\
2571 /* End Exception Helper Functions */
2577 # template for Main delegator for exception handling
2580 template_main_exception_delegator_start = """\
2582 * Main delegator for exception handling
2586 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_)
2588 proto_tree *tree _U_;
2590 if (!header->exception_id)
2596 # template for exception delegation code body
2598 template_ex_delegate_code = """\
2599 if (strcmp(header->exception_id, "@exname@") == 0) {
2600 tree = start_dissecting(tvb, pinfo, ptree, offset);
2601 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian); /* @exname@ */
2608 # End of Main delegator for exception handling
2611 template_main_exception_delegator_end = """
2612 return FALSE; /* user exception not found */
2617 # template for exception helper code
2621 template_exception_helper_function_start = """\
2622 /* Exception = @exname@ */
2624 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_)
2626 proto_item *item _U_;
2629 template_exception_helper_function_end = """\
2635 # template for struct helper code
2639 template_struct_helper_function_start = """\
2640 /* Struct = @stname@ */
2642 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_)
2646 template_struct_helper_function_end = """\
2651 # template for union helper code
2655 template_union_helper_function_start = """\
2656 /* Union = @unname@ */
2658 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_)
2660 proto_item* item _U_;
2663 template_union_helper_function_end = """\
2669 #-------------------------------------------------------------#
2670 # Value string templates #
2671 #-------------------------------------------------------------#
2673 template_value_string_start = """\
2674 static const value_string @valstringname@[] = {
2676 template_value_string_entry = """\
2677 { @intval@, \"@description@\" },"""
2679 template_value_string_end = """\
2686 #-------------------------------------------------------------#
2687 # Enum handling templates #
2688 #-------------------------------------------------------------#
2690 template_comment_enums_start = """\
2695 template_comment_enums_end = """\
2700 template_comment_enum_comment = """\
2707 #-------------------------------------------------------------#
2708 # Attribute handling templates #
2709 #-------------------------------------------------------------#
2712 template_comment_attributes_start = """\
2714 * IDL Attributes Start
2719 # get/set accessor method names are language mapping dependant.
2722 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2723 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2725 template_comment_attributes_end = """
2727 * IDL Attributes End
2733 # template for Attribute delegation code
2735 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2736 # Note: _set_xxx() should only be called for Request
2740 template_at_delegate_code_get = """\
2741 if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2742 tree = start_dissecting(tvb, pinfo, ptree, offset);
2743 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2747 template_at_delegate_code_set = """\
2748 if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
2749 tree = start_dissecting(tvb, pinfo, ptree, offset);
2750 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2754 template_attribute_helpers_start = """\
2755 /* Begin Attribute Helper Functions */
2757 template_attribute_helpers_end = """\
2759 /* End Attribute Helper Functions */
2763 # template for attribute helper code
2767 template_attribute_helper_function_start = """\
2769 /* Attribute = @atname@ */
2771 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_)
2773 proto_item* item _U_;
2776 template_attribute_helper_function_end = """\
2781 #-------------------------------------------------------------#
2782 # Debugging templates #
2783 #-------------------------------------------------------------#
2786 # Template for outputting TODO "C" comments
2787 # so user know I need ti improve something.
2790 template_debug_TODO = """\
2792 /* TODO - @message@ */
2795 # Template for outputting WARNING "C" comments
2796 # so user know if I have found a problem.
2799 template_debug_WARNING = """\
2800 /* WARNING - @message@ */
2805 #-------------------------------------------------------------#
2806 # IDL Union templates #
2807 #-------------------------------------------------------------#
2809 template_comment_union_code_start = """\
2811 * IDL Union Start - @uname@
2814 template_comment_union_code_end = """
2816 * IDL union End - @uname@
2819 template_comment_union_code_discriminant = """\
2821 * IDL Union - Discriminant - @uname@
2825 # Cast Unions types to something appropriate
2826 # Enum value cast to guint32, all others cast to gint32
2827 # as omniidl accessor returns integer or Enum.
2830 template_union_code_save_discriminant_enum = """\
2831 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2833 template_union_code_save_discriminant_long = """\
2834 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2837 template_union_code_save_discriminant_ulong = """\
2838 disc_s_@discname@ = (gint32) u_octet4; /* save guint32 discriminant and cast to gint32 */
2840 template_union_code_save_discriminant_short = """\
2841 disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
2844 template_union_code_save_discriminant_ushort = """\
2845 disc_s_@discname@ = (gint32) u_octet2; /* save guint16 discriminant and cast to gint32 */
2847 template_union_code_save_discriminant_char = """\
2848 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2850 template_union_code_save_discriminant_boolean = """\
2851 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2853 template_comment_union_code_label_compare_start = """\
2854 if (disc_s_@discname@ == @labelval@) {
2856 template_comment_union_code_label_compare_end = """\
2857 return; /* End Compare for this discriminant type */
2862 template_comment_union_code_label_default_start = """
2863 /* Default Union Case Start */
2865 template_comment_union_code_label_default_end = """\
2866 /* Default Union Case End */
2870 # Templates for function prototypes.
2871 # This is used in genDeclares() for declaring function prototypes
2872 # for structs and union helper functions.
2875 template_hf_operations = """
2876 static int hf_operationrequest = -1;/* Request_Operation field */
2880 static int hf_@name@ = -1;"""
2882 template_prototype_start_dissecting = """
2883 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
2886 template_prototype_struct_start = """\
2887 /* Struct prototype declaration Start */
2889 template_prototype_struct_end = """\
2890 /* Struct prototype declaration End */
2892 template_prototype_struct_body = """\
2893 /* Struct = @stname@ */
2894 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_);
2896 template_decode_struct = """\
2897 decode_@name@_st(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);"""
2899 template_prototype_union_start = """\
2900 /* Union prototype declaration Start */"""
2902 template_prototype_union_end = """\
2903 /* Union prototype declaration End */"""
2905 template_prototype_union_body = """
2906 /* Union = @unname@ */
2907 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_);
2909 template_decode_union = """
2910 decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2914 # Editor modelines - http://www.wireshark.org/tools/modelines.html
2918 # indent-tabs-mode: nil
2921 # vi: set shiftwidth=4 expandtab:
2922 # :indentSize=4:noTabs=true: