/// <summary> /// Process an Stream Features XMPP message /// </summary> /// <param name = "features"></param> private void ProcessStreamFeatures(StreamFeatures features) { if (features.Mechanisms != null && features.Mechanisms.SaslMechanisms.Count > 0) { foreach (string mechanism in features.Mechanisms.SaslMechanisms) { switch (mechanism) { case XmppCodes.SaslDigestMD5Mechanism: streamFeatures |= XmppStreamFeatures.SaslDigestMD5; break; case XmppCodes.SaslPlainMechanism: streamFeatures |= XmppStreamFeatures.SaslPlain; break; case XmppCodes.SaslXGoogleTokenMechanism: streamFeatures |= XmppStreamFeatures.XGoogleToken; break; } } } if (features.Bind != null) { streamFeatures |= XmppStreamFeatures.ResourceBinding; } if (features.SessionSpecified) { streamFeatures |= XmppStreamFeatures.Sessions; } if (features.Items.Count > 0) { foreach (object item in features.Items) { if (item is RegisterIQ) { streamFeatures |= XmppStreamFeatures.InBandRegistration; } } } streamFeaturesEvent.Set(); }
/// <summary> /// Checks if a speficic stream feature is supported by the XMPP server. /// </summary> /// <param elementname = "feature">Feature to check.</param> /// <returns><b>true</b> if the feature is supported by the server; or <b>false</b> if not</returns> private bool SupportsFeature(XmppStreamFeatures feature) { return ((streamFeatures & feature) == feature); }
/// <summary> /// Closes the connection /// </summary> public void Close() { if (state != XmppConnectionState.Closed) { if (ConnectionClosing != null) { ConnectionClosing(this, new EventArgs()); } try { state = XmppConnectionState.Closing; if (transport != null) { transport.Close(); } } catch { } finally { if (initializedStreamEvent != null) { initializedStreamEvent.Set(); initializedStreamEvent = null; } if (streamFeaturesEvent != null) { streamFeaturesEvent.Set(); streamFeaturesEvent = null; } if (bindResourceEvent != null) { bindResourceEvent.Set(); bindResourceEvent = null; } if (initializedStreamEvent != null) { initializedStreamEvent.Close(); initializedStreamEvent = null; } if (streamFeaturesEvent != null) { streamFeaturesEvent.Close(); streamFeaturesEvent = null; } if (bindResourceEvent != null) { bindResourceEvent.Close(); bindResourceEvent = null; } if (transportMessageSubscription != null) { transportMessageSubscription.Dispose(); transportMessageSubscription = null; } if (transportStreamInitializedSubscription != null) { transportStreamInitializedSubscription.Dispose(); transportStreamInitializedSubscription = null; } if (transportStreamClosedSubscription != null) { transportStreamClosedSubscription.Dispose(); transportStreamClosedSubscription = null; } if (transport != null) { transport = null; } streamFeatures = streamFeatures & (~streamFeatures); state = XmppConnectionState.Closed; connectionString = null; userId = null; } if (ConnectionClosed != null) { ConnectionClosed(this, new EventArgs()); } } }
/// <summary> /// Closes the connection /// </summary> public void Close() { if (this.state != XmppConnectionState.Closed) { if (this.ConnectionClosing != null) { this.ConnectionClosing(this, new EventArgs()); } try { this.state = XmppConnectionState.Closing; if (this.transport != null) { this.transport.Close(); } } catch { } finally { if (this.initializedStreamEvent != null) { this.initializedStreamEvent.Set(); this.initializedStreamEvent = null; } if (this.streamFeaturesEvent != null) { this.streamFeaturesEvent.Set(); this.streamFeaturesEvent = null; } if (this.bindResourceEvent != null) { this.bindResourceEvent.Set(); this.bindResourceEvent = null; } if (this.initializedStreamEvent != null) { this.initializedStreamEvent.Close(); this.initializedStreamEvent = null; } if (this.streamFeaturesEvent != null) { this.streamFeaturesEvent.Close(); this.streamFeaturesEvent = null; } if (this.bindResourceEvent != null) { this.bindResourceEvent.Close(); this.bindResourceEvent = null; } if (this.transportMessageSubscription != null) { this.transportMessageSubscription.Dispose(); this.transportMessageSubscription = null; } if (this.transportStreamInitializedSubscription != null) { this.transportStreamInitializedSubscription.Dispose(); this.transportStreamInitializedSubscription = null; } if (this.transportStreamClosedSubscription != null) { this.transportStreamClosedSubscription.Dispose(); this.transportStreamClosedSubscription = null; } if (this.transport != null) { this.transport = null; } this.streamFeatures = this.streamFeatures & (~this.streamFeatures); this.state = XmppConnectionState.Closed; this.connectionString = null; this.userId = null; } if (this.ConnectionClosed != null) { this.ConnectionClosed(this, new EventArgs()); } } }
/// <summary> /// Checks if a speficic stream feature is supported by the XMPP server. /// </summary> /// <param elementname = "feature">Feature to check.</param> /// <returns><b>true</b> if the feature is supported by the server; or <b>false</b> if not</returns> private bool SupportsFeature(XmppStreamFeatures feature) { return((streamFeatures & feature) == feature); }