Witness: enum witness_interface_state
[metze/wireshark/wip.git] / tools / wireshark_gen.py
1 # -*- python -*-
2 #
3 # $Id$
4 #
5 # wireshark_gen.py (part of idl2wrs)
6 #
7 # Author : Frank Singleton (frank.singleton@ericsson.com)
8 #
9 #    Copyright (C) 2001 Frank Singleton, Ericsson Inc.
10 #
11 #  This file is a backend to "omniidl", used to generate "Wireshark"
12 #  dissectors from CORBA IDL descriptions. The output language generated
13 #  is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
14 #
15 #  Please see packet-giop.h in Wireshark distro for API description.
16 #  Wireshark is available at http://www.wireshark.org/
17 #
18 #  Omniidl is part of the OmniOrb distribution, and is available at
19 #  http://omniorb.sourceforge.net
20 #
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.
25 #
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.
30 #
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
34 #  02111-1307, USA.
35 #
36 # Description:
37 #
38 #   Omniidl Back-end which parses an IDL list of "Operation" nodes
39 #   passed from wireshark_be2.py and generates "C" code for compiling
40 #   as a plugin for the  Wireshark IP Protocol Analyser.
41 #
42 #
43 # Strategy (sneaky but ...)
44 #
45 # problem: I dont know what variables to declare until AFTER the helper functions
46 # have been built, so ...
47 #
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.
52 #
53
54
55 """Wireshark IDL compiler back-end."""
56
57 from omniidl import idlast, idltype, idlutil, output
58 import sys, string
59 import tempfile
60
61 #
62 # Output class, generates "C" src code for the sub-dissector
63 #
64 # in:
65 #
66 #
67 # self - me
68 # st   - output stream
69 # node - a reference to an Operations object.
70 # name - scoped name (Module::Module::Interface:: .. ::Operation
71 #
72
73
74
75 #
76 # TODO -- FS
77 #
78 # 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved]
79 # 2. add item instead of add_text() [done]
80 # 3. sequence handling [done]
81 # 4. User Exceptions [done]
82 # 5. Fix arrays, and structs containing arrays [done]
83 # 6. Handle pragmas.
84 # 7. Exception can be common to many operations, so handle them outside the
85 #    operation helper functions [done]
86 # 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
87 #    For example, mutlidimensional arrays.
88 # 9. wchar and wstring handling [giop API needs improving]
89 # 10. Support Fixed [done]
90 # 11. Support attributes (get/set) [started, needs language mapping option, perhaps wireshark GUI option
91 #     to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
92 #     eg: attribute string apple  =>   _get_apple and _set_apple
93 #
94 # 12. Implement IDL "union" code [done]
95 # 13. Implement support for plugins [done]
96 # 14. Dont generate code for empty operations (cf: exceptions without members)
97 # 15. Generate code to display Enums numerically and symbolically [done]
98 # 16. Place structs/unions in subtrees
99 # 17. Recursive struct and union handling [done]
100 # 18. Improve variable naming for display (eg: structs, unions etc) [done]
101 #
102 # Also test, Test, TEST
103 #
104
105
106
107 #
108 #   Strategy:
109 #    For every operation and attribute do
110 #       For return val and all parameters do
111 #       find basic IDL type for each parameter
112 #       output get_CDR_xxx
113 #       output exception handling code
114 #       output attribute handling code
115 #
116 #
117
118 class wireshark_gen_C:
119
120
121     #
122     # Turn DEBUG stuff on/off
123     #
124
125     DEBUG = 0
126
127     #
128     # Some string constants for our templates
129     #
130     c_u_octet8    = "guint64   u_octet8;"
131     c_s_octet8    = "gint64    s_octet8;"
132     c_u_octet4    = "guint32   u_octet4;"
133     c_s_octet4    = "gint32    s_octet4;"
134     c_u_octet2    = "guint16   u_octet2;"
135     c_s_octet2    = "gint16    s_octet2;"
136     c_u_octet1    = "guint8    u_octet1;"
137     c_s_octet1    = "gint8     s_octet1;"
138
139     c_float       = "gfloat    my_float;"
140     c_double      = "gdouble   my_double;"
141
142     c_seq         = "gchar   *seq = NULL;"          # pointer to buffer of gchars
143     c_i           = "guint32   i_";                 # loop index
144     c_i_lim       = "guint32   u_octet4_loop_";     # loop limit
145     c_u_disc      = "guint32   disc_u_";            # unsigned int union discriminant variable name (enum)
146     c_s_disc      = "gint32    disc_s_";            # signed int union discriminant variable name (other cases, except Enum)
147
148     #
149     # Constructor
150     #
151
152     def __init__(self, st, protocol_name, dissector_name ,description):
153         self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only
154
155         self.st_save = st               # where 2nd pass should go
156         self.protoname = protocol_name  # Protocol Name (eg: ECHO)
157         self.dissname = dissector_name  # Dissector name (eg: echo)
158         self.description = description  # Detailed Protocol description (eg: Echo IDL Example)
159         self.exlist = []                # list of exceptions used in operations.
160         #self.curr_sname                # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
161         self.fn_hash = {}               # top level hash to contain key = function/exception and val = list of variable declarations
162                                         # ie a hash of lists
163         self.fn_hash_built = 0          # flag to indicate the 1st pass is complete, and the fn_hash is correctly
164                                         # populated with operations/vars and exceptions/vars
165
166
167     #
168     # genCode()
169     #
170     # Main entry point, controls sequence of
171     # generated code.
172     #
173     #
174
175     def genCode(self,oplist, atlist, enlist, stlist, unlist):   # operation,attribute,enums,struct and union lists
176
177
178         self.genHelpers(oplist,stlist,unlist)  # sneaky .. call it now, to populate the fn_hash
179                                         # so when I come to that operation later, I have the variables to
180                                         # declare already.
181
182         self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
183                                          # so when I come to that exception later, I have the variables to
184                                          # declare already.
185
186         self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
187                                          # so when I come to that exception later, I have the variables to
188                                          # declare already.
189
190
191         self.fn_hash_built = 1          # DONE, so now I know , see genOperation()
192
193         self.st = self.st_save
194         self.genHeader()                # initial dissector comments
195         self.genEthCopyright()          # Wireshark Copyright comments.
196         self.genGPL()                   # GPL license
197         self.genIncludes()
198         self.genPrototype()
199         self.genProtocol()
200         self.genDeclares(oplist,atlist,enlist,stlist,unlist)
201         if (len(atlist) > 0):
202             self.genAtList(atlist)          # string constant declares for Attributes
203         if (len(enlist) > 0):
204             self.genEnList(enlist)          # string constant declares for Enums
205
206
207         self.genExceptionHelpers(oplist)   # helper function to decode user exceptions that have members
208         self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
209         if (len(atlist) > 0):
210             self.genAttributeHelpers(atlist)   # helper function to decode "attributes"
211
212         self.genHelpers(oplist,stlist,unlist)  # operation, struct and union decode helper functions
213
214         self.genMainEntryStart(oplist)
215         self.genOpDelegator(oplist)
216         self.genAtDelegator(atlist)
217         self.genMainEntryEnd()
218
219         self.gen_proto_register(oplist, atlist, stlist, unlist)
220         self.gen_proto_reg_handoff(oplist)
221         # All the dissectors are now built-in
222         #self.gen_plugin_register()
223
224         #self.dumpvars()                 # debug
225         self.genModelines();
226
227
228
229     #
230     # genHeader
231     #
232     # Generate Standard Wireshark Header Comments
233     #
234     #
235
236     def genHeader(self):
237         self.st.out(self.template_Header,dissector_name=self.dissname)
238         if self.DEBUG:
239             print "XXX genHeader"
240
241
242
243
244     #
245     # genEthCopyright
246     #
247     # Wireshark Copyright Info
248     #
249     #
250
251     def genEthCopyright(self):
252         if self.DEBUG:
253             print "XXX genEthCopyright"
254         self.st.out(self.template_wireshark_copyright)
255
256
257     #
258     # genModelines
259     #
260     # Modelines info
261     #
262     #
263
264     def genModelines(self):
265         if self.DEBUG:
266             print "XXX genModelines"
267
268         self.st.out(self.template_Modelines)
269
270
271     #
272     # genGPL
273     #
274     # GPL license
275     #
276     #
277
278     def genGPL(self):
279         if self.DEBUG:
280             print "XXX genGPL"
281
282         self.st.out(self.template_GPL)
283
284     #
285     # genIncludes
286     #
287     # GPL license
288     #
289     #
290
291     def genIncludes(self):
292         if self.DEBUG:
293             print "XXX genIncludes"
294
295         self.st.out(self.template_Includes)
296
297     #
298     # genOpDeclares()
299     #
300     # Generate hf variables for operation filters
301     #
302     # in: opnode ( an operation node)
303     #
304
305     def genOpDeclares(self, op):
306         if self.DEBUG:
307             print "XXX genOpDeclares"
308             print "XXX return type  = " , op.returnType().kind()
309
310         sname = self.namespace(op, "_")
311         rt = op.returnType()
312
313         if (rt.kind() != idltype.tk_void):
314             if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
315                 #self.get_CDR_alias(rt, rt.name() )
316                 self.st.out(self.template_hf, name=sname + "_return")
317             else:
318                 self.st.out(self.template_hf, name=sname + "_return")
319
320         for p in op.parameters():
321             self.st.out(self.template_hf, name=sname + "_" + p.identifier())
322
323     #
324     # genAtDeclares()
325     #
326     # Generate hf variables for attributes
327     #
328     # in: at ( an attribute)
329     #
330
331     def genAtDeclares(self, at):
332         if self.DEBUG:
333             print "XXX genAtDeclares"
334
335         for decl in at.declarators():
336             sname = self.namespace(decl, "_")
337
338             self.st.out(self.template_hf, name="get" + "_" + sname + "_" + decl.identifier())
339             if not at.readonly():
340                 self.st.out(self.template_hf, name="set" + "_" + sname + "_" + decl.identifier())
341
342     #
343     # genStDeclares()
344     #
345     # Generate hf variables for structs
346     #
347     # in: st ( a struct)
348     #
349
350     def genStDeclares(self, st):
351         if self.DEBUG:
352             print "XXX genStDeclares"
353
354         sname = self.namespace(st, "_")
355
356         for m in st.members():
357             for decl in m.declarators():
358                 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
359
360     #
361     # genExDeclares()
362     #
363     # Generate hf variables for user exception filters
364     #
365     # in: exnode ( an exception node)
366     #
367
368     def genExDeclares(self,ex):
369         if self.DEBUG:
370             print "XXX genExDeclares"
371
372         sname = self.namespace(ex, "_")
373
374         for m in ex.members():
375             for decl in m.declarators():
376                 self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
377
378     #
379     # genUnionDeclares()
380     #
381     # Generate hf variables for union filters
382     #
383     # in: un ( an union)
384     #
385
386     def genUnionDeclares(self,un):
387         if self.DEBUG:
388             print "XXX genUnionDeclares"
389
390         sname = self.namespace(un, "_")
391         self.st.out(self.template_hf, name=sname + "_" + un.identifier())
392
393         for uc in un.cases():           # for all UnionCase objects in this union
394             for cl in uc.labels():      # for all Caselabel objects in this UnionCase
395                 self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
396
397
398     #
399     # genExpertInfoDeclares()
400     #
401     # Generate ei variables for expert info filters
402     #
403
404     def genExpertInfoDeclares(self):
405         if self.DEBUG:
406             print "XXX genExpertInfoDeclares"
407
408         self.st.out(self.template_proto_register_ei_filters, dissector_name=self.dissname)
409
410     #
411     # genDeclares
412     #
413     # generate function prototypes if required
414     #
415     # Currently this is used for struct and union helper function declarations.
416     #
417
418
419     def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
420         if self.DEBUG:
421             print "XXX genDeclares"
422
423         # prototype for operation filters
424         self.st.out(self.template_hf_operations)
425
426         #operation specific filters
427         if (len(oplist) > 0):
428             self.st.out(self.template_proto_register_op_filter_comment)
429         for op in oplist:
430             self.genOpDeclares(op)
431
432         #attribute filters
433         if (len(atlist) > 0):
434             self.st.out(self.template_proto_register_at_filter_comment)
435         for at in atlist:
436             self.genAtDeclares(at)
437
438         #struct filters
439         if (len(stlist) > 0):
440             self.st.out(self.template_proto_register_st_filter_comment)
441         for st in stlist:
442             self.genStDeclares(st)
443
444         # exception List filters
445         exlist = self.get_exceptionList(oplist) # grab list of exception nodes
446         if (len(exlist) > 0):
447             self.st.out(self.template_proto_register_ex_filter_comment)
448         for ex in exlist:
449             if (ex.members()):          # only if has members
450                 self.genExDeclares(ex)
451
452         #union filters
453         if (len(unlist) > 0):
454             self.st.out(self.template_proto_register_un_filter_comment)
455         for un in unlist:
456             self.genUnionDeclares(un)
457
458         #expert info filters
459         self.genExpertInfoDeclares()
460
461         # prototype for start_dissecting()
462
463         self.st.out(self.template_prototype_start_dissecting)
464
465         # struct prototypes
466
467         if len(stlist):
468             self.st.out(self.template_prototype_struct_start)
469             for st in stlist:
470                 #print st.repoId()
471                 sname = self.namespace(st, "_")
472                 self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
473
474             self.st.out(self.template_prototype_struct_end)
475
476         # union prototypes
477         if len(unlist):
478             self.st.out(self.template_prototype_union_start)
479             for un in unlist:
480                 sname = self.namespace(un, "_")
481                 self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
482             self.st.out(self.template_prototype_union_end)
483
484
485     #
486     # genPrototype
487     #
488     #
489
490     def genPrototype(self):
491         self.st.out(self.template_prototype, dissector_name=self.dissname)
492
493     #
494     # genProtocol
495     #
496     #
497
498     def genProtocol(self):
499         self.st.out(self.template_protocol, dissector_name=self.dissname)
500         self.st.out(self.template_init_boundary)
501
502     #
503     # genMainEntryStart
504     #
505
506     def genMainEntryStart(self,oplist):
507         self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
508         self.st.inc_indent()
509         self.st.out(self.template_main_dissector_switch_msgtype_start)
510         self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
511         self.st.inc_indent()
512
513
514     #
515     # genMainEntryEnd
516     #
517
518     def genMainEntryEnd(self):
519
520         self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
521         self.st.dec_indent()
522         self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
523         self.st.dec_indent()
524         self.st.out(self.template_main_dissector_end)
525
526
527     #
528     # genAtList
529     #
530     # in: atlist
531     #
532     # out: C code for IDL attribute decalarations.
533     #
534     # NOTE: Mapping of attributes to  operation(function) names is tricky.
535     #
536     # The actual accessor function names are language-mapping specific. The attribute name
537     # is subject to OMG IDL's name scoping rules; the accessor function names are
538     # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
539     #
540     # eg:
541     #
542     # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
543     # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
544     #
545     # or:
546     #
547     # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
548     # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
549     #
550     # TODO: Implement some language dependant templates to handle naming conventions
551     #       language <=> attribute. for C, C++. Java etc
552     #
553     # OR, just add a runtime GUI option to select language binding for attributes -- FS
554     #
555     #
556     #
557     # ie: def genAtlist(self,atlist,language)
558     #
559
560
561
562     def genAtList(self,atlist):
563         self.st.out(self.template_comment_attributes_start)
564
565         for n in atlist:
566             for i in n.declarators():   #
567                 sname = self.namespace(i, "_")
568                 atname = i.identifier()
569                 self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
570                 if not n.readonly():
571                     self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
572
573         self.st.out(self.template_comment_attributes_end)
574
575
576     #
577     # genEnList
578     #
579     # in: enlist
580     #
581     # out: C code for IDL Enum decalarations using "static const value_string" template
582     #
583
584
585
586     def genEnList(self,enlist):
587
588         self.st.out(self.template_comment_enums_start)
589
590         for enum in enlist:
591             sname = self.namespace(enum, "_")
592
593             self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
594             self.st.out(self.template_value_string_start, valstringname=sname)
595             for enumerator in enum.enumerators():
596                 self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
597
598
599             #atname = n.identifier()
600             self.st.out(self.template_value_string_end, valstringname=sname)
601
602         self.st.out(self.template_comment_enums_end)
603
604
605
606
607
608
609
610
611
612
613     #
614     # genExceptionDelegator
615     #
616     # in: oplist
617     #
618     # out: C code for User exception delegator
619     #
620     # eg:
621     #
622     #
623
624     def genExceptionDelegator(self,oplist):
625
626         self.st.out(self.template_main_exception_delegator_start)
627         self.st.inc_indent()
628
629         exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
630
631         for ex in exlist:
632             if self.DEBUG:
633                 print "XXX Exception " , ex.repoId()
634                 print "XXX Exception Identifier" , ex.identifier()
635                 print "XXX Exception Scoped Name" , ex.scopedName()
636
637             if (ex.members()):          # only if has members
638                 sname = self.namespace(ex, "_")
639                 exname = ex.repoId()
640                 self.st.out(self.template_ex_delegate_code,  sname=sname, exname=ex.repoId())
641
642         self.st.dec_indent()
643         self.st.out(self.template_main_exception_delegator_end)
644
645
646     #
647     # genAttribueHelpers()
648     #
649     # Generate private helper functions to decode Attributes.
650     #
651     # in: atlist
652     #
653     # For readonly attribute - generate get_xxx()
654     # If NOT readonly attribute - also generate set_xxx()
655     #
656
657     def genAttributeHelpers(self,atlist):
658         if self.DEBUG:
659             print "XXX genAttributeHelpers: atlist = ", atlist
660
661         self.st.out(self.template_attribute_helpers_start)
662
663         for attrib in atlist:
664             for decl in attrib.declarators():
665                 self.genAtHelper(attrib,decl,"get") # get accessor
666                 if not attrib.readonly():
667                     self.genAtHelper(attrib,decl,"set") # set accessor
668
669         self.st.out(self.template_attribute_helpers_end)
670
671     #
672     # genAtHelper()
673     #
674     # Generate private helper functions to decode an attribute
675     #
676     # in: at - attribute node
677     # in: decl - declarator belonging to this attribute
678     # in: order - to generate a "get" or "set" helper
679
680     def genAtHelper(self,attrib,decl,order):
681         if self.DEBUG:
682             print "XXX genAtHelper"
683
684         sname = order + "_" + self.namespace(decl, "_")  # must use set or get prefix to avoid collision
685         self.curr_sname = sname                    # update current opnode/exnode scoped name
686
687         if not self.fn_hash_built:
688             self.fn_hash[sname] = []        # init empty list as val for this sname key
689                                             # but only if the fn_hash is not already built
690
691         self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
692         self.st.inc_indent()
693
694         if (len(self.fn_hash[sname]) > 0):
695             self.st.out(self.template_helper_function_vars_start)
696             self.dumpCvars(sname)
697             self.st.out(self.template_helper_function_vars_end )
698
699         self.getCDR(attrib.attrType(), sname + "_" + decl.identifier() )
700
701         self.st.dec_indent()
702         self.st.out(self.template_attribute_helper_function_end)
703
704
705
706     #
707     # genExceptionHelpers()
708     #
709     # Generate private helper functions to decode Exceptions used
710     # within operations
711     #
712     # in: oplist
713     #
714
715
716     def genExceptionHelpers(self,oplist):
717         exlist = self.get_exceptionList(oplist) # grab list of exception nodes
718         if self.DEBUG:
719             print "XXX genExceptionHelpers: exlist = ", exlist
720
721         self.st.out(self.template_exception_helpers_start)
722         for ex in exlist:
723             if (ex.members()):          # only if has members
724                 #print "XXX Exception = " + ex.identifier()
725                 self.genExHelper(ex)
726
727         self.st.out(self.template_exception_helpers_end)
728
729
730     #
731     # genExhelper()
732     #
733     # Generate private helper functions to decode User Exceptions
734     #
735     # in: exnode ( an exception node)
736     #
737
738     def genExHelper(self,ex):
739         if self.DEBUG:
740             print "XXX genExHelper"
741
742         sname = self.namespace(ex, "_")
743         self.curr_sname = sname         # update current opnode/exnode scoped name
744         if not self.fn_hash_built:
745             self.fn_hash[sname] = []        # init empty list as val for this sname key
746                                             # but only if the fn_hash is not already built
747
748         self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
749         self.st.inc_indent()
750
751         if (len(self.fn_hash[sname]) > 0):
752             self.st.out(self.template_helper_function_vars_start)
753             self.dumpCvars(sname)
754             self.st.out(self.template_helper_function_vars_end )
755
756         for m in ex.members():
757             if self.DEBUG:
758                 print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
759
760             for decl in m.declarators():
761                 if self.DEBUG:
762                     print "XXX genExhelper, d = ", decl
763
764                 if decl.sizes():        # an array
765                     indices = self.get_indices_from_sizes(decl.sizes())
766                     string_indices = '%i ' % indices # convert int to string
767                     self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
768                     self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
769                     self.addvar(self.c_i + decl.identifier() + ";")
770
771                     self.st.inc_indent()
772                     self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
773
774                     self.st.dec_indent()
775                     self.st.out(self.template_get_CDR_array_end)
776
777
778                 else:
779                     self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
780
781         self.st.dec_indent()
782         self.st.out(self.template_exception_helper_function_end)
783
784
785     #
786     # genHelpers()
787     #
788     # Generate private helper functions for each IDL operation.
789     # Generate private helper functions for each IDL struct.
790     # Generate private helper functions for each IDL union.
791     #
792     #
793     # in: oplist, stlist, unlist
794     #
795
796
797     def genHelpers(self,oplist,stlist,unlist):
798         for op in oplist:
799             self.genOperation(op)
800         for st in stlist:
801             self.genStructHelper(st)
802         for un in unlist:
803             self.genUnionHelper(un)
804
805     #
806     # genOperation()
807     #
808     # Generate private helper functions for a specificIDL operation.
809     #
810     # in: opnode
811     #
812
813     def genOperation(self,opnode):
814         if self.DEBUG:
815             print "XXX genOperation called"
816
817         sname = self.namespace(opnode, "_")
818         if not self.fn_hash_built:
819             self.fn_hash[sname] = []        # init empty list as val for this sname key
820                                             # but only if the fn_hash is not already built
821
822         self.curr_sname = sname         # update current opnode's scoped name
823         opname = opnode.identifier()
824
825         self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
826
827         self.st.out(self.template_helper_function_start, sname=sname)
828         self.st.inc_indent()
829
830         if (len(self.fn_hash[sname]) > 0):
831             self.st.out(self.template_helper_function_vars_start)
832             self.dumpCvars(sname)
833             self.st.out(self.template_helper_function_vars_end )
834
835         self.st.out(self.template_helper_switch_msgtype_start)
836
837         self.st.out(self.template_helper_switch_msgtype_request_start)
838         self.st.inc_indent()
839         self.genOperationRequest(opnode)
840         self.st.out(self.template_helper_switch_msgtype_request_end)
841         self.st.dec_indent()
842
843         self.st.out(self.template_helper_switch_msgtype_reply_start)
844         self.st.inc_indent()
845
846         self.st.out(self.template_helper_switch_rep_status_start)
847
848
849         self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
850         self.st.inc_indent()
851         self.genOperationReply(opnode)
852         self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
853         self.st.dec_indent()
854
855         self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
856         self.st.inc_indent()
857         self.genOpExceptions(opnode)
858         self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
859         self.st.dec_indent()
860
861         self.st.out(self.template_helper_switch_msgtype_reply_default_start, dissector_name=self.dissname)
862         self.st.out(self.template_helper_switch_msgtype_reply_default_end)
863
864         self.st.out(self.template_helper_switch_rep_status_end)
865
866         self.st.dec_indent()
867
868         self.st.out(self.template_helper_switch_msgtype_default_start, dissector_name=self.dissname)
869         self.st.out(self.template_helper_switch_msgtype_default_end)
870
871         self.st.out(self.template_helper_switch_msgtype_end)
872         self.st.dec_indent()
873
874
875         self.st.out(self.template_helper_function_end, sname=sname)
876
877
878
879
880     #
881     # Decode function parameters for a GIOP request message
882     #
883     #
884
885     def genOperationRequest(self,opnode):
886         for p in opnode.parameters():
887             if p.is_in():
888                 if self.DEBUG:
889                     print "XXX parameter = " ,p
890                     print "XXX parameter type = " ,p.paramType()
891                     print "XXX parameter type kind = " ,p.paramType().kind()
892
893                 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
894
895
896     #
897     # Decode function parameters for a GIOP reply message
898     #
899
900
901     def genOperationReply(self,opnode):
902
903         rt = opnode.returnType()        # get return type
904         if self.DEBUG:
905             print "XXX genOperationReply"
906             print "XXX opnode  = " , opnode
907             print "XXX return type  = " , rt
908             print "XXX return type.unalias  = " , rt.unalias()
909             print "XXX return type.kind()  = " , rt.kind();
910
911         sname = self.namespace(opnode, "_")
912
913         if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
914             #self.getCDR(rt.decl().alias().aliasType(),"dummy")    # return value maybe a typedef
915             self.get_CDR_alias(rt, sname + "_return" )
916             #self.get_CDR_alias(rt, rt.name() )
917
918         else:
919             self.getCDR(rt, sname + "_return")    # return value is NOT an alias
920
921         for p in opnode.parameters():
922             if p.is_out():              # out or inout
923                 self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())
924
925         #self.st.dec_indent()
926
927     def genOpExceptions(self,opnode):
928         for ex in opnode.raises():
929             if ex.members():
930                 #print ex.members()
931                 for m in ex.members():
932                     t=0
933                     #print m.memberType(), m.memberType().kind()
934     #
935     # Delegator for Operations
936     #
937
938     def genOpDelegator(self,oplist):
939         for op in oplist:
940             iname = "/".join(op.scopedName()[:-1])
941             opname = op.identifier()
942             sname = self.namespace(op, "_")
943             self.st.out(self.template_op_delegate_code, interface=iname, sname=sname, opname=opname)
944
945     #
946     # Delegator for Attributes
947     #
948
949     def genAtDelegator(self,atlist):
950         for a in atlist:
951             for i in a.declarators():
952                 atname = i.identifier()
953                 sname = self.namespace(i, "_")
954                 self.st.out(self.template_at_delegate_code_get, sname=sname)
955                 if not a.readonly():
956                     self.st.out(self.template_at_delegate_code_set, sname=sname)
957
958
959     #
960     # Add a variable declaration to the hash of list
961     #
962
963     def addvar(self, var):
964         if not ( var in self.fn_hash[self.curr_sname] ):
965             self.fn_hash[self.curr_sname].append(var)
966
967     #
968     # Print the variable declaration from  the hash of list
969     #
970
971
972     def dumpvars(self):
973         for fn in self.fn_hash.keys():
974             print "FN = " + fn
975             for v in self.fn_hash[fn]:
976                 print "-> " + v
977     #
978     # Print the "C" variable declaration from  the hash of list
979     # for a given scoped operation name (eg: tux_penguin_eat)
980     #
981
982
983     def dumpCvars(self, sname):
984         for v in self.fn_hash[sname]:
985             self.st.out(v)
986
987
988     #
989     # Given an enum node, and a enumerator node, return
990     # the enumerator's numerical value.
991     #
992     # eg: enum Color {red,green,blue} should return
993     # val = 1 for green
994     #
995
996     def valFromEnum(self,enumNode, enumeratorNode):
997         if self.DEBUG:
998             print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
999             print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
1000
1001         if isinstance(enumeratorNode,idlast.Enumerator):
1002             value = enumNode.enumerators().index(enumeratorNode)
1003             return value
1004
1005
1006 ## tk_null               = 0
1007 ## tk_void               = 1
1008 ## tk_short              = 2
1009 ## tk_long               = 3
1010 ## tk_ushort             = 4
1011 ## tk_ulong              = 5
1012 ## tk_float              = 6
1013 ## tk_double             = 7
1014 ## tk_boolean            = 8
1015 ## tk_char               = 9
1016 ## tk_octet              = 10
1017 ## tk_any                = 11
1018 ## tk_TypeCode           = 12
1019 ## tk_Principal          = 13
1020 ## tk_objref             = 14
1021 ## tk_struct             = 15
1022 ## tk_union              = 16
1023 ## tk_enum               = 17
1024 ## tk_string             = 18
1025 ## tk_sequence           = 19
1026 ## tk_array              = 20
1027 ## tk_alias              = 21
1028 ## tk_except             = 22
1029 ## tk_longlong           = 23
1030 ## tk_ulonglong          = 24
1031 ## tk_longdouble         = 25
1032 ## tk_wchar              = 26
1033 ## tk_wstring            = 27
1034 ## tk_fixed              = 28
1035 ## tk_value              = 29
1036 ## tk_value_box          = 30
1037 ## tk_native             = 31
1038 ## tk_abstract_interface = 32
1039
1040
1041     #
1042     # getCDR()
1043     #
1044     # This is the main "iterator" function. It takes a node, and tries to output
1045     # a get_CDR_XXX accessor method(s). It can call itself multiple times
1046     # if I find nested structures etc.
1047     #
1048
1049     def getCDR(self,type,name="fred"):
1050
1051         pt = type.unalias().kind()      # param CDR type
1052         pn = name                       # param name
1053
1054         if self.DEBUG:
1055             print "XXX getCDR: kind = " , pt
1056             print "XXX getCDR: name = " , pn
1057
1058         if pt == idltype.tk_ulong:
1059             self.get_CDR_ulong(pn)
1060         elif pt == idltype.tk_longlong:
1061             self.get_CDR_longlong(pn)
1062         elif pt == idltype.tk_ulonglong:
1063             self.get_CDR_ulonglong(pn)
1064         elif pt ==  idltype.tk_void:
1065             self.get_CDR_void(pn)
1066         elif pt ==  idltype.tk_short:
1067             self.get_CDR_short(pn)
1068         elif pt ==  idltype.tk_long:
1069             self.get_CDR_long(pn)
1070         elif pt ==  idltype.tk_ushort:
1071             self.get_CDR_ushort(pn)
1072         elif pt ==  idltype.tk_float:
1073             self.get_CDR_float(pn)
1074         elif pt ==  idltype.tk_double:
1075             self.get_CDR_double(pn)
1076         elif pt == idltype.tk_fixed:
1077             self.get_CDR_fixed(type.unalias(),pn)
1078         elif pt ==  idltype.tk_boolean:
1079             self.get_CDR_boolean(pn)
1080         elif pt ==  idltype.tk_char:
1081             self.get_CDR_char(pn)
1082         elif pt ==  idltype.tk_octet:
1083             self.get_CDR_octet(pn)
1084         elif pt ==  idltype.tk_any:
1085             self.get_CDR_any(pn)
1086         elif pt ==  idltype.tk_string:
1087             self.get_CDR_string(pn)
1088         elif pt ==  idltype.tk_wstring:
1089             self.get_CDR_wstring(pn)
1090         elif pt ==  idltype.tk_wchar:
1091             self.get_CDR_wchar(pn)
1092         elif pt ==  idltype.tk_enum:
1093             #print type.decl()
1094             self.get_CDR_enum(pn,type)
1095             #self.get_CDR_enum(pn)
1096
1097         elif pt ==  idltype.tk_struct:
1098             self.get_CDR_struct(type,pn)
1099         elif pt ==  idltype.tk_TypeCode: # will I ever get here ?
1100             self.get_CDR_TypeCode(pn)
1101         elif pt == idltype.tk_sequence:
1102             if type.unalias().seqType().kind() == idltype.tk_octet:
1103                 self.get_CDR_sequence_octet(type,pn)
1104             else:
1105                 self.get_CDR_sequence(type,pn)
1106         elif pt == idltype.tk_objref:
1107             self.get_CDR_objref(type,pn)
1108         elif pt == idltype.tk_array:
1109             pn = pn # Supported elsewhere
1110         elif pt == idltype.tk_union:
1111             self.get_CDR_union(type,pn)
1112         elif pt == idltype.tk_alias:
1113             if self.DEBUG:
1114                 print "XXXXX Alias type XXXXX " , type
1115             self.get_CDR_alias(type,pn)
1116         else:
1117             self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1118
1119
1120     #
1121     # get_CDR_XXX methods are here ..
1122     #
1123     #
1124
1125
1126     def get_CDR_ulong(self,pn):
1127         self.st.out(self.template_get_CDR_ulong, hfname=pn)
1128
1129     def get_CDR_short(self,pn):
1130         self.st.out(self.template_get_CDR_short, hfname=pn)
1131
1132     def get_CDR_void(self,pn):
1133         self.st.out(self.template_get_CDR_void, hfname=pn)
1134
1135     def get_CDR_long(self,pn):
1136         self.st.out(self.template_get_CDR_long, hfname=pn)
1137
1138     def get_CDR_ushort(self,pn):
1139         self.st.out(self.template_get_CDR_ushort, hfname=pn)
1140
1141     def get_CDR_float(self,pn):
1142         self.st.out(self.template_get_CDR_float, hfname=pn)
1143
1144     def get_CDR_double(self,pn):
1145         self.st.out(self.template_get_CDR_double, hfname=pn)
1146
1147     def get_CDR_longlong(self,pn):
1148         self.st.out(self.template_get_CDR_longlong, hfname=pn)
1149
1150     def get_CDR_ulonglong(self,pn):
1151         self.st.out(self.template_get_CDR_ulonglong, hfname=pn)
1152
1153     def get_CDR_boolean(self,pn):
1154         self.st.out(self.template_get_CDR_boolean, hfname=pn)
1155
1156     def get_CDR_fixed(self,type,pn):
1157         if self.DEBUG:
1158             print "XXXX calling get_CDR_fixed, type = ", type
1159             print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
1160             print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()
1161
1162         string_digits = '%i ' % type.digits() # convert int to string
1163         string_scale  = '%i ' % type.scale()  # convert int to string
1164         string_length  = '%i ' % self.dig_to_len(type.digits())  # how many octets to hilight for a number of digits
1165
1166         self.st.out(self.template_get_CDR_fixed, varname=pn, digits=string_digits, scale=string_scale, length=string_length )
1167         self.addvar(self.c_seq)
1168
1169
1170     def get_CDR_char(self,pn):
1171         self.st.out(self.template_get_CDR_char, hfname=pn)
1172
1173     def get_CDR_octet(self,pn):
1174         self.st.out(self.template_get_CDR_octet, hfname=pn)
1175
1176     def get_CDR_any(self,pn):
1177         self.st.out(self.template_get_CDR_any, varname=pn)
1178
1179     def get_CDR_enum(self,pn,type):
1180         #self.st.out(self.template_get_CDR_enum, hfname=pn)
1181         sname = self.namespace(type.unalias(), "_")
1182         self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname,hfname=pn)
1183         self.addvar(self.c_u_octet4)
1184
1185     def get_CDR_string(self,pn):
1186         self.st.out(self.template_get_CDR_string, hfname=pn)
1187
1188     def get_CDR_wstring(self,pn):
1189         self.st.out(self.template_get_CDR_wstring, varname=pn)
1190         self.addvar(self.c_u_octet4)
1191         self.addvar(self.c_seq)
1192
1193     def get_CDR_wchar(self,pn):
1194         self.st.out(self.template_get_CDR_wchar, varname=pn)
1195         self.addvar(self.c_s_octet1)
1196         self.addvar(self.c_seq)
1197
1198     def get_CDR_TypeCode(self,pn):
1199         self.st.out(self.template_get_CDR_TypeCode, varname=pn)
1200         self.addvar(self.c_u_octet4)
1201
1202     def get_CDR_objref(self,type,pn):
1203         self.st.out(self.template_get_CDR_object)
1204
1205     def get_CDR_sequence_len(self,pn):
1206         self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1207
1208
1209     def get_CDR_union(self,type,pn):
1210         if self.DEBUG:
1211             print "XXX Union type =" , type, " pn = ",pn
1212             print "XXX Union type.decl()" , type.decl()
1213             print "XXX Union Scoped Name" , type.scopedName()
1214
1215        #  If I am a typedef union {..}; node then find the union node
1216
1217         if isinstance(type.decl(), idlast.Declarator):
1218             ntype = type.decl().alias().aliasType().decl()
1219         else:
1220             ntype = type.decl()         # I am a union node
1221
1222         if self.DEBUG:
1223             print "XXX Union ntype =" , ntype
1224
1225         sname = self.namespace(ntype, "_")
1226         self.st.out(self.template_union_start, name=sname )
1227
1228         # Output a call to the union helper function so I can handle recursive union also.
1229
1230         self.st.out(self.template_decode_union,name=sname)
1231
1232         self.st.out(self.template_union_end, name=sname )
1233
1234     #
1235     # getCDR_hf()
1236     #
1237     # This takes a node, and tries to output the appropriate item for the
1238     # hf array.
1239     #
1240
1241     def getCDR_hf(self,type,desc,filter,hf_name="fred"):
1242
1243         pt = type.unalias().kind()      # param CDR type
1244         pn = hf_name                       # param name
1245
1246         if self.DEBUG:
1247             print "XXX getCDR_hf: kind = " , pt
1248             print "XXX getCDR_hf: name = " , pn
1249
1250         if pt == idltype.tk_ulong:
1251             self.get_CDR_ulong_hf(pn, desc, filter, self.dissname)
1252         elif pt == idltype.tk_longlong:
1253             self.get_CDR_longlong_hf(pn, desc, filter, self.dissname)
1254         elif pt == idltype.tk_ulonglong:
1255             self.get_CDR_ulonglong_hf(pn, desc, filter, self.dissname)
1256         elif pt == idltype.tk_void:
1257             pt = pt   # no hf_ variables needed
1258         elif pt ==  idltype.tk_short:
1259             self.get_CDR_short_hf(pn, desc, filter, self.dissname)
1260         elif pt ==  idltype.tk_long:
1261             self.get_CDR_long_hf(pn, desc, filter, self.dissname)
1262         elif pt ==  idltype.tk_ushort:
1263             self.get_CDR_ushort_hf(pn, desc, filter, self.dissname)
1264         elif pt ==  idltype.tk_float:
1265             self.get_CDR_float_hf(pn, desc, filter, self.dissname)
1266         elif pt ==  idltype.tk_double:
1267             self.get_CDR_double_hf(pn, desc, filter, self.dissname)
1268         elif pt == idltype.tk_fixed:
1269             pt = pt   # no hf_ variables needed
1270         elif pt ==  idltype.tk_boolean:
1271             self.get_CDR_boolean_hf(pn, desc, filter, self.dissname)
1272         elif pt ==  idltype.tk_char:
1273             self.get_CDR_char_hf(pn, desc, filter, self.dissname)
1274         elif pt ==  idltype.tk_octet:
1275             self.get_CDR_octet_hf(pn, desc, filter, self.dissname)
1276         elif pt ==  idltype.tk_any:
1277             pt = pt   # no hf_ variables needed
1278         elif pt ==  idltype.tk_string:
1279             self.get_CDR_string_hf(pn, desc, filter, self.dissname)
1280         elif pt ==  idltype.tk_wstring:
1281             self.get_CDR_wstring_hf(pn, desc, filter, self.dissname)
1282         elif pt ==  idltype.tk_wchar:
1283             self.get_CDR_wchar_hf(pn, desc, filter, self.dissname)
1284         elif pt ==  idltype.tk_enum:
1285             self.get_CDR_enum_hf(pn, type, desc, filter, self.dissname)
1286         elif pt ==  idltype.tk_struct:
1287             pt = pt   # no hf_ variables needed (should be already contained in struct members)
1288         elif pt ==  idltype.tk_TypeCode: # will I ever get here ?
1289             self.get_CDR_TypeCode_hf(pn, desc, filter, self.dissname)
1290         elif pt == idltype.tk_sequence:
1291             if type.unalias().seqType().kind() == idltype.tk_octet:
1292                 self.get_CDR_sequence_octet_hf(type, pn, desc, filter, self.dissname)
1293             else:
1294                 self.get_CDR_sequence_hf(type, pn, desc, filter, self.dissname)
1295         elif pt == idltype.tk_objref:
1296             pt = pt   # no object specific hf_ variables used, use generic ones from giop dissector
1297         elif pt == idltype.tk_array:
1298             pt = pt   # Supported elsewhere
1299         elif pt == idltype.tk_union:
1300             pt = pt   # no hf_ variables needed (should be already contained in union members)
1301         elif pt == idltype.tk_alias:
1302             if self.DEBUG:
1303                 print "XXXXX Alias type hf XXXXX " , type
1304             self.get_CDR_alias_hf(type,pn)
1305         else:
1306             self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
1307
1308     #
1309     # get_CDR_XXX_hf methods are here ..
1310     #
1311     #
1312
1313
1314     def get_CDR_ulong_hf(self,pn,desc,filter,diss):
1315         self.st.out(self.template_get_CDR_ulong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1316
1317     def get_CDR_short_hf(self,pn,desc,filter,diss):
1318         self.st.out(self.template_get_CDR_short_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1319
1320     def get_CDR_long_hf(self,pn,desc,filter,diss):
1321         self.st.out(self.template_get_CDR_long_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1322
1323     def get_CDR_ushort_hf(self,pn,desc,filter,diss):
1324         self.st.out(self.template_get_CDR_ushort_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1325
1326     def get_CDR_float_hf(self,pn,desc,filter,diss):
1327         self.st.out(self.template_get_CDR_float_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1328
1329     def get_CDR_double_hf(self,pn,desc,filter,diss):
1330         self.st.out(self.template_get_CDR_double_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1331
1332     def get_CDR_longlong_hf(self,pn,desc,filter,diss):
1333         self.st.out(self.template_get_CDR_longlong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1334
1335     def get_CDR_ulonglong_hf(self,pn,desc,filter,diss):
1336         self.st.out(self.template_get_CDR_ulonglong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1337
1338     def get_CDR_boolean_hf(self,pn,desc,filter,diss):
1339         self.st.out(self.template_get_CDR_boolean_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1340
1341     def get_CDR_char_hf(self,pn,desc,filter,diss):
1342         self.st.out(self.template_get_CDR_char_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1343
1344     def get_CDR_octet_hf(self,pn,desc,filter,diss):
1345         self.st.out(self.template_get_CDR_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1346
1347     def get_CDR_enum_hf(self,pn,type,desc,filter,diss):
1348         sname = self.namespace(type.unalias(), "_")
1349         self.st.out(self.template_get_CDR_enum_symbolic_hf, valstringarray=sname,hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1350
1351     def get_CDR_string_hf(self,pn,desc,filter,diss):
1352         self.st.out(self.template_get_CDR_string_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1353
1354     def get_CDR_wstring_hf(self,pn,desc,filter,diss):
1355         self.st.out(self.template_get_CDR_wstring_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1356 #        self.addvar(self.c_u_octet4)
1357 #        self.addvar(self.c_seq)
1358
1359     def get_CDR_wchar_hf(self,pn,desc,filter,diss):
1360         self.st.out(self.template_get_CDR_wchar_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1361 #        self.addvar(self.c_s_octet1)
1362 #        self.addvar(self.c_seq)
1363
1364     def get_CDR_TypeCode_hf(self,pn,desc,filter,diss):
1365         self.st.out(self.template_get_CDR_TypeCode_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1366
1367     def get_CDR_sequence_octet_hf(self,type,pn,desc,filter,diss):
1368         self.st.out(self.template_get_CDR_sequence_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1369
1370     def get_CDR_sequence_hf(self,type,pn,desc,filter,diss):
1371         self.st.out(self.template_get_CDR_sequence_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
1372
1373     def get_CDR_alias_hf(self,type,pn):
1374         if self.DEBUG:
1375             print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1376             print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1377             print "XXX get_CDR_alias_hf, type.decl().alias() = " ,type.decl().alias()
1378
1379         decl = type.decl()              # get declarator object
1380
1381         if (decl.sizes()):        # a typedef array
1382             #indices = self.get_indices_from_sizes(decl.sizes())
1383             #string_indices = '%i ' % indices # convert int to string
1384             #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1385
1386             #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1387             #self.addvar(self.c_i + pn + ";")
1388             #self.st.inc_indent()
1389             self.getCDR_hf(type.decl().alias().aliasType(),  pn )
1390
1391             #self.st.dec_indent()
1392             #self.st.out(self.template_get_CDR_array_end)
1393
1394
1395         else:                           # a simple typdef
1396             if self.DEBUG:
1397                 print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
1398                 print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
1399
1400             self.getCDR_hf(type, decl.identifier() )
1401
1402
1403     #
1404     # Code to generate Union Helper functions
1405     #
1406     # in: un - a union node
1407     #
1408     #
1409
1410
1411     def genUnionHelper(self,un):
1412         if self.DEBUG:
1413             print "XXX genUnionHelper called"
1414             print "XXX Union type =" , un
1415             print "XXX Union type.switchType()" , un.switchType()
1416             print "XXX Union Scoped Name" , un.scopedName()
1417
1418         sname = self.namespace(un, "_")
1419         self.curr_sname = sname         # update current opnode/exnode/stnode/unnode scoped name
1420         if not self.fn_hash_built:
1421             self.fn_hash[sname] = []        # init empty list as val for this sname key
1422                                             # but only if the fn_hash is not already built
1423
1424         self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
1425         self.st.inc_indent()
1426
1427         if (len(self.fn_hash[sname]) > 0):
1428             self.st.out(self.template_helper_function_vars_start)
1429             self.dumpCvars(sname)
1430             self.st.out(self.template_helper_function_vars_end )
1431
1432         st = un.switchType().unalias() # may be typedef switch type, so find real type
1433
1434         self.st.out(self.template_comment_union_code_start, uname=un.repoId() )
1435
1436         self.getCDR(st, sname + "_" + un.identifier());
1437
1438         # Depending on what kind of discriminant I come accross (enum,integer,char,
1439         # short, boolean), make sure I cast the return value of the get_XXX accessor
1440         # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
1441         # return an integer, or an Enumerator object that is then converted to its
1442         # integer equivalent.
1443         #
1444         #
1445         # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
1446         #
1447
1448         if (st.kind() == idltype.tk_enum):
1449             std = st.decl()
1450             self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
1451             self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
1452             self.addvar(self.c_s_disc + un.identifier() + ";")
1453
1454         elif (st.kind() == idltype.tk_long):
1455             self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
1456             self.addvar(self.c_s_disc + un.identifier() + ";")
1457
1458         elif (st.kind() == idltype.tk_ulong):
1459             self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
1460             self.addvar(self.c_s_disc + un.identifier() + ";")
1461
1462         elif (st.kind() == idltype.tk_short):
1463             self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
1464             self.addvar(self.c_s_disc + un.identifier() + ";")
1465
1466         elif (st.kind() == idltype.tk_ushort):
1467             self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
1468             self.addvar(self.c_s_disc + un.identifier() + ";")
1469
1470         elif (st.kind() == idltype.tk_boolean):
1471             self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier()  )
1472             self.addvar(self.c_s_disc + un.identifier() + ";")
1473
1474         elif (st.kind() == idltype.tk_char):
1475             self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
1476             self.addvar(self.c_s_disc + un.identifier() + ";")
1477
1478         else:
1479             print "XXX Unknown st.kind() = ", st.kind()
1480
1481         #
1482         # Loop over all cases in this union
1483         #
1484
1485         for uc in un.cases():           # for all UnionCase objects in this union
1486             for cl in uc.labels():      # for all Caselabel objects in this UnionCase
1487
1488                 # get integer value, even if discriminant is
1489                 # an Enumerator node
1490
1491                 if isinstance(cl.value(),idlast.Enumerator):
1492                     if self.DEBUG:
1493                         print "XXX clv.identifier()", cl.value().identifier()
1494                         print "XXX clv.repoId()", cl.value().repoId()
1495                         print "XXX clv.scopedName()", cl.value().scopedName()
1496
1497                     # find index of enumerator in enum declaration
1498                     # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
1499
1500                     clv = self.valFromEnum(std,cl.value())
1501
1502                 else:
1503                     clv = cl.value()
1504
1505                 #print "XXX clv = ",clv
1506
1507                 #
1508                 # if char, dont convert to int, but put inside single quotes so that it is understood by C.
1509                 # eg: if (disc == 'b')..
1510                 #
1511                 # TODO : handle \xxx chars generically from a function or table lookup rather than
1512                 #        a whole bunch of "if" statements. -- FS
1513
1514
1515                 if (st.kind() == idltype.tk_char):
1516                     if (clv == '\n'):          # newline
1517                         string_clv = "'\\n'"
1518                     elif (clv == '\t'):        # tab
1519                         string_clv = "'\\t'"
1520                     else:
1521                         string_clv = "'" + clv + "'"
1522                 else:
1523                     string_clv = '%i ' % clv
1524
1525                 #
1526                 # If default case, then skp comparison with discriminator
1527                 #
1528
1529                 if not cl.default():
1530                     self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
1531                     self.st.inc_indent()
1532                 else:
1533                     self.st.out(self.template_comment_union_code_label_default_start  )
1534
1535
1536                 self.getCDR(uc.caseType(),sname + "_" + uc.declarator().identifier())
1537
1538                 if not cl.default():
1539                     self.st.dec_indent()
1540                     self.st.out(self.template_comment_union_code_label_compare_end )
1541                 else:
1542                     self.st.out(self.template_comment_union_code_label_default_end  )
1543
1544         self.st.dec_indent()
1545         self.st.out(self.template_union_helper_function_end)
1546
1547
1548
1549     #
1550     # Currently, get_CDR_alias is geared to finding typdef
1551     #
1552
1553     def get_CDR_alias(self,type,pn):
1554         if self.DEBUG:
1555             print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1556             print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1557             print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()
1558
1559         decl = type.decl()              # get declarator object
1560
1561         if (decl.sizes()):        # a typedef array
1562             indices = self.get_indices_from_sizes(decl.sizes())
1563             string_indices = '%i ' % indices # convert int to string
1564             self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)
1565
1566             self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
1567             self.addvar(self.c_i + pn + ";")
1568             self.st.inc_indent()
1569             self.getCDR(type.decl().alias().aliasType(),  pn )
1570
1571             self.st.dec_indent()
1572             self.st.out(self.template_get_CDR_array_end)
1573
1574
1575         else:                           # a simple typdef
1576             if self.DEBUG:
1577                 print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
1578                 print "XXX get_CDR_alias, type.decl() = " ,type.decl()
1579
1580             self.getCDR(type, pn )
1581
1582
1583
1584
1585
1586
1587     #
1588     # Handle structs, including recursive
1589     #
1590
1591     def get_CDR_struct(self,type,pn):
1592
1593         #  If I am a typedef struct {..}; node then find the struct node
1594
1595         if isinstance(type.decl(), idlast.Declarator):
1596             ntype = type.decl().alias().aliasType().decl()
1597         else:
1598             ntype = type.decl()         # I am a struct node
1599
1600         sname = self.namespace(ntype, "_")
1601         self.st.out(self.template_structure_start, name=sname )
1602
1603         # Output a call to the struct helper function so I can handle recursive structs also.
1604
1605         self.st.out(self.template_decode_struct,name=sname)
1606
1607         self.st.out(self.template_structure_end, name=sname )
1608
1609     #
1610     # genStructhelper()
1611     #
1612     # Generate private helper functions to decode a struct
1613     #
1614     # in: stnode ( a struct node)
1615     #
1616
1617     def genStructHelper(self,st):
1618         if self.DEBUG:
1619             print "XXX genStructHelper"
1620
1621         sname = self.namespace(st, "_")
1622         self.curr_sname = sname         # update current opnode/exnode/stnode scoped name
1623         if not self.fn_hash_built:
1624             self.fn_hash[sname] = []        # init empty list as val for this sname key
1625                                             # but only if the fn_hash is not already built
1626
1627         self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
1628         self.st.inc_indent()
1629
1630         if (len(self.fn_hash[sname]) > 0):
1631             self.st.out(self.template_helper_function_vars_start)
1632             self.dumpCvars(sname)
1633             self.st.out(self.template_helper_function_vars_end )
1634
1635         for m in st.members():
1636             for decl in m.declarators():
1637                 if decl.sizes():        # an array
1638                     indices = self.get_indices_from_sizes(decl.sizes())
1639                     string_indices = '%i ' % indices # convert int to string
1640                     self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
1641                     self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
1642                     self.addvar(self.c_i + decl.identifier() + ";")
1643
1644                     self.st.inc_indent()
1645                     self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1646                     self.st.dec_indent()
1647                     self.st.out(self.template_get_CDR_array_end)
1648
1649
1650                 else:
1651                     self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
1652
1653         self.st.dec_indent()
1654         self.st.out(self.template_struct_helper_function_end)
1655
1656
1657
1658
1659
1660     #
1661     # Generate code to access a sequence of a type
1662     #
1663
1664
1665     def get_CDR_sequence(self,type, pn):
1666         self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
1667         self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
1668         self.addvar(self.c_i_lim + pn + ";" )
1669         self.addvar(self.c_i + pn + ";")
1670
1671         self.st.inc_indent()
1672         self.getCDR(type.unalias().seqType(), pn ) # and start all over with the type
1673         self.st.dec_indent()
1674
1675         self.st.out(self.template_get_CDR_sequence_loop_end)
1676
1677
1678     #
1679     # Generate code to access a sequence of octet
1680     #
1681
1682     def get_CDR_sequence_octet(self,type, pn):
1683         self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
1684         self.st.out(self.template_get_CDR_sequence_octet, seqname=pn)
1685         self.addvar(self.c_i_lim + pn + ";")
1686         self.addvar("gchar * binary_seq_" + pn + ";")
1687         self.addvar("gchar * text_seq_" + pn + ";")
1688
1689
1690    #
1691    # namespace()
1692    #
1693    # in - op node
1694    #
1695    # out - scoped operation name, using sep character instead of "::"
1696    #
1697    # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
1698    #
1699    #
1700
1701     def namespace(self,node,sep):
1702         sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
1703         #print "XXX namespace: sname = " + sname
1704         return sname
1705
1706
1707     #
1708     # generate code for plugin initialisation
1709     #
1710
1711     def gen_plugin_register(self):
1712         self.st.out(self.template_plugin_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1713
1714     #
1715     # generate  register_giop_user_module code, and register only
1716     # unique interfaces that contain operations. Also output
1717     # a heuristic register in case we want to use that.
1718     #
1719     # TODO - make this a command line option
1720     #
1721     # -e explicit
1722     # -h heuristic
1723     #
1724
1725
1726
1727     def gen_proto_reg_handoff(self, oplist):
1728
1729         self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
1730         self.st.inc_indent()
1731
1732         for iname in self.get_intlist(oplist):
1733             self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )
1734
1735         self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname,  protocol_name=self.protoname)
1736         self.st.dec_indent()
1737
1738         self.st.out(self.template_proto_reg_handoff_end)
1739
1740     #
1741     # generate hf_ array element for operation, attribute, enums, struct and union lists
1742     #
1743
1744     def genOp_hf(self,op):
1745         sname = self.namespace(op, "_")
1746         opname = sname[string.find(sname, "_")+1:]
1747         opname = opname[:string.find(opname, "_")]
1748         rt = op.returnType()
1749
1750         if (rt.kind() != idltype.tk_void):
1751             if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
1752                 self.getCDR_hf(rt, rt.name(),\
1753                     opname + "." + op.identifier() + ".return", sname + "_return")
1754             else:
1755                 self.getCDR_hf(rt, "Return value",\
1756                     opname + "." + op.identifier() + ".return", sname + "_return")
1757
1758         for p in op.parameters():
1759             self.getCDR_hf(p.paramType(), p.identifier(),\
1760                 opname + "." + op.identifier() + "." + p.identifier(), sname + "_" + p.identifier())
1761
1762     def genAt_hf(self,at):
1763         for decl in at.declarators():
1764             sname = self.namespace(decl, "_")
1765             atname = sname[string.find(sname, "_")+1:]
1766             atname = atname[:string.find(atname, "_")]
1767
1768             self.getCDR_hf(at.attrType(), decl.identifier(),\
1769                      atname + "." + decl.identifier() + ".get", "get" + "_" + sname + "_" + decl.identifier())
1770             if not at.readonly():
1771                 self.getCDR_hf(at.attrType(), decl.identifier(),\
1772                     atname + "." + decl.identifier() + ".set", "set" + "_" + sname + "_" + decl.identifier())
1773
1774     def genSt_hf(self,st):
1775         sname = self.namespace(st, "_")
1776         stname = sname[string.find(sname, "_")+1:]
1777         stname = stname[:string.find(stname, "_")]
1778         for m in st.members():
1779             for decl in m.declarators():
1780                 self.getCDR_hf(m.memberType(), st.identifier() + "_" + decl.identifier(),\
1781                         st.identifier() + "." + decl.identifier(), sname + "_" + decl.identifier())
1782
1783     def genEx_hf(self,ex):
1784         sname = self.namespace(ex, "_")
1785         exname = sname[string.find(sname, "_")+1:]
1786         exname = exname[:string.find(exname, "_")]
1787         for m in ex.members():
1788             for decl in m.declarators():
1789                 self.getCDR_hf(m.memberType(), ex.identifier() + "_" + decl.identifier(),\
1790                         exname + "." + ex.identifier() + "_" + decl.identifier(), sname + "_" + decl.identifier())
1791
1792     def genUnion_hf(self,un):
1793         sname = self.namespace(un, "_")
1794         unname = sname[:string.rfind(sname, "_")]
1795         unname = string.replace(unname, "_", ".")
1796
1797         self.getCDR_hf(un.switchType().unalias(), un.identifier(),\
1798                 unname + "." + un.identifier(), sname + "_" + un.identifier())
1799
1800         for uc in un.cases():           # for all UnionCase objects in this union
1801             for cl in uc.labels():      # for all Caselabel objects in this UnionCase
1802                 self.getCDR_hf(uc.caseType(), un.identifier() + "_" + uc.declarator().identifier(),\
1803                       unname + "." + un.identifier() + "." + uc.declarator().identifier(),\
1804                       sname + "_" + uc.declarator().identifier())
1805
1806     #
1807     # generate  proto_register_<protoname> code,
1808     #
1809     # in - oplist[], atlist[], stline[], unlist[]
1810     #
1811
1812
1813     def gen_proto_register(self, oplist, atlist, stlist, unlist):
1814         self.st.out(self.template_proto_register_start, dissector_name=self.dissname)
1815
1816         #operation specific filters
1817         self.st.out(self.template_proto_register_op_filter_comment)
1818         for op in oplist:
1819             self.genOp_hf(op)
1820
1821         #attribute filters
1822         self.st.out(self.template_proto_register_at_filter_comment)
1823         for at in atlist:
1824             self.genAt_hf(at)
1825
1826         #struct filters
1827         self.st.out(self.template_proto_register_st_filter_comment)
1828         for st in stlist:
1829             if (st.members()):          # only if has members
1830                 self.genSt_hf(st)
1831
1832         # exception List filters
1833         exlist = self.get_exceptionList(oplist) # grab list of exception nodes
1834         self.st.out(self.template_proto_register_ex_filter_comment)
1835         for ex in exlist:
1836             if (ex.members()):          # only if has members
1837                 self.genEx_hf(ex)
1838
1839         # Union filters
1840         self.st.out(self.template_proto_register_un_filter_comment)
1841         for un in unlist:
1842             self.genUnion_hf(un)
1843
1844         self.st.out(self.template_proto_register_end, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
1845
1846
1847     #
1848     # in - oplist[]
1849     #
1850     # out - a list of unique interface names. This will be used in
1851     # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" );   so the operation
1852     # name must be removed from the scope. And we also only want unique interfaces.
1853     #
1854
1855     def get_intlist(self,oplist):
1856         int_hash = {}                   # holds a hash of unique interfaces
1857         for op in oplist:
1858             sc = op.scopedName()        # eg: penguin,tux,bite
1859             sc1 = sc[:-1]               # drop last entry
1860             sn = idlutil.slashName(sc1)         # penguin/tux
1861             if not int_hash.has_key(sn):
1862                 int_hash[sn] = 0;       # dummy val, but at least key is unique
1863         ret = int_hash.keys()
1864         ret.sort()
1865         return ret
1866
1867
1868
1869     #
1870     # in - oplist[]
1871     #
1872     # out - a list of exception nodes (unique). This will be used in
1873     # to generate dissect_exception_XXX functions.
1874     #
1875
1876
1877
1878     def get_exceptionList(self,oplist):
1879         ex_hash = {}                   # holds a hash of unique exceptions.
1880         for op in oplist:
1881             for ex in op.raises():
1882                 if not ex_hash.has_key(ex):
1883                     ex_hash[ex] = 0; # dummy val, but at least key is unique
1884                     if self.DEBUG:
1885                         print "XXX Exception = " + ex.identifier()
1886         ret = ex_hash.keys()
1887         ret.sort()
1888         return ret
1889
1890
1891
1892     #
1893     # Simple function to take a list of array sizes and find the
1894     # total number of elements
1895     #
1896     #
1897     # eg: temp[4][3] = 12 elements
1898     #
1899
1900     def get_indices_from_sizes(self,sizelist):
1901         val = 1;
1902         for i in sizelist:
1903             val = val * i
1904
1905         return val
1906
1907     #
1908     # Determine how many octets contain requested number
1909     # of digits for an "fixed" IDL type  "on the wire"
1910     #
1911
1912     def dig_to_len(self,dignum):
1913         return (dignum/2) + 1
1914
1915
1916
1917     #
1918     # Output some TODO comment
1919     #
1920
1921
1922     def genTODO(self,message):
1923         self.st.out(self.template_debug_TODO, message=message)
1924
1925     #
1926     # Output some WARNING comment
1927     #
1928
1929
1930     def genWARNING(self,message):
1931         self.st.out(self.template_debug_WARNING, message=message)
1932
1933     #
1934     # Templates for C code
1935     #
1936
1937     template_helper_function_comment = """\
1938 /*
1939  * @repoid@
1940  */"""
1941     template_helper_function_vars_start = """\
1942 /* Operation specific Variable declarations Begin */"""
1943
1944     template_helper_function_vars_end = """\
1945 /* Operation specific Variable declarations End */
1946
1947 (void)item; /* Avoid coverity param_set_but_unused parse warning */
1948 """
1949
1950     template_helper_function_start = """\
1951 static void
1952 decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
1953 {"""
1954
1955     template_helper_function_end = """\
1956 }
1957 """
1958     #
1959     # proto_reg_handoff() templates
1960     #
1961
1962     template_proto_reg_handoff_start = """\
1963 /* register me as handler for these interfaces */
1964 void proto_reg_handoff_giop_@dissector_name@(void)
1965 {"""
1966
1967     template_proto_reg_handoff_body = """\
1968 /* Register for Explicit Dissection */
1969 register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ );     /* explicit dissector */
1970 """
1971
1972     template_proto_reg_handoff_heuristic = """\
1973 /* Register for Heuristic Dissection */
1974 register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@);     /* heuristic dissector */
1975 """
1976
1977     template_proto_reg_handoff_end = """\
1978 }
1979 """
1980
1981     #
1982     # Prototype
1983     #
1984
1985     template_prototype = """
1986 void proto_register_giop_@dissector_name@(void);
1987 void proto_reg_handoff_giop_@dissector_name@(void);"""
1988
1989     #
1990     # Initialize the protocol
1991     #
1992
1993     template_protocol = """
1994 /* Initialise the protocol and subtree pointers */
1995 static int proto_@dissector_name@ = -1;
1996 static gint ett_@dissector_name@ = -1;
1997 """
1998     #
1999     # Initialize the boundary Alignment
2000     #
2001
2002     template_init_boundary = """
2003 /* Initialise the initial Alignment */
2004 static guint32  boundary = GIOP_HEADER_SIZE;  /* initial value */"""
2005
2006     #
2007     # plugin_register and plugin_reg_handoff templates
2008     #
2009
2010     template_plugin_register = """
2011 #if 0
2012
2013 WS_DLL_PUBLIC_DEF void
2014 plugin_register(void)
2015 {
2016     if (proto_@dissector_name@ == -1) {
2017         proto_register_giop_@dissector_name@();
2018     }
2019 }
2020
2021 WS_DLL_PUBLIC_DEF void
2022 plugin_reg_handoff(void){
2023     proto_register_handoff_giop_@dissector_name@();
2024 }
2025 #endif
2026 """
2027     #
2028     # proto_register_<dissector name>(void) templates
2029     #
2030
2031     template_proto_register_start = """
2032 /* Register the protocol with Wireshark */
2033 void proto_register_giop_@dissector_name@(void)
2034 {
2035     /* setup list of header fields */
2036     static hf_register_info hf[] = {
2037         /* field that indicates the currently ongoing request/reply exchange */
2038             {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2039
2040     template_proto_register_end = """
2041     };
2042
2043     static ei_register_info ei[] = {
2044         { &ei_@dissector_name@_unknown_giop_msg, { "giop-@dissector_name@.unknown_giop_msg", PI_PROTOCOL, PI_WARN, "Unknown GIOP message", EXPFILL }},
2045         { &ei_@dissector_name@_unknown_exception, { "giop-@dissector_name@.unknown_exception", PI_PROTOCOL, PI_WARN, "Unknown exception", EXPFILL }},
2046         { &ei_@dissector_name@_unknown_reply_status, { "giop-@dissector_name@.unknown_reply_status", PI_PROTOCOL, PI_WARN, "Unknown reply status", EXPFILL }},
2047     };
2048
2049     /* setup protocol subtree array */
2050
2051     static gint *ett[] = {
2052         &ett_@dissector_name@,
2053     };
2054
2055     expert_module_t* expert_@dissector_name@;
2056
2057
2058     /* Register the protocol name and description */
2059     proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
2060     proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
2061     proto_register_subtree_array(ett, array_length(ett));
2062
2063     expert_@dissector_name@ = expert_register_protocol(proto_@dissector_name@);
2064     expert_register_field_array(expert_@dissector_name@, ei, array_length(ei));
2065 }
2066 """
2067
2068     template_proto_register_op_filter_comment = """\
2069         /* Operation filters */"""
2070
2071     template_proto_register_at_filter_comment = """\
2072         /* Attribute filters */"""
2073
2074     template_proto_register_st_filter_comment = """\
2075         /* Struct filters */"""
2076
2077     template_proto_register_ex_filter_comment = """\
2078         /* User exception filters */"""
2079
2080     template_proto_register_un_filter_comment = """\
2081         /* Union filters */"""
2082
2083     template_proto_register_ei_filters = """\
2084         /* Expert info filters */
2085 static expert_field ei_@dissector_name@_unknown_giop_msg = EI_INIT;
2086 static expert_field ei_@dissector_name@_unknown_exception = EI_INIT;
2087 static expert_field ei_@dissector_name@_unknown_reply_status = EI_INIT;
2088 """
2089
2090     #
2091     # template for delegation code
2092     #
2093
2094     template_op_delegate_code = """\
2095 if (strcmp(operation, "@opname@") == 0
2096     && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
2097     item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
2098     tree = start_dissecting(tvb, pinfo, ptree, offset);
2099     decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
2100     return TRUE;
2101 }
2102 """
2103     #
2104     # Templates for the helper functions
2105     #
2106     #
2107     #
2108
2109     template_helper_switch_msgtype_start = """\
2110 switch(header->message_type) {"""
2111
2112     template_helper_switch_msgtype_default_start = """\
2113 default:
2114     /* Unknown GIOP Message */
2115     expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2116
2117     template_helper_switch_msgtype_default_end = """\
2118 break;"""
2119
2120     template_helper_switch_msgtype_end = """\
2121 } /* switch(header->message_type) */"""
2122
2123     template_helper_switch_msgtype_request_start = """\
2124 case Request:"""
2125
2126     template_helper_switch_msgtype_request_end = """\
2127 break;"""
2128
2129     template_helper_switch_msgtype_reply_start = """\
2130 case Reply:"""
2131
2132     template_helper_switch_msgtype_reply_no_exception_start = """\
2133 case NO_EXCEPTION:"""
2134
2135     template_helper_switch_msgtype_reply_no_exception_end = """\
2136 break;"""
2137
2138     template_helper_switch_msgtype_reply_user_exception_start = """\
2139 case USER_EXCEPTION:"""
2140
2141     template_helper_switch_msgtype_reply_user_exception_end = """\
2142 break;"""
2143
2144     template_helper_switch_msgtype_reply_default_start = """\
2145 default:
2146     /* Unknown Exception */
2147     expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_exception, "Unknown exception %d", header->rep_status);"""
2148
2149     template_helper_switch_msgtype_reply_default_end = """\
2150     break;"""
2151
2152     template_helper_switch_msgtype_reply_end = """\
2153 break;"""
2154
2155     template_helper_switch_msgtype_default_start = """\
2156 default:
2157     /* Unknown GIOP Message */
2158     expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""
2159
2160     template_helper_switch_msgtype_default_end = """\
2161     break;"""
2162
2163     template_helper_switch_rep_status_start = """\
2164 switch(header->rep_status) {"""
2165
2166     template_helper_switch_rep_status_default_start = """\
2167 default:
2168     /* Unknown Reply Status */
2169     expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_reply_status, "Unknown reply status %d", header->rep_status);"""
2170
2171     template_helper_switch_rep_status_default_end = """\
2172     break;"""
2173
2174     template_helper_switch_rep_status_end = """\
2175 }   /* switch(header->rep_status) */
2176
2177 break;"""
2178
2179     #
2180     # Templates for get_CDR_xxx accessors
2181     #
2182
2183     template_get_CDR_ulong = """\
2184 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
2185 """
2186     template_get_CDR_short = """\
2187 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
2188 """
2189     template_get_CDR_void = """\
2190 /* Function returns void */
2191 """
2192     template_get_CDR_long = """\
2193 proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
2194 """
2195     template_get_CDR_ushort = """\
2196 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
2197 """
2198     template_get_CDR_float = """\
2199 proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
2200 """
2201     template_get_CDR_double = """\
2202 proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
2203 """
2204     template_get_CDR_longlong = """\
2205 proto_tree_add_int64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
2206 """
2207     template_get_CDR_ulonglong = """\
2208 proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
2209 """
2210     template_get_CDR_boolean = """\
2211 proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
2212 """
2213     template_get_CDR_char = """\
2214 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
2215 """
2216     template_get_CDR_octet = """\
2217 proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
2218 """
2219     template_get_CDR_any = """\
2220 get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
2221 """
2222     template_get_CDR_fixed = """\
2223 get_CDR_fixed(tvb, pinfo, item, &seq, offset, @digits@, @scale@);
2224 proto_tree_add_text(tree,tvb,*offset-@length@, @length@, "@varname@ < @digits@, @scale@> = %s",seq);
2225 """
2226     template_get_CDR_enum_symbolic = """\
2227 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
2228 /* coverity[returned_pointer] */
2229 item = proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
2230 """
2231     template_get_CDR_string = """\
2232 giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, hf_@hfname@);
2233 """
2234     template_get_CDR_wstring = """\
2235 u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
2236 proto_tree_add_text(tree,tvb,*offset-u_octet4,u_octet4,"@varname@ (%u) = %s",
2237       u_octet4, (u_octet4 > 0) ? seq : \"\");
2238 """
2239     template_get_CDR_wchar = """\
2240 s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
2241 if (tree) {
2242     if (s_octet1 > 0)
2243         proto_tree_add_text(tree,tvb,*offset-1-s_octet1,1,"length = %u",s_octet1);
2244
2245     if (s_octet1 < 0)
2246         s_octet1 = -s_octet1;
2247
2248     if (s_octet1 > 0)
2249         proto_tree_add_text(tree,tvb,*offset-s_octet1,s_octet1,"@varname@ = %s",seq);
2250 }
2251 """
2252     template_get_CDR_TypeCode = """\
2253 u_octet4 = get_CDR_typeCode(tvb, pinfo, tree, offset, stream_is_big_endian, boundary, header);
2254 """
2255
2256     template_get_CDR_object = """\
2257 get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
2258 """
2259
2260     template_get_CDR_sequence_length = """\
2261 u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
2262 /* coverity[returned_pointer] */
2263 item = proto_tree_add_uint(tree, hf_@seqname@, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
2264 """
2265     template_get_CDR_sequence_loop_start = """\
2266 for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
2267 """
2268     template_get_CDR_sequence_loop_end = """\
2269 }
2270 """
2271
2272     template_get_CDR_sequence_octet = """\
2273 if (u_octet4_loop_@seqname@ > 0 && tree) {
2274     get_CDR_octet_seq(tvb, &binary_seq_@seqname@, offset,
2275         u_octet4_loop_@seqname@);
2276     text_seq_@seqname@ = make_printable_string(binary_seq_@seqname@,
2277         u_octet4_loop_@seqname@);
2278     proto_tree_add_text(tree, tvb, *offset - u_octet4_loop_@seqname@,
2279         u_octet4_loop_@seqname@, \"@seqname@: %s\", text_seq_@seqname@);
2280 }
2281 """
2282     template_get_CDR_array_start = """\
2283 for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
2284 """
2285     template_get_CDR_array_end = """\
2286 }
2287 """
2288     template_get_CDR_array_comment = """\
2289 /* Array: @aname@[ @asize@]  */
2290 """
2291     template_structure_start = """\
2292 /*  Begin struct \"@name@\"  */"""
2293
2294     template_structure_end = """\
2295 /*  End struct \"@name@\"  */"""
2296
2297     template_union_start = """\
2298 /*  Begin union \"@name@\"  */"""
2299
2300     template_union_end = """\
2301 /*  End union \"@name@\"  */"""
2302
2303     #
2304     # Templates for get_CDR_xxx_hf accessors
2305     #
2306
2307     template_get_CDR_ulong_hf = """\
2308         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2309
2310     template_get_CDR_short_hf = """\
2311         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2312
2313     template_get_CDR_long_hf = """\
2314         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2315
2316     template_get_CDR_ushort_hf = """\
2317         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2318
2319     template_get_CDR_float_hf = """\
2320         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2321
2322     template_get_CDR_double_hf = """\
2323         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2324
2325     template_get_CDR_longlong_hf = """\
2326         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2327
2328     template_get_CDR_ulonglong_hf = """\
2329         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2330
2331     template_get_CDR_boolean_hf = """\
2332         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""
2333
2334     template_get_CDR_char_hf = """\
2335         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2336
2337     template_get_CDR_octet_hf = """\
2338         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2339
2340     template_get_CDR_enum_symbolic_hf = """\
2341         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""
2342
2343     template_get_CDR_string_hf = """\
2344         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2345
2346     template_get_CDR_wstring_hf = """\
2347         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""
2348
2349     template_get_CDR_wchar_hf = """\
2350         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2351
2352     template_get_CDR_TypeCode_hf = """\
2353         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2354
2355     template_get_CDR_sequence_hf = """\
2356         {&hf_@hfname@, {"Seq length of @descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""
2357
2358     template_get_CDR_sequence_octet_hf = """\
2359         {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""
2360
2361 #
2362 # Program Header Template
2363 #
2364
2365     template_Header = """\
2366 /* packet-@dissector_name@.c
2367  *
2368  * $Id$
2369  *
2370  * Routines for IDL dissection
2371  *
2372  * Autogenerated from idl2wrs
2373  * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
2374  */
2375
2376 """
2377
2378     template_wireshark_copyright = """\
2379 /*
2380  * Wireshark - Network traffic analyzer
2381  * By Gerald Combs
2382  * Copyright 1999 - 2012 Gerald Combs
2383  */
2384 """
2385
2386
2387
2388 #
2389 # GPL Template
2390 #
2391
2392
2393     template_GPL = """\
2394 /*
2395  * This program is free software; you can redistribute it and/or
2396  * modify it under the terms of the GNU General Public License
2397  * as published by the Free Software Foundation; either version 2
2398  * of the License, or (at your option) any later version.
2399  *
2400  * This program is distributed in the hope that it will be useful,
2401  * but WITHOUT ANY WARRANTY; without even the implied warranty of
2402  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2403  * GNU General Public License for more details.
2404  *
2405  * You should have received a copy of the GNU General Public License
2406  * along with this program; if not, write to the Free Software
2407  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2408  */
2409 """
2410
2411 #
2412 # Modelines Template
2413 #
2414
2415
2416     template_Modelines = """\
2417 /*
2418  * Editor modelines
2419  *
2420  * Local Variables:
2421  * c-basic-offset: 4
2422  * tab-width: 8
2423  * indent-tabs-mode: nil
2424  * End:
2425  *
2426  * ex: set shiftwidth=4 tabstop=8 expandtab:
2427  * :indentSize=4:tabSize=8:noTabs=true:
2428  */"""
2429
2430 #
2431 # Includes template
2432 #
2433
2434     template_Includes = """\
2435
2436 #include "config.h"
2437
2438 #include <gmodule.h>
2439
2440 #include <string.h>
2441 #include <glib.h>
2442 #include <epan/packet.h>
2443 #include <epan/proto.h>
2444 #include <epan/dissectors/packet-giop.h>
2445 #include <epan/expert.h>
2446
2447 #ifdef _MSC_VER
2448 /* disable warning: "unreference local variable" */
2449 #pragma warning(disable:4101)
2450 #endif
2451
2452 #if defined(__GNUC__)
2453 #pragma GCC diagnostic ignored "-Wunused-function"
2454 #pragma GCC diagnostic ignored "-Wunused-variable"
2455 #endif"""
2456
2457
2458 #
2459 # Main dissector entry templates
2460 #
2461
2462     template_main_dissector_start = """\
2463 /*
2464  * Called once we accept the packet as being for us; it sets the
2465  * Protocol and Info columns and creates the top-level protocol
2466  * tree item.
2467  */
2468 static proto_tree *
2469 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
2470 {
2471
2472     proto_item *ti = NULL;
2473     proto_tree *tree = NULL;            /* init later, inside if(tree) */
2474
2475     col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");
2476
2477     /*
2478      * Do not clear COL_INFO, as nothing is being written there by
2479      * this dissector yet. So leave it as is from the GIOP dissector.
2480      * TODO: add something useful to COL_INFO
2481      *     col_clear(pinfo->cinfo, COL_INFO);
2482      */
2483
2484     if (ptree) {
2485         ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, -1, ENC_NA);
2486         tree = proto_item_add_subtree(ti, ett_@dissname@);
2487     }
2488     return tree;
2489 }
2490
2491 static proto_item*
2492 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const gchar *operation)
2493 {
2494     proto_item *pi;
2495     if(header->message_type == Reply) {
2496         /* fill-up info column */
2497         col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
2498     }
2499     /* fill-up the field */
2500     pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
2501     PROTO_ITEM_SET_GENERATED(pi);
2502     return pi;
2503 }
2504
2505 static gboolean
2506 dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const gchar *operation, gchar *idlname)
2507 {
2508     proto_item *item _U_;
2509     proto_tree *tree _U_;
2510     gboolean stream_is_big_endian = is_big_endian(header); /* get endianess */
2511
2512     /* If we have a USER Exception, then decode it and return */
2513     if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
2514        return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
2515     }
2516 """
2517
2518     template_main_dissector_switch_msgtype_start = """\
2519 switch(header->message_type) {
2520 """
2521     template_main_dissector_switch_msgtype_start_request_reply = """\
2522 case Request:
2523 case Reply:
2524 """
2525     template_main_dissector_switch_msgtype_end_request_reply = """\
2526 break;
2527 """
2528     template_main_dissector_switch_msgtype_all_other_msgtype = """\
2529 case CancelRequest:
2530 case LocateRequest:
2531 case LocateReply:
2532 case CloseConnection:
2533 case MessageError:
2534 case Fragment:
2535    return FALSE;      /* not handled yet */
2536
2537 default:
2538    return FALSE;      /* not handled yet */
2539
2540 }   /* switch */
2541 """
2542     template_main_dissector_end = """\
2543
2544     return FALSE;
2545
2546 }  /* End of main dissector  */
2547 """
2548
2549
2550
2551
2552
2553
2554
2555 #-------------------------------------------------------------#
2556 #             Exception handling templates                    #
2557 #-------------------------------------------------------------#
2558
2559
2560
2561
2562
2563
2564
2565     template_exception_helpers_start = """\
2566 /*  Begin Exception Helper Functions  */
2567
2568 """
2569     template_exception_helpers_end = """\
2570
2571 /*  End Exception Helper Functions  */
2572 """
2573
2574
2575
2576 #
2577 # template for Main delegator for exception handling
2578 #
2579
2580     template_main_exception_delegator_start = """\
2581 /*
2582  * Main delegator for exception handling
2583  *
2584  */
2585 static gboolean
2586 decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2587 {
2588     proto_tree *tree _U_;
2589
2590     if (!header->exception_id)
2591         return FALSE;
2592 """
2593
2594
2595 #
2596 # template for exception delegation code body
2597 #
2598     template_ex_delegate_code = """\
2599 if (strcmp(header->exception_id, "@exname@") == 0) {
2600     tree = start_dissecting(tvb, pinfo, ptree, offset);
2601     decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);   /*  @exname@  */
2602     return TRUE;
2603 }
2604 """
2605
2606
2607 #
2608 # End of Main delegator for exception handling
2609 #
2610
2611     template_main_exception_delegator_end = """
2612     return FALSE;    /* user exception not found */
2613 }
2614 """
2615
2616 #
2617 # template for exception helper code
2618 #
2619
2620
2621     template_exception_helper_function_start = """\
2622 /* Exception = @exname@ */
2623 static void
2624 decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2625 {
2626     proto_item *item _U_;
2627 """
2628
2629     template_exception_helper_function_end = """\
2630 }
2631 """
2632
2633
2634 #
2635 # template for struct helper code
2636 #
2637
2638
2639     template_struct_helper_function_start = """\
2640 /* Struct = @stname@ */
2641 static void
2642 decode_@sname@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2643 {
2644 """
2645
2646     template_struct_helper_function_end = """\
2647 }
2648 """
2649
2650 #
2651 # template for union helper code
2652 #
2653
2654
2655     template_union_helper_function_start = """\
2656 /* Union = @unname@ */
2657 static void
2658 decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2659 {
2660     proto_item* item _U_;
2661 """
2662
2663     template_union_helper_function_end = """\
2664 }
2665 """
2666
2667
2668
2669 #-------------------------------------------------------------#
2670 #             Value string  templates                         #
2671 #-------------------------------------------------------------#
2672
2673     template_value_string_start = """\
2674 static const value_string @valstringname@[] = {
2675 """
2676     template_value_string_entry = """\
2677     { @intval@, \"@description@\" },"""
2678
2679     template_value_string_end = """\
2680     { 0,       NULL },
2681 };
2682 """
2683
2684
2685
2686 #-------------------------------------------------------------#
2687 #             Enum   handling templates                       #
2688 #-------------------------------------------------------------#
2689
2690     template_comment_enums_start = """\
2691 /*
2692  * IDL Enums Start
2693  */
2694 """
2695     template_comment_enums_end = """\
2696 /*
2697  * IDL Enums End
2698  */
2699 """
2700     template_comment_enum_comment = """\
2701 /*
2702  * Enum = @ename@
2703  */"""
2704
2705
2706
2707 #-------------------------------------------------------------#
2708 #             Attribute handling templates                    #
2709 #-------------------------------------------------------------#
2710
2711
2712     template_comment_attributes_start = """\
2713 /*
2714  * IDL Attributes Start
2715  */
2716 """
2717
2718     #
2719     # get/set accessor method names are language mapping dependant.
2720     #
2721
2722     template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
2723     template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
2724
2725     template_comment_attributes_end = """
2726 /*
2727  * IDL Attributes End
2728  */
2729 """
2730
2731
2732     #
2733     # template for Attribute delegation code
2734     #
2735     # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
2736     # Note: _set_xxx() should only be called for Request
2737     #
2738     #
2739
2740     template_at_delegate_code_get = """\
2741 if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
2742     tree = start_dissecting(tvb, pinfo, ptree, offset);
2743     decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2744     return TRUE;
2745 }
2746 """
2747     template_at_delegate_code_set = """\
2748 if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
2749     tree = start_dissecting(tvb, pinfo, ptree, offset);
2750     decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2751     return TRUE;
2752 }
2753 """
2754     template_attribute_helpers_start = """\
2755 /*  Begin Attribute Helper Functions  */
2756 """
2757     template_attribute_helpers_end = """\
2758
2759 /*  End Attribute Helper Functions  */
2760 """
2761
2762 #
2763 # template for attribute helper code
2764 #
2765
2766
2767     template_attribute_helper_function_start = """\
2768
2769 /* Attribute = @atname@ */
2770 static void
2771 decode_@sname@_at(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
2772 {
2773     proto_item* item _U_;
2774 """
2775
2776     template_attribute_helper_function_end = """\
2777 }
2778 """
2779
2780
2781 #-------------------------------------------------------------#
2782 #                     Debugging  templates                    #
2783 #-------------------------------------------------------------#
2784
2785     #
2786     # Template for outputting TODO "C" comments
2787     # so user know I need ti improve something.
2788     #
2789
2790     template_debug_TODO = """\
2791
2792 /* TODO - @message@ */
2793 """
2794     #
2795     # Template for outputting WARNING "C" comments
2796     # so user know if I have found a problem.
2797     #
2798
2799     template_debug_WARNING = """\
2800 /* WARNING - @message@ */
2801 """
2802
2803
2804
2805 #-------------------------------------------------------------#
2806 #                     IDL Union  templates                    #
2807 #-------------------------------------------------------------#
2808
2809     template_comment_union_code_start = """\
2810 /*
2811  * IDL Union Start - @uname@
2812  */
2813 """
2814     template_comment_union_code_end = """
2815 /*
2816  * IDL union End - @uname@
2817  */
2818 """
2819     template_comment_union_code_discriminant = """\
2820 /*
2821  * IDL Union - Discriminant - @uname@
2822  */
2823 """
2824     #
2825     # Cast Unions types to something appropriate
2826     # Enum value cast to guint32, all others cast to gint32
2827     # as omniidl accessor returns integer or Enum.
2828     #
2829
2830     template_union_code_save_discriminant_enum = """\
2831 disc_s_@discname@ = (gint32) u_octet4;     /* save Enum Value  discriminant and cast to gint32 */
2832 """
2833     template_union_code_save_discriminant_long = """\
2834 disc_s_@discname@ = (gint32) s_octet4;     /* save gint32 discriminant and cast to gint32 */
2835 """
2836
2837     template_union_code_save_discriminant_ulong = """\
2838 disc_s_@discname@ = (gint32) u_octet4;     /* save guint32 discriminant and cast to gint32 */
2839 """
2840     template_union_code_save_discriminant_short = """\
2841 disc_s_@discname@ = (gint32) s_octet2;     /* save gint16 discriminant and cast to gint32 */
2842 """
2843
2844     template_union_code_save_discriminant_ushort = """\
2845 disc_s_@discname@ = (gint32) u_octet2;     /* save guint16 discriminant and cast to gint32 */
2846 """
2847     template_union_code_save_discriminant_char = """\
2848 disc_s_@discname@ = (gint32) u_octet1;     /* save guint1 discriminant and cast to gint32 */
2849 """
2850     template_union_code_save_discriminant_boolean = """\
2851 disc_s_@discname@ = (gint32) u_octet1;     /* save guint1 discriminant and cast to gint32 */
2852 """
2853     template_comment_union_code_label_compare_start = """\
2854 if (disc_s_@discname@ == @labelval@) {
2855 """
2856     template_comment_union_code_label_compare_end = """\
2857     return;     /* End Compare for this discriminant type */
2858 }
2859 """
2860
2861
2862     template_comment_union_code_label_default_start = """
2863 /* Default Union Case Start */
2864 """
2865     template_comment_union_code_label_default_end = """\
2866 /* Default Union Case End */
2867 """
2868
2869     #
2870     # Templates for function prototypes.
2871     # This is used in genDeclares() for declaring function prototypes
2872     # for structs and union helper functions.
2873     #
2874
2875     template_hf_operations = """
2876 static int hf_operationrequest = -1;/* Request_Operation field */
2877 """
2878
2879     template_hf = """\
2880 static int hf_@name@ = -1;"""
2881
2882     template_prototype_start_dissecting = """
2883 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
2884
2885 """
2886     template_prototype_struct_start = """\
2887 /* Struct prototype declaration Start */
2888 """
2889     template_prototype_struct_end = """\
2890 /* Struct prototype declaration End */
2891 """
2892     template_prototype_struct_body = """\
2893 /* Struct = @stname@ */
2894 static void decode_@name@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
2895 """
2896     template_decode_struct = """\
2897 decode_@name@_st(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);"""
2898
2899     template_prototype_union_start = """\
2900 /* Union prototype declaration Start */"""
2901
2902     template_prototype_union_end = """\
2903 /* Union prototype declaration End */"""
2904
2905     template_prototype_union_body = """
2906 /* Union = @unname@ */
2907 static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
2908 """
2909     template_decode_union = """
2910 decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
2911 """
2912
2913 #
2914 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
2915 #
2916 # Local variables:
2917 # c-basic-offset: 4
2918 # indent-tabs-mode: nil
2919 # End:
2920 #
2921 # vi: set shiftwidth=4 expandtab:
2922 # :indentSize=4:noTabs=true:
2923 #