# -*- python -*-
#
-# $Id: ethereal_gen.py,v 1.3 2001/06/27 20:41:16 guy Exp $
-#
+# $Id: ethereal_gen.py,v 1.11 2001/08/11 04:37:31 guy Exp $
#
# ethereal_gen.py (part of idl2eth)
#
# Copyright (C) 2001 Frank Singleton, Ericsson Inc.
#
# This file is a backend to "omniidl", used to generate "Ethereal"
-# dissectors from IDL descriptions. The output language generated
+# dissectors from CORBA IDL descriptions. The output language generated
# is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
#
# Please see packet-giop.h in Ethereal distro for API description.
# 1. generate hf[] data for searchable fields (but what is searchable?)
# 2. add item instead of add_text()
# 3. sequence handling [done]
-# 4. Exceptions
-# 5. Fix arrays, and structs containing arrays [started]
+# 4. User Exceptions [done]
+# 5. Fix arrays, and structs containing arrays [done]
# 6. Handle pragmas.
# 7. Exception can be common to many operations, so handle them outside the
-# operation helper functions.
-# 8. Automatic variable declaration [done, improve]
-# 9. wchar and wstring handling
-# 10. Support Fixed [started]
-# 11. Support attributes (get/set)
+# operation helper functions [done]
+# 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
+# For example, mutlidimensional arrays.
+# 9. wchar and wstring handling [giop API needs improving]
+# 10. Support Fixed [done]
+# 11. Support attributes (get/set) [started, needs language mapping option, perhaps ethereal GUI option
+# to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
+# eg: attribute string apple => _get_apple and _set_apple
+#
+# 12. Implement IDL "union" code [done]
+# 13. Implement support for plugins [done]
+# 14. Dont generate code for empty operations (cf: exceptions without members)
+#
+# Also test, Test, TEST
+#
# find basic IDL type for each parameter
# output get_CDR_xxx
# output exception handling code
+# output attribute handling code
#
#
c_seq = "gchar *seq = NULL;" # pointer to buffer of gchars
c_i = "guint32 i_"; # loop index
c_i_lim = "guint32 u_octet4_loop_"; # loop limit
+ c_u_disc = "guint32 disc_u_"; # unsigned int union discriminant variable name (enum)
+ c_s_disc = "gint32 disc_s_"; # signed int union discriminant variable name (other cases, except Enum)
#
# Constructor
self.dissname = dissector_name # Dissector name (eg: echo)
self.description = description # Detailed Protocol description (eg: Echo IDL Example)
self.exlist = [] # list of exceptions used in operations.
- #self.curr_sname # scoped name of current opnode I am visiting, used for generating "C" var declares
- self.fn_hash = {} # top level hash to contain function and a key = list of variable declarations
+ #self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
+ self.fn_hash = {} # top level hash to contain key = function/exception and val = list of variable declarations
# ie a hash of lists
- self.fn_hash_built = 0 # flag to indicate the ist pass is complete, and the fn_hash is correctly
- # populated.
+ self.fn_hash_built = 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
+ # populated with operations/vars and exceptions/vars
#
#
#
- def genCode(self,oplist):
+ def genCode(self,oplist, atlist): # operation and attribute lists
self.genHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
- # so when I come to that function later, I have the variables to
+ # so when I come to that operation later, I have the variables to
# declare already.
+
+ self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
+ # so when I come to that exception later, I have the variables to
+ # declare already.
+
+ self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
+ # so when I come to that exception later, I have the variables to
+ # declare already.
+
+
self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
self.st = self.st_save
self.genHeader() # initial dissector comments
+ self.genEthCopyright() # Ethereal Copyright comments.
self.genGPL() # GPL license
self.genIncludes()
self.genDeclares(oplist)
self.genProtocol()
self.genRegisteredFields()
- self.genOpList(oplist)
+ self.genOpList(oplist) # string constant declares for operation names
+ self.genExList(oplist) # string constant declares for user exceptions
+ self.genAtList(atlist) # string constant declares for Attributes
+
+
+ self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
+ self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
+ self.genAttributeHelpers(atlist) # helper function to decode "attributes"
- self.genExceptionHelpers(oplist)
self.genHelpers(oplist)
self.genMainEntryStart(oplist)
- self.genDelegator(oplist)
+ self.genOpDelegator(oplist)
+ self.genAtDelegator(atlist)
self.genMainEntryEnd()
self.gen_proto_register()
self.gen_proto_reg_handoff(oplist)
+ self.gen_plugin_init()
#self.dumpvars() # debug
if self.DEBUG:
print "XXX genHeader"
+
+
+
+ #
+ # genEthCopyright
+ #
+ # Ethereal Copyright Info
+ #
+ #
+
+ def genEthCopyright(self):
+ if self.DEBUG:
+ print "XXX genEthCopyright"
+ self.st.out(self.template_ethereal_copyright)
+
+
#
# genGPL
#
self.st.out(self.template_comment_operations_end)
+ #
+ # genExList
+ #
+ # in: oplist
+ #
+ # out: C code for IDL User Exceptions that contain members
+ #
+ # eg:
+ #
+ # static const char user_exception_tux_bad_value[] = "IDL:tux/bad_value:1.0" ;
+ #
+
+ def genExList(self,oplist):
+
+ self.st.out(self.template_comment_user_exceptions_string_declare_start)
+
+ exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
+
+ for ex in exlist:
+ if self.DEBUG:
+ print "XXX Exception " , ex.repoId()
+ print "XXX Exception Identifier" , ex.identifier()
+ print "XXX Exception Scoped Name" , ex.scopedName()
+
+ if (ex.members()): # only if has members
+ sname = self.namespace(ex, "_")
+ exname = ex.repoId()
+ self.st.out(self.template_user_exceptions_declare, sname=sname, exname=ex.repoId())
+
+ self.st.out(self.template_comment_user_exceptions_string_declare_end)
+
+ #
+ # genAtList
+ #
+ # in: atlist
+ #
+ # out: C code for IDL attribute decalarations.
+ #
+ # NOTE: Mapping of attributes to operation(function) names is tricky.
+ #
+ # The actual accessor function names are language-mapping specific. The attribute name
+ # is subject to OMG IDL's name scoping rules; the accessor function names are
+ # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
+ #
+ # eg:
+ #
+ # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
+ # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
+ #
+ # or:
+ #
+ # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
+ # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
+ #
+ # TODO: Implement some language dependant templates to handle naming conventions
+ # language <=> attribute. for C, C++. Java etc
+ #
+ # OR, just add a runtime GUI option to select language binding for attributes -- FS
+ #
+ #
+ #
+ # ie: def genAtlist(self,atlist,language)
+ #
+
+
+
+ def genAtList(self,atlist):
+ self.st.out(self.template_comment_attributes_start)
+
+ for n in atlist:
+ for i in n.declarators(): #
+ sname = self.namespace(i, "_")
+ atname = i.identifier()
+ self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
+ if not n.readonly():
+ self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
+
+ self.st.out(self.template_comment_attributes_end)
+
+
+ #
+ # genExceptionDelegator
+ #
+ # in: oplist
+ #
+ # out: C code for User exception delegator
+ #
+ # eg:
+ #
+ #
+
+ def genExceptionDelegator(self,oplist):
+
+ self.st.out(self.template_main_exception_delegator_start)
+ self.st.inc_indent()
+
+ exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
+
+ for ex in exlist:
+ if self.DEBUG:
+ print "XXX Exception " , ex.repoId()
+ print "XXX Exception Identifier" , ex.identifier()
+ print "XXX Exception Scoped Name" , ex.scopedName()
+
+ if (ex.members()): # only if has members
+ sname = self.namespace(ex, "_")
+ exname = ex.repoId()
+ self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
+
+ self.st.dec_indent()
+ self.st.out(self.template_main_exception_delegator_end)
+
+
+ #
+ # genAttribueHelpers()
+ #
+ # Generate private helper functions to decode Attributes.
+ #
+ # in: atlist
+ #
+ # For readonly attribute - generate get_xxx()
+ # If NOT readonly attribute - also generate set_xxx()
+ #
+
+ def genAttributeHelpers(self,atlist):
+ if self.DEBUG:
+ print "XXX genAttributeHelpers: atlist = ", atlist
+
+ self.st.out(self.template_attribute_helpers_start)
+
+ for attrib in atlist:
+ for decl in attrib.declarators():
+ self.genAtHelper(attrib,decl,"get") # get accessor
+ if not attrib.readonly():
+ self.genAtHelper(attrib,decl,"set") # set accessor
+
+ self.st.out(self.template_attribute_helpers_end)
+
+ #
+ # genAtHelper()
+ #
+ # Generate private helper functions to decode an attribute
+ #
+ # in: at - attribute node
+ # in: decl - declarator belonging to this attribute
+ # in: order - to generate a "get" or "set" helper
+
+ def genAtHelper(self,attrib,decl,order):
+ if self.DEBUG:
+ print "XXX genAtHelper"
+
+ sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
+ self.curr_sname = sname # update current opnode/exnode scoped name
+
+ if not self.fn_hash_built:
+ self.fn_hash[sname] = [] # init empty list as val for this sname key
+ # but only if the fn_hash is not already built
+
+ self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
+ self.st.inc_indent()
+
+ self.st.out(self.template_helper_function_vars_start)
+ self.dumpCvars(sname)
+ self.st.out(self.template_helper_function_vars_end )
+
+ self.st.out(self.template_exception_helper_function_get_endianess)
+
+ #
+ # TODO - attributes are simple types, so remove array handling
+ #
+
+ if decl.sizes(): # an array
+ indices = self.get_indices_from_sizes(decl.sizes())
+ string_indices = '%i ' % indices # convert int to string
+ self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
+ self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
+ self.addvar(self.c_i + decl.identifier() + ";")
+
+ self.st.inc_indent()
+
+ self.getCDR3(attrib.attrType(), decl.identifier() )
+
+ self.st.dec_indent()
+ self.st.out(self.template_get_CDR_array_end)
+
+
+ else:
+
+ self.getCDR3(attrib.attrType(), decl.identifier() )
+
+ self.st.dec_indent()
+ self.st.out(self.template_attribute_helper_function_end)
+
#
#
- def genExceptionHelpers(self,oplist):
+ def genExceptionHelpers(self,oplist):
exlist = self.get_exceptionList(oplist) # grab list of exception nodes
+ if self.DEBUG:
+ print "XXX genExceptionHelpers: exlist = ", exlist
self.st.out(self.template_exception_helpers_start)
-
- for ex in self.exlist:
- #print "Exception = " + ex.identifier()
- self.genExHelper()
+ for ex in exlist:
+ if (ex.members()): # only if has members
+ #print "XXX Exception = " + ex.identifier()
+ self.genExHelper(ex)
self.st.out(self.template_exception_helpers_end)
#
- # genExhelper() -- TODO not complete yet
+ # genExhelper()
#
- # Generate private helper functions to decode used exceptions
+ # Generate private helper functions to decode User Exceptions
#
# in: exnode ( an exception node)
#
- def genExHelper(self,exnode):
- t = 0
+ def genExHelper(self,ex):
+ if self.DEBUG:
+ print "XXX genExHelper"
+
+ sname = self.namespace(ex, "_")
+ self.curr_sname = sname # update current opnode/exnode scoped name
+ if not self.fn_hash_built:
+ self.fn_hash[sname] = [] # init empty list as val for this sname key
+ # but only if the fn_hash is not already built
+ self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
+ self.st.inc_indent()
+ self.st.out(self.template_helper_function_vars_start)
+ self.dumpCvars(sname)
+ self.st.out(self.template_helper_function_vars_end )
+
+ self.st.out(self.template_exception_helper_function_get_endianess)
+
+
+ for m in ex.members():
+ #print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
+
+
+ for decl in m.declarators():
+ #print "XXX genExhelper, d = ", decl
+ if decl.sizes(): # an array
+ indices = self.get_indices_from_sizes(decl.sizes())
+ string_indices = '%i ' % indices # convert int to string
+ self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
+ self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
+ self.addvar(self.c_i + decl.identifier() + ";")
+
+ self.st.inc_indent()
+ self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
+
+ self.st.dec_indent()
+ self.st.out(self.template_get_CDR_array_end)
+
+
+ else:
+ self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
+
+ self.st.dec_indent()
+ self.st.out(self.template_exception_helper_function_end)
#
#
def genOperation(self,opnode):
- ##print "visitOperation called"
+ if self.DEBUG:
+ print "XXX genOperation called"
+
sname = self.namespace(opnode, "_")
if not self.fn_hash_built:
self.fn_hash[sname] = [] # init empty list as val for this sname key
- # but on if the fn_hash is not already built
+ # but only if the fn_hash is not already built
self.curr_sname = sname # update current opnode's scoped name
opname = opnode.identifier()
if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
#self.getCDR3(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
- self.get_CDR_alias(rt, "Operation Return Value" )
+ #self.get_CDR_alias(rt, "Operation_Return_Value" )
+ self.get_CDR_alias(rt, rt.name() )
else:
- self.getCDR3(rt, "Operation Return Value") # return value is NOT an alias
+ self.getCDR3(rt, "Operation_Return_Value") # return value is NOT an alias
for p in opnode.parameters():
if p.is_out(): # out or inout
for m in ex.members():
t=0
#print m.memberType(), m.memberType().kind()
-
- def genDelegator(self,oplist):
+ #
+ # Delegator for Operations
+ #
+
+ def genOpDelegator(self,oplist):
for op in oplist:
opname = op.identifier()
sname = self.namespace(op, "_")
- self.st.out(self.template_delegate_code, opname=opname, sname=sname)
+ self.st.out(self.template_op_delegate_code, sname=sname)
+
+ #
+ # Delegator for Attributes
+ #
+
+ def genAtDelegator(self,atlist):
+ for a in atlist:
+ for i in a.declarators():
+ atname = i.identifier()
+ sname = self.namespace(i, "_")
+ self.st.out(self.template_at_delegate_code_get, sname=sname)
+ if not a.readonly():
+ self.st.out(self.template_at_delegate_code_set, sname=sname)
+
#
# Add a variable declaration to the hash of list
self.st.out(v)
-
+ #
+ # Given an enum node, and a enumerator node, return
+ # the enumerator's numerical value.
+ #
+ # eg: enum Color {red,green,blue} should return
+ # val = 1 for green
+ #
+
+ def valFromEnum(self,enumNode, enumeratorNode):
+ if self.DEBUG:
+ print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
+ print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
+
+ if isinstance(enumeratorNode,idlast.Enumerator):
+ value = enumNode.enumerators().index(enumeratorNode)
+ return value
## tk_null = 0
self.get_CDR_objref(type,pn)
elif pt == idltype.tk_array:
self.get_CDR_array(type,pn)
+ elif pt == idltype.tk_union:
+ self.get_CDR_union(type,pn)
elif pt == idltype.tk_alias:
if self.DEBUG:
print "XXXXX Alias type XXXXX " , type
self.get_CDR_alias(type,pn)
else:
- if self.DEBUG:
- print "XXXXX Unknown type XXXXX " , pt
+ self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code
#
self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
self.addvar(self.c_u_octet4)
+ def get_CDR_union(self,type,pn):
+ if self.DEBUG:
+ print "XXX Union type =" , type, " pn = ",pn
+ print "XXX Union type.decl()" , type.decl()
+ print "XXX Union Scoped Name" , type.scopedName()
+
+ # If I am a typedef union {..}; node then find the union node
+
+ if isinstance(type.decl(), idlast.Declarator):
+ ntype = type.decl().alias().aliasType().decl()
+ else:
+ ntype = type.decl() # I am a union node
+
+ if self.DEBUG:
+ print "XXX Union ntype =" , ntype
+
+ st = ntype.switchType()
+
+
+
+ #std = st.decl()
+
+ if self.DEBUG:
+ print "XXX Union ntype =" , ntype
+ print "XXX Union ntype.switchType =" , st
+ #print "XXX Union ntype.switchType().decl() = " , std
+ #print "XXX Union std.repoId() = ", std.repoId()
+
+
+ self.st.out(self.template_comment_union_code_start, uname=ntype.repoId() )
+
+ self.getCDR3(st,pn);
+
+ # Depending on what kind of discriminant I come accross (enum,integer,char,
+ # boolean), make sure I cast the return value of the get_XXX accessor
+ # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
+ # return an integer, or an Enumerator object that is then converted to its
+ # integer equivalent.
+ #
+ #
+ # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
+ #
+
+ if (st.kind() == idltype.tk_enum):
+ std = st.decl()
+ self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
+ self.st.out(self.template_union_code_save_discriminant_enum, discname=pn )
+ self.addvar(self.c_s_disc + pn + ";")
+
+ elif (st.kind() == idltype.tk_long):
+ self.st.out(self.template_union_code_save_discriminant_integer, discname=pn )
+ self.addvar(self.c_s_disc + pn + ";")
+
+ elif (st.kind() == idltype.tk_boolean):
+ self.st.out(self.template_union_code_save_discriminant_boolean, discname=pn )
+ self.addvar(self.c_s_disc + pn + ";")
+
+ elif (st.kind() == idltype.tk_char):
+ self.st.out(self.template_union_code_save_discriminant_char, discname=pn )
+ self.addvar(self.c_s_disc + pn + ";")
+
+ else:
+ print "XXX Unknown st.kind() = ", st.kind()
+
+ #
+ # Loop over all cases in this union
+ #
+
+ for uc in ntype.cases(): # for all UnionCase objects in this union
+ for cl in uc.labels(): # for all Caselabel objects in this UnionCase
+
+ # get integer value, even if discriminant is
+ # an Enumerator node
+
+ if isinstance(cl.value(),idlast.Enumerator):
+ if self.DEBUG:
+ print "XXX clv.identifier()", cl.value().identifier()
+ print "XXX clv.repoId()", cl.value().repoId()
+ print "XXX clv.scopedName()", cl.value().scopedName()
+
+ # find index of enumerator in enum declaration
+ # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }
+
+ clv = self.valFromEnum(std,cl.value())
+
+ else:
+ clv = cl.value()
+
+ #print "XXX clv = ",clv
+
+ #
+ # if char, dont convert to int, but put inside single quotes so that it is understood by C.
+ # eg: if (disc == 'b')..
+
+ if (st.kind() == idltype.tk_char):
+ string_clv = "'" + clv + "'"
+ else:
+ string_clv = '%i ' % clv
+
+ #
+ # If default case, then skp comparison with discriminator
+ #
+
+ if not cl.default():
+ self.st.out(self.template_comment_union_code_label_compare_start, discname=pn,labelval=string_clv )
+ self.st.inc_indent()
+ else:
+ self.st.out(self.template_comment_union_code_label_default_start )
+
+
+ self.getCDR3(uc.caseType(),uc.declarator().identifier())
+
+ if not cl.default():
+ self.st.dec_indent()
+ self.st.out(self.template_comment_union_code_label_compare_end )
+ else:
+ self.st.out(self.template_comment_union_code_label_default_end )
+
#
# Currently, get_CDR_alias is geared to finding typdef
self.addvar(self.c_i + pn + ";")
self.st.inc_indent()
- self.getCDR3(type.unalias().seqType() ) # and start all over with the type
+ self.getCDR3(type.unalias().seqType(), pn ) # and start all over with the type
self.st.dec_indent()
self.st.out(self.template_get_CDR_sequence_loop_end)
def namespace(self,node,sep):
sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
+ #print "XXX namespace: sname = " + sname
return sname
+ #
+ # generate code for plugin initialisation
+ #
+
+ def gen_plugin_init(self):
+ self.st.out(self.template_plugin_init, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)
+
#
# generate register_giop_user_module code, and register only
# unique interfaces that contain operations. Also output
ex_hash = {} # holds a hash of unique exceptions.
for op in oplist:
for ex in op.raises():
- if not ex_hash.has_key(ex.identifier()):
- ex_hash[ex.identifier()] = 0; # dummy val, but at least key is unique
- #print "Exception = " + ex.identifier()
+ if not ex_hash.has_key(ex):
+ ex_hash[ex] = 0; # dummy val, but at least key is unique
+ if self.DEBUG:
+ print "XXX Exception = " + ex.identifier()
+
return ex_hash.keys()
return (dignum/2) + 1
+
+ #
+ # Output some TODO comment
+ #
+
+
+ def genTODO(self,message):
+ self.st.out(self.template_debug_TODO, message=message)
+
+ #
+ # Output some WARNING comment
+ #
+
+ def genWARNING(self,message):
+ self.st.out(self.template_debug_WARNING, message=message)
+
#
# Templates for C code
#
template_proto_reg_handoff_start = """
/* register me as handler for these interfaces */
-void proto_register_handoff_@dissector_name@(void) {
+void proto_register_handoff_giop_@dissector_name@(void) {
"""
/* Register for Explicit Dissection */
-register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\" ); /* explicit dissector */
+register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ ); /* explicit dissector */
#endif
/* Register for Heuristic Dissection */
-register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ); /* heuristic dissector */
+register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@); /* heuristic dissector */
"""
/* TODO - Use registered fields */
"""
-
+ #
+ # plugin_init and plugin_reg_handoff templates
+ #
+
+ template_plugin_init = """
+
+#ifndef __ETHEREAL_STATIC__
+
+G_MODULE_EXPORT void
+plugin_reg_handoff(void){
+ proto_register_handoff_giop_@dissector_name@();
+}
+
+G_MODULE_EXPORT void
+plugin_init(plugin_address_table_t *pat){
+ /* initialise the table of pointers needed in Win32 DLLs */
+ plugin_address_table_init(pat);
+ if (proto_@dissector_name@ == -1) {
+ proto_register_giop_@dissector_name@();
+ }
+}
+
+#endif
+"""
#
# proto_register_<dissector name>(void) templates
/* Register the protocol with Ethereal */
-void proto_register_@dissector_name@(void) {
+void proto_register_giop_@dissector_name@(void) {
/* setup list of header fields */
+#if 0
static hf_register_info hf[] = {
/* no fields yet */
};
+#endif
/* setup protocol subtree array */
/* Register the protocol name and description */
- proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"@dissector_name@\" );
+ proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
+#if 0
proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
+#endif
proto_register_subtree_array(ett,array_length(ett));
}
# template for delegation code
#
- template_delegate_code = """\
+ template_op_delegate_code = """\
if (!strcmp(operation, @sname@_op )) {
decode_@sname@(tvb, pinfo, tree, offset, header, operation);
return TRUE;
#
template_Header = """\
-/*
- * packet-@dissector_name@-idl.c
+/* packet-@dissector_name@.c
* Routines for IDL dissection
*
- * Autogenerated from ethereal_be.py
+ * Autogenerated from idl2eth
* Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
*/
"""
+ template_ethereal_copyright = """\
+/*
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs
+ * Copyright 1999 Gerald Combs
+ */
+
+"""
+
+
+
#
# GPL Template
#
# include "config.h"
#endif
+#include "plugins/plugin_api.h"
+
#include <stdio.h>
#include <stdlib.h>
+#include <gmodule.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#include "proto.h"
#include "packet-giop.h"
+#ifndef __ETHEREAL_STATIC__
+G_MODULE_EXPORT const gchar version[] = "0.0.1";
+#endif
+
"""
#
template_main_dissector_start = """\
-gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname) {
+static gboolean dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, gchar *operation, gchar *idlname) {
proto_item *ti = NULL;
proto_tree *tree = NULL; /* init later, inside if(tree) */
be = is_big_endian(header); /* get endianess - TODO use passed in stream_is_big_endian instead ? */
+ /* If we have a USER Exception, then decode it and return */
+
+ if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
+
+ return decode_user_exception(tvb, pinfo, tree, offset, header, operation);
+
+ }
+
"""
+
+
+
+#-------------------------------------------------------------#
+# Exception handling templates #
+#-------------------------------------------------------------#
+
+
+
+
+
+
+
template_exception_helpers_start = """\
/* Begin Exception Helper Functions */
/* End Exception Helper Functions */
"""
+
+
+
+#
+# Templates for declaration of string constants for user exceptions.
+#
+
+ template_comment_user_exceptions_string_declare_start = """\
+/* Begin Exception (containing members) String Declare */
+
+"""
+
+ template_user_exceptions_declare = """static const char user_exception_@sname@[] = \"@exname@\" ; """
+
+
+ template_comment_user_exceptions_string_declare_end = """\
+
+/* End Exception (containing members) String Declare */
+
+"""
+
+
+
+
+#
+# template for Main delegator for exception handling
+#
+
+ template_main_exception_delegator_start = """\
+
+/*
+ * Main delegator for exception handling
+ *
+ */
+
+static gboolean decode_user_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation ) {
+
+ gboolean be; /* big endianess */
+
+
+"""
+
+
+#
+# template for exception delegation code body
+#
+ template_ex_delegate_code = """\
+if (!strcmp(header->exception_id, user_exception_@sname@ )) {
+ decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation); /* @exname@ */
+ return TRUE;
+}
+
+"""
+
+
+#
+# End of Main delegator for exception handling
+#
+
+ template_main_exception_delegator_end = """\
+
+
+ return FALSE; /* user exception not found */
+
+}
+"""
+
+#
+# template for exception helper code
+#
+ template_exception_helper_function_start = """\
+/* Exception = @exname@ */
+static void decode_ex_@sname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
+
+ gboolean stream_is_big_endian; /* big endianess */
+"""
+
+
+
+ #
+ # Template for the helper function
+ # to get stream endianess from header
+ #
+
+ template_exception_helper_function_get_endianess = """\
+
+stream_is_big_endian = is_big_endian(header); /* get stream endianess */
+
+"""
+
+
+ template_exception_helper_function_end = """\
+}
+"""
+
+
+
+
+#-------------------------------------------------------------#
+# Attribute handling templates #
+#-------------------------------------------------------------#
+
+
+ template_comment_attributes_start = """\
+/*
+ * IDL Attributes Start
+ */
+
+ """
+
+ #
+ # get/set accessor method names are language mapping dependant.
+ #
+
+ template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
+ template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""
+
+
+ template_comment_attributes_end = """
+/*
+ * IDL Attributes End
+ */
+
+"""
+
+
+ #
+ # template for Attribute delegation code
+ #
+ # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
+ # Note: _set_xxx() should only be called for Request
+ #
+ #
+
+ template_at_delegate_code_get = """\
+if (!strcmp(operation, get_@sname@_at ) && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
+ decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation);
+ return TRUE;
+}
+"""
+
+ template_at_delegate_code_set = """\
+if (!strcmp(operation, set_@sname@_at ) && (header->message_type == Request) ) {
+ decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation);
+ return TRUE;
+}
+"""
+
+
+
+ template_attribute_helpers_start = """\
+/* Begin Attribute Helper Functions */
+
+"""
+
+ template_attribute_helpers_end = """\
+
+/* End Attribute Helper Functions */
+
+"""
+
+#
+# template for attribute helper code
+#
+
+
+ template_attribute_helper_function_start = """\
+
+/* Attribute = @atname@ */
+
+static void decode_@sname@_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, MessageHeader *header, gchar *operation) {
+
+ gboolean stream_is_big_endian; /* big endianess */
+"""
+
+
+
+ #
+ # Template for the helper function
+ # to get stream endianess from header
+ #
+
+ template_attribute_helper_function_get_endianess = """\
+
+stream_is_big_endian = is_big_endian(header); /* get stream endianess */
+
+"""
+
+
+ template_attribute_helper_function_end = """\
+}
+"""
+
+
+#-------------------------------------------------------------#
+# Debugging templates #
+#-------------------------------------------------------------#
+
+
+ #
+ # Template for outputting TODO "C" comments
+ # so user know I need ti improve something.
+ #
+
+ template_debug_TODO = """\
+
+/* TODO - @message@ */
+"""
+
+ #
+ # Template for outputting WARNING "C" comments
+ # so user know if I have found a problem.
+ #
+
+ template_debug_WARNING = """\
+
+/* WARNING - @message@ */
+"""
+
+
+
+#-------------------------------------------------------------#
+# IDL Union templates #
+#-------------------------------------------------------------#
+
+
+
+ template_comment_union_code_start = """\
+/*
+ * IDL Union Start - @uname@
+ */
+
+ """
+
+
+ template_comment_union_code_end = """
+/*
+ * IDL union End - @uname@
+ */
+
+"""
+
+ template_comment_union_code_discriminant = """\
+/*
+ * IDL Union - Discriminant - @uname@
+ */
+
+ """
+
+ #
+ # Cast Unions types to something appropriate
+ # Enum value cast to guint32, all others cast to gint32
+ # as omniidl accessor returns integer or Enum.
+ #
+
+ template_union_code_save_discriminant_enum = """\
+disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
+"""
+
+ template_union_code_save_discriminant_integer = """\
+disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
+"""
+
+ template_union_code_save_discriminant_char = """\
+disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
+"""
+
+ template_union_code_save_discriminant_boolean = """\
+disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */
+"""
+
+
+ template_comment_union_code_label_compare_start = """\
+if (disc_s_@discname@ == @labelval@) {
+
+ """
+ template_comment_union_code_label_compare_end = """\
+ break;
+}
+
+ """
+
+
+ template_comment_union_code_label_default_start = """
+/* Default Union Case Start */
+
+"""
+
+ template_comment_union_code_label_default_end = """\
+/* Default Union Case End */
+
+ """