Advertisement
Guest User

libsmi.py

a guest
Dec 14th, 2010
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.85 KB | None | 0 0
  1. from ctypes import *
  2.  
  3. # C define statements!  (#define SMI_VERSION_MAJOR 0)
  4. SMI_LIBRARY_VERSION = c_char_p("2:25:0")
  5. #extern const char *smi_library_version; ?? what to do with this. hrmm.
  6.  
  7. SMI_VERSION_MAJOR= 0
  8. SMI_VERSION_MINOR= 4
  9. SMI_VERSION_PATCHLEVEL= 5
  10. SMI_VERSION_STRING = c_char_p("0.4.5")
  11. #extern const char *smi_version_string; ?? what to do with this. hrmm.
  12.  
  13. SMI_FLAG_NODESCR = 0x0800 #/* do not load descriptions/references.    */
  14. SMI_FLAG_VIEWALL = 0x1000 #/* all modules are `known', need no views. */
  15. SMI_FLAG_ERRORS = 0x2000 #/* print parser errors.                    */
  16. SMI_FLAG_RECURSIVE = 0x4000 #/* recursively parse imported modules.     */
  17. SMI_FLAG_STATS = 0x8000 #/* print statistics after parsing module.  */
  18. SMI_FLAG_MASK = (SMI_FLAG_NODESCR,SMI_FLAG_VIEWALL,SMI_FLAG_STATS,SMI_FLAG_RECURSIVE,SMI_FLAG_ERRORS)
  19.  
  20. SMI_NODEKIND_UNKNOWN=0x0000     #/* should not occur             */
  21. SMI_NODEKIND_NODE=0x0001
  22. SMI_NODEKIND_SCALAR=0x0002
  23. SMI_NODEKIND_TABLE=0x0004
  24. SMI_NODEKIND_ROW=0x0008
  25. SMI_NODEKIND_COLUMN=0x0010
  26. SMI_NODEKIND_NOTIFICATION= 0x0020
  27. SMI_NODEKIND_GROUP=0x0040
  28. SMI_NODEKIND_COMPLIANCE=0x0080
  29. SMI_NODEKIND_CAPABILITIES =0x0100
  30. SMI_NODEKIND_ANY=0xffff
  31.  
  32. SMI_RENDER_NUMERIC=0x01 # render as numeric values
  33. SMI_RENDER_NAME=0x02 # render as names
  34. SMI_RENDER_QUALIFIED= 0x04 # render names with module prefix
  35. SMI_RENDER_FORMAT=0x08 # render by applying the type's format if type is given and format is present
  36. SMI_RENDER_PRINTABLE =0x10 # render string values as a printable string if all octets are isprint()
  37. SMI_RENDER_UNKNOWN=0x20 # render even unknown items as strings ("<unknown>") so that we never get NULL
  38. SMI_RENDER_ALL=0xff # render as `human friendly' as possible
  39.  
  40. SMI_UNKNOWN_LABEL =c_char_p("<unknown>")
  41.  
  42. # misc typedef mappings of SMI types to ctypes
  43. SmiNodekind = c_uint
  44. SmiIdentifier = c_char_p
  45. SmiSubid = c_uint
  46. SmiUnsigned32 = c_ulong
  47. SmiInteger32 = c_long
  48. SmiUnsigned64 = c_ulonglong
  49. SmiInteger64 = c_longlong
  50. SmiFloat32 = c_float
  51. SmiFloat64 = c_double
  52. SmiFloat128 = c_longdouble
  53. SmiLanguage = c_uint
  54.  
  55. #/* SmiLanguage -- language of an actual MIB module                           */
  56. #typedef enum SmiLanguage {
  57. SMI_LANGUAGE_UNKNOWN                = 0  #/* should not occur            */
  58. SMI_LANGUAGE_SMIV1                  = 1
  59. SMI_LANGUAGE_SMIV2                  = 2
  60. SMI_LANGUAGE_SMING                  = 3
  61. SMI_LANGUAGE_SPPI                   = 4
  62.  
  63.  
  64. #/* SmiBasetype -- base types of all languages                                */
  65. #typedef enum SmiBasetype {
  66. SMI_BASETYPE_UNKNOWN                = 0,  #/* should not occur            */
  67. SMI_BASETYPE_INTEGER32              = 1  #/* also SMIv1/v2 INTEGER       */
  68. SMI_BASETYPE_OCTETSTRING            = 2
  69. SMI_BASETYPE_OBJECTIDENTIFIER       = 3
  70. SMI_BASETYPE_UNSIGNED32             = 4
  71. SMI_BASETYPE_INTEGER64              = 5  #/* SMIng and SPPI              */
  72. SMI_BASETYPE_UNSIGNED64             = 6  #/* SMIv2, SMIng and SPPI       */
  73. SMI_BASETYPE_FLOAT32                = 7  #/* only SMIng                  */
  74. SMI_BASETYPE_FLOAT64                = 8  #/* only SMIng                  */
  75. SMI_BASETYPE_FLOAT128               = 9  #/* only SMIng                  */
  76. SMI_BASETYPE_ENUM                   = 10
  77. SMI_BASETYPE_BITS                   = 11  #/* SMIv2, SMIng and SPPI       */
  78.  
  79.  
  80. #/* SmiStatus -- values of status levels                                      */
  81. #typedef enum SmiStatus {
  82. SMI_STATUS_UNKNOWN          = 0 #/* should not occur                     */
  83. SMI_STATUS_CURRENT          = 1 #/* only SMIv2, SMIng and SPPI           */
  84. SMI_STATUS_DEPRECATED       = 2 #/* SMIv1, SMIv2, SMIng and SPPI         */
  85. SMI_STATUS_MANDATORY        = 3 #/* only SMIv1                           */
  86. SMI_STATUS_OPTIONAL         = 4 #/* only SMIv1                           */
  87. SMI_STATUS_OBSOLETE         = 5  #/* SMIv1, SMIv2, SMIng and SPPI         */
  88.  
  89.  
  90. #/* SmiAccess -- values of access levels                                      */
  91. #typedef enum SmiAccess {
  92. SMI_ACCESS_UNKNOWN          = 0 #/* should not occur                     */
  93. SMI_ACCESS_NOT_IMPLEMENTED  = 1 #/* only for agent capability variations */
  94. SMI_ACCESS_NOT_ACCESSIBLE   = 2 #/* the values 2 to 5 are allowed to be  */
  95. SMI_ACCESS_NOTIFY           = 3 #/* compared by relational operators.    */
  96. SMI_ACCESS_READ_ONLY        = 4
  97. SMI_ACCESS_READ_WRITE       = 5
  98. SMI_ACCESS_INSTALL          = 6 #/* these three entries are only valid   */
  99. SMI_ACCESS_INSTALL_NOTIFY   = 7 #/* for SPPI                             */
  100. SMI_ACCESS_REPORT_ONLY      = 8
  101.  
  102.  
  103. #/* SmiDecl -- type or statement that leads to a definition                   */
  104. #typedef enum SmiDecl {
  105. SMI_DECL_UNKNOWN            = 0  #/* should not occur                    */
  106. #/* SMIv1/v2 ASN.1 statements and macros */
  107. SMI_DECL_IMPLICIT_TYPE      = 1
  108. SMI_DECL_TYPEASSIGNMENT     = 2
  109. SMI_DECL_IMPL_SEQUENCEOF    = 4 #/* this will go away */
  110. SMI_DECL_VALUEASSIGNMENT    = 5
  111. SMI_DECL_OBJECTTYPE         = 6    #/* values >= 6 are assumed to be */
  112. SMI_DECL_OBJECTIDENTITY     = 7    #/* registering an OID, see check.c */
  113. SMI_DECL_MODULEIDENTITY     = 8
  114. SMI_DECL_NOTIFICATIONTYPE   = 9
  115. SMI_DECL_TRAPTYPE           = 10
  116. SMI_DECL_OBJECTGROUP        = 11
  117. SMI_DECL_NOTIFICATIONGROUP  = 12
  118. SMI_DECL_MODULECOMPLIANCE   = 13
  119. SMI_DECL_AGENTCAPABILITIES  = 14
  120. SMI_DECL_TEXTUALCONVENTION  = 15
  121. SMI_DECL_MACRO          = 16
  122. SMI_DECL_COMPL_GROUP        = 17
  123. SMI_DECL_COMPL_OBJECT       = 18
  124. SMI_DECL_IMPL_OBJECT        = 19    #/* object label in sth like "iso(1)" */
  125. #/* SMIng statements */
  126. SMI_DECL_MODULE             = 33
  127. SMI_DECL_EXTENSION          = 34
  128. SMI_DECL_TYPEDEF            = 35
  129. SMI_DECL_NODE               = 36
  130. SMI_DECL_SCALAR             = 37
  131. SMI_DECL_TABLE              = 38
  132. SMI_DECL_ROW                = 39
  133. SMI_DECL_COLUMN             = 40
  134. SMI_DECL_NOTIFICATION       = 41
  135. SMI_DECL_GROUP              = 42
  136. SMI_DECL_COMPLIANCE         = 43
  137.  
  138.  
  139. #/* SmiIndexkind -- actual kind of a table row's index method                 */
  140. #typedef enum SmiIndexkind {
  141. SMI_INDEX_UNKNOWN           = 0
  142. SMI_INDEX_INDEX             = 1
  143. SMI_INDEX_AUGMENT           = 2
  144. SMI_INDEX_REORDER           = 3
  145. SMI_INDEX_SPARSE            = 4
  146. SMI_INDEX_EXPAND            = 5
  147. #/* SmiLanguage -- language of an actual MIB module
  148. #typedef enum SmiLanguage
  149. SMI_LANGUAGE_UNKNOWN                = 0  # should not occur            
  150. SMI_LANGUAGE_SMIV1                  = 1
  151. SMI_LANGUAGE_SMIV2                  = 2
  152. SMI_LANGUAGE_SMING                  = 3
  153. SMI_LANGUAGE_SPPI                   = 4
  154.  
  155. class SmiValue_u(Union):
  156.     """See SmiValue"""
  157.     _fields_ = [("unsigned64",SmiUnsigned64),
  158.                 ("integer64",SmiInteger64),
  159.                 ("unsigned32",SmiUnsigned32),
  160.                 ("integer32",SmiInteger32),
  161.                 ("float32",SmiFloat32),
  162.                 ("float64",SmiFloat64),
  163.                 ("float128",SmiFloat128),
  164.                 ("oid",POINTER(SmiSubid)),
  165.                 ("ptr",POINTER(c_ubyte)),]
  166.  
  167. class SmiValue(Structure):
  168.     """
  169.    typedef struct SmiValue {
  170.        SmiBasetype             basetype;
  171.         unsigned int        len;         /* OID, OctetString, Bits           */
  172.        union {
  173.            SmiUnsigned64       unsigned64;
  174.            SmiInteger64        integer64;
  175.            SmiUnsigned32       unsigned32;
  176.            SmiInteger32        integer32;
  177.            SmiFloat32          float32;
  178.            SmiFloat64          float64;
  179.            SmiFloat128         float128;
  180.             SmiSubid        *oid;
  181.             unsigned char       *ptr;    /* OctetString, Bits                */
  182.        } value;
  183.    } SmiValue;
  184.    """
  185.     _fields_ = [("basetype",c_uint),
  186.                 ("len",c_uint), # OID, OctetString, Bits
  187.                 ("value",SmiValue_u),]
  188.  
  189. class SmiNode(Structure):
  190.     """
  191.    typedef struct SmiNode {
  192.        SmiIdentifier       name;
  193.         unsigned int    oidlen;
  194.         SmiSubid        *oid;         /* array of length oidlen */
  195.        SmiDecl             decl;
  196.        SmiAccess           access;
  197.        SmiStatus           status;
  198.        char                *format;
  199.        SmiValue            value;
  200.        char                *units;
  201.        char                *description;
  202.        char                *reference;
  203.        SmiIndexkind        indexkind;    /* only valid for rows */
  204.        int                 implied;      /* only valid for rows */
  205.        int                 create;       /* only valid for rows */
  206.        SmiNodekind         nodekind;
  207.    } SmiNode;
  208.    """
  209.     _fields_ = [("name",SmiIdentifier),
  210.                 ("oidlen",c_uint),
  211.                 ("oid",POINTER(SmiSubid)),
  212.                 ("decl",c_uint),
  213.                 ("access",c_uint),
  214.                 ("status",c_uint),
  215.                 ("format",POINTER(c_char_p)),
  216.                 ("value",SmiValue),
  217.                 ("units",POINTER(c_char_p)),
  218.                 ("description",POINTER(c_char_p)),
  219.                 ("reference",POINTER(c_char_p)),
  220.                 ("indexkind",c_uint),
  221.                 ("implied",c_int),
  222.                 ("create",c_int),
  223.                 ("nodekind",SmiNodekind),]
  224.  
  225. # SmiModule -- the main structure of a module
  226. class SmiModule(Structure):
  227.     """
  228.    typedef struct SmiModule {
  229.        SmiIdentifier       name;
  230.        char                *path;
  231.        char                *organization;
  232.        char                *contactinfo;
  233.        char                *description;
  234.        char                *reference;
  235.         SmiLanguage     language;
  236.        int                 conformance;
  237.    } SmiModule;
  238.    """
  239.     _fields_ = [("name",SmiIdentifier),
  240.                 ("path",POINTER(c_char_p)),
  241.                 ("organization",POINTER(c_char_p)),
  242.                 ("contactinfo",POINTER(c_char_p)),
  243.                 ("description",POINTER(c_char_p)),
  244.                 ("reference",POINTER(c_char_p)),
  245.                 ("language",SmiLanguage),
  246.                 ("conformance",c_uint),]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement