Beispiel #1
0
        public void ModifyRoomConfig(Jid room, RegistrationCallback callback)
        {
            RequestForm form   = RequestRoomConfigForm(room);
            SubmitForm  submit = callback.Invoke(form);

            SubmitRoomConfigForm(room, submit);
        }
Beispiel #2
0
        public bool Input(Im.Message stanza)
        {
            if (MucError.IsError(stanza))
            {
                // Unable to send a message... many reasons
                var error = new MucError(stanza);
                MucErrorResponse?.Raise(this, new GroupErrorEventArgs(error));
                return(true);
            }

            if (Invite.IsElement(stanza))
            {
                // Incoming chat room invite
                var invite = new Invite(stanza);
                InviteReceived.Raise(this, new GroupInviteEventArgs(invite));
                return(true);
            }

            if (DirectInvite.IsElement(stanza))
            {
                // Incoming chat room invite
                var invite = new DirectInvite(stanza);
                InviteReceived.Raise(this, new GroupInviteEventArgs(invite));
                return(true);
            }


            if (InviteDeclined.IsElement(stanza))
            {
                // Chat room invite was declined
                var invite = new InviteDeclined(stanza);
                InviteWasDeclined.Raise(this, new GroupInviteDeclinedEventArgs(invite));
                return(true);
            }

            if (stanza.Subject != null)
            {
                // Subject change
                SubjectChanged.Raise(this, new Im.MessageEventArgs(stanza.From, stanza));
                return(true);
            }

            // Things that could happen here:
            // Receive Registration Request
            // Receive Voice Request
            XmlElement xElement = stanza.Data["x"];

            if (xElement != null && xElement.NamespaceURI == MucNs.NsXData)
            {
                switch (xElement.FirstChild.Value)
                {
                default:
                    break;

                case MucNs.NsRequest:
                    // Invoke Voice Request Submission callback/event.
                    // 8.6 Approving Voice Requests
                    if (VoiceRequested != null)
                    {
                        SubmitForm form    = VoiceRequested.Invoke(new RequestForm(xElement));
                        var        message = new Core.Message(stanza.From, im.Jid, form.ToXmlElement());
                        SendMessage(message);
                        return(true);
                    }
                    break;

                case MucNs.NsRegister:
                    // Invoke Registration Request Submission callback/event.
                    // 9.9 Approving Registration Requests
                    // I'm unsure on how to implement this.
                    // return true;
                    break;
                }
            }

            // Any message with a body can be managed by the IM extension
            // Such as Group Chat Message & Group Chat History
            return(false);
        }
        /// <summary>
        /// Registers a new XMPP account on the connected XMPP server.
        /// </summary>
        /// <param name="callback">A callback method invoked during the registration
        /// process to gather user information.</param>
        /// <exception cref="ArgumentNullException">The callback parameter is
        /// null.</exception>
        /// <exception cref="NotSupportedException">The XMPP entity with
        /// the specified JID does not support the 'In-Band Registration' XMPP
        /// extension.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        public void Register(RegistrationCallback callback)
        {
            callback.ThrowIfNull("callback");
            Iq iq = im.IqRequest(IqType.Get, null, null,
                                 Xml.Element("query", "jabber:iq:register"));

            if (iq.Type == IqType.Error)
            {
                throw new NotSupportedException("The XMPP server does not support the " +
                                                "'In-Band Registration' extension.");
            }
            var query = iq.Data["query"];

            if (query == null || query.NamespaceURI != "jabber:iq:register")
            {
                throw new XmppException("Erroneous server response: " + iq);
            }
            if (query["registered"] != null)
            {
                throw new XmppException("The XMPP entity is already registered.");
            }
            // If the IQ contains binary data, cache it.
            var data = query["data"];

            if (data != null && data.NamespaceURI == "urn:xmpp:bob")
            {
                BobData bobData = BobData.Parse(data);
                bob.Add(bobData);
            }
            RequestForm form  = null;
            bool        xdata = query["x"] != null;

            if (xdata)
            {
                form = DataFormFactory.Create(query["x"]) as RequestForm;
            }
            // "Traditional" registration, create a data-form off the provided fields.
            else
            {
                form = CreateDataForm(query);
            }
            // Hand the data-form to the caller to have it filled-out.
            var submit = callback.Invoke(form);
            // Construct the response element.
            var xml = Xml.Element("query", "jabber:iq:register");

            // Convert the data-form back to traditional fields if needed.
            if (xdata)
            {
                xml.Child(submit.ToXmlElement());
            }
            else
            {
                foreach (var field in submit.Fields)
                {
                    xml.Child(Xml.Element(field.Name).Text(
                                  field.Values.FirstOrDefault()));
                }
            }
            iq = im.IqRequest(IqType.Set, null, null, xml);
            if (iq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(iq, "The registration could not be " +
                                              "completed.");
            }
            // Reconnect.
        }
 /// <summary>
 /// Registers a new XMPP account on the connected XMPP server.
 /// </summary>
 /// <param name="callback">A callback method invoked during the registration
 /// process to gather user information.</param>
 /// <exception cref="ArgumentNullException">The callback parameter is
 /// null.</exception>
 /// <exception cref="NotSupportedException">The XMPP entity with
 /// the specified JID does not support the 'In-Band Registration' XMPP
 /// extension.</exception>
 /// <exception cref="XmppErrorException">The server returned an XMPP error code.
 /// Use the Error property of the XmppErrorException to obtain the specific
 /// error condition.</exception>
 /// <exception cref="XmppException">The server returned invalid data or another
 /// unspecified XMPP error occurred.</exception>
 public void Register(RegistrationCallback callback)
 {
     callback.ThrowIfNull("callback");
     Iq iq = IM.IqRequest(IqType.Get, null, null,
         Xml.Element("query", "jabber:iq:register"));
     if (iq.Type == IqType.Error)
         throw new NotSupportedException("The XMPP server does not support the " +
             "'In-Band Registration' extension.");
     var query = iq.Data["query"];
     if (query == null || query.NamespaceURI != "jabber:iq:register")
         throw new XmppException("Erroneous server response: " + iq);
     if (query["registered"] != null)
         throw new XmppException("The XMPP entity is already registered.");
     // If the IQ contains binary data, cache it.
     var data = query["data"];
     if (data != null && data.NamespaceURI == "urn:xmpp:bob")
     {
         BobData bobData = BobData.Parse(data);
         bob.Add(bobData);
     }
     RequestForm form = null;
     bool xdata = query["x"] != null;
     if (xdata)
         form = DataFormFactory.Create(query["x"]) as RequestForm;
     // "Traditional" registration, create a data-form off the provided fields.
     else
         form = CreateDataForm(query);
     // Hand the data-form to the caller to have it filled-out.
     var submit = callback.Invoke(form);
     // Construct the response element.
     var xml = Xml.Element("query", "jabber:iq:register");
     // Convert the data-form back to traditional fields if needed.
     if (xdata)
         xml.Child(submit.ToXmlElement());
     else
     {
         foreach (var field in submit.Fields)
         {
             xml.Child(Xml.Element(field.Name).Text(
                 field.Values.FirstOrDefault()));
         }
     }
     iq = IM.IqRequest(IqType.Set, null, null, xml);
     if (iq.Type == IqType.Error)
         throw Util.ExceptionFromError(iq, "The registration could not be " +
             "completed.");
     // Reconnect.
 }