5 # ethereal_gen.py (part of idl2eth)
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 "Ethereal"
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 Ethereal distro for API description.
16 # Ethereal is available at http://www.ethereal.com/
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 ethereal_be2.py and generates "C" code for compiling
40 # as a plugin for the Ethereal 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 """Ethereal 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 ethereal 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 ethereal_gen_C:
122 # Turn DEBUG stuff on/off
128 # Some string constants for our templates
131 c_u_octet4 = "guint32 u_octet4;"
132 c_s_octet4 = "gint32 s_octet4;"
133 c_u_octet2 = "guint16 u_octet2;"
134 c_s_octet2 = "gint16 s_octet2;"
135 c_u_octet1 = "guint8 u_octet1;"
136 c_s_octet1 = "gint8 s_octet1;"
138 c_float = "gfloat my_float;"
139 c_double = "gdouble my_double;"
141 c_seq = "gchar *seq = NULL;" # pointer to buffer of gchars
142 c_i = "guint32 i_"; # loop index
143 c_i_lim = "guint32 u_octet4_loop_"; # loop limit
144 c_u_disc = "guint32 disc_u_"; # unsigned int union discriminant variable name (enum)
145 c_s_disc = "gint32 disc_s_"; # signed int union discriminant variable name (other cases, except Enum)
151 def __init__(self, st, protocol_name, dissector_name ,description):
152 self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only
154 self.st_save = st # where 2nd pass should go
155 self.protoname = protocol_name # Protocol Name (eg: ECHO)
156 self.dissname = dissector_name # Dissector name (eg: echo)
157 self.description = description # Detailed Protocol description (eg: Echo IDL Example)
158 self.exlist = [] # list of exceptions used in operations.
159 #self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
160 self.fn_hash = {} # top level hash to contain key = function/exception and val = list of variable declarations
162 self.fn_hash_built = 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
163 # populated with operations/vars and exceptions/vars
169 # Main entry point, controls sequence of
174 def genCode(self,oplist, atlist, enlist, stlist, unlist): # operation,attribute,enums,struct and union lists
177 self.genHelpers(oplist,stlist,unlist) # sneaky .. call it now, to populate the fn_hash
178 # so when I come to that operation later, I have the variables to
181 self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
182 # so when I come to that exception later, I have the variables to
185 self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
186 # so when I come to that exception later, I have the variables to
190 self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
192 self.st = self.st_save
193 self.genHeader() # initial dissector comments
194 self.genEthCopyright() # Ethereal Copyright comments.
195 self.genGPL() # GPL license
197 self.genDeclares(oplist,atlist,enlist,stlist,unlist)
199 self.genRegisteredFields()
200 self.genOpList(oplist) # string constant declares for operation names
201 self.genExList(oplist) # string constant declares for user exceptions
202 self.genAtList(atlist) # string constant declares for Attributes
203 self.genEnList(enlist) # string constant declares for Enums
206 self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
207 self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
208 self.genAttributeHelpers(atlist) # helper function to decode "attributes"
210 self.genHelpers(oplist,stlist,unlist) # operation, struct and union decode helper functions
212 self.genMainEntryStart(oplist)
213 self.genOpDelegator(oplist)
214 self.genAtDelegator(atlist)
215 self.genMainEntryEnd()
217 self.gen_proto_register()
218 self.gen_proto_reg_handoff(oplist)
219 self.gen_plugin_init()
221 #self.dumpvars() # debug
228 # Generate Standard Ethereal Header Comments
233 self.st.out(self.template_Header,dissector_name=self.dissname)
235 print "XXX genHeader"
243 # Ethereal Copyright Info
247 def genEthCopyright(self):
249 print "XXX genEthCopyright"
250 self.st.out(self.template_ethereal_copyright)
264 self.st.out(self.template_GPL)
273 def genIncludes(self):
275 print "XXX genIncludes"
277 self.st.out(self.template_Includes)
283 # generate function prototypes if required
285 # Currently this is used for struct and union helper function declarations.
289 def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
291 print "XXX genDeclares"
295 self.st.out(self.template_prototype_struct_start)
298 sname = self.namespace(st, "_")
300 self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
301 self.st.out(self.template_prototype_struct_end)
305 self.st.out(self.template_prototype_union_start)
307 sname = self.namespace(un, "_")
308 self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
309 self.st.out(self.template_prototype_union_end)
319 def genProtocol(self):
320 self.st.out(self.template_protocol, dissector_name=self.dissname)
321 self.st.out(self.template_init_boundary)
325 # genProtoAndRegisteredFields
329 def genRegisteredFields(self):
330 self.st.out(self.template_registered_fields )
338 def genMainEntryStart(self,oplist):
339 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
341 self.st.out(self.template_main_dissector_switch_msgtype_start)
342 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
350 def genMainEntryEnd(self):
352 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
354 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
356 self.st.out(self.template_main_dissector_end)
364 # out: C code for IDL operations
368 # static const char Penguin_Echo_echoShort_op[] = "echoShort" ;
371 def genOpList(self,oplist):
372 self.st.out(self.template_comment_operations_start)
375 sname = self.namespace(n, "_")
376 opname = n.identifier()
377 self.st.out(self.template_operations_declare, sname=sname, opname=opname)
379 self.st.out(self.template_comment_operations_end)
386 # out: C code for IDL User Exceptions that contain members
390 # static const char user_exception_tux_bad_value[] = "IDL:tux/bad_value:1.0" ;
393 def genExList(self,oplist):
395 self.st.out(self.template_comment_user_exceptions_string_declare_start)
397 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
401 print "XXX Exception " , ex.repoId()
402 print "XXX Exception Identifier" , ex.identifier()
403 print "XXX Exception Scoped Name" , ex.scopedName()
405 if (ex.members()): # only if has members
406 sname = self.namespace(ex, "_")
408 self.st.out(self.template_user_exceptions_declare, sname=sname, exname=ex.repoId())
410 self.st.out(self.template_comment_user_exceptions_string_declare_end)
417 # out: C code for IDL attribute decalarations.
419 # NOTE: Mapping of attributes to operation(function) names is tricky.
421 # The actual accessor function names are language-mapping specific. The attribute name
422 # is subject to OMG IDL's name scoping rules; the accessor function names are
423 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
427 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
428 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
432 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
433 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
435 # TODO: Implement some language dependant templates to handle naming conventions
436 # language <=> attribute. for C, C++. Java etc
438 # OR, just add a runtime GUI option to select language binding for attributes -- FS
442 # ie: def genAtlist(self,atlist,language)
447 def genAtList(self,atlist):
448 self.st.out(self.template_comment_attributes_start)
451 for i in n.declarators(): #
452 sname = self.namespace(i, "_")
453 atname = i.identifier()
454 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
456 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
458 self.st.out(self.template_comment_attributes_end)
466 # out: C code for IDL Enum decalarations using "static const value_string" template
471 def genEnList(self,enlist):
473 self.st.out(self.template_comment_enums_start)
476 sname = self.namespace(enum, "_")
478 self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
479 self.st.out(self.template_value_string_start, valstringname=sname)
480 for enumerator in enum.enumerators():
481 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
484 #atname = n.identifier()
485 self.st.out(self.template_value_string_end, valstringname=sname)
487 self.st.out(self.template_comment_enums_end)
499 # genExceptionDelegator
503 # out: C code for User exception delegator
509 def genExceptionDelegator(self,oplist):
511 self.st.out(self.template_main_exception_delegator_start)
514 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
518 print "XXX Exception " , ex.repoId()
519 print "XXX Exception Identifier" , ex.identifier()
520 print "XXX Exception Scoped Name" , ex.scopedName()
522 if (ex.members()): # only if has members
523 sname = self.namespace(ex, "_")
525 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
528 self.st.out(self.template_main_exception_delegator_end)
532 # genAttribueHelpers()
534 # Generate private helper functions to decode Attributes.
538 # For readonly attribute - generate get_xxx()
539 # If NOT readonly attribute - also generate set_xxx()
542 def genAttributeHelpers(self,atlist):
544 print "XXX genAttributeHelpers: atlist = ", atlist
546 self.st.out(self.template_attribute_helpers_start)
548 for attrib in atlist:
549 for decl in attrib.declarators():
550 self.genAtHelper(attrib,decl,"get") # get accessor
551 if not attrib.readonly():
552 self.genAtHelper(attrib,decl,"set") # set accessor
554 self.st.out(self.template_attribute_helpers_end)
559 # Generate private helper functions to decode an attribute
561 # in: at - attribute node
562 # in: decl - declarator belonging to this attribute
563 # in: order - to generate a "get" or "set" helper
565 def genAtHelper(self,attrib,decl,order):
567 print "XXX genAtHelper"
569 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
570 self.curr_sname = sname # update current opnode/exnode scoped name
572 if not self.fn_hash_built:
573 self.fn_hash[sname] = [] # init empty list as val for this sname key
574 # but only if the fn_hash is not already built
576 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
579 self.st.out(self.template_helper_function_vars_start)
580 self.dumpCvars(sname)
581 self.st.out(self.template_helper_function_vars_end )
583 self.st.out(self.template_exception_helper_function_get_endianess)
586 # TODO - attributes are simple types, so remove array handling
589 if decl.sizes(): # an array
590 indices = self.get_indices_from_sizes(decl.sizes())
591 string_indices = '%i ' % indices # convert int to string
592 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
593 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
594 self.addvar(self.c_i + decl.identifier() + ";")
598 self.getCDR3(attrib.attrType(), decl.identifier() )
601 self.st.out(self.template_get_CDR_array_end)
606 self.getCDR3(attrib.attrType(), decl.identifier() )
609 self.st.out(self.template_attribute_helper_function_end)
614 # genExceptionHelpers()
616 # Generate private helper functions to decode Exceptions used
623 def genExceptionHelpers(self,oplist):
624 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
626 print "XXX genExceptionHelpers: exlist = ", exlist
628 self.st.out(self.template_exception_helpers_start)
630 if (ex.members()): # only if has members
631 #print "XXX Exception = " + ex.identifier()
634 self.st.out(self.template_exception_helpers_end)
640 # Generate private helper functions to decode User Exceptions
642 # in: exnode ( an exception node)
645 def genExHelper(self,ex):
647 print "XXX genExHelper"
649 sname = self.namespace(ex, "_")
650 self.curr_sname = sname # update current opnode/exnode scoped name
651 if not self.fn_hash_built:
652 self.fn_hash[sname] = [] # init empty list as val for this sname key
653 # but only if the fn_hash is not already built
655 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
658 self.st.out(self.template_helper_function_vars_start)
659 self.dumpCvars(sname)
660 self.st.out(self.template_helper_function_vars_end )
662 self.st.out(self.template_exception_helper_function_get_endianess)
665 for m in ex.members():
666 #print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
669 for decl in m.declarators():
670 #print "XXX genExhelper, d = ", decl
671 if decl.sizes(): # an array
672 indices = self.get_indices_from_sizes(decl.sizes())
673 string_indices = '%i ' % indices # convert int to string
674 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
675 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
676 self.addvar(self.c_i + decl.identifier() + ";")
679 self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
682 self.st.out(self.template_get_CDR_array_end)
686 self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
689 self.st.out(self.template_exception_helper_function_end)
695 # Generate private helper functions for each IDL operation.
696 # Generate private helper functions for each IDL struct.
697 # Generate private helper functions for each IDL union.
700 # in: oplist, stlist, unlist
704 def genHelpers(self,oplist,stlist,unlist):
706 self.genOperation(op)
708 self.genStructHelper(st)
710 self.genUnionHelper(un)
715 # Generate private helper functions for a specificIDL operation.
720 def genOperation(self,opnode):
722 print "XXX genOperation called"
724 sname = self.namespace(opnode, "_")
725 if not self.fn_hash_built:
726 self.fn_hash[sname] = [] # init empty list as val for this sname key
727 # but only if the fn_hash is not already built
729 self.curr_sname = sname # update current opnode's scoped name
730 opname = opnode.identifier()
732 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
734 self.st.out(self.template_helper_function_start, sname=sname)
737 self.st.out(self.template_helper_function_vars_start)
738 self.dumpCvars(sname)
739 self.st.out(self.template_helper_function_vars_end )
742 self.st.out(self.template_helper_switch_msgtype_start)
744 self.st.out(self.template_helper_switch_msgtype_request_start)
746 self.genOperationRequest(opnode)
747 self.st.out(self.template_helper_switch_msgtype_request_end)
750 self.st.out(self.template_helper_switch_msgtype_reply_start)
753 self.st.out(self.template_helper_switch_rep_status_start)
756 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
758 self.genOperationReply(opnode)
759 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
762 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
764 self.genOpExceptions(opnode)
765 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
768 self.st.out(self.template_helper_switch_msgtype_reply_default_start)
769 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
771 self.st.out(self.template_helper_switch_rep_status_end)
775 self.st.out(self.template_helper_switch_msgtype_default_start)
776 self.st.out(self.template_helper_switch_msgtype_default_end)
778 self.st.out(self.template_helper_switch_msgtype_end)
782 self.st.out(self.template_helper_function_end, sname=sname)
788 # Decode function parameters for a GIOP request message
792 def genOperationRequest(self,opnode):
793 for p in opnode.parameters():
796 print "XXX parameter = " ,p
797 print "XXX parameter type = " ,p.paramType()
798 print "XXX parameter type kind = " ,p.paramType().kind()
800 self.getCDR3(p.paramType(),p.identifier())
804 # Decode function parameters for a GIOP reply message
808 def genOperationReply(self,opnode):
810 rt = opnode.returnType() # get return type
812 print "XXX opnode = " , opnode
813 print "XXX return type = " , rt
814 print "XXX return type.unalias = " , rt.unalias()
815 print "XXX return type.kind() = " , rt.kind();
818 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
819 #self.getCDR3(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
820 #self.get_CDR_alias(rt, "Operation_Return_Value" )
821 self.get_CDR_alias(rt, rt.name() )
824 self.getCDR3(rt, "Operation_Return_Value") # return value is NOT an alias
826 for p in opnode.parameters():
827 if p.is_out(): # out or inout
828 self.getCDR3(p.paramType(),p.identifier())
830 #self.st.dec_indent()
832 def genOpExceptions(self,opnode):
833 for ex in opnode.raises():
836 for m in ex.members():
838 #print m.memberType(), m.memberType().kind()
840 # Delegator for Operations
843 def genOpDelegator(self,oplist):
845 opname = op.identifier()
846 sname = self.namespace(op, "_")
847 self.st.out(self.template_op_delegate_code, sname=sname)
850 # Delegator for Attributes
853 def genAtDelegator(self,atlist):
855 for i in a.declarators():
856 atname = i.identifier()
857 sname = self.namespace(i, "_")
858 self.st.out(self.template_at_delegate_code_get, sname=sname)
860 self.st.out(self.template_at_delegate_code_set, sname=sname)
864 # Add a variable declaration to the hash of list
867 def addvar(self, var):
868 if not ( var in self.fn_hash[self.curr_sname] ):
869 self.fn_hash[self.curr_sname].append(var)
872 # Print the variable declaration from the hash of list
877 for fn in self.fn_hash.keys():
879 for v in self.fn_hash[fn]:
882 # Print the "C" variable declaration from the hash of list
883 # for a given scoped operation name (eg: tux_penguin_eat)
887 def dumpCvars(self, sname):
888 for v in self.fn_hash[sname]:
893 # Given an enum node, and a enumerator node, return
894 # the enumerator's numerical value.
896 # eg: enum Color {red,green,blue} should return
900 def valFromEnum(self,enumNode, enumeratorNode):
902 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
903 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
905 if isinstance(enumeratorNode,idlast.Enumerator):
906 value = enumNode.enumerators().index(enumeratorNode)
935 ## tk_longdouble = 25
942 ## tk_abstract_interface = 32
948 # This is the main "iterator" function. It takes a node, and tries to output
949 # a get_CDR_XXX accessor method(s). It can call itself multiple times
950 # if I find nested structures etc.
953 def getCDR3(self,type,name="fred"):
955 pt = type.unalias().kind() # param CDR type
956 pn = name # param name
959 print "XXX getCDR3: kind = " , pt
961 if pt == idltype.tk_ulong:
962 self.get_CDR_ulong(pn)
963 elif pt == idltype.tk_void:
964 self.get_CDR_void(pn)
965 elif pt == idltype.tk_short:
966 self.get_CDR_short(pn)
967 elif pt == idltype.tk_long:
968 self.get_CDR_long(pn)
969 elif pt == idltype.tk_ushort:
970 self.get_CDR_ushort(pn)
971 elif pt == idltype.tk_float:
972 self.get_CDR_float(pn)
973 elif pt == idltype.tk_double:
974 self.get_CDR_double(pn)
975 elif pt == idltype.tk_fixed:
976 self.get_CDR_fixed(type.unalias(),pn)
977 elif pt == idltype.tk_boolean:
978 self.get_CDR_boolean(pn)
979 elif pt == idltype.tk_char:
980 self.get_CDR_char(pn)
981 elif pt == idltype.tk_octet:
982 self.get_CDR_octet(pn)
983 elif pt == idltype.tk_any:
985 elif pt == idltype.tk_string:
986 self.get_CDR_string(pn)
987 elif pt == idltype.tk_wstring:
988 self.get_CDR_wstring(pn)
989 elif pt == idltype.tk_wchar:
990 self.get_CDR_wchar(pn)
991 elif pt == idltype.tk_enum:
993 self.get_CDR_enum(pn,type)
994 #self.get_CDR_enum(pn)
996 elif pt == idltype.tk_struct:
997 self.get_CDR_struct(type,pn)
998 elif pt == idltype.tk_TypeCode: # will I ever get here ?
999 self.get_CDR_TypeCode(pn)
1000 elif pt == idltype.tk_sequence:
1001 self.get_CDR_sequence(type,pn)
1002 elif pt == idltype.tk_objref:
1003 self.get_CDR_objref(type,pn)
1004 elif pt == idltype.tk_array:
1005 self.get_CDR_array(type,pn)
1006 elif pt == idltype.tk_union:
1007 self.get_CDR_union(type,pn)
1008 elif pt == idltype.tk_alias:
1010 print "XXXXX Alias type XXXXX " , type
1011 self.get_CDR_alias(type,pn)
1013 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1017 # get_CDR_XXX methods are here ..
1022 def get_CDR_ulong(self,pn):
1023 self.st.out(self.template_get_CDR_ulong, varname=pn)
1024 self.addvar(self.c_u_octet4)
1026 def get_CDR_short(self,pn):
1027 self.st.out(self.template_get_CDR_short, varname=pn)
1028 self.addvar(self.c_s_octet2)
1030 def get_CDR_void(self,pn):
1031 self.st.out(self.template_get_CDR_void, varname=pn)
1033 def get_CDR_long(self,pn):
1034 self.st.out(self.template_get_CDR_long, varname=pn)
1035 self.addvar(self.c_s_octet4)
1037 def get_CDR_ushort(self,pn):
1038 self.st.out(self.template_get_CDR_ushort, varname=pn)
1039 self.addvar(self.c_u_octet2)
1041 def get_CDR_float(self,pn):
1042 self.st.out(self.template_get_CDR_float, varname=pn)
1043 self.addvar(self.c_float)
1045 def get_CDR_double(self,pn):
1046 self.st.out(self.template_get_CDR_double, varname=pn)
1047 self.addvar(self.c_double)
1049 def get_CDR_boolean(self,pn):
1050 self.st.out(self.template_get_CDR_boolean, varname=pn)
1051 self.addvar(self.c_u_octet1)
1053 def get_CDR_fixed(self,type,pn):
1055 print "XXXX calling get_CDR_fixed, type = ", type
1056 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1057 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1059 string_digits = '%i ' % type.digits() # convert int to string
1060 string_scale = '%i ' % type.scale() # convert int to string
1061 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
1063 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1064 self.addvar(self.c_seq)
1067 def get_CDR_char(self,pn):
1068 self.st.out(self.template_get_CDR_char, varname=pn)
1069 self.addvar(self.c_u_octet1)
1071 def get_CDR_octet(self,pn):
1072 self.st.out(self.template_get_CDR_octet, varname=pn)
1073 self.addvar(self.c_u_octet1)
1075 def get_CDR_any(self,pn):
1076 self.st.out(self.template_get_CDR_any, varname=pn)
1078 def get_CDR_enum(self,pn,type):
1079 #self.st.out(self.template_get_CDR_enum, varname=pn)
1080 sname = self.namespace(type.unalias(), "_")
1081 self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname)
1084 self.addvar(self.c_u_octet4)
1086 def get_CDR_string(self,pn):
1087 self.st.out(self.template_get_CDR_string, varname=pn)
1088 self.addvar(self.c_u_octet4)
1089 self.addvar(self.c_seq)
1091 def get_CDR_wstring(self,pn):
1092 self.st.out(self.template_get_CDR_wstring, varname=pn)
1093 self.addvar(self.c_u_octet4)
1094 self.addvar(self.c_seq)
1096 def get_CDR_wchar(self,pn):
1097 self.st.out(self.template_get_CDR_wchar, varname=pn)
1098 self.addvar(self.c_s_octet1)
1099 self.addvar(self.c_seq)
1101 def get_CDR_TypeCode(self,pn):
1102 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1103 self.addvar(self.c_u_octet4)
1105 def get_CDR_objref(self,type,pn):
1106 self.st.out(self.template_get_CDR_object)
1108 def get_CDR_sequence_len(self,pn):
1109 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1110 self.addvar(self.c_u_octet4)
1114 def get_CDR_union(self,type,pn):
1116 print "XXX Union type =" , type, " pn = ",pn
1117 print "XXX Union type.decl()" , type.decl()
1118 print "XXX Union Scoped Name" , type.scopedName()
1120 # If I am a typedef union {..}; node then find the union node
1122 if isinstance(type.decl(), idlast.Declarator):
1123 ntype = type.decl().alias().aliasType().decl()
1125 ntype = type.decl() # I am a union node
1128 print "XXX Union ntype =" , ntype
1130 sname = self.namespace(ntype, "_")
1131 self.st.out(self.template_union_start, name=sname )
1133 # Output a call to the union helper function so I can handle recursive union also.
1135 self.st.out(self.template_decode_union,name=sname)
1137 self.st.out(self.template_union_end, name=sname )
1141 # Code to generate Union Helper functions
1143 # in: un - a union node
1148 def genUnionHelper(self,un):
1150 print "XXX Union type =" , un
1151 print "XXX Union type.decl()" , un.decl()
1152 print "XXX Union Scoped Name" , un.scopedName()
1154 sname = self.namespace(un, "_")
1155 self.curr_sname = sname # update current opnode/exnode/stnode/unnode scoped name
1156 if not self.fn_hash_built:
1157 self.fn_hash[sname] = [] # init empty list as val for this sname key
1158 # but only if the fn_hash is not already built
1160 self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
1161 self.st.inc_indent()
1163 self.st.out(self.template_helper_function_vars_start)
1164 self.dumpCvars(sname)
1165 self.st.out(self.template_helper_function_vars_end )
1167 self.st.out(self.template_union_helper_function_get_endianess)
1169 st = un.switchType().unalias() # may be typedef switch type, so find real type
1171 self.st.out(self.template_comment_union_code_start, uname=un.repoId() )
1173 self.getCDR3(st,un.identifier());
1175 # Depending on what kind of discriminant I come accross (enum,integer,char,
1176 # short, boolean), make sure I cast the return value of the get_XXX accessor
1177 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1178 # return an integer, or an Enumerator object that is then converted to its
1179 # integer equivalent.
1182 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1185 if (st.kind() == idltype.tk_enum):
1187 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1188 self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
1189 self.addvar(self.c_s_disc + un.identifier() + ";")
1191 elif (st.kind() == idltype.tk_long):
1192 self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
1193 self.addvar(self.c_s_disc + un.identifier() + ";")
1195 elif (st.kind() == idltype.tk_ulong):
1196 self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
1197 self.addvar(self.c_s_disc + un.identifier() + ";")
1199 elif (st.kind() == idltype.tk_short):
1200 self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
1201 self.addvar(self.c_s_disc + un.identifier() + ";")
1203 elif (st.kind() == idltype.tk_ushort):
1204 self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
1205 self.addvar(self.c_s_disc + un.identifier() + ";")
1207 elif (st.kind() == idltype.tk_boolean):
1208 self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier() )
1209 self.addvar(self.c_s_disc + un.identifier() + ";")
1211 elif (st.kind() == idltype.tk_char):
1212 self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
1213 self.addvar(self.c_s_disc + un.identifier() + ";")
1216 print "XXX Unknown st.kind() = ", st.kind()
1219 # Loop over all cases in this union
1222 for uc in un.cases(): # for all UnionCase objects in this union
1223 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1225 # get integer value, even if discriminant is
1226 # an Enumerator node
1228 if isinstance(cl.value(),idlast.Enumerator):
1230 print "XXX clv.identifier()", cl.value().identifier()
1231 print "XXX clv.repoId()", cl.value().repoId()
1232 print "XXX clv.scopedName()", cl.value().scopedName()
1234 # find index of enumerator in enum declaration
1235 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1237 clv = self.valFromEnum(std,cl.value())
1242 #print "XXX clv = ",clv
1245 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1246 # eg: if (disc == 'b')..
1248 # TODO : handle \xxx chars generically from a function or table lookup rather than
1249 # a whole bunch of "if" statements. -- FS
1252 if (st.kind() == idltype.tk_char):
1253 if (clv == '\n'): # newline
1254 string_clv = "'\\n'"
1255 elif (clv == '\t'): # tab
1256 string_clv = "'\\t'"
1258 string_clv = "'" + clv + "'"
1260 string_clv = '%i ' % clv
1263 # If default case, then skp comparison with discriminator
1266 if not cl.default():
1267 self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
1268 self.st.inc_indent()
1270 self.st.out(self.template_comment_union_code_label_default_start )
1273 self.getCDR3(uc.caseType(),uc.declarator().identifier())
1275 if not cl.default():
1276 self.st.dec_indent()
1277 self.st.out(self.template_comment_union_code_label_compare_end )
1279 self.st.out(self.template_comment_union_code_label_default_end )
1281 self.st.dec_indent()
1282 self.st.out(self.template_union_helper_function_end)
1287 # Currently, get_CDR_alias is geared to finding typdef
1290 def get_CDR_alias(self,type,pn):
1292 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1293 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1294 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1296 decl = type.decl() # get declarator object
1298 if (decl.sizes()): # a typedef array
1299 indices = self.get_indices_from_sizes(decl.sizes())
1300 string_indices = '%i ' % indices # convert int to string
1301 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1303 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1304 self.addvar(self.c_i + pn + ";")
1305 self.st.inc_indent()
1306 self.getCDR3(type.decl().alias().aliasType(), pn )
1308 self.st.dec_indent()
1309 self.st.out(self.template_get_CDR_array_end)
1312 else: # a simple typdef
1314 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1315 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1317 self.getCDR3(type, decl.identifier() )
1325 # Handle structs, including recursive
1328 def get_CDR_struct(self,type,pn):
1330 # If I am a typedef struct {..}; node then find the struct node
1332 if isinstance(type.decl(), idlast.Declarator):
1333 ntype = type.decl().alias().aliasType().decl()
1335 ntype = type.decl() # I am a struct node
1337 sname = self.namespace(ntype, "_")
1338 self.st.out(self.template_structure_start, name=sname )
1340 # Output a call to the struct helper function so I can handle recursive structs also.
1342 self.st.out(self.template_decode_struct,name=sname)
1344 self.st.out(self.template_structure_end, name=sname )
1349 # Generate private helper functions to decode a struct
1351 # in: stnode ( a struct node)
1354 def genStructHelper(self,st):
1356 print "XXX genStructHelper"
1358 sname = self.namespace(st, "_")
1359 self.curr_sname = sname # update current opnode/exnode/stnode scoped name
1360 if not self.fn_hash_built:
1361 self.fn_hash[sname] = [] # init empty list as val for this sname key
1362 # but only if the fn_hash is not already built
1364 self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
1365 self.st.inc_indent()
1367 self.st.out(self.template_helper_function_vars_start)
1368 self.dumpCvars(sname)
1369 self.st.out(self.template_helper_function_vars_end )
1371 self.st.out(self.template_struct_helper_function_get_endianess)
1373 for m in st.members():
1374 for decl in m.declarators():
1375 if decl.sizes(): # an array
1376 indices = self.get_indices_from_sizes(decl.sizes())
1377 string_indices = '%i ' % indices # convert int to string
1378 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1379 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1380 self.addvar(self.c_i + decl.identifier() + ";")
1382 self.st.inc_indent()
1383 self.getCDR3(m.memberType(), st.identifier() + "_" + decl.identifier() )
1384 self.st.dec_indent()
1385 self.st.out(self.template_get_CDR_array_end)
1389 self.getCDR3(m.memberType(), st.identifier() + "_" + decl.identifier() )
1391 self.st.dec_indent()
1392 self.st.out(self.template_struct_helper_function_end)
1399 # Generate code to access a sequence of a type
1403 def get_CDR_sequence(self,type, pn):
1404 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1405 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1406 self.addvar(self.c_i_lim + pn + ";" )
1407 self.addvar(self.c_i + pn + ";")
1409 self.st.inc_indent()
1410 self.getCDR3(type.unalias().seqType(), pn ) # and start all over with the type
1411 self.st.dec_indent()
1413 self.st.out(self.template_get_CDR_sequence_loop_end)
1418 # Generate code to access arrays,
1420 # This is handled elsewhere. Arrays are either typedefs or in
1423 # TODO - Remove this
1426 def get_CDR_array(self,type, decl):
1428 print "XXX get_CDR_array called "
1429 print "XXX array size = " ,decl.sizes()
1437 # out - scoped operation name, using sep character instead of "::"
1439 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1443 def namespace(self,node,sep):
1444 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1445 #print "XXX namespace: sname = " + sname
1450 # generate code for plugin initialisation
1453 def gen_plugin_init(self):
1454 self.st.out(self.template_plugin_init, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1457 # generate register_giop_user_module code, and register only
1458 # unique interfaces that contain operations. Also output
1459 # a heuristic register in case we want to use that.
1461 # TODO - make this a command line option
1469 def gen_proto_reg_handoff(self, oplist):
1471 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1472 self.st.inc_indent()
1474 for iname in self.get_intlist(oplist):
1475 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1477 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1478 self.st.dec_indent()
1480 self.st.out(self.template_proto_reg_handoff_end)
1485 # generate proto_register_<protoname> code,
1489 def gen_proto_register(self):
1490 self.st.out(self.template_proto_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1496 # out - a list of unique interface names. This will be used in
1497 # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1498 # name must be removed from the scope. And we also only want unique interfaces.
1501 def get_intlist(self,oplist):
1502 int_hash = {} # holds a hash of unique interfaces
1504 sc = op.scopedName() # eg: penguin,tux,bite
1505 sc1 = sc[:-1] # drop last entry
1506 sn = idlutil.slashName(sc1) # penguin/tux
1507 if not int_hash.has_key(sn):
1508 int_hash[sn] = 0; # dummy val, but at least key is unique
1510 return int_hash.keys()
1517 # out - a list of exception nodes (unique). This will be used in
1518 # to generate dissect_exception_XXX functions.
1523 def get_exceptionList(self,oplist):
1524 ex_hash = {} # holds a hash of unique exceptions.
1526 for ex in op.raises():
1527 if not ex_hash.has_key(ex):
1528 ex_hash[ex] = 0; # dummy val, but at least key is unique
1530 print "XXX Exception = " + ex.identifier()
1532 return ex_hash.keys()
1537 # Simple function to take a list of array sizes and find the
1538 # total number of elements
1541 # eg: temp[4][3] = 12 elements
1544 def get_indices_from_sizes(self,sizelist):
1552 # Determine how many octets contain requested number
1553 # of digits for an "fixed" IDL type "on the wire"
1556 def dig_to_len(self,dignum):
1557 return (dignum/2) + 1
1562 # Output some TODO comment
1566 def genTODO(self,message):
1567 self.st.out(self.template_debug_TODO, message=message)
1570 # Output some WARNING comment
1574 def genWARNING(self,message):
1575 self.st.out(self.template_debug_WARNING, message=message)
1578 # Templates for C code
1583 template_comment_operations_start = """\
1585 * IDL Operations Start
1591 template_operations_declare = """static const char @sname@_op[] = \"@opname@\" ;"""
1594 template_comment_operations_end = """
1596 * IDL Operations End
1601 template_helper_function_comment = """\
1609 template_helper_function_vars_start = """
1610 /* Operation specific Variable declarations Begin */
1613 template_helper_function_vars_end = """
1614 /* Operation specific Variable declarations End */
1619 template_helper_function_start = """\
1620 static void decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header, gchar *operation _U_) {
1622 gboolean stream_is_big_endian; /* big endianess */
1625 template_helper_function_end = """\
1630 # proto_reg_handoff() templates
1634 template_proto_reg_handoff_start = """
1635 /* register me as handler for these interfaces */
1637 void proto_register_handoff_giop_@dissector_name@(void) {
1641 template_proto_reg_handoff_body = """
1644 /* Register for Explicit Dissection */
1646 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
1652 template_proto_reg_handoff_heuristic = """
1654 /* Register for Heuristic Dissection */
1656 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
1660 template_proto_reg_handoff_end = """
1666 # Initialize the protocol
1669 template_protocol = """
1670 /* Initialise the protocol and subtree pointers */
1672 static int proto_@dissector_name@ = -1;
1674 static gint ett_@dissector_name@ = -1;
1681 # Initialize the boundary Alignment
1684 template_init_boundary = """
1685 /* Initialise the initial Alignment */
1687 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */
1696 # Initialize the Registered fields
1699 template_registered_fields = """
1701 /* Initialise the Registered fields */
1703 /* TODO - Use registered fields */
1708 # plugin_init and plugin_reg_handoff templates
1711 template_plugin_init = """
1713 #ifndef __ETHEREAL_STATIC__
1715 G_MODULE_EXPORT void
1716 plugin_reg_handoff(void){
1717 proto_register_handoff_giop_@dissector_name@();
1720 G_MODULE_EXPORT void
1721 plugin_init(plugin_address_table_t *pat
1722 #ifndef PLUGINS_NEED_ADDRESS_TABLE
1726 /* initialise the table of pointers needed in Win32 DLLs */
1727 plugin_address_table_init(pat);
1728 if (proto_@dissector_name@ == -1) {
1729 proto_register_giop_@dissector_name@();
1738 # proto_register_<dissector name>(void) templates
1742 template_proto_register = """
1744 /* Register the protocol with Ethereal */
1746 void proto_register_giop_@dissector_name@(void) {
1748 /* setup list of header fields */
1751 static hf_register_info hf[] = {
1758 /* setup protocol subtree array */
1760 static gint *ett[] = {
1761 &ett_@dissector_name@,
1764 /* Register the protocol name and description */
1766 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
1769 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
1771 proto_register_subtree_array(ett,array_length(ett));
1779 # template for delegation code
1782 template_op_delegate_code = """\
1783 if (!strcmp(operation, @sname@_op )) {
1784 decode_@sname@(tvb, pinfo, tree, offset, header, operation);
1790 # Templates for the helper functions
1796 template_helper_switch_msgtype_start = """\
1798 stream_is_big_endian = is_big_endian(header);
1800 switch(header->message_type) {
1803 template_helper_switch_msgtype_default_start = """\
1806 /* Unknown GIOP Exception */
1808 g_warning("Unknown GIOP Message");
1811 template_helper_switch_msgtype_default_end = """\
1817 template_helper_switch_msgtype_end = """\
1819 } /* switch(header->message_type) */
1822 template_helper_switch_msgtype_request_start = """\
1826 template_helper_switch_msgtype_request_end = """\
1830 template_helper_switch_msgtype_reply_start = """\
1834 template_helper_switch_msgtype_reply_no_exception_start = """\
1838 template_helper_switch_msgtype_reply_no_exception_end = """\
1843 template_helper_switch_msgtype_reply_user_exception_start = """\
1844 case USER_EXCEPTION:
1847 template_helper_switch_msgtype_reply_user_exception_end = """\
1851 template_helper_switch_msgtype_reply_default_start = """\
1854 /* Unknown Exception */
1856 g_warning("Unknown Exception ");
1861 template_helper_switch_msgtype_reply_default_end = """\
1866 template_helper_switch_msgtype_reply_end = """\
1870 template_helper_switch_msgtype_default_start = """\
1873 /* Unknown GIOP Message */
1875 g_warning("Unknown GIOP Message");
1879 template_helper_switch_msgtype_default_end = """\
1885 template_helper_switch_rep_status_start = """\
1886 switch(header->rep_status) {
1889 template_helper_switch_rep_status_default_start = """\
1892 /* Unknown Reply Status */
1894 g_warning("Unknown Reply Status");
1898 template_helper_switch_rep_status_default_end = """\
1902 template_helper_switch_rep_status_end = """\
1904 } /* switch(header->message_type) */
1914 # Templates for get_CDR_xxx accessors
1917 template_get_CDR_ulong = """\
1918 u_octet4 = get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary);
1920 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %u",u_octet4);
1924 template_get_CDR_short = """\
1925 s_octet2 = get_CDR_short(tvb,offset,stream_is_big_endian, boundary);
1927 proto_tree_add_text(tree,tvb,*offset-2,2,"@varname@ = %i",s_octet2);
1931 template_get_CDR_void = """\
1933 /* Function returns void */
1937 template_get_CDR_long = """\
1938 s_octet4 = get_CDR_long(tvb,offset,stream_is_big_endian, boundary);
1940 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %i",s_octet4);
1944 template_get_CDR_ushort = """\
1945 u_octet2 = get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary);
1947 proto_tree_add_text(tree,tvb,*offset-2,2,"@varname@ = %u",u_octet2);
1950 template_get_CDR_float = """\
1951 my_float = get_CDR_float(tvb,offset,stream_is_big_endian, boundary);
1953 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %.6e",my_float);
1957 template_get_CDR_double = """\
1958 my_double = get_CDR_double(tvb,offset,stream_is_big_endian, boundary);
1960 proto_tree_add_text(tree,tvb,*offset-8,8,"@varname@ = %.15e",my_double);
1964 template_get_CDR_boolean = """\
1965 u_octet1 = get_CDR_boolean(tvb,offset);
1967 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1971 template_get_CDR_char = """\
1972 u_octet1 = get_CDR_char(tvb,offset);
1974 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1978 template_get_CDR_octet = """\
1979 u_octet1 = get_CDR_octet(tvb,offset);
1981 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1987 template_get_CDR_any = """\
1988 get_CDR_any(tvb,tree,offset,stream_is_big_endian, boundary, header);
1992 template_get_CDR_fixed = """\
1993 get_CDR_fixed(tvb, &seq, offset, @digits@, @scale@);
1995 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
1998 g_free(seq); /* free buffer */
2004 template_get_CDR_enum_symbolic = """\
2006 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2008 proto_tree_add_text(tree,tvb,*offset-4,4,"Enum value = %u (%s)",u_octet4,val_to_str(u_octet4,@valstringarray@,"Unknown Enum Value"));
2014 template_get_CDR_string = """\
2015 u_octet4 = get_CDR_string(tvb, &seq, offset, stream_is_big_endian, boundary);
2017 proto_tree_add_text(tree,tvb,*offset-4-u_octet4,4,"length = %u",u_octet4);
2019 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ = %s",seq);
2023 g_free(seq); /* free buffer */
2028 template_get_CDR_wstring = """\
2029 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2031 proto_tree_add_text(tree,tvb,*offset-4-u_octet4,4,"length = %u",u_octet4);
2033 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ = %s",seq);
2037 g_free(seq); /* free buffer */
2042 template_get_CDR_wchar = """\
2043 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2046 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
2049 s_octet1 = -s_octet1;
2052 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
2056 g_free(seq); /* free buffer */
2063 template_get_CDR_TypeCode = """\
2064 u_octet4 = get_CDR_typeCode(tvb, tree, offset, stream_is_big_endian, boundary, header);
2068 template_get_CDR_object = """\
2069 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2074 template_get_CDR_sequence_length = """\
2075 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2077 proto_tree_add_text(tree,tvb,*offset-4, 4 ,"Seq length of @seqname@ = %u",u_octet4_loop_@seqname@);
2081 template_get_CDR_sequence_loop_start = """\
2082 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2084 template_get_CDR_sequence_loop_end = """\
2090 template_get_CDR_array_start = """\
2091 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2093 template_get_CDR_array_end = """\
2097 template_get_CDR_array_comment = """\
2098 /* Array: @aname@[ @asize@] */
2104 template_structure_start = """\
2105 /* Begin struct \"@name@\" */
2109 template_structure_end = """\
2110 /* End struct \"@name@\" */
2113 template_union_start = """\
2114 /* Begin union \"@name@\" */
2118 template_union_end = """\
2119 /* End union \"@name@\" */
2126 # Program Header Template
2129 template_Header = """\
2130 /* packet-@dissector_name@.c
2131 * Routines for IDL dissection
2133 * Autogenerated from idl2eth
2134 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2139 template_ethereal_copyright = """\
2141 * Ethereal - Network traffic analyzer
2143 * Copyright 1999 Gerald Combs
2157 * This program is free software; you can redistribute it and/or
2158 * modify it under the terms of the GNU General Public License
2159 * as published by the Free Software Foundation; either version 2
2160 * of the License, or (at your option) any later version.
2162 * This program is distributed in the hope that it will be useful,
2163 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2164 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2165 * GNU General Public License for more details.
2167 * You should have received a copy of the GNU General Public License
2168 * along with this program; if not, write to the Free Software
2169 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2178 template_Includes = """\
2180 #ifdef HAVE_CONFIG_H
2181 # include "config.h"
2184 #include "plugins/plugin_api.h"
2188 #include <gmodule.h>
2190 #ifdef NEED_SNPRINTF_H
2191 # include "snprintf.h"
2196 #include <epan/packet.h>
2197 #include <epan/proto.h>
2198 #include "packet-giop.h"
2200 #include "plugins/plugin_api_defs.h"
2202 #ifndef __ETHEREAL_STATIC__
2203 G_MODULE_EXPORT const gchar version[] = "0.0.1";
2210 # Main dissector entry templates
2213 template_main_dissector_start = """\
2214 static gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname _U_) {
2216 proto_item *ti = NULL;
2217 proto_tree *tree = NULL; /* init later, inside if(tree) */
2219 gboolean be; /* big endianess */
2221 if (check_col(pinfo->cinfo, COL_PROTOCOL))
2222 col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2225 * Do not clear COL_INFO, as nothing is being written there by
2226 * this dissector yet. So leave it as is from the GIOP dissector.
2227 * TODO: add something useful to COL_INFO
2228 * if (check_col(pinfo->cinfo, COL_INFO))
2229 * col_clear(pinfo->cinfo, COL_INFO);
2233 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, tvb_length(tvb) - *offset, FALSE);
2234 tree = proto_item_add_subtree(ti, ett_@dissname@);
2238 be = is_big_endian(header); /* get endianess - TODO use passed in stream_is_big_endian instead ? */
2240 /* If we have a USER Exception, then decode it and return */
2242 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2244 return decode_user_exception(tvb, pinfo, tree, offset, header, operation);
2254 template_main_dissector_switch_msgtype_start = """\
2255 switch(header->message_type) {
2258 template_main_dissector_switch_msgtype_start_request_reply = """\
2264 template_main_dissector_switch_msgtype_end_request_reply = """\
2270 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2274 case CloseConnection:
2277 return FALSE; /* not handled yet */
2280 return FALSE; /* not handled yet */
2287 template_main_dissector_end = """\
2291 } /* End of main dissector */
2301 #-------------------------------------------------------------#
2302 # Exception handling templates #
2303 #-------------------------------------------------------------#
2311 template_exception_helpers_start = """\
2312 /* Begin Exception Helper Functions */
2316 template_exception_helpers_end = """\
2318 /* End Exception Helper Functions */
2325 # Templates for declaration of string constants for user exceptions.
2328 template_comment_user_exceptions_string_declare_start = """\
2329 /* Begin Exception (containing members) String Declare */
2333 template_user_exceptions_declare = """static const char user_exception_@sname@[] = \"@exname@\" ; """
2336 template_comment_user_exceptions_string_declare_end = """\
2338 /* End Exception (containing members) String Declare */
2346 # template for Main delegator for exception handling
2349 template_main_exception_delegator_start = """\
2352 * Main delegator for exception handling
2356 static gboolean decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, gchar *operation _U_ ) {
2358 gboolean be _U_; /* big endianess */
2365 # template for exception delegation code body
2367 template_ex_delegate_code = """\
2368 if (!strcmp(header->exception_id, user_exception_@sname@ )) {
2369 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation); /* @exname@ */
2377 # End of Main delegator for exception handling
2380 template_main_exception_delegator_end = """\
2383 return FALSE; /* user exception not found */
2390 # template for exception helper code
2394 template_exception_helper_function_start = """\
2396 /* Exception = @exname@ */
2398 static void decode_ex_@sname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2400 gboolean stream_is_big_endian; /* big endianess */
2406 # Template for the helper function
2407 # to get stream endianess from header
2410 template_exception_helper_function_get_endianess = """\
2412 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2417 template_exception_helper_function_end = """\
2423 # template for struct helper code
2427 template_struct_helper_function_start = """\
2429 /* Struct = @stname@ */
2431 static void decode_@sname@_st(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2433 gboolean stream_is_big_endian; /* big endianess */
2440 # Template for the helper function
2441 # to get stream endianess from header
2444 template_struct_helper_function_get_endianess = """\
2446 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2451 template_struct_helper_function_end = """\
2456 # template for union helper code
2460 template_union_helper_function_start = """\
2462 /* Union = @unname@ */
2464 static void decode_@sname@_un(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2466 gboolean stream_is_big_endian; /* big endianess */
2473 # Template for the helper function
2474 # to get stream endianess from header
2477 template_union_helper_function_get_endianess = """\
2479 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2484 template_union_helper_function_end = """\
2490 #-------------------------------------------------------------#
2491 # Value string templates #
2492 #-------------------------------------------------------------#
2494 template_value_string_start = """\
2495 static const value_string @valstringname@[] = {
2498 template_value_string_entry = """\
2499 { @intval@, \"@description@\" }, """
2501 template_value_string_end = """\
2509 #-------------------------------------------------------------#
2510 # Enum handling templates #
2511 #-------------------------------------------------------------#
2513 template_comment_enums_start = """\
2520 template_comment_enums_end = """\
2527 template_comment_enum_comment = """\
2536 #-------------------------------------------------------------#
2537 # Attribute handling templates #
2538 #-------------------------------------------------------------#
2541 template_comment_attributes_start = """\
2543 * IDL Attributes Start
2549 # get/set accessor method names are language mapping dependant.
2552 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2553 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2556 template_comment_attributes_end = """
2558 * IDL Attributes End
2565 # template for Attribute delegation code
2567 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2568 # Note: _set_xxx() should only be called for Request
2572 template_at_delegate_code_get = """\
2573 if (!strcmp(operation, get_@sname@_at ) && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2574 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation);
2579 template_at_delegate_code_set = """\
2580 if (!strcmp(operation, set_@sname@_at ) && (header->message_type == Request) ) {
2581 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation);
2588 template_attribute_helpers_start = """\
2589 /* Begin Attribute Helper Functions */
2593 template_attribute_helpers_end = """\
2595 /* End Attribute Helper Functions */
2600 # template for attribute helper code
2604 template_attribute_helper_function_start = """\
2606 /* Attribute = @atname@ */
2608 static void decode_@sname@_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2610 gboolean stream_is_big_endian; /* big endianess */
2616 # Template for the helper function
2617 # to get stream endianess from header
2620 template_attribute_helper_function_get_endianess = """\
2622 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2627 template_attribute_helper_function_end = """\
2632 #-------------------------------------------------------------#
2633 # Debugging templates #
2634 #-------------------------------------------------------------#
2638 # Template for outputting TODO "C" comments
2639 # so user know I need ti improve something.
2642 template_debug_TODO = """\
2644 /* TODO - @message@ */
2648 # Template for outputting WARNING "C" comments
2649 # so user know if I have found a problem.
2652 template_debug_WARNING = """\
2654 /* WARNING - @message@ */
2659 #-------------------------------------------------------------#
2660 # IDL Union templates #
2661 #-------------------------------------------------------------#
2665 template_comment_union_code_start = """\
2667 * IDL Union Start - @uname@
2673 template_comment_union_code_end = """
2675 * IDL union End - @uname@
2680 template_comment_union_code_discriminant = """\
2682 * IDL Union - Discriminant - @uname@
2688 # Cast Unions types to something appropriate
2689 # Enum value cast to guint32, all others cast to gint32
2690 # as omniidl accessor returns integer or Enum.
2693 template_union_code_save_discriminant_enum = """\
2694 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2697 template_union_code_save_discriminant_long = """\
2698 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2701 template_union_code_save_discriminant_ulong = """\
2702 disc_s_@discname@ = (gint32) u_octet4; /* save guint32 discriminant and cast to gint32 */
2705 template_union_code_save_discriminant_short = """\
2706 disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
2709 template_union_code_save_discriminant_ushort = """\
2710 disc_s_@discname@ = (gint32) u_octet2; /* save guint16 discriminant and cast to gint32 */
2713 template_union_code_save_discriminant_char = """\
2714 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2717 template_union_code_save_discriminant_boolean = """\
2718 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2722 template_comment_union_code_label_compare_start = """\
2723 if (disc_s_@discname@ == @labelval@) {
2726 template_comment_union_code_label_compare_end = """\
2727 return; /* End Compare for this discriminant type */
2733 template_comment_union_code_label_default_start = """
2734 /* Default Union Case Start */
2738 template_comment_union_code_label_default_end = """\
2739 /* Default Union Case End */
2744 # Templates for function prototypes.
2745 # This is used in genDeclares() for declaring function prototypes
2746 # for structs and union helper functions.
2749 template_prototype_struct_start = """
2750 /* Struct prototype declaration Start */
2754 template_prototype_struct_end = """
2755 /* Struct prototype declaration End */
2759 template_prototype_struct_body = """
2761 /* Struct = @stname@ */
2763 static void decode_@name@_st(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation);
2767 template_decode_struct = """
2769 decode_@name@_st(tvb, pinfo, tree, offset, header, operation);
2776 template_prototype_union_start = """
2777 /* Union prototype declaration Start */
2781 template_prototype_union_end = """
2782 /* Union prototype declaration End */
2786 template_prototype_union_body = """
2788 /* Union = @unname@ */
2790 static void decode_@name@_un(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation);
2794 template_decode_union = """
2796 decode_@name@_un(tvb, pinfo, tree, offset, header, operation);