/// <summary> /// Checks if one MIB value is less than another. /// </summary> /// <param name="strict">The strict less than flag</param> /// <param name="value1">The first value</param> /// <param name="value2">The second value</param> /// <returns> /// True if the first value is less than the second, /// false if not /// </returns> private bool IsLessThan( bool strict, MibValue value1, MibValue value2) { NumberValue nv1 = value1 as NumberValue; NumberValue nv2 = value2 as NumberValue; if (value1 != null && value2 != null) { return(this.IsLessThan( strict, nv1.Value, nv2.Value)); } StringValue s1 = value1 as StringValue; StringValue s2 = value2 as StringValue; if (s1 != null && s2 != null) { return(this.IsLessThan( strict, s1.ToString(), s2.ToString())); } else { return(false); } }
/// <summary> /// Clears and prepares this value for garbage collection. This /// method will recursively clear any associated types or values, /// making sure that no data structures references this object. /// </summary> /// <remarks> /// This is an internal method that should /// only be called by the MIB loader. /// </remarks> public override void Clear() { // Recursively clear all children in same MIB if (this.children != null) { foreach (var c in this.children) { c.Clear(); } } // Remove parent reference if all children were cleared if (this.ChildCount <= 0) { if (this.parent != null) { this.Parent.children.Remove(this); this.parent = null; } this.children = null; } // Clear other value data this.symbol = null; base.Clear(); }
/// <summary> /// Initializes the MIB type. This will remove all levels of /// indirection present, such as references to types or values. No /// information is lost by this operation. This method may modify /// this object as a side-effect, and will return the basic /// type. /// NOTE: This is an internal method that should /// only be called by the MIB loader. /// </summary> /// <param name="symbol">The MIB symbol containing this type</param> /// <param name="log">The MIB loader log</param> /// <returns>The basic MIB type</returns> public override MibType Initialize(MibSymbol symbol, MibLoaderLog log) { if (!(symbol is MibValueSymbol)) { throw new MibException( symbol.Location, "only values can have the " + Name + " type"); } this.syntax = this.syntax.Initialize(symbol, log); SnmpObjectType.CheckType((MibValueSymbol)symbol, log, this.syntax); foreach (SnmpIndex si in this.index) { si.Initialize(symbol, log); } if (this.augments != null) { this.augments = this.augments.Initialize(log, this.syntax); } if (this.defaultValue != null) { this.defaultValue = this.defaultValue.Initialize(log, this.syntax); } return(this); }
/// <summary> /// Checks if the specified value is compatible with this type. A /// value is compatible if and only if it is an numeric value /// representing positive or negative infinity /// </summary> /// <param name="value">The value to check</param> /// <returns>True if the value is compatible, false if not</returns> public override bool IsCompatible(MibValue value) { if (value is RealValue number) { return(double.IsInfinity(number.Value)); } return(false); }
/// <summary> /// Compare this value to another MIB Value /// </summary> /// <param name="other">The MIB Value to compare against</param> /// <returns> /// Zero (0) if the objects are equal, an non-zero integer value if not /// </returns> public override int CompareTo(MibValue other) { if (other is NumberValue nv) { return(this.CompareToNumber(nv.value)); } return(this.ToString().CompareTo(other)); }
/// <summary> /// Compare this value to another MIB Value /// </summary> /// <param name="other">The MIB Value to compare against</param> /// <returns> /// Zero (0) if the objects are equal, an non-zero integer value if not /// </returns> public override int CompareTo(MibValue other) { if (!(other is BooleanValue bv)) { return(1); } return(bv.value == this.value ? 0 : 1); }
/// <summary> /// Checks if this object equals another object. This method will /// compare the string representations for equality. /// </summary> /// <param name="obj">The object to compare with</param> /// <returns>True if the objects are equal, false otherwise</returns> public override bool Equals(object obj) { MibValue mv = obj as MibValue; if (mv == null) { return(false); } return(this.CompareTo(mv) == 0); }
/// <summary> /// Compare this value to another MIB Value /// </summary> /// <param name="other">The MIB Value to compare against</param> /// <returns> /// Zero (0) if the objects are equal, an non-zero integer value if not /// </returns> public override int CompareTo(MibValue other) { BooleanValue bv = other as BooleanValue; if (bv == null) { return(1); } return(bv.value == this.value ? 0 : 1); }
/// <summary> /// Initializes a new instance of the <see cref="SnmpTrapType"/> class. /// </summary> /// <param name="enterprise">the enterprise value</param> /// <param name="variables">The list of MIB values</param> /// <param name="description">The type description or null</param> /// <param name="reference">The type reference or null</param> public SnmpTrapType( MibValue enterprise, IList <MibValue> variables, string description, string reference) : base("TRAP-TYPE", description) { this.enterprise = enterprise; this.variables = variables; this.reference = reference; }
/// <summary> /// Checks if the specified value is compatible with this type. A /// value is compatible if and only if it is an numeric value /// representing positive or negative infinity /// </summary> /// <param name="value">The value to check</param> /// <returns>True if the value is compatible, false if not</returns> public override bool IsCompatible(MibValue value) { RealValue number = value as RealValue; if (number != null) { return(double.IsInfinity(number.Value)); } return(false); }
/// <summary> /// Compare this value to another MIB Value /// </summary> /// <param name="other">The MIB Value to compare against</param> /// <returns> /// Zero (0) if the objects are equal, an non-zero integer value if not /// </returns> public override int CompareTo(MibValue other) { NumberValue nv = other as NumberValue; if (nv != null) { return(this.CompareToNumber((double)nv.Value)); } return(this.ToString().CompareTo(other)); }
/// <summary> /// Initializes the object. This will remove all levels of /// indirection present, such as references to other types and /// values.No information is lost by this operation.This method /// may modify this object as a side-effect, and will be called by /// the MIB loader. /// </summary> /// <param name="symbol">the MIB symbol containing this object</param> /// <param name="log">the MIB loader log</param> /// <exception cref="MibException"> /// If an error was encountered during the initialization /// </exception> public void Initialize(MibSymbol symbol, MibLoaderLog log) { if (this.value != null) { this.value = this.value.Initialize(log, null); } if (this.type != null) { this.type = this.type.Initialize(symbol, log); } }
/// <summary> /// Checks if the specified value is compatible with this /// constraint.Only octet string values can be compatible with a /// size constraint, and only if the string length is compatible /// with the value range in the size constraint. /// </summary> /// <param name="value">The value to check</param> /// <returns>True if the value is compatible, false if not</returns> public bool IsCompatible(MibValue value) { int size; if (value is StringValue) { size = value.ToString().Length; return(this.values.IsCompatible(new NumberValue((BigInteger)size))); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="ObjectIdentifierValue"/> class. /// </summary> /// <param name="location">The declaration file location</param> /// <param name="parent">The component parent</param> /// <param name="name">The component name</param> /// <param name="value">The component value</param> public ObjectIdentifierValue( FileLocation location, ValueReference parent, string name, int value) : base("OBJECT IDENTIFIER") { this.location = location; this.parent = parent; this.name = name; this.value = value; }
/// <summary> /// Checks if the specified value is compatible with this type. A /// values is considered compatible with this type, if it is /// compatible with any single type in the union. /// </summary> /// <param name="value">The value to check</param> /// <returns>True if the value is compatible, false if not</returns> public override bool IsCompatible(MibValue value) { foreach (ElementType elem in this.elements) { if (elem.IsCompatible(value)) { return(true); } } return(false); }
/// <summary> /// Initializes the MIB type. This will remove all levels of /// indirection present, such as references to types or values. No /// information is lost by this operation. This method may modify /// this object as a side-effect, and will return the basic /// type. /// NOTE: This is an internal method that should /// only be called by the MIB loader. /// </summary> /// <param name="symbol">The MIB symbol containing this type</param> /// <param name="log">The MIB loader log</param> /// <returns>The basic MIB type</returns> /// <exception cref="MibException"> /// If an error was encountered during the initialization /// </exception> public override MibType Initialize(MibSymbol symbol, MibLoaderLog log) { if (!(symbol is MibValueSymbol)) { throw new MibException( symbol.Location, "only values can have the " + Name + " type"); } this.enterprise = this.enterprise.Initialize(log, null); this.variables = this.variables.Select(v => v.Initialize(log, null)).ToList(); return(this); }
/// <summary> /// Initializes the MIB type. This will remove all levels of /// indirection present, such as references to types or values. No /// information is lost by this operation. This method may modify /// this object as a side-effect, and will return the basic /// type. /// NOTE: This is an internal method that should /// only be called by the MIB loader. /// </summary> /// <param name="type">The MIB type</param> /// <param name="log">The MIB loader log</param> /// <exception cref="MibException"> /// If an error is encountered during initialization /// </exception> public void Initialize(MibType type, MibLoaderLog log) { string message; this.value = this.value.Initialize(log, type); if (this.location != null && !this.IsCompatible(type)) { message = "Value constraint not compatible with this type"; log.AddWarning(this.location, message); } this.location = null; }
/// <summary> /// Initializes this object. This will remove all levels of /// indirection present, such as references to other types, and /// returns the basic type. No type information is lost by this /// operation. This method may modify this object as a /// side-effect, and will be called by the MIB loader. /// </summary> /// <param name="log">The MIB loader log</param> /// <exception cref="MibException"> /// If an error was encountered during the initialization /// </exception> public void Initialize(MibLoaderLog log) { this.value = this.value.Initialize(log, null); if (this.syntax != null) { this.syntax = this.syntax.Initialize(null, log); } if (this.writeSyntax != null) { this.writeSyntax = this.writeSyntax.Initialize(null, log); } }
/// <summary> /// Initializes a the MIB value from a value reference. This will /// resolve the reference, and set the bit corresponding to the /// value. /// </summary> /// <param name="log">The MIB loader log</param> /// <param name="type">The value type</param> /// <param name="vref">The value reference to resolve</param> /// <exception cref="MibException"> /// If an error occurred during initialization /// </exception> private void Initialize(MibLoaderLog log, MibType type, ValueReference vref) { MibValue val = vref.Initialize(log, type); if (val is NumberValue nv) { this.value.Set((int)nv.Value, true); } else { throw new MibException( vref.Location, "referenced value is not a number"); } }
/// <summary> /// Initializes a new instance of the <see cref="SnmpCompliance"/> class. /// </summary> /// <param name="group">The group compliance flag</param> /// <param name="value">The compliance value</param> /// <param name="syntax">The value syntax, or null</param> /// <param name="writeSyntax">The value write syntax, or null</param> /// <param name="access">The access mode, or null</param> /// <param name="description">The compliance description</param> public SnmpCompliance( bool group, MibValue value, MibType syntax, MibType writeSyntax, SnmpAccess access, string description) { this.group = group; this.value = value; this.syntax = syntax; this.writeSyntax = writeSyntax; this.access = access; this.description = description; }
/// <summary> /// Initializes a new instance of the <see cref="SnmpVariation"/> class. /// </summary> /// <param name="value">the variation value</param> /// <param name="syntax">the value syntax, or null</param> /// <param name="writeSyntax">the value write syntax, or null</param> /// <param name="access">the access mode, or null</param> /// <param name="requiredCells">the cell values required for creation</param> /// <param name="defaultValue">the default value, or null</param> /// <param name="description">the variation description</param> public SnmpVariation( MibValue value, MibType syntax, MibType writeSyntax, SnmpAccess access, IList <MibValue> requiredCells, MibValue defaultValue, string description) { this.value = value; this.syntax = syntax; this.writeSyntax = writeSyntax; this.access = access; this.requiredCells = requiredCells; this.defaultValue = defaultValue; this.description = description; }
/// <summary> /// Initializes a new instance of the <see cref="ObjectIdentifierValue"/> class. /// </summary> /// <param name="location">The declaration file location</param> /// <param name="parent">The component parent</param> /// <param name="name">The component name</param> /// <param name="value">The component value</param> /// <exception cref="MibException"> /// If the object identifier parent already has a child with /// the specified value /// </exception> public ObjectIdentifierValue( FileLocation location, ObjectIdentifierValue parent, string name, int value) : base("OBJECT IDENTIFIER") { this.parent = parent; this.name = name; this.value = value; if (parent.GetChildByValue(value) != null) { throw new MibException( location, "cannot add duplicate OID children with value " + value); } parent.AddChild(null, location, this); }
/// <summary> /// Initializes the MIB value. This will remove all levels of /// indirection present, such as references to other values. No /// value information is lost by this operation. This method may /// modify this object as a side-effect, and will return the basic /// value. /// </summary> /// <remarks> /// This is an internal method that should /// only be called by the MIB loader. /// </remarks> /// <param name="log">The MIB Loader log</param> /// <param name="type">The value type</param> /// <returns>The basic MIB value</returns> public override MibValue Initialize(MibLoaderLog log, MibType type) { ValueReference vref = null; ObjectIdentifierValue oid; if (this.parent == null) { return(this); } else if (this.parent is ValueReference) { vref = (ValueReference)this.parent; } this.parent = this.parent.Initialize(log, type); if (vref != null) { if (this.parent is ObjectIdentifierValue) { oid = (ObjectIdentifierValue)this.parent; oid.AddChild(log, this.location, this); } else { throw new MibException( vref.Location, "referenced value is not an object identifier"); } } this.location = null; if (this.parent is ObjectIdentifierValue) { return(((ObjectIdentifierValue)this.parent).GetChildByValue(this.value)); } else { return(this); } }
/// <summary> /// Checks if the specified value is compatible with this /// constraint. /// </summary> /// <param name="value">The value to check</param> /// <returns>True if the value is compatible, or /// false otherwise /// </returns> public bool IsCompatible(MibValue value) { string str1 = this.value.ToString(); string str2 = value.ToString(); if (this.value is NumberValue && value is NumberValue) { return(str1.Equals(str2)); } else if (this.value is StringValue && value is StringValue) { return(str1.Equals(str2)); } else { return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="SnmpObjectType"/> class. /// </summary> /// <param name="syntax">The object type syntax</param> /// <param name="units">The units description, or null</param> /// <param name="access">The access mode</param> /// <param name="status">The type status</param> /// <param name="description">The type description, or null</param> /// <param name="reference">The type reference, or null</param> /// <param name="index">The list of index objects</param> /// <param name="defaultValue">The default value, or null</param> public SnmpObjectType( MibType syntax, string units, SnmpAccess access, SnmpStatus status, string description, string reference, IList <SnmpIndex> index, MibValue defaultValue) : base("OBJECT-TYPE", description) { this.syntax = syntax; this.units = units; this.access = access; this.status = status; this.reference = reference; this.index = index; this.augments = null; this.defaultValue = defaultValue; }
/// <summary> /// Initializes the object. This will remove all levels of /// indirection present, such as references to other types, and /// returns the basic type. No information is lost by this operation. /// This method may modify this object as a side-effect, and will /// be called by the MIB loader. /// </summary> /// <param name="log">The MIB loader log</param> /// <exception cref="MibException"> /// If an error occurred during initialization /// </exception> public void Initialize(MibLoaderLog log) { MibType type = null; this.value = this.value.Initialize(log, null); if (this.BaseSymbol != null) { // TODO: use utility function to retrieve correct base type here type = this.BaseSymbol.Type; if (type is SnmpTextualConvention convention) { type = convention.Syntax; } if (type is SnmpObjectType type1) { type = type1.Syntax; } } if (this.syntax != null) { this.syntax = this.syntax.Initialize(null, log); } if (this.writeSyntax != null) { this.writeSyntax = this.writeSyntax.Initialize(null, log); } this.requiredCells = this.requiredCells.Select(rc => rc.Initialize(log, type)).ToList(); if (this.defaultValue != null) { this.defaultValue = this.defaultValue.Initialize(log, type); } }
/// <summary> /// Checks if the specified value is compatible with this type. /// The value is considered compatible with this type, if and only /// if it is a null value /// </summary> /// <param name="value">The value to check</param> /// <returns>true if the value is compatible, false otherwise</returns> public override bool IsCompatible(MibValue value) { return(value is NullValue); }
/// <summary> /// Checks if the specified value is compatible with this type. A /// value is compatible if and only if it is an object identifier /// value. /// </summary> /// <param name="value">The value to check for compatibility</param> /// <returns>True if the value is compatible, false if not</returns> public override bool IsCompatible(MibValue value) { return(value is ObjectIdentifierValue); }
/// <summary> /// Checks if the specified value is compatible with this type. No /// value is compatible with this type, so this method always /// returns false. /// </summary> /// <param name="value">The value to check</param> /// <returns>True if the value is compatible, false if not</returns> public override bool IsCompatible(MibValue value) { return(false); }
/// <summary> /// Checks if the specified value is compatible with this type. A /// value is compatible if and only if it is a boolean value. /// </summary> /// <param name="value">The value to be checked</param> /// <returns>True if the value is compatible, false if not</returns> public override bool IsCompatible(MibValue value) { return(value is BooleanValue); }