3 # wireshark_gen.py (part of idl2wrs)
5 # Author : Frank Singleton (frank.singleton@ericsson.com)
7 # Copyright (C) 2001 Frank Singleton, Ericsson Inc.
9 # This file is a backend to "omniidl", used to generate "Wireshark"
10 # dissectors from CORBA IDL descriptions. The output language generated
11 # is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
13 # Please see packet-giop.h in Wireshark distro for API description.
14 # Wireshark is available at http://www.wireshark.org/
16 # Omniidl is part of the OmniOrb distribution, and is available at
17 # http://omniorb.sourceforge.net
19 # This program is free software; you can redistribute it and/or modify it
20 # under the terms of the GNU General Public License as published by
21 # the Free Software Foundation; either version 2 of the License, or
22 # (at your option) any later version.
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 # General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
36 # Omniidl Back-end which parses an IDL list of "Operation" nodes
37 # passed from wireshark_be2.py and generates "C" code for compiling
38 # as a plugin for the Wireshark IP Protocol Analyser.
41 # Strategy (sneaky but ...)
43 # problem: I dont know what variables to declare until AFTER the helper functions
44 # have been built, so ...
46 # There are 2 passes through genHelpers, the first one is there just to
47 # make sure the fn_hash data struct is populated properly.
48 # The second pass is the real thing, generating code and declaring
49 # variables (from the 1st pass) properly.
53 """Wireshark IDL compiler back-end."""
55 from omniidl import idlast, idltype, idlutil, output
60 # Output class, generates "C" src code for the sub-dissector
67 # node - a reference to an Operations object.
68 # name - scoped name (Module::Module::Interface:: .. ::Operation
76 # 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved]
77 # 2. add item instead of add_text() [done]
78 # 3. sequence handling [done]
79 # 4. User Exceptions [done]
80 # 5. Fix arrays, and structs containing arrays [done]
82 # 7. Exception can be common to many operations, so handle them outside the
83 # operation helper functions [done]
84 # 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
85 # For example, mutlidimensional arrays.
86 # 9. wchar and wstring handling [giop API needs improving]
87 # 10. Support Fixed [done]
88 # 11. Support attributes (get/set) [started, needs language mapping option, perhaps wireshark GUI option
89 # to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
90 # eg: attribute string apple => _get_apple and _set_apple
92 # 12. Implement IDL "union" code [done]
93 # 13. Implement support for plugins [done]
94 # 14. Dont generate code for empty operations (cf: exceptions without members)
95 # 15. Generate code to display Enums numerically and symbolically [done]
96 # 16. Place structs/unions in subtrees
97 # 17. Recursive struct and union handling [done]
98 # 18. Improve variable naming for display (eg: structs, unions etc) [done]
100 # Also test, Test, TEST
107 # For every operation and attribute do
108 # For return val and all parameters do
109 # find basic IDL type for each parameter
111 # output exception handling code
112 # output attribute handling code
116 class wireshark_gen_C:
120 # Turn DEBUG stuff on/off
126 # Some string constants for our templates
128 c_u_octet8 = "guint64 u_octet8;"
129 c_s_octet8 = "gint64 s_octet8;"
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 = "const 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
176 self.genHelpers(oplist,stlist,unlist) # sneaky .. call it now, to populate the fn_hash
177 # so when I come to that operation later, I have the variables to
180 self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
181 # so when I come to that exception later, I have the variables to
184 self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
185 # so when I come to that exception later, I have the variables to
189 self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
191 self.st = self.st_save
192 self.genHeader() # initial dissector comments
193 self.genEthCopyright() # Wireshark Copyright comments.
194 self.genGPL() # GPL license
198 self.genDeclares(oplist,atlist,enlist,stlist,unlist)
199 if (len(atlist) > 0):
200 self.genAtList(atlist) # string constant declares for Attributes
201 if (len(enlist) > 0):
202 self.genEnList(enlist) # string constant declares for Enums
205 self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
206 self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
207 if (len(atlist) > 0):
208 self.genAttributeHelpers(atlist) # helper function to decode "attributes"
210 self.genHelpers(oplist,stlist,unlist) # operation, struct and union decode helper functions
212 self.genMainEntryStart(oplist)
213 self.genOpDelegator(oplist)
214 self.genAtDelegator(atlist)
215 self.genMainEntryEnd()
217 self.gen_proto_register(oplist, atlist, stlist, unlist)
218 self.gen_proto_reg_handoff(oplist)
219 # All the dissectors are now built-in
220 #self.gen_plugin_register()
222 #self.dumpvars() # debug
230 # Generate Standard Wireshark Header Comments
235 self.st.out(self.template_Header,dissector_name=self.dissname)
237 print "XXX genHeader"
245 # Wireshark Copyright Info
249 def genEthCopyright(self):
251 print "XXX genEthCopyright"
252 self.st.out(self.template_wireshark_copyright)
262 def genModelines(self):
264 print "XXX genModelines"
266 self.st.out(self.template_Modelines)
280 self.st.out(self.template_GPL)
289 def genIncludes(self):
291 print "XXX genIncludes"
293 self.st.out(self.template_Includes)
298 # Generate hf variables for operation filters
300 # in: opnode ( an operation node)
303 def genOpDeclares(self, op):
305 print "XXX genOpDeclares"
306 print "XXX return type = " , op.returnType().kind()
308 sname = self.namespace(op, "_")
311 if (rt.kind() != idltype.tk_void):
312 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
313 #self.get_CDR_alias(rt, rt.name() )
314 if (rt.unalias().kind() == idltype.tk_sequence):
315 self.st.out(self.template_hf, name=sname + "_return_loop")
316 if (self.isSeqNativeType(rt.unalias().seqType())):
317 self.st.out(self.template_hf, name=sname + "_return")
318 elif ((rt.unalias().kind() != idltype.tk_struct) and \
319 (rt.unalias().kind() != idltype.tk_objref) and \
320 (rt.unalias().kind() != idltype.tk_any)):
321 self.st.out(self.template_hf, name=sname + "_return")
323 elif ((rt.kind() != idltype.tk_struct) and \
324 (rt.kind() != idltype.tk_objref) and \
325 (rt.kind() != idltype.tk_union) and \
326 (rt.kind() != idltype.tk_any)):
327 self.st.out(self.template_hf, name=sname + "_return")
329 for p in op.parameters():
330 if (p.paramType().unalias().kind() == idltype.tk_sequence):
331 self.st.out(self.template_hf, name=sname + "_" + p.identifier() + "_loop")
332 if (self.isSeqNativeType(p.paramType().unalias().seqType())):
333 self.st.out(self.template_hf, name=sname + "_" + p.identifier())
334 elif ((p.paramType().unalias().kind() != idltype.tk_any) and \
335 (p.paramType().unalias().kind() != idltype.tk_struct) and \
336 (p.paramType().unalias().kind() != idltype.tk_objref) and \
337 (p.paramType().unalias().kind() != idltype.tk_union)):
338 self.st.out(self.template_hf, name=sname + "_" + p.identifier())
343 # Generate hf variables for attributes
345 # in: at ( an attribute)
348 def genAtDeclares(self, at):
350 print "XXX genAtDeclares"
352 for decl in at.declarators():
353 sname = self.namespace(decl, "_")
355 self.st.out(self.template_hf, name="get" + "_" + sname + "_" + decl.identifier())
356 if not at.readonly():
357 self.st.out(self.template_hf, name="set" + "_" + sname + "_" + decl.identifier())
362 # Generate hf variables for structs
367 def genStDeclares(self, st):
369 print "XXX genStDeclares"
371 sname = self.namespace(st, "_")
373 for m in st.members():
374 if ((self.isSeqNativeType(m.memberType())) or (m.memberType().unalias().kind() == idltype.tk_sequence)):
375 for decl in m.declarators():
376 if (m.memberType().unalias().kind() == idltype.tk_sequence):
377 self.st.out(self.template_hf, name=sname + "_" + decl.identifier() + "_loop")
378 if (self.isSeqNativeType(m.memberType().unalias().seqType())):
379 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
381 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
386 # Generate hf variables for user exception filters
388 # in: exnode ( an exception node)
391 def genExDeclares(self,ex):
393 print "XXX genExDeclares"
395 sname = self.namespace(ex, "_")
397 for m in ex.members():
398 for decl in m.declarators():
399 if (m.memberType().unalias().kind() == idltype.tk_sequence):
400 self.st.out(self.template_hf, name=sname + "_" + decl.identifier() + "_loop")
402 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
407 # Generate hf variables for union filters
412 def genUnionDeclares(self,un):
414 print "XXX genUnionDeclares"
416 sname = self.namespace(un, "_")
417 self.st.out(self.template_hf, name=sname + "_" + un.identifier())
419 for uc in un.cases(): # for all UnionCase objects in this union
420 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
421 if (uc.caseType().unalias().kind() == idltype.tk_sequence):
422 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier() + "_loop")
423 if (self.isSeqNativeType(uc.caseType().unalias().seqType())):
424 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
425 elif (self.isSeqNativeType(uc.caseType())):
426 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
429 # genExpertInfoDeclares()
431 # Generate ei variables for expert info filters
434 def genExpertInfoDeclares(self):
436 print "XXX genExpertInfoDeclares"
438 self.st.out(self.template_proto_register_ei_filters, dissector_name=self.dissname)
443 # generate function prototypes if required
445 # Currently this is used for struct and union helper function declarations.
449 def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
451 print "XXX genDeclares"
453 # prototype for operation filters
454 self.st.out(self.template_hf_operations)
456 #operation specific filters
457 if (len(oplist) > 0):
458 self.st.out(self.template_proto_register_op_filter_comment)
460 self.genOpDeclares(op)
463 if (len(atlist) > 0):
464 self.st.out(self.template_proto_register_at_filter_comment)
466 self.genAtDeclares(at)
469 if (len(stlist) > 0):
470 self.st.out(self.template_proto_register_st_filter_comment)
472 self.genStDeclares(st)
474 # exception List filters
475 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
476 if (len(exlist) > 0):
477 self.st.out(self.template_proto_register_ex_filter_comment)
479 if (ex.members()): # only if has members
480 self.genExDeclares(ex)
483 if (len(unlist) > 0):
484 self.st.out(self.template_proto_register_un_filter_comment)
486 self.genUnionDeclares(un)
489 self.genExpertInfoDeclares()
491 # prototype for start_dissecting()
493 self.st.out(self.template_prototype_start_dissecting)
498 self.st.out(self.template_prototype_struct_start)
501 sname = self.namespace(st, "_")
502 self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
504 self.st.out(self.template_prototype_struct_end)
508 self.st.out(self.template_prototype_union_start)
510 sname = self.namespace(un, "_")
511 self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
512 self.st.out(self.template_prototype_union_end)
520 def genPrototype(self):
521 self.st.out(self.template_prototype, dissector_name=self.dissname)
528 def genProtocol(self):
529 self.st.out(self.template_protocol, dissector_name=self.dissname)
530 self.st.out(self.template_init_boundary)
536 def genMainEntryStart(self,oplist):
537 self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
539 self.st.out(self.template_main_dissector_switch_msgtype_start)
540 self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
548 def genMainEntryEnd(self):
550 self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
552 self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
554 self.st.out(self.template_main_dissector_end)
562 # out: C code for IDL attribute decalarations.
564 # NOTE: Mapping of attributes to operation(function) names is tricky.
566 # The actual accessor function names are language-mapping specific. The attribute name
567 # is subject to OMG IDL's name scoping rules; the accessor function names are
568 # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
572 # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
573 # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
577 # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
578 # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
580 # TODO: Implement some language dependant templates to handle naming conventions
581 # language <=> attribute. for C, C++. Java etc
583 # OR, just add a runtime GUI option to select language binding for attributes -- FS
587 # ie: def genAtlist(self,atlist,language)
592 def genAtList(self,atlist):
593 self.st.out(self.template_comment_attributes_start)
596 for i in n.declarators(): #
597 sname = self.namespace(i, "_")
598 atname = i.identifier()
599 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
601 self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
603 self.st.out(self.template_comment_attributes_end)
611 # out: C code for IDL Enum decalarations using "static const value_string" template
616 def genEnList(self,enlist):
618 self.st.out(self.template_comment_enums_start)
621 sname = self.namespace(enum, "_")
623 self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
624 self.st.out(self.template_value_string_start, valstringname=sname)
625 for enumerator in enum.enumerators():
626 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
629 #atname = n.identifier()
630 self.st.out(self.template_value_string_end, valstringname=sname)
632 self.st.out(self.template_comment_enums_end)
644 # genExceptionDelegator
648 # out: C code for User exception delegator
654 def genExceptionDelegator(self,oplist):
656 self.st.out(self.template_main_exception_delegator_start)
659 exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
663 print "XXX Exception " , ex.repoId()
664 print "XXX Exception Identifier" , ex.identifier()
665 print "XXX Exception Scoped Name" , ex.scopedName()
667 if (ex.members()): # only if has members
668 sname = self.namespace(ex, "_")
670 self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
673 self.st.out(self.template_main_exception_delegator_end)
677 # genAttribueHelpers()
679 # Generate private helper functions to decode Attributes.
683 # For readonly attribute - generate get_xxx()
684 # If NOT readonly attribute - also generate set_xxx()
687 def genAttributeHelpers(self,atlist):
689 print "XXX genAttributeHelpers: atlist = ", atlist
691 self.st.out(self.template_attribute_helpers_start)
693 for attrib in atlist:
694 for decl in attrib.declarators():
695 self.genAtHelper(attrib,decl,"get") # get accessor
696 if not attrib.readonly():
697 self.genAtHelper(attrib,decl,"set") # set accessor
699 self.st.out(self.template_attribute_helpers_end)
704 # Generate private helper functions to decode an attribute
706 # in: at - attribute node
707 # in: decl - declarator belonging to this attribute
708 # in: order - to generate a "get" or "set" helper
710 def genAtHelper(self,attrib,decl,order):
712 print "XXX genAtHelper"
714 sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
715 self.curr_sname = sname # update current opnode/exnode scoped name
717 if not self.fn_hash_built:
718 self.fn_hash[sname] = [] # init empty list as val for this sname key
719 # but only if the fn_hash is not already built
721 self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
724 if (len(self.fn_hash[sname]) > 0):
725 self.st.out(self.template_helper_function_vars_start)
726 self.dumpCvars(sname)
727 self.st.out(self.template_helper_function_vars_end )
729 self.getCDR(attrib.attrType(), sname + "_" + decl.identifier() )
732 self.st.out(self.template_attribute_helper_function_end)
737 # genExceptionHelpers()
739 # Generate private helper functions to decode Exceptions used
746 def genExceptionHelpers(self,oplist):
747 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
749 print "XXX genExceptionHelpers: exlist = ", exlist
751 self.st.out(self.template_exception_helpers_start)
753 if (ex.members()): # only if has members
754 #print "XXX Exception = " + ex.identifier()
757 self.st.out(self.template_exception_helpers_end)
763 # Generate private helper functions to decode User Exceptions
765 # in: exnode ( an exception node)
768 def genExHelper(self,ex):
770 print "XXX genExHelper"
772 sname = self.namespace(ex, "_")
773 self.curr_sname = sname # update current opnode/exnode scoped name
774 if not self.fn_hash_built:
775 self.fn_hash[sname] = [] # init empty list as val for this sname key
776 # but only if the fn_hash is not already built
778 self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
781 if (len(self.fn_hash[sname]) > 0):
782 self.st.out(self.template_helper_function_vars_start)
783 self.dumpCvars(sname)
784 self.st.out(self.template_helper_function_vars_end )
786 for m in ex.members():
788 print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
790 for decl in m.declarators():
792 print "XXX genExhelper, d = ", decl
794 if decl.sizes(): # an array
795 indices = self.get_indices_from_sizes(decl.sizes())
796 string_indices = '%i ' % indices # convert int to string
797 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
798 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
799 self.addvar(self.c_i + decl.identifier() + ";")
802 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
805 self.st.out(self.template_get_CDR_array_end)
809 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
812 self.st.out(self.template_exception_helper_function_end)
818 # Generate private helper functions for each IDL operation.
819 # Generate private helper functions for each IDL struct.
820 # Generate private helper functions for each IDL union.
823 # in: oplist, stlist, unlist
827 def genHelpers(self,oplist,stlist,unlist):
829 self.genOperation(op)
831 self.genStructHelper(st)
833 self.genUnionHelper(un)
838 # Generate private helper functions for a specificIDL operation.
843 def genOperation(self,opnode):
845 print "XXX genOperation called"
847 sname = self.namespace(opnode, "_")
848 if not self.fn_hash_built:
849 self.fn_hash[sname] = [] # init empty list as val for this sname key
850 # but only if the fn_hash is not already built
852 self.curr_sname = sname # update current opnode's scoped name
853 opname = opnode.identifier()
855 self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
857 self.st.out(self.template_helper_function_start, sname=sname)
860 if (len(self.fn_hash[sname]) > 0):
861 self.st.out(self.template_helper_function_vars_start)
862 self.dumpCvars(sname)
863 self.st.out(self.template_helper_function_vars_end )
865 self.st.out(self.template_helper_switch_msgtype_start)
867 self.st.out(self.template_helper_switch_msgtype_request_start)
869 self.genOperationRequest(opnode)
870 self.st.out(self.template_helper_switch_msgtype_request_end)
873 self.st.out(self.template_helper_switch_msgtype_reply_start)
876 self.st.out(self.template_helper_switch_rep_status_start)
879 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
881 self.genOperationReply(opnode)
882 self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
885 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
887 self.genOpExceptions(opnode)
888 self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
891 self.st.out(self.template_helper_switch_msgtype_reply_default_start, dissector_name=self.dissname)
892 self.st.out(self.template_helper_switch_msgtype_reply_default_end)
894 self.st.out(self.template_helper_switch_rep_status_end)
898 self.st.out(self.template_helper_switch_msgtype_default_start, dissector_name=self.dissname)
899 self.st.out(self.template_helper_switch_msgtype_default_end)
901 self.st.out(self.template_helper_switch_msgtype_end)
905 self.st.out(self.template_helper_function_end, sname=sname)
911 # Decode function parameters for a GIOP request message
915 def genOperationRequest(self,opnode):
916 for p in opnode.parameters():
919 print "XXX parameter = " ,p
920 print "XXX parameter type = " ,p.paramType()
921 print "XXX parameter type kind = " ,p.paramType().kind()
923 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
927 # Decode function parameters for a GIOP reply message
931 def genOperationReply(self,opnode):
933 rt = opnode.returnType() # get return type
935 print "XXX genOperationReply"
936 print "XXX opnode = " , opnode
937 print "XXX return type = " , rt
938 print "XXX return type.unalias = " , rt.unalias()
939 print "XXX return type.kind() = " , rt.kind();
941 sname = self.namespace(opnode, "_")
943 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
944 #self.getCDR(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
945 self.get_CDR_alias(rt, sname + "_return" )
946 #self.get_CDR_alias(rt, rt.name() )
949 self.getCDR(rt, sname + "_return") # return value is NOT an alias
951 for p in opnode.parameters():
952 if p.is_out(): # out or inout
953 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
955 #self.st.dec_indent()
957 def genOpExceptions(self,opnode):
958 for ex in opnode.raises():
961 for m in ex.members():
963 #print m.memberType(), m.memberType().kind()
965 # Delegator for Operations
968 def genOpDelegator(self,oplist):
970 iname = "/".join(op.scopedName()[:-1])
971 opname = op.identifier()
972 sname = self.namespace(op, "_")
973 self.st.out(self.template_op_delegate_code, interface=iname, sname=sname, opname=opname)
976 # Delegator for Attributes
979 def genAtDelegator(self,atlist):
981 for i in a.declarators():
982 atname = i.identifier()
983 sname = self.namespace(i, "_")
984 self.st.out(self.template_at_delegate_code_get, sname=sname)
986 self.st.out(self.template_at_delegate_code_set, sname=sname)
990 # Add a variable declaration to the hash of list
993 def addvar(self, var):
994 if not ( var in self.fn_hash[self.curr_sname] ):
995 self.fn_hash[self.curr_sname].append(var)
998 # Print the variable declaration from the hash of list
1003 for fn in self.fn_hash.keys():
1005 for v in self.fn_hash[fn]:
1008 # Print the "C" variable declaration from the hash of list
1009 # for a given scoped operation name (eg: tux_penguin_eat)
1013 def dumpCvars(self, sname):
1014 for v in self.fn_hash[sname]:
1019 # Given an enum node, and a enumerator node, return
1020 # the enumerator's numerical value.
1022 # eg: enum Color {red,green,blue} should return
1026 def valFromEnum(self,enumNode, enumeratorNode):
1028 print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
1029 print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
1031 if isinstance(enumeratorNode,idlast.Enumerator):
1032 value = enumNode.enumerators().index(enumeratorNode)
1049 ## tk_Principal = 13
1060 ## tk_ulonglong = 24
1061 ## tk_longdouble = 25
1066 ## tk_value_box = 30
1068 ## tk_abstract_interface = 32
1074 # Return true for "native" datatypes that will generate a direct proto_tree_add_xxx
1075 # call for a sequence. Used to determine if a separate hf variable is needed for
1076 # the loop over the sequence
1078 def isSeqNativeType(self,type):
1080 pt = type.unalias().kind() # param CDR type
1083 print "XXX isSeqNativeType: kind = " , pt
1085 if pt == idltype.tk_ulong:
1087 elif pt == idltype.tk_longlong:
1089 elif pt == idltype.tk_ulonglong:
1091 elif pt == idltype.tk_short:
1093 elif pt == idltype.tk_long:
1095 elif pt == idltype.tk_ushort:
1097 elif pt == idltype.tk_float:
1099 elif pt == idltype.tk_double:
1101 elif pt == idltype.tk_boolean:
1103 elif pt == idltype.tk_octet:
1105 elif pt == idltype.tk_enum:
1107 elif pt == idltype.tk_string:
1109 elif pt == idltype.tk_wstring:
1111 elif pt == idltype.tk_wchar:
1113 elif pt == idltype.tk_char:
1122 # This is the main "iterator" function. It takes a node, and tries to output
1123 # a get_CDR_XXX accessor method(s). It can call itself multiple times
1124 # if I find nested structures etc.
1127 def getCDR(self,type,name="fred"):
1129 pt = type.unalias().kind() # param CDR type
1130 pn = name # param name
1133 print "XXX getCDR: kind = " , pt
1134 print "XXX getCDR: name = " , pn
1136 if pt == idltype.tk_ulong:
1137 self.get_CDR_ulong(pn)
1138 elif pt == idltype.tk_longlong:
1139 self.get_CDR_longlong(pn)
1140 elif pt == idltype.tk_ulonglong:
1141 self.get_CDR_ulonglong(pn)
1142 elif pt == idltype.tk_void:
1143 self.get_CDR_void(pn)
1144 elif pt == idltype.tk_short:
1145 self.get_CDR_short(pn)
1146 elif pt == idltype.tk_long:
1147 self.get_CDR_long(pn)
1148 elif pt == idltype.tk_ushort:
1149 self.get_CDR_ushort(pn)
1150 elif pt == idltype.tk_float:
1151 self.get_CDR_float(pn)
1152 elif pt == idltype.tk_double:
1153 self.get_CDR_double(pn)
1154 elif pt == idltype.tk_fixed:
1155 self.get_CDR_fixed(type.unalias(),pn)
1156 elif pt == idltype.tk_boolean:
1157 self.get_CDR_boolean(pn)
1158 elif pt == idltype.tk_char:
1159 self.get_CDR_char(pn)
1160 elif pt == idltype.tk_octet:
1161 self.get_CDR_octet(pn)
1162 elif pt == idltype.tk_any:
1163 self.get_CDR_any(pn)
1164 elif pt == idltype.tk_string:
1165 self.get_CDR_string(pn)
1166 elif pt == idltype.tk_wstring:
1167 self.get_CDR_wstring(pn)
1168 elif pt == idltype.tk_wchar:
1169 self.get_CDR_wchar(pn)
1170 elif pt == idltype.tk_enum:
1172 self.get_CDR_enum(pn,type)
1173 #self.get_CDR_enum(pn)
1175 elif pt == idltype.tk_struct:
1176 self.get_CDR_struct(type,pn)
1177 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1178 self.get_CDR_TypeCode(pn)
1179 elif pt == idltype.tk_sequence:
1180 if type.unalias().seqType().kind() == idltype.tk_octet:
1181 self.get_CDR_sequence_octet(type,pn)
1183 self.get_CDR_sequence(type,pn)
1184 elif pt == idltype.tk_objref:
1185 self.get_CDR_objref(type,pn)
1186 elif pt == idltype.tk_array:
1187 pn = pn # Supported elsewhere
1188 elif pt == idltype.tk_union:
1189 self.get_CDR_union(type,pn)
1190 elif pt == idltype.tk_alias:
1192 print "XXXXX Alias type XXXXX " , type
1193 self.get_CDR_alias(type,pn)
1195 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1199 # get_CDR_XXX methods are here ..
1204 def get_CDR_ulong(self,pn):
1205 self.st.out(self.template_get_CDR_ulong, hfname=pn)
1207 def get_CDR_short(self,pn):
1208 self.st.out(self.template_get_CDR_short, hfname=pn)
1210 def get_CDR_void(self,pn):
1211 self.st.out(self.template_get_CDR_void, hfname=pn)
1213 def get_CDR_long(self,pn):
1214 self.st.out(self.template_get_CDR_long, hfname=pn)
1216 def get_CDR_ushort(self,pn):
1217 self.st.out(self.template_get_CDR_ushort, hfname=pn)
1219 def get_CDR_float(self,pn):
1220 self.st.out(self.template_get_CDR_float, hfname=pn)
1222 def get_CDR_double(self,pn):
1223 self.st.out(self.template_get_CDR_double, hfname=pn)
1225 def get_CDR_longlong(self,pn):
1226 self.st.out(self.template_get_CDR_longlong, hfname=pn)
1228 def get_CDR_ulonglong(self,pn):
1229 self.st.out(self.template_get_CDR_ulonglong, hfname=pn)
1231 def get_CDR_boolean(self,pn):
1232 self.st.out(self.template_get_CDR_boolean, hfname=pn)
1234 def get_CDR_fixed(self,type,pn):
1236 print "XXXX calling get_CDR_fixed, type = ", type
1237 print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1238 print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1240 string_digits = '%i ' % type.digits() # convert int to string
1241 string_scale = '%i ' % type.scale() # convert int to string
1242 string_length = '%i ' % self.dig_to_len(type.digits()) # how many octets to hilight for a number of digits
1244 self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1245 self.addvar(self.c_seq)
1248 def get_CDR_char(self,pn):
1249 self.st.out(self.template_get_CDR_char, hfname=pn)
1251 def get_CDR_octet(self,pn):
1252 self.st.out(self.template_get_CDR_octet, hfname=pn)
1254 def get_CDR_any(self,pn):
1255 self.st.out(self.template_get_CDR_any, varname=pn)
1257 def get_CDR_enum(self,pn,type):
1258 #self.st.out(self.template_get_CDR_enum, hfname=pn)
1259 sname = self.namespace(type.unalias(), "_")
1260 self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname,hfname=pn)
1261 self.addvar(self.c_u_octet4)
1263 def get_CDR_string(self,pn):
1264 self.st.out(self.template_get_CDR_string, hfname=pn)
1266 def get_CDR_wstring(self,pn):
1267 self.st.out(self.template_get_CDR_wstring, varname=pn)
1268 self.addvar(self.c_u_octet4)
1269 self.addvar(self.c_seq)
1271 def get_CDR_wchar(self,pn):
1272 self.st.out(self.template_get_CDR_wchar, varname=pn)
1273 self.addvar(self.c_s_octet1)
1274 self.addvar(self.c_seq)
1276 def get_CDR_TypeCode(self,pn):
1277 self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1278 self.addvar(self.c_u_octet4)
1280 def get_CDR_objref(self,type,pn):
1281 self.st.out(self.template_get_CDR_object)
1283 def get_CDR_union(self,type,pn):
1285 print "XXX Union type =" , type, " pn = ",pn
1286 print "XXX Union type.decl()" , type.decl()
1287 print "XXX Union Scoped Name" , type.scopedName()
1289 # If I am a typedef union {..}; node then find the union node
1291 if isinstance(type.decl(), idlast.Declarator):
1292 ntype = type.decl().alias().aliasType().decl()
1294 ntype = type.decl() # I am a union node
1297 print "XXX Union ntype =" , ntype
1299 sname = self.namespace(ntype, "_")
1300 self.st.out(self.template_union_start, name=sname )
1302 # Output a call to the union helper function so I can handle recursive union also.
1304 self.st.out(self.template_decode_union,name=sname)
1306 self.st.out(self.template_union_end, name=sname )
1311 # This takes a node, and tries to output the appropriate item for the
1315 def getCDR_hf(self,type,desc,filter,hf_name="fred"):
1317 pt = type.unalias().kind() # param CDR type
1318 pn = hf_name # param name
1321 print "XXX getCDR_hf: kind = " , pt
1322 print "XXX getCDR_hf: name = " , pn
1324 if pt == idltype.tk_ulong:
1325 self.get_CDR_ulong_hf(pn, desc, filter, self.dissname)
1326 elif pt == idltype.tk_longlong:
1327 self.get_CDR_longlong_hf(pn, desc, filter, self.dissname)
1328 elif pt == idltype.tk_ulonglong:
1329 self.get_CDR_ulonglong_hf(pn, desc, filter, self.dissname)
1330 elif pt == idltype.tk_void:
1331 pt = pt # no hf_ variables needed
1332 elif pt == idltype.tk_short:
1333 self.get_CDR_short_hf(pn, desc, filter, self.dissname)
1334 elif pt == idltype.tk_long:
1335 self.get_CDR_long_hf(pn, desc, filter, self.dissname)
1336 elif pt == idltype.tk_ushort:
1337 self.get_CDR_ushort_hf(pn, desc, filter, self.dissname)
1338 elif pt == idltype.tk_float:
1339 self.get_CDR_float_hf(pn, desc, filter, self.dissname)
1340 elif pt == idltype.tk_double:
1341 self.get_CDR_double_hf(pn, desc, filter, self.dissname)
1342 elif pt == idltype.tk_fixed:
1343 pt = pt # no hf_ variables needed
1344 elif pt == idltype.tk_boolean:
1345 self.get_CDR_boolean_hf(pn, desc, filter, self.dissname)
1346 elif pt == idltype.tk_char:
1347 self.get_CDR_char_hf(pn, desc, filter, self.dissname)
1348 elif pt == idltype.tk_octet:
1349 self.get_CDR_octet_hf(pn, desc, filter, self.dissname)
1350 elif pt == idltype.tk_any:
1351 pt = pt # no hf_ variables needed
1352 elif pt == idltype.tk_string:
1353 self.get_CDR_string_hf(pn, desc, filter, self.dissname)
1354 elif pt == idltype.tk_wstring:
1355 self.get_CDR_wstring_hf(pn, desc, filter, self.dissname)
1356 elif pt == idltype.tk_wchar:
1357 self.get_CDR_wchar_hf(pn, desc, filter, self.dissname)
1358 elif pt == idltype.tk_enum:
1359 self.get_CDR_enum_hf(pn, type, desc, filter, self.dissname)
1360 elif pt == idltype.tk_struct:
1361 pt = pt # no hf_ variables needed (should be already contained in struct members)
1362 elif pt == idltype.tk_TypeCode: # will I ever get here ?
1363 self.get_CDR_TypeCode_hf(pn, desc, filter, self.dissname)
1364 elif pt == idltype.tk_sequence:
1365 if type.unalias().seqType().kind() == idltype.tk_octet:
1366 self.get_CDR_sequence_octet_hf(type, pn, desc, filter, self.dissname)
1368 self.get_CDR_sequence_hf(type, pn, desc, filter, self.dissname)
1369 elif pt == idltype.tk_objref:
1370 pt = pt # no object specific hf_ variables used, use generic ones from giop dissector
1371 elif pt == idltype.tk_array:
1372 pt = pt # Supported elsewhere
1373 elif pt == idltype.tk_union:
1374 pt = pt # no hf_ variables needed (should be already contained in union members)
1375 elif pt == idltype.tk_alias:
1377 print "XXXXX Alias type hf XXXXX " , type
1378 self.get_CDR_alias_hf(type,pn)
1380 self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1383 # get_CDR_XXX_hf methods are here ..
1388 def get_CDR_ulong_hf(self,pn,desc,filter,diss):
1389 self.st.out(self.template_get_CDR_ulong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1391 def get_CDR_short_hf(self,pn,desc,filter,diss):
1392 self.st.out(self.template_get_CDR_short_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1394 def get_CDR_long_hf(self,pn,desc,filter,diss):
1395 self.st.out(self.template_get_CDR_long_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1397 def get_CDR_ushort_hf(self,pn,desc,filter,diss):
1398 self.st.out(self.template_get_CDR_ushort_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1400 def get_CDR_float_hf(self,pn,desc,filter,diss):
1401 self.st.out(self.template_get_CDR_float_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1403 def get_CDR_double_hf(self,pn,desc,filter,diss):
1404 self.st.out(self.template_get_CDR_double_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1406 def get_CDR_longlong_hf(self,pn,desc,filter,diss):
1407 self.st.out(self.template_get_CDR_longlong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1409 def get_CDR_ulonglong_hf(self,pn,desc,filter,diss):
1410 self.st.out(self.template_get_CDR_ulonglong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1412 def get_CDR_boolean_hf(self,pn,desc,filter,diss):
1413 self.st.out(self.template_get_CDR_boolean_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1415 def get_CDR_char_hf(self,pn,desc,filter,diss):
1416 self.st.out(self.template_get_CDR_char_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1418 def get_CDR_octet_hf(self,pn,desc,filter,diss):
1419 self.st.out(self.template_get_CDR_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1421 def get_CDR_enum_hf(self,pn,type,desc,filter,diss):
1422 sname = self.namespace(type.unalias(), "_")
1423 self.st.out(self.template_get_CDR_enum_symbolic_hf, valstringarray=sname,hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1425 def get_CDR_string_hf(self,pn,desc,filter,diss):
1426 self.st.out(self.template_get_CDR_string_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1428 def get_CDR_wstring_hf(self,pn,desc,filter,diss):
1429 self.st.out(self.template_get_CDR_wstring_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1430 # self.addvar(self.c_u_octet4)
1431 # self.addvar(self.c_seq)
1433 def get_CDR_wchar_hf(self,pn,desc,filter,diss):
1434 self.st.out(self.template_get_CDR_wchar_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1435 # self.addvar(self.c_s_octet1)
1436 # self.addvar(self.c_seq)
1438 def get_CDR_TypeCode_hf(self,pn,desc,filter,diss):
1439 self.st.out(self.template_get_CDR_TypeCode_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1441 def get_CDR_sequence_octet_hf(self,type,pn,desc,filter,diss):
1442 self.st.out(self.template_get_CDR_sequence_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1444 def get_CDR_sequence_hf(self,type,pn,desc,filter,diss):
1445 self.st.out(self.template_get_CDR_sequence_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1446 if (self.isSeqNativeType(type.unalias().seqType())):
1447 self.getCDR_hf(type.unalias().seqType(),desc,filter,pn)
1449 def get_CDR_alias_hf(self,type,pn):
1451 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1452 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1453 print "XXX get_CDR_alias_hf, type.decl().alias() = " ,type.decl().alias()
1455 decl = type.decl() # get declarator object
1457 if (decl.sizes()): # a typedef array
1458 #indices = self.get_indices_from_sizes(decl.sizes())
1459 #string_indices = '%i ' % indices # convert int to string
1460 #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1462 #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1463 #self.addvar(self.c_i + pn + ";")
1464 #self.st.inc_indent()
1465 self.getCDR_hf(type.decl().alias().aliasType(), pn )
1467 #self.st.dec_indent()
1468 #self.st.out(self.template_get_CDR_array_end)
1471 else: # a simple typdef
1473 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1474 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1476 self.getCDR_hf(type, decl.identifier() )
1480 # Code to generate Union Helper functions
1482 # in: un - a union node
1487 def genUnionHelper(self,un):
1489 print "XXX genUnionHelper called"
1490 print "XXX Union type =" , un
1491 print "XXX Union type.switchType()" , un.switchType()
1492 print "XXX Union Scoped Name" , un.scopedName()
1494 sname = self.namespace(un, "_")
1495 self.curr_sname = sname # update current opnode/exnode/stnode/unnode scoped name
1496 if not self.fn_hash_built:
1497 self.fn_hash[sname] = [] # init empty list as val for this sname key
1498 # but only if the fn_hash is not already built
1500 self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
1501 self.st.inc_indent()
1503 if (len(self.fn_hash[sname]) > 0):
1504 self.st.out(self.template_helper_function_vars_start)
1505 self.dumpCvars(sname)
1506 self.st.out(self.template_helper_function_vars_end )
1508 st = un.switchType().unalias() # may be typedef switch type, so find real type
1510 self.st.out(self.template_comment_union_code_start, uname=un.repoId() )
1512 self.getCDR(st, sname + "_" + un.identifier());
1514 # Depending on what kind of discriminant I come accross (enum,integer,char,
1515 # short, boolean), make sure I cast the return value of the get_XXX accessor
1516 # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1517 # return an integer, or an Enumerator object that is then converted to its
1518 # integer equivalent.
1521 # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1524 if (st.kind() == idltype.tk_enum):
1526 self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1528 #count the number of cases to ensure variable is needed
1531 for uc in un.cases(): # for all UnionCase objects in this union
1532 num += len(uc.labels())
1533 for cl in uc.labels():
1537 if ((num != 1) or (num_defaults != 1)):
1538 self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
1539 self.addvar(self.c_s_disc + un.identifier() + ";")
1541 elif (st.kind() == idltype.tk_long):
1542 self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
1543 self.addvar(self.c_s_disc + un.identifier() + ";")
1545 elif (st.kind() == idltype.tk_ulong):
1546 self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
1547 self.addvar(self.c_s_disc + un.identifier() + ";")
1549 elif (st.kind() == idltype.tk_short):
1550 self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
1551 self.addvar(self.c_s_disc + un.identifier() + ";")
1553 elif (st.kind() == idltype.tk_ushort):
1554 self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
1555 self.addvar(self.c_s_disc + un.identifier() + ";")
1557 elif (st.kind() == idltype.tk_boolean):
1558 self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier() )
1559 self.addvar(self.c_s_disc + un.identifier() + ";")
1561 elif (st.kind() == idltype.tk_char):
1562 self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
1563 self.addvar(self.c_s_disc + un.identifier() + ";")
1566 print "XXX Unknown st.kind() = ", st.kind()
1569 # Loop over all cases in this union
1572 for uc in un.cases(): # for all UnionCase objects in this union
1573 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1575 # get integer value, even if discriminant is
1576 # an Enumerator node
1578 if isinstance(cl.value(),idlast.Enumerator):
1580 print "XXX clv.identifier()", cl.value().identifier()
1581 print "XXX clv.repoId()", cl.value().repoId()
1582 print "XXX clv.scopedName()", cl.value().scopedName()
1584 # find index of enumerator in enum declaration
1585 # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1587 clv = self.valFromEnum(std,cl.value())
1592 #print "XXX clv = ",clv
1595 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1596 # eg: if (disc == 'b')..
1598 # TODO : handle \xxx chars generically from a function or table lookup rather than
1599 # a whole bunch of "if" statements. -- FS
1602 if (st.kind() == idltype.tk_char):
1603 if (clv == '\n'): # newline
1604 string_clv = "'\\n'"
1605 elif (clv == '\t'): # tab
1606 string_clv = "'\\t'"
1608 string_clv = "'" + clv + "'"
1610 string_clv = '%i ' % clv
1613 # If default case, then skp comparison with discriminator
1616 if not cl.default():
1617 self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
1618 self.st.inc_indent()
1620 self.st.out(self.template_comment_union_code_label_default_start )
1623 self.getCDR(uc.caseType(),sname + "_" + uc.declarator().identifier())
1625 if not cl.default():
1626 self.st.dec_indent()
1627 self.st.out(self.template_comment_union_code_label_compare_end )
1629 self.st.out(self.template_comment_union_code_label_default_end )
1631 self.st.dec_indent()
1632 self.st.out(self.template_union_helper_function_end)
1637 # Currently, get_CDR_alias is geared to finding typdef
1640 def get_CDR_alias(self,type,pn):
1642 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1643 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1644 print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1646 decl = type.decl() # get declarator object
1648 if (decl.sizes()): # a typedef array
1649 indices = self.get_indices_from_sizes(decl.sizes())
1650 string_indices = '%i ' % indices # convert int to string
1651 self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1653 self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1654 self.addvar(self.c_i + pn + ";")
1655 self.st.inc_indent()
1656 self.getCDR(type.decl().alias().aliasType(), pn )
1658 self.st.dec_indent()
1659 self.st.out(self.template_get_CDR_array_end)
1662 else: # a simple typdef
1664 self.getCDR(type, pn )
1672 # Handle structs, including recursive
1675 def get_CDR_struct(self,type,pn):
1677 # If I am a typedef struct {..}; node then find the struct node
1679 if isinstance(type.decl(), idlast.Declarator):
1680 ntype = type.decl().alias().aliasType().decl()
1682 ntype = type.decl() # I am a struct node
1684 sname = self.namespace(ntype, "_")
1685 self.st.out(self.template_structure_start, name=sname )
1687 # Output a call to the struct helper function so I can handle recursive structs also.
1689 self.st.out(self.template_decode_struct,name=sname)
1691 self.st.out(self.template_structure_end, name=sname )
1696 # Generate private helper functions to decode a struct
1698 # in: stnode ( a struct node)
1701 def genStructHelper(self,st):
1703 print "XXX genStructHelper"
1705 sname = self.namespace(st, "_")
1706 self.curr_sname = sname # update current opnode/exnode/stnode scoped name
1707 if not self.fn_hash_built:
1708 self.fn_hash[sname] = [] # init empty list as val for this sname key
1709 # but only if the fn_hash is not already built
1711 self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
1712 self.st.inc_indent()
1714 if (len(self.fn_hash[sname]) > 0):
1715 self.st.out(self.template_helper_function_vars_start)
1716 self.dumpCvars(sname)
1717 self.st.out(self.template_helper_function_vars_end )
1719 for m in st.members():
1720 for decl in m.declarators():
1721 if decl.sizes(): # an array
1722 indices = self.get_indices_from_sizes(decl.sizes())
1723 string_indices = '%i ' % indices # convert int to string
1724 self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1725 self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1726 self.addvar(self.c_i + decl.identifier() + ";")
1728 self.st.inc_indent()
1729 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1730 self.st.dec_indent()
1731 self.st.out(self.template_get_CDR_array_end)
1735 self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1737 self.st.dec_indent()
1738 self.st.out(self.template_struct_helper_function_end)
1745 # Generate code to access a sequence of a type
1749 def get_CDR_sequence(self,type,pn):
1750 self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1751 self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1752 self.addvar(self.c_i_lim + pn + ";" )
1753 self.addvar(self.c_i + pn + ";")
1755 self.st.inc_indent()
1756 self.getCDR(type.unalias().seqType(), pn ) # and start all over with the type
1757 self.st.dec_indent()
1759 self.st.out(self.template_get_CDR_sequence_loop_end)
1763 # Generate code to access a sequence of octet
1766 def get_CDR_sequence_octet(self,type, pn):
1767 self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1768 self.st.out(self.template_get_CDR_sequence_octet, seqname=pn)
1769 self.addvar(self.c_i_lim + pn + ";")
1770 self.addvar("gchar * binary_seq_" + pn + ";")
1771 self.addvar("gchar * text_seq_" + pn + ";")
1779 # out - scoped operation name, using sep character instead of "::"
1781 # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1785 def namespace(self,node,sep):
1786 sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1787 #print "XXX namespace: sname = " + sname
1792 # generate code for plugin initialisation
1795 def gen_plugin_register(self):
1796 self.st.out(self.template_plugin_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1799 # generate register_giop_user_module code, and register only
1800 # unique interfaces that contain operations. Also output
1801 # a heuristic register in case we want to use that.
1803 # TODO - make this a command line option
1811 def gen_proto_reg_handoff(self, oplist):
1813 self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1814 self.st.inc_indent()
1816 for iname in self.get_intlist(oplist):
1817 self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1819 self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname, protocol_name=self.protoname)
1820 self.st.dec_indent()
1822 self.st.out(self.template_proto_reg_handoff_end)
1825 # generate hf_ array element for operation, attribute, enums, struct and union lists
1828 def genOp_hf(self,op):
1829 sname = self.namespace(op, "_")
1830 opname = sname[string.find(sname, "_")+1:]
1831 opname = opname[:string.find(opname, "_")]
1832 rt = op.returnType()
1834 if (rt.kind() != idltype.tk_void):
1835 if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
1836 self.getCDR_hf(rt, rt.name(),\
1837 opname + "." + op.identifier() + ".return", sname + "_return")
1839 self.getCDR_hf(rt, "Return value",\
1840 opname + "." + op.identifier() + ".return", sname + "_return")
1842 for p in op.parameters():
1843 self.getCDR_hf(p.paramType(), p.identifier(),\
1844 opname + "." + op.identifier() + "." + p.identifier(), sname + "_" + p.identifier())
1846 def genAt_hf(self,at):
1847 for decl in at.declarators():
1848 sname = self.namespace(decl, "_")
1849 atname = sname[string.find(sname, "_")+1:]
1850 atname = atname[:string.find(atname, "_")]
1852 self.getCDR_hf(at.attrType(), decl.identifier(),\
1853 atname + "." + decl.identifier() + ".get", "get" + "_" + sname + "_" + decl.identifier())
1854 if not at.readonly():
1855 self.getCDR_hf(at.attrType(), decl.identifier(),\
1856 atname + "." + decl.identifier() + ".set", "set" + "_" + sname + "_" + decl.identifier())
1858 def genSt_hf(self,st):
1859 sname = self.namespace(st, "_")
1860 stname = sname[string.find(sname, "_")+1:]
1861 stname = stname[:string.find(stname, "_")]
1862 for m in st.members():
1863 for decl in m.declarators():
1864 self.getCDR_hf(m.memberType(), st.identifier() + "_" + decl.identifier(),\
1865 st.identifier() + "." + decl.identifier(), sname + "_" + decl.identifier())
1867 def genEx_hf(self,ex):
1868 sname = self.namespace(ex, "_")
1869 exname = sname[string.find(sname, "_")+1:]
1870 exname = exname[:string.find(exname, "_")]
1871 for m in ex.members():
1872 for decl in m.declarators():
1873 self.getCDR_hf(m.memberType(), ex.identifier() + "_" + decl.identifier(),\
1874 exname + "." + ex.identifier() + "_" + decl.identifier(), sname + "_" + decl.identifier())
1876 def genUnion_hf(self,un):
1877 sname = self.namespace(un, "_")
1878 unname = sname[:string.rfind(sname, "_")]
1879 unname = string.replace(unname, "_", ".")
1881 self.getCDR_hf(un.switchType().unalias(), un.identifier(),\
1882 unname + "." + un.identifier(), sname + "_" + un.identifier())
1884 for uc in un.cases(): # for all UnionCase objects in this union
1885 for cl in uc.labels(): # for all Caselabel objects in this UnionCase
1886 self.getCDR_hf(uc.caseType(), un.identifier() + "_" + uc.declarator().identifier(),\
1887 unname + "." + un.identifier() + "." + uc.declarator().identifier(),\
1888 sname + "_" + uc.declarator().identifier())
1891 # generate proto_register_<protoname> code,
1893 # in - oplist[], atlist[], stline[], unlist[]
1897 def gen_proto_register(self, oplist, atlist, stlist, unlist):
1898 self.st.out(self.template_proto_register_start, dissector_name=self.dissname)
1900 #operation specific filters
1901 self.st.out(self.template_proto_register_op_filter_comment)
1906 self.st.out(self.template_proto_register_at_filter_comment)
1911 self.st.out(self.template_proto_register_st_filter_comment)
1913 if (st.members()): # only if has members
1916 # exception List filters
1917 exlist = self.get_exceptionList(oplist) # grab list of exception nodes
1918 self.st.out(self.template_proto_register_ex_filter_comment)
1920 if (ex.members()): # only if has members
1924 self.st.out(self.template_proto_register_un_filter_comment)
1926 self.genUnion_hf(un)
1928 self.st.out(self.template_proto_register_end, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1934 # out - a list of unique interface names. This will be used in
1935 # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" ); so the operation
1936 # name must be removed from the scope. And we also only want unique interfaces.
1939 def get_intlist(self,oplist):
1940 int_hash = {} # holds a hash of unique interfaces
1942 sc = op.scopedName() # eg: penguin,tux,bite
1943 sc1 = sc[:-1] # drop last entry
1944 sn = idlutil.slashName(sc1) # penguin/tux
1945 if not int_hash.has_key(sn):
1946 int_hash[sn] = 0; # dummy val, but at least key is unique
1947 ret = int_hash.keys()
1956 # out - a list of exception nodes (unique). This will be used in
1957 # to generate dissect_exception_XXX functions.
1962 def get_exceptionList(self,oplist):
1963 ex_hash = {} # holds a hash of unique exceptions.
1965 for ex in op.raises():
1966 if not ex_hash.has_key(ex):
1967 ex_hash[ex] = 0; # dummy val, but at least key is unique
1969 print "XXX Exception = " + ex.identifier()
1970 ret = ex_hash.keys()
1977 # Simple function to take a list of array sizes and find the
1978 # total number of elements
1981 # eg: temp[4][3] = 12 elements
1984 def get_indices_from_sizes(self,sizelist):
1992 # Determine how many octets contain requested number
1993 # of digits for an "fixed" IDL type "on the wire"
1996 def dig_to_len(self,dignum):
1997 return (dignum/2) + 1
2002 # Output some TODO comment
2006 def genTODO(self,message):
2007 self.st.out(self.template_debug_TODO, message=message)
2010 # Output some WARNING comment
2014 def genWARNING(self,message):
2015 self.st.out(self.template_debug_WARNING, message=message)
2018 # Templates for C code
2021 template_helper_function_comment = """\
2025 template_helper_function_vars_start = """\
2026 /* Operation specific Variable declarations Begin */"""
2028 template_helper_function_vars_end = """\
2029 /* Operation specific Variable declarations End */
2031 (void)item; /* Avoid coverity param_set_but_unused parse warning */
2034 template_helper_function_start = """\
2036 decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2039 template_helper_function_end = """\
2043 # proto_reg_handoff() templates
2046 template_proto_reg_handoff_start = """\
2047 /* register me as handler for these interfaces */
2048 void proto_reg_handoff_giop_@dissector_name@(void)
2051 template_proto_reg_handoff_body = """\
2052 /* Register for Explicit Dissection */
2053 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
2056 template_proto_reg_handoff_heuristic = """\
2057 /* Register for Heuristic Dissection */
2058 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
2061 template_proto_reg_handoff_end = """\
2069 template_prototype = """
2070 void proto_register_giop_@dissector_name@(void);
2071 void proto_reg_handoff_giop_@dissector_name@(void);"""
2074 # Initialize the protocol
2077 template_protocol = """
2078 /* Initialise the protocol and subtree pointers */
2079 static int proto_@dissector_name@ = -1;
2080 static gint ett_@dissector_name@ = -1;
2083 # Initialize the boundary Alignment
2086 template_init_boundary = """
2087 /* Initialise the initial Alignment */
2088 static guint32 boundary = GIOP_HEADER_SIZE; /* initial value */"""
2091 # plugin_register and plugin_reg_handoff templates
2094 template_plugin_register = """
2097 WS_DLL_PUBLIC_DEF void
2098 plugin_register(void)
2100 if (proto_@dissector_name@ == -1) {
2101 proto_register_giop_@dissector_name@();
2105 WS_DLL_PUBLIC_DEF void
2106 plugin_reg_handoff(void){
2107 proto_register_handoff_giop_@dissector_name@();
2112 # proto_register_<dissector name>(void) templates
2115 template_proto_register_start = """
2116 /* Register the protocol with Wireshark */
2117 void proto_register_giop_@dissector_name@(void)
2119 /* setup list of header fields */
2120 static hf_register_info hf[] = {
2121 /* field that indicates the currently ongoing request/reply exchange */
2122 {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2124 template_proto_register_end = """
2127 static ei_register_info ei[] = {
2128 { &ei_@dissector_name@_unknown_giop_msg, { "giop-@dissector_name@.unknown_giop_msg", PI_PROTOCOL, PI_WARN, "Unknown GIOP message", EXPFILL }},
2129 { &ei_@dissector_name@_unknown_exception, { "giop-@dissector_name@.unknown_exception", PI_PROTOCOL, PI_WARN, "Unknown exception", EXPFILL }},
2130 { &ei_@dissector_name@_unknown_reply_status, { "giop-@dissector_name@.unknown_reply_status", PI_PROTOCOL, PI_WARN, "Unknown reply status", EXPFILL }},
2133 /* setup protocol subtree array */
2135 static gint *ett[] = {
2136 &ett_@dissector_name@,
2139 expert_module_t* expert_@dissector_name@;
2142 /* Register the protocol name and description */
2143 proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
2144 proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
2145 proto_register_subtree_array(ett, array_length(ett));
2147 expert_@dissector_name@ = expert_register_protocol(proto_@dissector_name@);
2148 expert_register_field_array(expert_@dissector_name@, ei, array_length(ei));
2152 template_proto_register_op_filter_comment = """\
2153 /* Operation filters */"""
2155 template_proto_register_at_filter_comment = """\
2156 /* Attribute filters */"""
2158 template_proto_register_st_filter_comment = """\
2159 /* Struct filters */"""
2161 template_proto_register_ex_filter_comment = """\
2162 /* User exception filters */"""
2164 template_proto_register_un_filter_comment = """\
2165 /* Union filters */"""
2167 template_proto_register_ei_filters = """\
2168 /* Expert info filters */
2169 static expert_field ei_@dissector_name@_unknown_giop_msg = EI_INIT;
2170 static expert_field ei_@dissector_name@_unknown_exception = EI_INIT;
2171 static expert_field ei_@dissector_name@_unknown_reply_status = EI_INIT;
2175 # template for delegation code
2178 template_op_delegate_code = """\
2179 if (strcmp(operation, "@opname@") == 0
2180 && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
2181 item = process_RequestOperation(tvb, pinfo, ptree, header, operation); /* fill-up Request_Operation field & info column */
2182 tree = start_dissecting(tvb, pinfo, ptree, offset);
2183 decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
2188 # Templates for the helper functions
2193 template_helper_switch_msgtype_start = """\
2194 switch(header->message_type) {"""
2196 template_helper_switch_msgtype_default_start = """\
2198 /* Unknown GIOP Message */
2199 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2201 template_helper_switch_msgtype_default_end = """\
2204 template_helper_switch_msgtype_end = """\
2205 } /* switch(header->message_type) */"""
2207 template_helper_switch_msgtype_request_start = """\
2210 template_helper_switch_msgtype_request_end = """\
2213 template_helper_switch_msgtype_reply_start = """\
2216 template_helper_switch_msgtype_reply_no_exception_start = """\
2217 case NO_EXCEPTION:"""
2219 template_helper_switch_msgtype_reply_no_exception_end = """\
2222 template_helper_switch_msgtype_reply_user_exception_start = """\
2223 case USER_EXCEPTION:"""
2225 template_helper_switch_msgtype_reply_user_exception_end = """\
2228 template_helper_switch_msgtype_reply_default_start = """\
2230 /* Unknown Exception */
2231 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_exception, "Unknown exception %d", header->rep_status);"""
2233 template_helper_switch_msgtype_reply_default_end = """\
2236 template_helper_switch_msgtype_reply_end = """\
2239 template_helper_switch_msgtype_default_start = """\
2241 /* Unknown GIOP Message */
2242 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2244 template_helper_switch_msgtype_default_end = """\
2247 template_helper_switch_rep_status_start = """\
2248 switch(header->rep_status) {"""
2250 template_helper_switch_rep_status_default_start = """\
2252 /* Unknown Reply Status */
2253 expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_reply_status, "Unknown reply status %d", header->rep_status);"""
2255 template_helper_switch_rep_status_default_end = """\
2258 template_helper_switch_rep_status_end = """\
2259 } /* switch(header->rep_status) */
2264 # Templates for get_CDR_xxx accessors
2267 template_get_CDR_ulong = """\
2268 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
2270 template_get_CDR_short = """\
2271 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
2273 template_get_CDR_void = """\
2274 /* Function returns void */
2276 template_get_CDR_long = """\
2277 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
2279 template_get_CDR_ushort = """\
2280 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
2282 template_get_CDR_float = """\
2283 proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
2285 template_get_CDR_double = """\
2286 proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
2288 template_get_CDR_longlong = """\
2289 proto_tree_add_int64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
2291 template_get_CDR_ulonglong = """\
2292 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
2294 template_get_CDR_boolean = """\
2295 proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
2297 template_get_CDR_char = """\
2298 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
2300 template_get_CDR_octet = """\
2301 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
2303 template_get_CDR_any = """\
2304 get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
2306 template_get_CDR_fixed = """\
2307 get_CDR_fixed(tvb, pinfo, item, &seq, offset, @digits@, @scale@);
2308 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
2310 template_get_CDR_enum_symbolic = """\
2311 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2312 /* coverity[returned_pointer] */
2313 item = proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
2315 template_get_CDR_string = """\
2316 giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, hf_@hfname@);
2318 template_get_CDR_wstring = """\
2319 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2320 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ (%u) = %s",
2321 u_octet4, (u_octet4 > 0) ? seq : \"\");
2323 template_get_CDR_wchar = """\
2324 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2327 proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
2330 s_octet1 = -s_octet1;
2333 proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
2336 template_get_CDR_TypeCode = """\
2337 u_octet4 = get_CDR_typeCode(tvb, pinfo, tree, offset, stream_is_big_endian, boundary, header);
2340 template_get_CDR_object = """\
2341 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2344 template_get_CDR_sequence_length = """\
2345 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2346 /* coverity[returned_pointer] */
2347 item = proto_tree_add_uint(tree, hf_@seqname@_loop, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2349 template_get_CDR_sequence_loop_start = """\
2350 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2352 template_get_CDR_sequence_loop_end = """\
2356 template_get_CDR_sequence_octet = """\
2357 if (u_octet4_loop_@seqname@ > 0 && tree) {
2358 get_CDR_octet_seq(tvb, &binary_seq_@seqname@, offset,
2359 u_octet4_loop_@seqname@);
2360 text_seq_@seqname@ = make_printable_string(binary_seq_@seqname@,
2361 u_octet4_loop_@seqname@);
2362 proto_tree_add_text(tree, tvb, *offset - u_octet4_loop_@seqname@,
2363 u_octet4_loop_@seqname@, \"@seqname@: %s\", text_seq_@seqname@);
2366 template_get_CDR_array_start = """\
2367 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2369 template_get_CDR_array_end = """\
2372 template_get_CDR_array_comment = """\
2373 /* Array: @aname@[ @asize@] */
2375 template_structure_start = """\
2376 /* Begin struct \"@name@\" */"""
2378 template_structure_end = """\
2379 /* End struct \"@name@\" */"""
2381 template_union_start = """\
2382 /* Begin union \"@name@\" */"""
2384 template_union_end = """\
2385 /* End union \"@name@\" */"""
2388 # Templates for get_CDR_xxx_hf accessors
2391 template_get_CDR_ulong_hf = """\
2392 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2394 template_get_CDR_short_hf = """\
2395 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2397 template_get_CDR_long_hf = """\
2398 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2400 template_get_CDR_ushort_hf = """\
2401 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2403 template_get_CDR_float_hf = """\
2404 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2406 template_get_CDR_double_hf = """\
2407 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2409 template_get_CDR_longlong_hf = """\
2410 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2412 template_get_CDR_ulonglong_hf = """\
2413 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2415 template_get_CDR_boolean_hf = """\
2416 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""
2418 template_get_CDR_char_hf = """\
2419 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2421 template_get_CDR_octet_hf = """\
2422 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2424 template_get_CDR_enum_symbolic_hf = """\
2425 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2427 template_get_CDR_string_hf = """\
2428 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2430 template_get_CDR_wstring_hf = """\
2431 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2433 template_get_CDR_wchar_hf = """\
2434 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2436 template_get_CDR_TypeCode_hf = """\
2437 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2439 template_get_CDR_sequence_hf = """\
2440 {&hf_@hfname@_loop, {"Seq length of @descname@","giop-@dissector_name@.@filtername@.size",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2442 template_get_CDR_sequence_octet_hf = """\
2443 {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2446 # Program Header Template
2449 template_Header = """\
2450 /* packet-@dissector_name@.c
2452 * Routines for IDL dissection
2454 * Autogenerated from idl2wrs
2455 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2460 template_wireshark_copyright = """\
2462 * Wireshark - Network traffic analyzer
2464 * Copyright 1999 - 2012 Gerald Combs
2477 * This program is free software; you can redistribute it and/or
2478 * modify it under the terms of the GNU General Public License
2479 * as published by the Free Software Foundation; either version 2
2480 * of the License, or (at your option) any later version.
2482 * This program is distributed in the hope that it will be useful,
2483 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2484 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2485 * GNU General Public License for more details.
2487 * You should have received a copy of the GNU General Public License
2488 * along with this program; if not, write to the Free Software
2489 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2494 # Modelines Template
2498 template_Modelines = """\
2505 * indent-tabs-mode: nil
2508 * ex: set shiftwidth=4 tabstop=8 expandtab:
2509 * :indentSize=4:tabSize=8:noTabs=true:
2516 template_Includes = """\
2520 #include <gmodule.h>
2524 #include <epan/packet.h>
2525 #include <epan/proto.h>
2526 #include <epan/dissectors/packet-giop.h>
2527 #include <epan/expert.h>
2530 /* disable warning: "unreference local variable" */
2531 #pragma warning(disable:4101)
2534 #if defined(__GNUC__)
2535 #pragma GCC diagnostic ignored "-Wunused-function"
2536 #pragma GCC diagnostic ignored "-Wunused-variable"
2541 # Main dissector entry templates
2544 template_main_dissector_start = """\
2546 * Called once we accept the packet as being for us; it sets the
2547 * Protocol and Info columns and creates the top-level protocol
2551 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
2554 proto_item *ti = NULL;
2555 proto_tree *tree = NULL; /* init later, inside if(tree) */
2557 col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2560 * Do not clear COL_INFO, as nothing is being written there by
2561 * this dissector yet. So leave it as is from the GIOP dissector.
2562 * TODO: add something useful to COL_INFO
2563 * col_clear(pinfo->cinfo, COL_INFO);
2567 ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, -1, ENC_NA);
2568 tree = proto_item_add_subtree(ti, ett_@dissname@);
2574 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const gchar *operation)
2577 if(header->message_type == Reply) {
2578 /* fill-up info column */
2579 col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
2581 /* fill-up the field */
2582 pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
2583 PROTO_ITEM_SET_GENERATED(pi);
2588 dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const gchar *operation, gchar *idlname)
2590 proto_item *item _U_;
2591 proto_tree *tree _U_;
2592 gboolean stream_is_big_endian = is_big_endian(header); /* get endianess */
2594 /* If we have a USER Exception, then decode it and return */
2595 if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2596 return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
2600 template_main_dissector_switch_msgtype_start = """\
2601 switch(header->message_type) {
2603 template_main_dissector_switch_msgtype_start_request_reply = """\
2607 template_main_dissector_switch_msgtype_end_request_reply = """\
2610 template_main_dissector_switch_msgtype_all_other_msgtype = """\
2614 case CloseConnection:
2617 return FALSE; /* not handled yet */
2620 return FALSE; /* not handled yet */
2624 template_main_dissector_end = """\
2628 } /* End of main dissector */
2637 #-------------------------------------------------------------#
2638 # Exception handling templates #
2639 #-------------------------------------------------------------#
2647 template_exception_helpers_start = """\
2648 /* Begin Exception Helper Functions */
2651 template_exception_helpers_end = """\
2653 /* End Exception Helper Functions */
2659 # template for Main delegator for exception handling
2662 template_main_exception_delegator_start = """\
2664 * Main delegator for exception handling
2668 decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2670 proto_tree *tree _U_;
2672 if (!header->exception_id)
2678 # template for exception delegation code body
2680 template_ex_delegate_code = """\
2681 if (strcmp(header->exception_id, "@exname@") == 0) {
2682 tree = start_dissecting(tvb, pinfo, ptree, offset);
2683 decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian); /* @exname@ */
2690 # End of Main delegator for exception handling
2693 template_main_exception_delegator_end = """
2694 return FALSE; /* user exception not found */
2699 # template for exception helper code
2703 template_exception_helper_function_start = """\
2704 /* Exception = @exname@ */
2706 decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2708 proto_item *item _U_;
2711 template_exception_helper_function_end = """\
2717 # template for struct helper code
2721 template_struct_helper_function_start = """\
2722 /* Struct = @stname@ */
2724 decode_@sname@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2728 template_struct_helper_function_end = """\
2733 # template for union helper code
2737 template_union_helper_function_start = """\
2738 /* Union = @unname@ */
2740 decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2742 proto_item* item _U_;
2745 template_union_helper_function_end = """\
2751 #-------------------------------------------------------------#
2752 # Value string templates #
2753 #-------------------------------------------------------------#
2755 template_value_string_start = """\
2756 static const value_string @valstringname@[] = {
2758 template_value_string_entry = """\
2759 { @intval@, \"@description@\" },"""
2761 template_value_string_end = """\
2768 #-------------------------------------------------------------#
2769 # Enum handling templates #
2770 #-------------------------------------------------------------#
2772 template_comment_enums_start = """\
2777 template_comment_enums_end = """\
2782 template_comment_enum_comment = """\
2789 #-------------------------------------------------------------#
2790 # Attribute handling templates #
2791 #-------------------------------------------------------------#
2794 template_comment_attributes_start = """\
2796 * IDL Attributes Start
2801 # get/set accessor method names are language mapping dependant.
2804 template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2805 template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2807 template_comment_attributes_end = """
2809 * IDL Attributes End
2815 # template for Attribute delegation code
2817 # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2818 # Note: _set_xxx() should only be called for Request
2822 template_at_delegate_code_get = """\
2823 if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2824 tree = start_dissecting(tvb, pinfo, ptree, offset);
2825 decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2829 template_at_delegate_code_set = """\
2830 if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
2831 tree = start_dissecting(tvb, pinfo, ptree, offset);
2832 decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2836 template_attribute_helpers_start = """\
2837 /* Begin Attribute Helper Functions */
2839 template_attribute_helpers_end = """\
2841 /* End Attribute Helper Functions */
2845 # template for attribute helper code
2849 template_attribute_helper_function_start = """\
2851 /* Attribute = @atname@ */
2853 decode_@sname@_at(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2855 proto_item* item _U_;
2858 template_attribute_helper_function_end = """\
2863 #-------------------------------------------------------------#
2864 # Debugging templates #
2865 #-------------------------------------------------------------#
2868 # Template for outputting TODO "C" comments
2869 # so user know I need ti improve something.
2872 template_debug_TODO = """\
2874 /* TODO - @message@ */
2877 # Template for outputting WARNING "C" comments
2878 # so user know if I have found a problem.
2881 template_debug_WARNING = """\
2882 /* WARNING - @message@ */
2887 #-------------------------------------------------------------#
2888 # IDL Union templates #
2889 #-------------------------------------------------------------#
2891 template_comment_union_code_start = """\
2893 * IDL Union Start - @uname@
2896 template_comment_union_code_end = """
2898 * IDL union End - @uname@
2901 template_comment_union_code_discriminant = """\
2903 * IDL Union - Discriminant - @uname@
2907 # Cast Unions types to something appropriate
2908 # Enum value cast to guint32, all others cast to gint32
2909 # as omniidl accessor returns integer or Enum.
2912 template_union_code_save_discriminant_enum = """\
2913 disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
2915 template_union_code_save_discriminant_long = """\
2916 disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
2919 template_union_code_save_discriminant_ulong = """\
2920 disc_s_@discname@ = (gint32) u_octet4; /* save guint32 discriminant and cast to gint32 */
2922 template_union_code_save_discriminant_short = """\
2923 disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
2926 template_union_code_save_discriminant_ushort = """\
2927 disc_s_@discname@ = (gint32) u_octet2; /* save guint16 discriminant and cast to gint32 */
2929 template_union_code_save_discriminant_char = """\
2930 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2932 template_union_code_save_discriminant_boolean = """\
2933 disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
2935 template_comment_union_code_label_compare_start = """\
2936 if (disc_s_@discname@ == @labelval@) {
2938 template_comment_union_code_label_compare_end = """\
2939 return; /* End Compare for this discriminant type */
2944 template_comment_union_code_label_default_start = """
2945 /* Default Union Case Start */
2947 template_comment_union_code_label_default_end = """\
2948 /* Default Union Case End */
2952 # Templates for function prototypes.
2953 # This is used in genDeclares() for declaring function prototypes
2954 # for structs and union helper functions.
2957 template_hf_operations = """
2958 static int hf_operationrequest = -1;/* Request_Operation field */
2962 static int hf_@name@ = -1;"""
2964 template_prototype_start_dissecting = """
2965 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
2968 template_prototype_struct_start = """\
2969 /* Struct prototype declaration Start */
2971 template_prototype_struct_end = """\
2972 /* Struct prototype declaration End */
2974 template_prototype_struct_body = """\
2975 /* Struct = @stname@ */
2976 static void decode_@name@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
2978 template_decode_struct = """\
2979 decode_@name@_st(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);"""
2981 template_prototype_union_start = """\
2982 /* Union prototype declaration Start */"""
2984 template_prototype_union_end = """\
2985 /* Union prototype declaration End */"""
2987 template_prototype_union_body = """
2988 /* Union = @unname@ */
2989 static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
2991 template_decode_union = """
2992 decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2996 # Editor modelines - http://www.wireshark.org/tools/modelines.html
3000 # indent-tabs-mode: nil
3003 # vi: set shiftwidth=4 expandtab:
3004 # :indentSize=4:noTabs=true: