ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] idl2eth update - 2 patches

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Frank Singleton <frank.singleton@xxxxxxxxxxxx>
Date: Fri, 12 Oct 2001 09:07:05 -0500
Hi,


I have added some functionality to idl2eth to allow C code
generation and display of CORBA IDL Enum's as symbolic values, along
side the numerical value currently being displayed.
 
Twas diffed against the 2001-10-10 nightly CVS  tarball.

patch1.diff - ethereal_be.py
patch2.diff - ethereal_gen.py

Cheers / Frank

-- 
EUS/SV/Z Frank Singleton      ASO Americas BSS
Office : +1 972 583 3251      ECN 800 33251  
Mobile : +1 214 228 0874      Amateur Radio: VK3FCS/KM5WS   
Email : frank.singleton@xxxxxxxxxxxx

Hardware: HP Omnibook 4150 running Redhat Linux 7.1 (2.4.3-12 kernel).
--- ../ethereal-2001-10-10/ethereal_be.py	Thu Aug 30 14:31:53 2001
+++ ../ethereal-2001-10-10.updated/ethereal_be.py	Thu Oct 11 09:53:42 2001
@@ -1,6 +1,6 @@
 # -*- python -*-
 #
-# $Id: ethereal_be.py,v 1.4 2001/08/30 19:31:53 oabad Exp $
+# $Id: ethereal_be.py,v 1.7 2001/10/11 12:45:34 frank Exp $
 #
 #    File      : ethereal_be.py
 #
@@ -72,7 +72,7 @@
     def __init__(self, st):
         self.st = st
         self.oplist = []                # list of operation nodes
-        self.enumlist = []              # list of enum nodes
+        self.enlist = []                # list of enum nodes
         self.atlist = []                # list of attribute nodes
 
         
@@ -86,6 +86,9 @@
                 self.visitOperation(n)
             if isinstance(n, idlast.Attribute):
                 self.visitAttribute(n)
+            if isinstance(n, idlast.Enum):
+                self.visitEnum(n)
+                                
 
     def visitModule(self, node):
         for n in node.definitions():
@@ -97,7 +100,9 @@
                 self.visitOperation(n)   
             if isinstance(n, idlast.Attribute):
                 self.visitAttribute(n)
-
+            if isinstance(n, idlast.Enum):
+                self.visitEnum(n)
+                
     def visitInterface(self, node):
         #if node.mainFile():
         for c in node.callables():
@@ -106,6 +111,9 @@
             if isinstance(c, idlast.Attribute):
                 self.visitAttribute(c)
                 
+        for d in node.contents():
+            if isinstance(d, idlast.Enum):
+                self.visitEnum(d)                
     #
     # visitOperation
     #
@@ -126,6 +134,18 @@
     def visitAttribute(self,atnode):
         self.atlist.append(atnode)      # store attribute node
 
+    #
+    # visitEnum
+    #
+    # populates the enum node list "enumlist"
+    #
+    #
+    
+    def visitEnum(self,enode):
+        #print "XXX - enum found" , enode
+        self.enlist.append(enode)      # store enum node
+
+
         
 def run(tree, args):
 
@@ -148,7 +168,7 @@
     # and generate some C code
     
     eg = ethereal_gen_C(ev.st, string.upper(nl), string.lower(nl), string.capitalize(nl) + " Dissector Using GIOP API") 
-    eg.genCode(ev.oplist, ev.atlist)    # pass them onto the C generator
+    eg.genCode(ev.oplist, ev.atlist, ev.enlist)    # pass them onto the C generator
     
 
 

--- ../ethereal-2001-10-10/ethereal_gen.py	Fri Aug 10 23:37:31 2001
+++ ../ethereal-2001-10-10.updated/ethereal_gen.py	Fri Oct 12 08:24:43 2001
@@ -1,6 +1,6 @@
 # -*- python -*-
 #
-# $Id: ethereal_gen.py,v 1.11 2001/08/11 04:37:31 guy Exp $
+# $Id: ethereal_gen.py,v 1.12 2001/10/12 13:24:43 frank Exp $
 #                           
 # ethereal_gen.py (part of idl2eth)           
 #
@@ -94,6 +94,8 @@
 # 12. Implement IDL "union" code [done]
 # 13. Implement support for plugins [done]
 # 14. Dont generate code for empty operations (cf: exceptions without members)
+# 15. Generate code to display Enums numerically ans symbolically [done]
+# 16. Place structs in subtrees
 #
 # Also test, Test, TEST
 #
@@ -102,12 +104,12 @@
 
 #
 #   Strategy:
-#
-#    For return val and all parameters do
+#    For every operation and attribute do
+#       For return val and all parameters do
 #       find basic IDL type for each parameter
 #       output get_CDR_xxx
-#    output exception handling code
-#    output attribute handling code
+#       output exception handling code
+#       output attribute handling code
 #
 #
 
@@ -167,7 +169,7 @@
     #
     #
         
-    def genCode(self,oplist, atlist):   # operation and attribute lists
+    def genCode(self,oplist, atlist, enlist):   # operation and attribute lists
 
         self.genHelpers(oplist)         # sneaky .. call it now, to populate the fn_hash
                                         # so when I come to that operation later, I have the variables to
@@ -195,6 +197,7 @@
         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.genEnList(enlist)          # string constant declares for Enums
         
         
         self.genExceptionHelpers(oplist)   # helper function to decode user exceptions that have members
@@ -430,6 +433,43 @@
 
 
     #
+    # genEnList
+    #
+    # in: enlist
+    #
+    # out: C code for IDL Enum decalarations using "static const value_string" template
+    #
+
+    
+
+    def genEnList(self,enlist):
+        
+        self.st.out(self.template_comment_enums_start)        
+
+        for enum in enlist:
+            sname = self.namespace(enum, "_")
+            
+            self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
+            self.st.out(self.template_value_string_start, valstringname=sname)
+            for enumerator in enum.enumerators():
+                self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
+                
+                
+            #atname = n.identifier()
+            self.st.out(self.template_value_string_end, valstringname=sname)
+    
+        self.st.out(self.template_comment_enums_end)
+
+
+
+
+
+
+
+
+
+
+    #
     # genExceptionDelegator
     #
     # in: oplist
@@ -920,7 +960,9 @@
             self.get_CDR_wchar(pn)            
         elif pt ==  idltype.tk_enum:
             #print type.decl()
-            self.get_CDR_enum(pn)
+            self.get_CDR_enum(pn,type)
+            #self.get_CDR_enum(pn)
+            
         elif pt ==  idltype.tk_struct:
             self.get_CDR_struct(type,pn)
         elif pt ==  idltype.tk_TypeCode: # will I ever get here ?
@@ -1003,8 +1045,12 @@
     def get_CDR_any(self,pn):
         self.st.out(self.template_get_CDR_any, varname=pn)
 
-    def get_CDR_enum(self,pn):
-        self.st.out(self.template_get_CDR_enum, varname=pn)
+    def get_CDR_enum(self,pn,type):
+        #self.st.out(self.template_get_CDR_enum, varname=pn)
+        sname = self.namespace(type, "_")
+        self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname)
+
+
         self.addvar(self.c_u_octet4)
 
     def get_CDR_string(self,pn):
@@ -1821,18 +1867,18 @@
 seq = NULL;
 
 """
-    
-    
-    template_get_CDR_enum = """\
 
-/* TODO - translate Enum val into symbolic value */
+            
+    template_get_CDR_enum_symbolic = """\
     
 u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
 if (tree) {
-   proto_tree_add_text(tree,tvb,*offset-4,4,"Enum value = %u ",u_octet4);
+   proto_tree_add_text(tree,tvb,*offset-4,4,"Enum value = %u (%s)",u_octet4,val_to_str(u_octet4,@valstringarray@,"Unknown Enum Value"));
 }
 """
 
+
+
     template_get_CDR_string = """\
 u_octet4 = get_CDR_string(tvb, &seq, offset, stream_is_big_endian, boundary);
 if (tree) {
@@ -2262,6 +2308,49 @@
 }
 """
 
+#-------------------------------------------------------------#
+#             Value string  templates                         #
+#-------------------------------------------------------------#
+
+    template_value_string_start = """\
+static const value_string @valstringname@[] = {
+"""
+
+    template_value_string_entry = """\
+   { @intval@, \"@description@\" }, """    
+    
+    template_value_string_end = """\
+   { 0,       NULL },
+};
+    
+"""
+
+    
+
+#-------------------------------------------------------------#
+#             Enum   handling templates                       #
+#-------------------------------------------------------------#
+
+    template_comment_enums_start = """\
+/*
+ * IDL Enums Start
+ */
+ 
+ """
+    
+    template_comment_enums_end = """\
+/*
+ * IDL Enums End
+ */
+ 
+ """
+    
+    template_comment_enum_comment = """\
+/*
+ * Enum = @ename@
+ */
+ 
+ """