3 # $Id: ethereal_gen.py,v 1.16 2001/11/19 23:00:12 guy Exp $
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 dissector in Ethereal IP protocol anlayser.
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 in subtrees
99 # 17. Recursive struct and union handling [started - pass struct and union list to ethereal_gen.py ]
101 # Also test, Test, TEST
108 # For every operation and attribute do
109 # For return val and all parameters do
110 # find basic IDL type for each parameter
112 # output exception handling code
113 # output attribute handling code
117 class ethereal_gen_C:
121 # Turn DEBUG stuff on/off
127 # Some string constants for our templates
130 c_u_octet4 = "guint32 u_octet4;"
131 c_s_octet4 = "gint32 s_octet4;"
132 c_u_octet2 = "guint16 u_octet2;"
133 c_s_octet2 = "gint16 s_octet2;"
134 c_u_octet1 = "guint8 u_octet1;"
135 c_s_octet1 = "gint8 s_octet1;"
137 c_float = "gfloat my_float;"
138 c_double = "gdouble my_double;"
140 c_seq = "gchar *seq = NULL;" # pointer to buffer of gchars
141 c_i = "guint32 i_"; # loop index
142 c_i_lim = "guint32 u_octet4_loop_"; # loop limit
143 c_u_disc = "guint32 disc_u_"; # unsigned int union discriminant variable name (enum)
144 c_s_disc = "gint32 disc_s_"; # signed int union discriminant variable name (other cases, except Enum)
150 def __init__(self, st, protocol_name, dissector_name ,description):
151 self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only
153 self.st_save = st # where 2nd pass should go
154 self.protoname = protocol_name # Protocol Name (eg: ECHO)
155 self.dissname = dissector_name # Dissector name (eg: echo)
156 self.description = description # Detailed Protocol description (eg: Echo IDL Example)
157 self.exlist = [] # list of exceptions used in operations.
158 #self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
159 self.fn_hash = {} # top level hash to contain key = function/exception and val = list of variable declarations
161 self.fn_hash_built = 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
162 # populated with operations/vars and exceptions/vars
168 # Main entry point, controls sequence of
173 def genCode(self,oplist, atlist, enlist, stlist, unlist): # operation,attribute,enums,struct and union lists
175 self.genHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
176 # so when I come to that operation later, I have the variables to
179 self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
180 # so when I come to that exception later, I have the variables to
183 self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
184 # so when I come to that exception later, I have the variables to
188 self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
190 self.st = self.st_save
191 self.genHeader() # initial dissector comments
192 self.genEthCopyright() # Ethereal Copyright comments.
193 self.genGPL() # GPL license
195 self.genDeclares(oplist)
197 self.genRegisteredFields()
198 self.genOpList(oplist) # string constant declares for operation names
199 self.genExList(oplist) # string constant declares for user exceptions
200 self.genAtList(atlist) # string constant declares for Attributes
201 self.genEnList(enlist) # string constant declares for Enums
204 self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
205 self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
206 self.genAttributeHelpers(atlist) # helper function to decode "attributes"
208 self.genHelpers(oplist)
210 self.genMainEntryStart(oplist)
211 self.genOpDelegator(oplist)
212 self.genAtDelegator(atlist)
213 self.genMainEntryEnd()
215 self.gen_proto_register()
216 self.gen_proto_reg_handoff(oplist)
217 self.gen_plugin_init()
219 #self.dumpvars() # debug
226 # Generate Standard Ethereal Header Comments
231 self.st.out(self.template_Header,dissector_name=self.dissname)
233 print "XXX genHeader"
241 # Ethereal Copyright Info
245 def genEthCopyright(self):
247 print "XXX genEthCopyright"
248 self.st.out(self.template_ethereal_copyright)
262 self.st.out(self.template_GPL)
271 def genIncludes(self):
273 print "XXX genIncludes"
275 self.st.out(self.template_Includes)
282 def genDeclares(self,oplist):
284 print "XXX genDeclares"
293 def genProtocol(self):
294 self.st.out(self.template_protocol, dissector_name=self.dissname)
295 self.st.out(self.template_init_boundary)
299 # genProtoAndRegisteredFields
303 def genRegisteredFields(self):
304 self.st.out(self.template_registered_fields )
312 def genMainEntryStart(self,oplist):
313 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
315 self.st.out(self.template_main_dissector_switch_msgtype_start)
316 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
324 def genMainEntryEnd(self):
326 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
328 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
330 #self.st.out(self.template_main_dissector_switch_msgtype_end)
331 self.st.out(self.template_main_dissector_end)
339 # out: C code for IDL operations
343 # static const char Penguin_Echo_echoShort_op[] = "echoShort" ;
346 def genOpList(self,oplist):
347 self.st.out(self.template_comment_operations_start)
350 sname = self.namespace(n, "_")
351 opname = n.identifier()
352 self.st.out(self.template_operations_declare, sname=sname, opname=opname)
354 self.st.out(self.template_comment_operations_end)
361 # out: C code for IDL User Exceptions that contain members
365 # static const char user_exception_tux_bad_value[] = "IDL:tux/bad_value:1.0" ;
368 def genExList(self,oplist):
370 self.st.out(self.template_comment_user_exceptions_string_declare_start)
372 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
376 print "XXX Exception " , ex.repoId()
377 print "XXX Exception Identifier" , ex.identifier()
378 print "XXX Exception Scoped Name" , ex.scopedName()
380 if (ex.members()): # only if has members
381 sname = self.namespace(ex, "_")
383 self.st.out(self.template_user_exceptions_declare, sname=sname, exname=ex.repoId())
385 self.st.out(self.template_comment_user_exceptions_string_declare_end)
392 # out: C code for IDL attribute decalarations.
394 # NOTE: Mapping of attributes to operation(function) names is tricky.
396 # The actual accessor function names are language-mapping specific. The attribute name
397 # is subject to OMG IDL's name scoping rules; the accessor function names are
398 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
402 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
403 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
407 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
408 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
410 # TODO: Implement some language dependant templates to handle naming conventions
411 # language <=> attribute. for C, C++. Java etc
413 # OR, just add a runtime GUI option to select language binding for attributes -- FS
417 # ie: def genAtlist(self,atlist,language)
422 def genAtList(self,atlist):
423 self.st.out(self.template_comment_attributes_start)
426 for i in n.declarators(): #
427 sname = self.namespace(i, "_")
428 atname = i.identifier()
429 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
431 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
433 self.st.out(self.template_comment_attributes_end)
441 # out: C code for IDL Enum decalarations using "static const value_string" template
446 def genEnList(self,enlist):
448 self.st.out(self.template_comment_enums_start)
451 sname = self.namespace(enum, "_")
453 self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
454 self.st.out(self.template_value_string_start, valstringname=sname)
455 for enumerator in enum.enumerators():
456 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
459 #atname = n.identifier()
460 self.st.out(self.template_value_string_end, valstringname=sname)
462 self.st.out(self.template_comment_enums_end)
474 # genExceptionDelegator
478 # out: C code for User exception delegator
484 def genExceptionDelegator(self,oplist):
486 self.st.out(self.template_main_exception_delegator_start)
489 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
493 print "XXX Exception " , ex.repoId()
494 print "XXX Exception Identifier" , ex.identifier()
495 print "XXX Exception Scoped Name" , ex.scopedName()
497 if (ex.members()): # only if has members
498 sname = self.namespace(ex, "_")
500 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
503 self.st.out(self.template_main_exception_delegator_end)
507 # genAttribueHelpers()
509 # Generate private helper functions to decode Attributes.
513 # For readonly attribute - generate get_xxx()
514 # If NOT readonly attribute - also generate set_xxx()
517 def genAttributeHelpers(self,atlist):
519 print "XXX genAttributeHelpers: atlist = ", atlist
521 self.st.out(self.template_attribute_helpers_start)
523 for attrib in atlist:
524 for decl in attrib.declarators():
525 self.genAtHelper(attrib,decl,"get") # get accessor
526 if not attrib.readonly():
527 self.genAtHelper(attrib,decl,"set") # set accessor
529 self.st.out(self.template_attribute_helpers_end)
534 # Generate private helper functions to decode an attribute
536 # in: at - attribute node
537 # in: decl - declarator belonging to this attribute
538 # in: order - to generate a "get" or "set" helper
540 def genAtHelper(self,attrib,decl,order):
542 print "XXX genAtHelper"
544 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
545 self.curr_sname = sname # update current opnode/exnode scoped name
547 if not self.fn_hash_built:
548 self.fn_hash[sname] = [] # init empty list as val for this sname key
549 # but only if the fn_hash is not already built
551 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
554 self.st.out(self.template_helper_function_vars_start)
555 self.dumpCvars(sname)
556 self.st.out(self.template_helper_function_vars_end )
558 self.st.out(self.template_exception_helper_function_get_endianess)
561 # TODO - attributes are simple types, so remove array handling
564 if decl.sizes(): # an array
565 indices = self.get_indices_from_sizes(decl.sizes())
566 string_indices = '%i ' % indices # convert int to string
567 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
568 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
569 self.addvar(self.c_i + decl.identifier() + ";")
573 self.getCDR3(attrib.attrType(), decl.identifier() )
576 self.st.out(self.template_get_CDR_array_end)
581 self.getCDR3(attrib.attrType(), decl.identifier() )
584 self.st.out(self.template_attribute_helper_function_end)
589 # genExceptionHelpers()
591 # Generate private helper functions to decode Exceptions used
598 def genExceptionHelpers(self,oplist):
599 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
601 print "XXX genExceptionHelpers: exlist = ", exlist
603 self.st.out(self.template_exception_helpers_start)
605 if (ex.members()): # only if has members
606 #print "XXX Exception = " + ex.identifier()
609 self.st.out(self.template_exception_helpers_end)
615 # Generate private helper functions to decode User Exceptions
617 # in: exnode ( an exception node)
620 def genExHelper(self,ex):
622 print "XXX genExHelper"
624 sname = self.namespace(ex, "_")
625 self.curr_sname = sname # update current opnode/exnode scoped name
626 if not self.fn_hash_built:
627 self.fn_hash[sname] = [] # init empty list as val for this sname key
628 # but only if the fn_hash is not already built
630 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
633 self.st.out(self.template_helper_function_vars_start)
634 self.dumpCvars(sname)
635 self.st.out(self.template_helper_function_vars_end )
637 self.st.out(self.template_exception_helper_function_get_endianess)
640 for m in ex.members():
641 #print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
644 for decl in m.declarators():
645 #print "XXX genExhelper, d = ", decl
646 if decl.sizes(): # an array
647 indices = self.get_indices_from_sizes(decl.sizes())
648 string_indices = '%i ' % indices # convert int to string
649 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
650 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
651 self.addvar(self.c_i + decl.identifier() + ";")
654 self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
657 self.st.out(self.template_get_CDR_array_end)
661 self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
664 self.st.out(self.template_exception_helper_function_end)
670 # Generate private helper functions for each IDL operation.
676 def genHelpers(self,oplist):
678 self.genOperation(op)
684 # Generate private helper functions for a specificIDL operation.
689 def genOperation(self,opnode):
691 print "XXX genOperation called"
693 sname = self.namespace(opnode, "_")
694 if not self.fn_hash_built:
695 self.fn_hash[sname] = [] # init empty list as val for this sname key
696 # but only if the fn_hash is not already built
698 self.curr_sname = sname # update current opnode's scoped name
699 opname = opnode.identifier()
701 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
703 self.st.out(self.template_helper_function_start, sname=sname)
706 self.st.out(self.template_helper_function_vars_start)
707 self.dumpCvars(sname)
708 self.st.out(self.template_helper_function_vars_end )
711 self.st.out(self.template_helper_switch_msgtype_start)
713 self.st.out(self.template_helper_switch_msgtype_request_start)
715 self.genOperationRequest(opnode)
716 self.st.out(self.template_helper_switch_msgtype_request_end)
719 self.st.out(self.template_helper_switch_msgtype_reply_start)
722 self.st.out(self.template_helper_switch_rep_status_start)
725 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
727 self.genOperationReply(opnode)
728 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
731 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
733 self.genOpExceptions(opnode)
734 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
737 self.st.out(self.template_helper_switch_msgtype_reply_default_start)
738 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
740 self.st.out(self.template_helper_switch_rep_status_end)
744 self.st.out(self.template_helper_switch_msgtype_default_start)
745 self.st.out(self.template_helper_switch_msgtype_default_end)
747 self.st.out(self.template_helper_switch_msgtype_end)
751 self.st.out(self.template_helper_function_end, sname=sname)
757 # Decode function parameters for a GIOP request message
759 # TODO check for enum
762 def genOperationRequest(self,opnode):
763 for p in opnode.parameters():
766 print "XXX parameter = " ,p
767 print "XXX parameter type = " ,p.paramType()
768 print "XXX parameter type kind = " ,p.paramType().kind()
770 self.getCDR3(p.paramType(),p.identifier())
774 # Decode function parameters for a GIOP reply message
776 # TODO check for enum
779 def genOperationReply(self,opnode):
781 rt = opnode.returnType() # get return type
783 print "XXX opnode = " , opnode
784 print "XXX return type = " , rt
785 print "XXX return type.unalias = " , rt.unalias()
786 print "XXX return type.kind() = " , rt.kind();
789 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
790 #self.getCDR3(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
791 #self.get_CDR_alias(rt, "Operation_Return_Value" )
792 self.get_CDR_alias(rt, rt.name() )
795 self.getCDR3(rt, "Operation_Return_Value") # return value is NOT an alias
797 for p in opnode.parameters():
798 if p.is_out(): # out or inout
799 self.getCDR3(p.paramType(),p.identifier())
801 #self.st.dec_indent()
803 def genOpExceptions(self,opnode):
804 for ex in opnode.raises():
807 for m in ex.members():
809 #print m.memberType(), m.memberType().kind()
811 # Delegator for Operations
814 def genOpDelegator(self,oplist):
816 opname = op.identifier()
817 sname = self.namespace(op, "_")
818 self.st.out(self.template_op_delegate_code, sname=sname)
821 # Delegator for Attributes
824 def genAtDelegator(self,atlist):
826 for i in a.declarators():
827 atname = i.identifier()
828 sname = self.namespace(i, "_")
829 self.st.out(self.template_at_delegate_code_get, sname=sname)
831 self.st.out(self.template_at_delegate_code_set, sname=sname)
835 # Add a variable declaration to the hash of list
838 def addvar(self, var):
839 if not ( var in self.fn_hash[self.curr_sname] ):
840 self.fn_hash[self.curr_sname].append(var)
843 # Print the variable declaration from the hash of list
848 for fn in self.fn_hash.keys():
850 for v in self.fn_hash[fn]:
853 # Print the "C" variable declaration from the hash of list
854 # for a given scoped operation name (eg: tux_penguin_eat)
858 def dumpCvars(self, sname):
859 for v in self.fn_hash[sname]:
864 # Given an enum node, and a enumerator node, return
865 # the enumerator's numerical value.
867 # eg: enum Color {red,green,blue} should return
871 def valFromEnum(self,enumNode, enumeratorNode):
873 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
874 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
876 if isinstance(enumeratorNode,idlast.Enumerator):
877 value = enumNode.enumerators().index(enumeratorNode)
906 ## tk_longdouble = 25
913 ## tk_abstract_interface = 32
919 # This is the main "iterator" function. It takes a node, and tries to output
920 # a get_CDR_XXX accessor method(s). It can call itself multiple times
921 # if I find nested structures etc.
924 def getCDR3(self,type,name="fred"):
926 pt = type.unalias().kind() # param CDR type
927 pn = name # param name
930 print "XXX getCDR3: kind = " , pt
932 if pt == idltype.tk_ulong:
933 self.get_CDR_ulong(pn)
934 elif pt == idltype.tk_void:
935 self.get_CDR_void(pn)
936 elif pt == idltype.tk_short:
937 self.get_CDR_short(pn)
938 elif pt == idltype.tk_long:
939 self.get_CDR_long(pn)
940 elif pt == idltype.tk_ushort:
941 self.get_CDR_ushort(pn)
942 elif pt == idltype.tk_float:
943 self.get_CDR_float(pn)
944 elif pt == idltype.tk_double:
945 self.get_CDR_double(pn)
946 elif pt == idltype.tk_fixed:
947 self.get_CDR_fixed(type.unalias(),pn)
948 elif pt == idltype.tk_boolean:
949 self.get_CDR_boolean(pn)
950 elif pt == idltype.tk_char:
951 self.get_CDR_char(pn)
952 elif pt == idltype.tk_octet:
953 self.get_CDR_octet(pn)
954 elif pt == idltype.tk_any:
956 elif pt == idltype.tk_string:
957 self.get_CDR_string(pn)
958 elif pt == idltype.tk_wstring:
959 self.get_CDR_wstring(pn)
960 elif pt == idltype.tk_wchar:
961 self.get_CDR_wchar(pn)
962 elif pt == idltype.tk_enum:
964 self.get_CDR_enum(pn,type)
965 #self.get_CDR_enum(pn)
967 elif pt == idltype.tk_struct:
968 self.get_CDR_struct(type,pn)
969 elif pt == idltype.tk_TypeCode: # will I ever get here ?
970 self.get_CDR_TypeCode(type,pn)
971 elif pt == idltype.tk_sequence:
972 self.get_CDR_sequence(type,pn)
973 elif pt == idltype.tk_objref:
974 self.get_CDR_objref(type,pn)
975 elif pt == idltype.tk_array:
976 self.get_CDR_array(type,pn)
977 elif pt == idltype.tk_union:
978 self.get_CDR_union(type,pn)
979 elif pt == idltype.tk_alias:
981 print "XXXXX Alias type XXXXX " , type
982 self.get_CDR_alias(type,pn)
984 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
988 # get_CDR_XXX methods are here ..
993 def get_CDR_ulong(self,pn):
994 self.st.out(self.template_get_CDR_ulong, varname=pn)
995 self.addvar(self.c_u_octet4)
997 def get_CDR_short(self,pn):
998 self.st.out(self.template_get_CDR_short, varname=pn)
999 self.addvar(self.c_s_octet2)
1001 def get_CDR_void(self,pn):
1002 self.st.out(self.template_get_CDR_void, varname=pn)
1004 def get_CDR_long(self,pn):
1005 self.st.out(self.template_get_CDR_long, varname=pn)
1006 self.addvar(self.c_s_octet4)
1008 def get_CDR_ushort(self,pn):
1009 self.st.out(self.template_get_CDR_ushort, varname=pn)
1010 self.addvar(self.c_u_octet2)
1012 def get_CDR_float(self,pn):
1013 self.st.out(self.template_get_CDR_float, varname=pn)
1014 self.addvar(self.c_float)
1016 def get_CDR_double(self,pn):
1017 self.st.out(self.template_get_CDR_double, varname=pn)
1018 self.addvar(self.c_double)
1020 def get_CDR_boolean(self,pn):
1021 self.st.out(self.template_get_CDR_boolean, varname=pn)
1022 self.addvar(self.c_u_octet1)
1024 def get_CDR_fixed(self,type,pn):
1026 print "XXXX calling get_CDR_fixed, type = ", type
1027 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1028 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1030 string_digits = '%i ' % type.digits() # convert int to string
1031 string_scale = '%i ' % type.scale() # convert int to string
1032 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
1034 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1035 self.addvar(self.c_seq)
1038 def get_CDR_char(self,pn):
1039 self.st.out(self.template_get_CDR_char, varname=pn)
1040 self.addvar(self.c_u_octet1)
1042 def get_CDR_octet(self,pn):
1043 self.st.out(self.template_get_CDR_octet, varname=pn)
1044 self.addvar(self.c_u_octet1)
1046 def get_CDR_any(self,pn):
1047 self.st.out(self.template_get_CDR_any, varname=pn)
1049 def get_CDR_enum(self,pn,type):
1050 #self.st.out(self.template_get_CDR_enum, varname=pn)
1051 sname = self.namespace(type, "_")
1052 self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname)
1055 self.addvar(self.c_u_octet4)
1057 def get_CDR_string(self,pn):
1058 self.st.out(self.template_get_CDR_string, varname=pn)
1059 self.addvar(self.c_u_octet4)
1060 self.addvar(self.c_seq)
1062 def get_CDR_wstring(self,pn):
1063 self.st.out(self.template_get_CDR_wstring, varname=pn)
1064 self.addvar(self.c_u_octet4)
1065 self.addvar(self.c_seq)
1067 def get_CDR_wchar(self,pn):
1068 self.st.out(self.template_get_CDR_wchar, varname=pn)
1069 self.addvar(self.c_s_octet1)
1070 self.addvar(self.c_seq)
1072 def get_CDR_TypeCode(self,pn):
1073 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1074 self.addvar(self.c_u_octet4)
1076 def get_CDR_objref(self,type,pn):
1077 self.st.out(self.template_get_CDR_object)
1079 def get_CDR_sequence_len(self,pn):
1080 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1081 self.addvar(self.c_u_octet4)
1083 def get_CDR_union(self,type,pn):
1085 print "XXX Union type =" , type, " pn = ",pn
1086 print "XXX Union type.decl()" , type.decl()
1087 print "XXX Union Scoped Name" , type.scopedName()
1089 # If I am a typedef union {..}; node then find the union node
1091 if isinstance(type.decl(), idlast.Declarator):
1092 ntype = type.decl().alias().aliasType().decl()
1094 ntype = type.decl() # I am a union node
1097 print "XXX Union ntype =" , ntype
1099 if ntype.recursive():
1100 sys.stderr.write( "Error: idl2eth does not handle recursive unions yet \n")
1103 st = ntype.switchType().unalias() # may be typedef switch type, so find real type
1108 print "XXX Union ntype =" , ntype
1109 print "XXX Union ntype.switchType =" , st
1110 #print "XXX Union ntype.switchType().decl() = " , std
1111 #print "XXX Union std.repoId() = ", std.repoId()
1114 self.st.out(self.template_comment_union_code_start, uname=ntype.repoId() )
1116 self.getCDR3(st,pn);
1118 # Depending on what kind of discriminant I come accross (enum,integer,char,
1119 # boolean), make sure I cast the return value of the get_XXX accessor
1120 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1121 # return an integer, or an Enumerator object that is then converted to its
1122 # integer equivalent.
1125 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1128 if (st.kind() == idltype.tk_enum):
1130 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1131 self.st.out(self.template_union_code_save_discriminant_enum, discname=pn )
1132 self.addvar(self.c_s_disc + pn + ";")
1134 elif (st.kind() == idltype.tk_long):
1135 self.st.out(self.template_union_code_save_discriminant_long, discname=pn )
1136 self.addvar(self.c_s_disc + pn + ";")
1138 elif (st.kind() == idltype.tk_short):
1139 self.st.out(self.template_union_code_save_discriminant_short, discname=pn )
1140 self.addvar(self.c_s_disc + pn + ";")
1142 elif (st.kind() == idltype.tk_boolean):
1143 self.st.out(self.template_union_code_save_discriminant_boolean, discname=pn )
1144 self.addvar(self.c_s_disc + pn + ";")
1146 elif (st.kind() == idltype.tk_char):
1147 self.st.out(self.template_union_code_save_discriminant_char, discname=pn )
1148 self.addvar(self.c_s_disc + pn + ";")
1151 print "XXX Unknown st.kind() = ", st.kind()
1154 # Loop over all cases in this union
1157 for uc in ntype.cases(): # for all UnionCase objects in this union
1158 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1160 # get integer value, even if discriminant is
1161 # an Enumerator node
1163 if isinstance(cl.value(),idlast.Enumerator):
1165 print "XXX clv.identifier()", cl.value().identifier()
1166 print "XXX clv.repoId()", cl.value().repoId()
1167 print "XXX clv.scopedName()", cl.value().scopedName()
1169 # find index of enumerator in enum declaration
1170 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1172 clv = self.valFromEnum(std,cl.value())
1177 #print "XXX clv = ",clv
1180 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1181 # eg: if (disc == 'b')..
1183 # TODO : handle \xxx chars generically from a function or table lookup rather than
1184 # a whole bunch of "if" statements. -- FS
1187 if (st.kind() == idltype.tk_char):
1188 if (clv == '\n'): # newline
1189 string_clv = "'\\n'"
1190 elif (clv == '\t'): # tab
1191 string_clv = "'\\t'"
1193 string_clv = "'" + clv + "'"
1195 string_clv = '%i ' % clv
1198 # If default case, then skp comparison with discriminator
1201 if not cl.default():
1202 self.st.out(self.template_comment_union_code_label_compare_start, discname=pn,labelval=string_clv )
1203 self.st.inc_indent()
1205 self.st.out(self.template_comment_union_code_label_default_start )
1208 self.getCDR3(uc.caseType(),uc.declarator().identifier())
1210 if not cl.default():
1211 self.st.dec_indent()
1212 self.st.out(self.template_comment_union_code_label_compare_end )
1214 self.st.out(self.template_comment_union_code_label_default_end )
1218 # Currently, get_CDR_alias is geared to finding typdef
1221 def get_CDR_alias(self,type,pn):
1223 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1224 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1225 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1227 decl = type.decl() # get declarator object
1229 if (decl.sizes()): # a typedef array
1230 indices = self.get_indices_from_sizes(decl.sizes())
1231 string_indices = '%i ' % indices # convert int to string
1232 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1234 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1235 self.addvar(self.c_i + pn + ";")
1236 self.st.inc_indent()
1237 self.getCDR3(type.decl().alias().aliasType(), pn )
1239 self.st.dec_indent()
1240 self.st.out(self.template_get_CDR_array_end)
1243 else: # a simple typdef
1245 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1246 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1248 self.getCDR3(type, decl.identifier() )
1255 def get_CDR_struct(self,type,pn):
1256 self.st.out(self.template_structure_start, name=type.name() )
1258 # If I am a typedef struct {..}; node then find the struct node
1260 if isinstance(type.decl(), idlast.Declarator):
1261 ntype = type.decl().alias().aliasType().decl()
1263 ntype = type.decl() # I am a struct node
1265 if ntype.recursive():
1266 sys.stderr.write("Error: idl2eth does not handle recursive structs yet \n")
1269 for m in ntype.members():
1270 for decl in m.declarators():
1271 if decl.sizes(): # an array
1272 indices = self.get_indices_from_sizes(decl.sizes())
1273 string_indices = '%i ' % indices # convert int to string
1274 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1275 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1276 self.addvar(self.c_i + decl.identifier() + ";")
1278 self.st.inc_indent()
1279 self.getCDR3(m.memberType(), type.name() + "_" + decl.identifier() )
1280 self.st.dec_indent()
1281 self.st.out(self.template_get_CDR_array_end)
1285 self.getCDR3(m.memberType(), type.name() + "_" + decl.identifier() )
1287 self.st.out(self.template_structure_end, name=type.name())
1292 # Generate code to access a sequence of a type
1295 def get_CDR_sequence(self,type, pn):
1296 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1297 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1298 self.addvar(self.c_i_lim + pn + ";" )
1299 self.addvar(self.c_i + pn + ";")
1301 self.st.inc_indent()
1302 self.getCDR3(type.unalias().seqType(), pn ) # and start all over with the type
1303 self.st.dec_indent()
1305 self.st.out(self.template_get_CDR_sequence_loop_end)
1310 # Generate code to access arrays,
1312 # This is handled elsewhere. Arrays are either typedefs or in
1315 # TODO - Remove this
1318 def get_CDR_array(self,type, decl):
1320 print "XXX get_CDR_array called "
1321 print "XXX array size = " ,decl.sizes()
1329 # out - scoped operation name, using sep character instead of "::"
1331 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1335 def namespace(self,node,sep):
1336 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1337 #print "XXX namespace: sname = " + sname
1342 # generate code for plugin initialisation
1345 def gen_plugin_init(self):
1346 self.st.out(self.template_plugin_init, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1349 # generate register_giop_user_module code, and register only
1350 # unique interfaces that contain operations. Also output
1351 # a heuristic register in case we want to use that.
1353 # TODO - make this a command line option
1361 def gen_proto_reg_handoff(self, oplist):
1363 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1364 self.st.inc_indent()
1366 for iname in self.get_intlist(oplist):
1367 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1369 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1370 self.st.dec_indent()
1372 self.st.out(self.template_proto_reg_handoff_end)
1377 # generate proto_register_<protoname> code,
1381 def gen_proto_register(self):
1382 self.st.out(self.template_proto_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1388 # out - a list of unique interface names. This will be used in
1389 # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1390 # name must be removed from the scope. And we also only want unique interfaces.
1393 def get_intlist(self,oplist):
1394 int_hash = {} # holds a hash of unique interfaces
1396 sc = op.scopedName() # eg: penguin,tux,bite
1397 sc1 = sc[:-1] # drop last entry
1398 sn = idlutil.slashName(sc1) # penguin/tux
1399 if not int_hash.has_key(sn):
1400 int_hash[sn] = 0; # dummy val, but at least key is unique
1402 return int_hash.keys()
1409 # out - a list of exception nodes (unique). This will be used in
1410 # to generate dissect_exception_XXX functions.
1415 def get_exceptionList(self,oplist):
1416 ex_hash = {} # holds a hash of unique exceptions.
1418 for ex in op.raises():
1419 if not ex_hash.has_key(ex):
1420 ex_hash[ex] = 0; # dummy val, but at least key is unique
1422 print "XXX Exception = " + ex.identifier()
1424 return ex_hash.keys()
1429 # Simple function to take a list of array sizes and find the
1430 # total number of elements
1433 # eg: temp[4][3] = 12 elements
1436 def get_indices_from_sizes(self,sizelist):
1444 # Determine how many octets contain requested number
1445 # of digits for an "fixed" IDL type "on the wire"
1448 def dig_to_len(self,dignum):
1449 return (dignum/2) + 1
1454 # Output some TODO comment
1458 def genTODO(self,message):
1459 self.st.out(self.template_debug_TODO, message=message)
1462 # Output some WARNING comment
1466 def genWARNING(self,message):
1467 self.st.out(self.template_debug_WARNING, message=message)
1470 # Templates for C code
1475 template_comment_operations_start = """\
1477 * IDL Operations Start
1483 template_operations_declare = """static const char @sname@_op[] = \"@opname@\" ;"""
1486 template_comment_operations_end = """
1488 * IDL Operations End
1493 template_helper_function_comment = """\
1501 template_helper_function_vars_start = """
1502 /* Operation specific Variable declarations Begin */
1505 template_helper_function_vars_end = """
1506 /* Operation specific Variable declarations End */
1511 template_helper_function_start = """\
1512 static void decode_@sname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
1514 gboolean stream_is_big_endian; /* big endianess */
1517 template_helper_function_end = """\
1522 # proto_reg_handoff() templates
1526 template_proto_reg_handoff_start = """
1527 /* register me as handler for these interfaces */
1529 void proto_register_handoff_giop_@dissector_name@(void) {
1533 template_proto_reg_handoff_body = """
1536 /* Register for Explicit Dissection */
1538 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
1544 template_proto_reg_handoff_heuristic = """
1546 /* Register for Heuristic Dissection */
1548 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
1552 template_proto_reg_handoff_end = """
1558 # Initialize the protocol
1561 template_protocol = """
1562 /* Initialise the protocol and subtree pointers */
1564 static int proto_@dissector_name@ = -1;
1566 static gint ett_@dissector_name@ = -1;
1573 # Initialize the boundary Alignment
1576 template_init_boundary = """
1577 /* Initialise the initial Alignment */
1579 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */
1588 # Initialize the Registered fields
1591 template_registered_fields = """
1593 /* Initialise the Registered fields */
1595 /* TODO - Use registered fields */
1600 # plugin_init and plugin_reg_handoff templates
1603 template_plugin_init = """
1605 #ifndef __ETHEREAL_STATIC__
1607 G_MODULE_EXPORT void
1608 plugin_reg_handoff(void){
1609 proto_register_handoff_giop_@dissector_name@();
1612 G_MODULE_EXPORT void
1613 plugin_init(plugin_address_table_t *pat){
1614 /* initialise the table of pointers needed in Win32 DLLs */
1615 plugin_address_table_init(pat);
1616 if (proto_@dissector_name@ == -1) {
1617 proto_register_giop_@dissector_name@();
1626 # proto_register_<dissector name>(void) templates
1630 template_proto_register = """
1632 /* Register the protocol with Ethereal */
1634 void proto_register_giop_@dissector_name@(void) {
1636 /* setup list of header fields */
1639 static hf_register_info hf[] = {
1646 /* setup protocol subtree array */
1648 static gint *ett[] = {
1649 &ett_@dissector_name@,
1652 /* Register the protocol name and description */
1654 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
1657 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
1659 proto_register_subtree_array(ett,array_length(ett));
1667 # template for delegation code
1670 template_op_delegate_code = """\
1671 if (!strcmp(operation, @sname@_op )) {
1672 decode_@sname@(tvb, pinfo, tree, offset, header, operation);
1678 # Templates for the helper functions
1684 template_helper_switch_msgtype_start = """\
1686 stream_is_big_endian = is_big_endian(header);
1688 switch(header->message_type) {
1691 template_helper_switch_msgtype_default_start = """\
1694 /* Unknown GIOP Exception */
1696 g_warning("Unknown GIOP Message");
1699 template_helper_switch_msgtype_default_end = """\
1705 template_helper_switch_msgtype_end = """\
1707 } /* switch(header->message_type) */
1710 template_helper_switch_msgtype_request_start = """\
1714 template_helper_switch_msgtype_request_end = """\
1718 template_helper_switch_msgtype_reply_start = """\
1722 template_helper_switch_msgtype_reply_no_exception_start = """\
1726 template_helper_switch_msgtype_reply_no_exception_end = """\
1731 template_helper_switch_msgtype_reply_user_exception_start = """\
1732 case USER_EXCEPTION:
1735 template_helper_switch_msgtype_reply_user_exception_end = """\
1739 template_helper_switch_msgtype_reply_default_start = """\
1742 /* Unknown Exception */
1744 g_warning("Unknown Exception ");
1749 template_helper_switch_msgtype_reply_default_end = """\
1754 template_helper_switch_msgtype_reply_end = """\
1758 template_helper_switch_msgtype_default_start = """\
1761 /* Unknown GIOP Message */
1763 g_warning("Unknown GIOP Message");
1767 template_helper_switch_msgtype_default_end = """\
1773 template_helper_switch_rep_status_start = """\
1774 switch(header->rep_status) {
1777 template_helper_switch_rep_status_default_start = """\
1780 /* Unknown Reply Status */
1782 g_warning("Unknown Reply Status");
1786 template_helper_switch_rep_status_default_end = """\
1790 template_helper_switch_rep_status_end = """\
1792 } /* switch(header->message_type) */
1802 # Templates for get_CDR_xxx accessors
1805 template_get_CDR_ulong = """\
1806 u_octet4 = get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary);
1808 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %u",u_octet4);
1812 template_get_CDR_short = """\
1813 s_octet2 = get_CDR_short(tvb,offset,stream_is_big_endian, boundary);
1815 proto_tree_add_text(tree,tvb,*offset-2,2,"@varname@ = %i",s_octet2);
1819 template_get_CDR_void = """\
1821 /* Function returns void */
1825 template_get_CDR_long = """\
1826 s_octet4 = get_CDR_long(tvb,offset,stream_is_big_endian, boundary);
1828 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %i",s_octet4);
1832 template_get_CDR_ushort = """\
1833 u_octet2 = get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary);
1835 proto_tree_add_text(tree,tvb,*offset-2,2,"@varname@ = %u",u_octet2);
1838 template_get_CDR_float = """\
1839 my_float = get_CDR_float(tvb,offset,stream_is_big_endian, boundary);
1841 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %.6e",my_float);
1845 template_get_CDR_double = """\
1846 my_double = get_CDR_double(tvb,offset,stream_is_big_endian, boundary);
1848 proto_tree_add_text(tree,tvb,*offset-8,8,"@varname@ = %.15e",my_double);
1852 template_get_CDR_boolean = """\
1853 u_octet1 = get_CDR_boolean(tvb,offset);
1855 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1859 template_get_CDR_char = """\
1860 u_octet1 = get_CDR_char(tvb,offset);
1862 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1866 template_get_CDR_octet = """\
1867 u_octet1 = get_CDR_octet(tvb,offset);
1869 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1875 template_get_CDR_any = """\
1876 get_CDR_any(tvb,tree,offset,stream_is_big_endian, boundary, header);
1880 template_get_CDR_fixed = """\
1881 get_CDR_fixed(tvb, &seq, offset, @digits@, @scale@);
1883 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
1886 g_free(seq); /* free buffer */
1892 template_get_CDR_enum_symbolic = """\
1894 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
1896 proto_tree_add_text(tree,tvb,*offset-4,4,"Enum value = %u (%s)",u_octet4,val_to_str(u_octet4,@valstringarray@,"Unknown Enum Value"));
1902 template_get_CDR_string = """\
1903 u_octet4 = get_CDR_string(tvb, &seq, offset, stream_is_big_endian, boundary);
1905 proto_tree_add_text(tree,tvb,*offset-4-u_octet4,4,"length = %u",u_octet4);
1907 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ = %s",seq);
1911 g_free(seq); /* free buffer */
1916 template_get_CDR_wstring = """\
1917 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
1919 proto_tree_add_text(tree,tvb,*offset-4-u_octet4,4,"length = %u",u_octet4);
1921 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ = %s",seq);
1925 g_free(seq); /* free buffer */
1930 template_get_CDR_wchar = """\
1931 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
1934 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
1937 s_octet1 = -s_octet1;
1940 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
1944 g_free(seq); /* free buffer */
1951 template_get_CDR_TypeCode = """\
1952 u_octet4 = get_CDR_typeCode(tvb, tree, offset, stream_is_big_endian, boundary, header);
1956 template_get_CDR_object = """\
1957 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
1962 template_get_CDR_sequence_length = """\
1963 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
1965 proto_tree_add_text(tree,tvb,*offset-4, 4 ,"Seq length of @seqname@ = %u",u_octet4_loop_@seqname@);
1969 template_get_CDR_sequence_loop_start = """\
1970 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
1972 template_get_CDR_sequence_loop_end = """\
1978 template_get_CDR_array_start = """\
1979 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
1981 template_get_CDR_array_end = """\
1985 template_get_CDR_array_comment = """\
1986 /* Array: @aname@[ @asize@] */
1992 template_structure_start = """\
1993 /* Begin struct \"@name@\" */
1997 template_structure_end = """\
1998 /* End struct \"@name@\" */
2005 # Program Header Template
2008 template_Header = """\
2009 /* packet-@dissector_name@.c
2010 * Routines for IDL dissection
2012 * Autogenerated from idl2eth
2013 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2018 template_ethereal_copyright = """\
2020 * Ethereal - Network traffic analyzer
2022 * Copyright 1999 Gerald Combs
2036 * This program is free software; you can redistribute it and/or
2037 * modify it under the terms of the GNU General Public License
2038 * as published by the Free Software Foundation; either version 2
2039 * of the License, or (at your option) any later version.
2041 * This program is distributed in the hope that it will be useful,
2042 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2043 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2044 * GNU General Public License for more details.
2046 * You should have received a copy of the GNU General Public License
2047 * along with this program; if not, write to the Free Software
2048 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2057 template_Includes = """\
2059 #ifdef HAVE_CONFIG_H
2060 # include "config.h"
2063 #include "plugins/plugin_api.h"
2067 #include <gmodule.h>
2069 #ifdef HAVE_SYS_TYPES_H
2070 # include <sys/types.h>
2073 #ifdef HAVE_NETINET_IN_H
2074 # include <netinet/in.h>
2077 #ifdef NEED_SNPRINTF_H
2078 # ifdef HAVE_STDARG_H
2079 # include <stdarg.h>
2081 # include <varargs.h>
2083 # include "snprintf.h"
2090 #include "packet-giop.h"
2092 #include "plugins/plugin_api_defs.h"
2094 #ifndef __ETHEREAL_STATIC__
2095 G_MODULE_EXPORT const gchar version[] = "0.0.1";
2102 # Main dissector entry templates
2105 template_main_dissector_start = """\
2106 static gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname) {
2108 proto_item *ti = NULL;
2109 proto_tree *tree = NULL; /* init later, inside if(tree) */
2111 gboolean be; /* big endianess */
2112 guint32 offset_saved = (*offset); /* save in case we must back out */
2114 pinfo->current_proto = \"@disprot@\";
2116 if (check_col(pinfo->fd, COL_PROTOCOL))
2117 col_add_str(pinfo->fd, COL_PROTOCOL, \"@disprot@\");
2120 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, tvb_length(tvb) - *offset, FALSE);
2121 tree = proto_item_add_subtree(ti, ett_@dissname@);
2125 be = is_big_endian(header); /* get endianess - TODO use passed in stream_is_big_endian instead ? */
2127 /* If we have a USER Exception, then decode it and return */
2129 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2131 return decode_user_exception(tvb, pinfo, tree, offset, header, operation);
2141 template_main_dissector_switch_msgtype_start = """\
2142 switch(header->message_type) {
2145 template_main_dissector_switch_msgtype_start_request_reply = """\
2151 template_main_dissector_switch_msgtype_end_request_reply = """\
2157 template_main_dissector_switch_msgtype_end = """\
2161 * We failed to match ANY operations, so perhaps this is not for us !
2164 (*offset) = offset_saved; /* be nice */
2174 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2178 case CloseConnection:
2181 return FALSE; /* not handled yet */
2184 return FALSE; /* not handled yet */
2191 template_main_dissector_switch_msgtype_end = """\
2199 template_main_dissector_end = """\
2203 } /* End of main dissector */
2213 #-------------------------------------------------------------#
2214 # Exception handling templates #
2215 #-------------------------------------------------------------#
2223 template_exception_helpers_start = """\
2224 /* Begin Exception Helper Functions */
2228 template_exception_helpers_end = """\
2230 /* End Exception Helper Functions */
2237 # Templates for declaration of string constants for user exceptions.
2240 template_comment_user_exceptions_string_declare_start = """\
2241 /* Begin Exception (containing members) String Declare */
2245 template_user_exceptions_declare = """static const char user_exception_@sname@[] = \"@exname@\" ; """
2248 template_comment_user_exceptions_string_declare_end = """\
2250 /* End Exception (containing members) String Declare */
2258 # template for Main delegator for exception handling
2261 template_main_exception_delegator_start = """\
2264 * Main delegator for exception handling
2268 static gboolean decode_user_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation ) {
2270 gboolean be; /* big endianess */
2277 # template for exception delegation code body
2279 template_ex_delegate_code = """\
2280 if (!strcmp(header->exception_id, user_exception_@sname@ )) {
2281 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation); /* @exname@ */
2289 # End of Main delegator for exception handling
2292 template_main_exception_delegator_end = """\
2295 return FALSE; /* user exception not found */
2302 # template for exception helper code
2306 template_exception_helper_function_start = """\
2308 /* Exception = @exname@ */
2310 static void decode_ex_@sname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2312 gboolean stream_is_big_endian; /* big endianess */
2318 # Template for the helper function
2319 # to get stream endianess from header
2322 template_exception_helper_function_get_endianess = """\
2324 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2329 template_exception_helper_function_end = """\
2333 #-------------------------------------------------------------#
2334 # Value string templates #
2335 #-------------------------------------------------------------#
2337 template_value_string_start = """\
2338 static const value_string @valstringname@[] = {
2341 template_value_string_entry = """\
2342 { @intval@, \"@description@\" }, """
2344 template_value_string_end = """\
2352 #-------------------------------------------------------------#
2353 # Enum handling templates #
2354 #-------------------------------------------------------------#
2356 template_comment_enums_start = """\
2363 template_comment_enums_end = """\
2370 template_comment_enum_comment = """\
2379 #-------------------------------------------------------------#
2380 # Attribute handling templates #
2381 #-------------------------------------------------------------#
2384 template_comment_attributes_start = """\
2386 * IDL Attributes Start
2392 # get/set accessor method names are language mapping dependant.
2395 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2396 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2399 template_comment_attributes_end = """
2401 * IDL Attributes End
2408 # template for Attribute delegation code
2410 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2411 # Note: _set_xxx() should only be called for Request
2415 template_at_delegate_code_get = """\
2416 if (!strcmp(operation, get_@sname@_at ) && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2417 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation);
2422 template_at_delegate_code_set = """\
2423 if (!strcmp(operation, set_@sname@_at ) && (header->message_type == Request) ) {
2424 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation);
2431 template_attribute_helpers_start = """\
2432 /* Begin Attribute Helper Functions */
2436 template_attribute_helpers_end = """\
2438 /* End Attribute Helper Functions */
2443 # template for attribute helper code
2447 template_attribute_helper_function_start = """\
2449 /* Attribute = @atname@ */
2451 static void decode_@sname@_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2453 gboolean stream_is_big_endian; /* big endianess */
2459 # Template for the helper function
2460 # to get stream endianess from header
2463 template_attribute_helper_function_get_endianess = """\
2465 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2470 template_attribute_helper_function_end = """\
2475 #-------------------------------------------------------------#
2476 # Debugging templates #
2477 #-------------------------------------------------------------#
2481 # Template for outputting TODO "C" comments
2482 # so user know I need ti improve something.
2485 template_debug_TODO = """\
2487 /* TODO - @message@ */
2491 # Template for outputting WARNING "C" comments
2492 # so user know if I have found a problem.
2495 template_debug_WARNING = """\
2497 /* WARNING - @message@ */
2502 #-------------------------------------------------------------#
2503 # IDL Union templates #
2504 #-------------------------------------------------------------#
2508 template_comment_union_code_start = """\
2510 * IDL Union Start - @uname@
2516 template_comment_union_code_end = """
2518 * IDL union End - @uname@
2523 template_comment_union_code_discriminant = """\
2525 * IDL Union - Discriminant - @uname@
2531 # Cast Unions types to something appropriate
2532 # Enum value cast to guint32, all others cast to gint32
2533 # as omniidl accessor returns integer or Enum.
2536 template_union_code_save_discriminant_enum = """\
2537 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2540 template_union_code_save_discriminant_long = """\
2541 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2544 template_union_code_save_discriminant_short = """\
2545 disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
2548 template_union_code_save_discriminant_char = """\
2549 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2552 template_union_code_save_discriminant_boolean = """\
2553 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2557 template_comment_union_code_label_compare_start = """\
2558 if (disc_s_@discname@ == @labelval@) {
2561 template_comment_union_code_label_compare_end = """\
2568 template_comment_union_code_label_default_start = """
2569 /* Default Union Case Start */
2573 template_comment_union_code_label_default_end = """\
2574 /* Default Union Case End */