int NodeStackDepth = 0; /// Used in case we have a node inside a node... ex: <iq><elemeent><iq><otherjunk>lksjdfl</otherjunk></iq></elemeent></iq> public void ParseStanzas(XMPPConnection connection, XMPPClient XMPPClient) { try { XMPPXMLNode objNode = null; while ((objNode = ReadNextBlock(false)) != null) { //System.Diagnostics.Debug.WriteLine(string.Format("**ReadNextBlock got: {0}, type: {1}", objNode.Name, objNode.NodeType)); if ((objNode.NodeType == XmlNodeType.XmlDeclaration) || (objNode.NodeType == XmlNodeType.Comment) || (objNode.NodeType == XmlNodeType.Whitespace)) { continue; } //for stream management XEP 0198// for request if (objNode.Name == "r") { XMPPClient.FireDelegateStreamManagementHandler(objNode.OuterXML.ToString()); } if ((objNode.NodeType == XmlNodeType.EndElement) && (objNode.Name == "stream:stream")) { Flush(); /// We've been closed, tell whoever /// connection.GracefulDisconnect(); } else if (objNode.Name == "stream:stream") { //System.Diagnostics.Debug.WriteLine("Got stream beggining fragment"); FoundStreamBeginning = true; To = objNode.GetAttribute("to"); From = objNode.GetAttribute("from"); Id = objNode.GetAttribute("id"); Version = objNode.GetAttribute("version"); Language = objNode.GetAttribute("xml:lang"); CurrentNodeName = null; //System.Diagnostics.Debug.WriteLine("Setting CurrentNodeName to null"); Flush(); //if (XMPPClient.XMPPState == XMPPState.Authenticated) // XMPPClient.XMPPState = XMPPState.CanBind; } else if ((objNode.NodeType == XmlNodeType.EndElement) && (CurrentNodeName == null)) /// Must be a complete element { string strXML = FlushGet(); //System.Diagnostics.Debug.WriteLine(string.Format("Got unpaired end fragment: {0}", strXML)); XMPPStanza stanza = new XMPPStanza(strXML); connection.FireStanzaReceived(stanza); } else { if (CurrentNodeName == null) { CurrentNodeName = objNode.Name; NodeStackDepth = 0; //System.Diagnostics.Debug.WriteLine(string.Format("Setting CurrentNodeName to : {0}", CurrentNodeName)); } else { if (objNode.Name == CurrentNodeName) /// Found the end tag { if (objNode.NodeType == XmlNodeType.EndElement) { if (NodeStackDepth == 0) { //System.Diagnostics.Debug.WriteLine(string.Format("Found End tag to CurrentNodeName: {0}, setting to null", CurrentNodeName)); // Extract all the text up to this position CurrentNodeName = null; string strXML = FlushGet(); XMPPStanza stanza = new XMPPStanza(strXML); connection.FireStanzaReceived(stanza); } else { NodeStackDepth--; } } else { //System.Diagnostics.Debug.WriteLine(string.Format("Found nested node with the same name as our CurrentNodeName, incrementing NodeStackDepth: {0}", CurrentNodeName)); NodeStackDepth++; } } } } } } catch (Exception) { } finally { } }