Esempio n. 1
0
        public void Register(RegistrationCallback callback)
        {
            callback.ThrowIfNull <RegistrationCallback>("callback");
            Iq errorIq = base.im.IqRequest(IqType.Get, null, null, Xml.Element("query", "jabber:iq:register"), null, -1, "");

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

            if ((query == null) || (query.NamespaceURI != "jabber:iq:register"))
            {
                throw new XmppException("Erroneous server response: " + errorIq);
            }
            if (query["registered"] != null)
            {
                throw new XmppException("The XMPP entity is already registered.");
            }
            XmlElement element2 = query["data"];

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

            if (flag)
            {
                form = DataFormFactory.Create(query["x"]) as RequestForm;
            }
            else
            {
                form = this.CreateDataForm(query);
            }
            SubmitForm form2 = callback(form);
            XmlElement e     = Xml.Element("query", "jabber:iq:register");

            if (flag)
            {
                e.Child(form2.ToXmlElement());
            }
            else
            {
                foreach (DataField field in form2.Fields)
                {
                    e.Child(Xml.Element(field.Name, null).Text(field.Values.FirstOrDefault <string>()));
                }
            }
            errorIq = base.im.IqRequest(IqType.Set, null, null, e, null, -1, "");
            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The registration could not be completed.");
            }
        }
 /// <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.
 }
Esempio n. 3
0
        /// <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.
        }
Esempio n. 4
0
 /// <summary>
 /// Initiates in-band registration with the XMPP server in order to register
 /// a new XMPP account.
 /// </summary>
 /// <param name="callback">A callback method invoked to let the user
 /// enter any information required by the server in order to complete the
 /// registration.</param>
 /// <exception cref="ArgumentNullException">The callback parameter is
 /// null.</exception>
 /// <exception cref="NotSupportedException">The XMPP server with 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>
 /// <remarks>
 /// See the "Howto: Register an account" guide for a walkthrough on how to
 /// register an XMPP account through the in-band registration process.
 /// </remarks>
 public void Register(RegistrationCallback callback)
 {
     callback.ThrowIfNull("callback");
     inBandRegistration.Register(callback);
 }
Esempio n. 5
0
 public void Register(RegistrationCallback callback)
 {
     callback.ThrowIfNull <RegistrationCallback>("callback");
     this.inBandRegistration.Register(callback);
 }