Beispiel #1
0
        /// <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>
 /// Validates a MIB type. This will check any sequences and make
 /// sure their elements are present in the MIB file. If they are
 /// not, new symbols will be added to the MIB.
 /// </summary>
 /// <param name="symbol">The MIB symbol containing this type</param>
 /// <param name="log">The MIB loader log</param>
 /// <param name="type">The MIB type to check</param>
 /// <exception cref="MibException">
 /// If an error was encountered during the validation
 /// </exception>
 private static void CheckType(
     MibValueSymbol symbol,
     MibLoaderLog log,
     MibType type)
 {
     if (type is SequenceOfType sequence)
     {
         SnmpObjectType.CheckType(symbol, log, sequence.ElementType);
     }
     else if (type is SequenceType tp)
     {
         IList <ElementType> elems = tp.AllElements.ToList();
         for (int i = 0; i < elems.Count(); i++)
         {
             SnmpObjectType.CheckElement(symbol, log, elems[i], i + 1);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Validates an element type. This will check that the element
        /// is present in the MIB file. If it is not, a new symbol will be
        /// added to the MIB.
        /// </summary>
        /// <param name="symbol">The MIB symbol containing this type</param>
        /// <param name="log">The MIB Loader log</param>
        /// <param name="element">The MIB element type to check</param>
        /// <param name="pos">The MIB element position</param>
        /// <exception cref="MibException">
        /// If an error was encountered during the validation
        /// </exception>
        private static void CheckElement(
            MibValueSymbol symbol,
            MibLoaderLog log,
            ElementType element,
            int pos)
        {
            Mib                   mib = symbol.Mib;
            MibSymbol             elementSymbol;
            string                name;
            MibType               type;
            ObjectIdentifierValue value;

            elementSymbol = mib.GetSymbol(element.Name);

            if (elementSymbol == null)
            {
                if (element.Name != null)
                {
                    name = pos + " '" + element.Name + "'";
                }
                else
                {
                    name = pos.ToString();
                }

                string msg = "sequence element " + name + " is undefined " +
                             "in MIB, a default symbol will be created";
                log.AddWarning(symbol.Location, msg);

                name = element.Name;

                if (name == null)
                {
                    name = symbol.Name + "." + pos;
                }

                type = new SnmpObjectType(
                    element.Type,
                    null,
                    SnmpAccess.ReadOnly,
                    SnmpStatus.CURRENT,
                    "AUTOMATICALLY CREATED SYMBOL",
                    null,
                    new List <SnmpIndex>(),
                    null);

                value = (ObjectIdentifierValue)symbol.Value;
                value = new ObjectIdentifierValue(
                    symbol.Location,
                    value,
                    element.Name,
                    pos);

                elementSymbol = new MibValueSymbol(
                    symbol.Location,
                    mib,
                    name,
                    type,
                    value);
                elementSymbol.Initialize(log);
            }
            else if (elementSymbol is MibTypeSymbol)
            {
                if (element.Name != null)
                {
                    name = pos + " '" + element.Name + "'";
                }
                else
                {
                    name = pos.ToString();
                }

                throw new MibException(
                          symbol.Location,
                          "sequence element " + name + " does not refer to a value, but to a type");
            }
        }