public void Disconnect() { LogMessage("Calling XMPPClient::Disconnect()"); if (XMPPConnection != null) { XMPPConnection.Disconnect(); XMPPConnection = null; } }
public void Connect(ILogInterface log) { LogMessage("Calling XMPPClient::Connect()"); string strCurrentAccountName = this.JID.BareJID.Replace("@", "").Replace(" ", "").Replace("/", "_").Replace("\\", ""); AvatarStorage.AccountFolder = strCurrentAccountName; if (this.XMPPAccount.AccountName == null) { this.XMPPAccount.AccountName = strCurrentAccountName; } this.RosterItems.Clear(); XMPPConnection = new XMPPConnection(this, log); XMPPConnection.OnStanzaReceived += new System.Net.XMPP.XMPPConnection.DelegateStanza(XMPPConnection_OnStanzaReceived); XMPPConnection.Connect(); }
public void ParseStanzas(XMPPConnection connection, XMPPClient XMPPClient) { try { string CurrentNodeName = null; XMPPXMLNode objNode = null; while ( (objNode = ReadNextBlock(false)) != null) { //System.Diagnostics.Debug.WriteLine("**ReadNextBlock got: {0}", objNode.Name); if ((objNode.NodeType == XmlNodeType.XmlDeclaration) || (objNode.NodeType == XmlNodeType.Comment) || (objNode.NodeType == XmlNodeType.Whitespace)) continue; 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("Got unpaired end fragment: {0}", strXML); XMPPStanza stanza = new XMPPStanza(strXML); connection.FireStanzaReceived(stanza); } else { if (CurrentNodeName == null) { CurrentNodeName = objNode.Name; //System.Diagnostics.Debug.WriteLine("Setting CurrentNodeName to : {0}", CurrentNodeName); } else { if (objNode.Name == CurrentNodeName) /// Found the end tag { //System.Diagnostics.Debug.WriteLine("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); } } } } } catch (Exception) { } finally { } }
public void ParseStanzas(XMPPConnection connection, XMPPClient XMPPClient) { try { string CurrentNodeName = null; XMPPXMLNode objNode = null; while ((objNode = ReadNextBlock(false)) != null) { //System.Diagnostics.Debug.WriteLine("**ReadNextBlock got: {0}", objNode.Name); if ((objNode.NodeType == XmlNodeType.XmlDeclaration) || (objNode.NodeType == XmlNodeType.Comment) || (objNode.NodeType == XmlNodeType.Whitespace)) { continue; } 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("Got unpaired end fragment: {0}", strXML); XMPPStanza stanza = new XMPPStanza(strXML); connection.FireStanzaReceived(stanza); } else { if (CurrentNodeName == null) { CurrentNodeName = objNode.Name; //System.Diagnostics.Debug.WriteLine("Setting CurrentNodeName to : {0}", CurrentNodeName); } else { if (objNode.Name == CurrentNodeName) /// Found the end tag { //System.Diagnostics.Debug.WriteLine("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); } } } } } catch (Exception) { } finally { } }