Esempio n. 1
0
        protected override byte [] EncodeSecurityState(byte [] src)
        {
            foreach (byte b in src)
            {
                Console.Write("{0:X02} ", b);
            }
            Console.WriteLine();
            // this show how it is LAMESPEC.
            //Array.Reverse (src);
            XmlDictionary dic = new XmlDictionary();

            for (int i = 0; i < 60; i++)
            {
                dic.Add("n" + i);
            }
            XmlDictionaryReaderQuotas quotas =
                new XmlDictionaryReaderQuotas();
            XmlDictionaryReader cr = XmlDictionaryReader.CreateBinaryReader(src, 0, src.Length, dic, quotas);

            cr.Read();
            XmlWriter w = XmlWriter.Create(Console.Out);

            while (!cr.EOF)
            {
                switch (cr.NodeType)
                {
                case XmlNodeType.Element:
                    int dummy;
                    w.WriteStartElement(cr.Prefix, cr.LocalName, cr.NamespaceURI);
                    for (int i = 0; i < cr.AttributeCount; i++)
                    {
                        cr.MoveToAttribute(i);
                        w.WriteStartAttribute(cr.Prefix, cr.LocalName, cr.NamespaceURI);
                        bool b64 = cr.LocalName == "n41";
                        while (cr.ReadAttributeValue())
                        {
                            if (b64)
                            {
                                foreach (byte b in Convert.FromBase64String(cr.Value))
                                {
                                    w.WriteString(String.Format("{0:X02}-", b));
                                }
                            }
                            else
                            {
                                w.WriteString(cr.Value);
                            }
                        }
                        w.WriteEndAttribute();
                    }
                    //w.WriteAttributes (cr, false);
                    cr.MoveToElement();
                    if (cr.IsEmptyElement)
                    {
                        w.WriteEndElement();
                    }
                    cr.Read();
                    break;

                case XmlNodeType.EndElement:
                    w.WriteEndElement();
                    cr.Read();
                    break;

                default:
                    if (cr.TryGetBase64ContentLength(out dummy))
                    {
                        foreach (byte b in cr.ReadContentAsBase64())
                        {
                            w.WriteString(String.Format("{0:X02} ", b));
                        }
                    }
                    else
                    {
                        w.WriteNode(cr, false);
                    }
                    break;
                }
            }
            w.Close();

            return(src);
        }
Esempio n. 2
0
 public override bool MoveToElement()
 {
     return(innerReader.MoveToElement());
 }
Esempio n. 3
0
        internal static void ReadAck(ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader, out UniqueId sequenceId, out SequenceRangeCollection rangeCollection, out bool final)
        {
            WsrmFeb2005Dictionary dictionary   = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString   namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement(dictionary.SequenceAcknowledgement, namespaceUri);
            reader.ReadStartElement(dictionary.Identifier, namespaceUri);
            sequenceId = reader.ReadContentAsUniqueId();
            reader.ReadEndElement();
            bool allowZero = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005;

            rangeCollection = SequenceRangeCollection.Empty;
            while (reader.IsStartElement(dictionary.AcknowledgementRange, namespaceUri))
            {
                reader.MoveToAttribute("Lower");
                long lower = WsrmUtilities.ReadSequenceNumber(reader, allowZero);
                reader.MoveToAttribute("Upper");
                long upper = WsrmUtilities.ReadSequenceNumber(reader, allowZero);
                if ((((lower < 0L) || (lower > upper)) || (((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && (lower == 0L)) && (upper > 0L))) || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && (lower == 0L)))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidSequenceRange", new object[] { lower, upper })));
                }
                rangeCollection = rangeCollection.MergeWith(new SequenceRange(lower, upper));
                reader.MoveToElement();
                WsrmUtilities.ReadEmptyElement(reader);
            }
            bool flag2 = rangeCollection.Count > 0;

            final = false;
            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                Wsrm11Dictionary dictionary2 = DXD.Wsrm11Dictionary;
                if (reader.IsStartElement(dictionary2.None, namespaceUri))
                {
                    if (flag2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, dictionary.SequenceAcknowledgement })));
                    }
                    WsrmUtilities.ReadEmptyElement(reader);
                    flag2 = true;
                }
                if (reader.IsStartElement(dictionary2.Final, namespaceUri))
                {
                    if (!flag2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, dictionary.SequenceAcknowledgement })));
                    }
                    WsrmUtilities.ReadEmptyElement(reader);
                    final = true;
                }
            }
            bool flag4 = false;

            while (reader.IsStartElement(dictionary.Nack, namespaceUri))
            {
                if (flag2)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, "Body" })));
                }
                reader.ReadStartElement();
                WsrmUtilities.ReadSequenceNumber(reader, true);
                reader.ReadEndElement();
                flag4 = true;
            }
            if (!flag2 && !flag4)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, "Body" })));
            }
        }
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            try
            {
                do
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            writer.WriteAttributeString(reader.LocalName, reader.NamespaceURI, reader.Value.Replace(sourcePattern, targetPattern));
                        }
                        reader.MoveToElement();
                        if (reader.IsEmptyElement)
                        {
                            writer.WriteEndElement();
                        }
                        break;

                    case XmlNodeType.Text:
                        writer.WriteString(reader.Value.Replace(sourcePattern, targetPattern));
                        break;

                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        writer.WriteWhitespace(reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        writer.WriteCData(reader.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        writer.WriteEntityRef(reader.Name);
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        writer.WriteProcessingInstruction(reader.Name, reader.Value);
                        break;

                    case XmlNodeType.DocumentType:
                        writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                        break;

                    case XmlNodeType.Comment:
                        writer.WriteComment(reader.Value);
                        break;

                    case XmlNodeType.EndElement:
                        writer.WriteFullEndElement();
                        break;
                    }
                }while (reader.Read());
                writer.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
Esempio n. 5
0
        protected override BodyWriter OnCreateBufferedCopy(
            int maxBufferSize)
        {
#if true
            if (xml_bak == null)
            {
                if (consumed)
                {
                    throw new InvalidOperationException("Body xml reader is already consumed");
                }
                var sw = new StringWriter();
                var xw = XmlDictionaryWriter.CreateDictionaryWriter(XmlWriter.Create(sw));
                xw.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                for (int i = 0; i < reader.AttributeCount; i++)
                {
                    reader.MoveToAttribute(i);
                    if (reader.NamespaceURI != "http://www.w3.org/2000/xmlns/" || xw.LookupPrefix(reader.Value) == null)
                    {
                        xw.WriteAttributeString(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value);
                    }
                }
                reader.MoveToElement();

                var inr = reader as IXmlNamespaceResolver;
                if (inr != null)
                {
                    foreach (var p in inr.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
                    {
                        if (xw.LookupPrefix(p.Value) != p.Key)
                        {
                            xw.WriteXmlnsAttribute(p.Key, p.Value);
                        }
                    }
                }
                if (!reader.IsEmptyElement)
                {
                    reader.Read();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        xw.WriteNode(reader, false);
                    }
                }
                xw.WriteEndElement();

                xw.Close();
                xml_bak = sw.ToString();
                reader  = null;
            }
#else // FIXME: this should be better, but somehow doesn't work.
            if (xml_bak == null)
            {
                if (consumed)
                {
                    throw new InvalidOperationException("Body xml reader is already consumed");
                }
                var nss = new XmlNamespaceManager(reader.NameTable);
                var nsr = reader as IXmlNamespaceResolver;
                if (nsr != null)
                {
                    foreach (var p in nsr.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
                    {
                        nss.AddNamespace(p.Key, p.Value);
                    }
                }
                parser_context = new XmlParserContext(nss.NameTable, nss, reader.XmlLang, reader.XmlSpace);
                xml_bak        = reader.ReadOuterXml();
            }
#endif
            return(new XmlReaderBodyWriter(xml_bak, maxBufferSize, parser_context));
        }