Ejemplo n.º 1
0
        private bool Respond(bool CanControl, string RuleXml, IqResultEventHandlerAsync Callback, object State)
        {
            StringBuilder Xml = new StringBuilder();

            Xml.Append("<canControlRule xmlns='");
            Xml.Append(ProvisioningClient.NamespaceProvisioningOwner);
            Xml.Append("' jid='");
            Xml.Append(XML.Encode(this.JID));
            Xml.Append("' remoteJid='");
            Xml.Append(XML.Encode(this.RemoteJID));
            Xml.Append("' key='");
            Xml.Append(XML.Encode(this.Key));
            Xml.Append("' result='");
            Xml.Append(CommonTypes.Encode(CanControl));
            Xml.Append("'>");
            Xml.Append(RuleXml);
            Xml.Append("</canControlRule>");

            RosterItem Item = this.Client.Client[this.FromBareJID];

            if (Item.HasLastPresence && Item.LastPresence.IsOnline)
            {
                this.Client.Client.SendIqSet(Item.LastPresenceFullJid, Xml.ToString(), Callback, State);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unsubscribes to updates to a given software package.
        /// </summary>
        /// <param name="FileName">Filename of software package. If using a <see cref="Wildcard"/>,
        /// events will be received when any software package is updated.</param>
        /// <param name="Callback">Method to call when response is returned.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        public void Unsubscribe(string FileName, IqResultEventHandlerAsync Callback, object State)
        {
            StringBuilder Xml = new StringBuilder();

            Xml.Append("<unsubscribe xmlns='");
            Xml.Append(NamespaceSoftwareUpdates);
            Xml.Append("' fileName='");
            Xml.Append(XML.Encode(FileName));
            Xml.Append("'/>");

            this.client.SendIqSet(this.componentAddress, Xml.ToString(), Callback, State);
        }
Ejemplo n.º 3
0
 private async Task CallCallback(IqResultEventHandlerAsync Callback, object State, IqResultEventArgs e)
 {
     if (!(Callback is null))
     {
         try
         {
             e.State = State;
             await Callback(this, e);
         }
         catch (Exception ex)
         {
             Log.Critical(ex);
         }
     }
 }
Ejemplo n.º 4
0
        internal PendingRequest(uint SeqNr, PresenceEventHandlerAsync Callback, object State, int RetryTimeout, int NrRetries, bool DropOff, int MaxRetryTimeout,
                                string To)
        {
            this.seqNr            = SeqNr;
            this.iqCallback       = null;
            this.presenceCallback = Callback;
            this.state            = State;
            this.retryTimeout     = RetryTimeout;
            this.nrRetries        = NrRetries;
            this.maxRetryTimeout  = MaxRetryTimeout;
            this.dropOff          = DropOff;
            this.to = To;

            this.timeout = DateTime.Now.AddMilliseconds(RetryTimeout);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Unblocks all JIDs
        /// </summary>
        /// <param name="Callback">Callback method.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        public async Task UnblockAll(IqResultEventHandlerAsync Callback, object State)
        {
            if (this.supportsBlocking)
            {
                this.client.SendIqSet(this.client.Domain, "<unblock xmlns='" + NamespaceBlocking + "'/>", async(sender, e) =>
                {
                    if (e.Ok)
                    {
                        lock (this.blockList)
                        {
                            this.blockList.Clear();
                        }
                    }

                    await this.CallCallback(Callback, State, e);
                }, null);
            }
            else
            {
                await this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, false, State));
            }
        }
Ejemplo n.º 6
0
        private void BeginSearchSupport()
        {
            Client.SendServiceDiscoveryRequest(Client.Domain, async(sender, e) =>
            {
                if (e.Ok)
                {
                    this.supportsBlocking    = e.HasFeature(NamespaceBlocking);
                    this.supportsReporting   = e.HasFeature(NamespaceReporting);
                    this.supportsSpamReason  = e.HasFeature(NamespaceSpamReason);
                    this.supportsAbuseReason = e.HasFeature(NamespaceAbuseReason);

                    if (this.supportsBlocking)
                    {
                        this.StartGetBlockList(null, null);
                    }
                }
                else
                {
                    this.supportsBlocking    = false;
                    this.supportsReporting   = false;
                    this.supportsSpamReason  = false;
                    this.supportsAbuseReason = false;
                }

                IqResultEventHandlerAsync h = this.OnSearchSupportResponse;
                if (!(h is null))
                {
                    try
                    {
                        await h(this, e);
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                }
            }, null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Unblocks a JID
        /// </summary>
        /// <param name="JID">JID to unblock.</param>
        /// <param name="Callback">Callback method.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        public async Task UnblockJID(string JID, IqResultEventHandlerAsync Callback, object State)
        {
            bool Blocked;

            lock (this.blockList)
            {
                if (!this.blockList.TryGetValue(JID, out Blocked))
                {
                    Blocked = false;
                }
            }

            if (!Blocked)
            {
                await this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, true, State));
            }
            else if (this.supportsBlocking)
            {
                this.client.SendIqSet(this.client.Domain, "<unblock xmlns='" + NamespaceBlocking + "'><item jid='" + JID + "'/></unblock>",
                                      async(sender, e) =>
                {
                    if (e.Ok)
                    {
                        lock (this.blockList)
                        {
                            this.blockList.Remove(JID);
                        }
                    }

                    await this.CallCallback(Callback, State, e);
                }, null);
            }
            else
            {
                await this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, false, State));
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Deletes a message object from the broker.
 /// </summary>
 /// <param name="ObjectId">ID of the message object to delete.</param>
 /// <param name="Callback">Method to call when response has been returned.</param>
 /// <param name="State">State object to pass on to callback method.</param>
 public void Delete(string ObjectId, IqResultEventHandlerAsync Callback, object State)
 {
     this.client.SendIqSet(this.client.Domain, "<delete xmlns='" + NamespaceMail + "' cid='" + XML.Encode(ObjectId) + "'/>",
                           Callback, State);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Reject control operations from this user.
 /// </summary>
 /// <param name="UserToken">Which user token is to be rejected.</param>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool RejectAllFromUser(string UserToken, IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(false, "<fromUser token='" + XML.Encode(UserToken) + "'/>", Callback, State));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Reject control operations from this remote JID.
 /// </summary>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool RejectAllFromJID(IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(false, "<fromJid/>", Callback, State));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Accept partial control operations from this user.
 /// </summary>
 /// <param name="Parameters">Parameters that can be controlled.</param>
 /// <param name="UserToken">Which user token is to be accepted.</param>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool AcceptPartialFromUser(string[] Parameters, string UserToken, IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(true, this.PartialParameters(Parameters) + "<fromUser token='" + XML.Encode(UserToken) + "'/>", Callback, State));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Accept partial control operations from all entities of the remote domain.
 /// </summary>
 /// <param name="Parameters">Parameters that can be controlled.</param>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool AcceptPartialFromDomain(string[] Parameters, IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(true, this.PartialParameters(Parameters) + "<fromDomain/>", Callback, State));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Rejects the friendship, and similar future requests from the entire remote domain.
 /// </summary>
 public void RejectForEntireDomain(IqResultEventHandlerAsync Callback, object State)
 {
     this.Respond(false, RuleRange.Domain, Callback, State);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Accept partial readouts from this device.
 /// </summary>
 /// <param name="Fields">Fields that can be read.</param>
 /// <param name="FieldTypes">Field categories that can be read.</param>
 /// <param name="DeviceToken">Which device token is to be accepted.</param>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool AcceptPartialFromDevice(string[] Fields, FieldType FieldTypes, string DeviceToken, IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(true, this.PartialFields(Fields, FieldTypes) + "<fromDevice token='" + XML.Encode(DeviceToken) + "'/>", Callback, State));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Accept partial readouts from all entities of the remote domain.
 /// </summary>
 /// <param name="Fields">Fields that can be read.</param>
 /// <param name="FieldTypes">Field categories that can be read.</param>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool AcceptPartialFromDomain(string[] Fields, FieldType FieldTypes, IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(true, this.PartialFields(Fields, FieldTypes) + "<fromDomain/>", Callback, State));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Accepts the friendship.
 /// </summary>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 public void Accept(IqResultEventHandlerAsync Callback, object State)
 {
     this.Respond(true, RuleRange.Caller, Callback, State);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Accept control operations from all entities of the remote domain.
 /// </summary>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool AcceptAllFromDomain(IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(true, "<fromDomain/>", Callback, State));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Rejects the friendship, and all future requests.
 /// </summary>
 public void RejectForAll(IqResultEventHandlerAsync Callback, object State)
 {
     this.Respond(false, RuleRange.All, Callback, State);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Blocks a JID
        /// </summary>
        /// <param name="JID">JID to block.</param>
        /// <param name="Reason">Reason for blocking JID.</param>
        /// <param name="Callback">Callback method.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        public async Task BlockJID(string JID, ReportingReason Reason, IqResultEventHandlerAsync Callback, object State)
        {
            bool Blocked;

            lock (this.blockList)
            {
                if (!this.blockList.TryGetValue(JID, out Blocked))
                {
                    Blocked = false;
                }
            }

            if (Blocked)
            {
                await this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, true, State));
            }
            else if (this.supportsBlocking)
            {
                StringBuilder Xml = new StringBuilder();

                Xml.Append("<block xmlns='");
                Xml.Append(NamespaceBlocking);
                Xml.Append("'><item jid='");
                Xml.Append(JID);

                if (!this.supportsReporting)
                {
                    Xml.Append("'/></block>");
                }
                else if (Reason == ReportingReason.Spam && this.supportsSpamReason)
                {
                    Xml.Append("'><report xmlns='");
                    Xml.Append(NamespaceReporting);
                    Xml.Append("'><spam/></report></item></block>");
                }
                else if (Reason == ReportingReason.Abuse && this.supportsAbuseReason)
                {
                    Xml.Append("'><report xmlns='");
                    Xml.Append(NamespaceReporting);
                    Xml.Append("'><abuse/></report></item></block>");
                }
                else
                {
                    Xml.Append("'/></block>");
                }

                this.client.SendIqSet(this.client.Domain, Xml.ToString(), async(sender, e) =>
                {
                    if (e.Ok)
                    {
                        lock (this.blockList)
                        {
                            this.blockList[JID] = true;
                        }
                    }

                    await this.CallCallback(Callback, State, e);
                }, null);
            }
            else
            {
                await this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, false, State));
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Accept control operations from this service.
 /// </summary>
 /// <param name="ServiceToken">Which service token is to be accepted.</param>
 /// <param name="Callback">Callback method to call when response is received.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <returns>If the response could be sent.</returns>
 public bool AcceptAllFromService(string ServiceToken, IqResultEventHandlerAsync Callback, object State)
 {
     return(this.Respond(true, "<fromService token='" + XML.Encode(ServiceToken) + "'/>", Callback, State));
 }
Ejemplo n.º 21
0
 private void Respond(bool IsFriend, RuleRange Range, IqResultEventHandlerAsync Callback, object State)
 {
     this.Client.IsFriendResponse(this.JID, this.RemoteJID, this.Key, IsFriend, Range, Callback, State);
 }