3 # $Id: ethereal_gen.py,v 1.11 2001/08/11 04:37:31 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)
98 # Also test, Test, TEST
106 # For return val and all parameters do
107 # find basic IDL type for each parameter
109 # output exception handling code
110 # output attribute handling code
114 class ethereal_gen_C:
118 # Turn DEBUG stuff on/off
124 # Some string constants for our templates
127 c_u_octet4 = "guint32 u_octet4;"
128 c_s_octet4 = "gint32 s_octet4;"
129 c_u_octet2 = "guint16 u_octet2;"
130 c_s_octet2 = "gint16 s_octet2;"
131 c_u_octet1 = "guint8 u_octet1;"
132 c_s_octet1 = "gint8 s_octet1;"
134 c_float = "gfloat my_float;"
135 c_double = "gdouble my_double;"
137 c_seq = "gchar *seq = NULL;" # pointer to buffer of gchars
138 c_i = "guint32 i_"; # loop index
139 c_i_lim = "guint32 u_octet4_loop_"; # loop limit
140 c_u_disc = "guint32 disc_u_"; # unsigned int union discriminant variable name (enum)
141 c_s_disc = "gint32 disc_s_"; # signed int union discriminant variable name (other cases, except Enum)
147 def __init__(self, st, protocol_name, dissector_name ,description):
148 self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only
150 self.st_save = st # where 2nd pass should go
151 self.protoname = protocol_name # Protocol Name (eg: ECHO)
152 self.dissname = dissector_name # Dissector name (eg: echo)
153 self.description = description # Detailed Protocol description (eg: Echo IDL Example)
154 self.exlist = [] # list of exceptions used in operations.
155 #self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
156 self.fn_hash = {} # top level hash to contain key = function/exception and val = list of variable declarations
158 self.fn_hash_built = 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
159 # populated with operations/vars and exceptions/vars
165 # Main entry point, controls sequence of
170 def genCode(self,oplist, atlist): # operation and attribute lists
172 self.genHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
173 # so when I come to that operation later, I have the variables to
176 self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
177 # so when I come to that exception later, I have the variables to
180 self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
181 # so when I come to that exception later, I have the variables to
185 self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
187 self.st = self.st_save
188 self.genHeader() # initial dissector comments
189 self.genEthCopyright() # Ethereal Copyright comments.
190 self.genGPL() # GPL license
192 self.genDeclares(oplist)
194 self.genRegisteredFields()
195 self.genOpList(oplist) # string constant declares for operation names
196 self.genExList(oplist) # string constant declares for user exceptions
197 self.genAtList(atlist) # string constant declares for Attributes
200 self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
201 self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
202 self.genAttributeHelpers(atlist) # helper function to decode "attributes"
204 self.genHelpers(oplist)
206 self.genMainEntryStart(oplist)
207 self.genOpDelegator(oplist)
208 self.genAtDelegator(atlist)
209 self.genMainEntryEnd()
211 self.gen_proto_register()
212 self.gen_proto_reg_handoff(oplist)
213 self.gen_plugin_init()
215 #self.dumpvars() # debug
222 # Generate Standard Ethereal Header Comments
227 self.st.out(self.template_Header,dissector_name=self.dissname)
229 print "XXX genHeader"
237 # Ethereal Copyright Info
241 def genEthCopyright(self):
243 print "XXX genEthCopyright"
244 self.st.out(self.template_ethereal_copyright)
258 self.st.out(self.template_GPL)
267 def genIncludes(self):
269 print "XXX genIncludes"
271 self.st.out(self.template_Includes)
278 def genDeclares(self,oplist):
280 print "XXX genDeclares"
289 def genProtocol(self):
290 self.st.out(self.template_protocol, dissector_name=self.dissname)
291 self.st.out(self.template_init_boundary)
295 # genProtoAndRegisteredFields
299 def genRegisteredFields(self):
300 self.st.out(self.template_registered_fields )
308 def genMainEntryStart(self,oplist):
309 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
311 self.st.out(self.template_main_dissector_switch_msgtype_start)
312 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
320 def genMainEntryEnd(self):
322 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
324 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
326 #self.st.out(self.template_main_dissector_switch_msgtype_end)
327 self.st.out(self.template_main_dissector_end)
335 # out: C code for IDL operations
339 # static const char Penguin_Echo_echoShort_op[] = "echoShort" ;
342 def genOpList(self,oplist):
343 self.st.out(self.template_comment_operations_start)
346 sname = self.namespace(n, "_")
347 opname = n.identifier()
348 self.st.out(self.template_operations_declare, sname=sname, opname=opname)
350 self.st.out(self.template_comment_operations_end)
357 # out: C code for IDL User Exceptions that contain members
361 # static const char user_exception_tux_bad_value[] = "IDL:tux/bad_value:1.0" ;
364 def genExList(self,oplist):
366 self.st.out(self.template_comment_user_exceptions_string_declare_start)
368 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
372 print "XXX Exception " , ex.repoId()
373 print "XXX Exception Identifier" , ex.identifier()
374 print "XXX Exception Scoped Name" , ex.scopedName()
376 if (ex.members()): # only if has members
377 sname = self.namespace(ex, "_")
379 self.st.out(self.template_user_exceptions_declare, sname=sname, exname=ex.repoId())
381 self.st.out(self.template_comment_user_exceptions_string_declare_end)
388 # out: C code for IDL attribute decalarations.
390 # NOTE: Mapping of attributes to operation(function) names is tricky.
392 # The actual accessor function names are language-mapping specific. The attribute name
393 # is subject to OMG IDL's name scoping rules; the accessor function names are
394 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
398 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
399 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
403 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
404 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
406 # TODO: Implement some language dependant templates to handle naming conventions
407 # language <=> attribute. for C, C++. Java etc
409 # OR, just add a runtime GUI option to select language binding for attributes -- FS
413 # ie: def genAtlist(self,atlist,language)
418 def genAtList(self,atlist):
419 self.st.out(self.template_comment_attributes_start)
422 for i in n.declarators(): #
423 sname = self.namespace(i, "_")
424 atname = i.identifier()
425 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
427 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
429 self.st.out(self.template_comment_attributes_end)
433 # genExceptionDelegator
437 # out: C code for User exception delegator
443 def genExceptionDelegator(self,oplist):
445 self.st.out(self.template_main_exception_delegator_start)
448 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
452 print "XXX Exception " , ex.repoId()
453 print "XXX Exception Identifier" , ex.identifier()
454 print "XXX Exception Scoped Name" , ex.scopedName()
456 if (ex.members()): # only if has members
457 sname = self.namespace(ex, "_")
459 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
462 self.st.out(self.template_main_exception_delegator_end)
466 # genAttribueHelpers()
468 # Generate private helper functions to decode Attributes.
472 # For readonly attribute - generate get_xxx()
473 # If NOT readonly attribute - also generate set_xxx()
476 def genAttributeHelpers(self,atlist):
478 print "XXX genAttributeHelpers: atlist = ", atlist
480 self.st.out(self.template_attribute_helpers_start)
482 for attrib in atlist:
483 for decl in attrib.declarators():
484 self.genAtHelper(attrib,decl,"get") # get accessor
485 if not attrib.readonly():
486 self.genAtHelper(attrib,decl,"set") # set accessor
488 self.st.out(self.template_attribute_helpers_end)
493 # Generate private helper functions to decode an attribute
495 # in: at - attribute node
496 # in: decl - declarator belonging to this attribute
497 # in: order - to generate a "get" or "set" helper
499 def genAtHelper(self,attrib,decl,order):
501 print "XXX genAtHelper"
503 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
504 self.curr_sname = sname # update current opnode/exnode scoped name
506 if not self.fn_hash_built:
507 self.fn_hash[sname] = [] # init empty list as val for this sname key
508 # but only if the fn_hash is not already built
510 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
513 self.st.out(self.template_helper_function_vars_start)
514 self.dumpCvars(sname)
515 self.st.out(self.template_helper_function_vars_end )
517 self.st.out(self.template_exception_helper_function_get_endianess)
520 # TODO - attributes are simple types, so remove array handling
523 if decl.sizes(): # an array
524 indices = self.get_indices_from_sizes(decl.sizes())
525 string_indices = '%i ' % indices # convert int to string
526 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
527 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
528 self.addvar(self.c_i + decl.identifier() + ";")
532 self.getCDR3(attrib.attrType(), decl.identifier() )
535 self.st.out(self.template_get_CDR_array_end)
540 self.getCDR3(attrib.attrType(), decl.identifier() )
543 self.st.out(self.template_attribute_helper_function_end)
548 # genExceptionHelpers()
550 # Generate private helper functions to decode Exceptions used
557 def genExceptionHelpers(self,oplist):
558 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
560 print "XXX genExceptionHelpers: exlist = ", exlist
562 self.st.out(self.template_exception_helpers_start)
564 if (ex.members()): # only if has members
565 #print "XXX Exception = " + ex.identifier()
568 self.st.out(self.template_exception_helpers_end)
574 # Generate private helper functions to decode User Exceptions
576 # in: exnode ( an exception node)
579 def genExHelper(self,ex):
581 print "XXX genExHelper"
583 sname = self.namespace(ex, "_")
584 self.curr_sname = sname # update current opnode/exnode scoped name
585 if not self.fn_hash_built:
586 self.fn_hash[sname] = [] # init empty list as val for this sname key
587 # but only if the fn_hash is not already built
589 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
592 self.st.out(self.template_helper_function_vars_start)
593 self.dumpCvars(sname)
594 self.st.out(self.template_helper_function_vars_end )
596 self.st.out(self.template_exception_helper_function_get_endianess)
599 for m in ex.members():
600 #print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
603 for decl in m.declarators():
604 #print "XXX genExhelper, d = ", decl
605 if decl.sizes(): # an array
606 indices = self.get_indices_from_sizes(decl.sizes())
607 string_indices = '%i ' % indices # convert int to string
608 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
609 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
610 self.addvar(self.c_i + decl.identifier() + ";")
613 self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
616 self.st.out(self.template_get_CDR_array_end)
620 self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
623 self.st.out(self.template_exception_helper_function_end)
629 # Generate private helper functions for each IDL operation.
635 def genHelpers(self,oplist):
637 self.genOperation(op)
643 # Generate private helper functions for a specificIDL operation.
648 def genOperation(self,opnode):
650 print "XXX genOperation called"
652 sname = self.namespace(opnode, "_")
653 if not self.fn_hash_built:
654 self.fn_hash[sname] = [] # init empty list as val for this sname key
655 # but only if the fn_hash is not already built
657 self.curr_sname = sname # update current opnode's scoped name
658 opname = opnode.identifier()
660 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
662 self.st.out(self.template_helper_function_start, sname=sname)
665 self.st.out(self.template_helper_function_vars_start)
666 self.dumpCvars(sname)
667 self.st.out(self.template_helper_function_vars_end )
670 self.st.out(self.template_helper_switch_msgtype_start)
672 self.st.out(self.template_helper_switch_msgtype_request_start)
674 self.genOperationRequest(opnode)
675 self.st.out(self.template_helper_switch_msgtype_request_end)
678 self.st.out(self.template_helper_switch_msgtype_reply_start)
681 self.st.out(self.template_helper_switch_rep_status_start)
684 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
686 self.genOperationReply(opnode)
687 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
690 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
692 self.genOpExceptions(opnode)
693 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
696 self.st.out(self.template_helper_switch_msgtype_reply_default_start)
697 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
699 self.st.out(self.template_helper_switch_rep_status_end)
703 self.st.out(self.template_helper_switch_msgtype_default_start)
704 self.st.out(self.template_helper_switch_msgtype_default_end)
706 self.st.out(self.template_helper_switch_msgtype_end)
710 self.st.out(self.template_helper_function_end, sname=sname)
716 # Decode function parameters for a GIOP request message
718 # TODO check for enum
721 def genOperationRequest(self,opnode):
722 for p in opnode.parameters():
725 print "XXX parameter = " ,p
726 print "XXX parameter type = " ,p.paramType()
727 print "XXX parameter type kind = " ,p.paramType().kind()
729 self.getCDR3(p.paramType(),p.identifier())
733 # Decode function parameters for a GIOP reply message
735 # TODO check for enum
738 def genOperationReply(self,opnode):
740 rt = opnode.returnType() # get return type
742 print "XXX opnode = " , opnode
743 print "XXX return type = " , rt
744 print "XXX return type.unalias = " , rt.unalias()
745 print "XXX return type.kind() = " , rt.kind();
748 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
749 #self.getCDR3(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
750 #self.get_CDR_alias(rt, "Operation_Return_Value" )
751 self.get_CDR_alias(rt, rt.name() )
754 self.getCDR3(rt, "Operation_Return_Value") # return value is NOT an alias
756 for p in opnode.parameters():
757 if p.is_out(): # out or inout
758 self.getCDR3(p.paramType(),p.identifier())
760 #self.st.dec_indent()
762 def genOpExceptions(self,opnode):
763 for ex in opnode.raises():
766 for m in ex.members():
768 #print m.memberType(), m.memberType().kind()
770 # Delegator for Operations
773 def genOpDelegator(self,oplist):
775 opname = op.identifier()
776 sname = self.namespace(op, "_")
777 self.st.out(self.template_op_delegate_code, sname=sname)
780 # Delegator for Attributes
783 def genAtDelegator(self,atlist):
785 for i in a.declarators():
786 atname = i.identifier()
787 sname = self.namespace(i, "_")
788 self.st.out(self.template_at_delegate_code_get, sname=sname)
790 self.st.out(self.template_at_delegate_code_set, sname=sname)
794 # Add a variable declaration to the hash of list
797 def addvar(self, var):
798 if not ( var in self.fn_hash[self.curr_sname] ):
799 self.fn_hash[self.curr_sname].append(var)
802 # Print the variable declaration from the hash of list
807 for fn in self.fn_hash.keys():
809 for v in self.fn_hash[fn]:
812 # Print the "C" variable declaration from the hash of list
813 # for a given scoped operation name (eg: tux_penguin_eat)
817 def dumpCvars(self, sname):
818 for v in self.fn_hash[sname]:
823 # Given an enum node, and a enumerator node, return
824 # the enumerator's numerical value.
826 # eg: enum Color {red,green,blue} should return
830 def valFromEnum(self,enumNode, enumeratorNode):
832 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
833 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
835 if isinstance(enumeratorNode,idlast.Enumerator):
836 value = enumNode.enumerators().index(enumeratorNode)
865 ## tk_longdouble = 25
872 ## tk_abstract_interface = 32
878 # This is the main "iterator" function. It takes a node, and tries to output
879 # a get_CDR_XXX accessor method(s). It can call itself multiple times
880 # if I find nested structures etc.
883 def getCDR3(self,type,name="fred"):
885 pt = type.unalias().kind() # param CDR type
886 pn = name # param name
889 print "XXX getCDR3: kind = " , pt
891 if pt == idltype.tk_ulong:
892 self.get_CDR_ulong(pn)
893 elif pt == idltype.tk_void:
894 self.get_CDR_void(pn)
895 elif pt == idltype.tk_short:
896 self.get_CDR_short(pn)
897 elif pt == idltype.tk_long:
898 self.get_CDR_long(pn)
899 elif pt == idltype.tk_ushort:
900 self.get_CDR_ushort(pn)
901 elif pt == idltype.tk_float:
902 self.get_CDR_float(pn)
903 elif pt == idltype.tk_double:
904 self.get_CDR_double(pn)
905 elif pt == idltype.tk_fixed:
906 self.get_CDR_fixed(type.unalias(),pn)
907 elif pt == idltype.tk_boolean:
908 self.get_CDR_boolean(pn)
909 elif pt == idltype.tk_char:
910 self.get_CDR_char(pn)
911 elif pt == idltype.tk_octet:
912 self.get_CDR_octet(pn)
913 elif pt == idltype.tk_any:
915 elif pt == idltype.tk_string:
916 self.get_CDR_string(pn)
917 elif pt == idltype.tk_wstring:
918 self.get_CDR_wstring(pn)
919 elif pt == idltype.tk_wchar:
920 self.get_CDR_wchar(pn)
921 elif pt == idltype.tk_enum:
923 self.get_CDR_enum(pn)
924 elif pt == idltype.tk_struct:
925 self.get_CDR_struct(type,pn)
926 elif pt == idltype.tk_TypeCode: # will I ever get here ?
927 self.get_CDR_TypeCode(type,pn)
928 elif pt == idltype.tk_sequence:
929 self.get_CDR_sequence(type,pn)
930 elif pt == idltype.tk_objref:
931 self.get_CDR_objref(type,pn)
932 elif pt == idltype.tk_array:
933 self.get_CDR_array(type,pn)
934 elif pt == idltype.tk_union:
935 self.get_CDR_union(type,pn)
936 elif pt == idltype.tk_alias:
938 print "XXXXX Alias type XXXXX " , type
939 self.get_CDR_alias(type,pn)
941 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
945 # get_CDR_XXX methods are here ..
950 def get_CDR_ulong(self,pn):
951 self.st.out(self.template_get_CDR_ulong, varname=pn)
952 self.addvar(self.c_u_octet4)
954 def get_CDR_short(self,pn):
955 self.st.out(self.template_get_CDR_short, varname=pn)
956 self.addvar(self.c_s_octet2)
958 def get_CDR_void(self,pn):
959 self.st.out(self.template_get_CDR_void, varname=pn)
961 def get_CDR_long(self,pn):
962 self.st.out(self.template_get_CDR_long, varname=pn)
963 self.addvar(self.c_s_octet4)
965 def get_CDR_ushort(self,pn):
966 self.st.out(self.template_get_CDR_ushort, varname=pn)
967 self.addvar(self.c_u_octet2)
969 def get_CDR_float(self,pn):
970 self.st.out(self.template_get_CDR_float, varname=pn)
971 self.addvar(self.c_float)
973 def get_CDR_double(self,pn):
974 self.st.out(self.template_get_CDR_double, varname=pn)
975 self.addvar(self.c_double)
977 def get_CDR_boolean(self,pn):
978 self.st.out(self.template_get_CDR_boolean, varname=pn)
979 self.addvar(self.c_u_octet1)
981 def get_CDR_fixed(self,type,pn):
983 print "XXXX calling get_CDR_fixed, type = ", type
984 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
985 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
987 string_digits = '%i ' % type.digits() # convert int to string
988 string_scale = '%i ' % type.scale() # convert int to string
989 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
991 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
992 self.addvar(self.c_seq)
995 def get_CDR_char(self,pn):
996 self.st.out(self.template_get_CDR_char, varname=pn)
997 self.addvar(self.c_u_octet1)
999 def get_CDR_octet(self,pn):
1000 self.st.out(self.template_get_CDR_octet, varname=pn)
1001 self.addvar(self.c_u_octet1)
1003 def get_CDR_any(self,pn):
1004 self.st.out(self.template_get_CDR_any, varname=pn)
1006 def get_CDR_enum(self,pn):
1007 self.st.out(self.template_get_CDR_enum, varname=pn)
1008 self.addvar(self.c_u_octet4)
1010 def get_CDR_string(self,pn):
1011 self.st.out(self.template_get_CDR_string, varname=pn)
1012 self.addvar(self.c_u_octet4)
1013 self.addvar(self.c_seq)
1015 def get_CDR_wstring(self,pn):
1016 self.st.out(self.template_get_CDR_wstring, varname=pn)
1017 self.addvar(self.c_u_octet4)
1018 self.addvar(self.c_seq)
1020 def get_CDR_wchar(self,pn):
1021 self.st.out(self.template_get_CDR_wchar, varname=pn)
1022 self.addvar(self.c_s_octet1)
1023 self.addvar(self.c_seq)
1025 def get_CDR_TypeCode(self,pn):
1026 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1027 self.addvar(self.c_u_octet4)
1029 def get_CDR_objref(self,type,pn):
1030 self.st.out(self.template_get_CDR_object)
1032 def get_CDR_sequence_len(self,pn):
1033 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1034 self.addvar(self.c_u_octet4)
1036 def get_CDR_union(self,type,pn):
1038 print "XXX Union type =" , type, " pn = ",pn
1039 print "XXX Union type.decl()" , type.decl()
1040 print "XXX Union Scoped Name" , type.scopedName()
1042 # If I am a typedef union {..}; node then find the union node
1044 if isinstance(type.decl(), idlast.Declarator):
1045 ntype = type.decl().alias().aliasType().decl()
1047 ntype = type.decl() # I am a union node
1050 print "XXX Union ntype =" , ntype
1052 st = ntype.switchType()
1059 print "XXX Union ntype =" , ntype
1060 print "XXX Union ntype.switchType =" , st
1061 #print "XXX Union ntype.switchType().decl() = " , std
1062 #print "XXX Union std.repoId() = ", std.repoId()
1065 self.st.out(self.template_comment_union_code_start, uname=ntype.repoId() )
1067 self.getCDR3(st,pn);
1069 # Depending on what kind of discriminant I come accross (enum,integer,char,
1070 # boolean), make sure I cast the return value of the get_XXX accessor
1071 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1072 # return an integer, or an Enumerator object that is then converted to its
1073 # integer equivalent.
1076 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1079 if (st.kind() == idltype.tk_enum):
1081 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1082 self.st.out(self.template_union_code_save_discriminant_enum, discname=pn )
1083 self.addvar(self.c_s_disc + pn + ";")
1085 elif (st.kind() == idltype.tk_long):
1086 self.st.out(self.template_union_code_save_discriminant_integer, discname=pn )
1087 self.addvar(self.c_s_disc + pn + ";")
1089 elif (st.kind() == idltype.tk_boolean):
1090 self.st.out(self.template_union_code_save_discriminant_boolean, discname=pn )
1091 self.addvar(self.c_s_disc + pn + ";")
1093 elif (st.kind() == idltype.tk_char):
1094 self.st.out(self.template_union_code_save_discriminant_char, discname=pn )
1095 self.addvar(self.c_s_disc + pn + ";")
1098 print "XXX Unknown st.kind() = ", st.kind()
1101 # Loop over all cases in this union
1104 for uc in ntype.cases(): # for all UnionCase objects in this union
1105 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1107 # get integer value, even if discriminant is
1108 # an Enumerator node
1110 if isinstance(cl.value(),idlast.Enumerator):
1112 print "XXX clv.identifier()", cl.value().identifier()
1113 print "XXX clv.repoId()", cl.value().repoId()
1114 print "XXX clv.scopedName()", cl.value().scopedName()
1116 # find index of enumerator in enum declaration
1117 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1119 clv = self.valFromEnum(std,cl.value())
1124 #print "XXX clv = ",clv
1127 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1128 # eg: if (disc == 'b')..
1130 if (st.kind() == idltype.tk_char):
1131 string_clv = "'" + clv + "'"
1133 string_clv = '%i ' % clv
1136 # If default case, then skp comparison with discriminator
1139 if not cl.default():
1140 self.st.out(self.template_comment_union_code_label_compare_start, discname=pn,labelval=string_clv )
1141 self.st.inc_indent()
1143 self.st.out(self.template_comment_union_code_label_default_start )
1146 self.getCDR3(uc.caseType(),uc.declarator().identifier())
1148 if not cl.default():
1149 self.st.dec_indent()
1150 self.st.out(self.template_comment_union_code_label_compare_end )
1152 self.st.out(self.template_comment_union_code_label_default_end )
1156 # Currently, get_CDR_alias is geared to finding typdef
1159 def get_CDR_alias(self,type,pn):
1161 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1162 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1163 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1165 decl = type.decl() # get declarator object
1167 if (decl.sizes()): # a typedef array
1168 indices = self.get_indices_from_sizes(decl.sizes())
1169 string_indices = '%i ' % indices # convert int to string
1170 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1172 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1173 self.addvar(self.c_i + pn + ";")
1174 self.st.inc_indent()
1175 self.getCDR3(type.decl().alias().aliasType(), pn )
1177 self.st.dec_indent()
1178 self.st.out(self.template_get_CDR_array_end)
1181 else: # a simple typdef
1183 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1184 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1186 self.getCDR3(type, decl.identifier() )
1193 def get_CDR_struct(self,type,pn):
1194 self.st.out(self.template_structure_start, name=type.name() )
1196 # If I am a typedef struct {..}; node then find the struct node
1198 if isinstance(type.decl(), idlast.Declarator):
1199 ntype = type.decl().alias().aliasType().decl()
1201 ntype = type.decl() # I am a struct node
1203 for m in ntype.members():
1204 for decl in m.declarators():
1205 if decl.sizes(): # an array
1206 indices = self.get_indices_from_sizes(decl.sizes())
1207 string_indices = '%i ' % indices # convert int to string
1208 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1209 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1210 self.addvar(self.c_i + decl.identifier() + ";")
1212 self.st.inc_indent()
1213 self.getCDR3(m.memberType(), type.name() + "_" + decl.identifier() )
1214 self.st.dec_indent()
1215 self.st.out(self.template_get_CDR_array_end)
1219 self.getCDR3(m.memberType(), type.name() + "_" + decl.identifier() )
1221 self.st.out(self.template_structure_end, name=type.name())
1226 # Generate code to access a sequence of a type
1229 def get_CDR_sequence(self,type, pn):
1230 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1231 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1232 self.addvar(self.c_i_lim + pn + ";" )
1233 self.addvar(self.c_i + pn + ";")
1235 self.st.inc_indent()
1236 self.getCDR3(type.unalias().seqType(), pn ) # and start all over with the type
1237 self.st.dec_indent()
1239 self.st.out(self.template_get_CDR_sequence_loop_end)
1244 # Generate code to access arrays,
1246 # This is handled elsewhere. Arrays are either typedefs or in
1249 # TODO - Remove this
1252 def get_CDR_array(self,type, decl):
1254 print "XXX get_CDR_array called "
1255 print "XXX array size = " ,decl.sizes()
1263 # out - scoped operation name, using sep character instead of "::"
1265 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1269 def namespace(self,node,sep):
1270 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1271 #print "XXX namespace: sname = " + sname
1276 # generate code for plugin initialisation
1279 def gen_plugin_init(self):
1280 self.st.out(self.template_plugin_init, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1283 # generate register_giop_user_module code, and register only
1284 # unique interfaces that contain operations. Also output
1285 # a heuristic register in case we want to use that.
1287 # TODO - make this a command line option
1295 def gen_proto_reg_handoff(self, oplist):
1297 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1298 self.st.inc_indent()
1300 for iname in self.get_intlist(oplist):
1301 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1303 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1304 self.st.dec_indent()
1306 self.st.out(self.template_proto_reg_handoff_end)
1311 # generate proto_register_<protoname> code,
1315 def gen_proto_register(self):
1316 self.st.out(self.template_proto_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1322 # out - a list of unique interface names. This will be used in
1323 # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1324 # name must be removed from the scope. And we also only want unique interfaces.
1327 def get_intlist(self,oplist):
1328 int_hash = {} # holds a hash of unique interfaces
1330 sc = op.scopedName() # eg: penguin,tux,bite
1331 sc1 = sc[:-1] # drop last entry
1332 sn = idlutil.slashName(sc1) # penguin/tux
1333 if not int_hash.has_key(sn):
1334 int_hash[sn] = 0; # dummy val, but at least key is unique
1336 return int_hash.keys()
1343 # out - a list of exception nodes (unique). This will be used in
1344 # to generate dissect_exception_XXX functions.
1349 def get_exceptionList(self,oplist):
1350 ex_hash = {} # holds a hash of unique exceptions.
1352 for ex in op.raises():
1353 if not ex_hash.has_key(ex):
1354 ex_hash[ex] = 0; # dummy val, but at least key is unique
1356 print "XXX Exception = " + ex.identifier()
1358 return ex_hash.keys()
1363 # Simple function to take a list of array sizes and find the
1364 # total number of elements
1367 # eg: temp[4][3] = 12 elements
1370 def get_indices_from_sizes(self,sizelist):
1378 # Determine how many octets contain requested number
1379 # of digits for an "fixed" IDL type "on the wire"
1382 def dig_to_len(self,dignum):
1383 return (dignum/2) + 1
1388 # Output some TODO comment
1392 def genTODO(self,message):
1393 self.st.out(self.template_debug_TODO, message=message)
1396 # Output some WARNING comment
1400 def genWARNING(self,message):
1401 self.st.out(self.template_debug_WARNING, message=message)
1404 # Templates for C code
1409 template_comment_operations_start = """\
1411 * IDL Operations Start
1417 template_operations_declare = """static const char @sname@_op[] = \"@opname@\" ;"""
1420 template_comment_operations_end = """
1422 * IDL Operations End
1427 template_helper_function_comment = """\
1435 template_helper_function_vars_start = """
1436 /* Operation specific Variable declarations Begin */
1439 template_helper_function_vars_end = """
1440 /* Operation specific Variable declarations End */
1445 template_helper_function_start = """\
1446 static void decode_@sname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
1448 gboolean stream_is_big_endian; /* big endianess */
1451 template_helper_function_end = """\
1456 # proto_reg_handoff() templates
1460 template_proto_reg_handoff_start = """
1461 /* register me as handler for these interfaces */
1463 void proto_register_handoff_giop_@dissector_name@(void) {
1467 template_proto_reg_handoff_body = """
1470 /* Register for Explicit Dissection */
1472 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
1478 template_proto_reg_handoff_heuristic = """
1480 /* Register for Heuristic Dissection */
1482 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
1486 template_proto_reg_handoff_end = """
1492 # Initialize the protocol
1495 template_protocol = """
1496 /* Initialise the protocol and subtree pointers */
1498 static int proto_@dissector_name@ = -1;
1500 static gint ett_@dissector_name@ = -1;
1507 # Initialize the boundary Alignment
1510 template_init_boundary = """
1511 /* Initialise the initial Alignment */
1513 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */
1522 # Initialize the Registered fields
1525 template_registered_fields = """
1527 /* Initialise the Registered fields */
1529 /* TODO - Use registered fields */
1534 # plugin_init and plugin_reg_handoff templates
1537 template_plugin_init = """
1539 #ifndef __ETHEREAL_STATIC__
1541 G_MODULE_EXPORT void
1542 plugin_reg_handoff(void){
1543 proto_register_handoff_giop_@dissector_name@();
1546 G_MODULE_EXPORT void
1547 plugin_init(plugin_address_table_t *pat){
1548 /* initialise the table of pointers needed in Win32 DLLs */
1549 plugin_address_table_init(pat);
1550 if (proto_@dissector_name@ == -1) {
1551 proto_register_giop_@dissector_name@();
1560 # proto_register_<dissector name>(void) templates
1564 template_proto_register = """
1566 /* Register the protocol with Ethereal */
1568 void proto_register_giop_@dissector_name@(void) {
1570 /* setup list of header fields */
1573 static hf_register_info hf[] = {
1580 /* setup protocol subtree array */
1582 static gint *ett[] = {
1583 &ett_@dissector_name@,
1586 /* Register the protocol name and description */
1588 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
1591 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
1593 proto_register_subtree_array(ett,array_length(ett));
1601 # template for delegation code
1604 template_op_delegate_code = """\
1605 if (!strcmp(operation, @sname@_op )) {
1606 decode_@sname@(tvb, pinfo, tree, offset, header, operation);
1612 # Templates for the helper functions
1618 template_helper_switch_msgtype_start = """\
1620 stream_is_big_endian = is_big_endian(header);
1622 switch(header->message_type) {
1625 template_helper_switch_msgtype_default_start = """\
1628 /* Unknown GIOP Exception */
1630 g_warning("Unknown GIOP Message");
1633 template_helper_switch_msgtype_default_end = """\
1639 template_helper_switch_msgtype_end = """\
1641 } /* switch(header->message_type) */
1644 template_helper_switch_msgtype_request_start = """\
1648 template_helper_switch_msgtype_request_end = """\
1652 template_helper_switch_msgtype_reply_start = """\
1656 template_helper_switch_msgtype_reply_no_exception_start = """\
1660 template_helper_switch_msgtype_reply_no_exception_end = """\
1665 template_helper_switch_msgtype_reply_user_exception_start = """\
1666 case USER_EXCEPTION:
1669 template_helper_switch_msgtype_reply_user_exception_end = """\
1673 template_helper_switch_msgtype_reply_default_start = """\
1676 /* Unknown Exception */
1678 g_warning("Unknown Exception ");
1683 template_helper_switch_msgtype_reply_default_end = """\
1688 template_helper_switch_msgtype_reply_end = """\
1692 template_helper_switch_msgtype_default_start = """\
1695 /* Unknown GIOP Message */
1697 g_warning("Unknown GIOP Message");
1701 template_helper_switch_msgtype_default_end = """\
1707 template_helper_switch_rep_status_start = """\
1708 switch(header->rep_status) {
1711 template_helper_switch_rep_status_default_start = """\
1714 /* Unknown Reply Status */
1716 g_warning("Unknown Reply Status");
1720 template_helper_switch_rep_status_default_end = """\
1724 template_helper_switch_rep_status_end = """\
1726 } /* switch(header->message_type) */
1736 # Templates for get_CDR_xxx accessors
1739 template_get_CDR_ulong = """\
1740 u_octet4 = get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary);
1742 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %u",u_octet4);
1746 template_get_CDR_short = """\
1747 s_octet2 = get_CDR_short(tvb,offset,stream_is_big_endian, boundary);
1749 proto_tree_add_text(tree,tvb,*offset-2,2,"@varname@ = %i",s_octet2);
1753 template_get_CDR_void = """\
1755 /* Function returns void */
1759 template_get_CDR_long = """\
1760 s_octet4 = get_CDR_long(tvb,offset,stream_is_big_endian, boundary);
1762 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %i",s_octet4);
1766 template_get_CDR_ushort = """\
1767 u_octet2 = get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary);
1769 proto_tree_add_text(tree,tvb,*offset-2,2,"@varname@ = %u",u_octet2);
1772 template_get_CDR_float = """\
1773 my_float = get_CDR_float(tvb,offset,stream_is_big_endian, boundary);
1775 proto_tree_add_text(tree,tvb,*offset-4,4,"@varname@ = %.6e",my_float);
1779 template_get_CDR_double = """\
1780 my_double = get_CDR_double(tvb,offset,stream_is_big_endian, boundary);
1782 proto_tree_add_text(tree,tvb,*offset-8,8,"@varname@ = %.15e",my_double);
1786 template_get_CDR_boolean = """\
1787 u_octet1 = get_CDR_boolean(tvb,offset);
1789 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1793 template_get_CDR_char = """\
1794 u_octet1 = get_CDR_char(tvb,offset);
1796 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1800 template_get_CDR_octet = """\
1801 u_octet1 = get_CDR_octet(tvb,offset);
1803 proto_tree_add_text(tree,tvb,*offset-1,1,"@varname@ = %u",u_octet1);
1809 template_get_CDR_any = """\
1810 get_CDR_any(tvb,tree,offset,stream_is_big_endian, boundary, header);
1814 template_get_CDR_fixed = """\
1815 get_CDR_fixed(tvb, &seq, offset, @digits@, @scale@);
1817 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
1820 g_free(seq); /* free buffer */
1826 template_get_CDR_enum = """\
1828 /* TODO - translate Enum val into symbolic value */
1830 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
1832 proto_tree_add_text(tree,tvb,*offset-4,4,"Enum value = %u ",u_octet4);
1836 template_get_CDR_string = """\
1837 u_octet4 = get_CDR_string(tvb, &seq, offset, stream_is_big_endian, boundary);
1839 proto_tree_add_text(tree,tvb,*offset-4-u_octet4,4,"length = %u",u_octet4);
1841 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ = %s",seq);
1845 g_free(seq); /* free buffer */
1850 template_get_CDR_wstring = """\
1851 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
1853 proto_tree_add_text(tree,tvb,*offset-4-u_octet4,4,"length = %u",u_octet4);
1855 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ = %s",seq);
1859 g_free(seq); /* free buffer */
1864 template_get_CDR_wchar = """\
1865 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
1868 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
1871 s_octet1 = -s_octet1;
1874 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
1878 g_free(seq); /* free buffer */
1885 template_get_CDR_TypeCode = """\
1886 u_octet4 = get_CDR_typeCode(tvb, tree, offset, stream_is_big_endian, boundary, header);
1890 template_get_CDR_object = """\
1891 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
1896 template_get_CDR_sequence_length = """\
1897 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
1899 proto_tree_add_text(tree,tvb,*offset-4, 4 ,"Seq length of @seqname@ = %u",u_octet4_loop_@seqname@);
1903 template_get_CDR_sequence_loop_start = """\
1904 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
1906 template_get_CDR_sequence_loop_end = """\
1912 template_get_CDR_array_start = """\
1913 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
1915 template_get_CDR_array_end = """\
1919 template_get_CDR_array_comment = """\
1920 /* Array: @aname@[ @asize@] */
1926 template_structure_start = """\
1927 /* Begin struct \"@name@\" */
1931 template_structure_end = """\
1932 /* End struct \"@name@\" */
1939 # Program Header Template
1942 template_Header = """\
1943 /* packet-@dissector_name@.c
1944 * Routines for IDL dissection
1946 * Autogenerated from idl2eth
1947 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
1952 template_ethereal_copyright = """\
1954 * Ethereal - Network traffic analyzer
1956 * Copyright 1999 Gerald Combs
1970 * This program is free software; you can redistribute it and/or
1971 * modify it under the terms of the GNU General Public License
1972 * as published by the Free Software Foundation; either version 2
1973 * of the License, or (at your option) any later version.
1975 * This program is distributed in the hope that it will be useful,
1976 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1977 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1978 * GNU General Public License for more details.
1980 * You should have received a copy of the GNU General Public License
1981 * along with this program; if not, write to the Free Software
1982 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1991 template_Includes = """\
1993 #ifdef HAVE_CONFIG_H
1994 # include "config.h"
1997 #include "plugins/plugin_api.h"
2001 #include <gmodule.h>
2003 #ifdef HAVE_SYS_TYPES_H
2004 # include <sys/types.h>
2007 #ifdef HAVE_NETINET_IN_H
2008 # include <netinet/in.h>
2011 #ifdef NEED_SNPRINTF_H
2012 # ifdef HAVE_STDARG_H
2013 # include <stdarg.h>
2015 # include <varargs.h>
2017 # include "snprintf.h"
2024 #include "packet-giop.h"
2026 #ifndef __ETHEREAL_STATIC__
2027 G_MODULE_EXPORT const gchar version[] = "0.0.1";
2034 # Main dissector entry templates
2037 template_main_dissector_start = """\
2038 static gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname) {
2040 proto_item *ti = NULL;
2041 proto_tree *tree = NULL; /* init later, inside if(tree) */
2043 gboolean be; /* big endianess */
2044 guint32 offset_saved = (*offset); /* save in case we must back out */
2046 pinfo->current_proto = \"@disprot@\";
2048 if (check_col(pinfo->fd, COL_PROTOCOL))
2049 col_add_str(pinfo->fd, COL_PROTOCOL, \"@disprot@\");
2052 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, tvb_length(tvb) - *offset, FALSE);
2053 tree = proto_item_add_subtree(ti, ett_@dissname@);
2057 be = is_big_endian(header); /* get endianess - TODO use passed in stream_is_big_endian instead ? */
2059 /* If we have a USER Exception, then decode it and return */
2061 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2063 return decode_user_exception(tvb, pinfo, tree, offset, header, operation);
2073 template_main_dissector_switch_msgtype_start = """\
2074 switch(header->message_type) {
2077 template_main_dissector_switch_msgtype_start_request_reply = """\
2083 template_main_dissector_switch_msgtype_end_request_reply = """\
2089 template_main_dissector_switch_msgtype_end = """\
2093 * We failed to match ANY operations, so perhaps this is not for us !
2096 (*offset) = offset_saved; /* be nice */
2106 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2110 case CloseConnection:
2113 return FALSE; /* not handled yet */
2116 return FALSE; /* not handled yet */
2123 template_main_dissector_switch_msgtype_end = """\
2131 template_main_dissector_end = """\
2135 } /* End of main dissector */
2145 #-------------------------------------------------------------#
2146 # Exception handling templates #
2147 #-------------------------------------------------------------#
2155 template_exception_helpers_start = """\
2156 /* Begin Exception Helper Functions */
2160 template_exception_helpers_end = """\
2162 /* End Exception Helper Functions */
2169 # Templates for declaration of string constants for user exceptions.
2172 template_comment_user_exceptions_string_declare_start = """\
2173 /* Begin Exception (containing members) String Declare */
2177 template_user_exceptions_declare = """static const char user_exception_@sname@[] = \"@exname@\" ; """
2180 template_comment_user_exceptions_string_declare_end = """\
2182 /* End Exception (containing members) String Declare */
2190 # template for Main delegator for exception handling
2193 template_main_exception_delegator_start = """\
2196 * Main delegator for exception handling
2200 static gboolean decode_user_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation ) {
2202 gboolean be; /* big endianess */
2209 # template for exception delegation code body
2211 template_ex_delegate_code = """\
2212 if (!strcmp(header->exception_id, user_exception_@sname@ )) {
2213 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation); /* @exname@ */
2221 # End of Main delegator for exception handling
2224 template_main_exception_delegator_end = """\
2227 return FALSE; /* user exception not found */
2234 # template for exception helper code
2238 template_exception_helper_function_start = """\
2240 /* Exception = @exname@ */
2242 static void decode_ex_@sname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2244 gboolean stream_is_big_endian; /* big endianess */
2250 # Template for the helper function
2251 # to get stream endianess from header
2254 template_exception_helper_function_get_endianess = """\
2256 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2261 template_exception_helper_function_end = """\
2268 #-------------------------------------------------------------#
2269 # Attribute handling templates #
2270 #-------------------------------------------------------------#
2273 template_comment_attributes_start = """\
2275 * IDL Attributes Start
2281 # get/set accessor method names are language mapping dependant.
2284 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2285 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2288 template_comment_attributes_end = """
2290 * IDL Attributes End
2297 # template for Attribute delegation code
2299 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2300 # Note: _set_xxx() should only be called for Request
2304 template_at_delegate_code_get = """\
2305 if (!strcmp(operation, get_@sname@_at ) && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2306 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation);
2311 template_at_delegate_code_set = """\
2312 if (!strcmp(operation, set_@sname@_at ) && (header->message_type == Request) ) {
2313 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation);
2320 template_attribute_helpers_start = """\
2321 /* Begin Attribute Helper Functions */
2325 template_attribute_helpers_end = """\
2327 /* End Attribute Helper Functions */
2332 # template for attribute helper code
2336 template_attribute_helper_function_start = """\
2338 /* Attribute = @atname@ */
2340 static void decode_@sname@_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
2342 gboolean stream_is_big_endian; /* big endianess */
2348 # Template for the helper function
2349 # to get stream endianess from header
2352 template_attribute_helper_function_get_endianess = """\
2354 stream_is_big_endian = is_big_endian(header); /* get stream endianess */
2359 template_attribute_helper_function_end = """\
2364 #-------------------------------------------------------------#
2365 # Debugging templates #
2366 #-------------------------------------------------------------#
2370 # Template for outputting TODO "C" comments
2371 # so user know I need ti improve something.
2374 template_debug_TODO = """\
2376 /* TODO - @message@ */
2380 # Template for outputting WARNING "C" comments
2381 # so user know if I have found a problem.
2384 template_debug_WARNING = """\
2386 /* WARNING - @message@ */
2391 #-------------------------------------------------------------#
2392 # IDL Union templates #
2393 #-------------------------------------------------------------#
2397 template_comment_union_code_start = """\
2399 * IDL Union Start - @uname@
2405 template_comment_union_code_end = """
2407 * IDL union End - @uname@
2412 template_comment_union_code_discriminant = """\
2414 * IDL Union - Discriminant - @uname@
2420 # Cast Unions types to something appropriate
2421 # Enum value cast to guint32, all others cast to gint32
2422 # as omniidl accessor returns integer or Enum.
2425 template_union_code_save_discriminant_enum = """\
2426 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2429 template_union_code_save_discriminant_integer = """\
2430 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2433 template_union_code_save_discriminant_char = """\
2434 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2437 template_union_code_save_discriminant_boolean = """\
2438 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2442 template_comment_union_code_label_compare_start = """\
2443 if (disc_s_@discname@ == @labelval@) {
2446 template_comment_union_code_label_compare_end = """\
2453 template_comment_union_code_label_default_start = """
2454 /* Default Union Case Start */
2458 template_comment_union_code_label_default_end = """\
2459 /* Default Union Case End */