bool read_node = false; read: read_node = reader.Read(); no_read: if( !read_node ) { // at end of available reading material, it seems. throw new Xmpp.ProtocolException("No stream:stream element found!"); } else if( reader.NodeType == XmlNodeType.None ) { throw new Xmpp.Exception("WTF"); } else if( reader.NodeType == XmlNodeType.XmlDeclaration ) { // Read another node off the top of the stack. goto read; } else if( reader.NodeType == XmlNodeType.Element && reader.Name == "stream:stream" ) { if(log.IsDebugEnabled) log.Debug("Found stream:stream opening element..."); /* Only thing I care about in stream-opening element is xmpp version... If this call returns false, throw an exception because the version attribute is missing. */ if( !reader.MoveToAttribute("version") ) { throw new Xmpp.ProtocolException( "Server failed to specify Xmpp version!"); } else if( log.IsDebugEnabled ) { log.Debug("Found \"version\" attribute for stream:stream element"); } // Don't call Read(), MoveToAttribute() already read a new node. goto no_read; } else if( reader.NodeType == XmlNodeType.Attribute && reader.Name == "version" ) { if( reader.Value != "1.0" ) { throw new Xmpp.ProtocolException( String.Format("Bad version \"{0}\"!", reader.Value)); } // Go to next stage. goto end; } end: /* this is used to parse the first TWO (!!) elements of following: 0000 00 00 03 04 00 00 00 00 00 00 00 00 00 00 08 00 ................ 0010 45 00 02 74 68 ac 40 00 40 06 d1 d5 7f 00 00 01 E..th.@.@....... 0020 7f 00 00 01 d7 b6 87 9d 64 63 22 81 63 88 e2 c5 ........dc".c... 0030 80 18 20 00 00 69 00 00 01 01 08 0a dc 50 4a 34 .. ..i.......PJ4 0040 dc 50 4a 33 3c 3f 78 6d 6c 20 76 65 72 73 69 6f .PJ3CRAM-MD5 0190 3c 2f 6d 65 63 68 61 6e 69 73 6d 3e 3c 6d 65 63 DIGEST-MD 01b0 35 3c 2f 6d 65 63 68 61 6e 69 73 6d 3e 3c 6d 65 5PLAINANONYMOUS */