//
        // Constructor & finalizer
        //
        internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings)
        {
            Debug.Assert(writer != null);
            Debug.Assert(settings != null);
            Debug.Assert(MaxNamespacesWalkCount <= 3);

            _writer = writer;

            _rawWriter = writer as XmlRawWriter;
            _predefinedNamespaces = writer as IXmlNamespaceResolver;
            if (_rawWriter != null)
            {
                _rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
            }

            _checkCharacters = settings.CheckCharacters;
            _omitDuplNamespaces = (settings.NamespaceHandling & NamespaceHandling.OmitDuplicates) != 0;
            _writeEndDocumentOnClose = settings.WriteEndDocumentOnClose;

            _conformanceLevel = settings.ConformanceLevel;
            _stateTable = (_conformanceLevel == ConformanceLevel.Document) ? s_stateTableDocument : s_stateTableAuto;

            _currentState = State.Start;

            _nsStack = new Namespace[NamespaceStackInitialSize];
            _nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
            _nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
            if (_predefinedNamespaces == null)
            {
                _nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
            }
            else
            {
                string defaultNs = _predefinedNamespaces.LookupNamespace(string.Empty);
                _nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
            }
            _nsTop = 2;

            _elemScopeStack = new ElementScope[ElementStackInitialSize];
            _elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, _nsTop);
            _elemScopeStack[0].xmlSpace = XmlSpace.None;
            _elemScopeStack[0].xmlLang = null;
            _elemTop = 0;

            _attrStack = new AttrName[AttributeArrayInitialSize];

            _hasher = new SecureStringHasher();
        }
        public XmlSqlBinaryReader(System.IO.Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings) {
            unicode = System.Text.Encoding.Unicode;
            xmlCharType = XmlCharType.Instance;

            this.xnt = settings.NameTable;
            if (this.xnt == null) {
                this.xnt = new NameTable();
                this.xntFromSettings = false;
            }
            else {
                this.xntFromSettings = true;
            }
            this.xml = this.xnt.Add("xml");
            this.xmlns = this.xnt.Add("xmlns");
            this.nsxmlns = this.xnt.Add(XmlReservedNs.NsXmlNs);
            this.baseUri = baseUri;
            this.state = ScanState.Init;
            this.nodetype = XmlNodeType.None;
            this.token = BinXmlToken.Error;
            this.elementStack = new ElemInfo[16];
            //this.elemDepth = 0;
            this.attributes = new AttrInfo[8];
            this.attrHashTbl = new int[8];
            //this.attrCount = 0;
            //this.attrIndex = 0;
            this.symbolTables.Init();
            this.qnameOther.Clear();
            this.qnameElement.Clear();
            this.xmlspacePreserve = false;
            this.hasher = new SecureStringHasher();
            this.namespaces = new Dictionary<String, NamespaceDecl>(hasher);
            AddInitNamespace(String.Empty, String.Empty);
            AddInitNamespace(this.xml, this.xnt.Add(XmlReservedNs.NsXml));
            AddInitNamespace(this.xmlns, this.nsxmlns);
            this.valueType = TypeOfString;
            // init buffer position, etc
            this.inStrm = stream;
            if (data != null) {
                Debug.Assert(len >= 2 && (data[0] == 0xdf && data[1] == 0xff));
                this.data = data;
                this.end = len;
                this.pos = 2;
                this.sniffed = true;
            }
            else {
                this.data = new byte[XmlReader.DefaultBufferSize];
                this.end = stream.Read(this.data, 0, XmlReader.DefaultBufferSize);
                this.pos = 0;
                this.sniffed = false;
            }

            this.mark = -1;
            this.eof = (0 == this.end);
            this.offset = 0;
            this.closeInput = closeInput;
            switch (settings.ConformanceLevel) {
                case ConformanceLevel.Auto:
                    this.docState = 0; break;
                case ConformanceLevel.Fragment:
                    this.docState = 9; break;
                case ConformanceLevel.Document:
                    this.docState = 1; break;
            }
            this.checkCharacters = settings.CheckCharacters;
            this.dtdProcessing = settings.DtdProcessing;
            this.ignoreWhitespace = settings.IgnoreWhitespace;
            this.ignorePIs = settings.IgnoreProcessingInstructions;
            this.ignoreComments = settings.IgnoreComments;

            if (TokenTypeMap == null)
                GenerateTokenTypeMap();
        }
 public int GetNSHashCode(SecureStringHasher hasher) {
     return hasher.GetHashCode(this.namespaceUri) ^ hasher.GetHashCode(this.localname);
 }
 public int GetLocalnameAndNamespaceUriAndHash(SecureStringHasher hasher, out string localname, out string namespaceUri) {
     localname = this.name.localname;
     namespaceUri = this.name.namespaceUri;
     return this.hashCode = this.name.GetNSHashCode(hasher);
 }
Example #5
0
 public SecureStringHasherTests()
 {
     this.secureStringHasher = new SecureStringHasher();
 }
        public XmlSqlBinaryReader(Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings)
        {
            this.xnt = settings.NameTable;
            if (this.xnt == null)
            {
                this.xnt = new System.Xml.NameTable();
                this.xntFromSettings = false;
            }
            else
            {
                this.xntFromSettings = true;
            }
            this.xml = this.xnt.Add("xml");
            this.xmlns = this.xnt.Add("xmlns");
            this.nsxmlns = this.xnt.Add("http://www.w3.org/2000/xmlns/");
            this.baseUri = baseUri;
            this.state = ScanState.Init;
            this.nodetype = XmlNodeType.None;
            this.token = BinXmlToken.Error;
            this.elementStack = new ElemInfo[0x10];
            this.attributes = new AttrInfo[8];
            this.attrHashTbl = new int[8];
            this.symbolTables.Init();
            this.qnameOther.Clear();
            this.qnameElement.Clear();
            this.xmlspacePreserve = false;
            this.hasher = new SecureStringHasher();
            this.namespaces = new Dictionary<string, NamespaceDecl>(this.hasher);
            this.AddInitNamespace(string.Empty, string.Empty);
            this.AddInitNamespace(this.xml, this.xnt.Add("http://www.w3.org/XML/1998/namespace"));
            this.AddInitNamespace(this.xmlns, this.nsxmlns);
            this.valueType = TypeOfString;
            this.inStrm = stream;
            if (data != null)
            {
                this.data = data;
                this.end = len;
                this.pos = 2;
                this.sniffed = true;
            }
            else
            {
                this.data = new byte[0x1000];
                this.end = stream.Read(this.data, 0, 0x1000);
                this.pos = 0;
                this.sniffed = false;
            }
            this.mark = -1;
            this.eof = 0 == this.end;
            this.offset = 0L;
            this.closeInput = closeInput;
            switch (settings.ConformanceLevel)
            {
                case ConformanceLevel.Auto:
                    this.docState = 0;
                    break;

                case ConformanceLevel.Fragment:
                    this.docState = 9;
                    break;

                case ConformanceLevel.Document:
                    this.docState = 1;
                    break;
            }
            this.checkCharacters = settings.CheckCharacters;
            this.dtdProcessing = settings.DtdProcessing;
            this.ignoreWhitespace = settings.IgnoreWhitespace;
            this.ignorePIs = settings.IgnoreProcessingInstructions;
            this.ignoreComments = settings.IgnoreComments;
            if (TokenTypeMap == null)
            {
                this.GenerateTokenTypeMap();
            }
        }
        //
        // Constructor & finalizer
        //
        internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings) {
            Debug.Assert(writer != null);
            Debug.Assert(settings != null);
            Debug.Assert(MaxNamespacesWalkCount <= 3);

            this.writer = writer;

            rawWriter = writer as XmlRawWriter;
            predefinedNamespaces = writer as IXmlNamespaceResolver;
            if (rawWriter != null) {
                rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
            }

            checkCharacters = settings.CheckCharacters;

            conformanceLevel = settings.ConformanceLevel;
            stateTable = (conformanceLevel == ConformanceLevel.Document) ? StateTableDocument : StateTableAuto;

            currentState = State.Start;

            nsStack = new Namespace[NamespaceStackInitialSize];
            nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
            nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
            if (predefinedNamespaces == null) {
                nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
            }
            else {
                string defaultNs = predefinedNamespaces.LookupNamespace(string.Empty);
                nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
            }
            nsTop = 2;

            elemScopeStack = new ElementScope[ElementStackInitialSize];
            elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, nsTop);
            elemScopeStack[0].xmlSpace = XmlSpace.None;
            elemScopeStack[0].xmlLang = null;
            elemTop = 0;

            attrStack = new AttrName[AttributeArrayInitialSize];

            attrValue = new StringBuilder();

            hasher = new SecureStringHasher();
        }
 internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings)
 {
     this.writer = writer;
     this.rawWriter = writer as XmlRawWriter;
     this.predefinedNamespaces = writer as IXmlNamespaceResolver;
     if (this.rawWriter != null)
     {
         this.rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
     }
     this.checkCharacters = settings.CheckCharacters;
     this.omitDuplNamespaces = (settings.NamespaceHandling & NamespaceHandling.OmitDuplicates) != NamespaceHandling.Default;
     this.conformanceLevel = settings.ConformanceLevel;
     this.stateTable = (this.conformanceLevel == ConformanceLevel.Document) ? StateTableDocument : StateTableAuto;
     this.currentState = State.Start;
     this.nsStack = new Namespace[8];
     this.nsStack[0].Set("xmlns", "http://www.w3.org/2000/xmlns/", NamespaceKind.Special);
     this.nsStack[1].Set("xml", "http://www.w3.org/XML/1998/namespace", NamespaceKind.Special);
     if (this.predefinedNamespaces == null)
     {
         this.nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
     }
     else
     {
         string str = this.predefinedNamespaces.LookupNamespace(string.Empty);
         this.nsStack[2].Set(string.Empty, (str == null) ? string.Empty : str, NamespaceKind.Implied);
     }
     this.nsTop = 2;
     this.elemScopeStack = new ElementScope[8];
     this.elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, this.nsTop);
     this.elemScopeStack[0].xmlSpace = System.Xml.XmlSpace.None;
     this.elemScopeStack[0].xmlLang = null;
     this.elemTop = 0;
     this.attrStack = new AttrName[8];
     this.hasher = new SecureStringHasher();
 }