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?");
                }
            }
        }