Roxen.git / server / etc / modules / SNMP.pmod

version» Context lines:

Roxen.git/server/etc/modules/SNMP.pmod:1:   //   // SNMP helper stuff.   // - // $Id: SNMP.pmod,v 1.4 2007/09/14 11:23:37 grubba Exp $ + // $Id: SNMP.pmod,v 1.5 2007/10/25 12:43:44 grubba Exp $   //   // 2007-08-29 Henrik Grubbström   //      // Some OIDs      //! iso.organizations.dod.internet   constant INTERNET_OID = ({ 1, 3, 6, 1 });      //! iso.organizations.dod.internet.private.enterprises.roxenis
Roxen.git/server/etc/modules/SNMP.pmod:43:    constant cls = 1;    constant type_name = "APPLICATION INTEGER";    constant tag = 0;    static void create(int|function(:int) val, string|void name, string|void doc_string)    {    if (intp(val)) {    update::create(UNDEFINED);    integer::create(val);    } else {    update::create(val); -  integer::create(val()); +  integer::create(0);    }    doc::create(name, doc_string);    } -  +  static string _sprintf(int t) +  { +  if (t == 's') return (string)value; +  return ::_sprintf(t);    } -  + }      class app_octet_string   {    inherit Standards.ASN1.Types.asn1_octet_string : octet_string;    inherit Documentation : doc;    inherit Updateable : update;    constant cls = 1;    constant type_name = "APPLICATION OCTET_STRING";    constant tag = 0;    static void create(string|function(:string) val, string|void name, string|void doc_string)    {    if (stringp(val)) {    update::create(UNDEFINED);    octet_string::create(val);    } else {    update::create(val); -  octet_string::create(val()); +  octet_string::create("");    }    doc::create(name, doc_string);    } -  +  static string _sprintf(int t) +  { +  if (t == 's') return value; +  return ::_sprintf(t);    } -  + }      class OID   {    inherit Standards.ASN1.Types.asn1_identifier : identifier;    inherit Documentation : doc;    constant type_name = "OID";    static void create(array(int) oid, string|void name, string|void doc_string)    {    identifier::create(@oid);    doc::create(name, doc_string);    } -  +  static string _sprintf(int t) +  { +  if (t == 's') { +  return ((array(string))id) * ".";    } -  +  return ::_sprintf(t); +  } + }      class Integer   {    inherit Standards.ASN1.Types.asn1_integer : integer;    inherit Documentation : doc;    inherit Updateable : update;    constant type_name = "INTEGER";    static void create(int|function(:int) val, string|void name, string|void doc_string)    {    if (intp(val)) {    update::create(UNDEFINED);    integer::create(val);    } else {    update::create(val); -  integer::create(val()); +  integer::create(0);    }    doc::create(name, doc_string);    } -  +  static string _sprintf(int t) +  { +  if (t == 's' || t == 'd') { +  return (string)value;    } -  +  return ::_sprintf(t); +  } + }      class String   {    inherit Standards.ASN1.Types.asn1_octet_string : octet_string;    inherit Documentation : doc;    inherit Updateable : update;    constant type_name = "STRING";    static void create(string|function(:string) val, string|void name, string|void doc_string)    {    if (stringp(val)) {    update::create(UNDEFINED);    octet_string::create(val);    } else {    update::create(val); -  octet_string::create(val()); +  octet_string::create("");    }    doc::create(name, doc_string);    } -  +  static string _sprintf(int t) +  { +  if (t == 's') { +  return value;    } -  +  return ::_sprintf(t); +  } + }      class Counter   {    inherit app_integer;    constant tag = 1;    constant type_name = "COUNTER";   }      class Gauge   {    inherit app_integer;    constant tag = 2;    constant type_name = "GAUGE";   }    -  + //! One tick is 1/100 seconds.   class Tick   {    inherit app_integer;    constant tag = 3;    constant type_name = "TICK"; -  +  static string _sprintf(int t) +  { +  if (t == 'd') { +  return (string)value;    } -  +  if (t == 's') { +  return Roxen.short_date(time(1) + value/100); +  } +  return ::_sprintf(t); +  } + }      class Opaque   {    inherit app_octet_string;    constant tag = 4;    constant type_name = "OPAQUE"; -  +  static string _sprintf(int t) +  { +  if (t == 's') return ""; +  return ::_sprintf(t);    } -  + }      class Counter64   {    inherit app_integer;    constant tag = 6;    constant type_name = "COUNTER64";   }      //! No such object marker.   Protocols.LDAP.ldap_privates.asn1_context_octet_string NO_SUCH_OBJECT =
Roxen.git/server/etc/modules/SNMP.pmod:196:    }       Standards.ASN1.Types.Object lookup(array(int) key)    {    function|Standards.ASN1.Types.Object res = ::lookup(key);    if (zero_type(res)) return UNDEFINED;    if (functionp(res)) return res();    return res;    }   } +  + #if 0 // Not ready for production yet. +  + class Describer(string symbol) + { + } +  + class IndexDescriber + { +  inherit Describer; +  constant is_index = "int"; + } +  + class StringIndexDescriber + { +  inherit Describer; +  constant is_index = "string"; + } +  + class IndexedDescriber + { +  inherit Describer; +  constant index = "int"; + } +  + class StringIndexedDescriber + { +  inherit Describer; +  constant index = "string"; + } +  + ADT.Trie OID_ParseInfo = ADT.Trie(); +  + void add_oid_path(array(int) oid, string symbolic_oid) + { +  int i; +  foreach(symbolic_oid/".", string symbol) { +  if (i >= sizeof(oid)) return; +  if (sizeof(symbol)) { +  if (symbol[0] == '"') { +  OID_ParseInfo->insert(oid[..i], StringDescriber(symbol)); +  i += oid[i]; +  } else { +  OID_ParseInfo->insert(oid[..i], Describer(symbol)); +  } +  } +  i++; +  } + } +  + string format_oid(array(int) oid) + { +  ADT.Trie parse_info = OID_ParseInfo; +  +  int i; +  array(IndexDescriber) indexers = ({}); +  array(string) res = ({}); +  for (i=0; i < sizeof(oid); i++) { +  int j = i; +  while(i < parse_info->offset) { +  if (oid[i] != parse_info->path[i]) { +  i = j; +  break; +  } +  i++; +  } +  if (i < parse_info->offset) break; +  Describer desc = parse_info->value; +  switch(desc && desc->is_index) { +  case "string": +  if (i + oid[i] < sizeof(oid)) { +  res += ({ sprintf("%O", (string)oid[i+1..i+oid[i]]) }); +  i += oid[i]; +  break; +  } +  res += ({ (string)oid[i] }); +  break; +  case 0: +  if (desc->symbol) { +  res += desc->symbol; +  break; +  } +  case "int": +  default: +  res += ({ (string)oid[i] }); +  } +  if (desc && desc->index) { +  indexers += ({ desc }); +  } +  while (parse_info && parse_info->offset < i) { +  parse_info = parse_info->trie[oid[parse_info->offset]]; +  } +  if (parse_info) break; +  } +  return res * "."; + } +  + static void create() + { +  add_oid_path(RIS_OID_WEBSERVER, +  "iso.organizations.dod.internet.private." +  "enterprises.roxenis.app.webserver"); + } +  + #endif /* 0 */