4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
|
0917d3 | 2013-03-04 | Anders Johansson | |
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
constant INTERNET_OID = ({ 1, 3, 6, 1 });
constant RIS_OID = INTERNET_OID + ({ 4, 1, 8614 });
constant RIS_OID_WEBSERVER = RIS_OID + ({ 1, 1 });
class Documentation(string name,
string doc)
{
}
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | class Updateable(function(:mixed) fun)
{
void update_value()
{
if (fun) {
|
a396fb | 2007-10-25 | Henrik Grubbström (Grubba) | | mixed val = fun();
if (
#if __VERSION__ < 7.6
intp(val)
#else
0
#endif
) {
this_object()->value = Gmp.mpz(val);
} else {
this_object()->value = val;
}
|
7f54e7 | 2007-09-12 | Henrik Grubbström (Grubba) | | this_object()->der = UNDEFINED;
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
}
}
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | class OwnerInfo
{
Configuration conf;
RoxenModule module;
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
class app_integer
{
|
792b83 | 2014-06-27 | Henrik Grubbström (Grubba) | | inherit Standards.ASN1.Types.Integer : integer;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Documentation : doc;
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Updateable : update;
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | inherit OwnerInfo : owner_info;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "APPLICATION INTEGER";
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
constant cls = 1;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 0;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int cls = 1;
int tag = 0;
#endif
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(int|function(:int) val, string|void name,
string|void doc_string)
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | {
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | if (intp(val)) {
update::create(UNDEFINED);
integer::create(val);
} else {
update::create(val);
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | integer::create(0);
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | doc::create(name, doc_string);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
|
a54a1b | 2007-10-25 | Henrik Grubbström (Grubba) | | switch(t) {
case 's': return (string)value;
default: return sprintf("%s[%d][%d](%O)", type_name, cls, tag, value);
}
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | }
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class app_octet_string
{
|
792b83 | 2014-06-27 | Henrik Grubbström (Grubba) | | inherit Standards.ASN1.Types.OctetString : octet_string;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Documentation : doc;
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Updateable : update;
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | inherit OwnerInfo : owner_info;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "APPLICATION OCTET_STRING";
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
constant cls = 1;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 0;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int cls = 1;
int tag = 0;
#endif
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(string|function(:string) val, string|void name,
string|void doc_string)
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | {
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | if (stringp(val)) {
update::create(UNDEFINED);
octet_string::create(val);
} else {
update::create(val);
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | octet_string::create("");
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | doc::create(name, doc_string);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
|
a54a1b | 2007-10-25 | Henrik Grubbström (Grubba) | | switch(t) {
case 's': return (string)value;
default: return sprintf("%s[%d][%d](%O)", type_name, cls, tag, value);
}
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | }
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class OID
{
|
792b83 | 2014-06-27 | Henrik Grubbström (Grubba) | | inherit Standards.ASN1.Types.Identifier : identifier;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Documentation : doc;
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | inherit OwnerInfo : owner_info;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "OID";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(array(int) oid, string|void name,
string|void doc_string)
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | {
identifier::create(@oid);
doc::create(name, doc_string);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
|
a54a1b | 2007-10-25 | Henrik Grubbström (Grubba) | | switch(t) {
case 's': return ((array(string))id) * ".";
default: return sprintf("%s[%d][%d](%O)",
type_name, cls, tag,
((array(string))id) * ".");
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | }
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class Integer
{
|
792b83 | 2014-06-27 | Henrik Grubbström (Grubba) | | inherit Standards.ASN1.Types.Integer : integer;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Documentation : doc;
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Updateable : update;
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | inherit OwnerInfo : owner_info;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "INTEGER";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(int|function(:int) val, string|void name,
string|void doc_string)
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | {
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | if (intp(val)) {
update::create(UNDEFINED);
integer::create(val);
} else {
update::create(val);
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | integer::create(0);
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | doc::create(name, doc_string);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
|
a54a1b | 2007-10-25 | Henrik Grubbström (Grubba) | | switch(t) {
case 'd':
case 's': return (string)value;
default: return sprintf("%s[%d][%d](%O)", type_name, cls, tag, value);
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | }
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class String
{
|
792b83 | 2014-06-27 | Henrik Grubbström (Grubba) | | inherit Standards.ASN1.Types.OctetString : octet_string;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Documentation : doc;
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | inherit Updateable : update;
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | inherit OwnerInfo : owner_info;
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "STRING";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(string|function(:string) val, string|void name,
string|void doc_string)
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | {
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | if (stringp(val)) {
update::create(UNDEFINED);
octet_string::create(val);
} else {
update::create(val);
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | octet_string::create("");
|
304d30 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | doc::create(name, doc_string);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
|
a54a1b | 2007-10-25 | Henrik Grubbström (Grubba) | | switch(t) {
case 's': return (string)value;
default: return sprintf("%s[%d][%d](%O)",
type_name, cls, tag, (string)value);
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | }
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class Counter
{
inherit app_integer;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 1;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int tag = 1;
#endif
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "COUNTER";
}
class Gauge
{
inherit app_integer;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 2;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int tag = 2;
#endif
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "GAUGE";
}
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | |
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | class Tick
{
inherit app_integer;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 3;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int tag = 3;
#endif
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "TICK";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
if (t == 's') {
|
39fa2e | 2010-11-25 | Henrik Grubbström (Grubba) | | return Roxen.short_date((int)(time(1) - value/100));
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | }
return ::_sprintf(t);
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class Opaque
{
inherit app_octet_string;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 4;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int tag = 4;
#endif
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "OPAQUE";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf(int t)
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
if (t == 's') return "";
return ::_sprintf(t);
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
class Counter64
{
inherit app_integer;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant tag = 6;
|
6b1d4d | 2014-06-25 | Henrik Grubbström (Grubba) | | #else
int tag = 6;
#endif
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | constant type_name = "COUNTER64";
}
|
87b18e | 2014-06-25 | Henrik Grubbström (Grubba) | | #if __VERSION__ < 8.0
constant ContextOctetString =
Protocols.LDAP.ldap_privates.asn1_context_octet_string;
constant ContextSequence =
Protocols.LDAP.ldap_privates.asn1_context_sequence;
#else
class ContextOctetString
{
inherit Standards.ASN1.Types.OctetString;
int cls = 2;
constant type_name = "CONTEXT OCTET STRING";
protected void create(int tag, string(8bit) val)
{
this_program::tag = tag;
::create(val);
}
}
class ContextSequence
{
inherit Standards.ASN1.Types.Sequence;
int cls = 2;
constant type_name = "CONTEXT SEQUENCE";
protected void create(int tag, array arg)
{
this_program::tag = tag;
::create(arg);
}
}
#endif
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
|
87b18e | 2014-06-25 | Henrik Grubbström (Grubba) | | ContextOctetString NO_SUCH_OBJECT = ContextOctetString(0, "");
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
|
87b18e | 2014-06-25 | Henrik Grubbström (Grubba) | | ContextOctetString NO_SUCH_INSTANCE = ContextOctetString(1, "");
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
|
87b18e | 2014-06-25 | Henrik Grubbström (Grubba) | | ContextOctetString END_OF_MIB = ContextOctetString(2, "");
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | |
Counter NULL_COUNTER = Counter(0);
class SimpleMIB
{
inherit ADT.Trie;
|
bc077a | 2010-05-04 | Henrik Grubbström (Grubba) | | protected void init(array(int) oid,
array(int) oid_suffix,
array(Standards.ASN1.Types.Object|
function|array|mapping)|
mapping(int:Standards.ASN1.Types.Object|
function|array|mapping) values)
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | {
|
bc077a | 2010-05-04 | Henrik Grubbström (Grubba) | | foreach(values; int i;
function|Standards.ASN1.Types.Object|array|mapping val) {
if (arrayp(val) || mappingp(val)) {
|
b02fc8 | 2010-05-04 | Henrik Grubbström (Grubba) | | init(oid + ({ i }), oid_suffix, val);
|
bc077a | 2010-05-04 | Henrik Grubbström (Grubba) | | } else if (!zero_type(val)) {
|
747c74 | 2007-09-14 | Henrik Grubbström (Grubba) | | insert(oid + ({ i }) + oid_suffix + ({ 0 }), val);
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | }
}
}
|
bc077a | 2010-05-04 | Henrik Grubbström (Grubba) | | protected void create(array(int) oid,
array(int) oid_suffix,
array(Standards.ASN1.Types.Object|
function|array|mapping)|
mapping(int:Standards.ASN1.Types.Object|
function|array|mapping) values)
{
::create(oid);
init(oid, oid_suffix, values);
}
|
4e36d4 | 2007-09-10 | Henrik Grubbström (Grubba) | | 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;
}
}
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | |
|
c4f246 | 2007-11-03 | Henrik Grubbström (Grubba) | | void set_owner(ADT.Trie mib, Configuration conf, RoxenModule|void module)
{
array(int) oid = mib->first();
while (oid) {
Standards.ASN1.Types.Object o = mib->lookup(oid);
catch {
o->conf = conf;
if (module) {
o->module = module;
}
};
oid = mib->next(oid);
}
}
void remove_owned(ADT.Trie mib, Configuration conf, RoxenModule|void module)
{
array(int) oid = mib->first();
while(oid) {
Standards.ASN1.Types.Object o = mib->lookup(oid);
if (objectp(o) && (o->conf == conf) &&
(!module || (o->module == module))) {
mib->remove(oid);
}
oid = mib->next(oid);
}
}
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | #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 * ".";
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create()
|
ddfdc0 | 2007-10-25 | Henrik Grubbström (Grubba) | | {
add_oid_path(RIS_OID_WEBSERVER,
"iso.organizations.dod.internet.private."
"enterprises.roxenis.app.webserver");
}
#endif /* 0 */
|