Example #1
0
        private void BeginStream()
        {
            OnConnected();
            parser        = new AsyncXmlParser();
            parser.Origin = fConnection;
            fState        = XMPP.State.Connected;
            fServerRoot   = null;
            parser.ReadXmlElementAsync(new Action <XmlParserResult>(GotData), false);

            fRootElement    = new ClientStream();
            fRootElement.To = new JID(Domain);

            BeginSend(fRootElement, WriteMode.Open, null);
            BeginTimeout();
        }
Example #2
0
        private void GotData(XmlParserResult data)
        {
            bool lStopReading = false;

            switch (data.Type)
            {
            case XmlParserResultType.Error:
                SendStreamError(new StreamError {
                    Error = ((XmlErrorResult)data).Error
                });
                return;

            case XmlParserResultType.Node:
                XmlNodeResult nd = (XmlNodeResult)data;
                switch (nd.NodeType)
                {
                case XmlNodeType.XmlInfo: break;         // who cares about that?

                case XmlNodeType.Single:
                    if (fServerElementStack.Count == 0)
                    {
                        SendStreamError(new StreamError {
                            Error = StreamErrorKind.InvalidXml
                        });
                        return;
                    }
                    Element el = CreateNode(nd, fServerElementStack[fServerElementStack.Count - 1]);
                    if (this.fServerElementStack.Count <= 1)
                    {
                        lStopReading = GotFirstLevelElement(el);
                    }
                    break;

                case XmlNodeType.Open:
                    el = CreateNode(nd, fServerElementStack.Count == 0 ? null : fServerElementStack[fServerElementStack.Count - 1]);
                    this.fServerElementStack.Add(el);
                    if (this.fServerElementStack.Count == 1)
                    {
                        GotRootLevelElement(el);
                    }

                    break;

                case XmlNodeType.Close:
                    if (fServerElementStack.Count == 0 || !fServerElementStack[fServerElementStack.Count - 1].Matches(nd.Prefix, nd.Name))
                    {
                        SendStreamError(new StreamError {
                            Error = StreamErrorKind.InvalidXml
                        });
                        return;
                    }
                    el = fServerElementStack[fServerElementStack.Count - 1];
                    fServerElementStack.RemoveAt(fServerElementStack.Count - 1);
                    if (fServerElementStack.Count == 0)
                    {
                        Close();
                        break;
                    }
                    if (fServerElementStack.Count == 1)
                    {
                        lStopReading = GotFirstLevelElement(el);
                    }
                    break;
                }
                break;

            case XmlParserResultType.Text:
                if (fServerElementStack.Count == 0)
                {
                    // discard
                }
                else
                {
                    fServerElementStack[fServerElementStack.Count - 1].Text += ((XmlTextResult)data).Text;
                }
                break;
            }
            if (!lStopReading)
            {
                parser.ReadXmlElementAsync(new Action <XmlParserResult>(GotData), fServerElementStack.Count > 0);
            }
        }