protected virtual void OnSendingServiceUnavailable(SendingServiceUnavailableEventArgs e)
 {
     if (SendingServiceUnavailable != null)
         SendingServiceUnavailable(this, e);
 }
Exemple #2
0
 void OnSendingServiceUnavailable(object sender, SendingServiceUnavailableEventArgs e)
 {
     if (e.Stanza.To == null) {
         // can only be received by the server
         return;
     }
     if (e.Stanza.To == JabberClient.MyJID.Server) {
         // explicitly targeting the server
         return;
     }
     XmppPersonModel person;
     if (!Contacts.TryGetValue(e.Stanza.To.Bare, out person)) {
         e.Cancel = true;
         return;
     }
     if (person.Subscription != SubscriptionType.both &&
         person.Subscription != SubscriptionType.from) {
         e.Cancel = true;
         return;
     }
     // the person already knows we are online, this does not give away our privacy
 }
        public override void StreamParserStreamElementNotHandled(object sender, UnhandledElementEventArgs eventArgs)
        {
            var stanza = eventArgs.Element as protocol.Base.StanzaWithError;
            if (stanza == null) {
                // what should we do here?
                return;
            }
            if (stanza.Error != null) {
                // don't respond to error messages with service unavailable
                return;
            }
            stanza.Error = new protocol.client.Error(ErrorCondition.ServiceUnavailable);
            stanza.SwitchDirection();

            // allow the client to prevent this message (privacy/security reasons)
            var ev = new SendingServiceUnavailableEventArgs(stanza);
            OnSendingServiceUnavailable(ev);
            if (ev.Cancel) {
                // the client has cancelled this
                return;
            }
            Send(eventArgs.Element);
        }