예제 #1
0
            /// <summary>
            /// Parses the MIB input source and returns the MIB modules
            /// found. This method will read the MIB either from file, URL
            /// or input stream.
            /// </summary>
            /// <param name="loader">The MIB loader to use for imports</param>
            /// <param name="log">The MIB log to use for errors</param>
            /// <returns>The list of MIB modules created</returns>
            /// <exception cref="IOException">If the MIB couldn't be found</exception>
            /// <exception cref="MibLoaderException">
            /// If the MIB couldn't be parsed correctly
            /// </exception>
            public IList <Mib> ParseMib(MibLoader loader, MibLoaderLog log)
            {
                string result = string.Empty;

                // Open input stream
                if (this.input != null)
                {
                    result = this.input.ReadToEnd();
                }
                else if (this.url != null)
                {
                    using (var client = new System.Net.WebClient())
                    {
                        result = client.DownloadString(this.url);
                    }
                }
                else
                {
                    using (TextReader reader = System.IO.File.OpenText(this.File))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                using (this.input = new StringReader(result))
                {
                    // Parse input stream
                    MibAnalyzer analyzer = new MibAnalyzer(this.File, loader, log);
                    try
                    {
                        if (parser == null)
                        {
                            Asn1Tokenizer tokenizer = new Asn1Tokenizer(this.input);
                            parser = new Asn1Parser(tokenizer, analyzer);
                            parser.Tokenizer.UseTokenList = true;
                        }
                        else
                        {
                            parser.Reset(this.input, analyzer);
                        }

                        parser.Parse();
                        return(analyzer.Mibs.ToList());
                    }
                    catch (ParserCreationException e)
                    {
                        log.AddInternalError(this.File, "parser creation error in ASN.1 parser: " + e.Message);
                        analyzer.Reset();
                        throw new MibLoaderException(log);
                    }
                    catch (ParserLogException e)
                    {
                        log.AddAll(this.File, e);
                        analyzer.Reset();
                        throw new MibLoaderException(log);
                    }
                }
            }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MibImport"/> class.
 /// </summary>
 /// <param name="loader">The MIB Loader to be used</param>
 /// <param name="location">The import location</param>
 /// <param name="name">The imported MIB's name</param>
 /// <param name="symbols">The imported MIB symbol names</param>
 public MibImport(
     MibLoader loader,
     FileLocation location,
     string name,
     IList <MibSymbol> symbols)
 {
     this.loader   = loader;
     this.location = location;
     this.name     = name;
     this.symbols  = symbols;
 }
예제 #3
0
        /// <summary>
        /// Clears and prepares this MIB for garbage collection. This method
        /// will recursively clear all associated symbols, making sure that
        /// no data structures references symbols from this MIB. Obviously,
        /// this method shouldn't be called unless all dependant MIBs have
        /// been cleared first.
        /// </summary>
        public void Clear()
        {
            this.loader = null;
            this.log    = null;

            if (this.imports != null)
            {
                this.imports.Clear();
            }

            this.imports = null;
            if (this.symbolList != null)
            {
                foreach (MibSymbol symbol in this.symbolList)
                {
                    symbol.Clear();
                }

                this.symbolList.Clear();
            }

            this.symbolList = null;

            if (this.symbolNameMap != null)
            {
                this.symbolNameMap.Clear();
            }

            this.symbolNameMap = null;

            if (this.symbolValueMap != null)
            {
                this.symbolValueMap.Clear();
            }

            this.symbolValueMap = null;
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mib"/> class.
 /// This will NOT read the actual MIB file, but only creates
 /// an empty container. The symbols are then added during the
 /// first analysis pass (of two), leaving symbols in the MIB
 /// possibly containing unresolved references.
 /// A separate call to Initialize() must be made once all
 /// referenced MIB modules have also been loaded.
 /// </summary>
 /// <param name="file">The MIB file name</param>
 /// <param name="loader">The MIB loader to use for imports</param>
 /// <param name="log">The MIB log to use for errors</param>
 /// <see cref="Initialize"/>
 public Mib(string file, MibLoader loader, MibLoaderLog log)
 {
     this.file   = file;
     this.loader = loader;
     this.log    = log;
 }