예제 #1
0
        /// <summary>
        /// Asks the provisioning server if a JID is a friend or not.
        /// </summary>
        /// <param name="JID">JID</param>
        /// <param name="Callback">Method to call when response is received.</param>
        /// <param name="State">State object to pass to callback method.</param>
        public void IsFriend(string JID, IsFriendCallback Callback, object State)
        {
            if ((!string.IsNullOrEmpty(this.ownerJid) && string.Compare(JID, this.ownerJid, true) == 0) ||
                string.Compare(JID, this.provisioningServerAddress, true) == 0)
            {
                if (Callback != null)
                {
                    try
                    {
                        IqResultEventArgs         e0 = new IqResultEventArgs(null, string.Empty, this.client.FullJID, this.provisioningServerAddress, true, State);
                        IsFriendResponseEventArgs e  = new IsFriendResponseEventArgs(e0, State, JID, true);

                        Callback(this.client, e);
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                }

                return;
            }

            this.CachedIqGet("<isFriend xmlns='" + NamespaceProvisioningDevice + "' jid='" +
                             XML.Encode(JID) + "'/>", this.IsFriendCallback, new object[] { Callback, State });
        }
예제 #2
0
        private void IsFriendCallback(object Sender, IqResultEventArgs e)
        {
            object[]         P        = (object[])e.State;
            IsFriendCallback Callback = (IsFriendCallback)P[0];
            object           State    = P[1];
            string           JID;
            bool             Result;
            XmlElement       E = e.FirstElement;

            if (e.Ok && E != null && E.LocalName == "isFriendResponse" && E.NamespaceURI == NamespaceProvisioningDevice)
            {
                JID    = XML.Attribute(E, "jid");
                Result = XML.Attribute(E, "result", false);
            }
            else
            {
                Result = false;
                JID    = null;
            }

            IsFriendResponseEventArgs e2 = new IsFriendResponseEventArgs(e, State, JID, Result);

            try
            {
                Callback(this, e2);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }
        }
        private void IsFriendResponse(XmppClient Client, string Type, XmlNodeList Response, ref StanzaError Error, object State)
        {
            object[]         P        = (object[])State;
            IsFriendCallback Callback = (IsFriendCallback)P [0];
            object           State2   = (object)P [1];
            string           Hash     = (string)P [2];
            bool             IsFriend = false;
            bool             SecondaryTrustAllowed = false;
            string           Jid = string.Empty;
            XmlElement       E;

            if (Error != null)
            {
                Error = null;
            }
            else if (Response != null)
            {
                if (Hash != null)
                {
                    this.AddToCache(Hash, Response);
                }

                foreach (XmlNode N in Response)
                {
                    if (N.LocalName == "isFriendResponse" && (E = N as XmlElement) != null)
                    {
                        Jid      = XmlUtilities.GetAttribute(E, "jid", string.Empty);
                        IsFriend = XmlUtilities.GetAttribute(E, "result", false);
                        SecondaryTrustAllowed = XmlUtilities.GetAttribute(E, "secondaryTrustAllowed", false);
                        break;
                    }
                }
            }

            IsFriendEventArgs e = new IsFriendEventArgs(Jid, IsFriend, SecondaryTrustAllowed, State2);

            if (Callback != null)
            {
                try
                {
                    Callback(e);
                } catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            }
        }
        /// <summary>
        /// Determines whether a Jid is a friend of the current device.
        /// </summary>
        /// <param name="Jid">JID to check.</param>
        /// <param name="Callback">Callback method to call, when the response is available.</param>
        /// <param name="State">State object to pass on to the response callback.</param>
        public void IsFriend(string Jid, IsFriendCallback Callback, object State)
        {
            Jid = XmppClient.StripResource(Jid);

            if (Jid == this.address)
            {
                if (Callback != null)
                {
                    IsFriendEventArgs e = new IsFriendEventArgs(Jid, true, false, State);

                    try
                    {
                        Callback(e);
                    } catch (Exception ex)
                    {
                        Log.Exception(ex);
                    }
                }
            }
            else
            {
                string      Xml   = "<isFriend xmlns='urn:xmpp:iot:provisioning' jid='" + Jid + "'/>";
                string      Hash  = this.CalcHash(Xml);
                StanzaError Error = null;
                XmlNodeList Response;

                if ((Response = this.GetCachedResponse(Hash)) != null)
                {
                    this.IsFriendResponse(this.client, string.Empty, Response, ref Error, new object[] { Callback, State, null });
                }
                else
                {
                    this.client.IqGet(Xml, this.address, this.IsFriendResponse, new object[] { Callback, State, Hash }, "Is Friend?");
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Asks the provisioning server if a JID is a friend or not.
 /// </summary>
 /// <param name="JID">JID</param>
 /// <param name="Callback">Method to call when response is received.</param>
 /// <param name="State">State object to pass to callback method.</param>
 public void IsFriend(string JID, IsFriendCallback Callback, object State)
 {
     this.client.SendIqGet(this.provisioningServerAddress, "<isFriend xmlns='" + NamespaceProvisioning + "' jid='" +
                           XML.Encode(JID) + "'/>", this.IsFriendCallback, new object[] { Callback, State });
 }