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