internal RosterItem(XmlElement Item) { this.bareJid = XML.Attribute(Item, "jid"); this.name = XML.Attribute(Item, "name"); switch (XML.Attribute(Item, "subscription")) { case "both": this.state = SubscriptionState.Both; break; case "to": this.state = SubscriptionState.To; break; case "from": this.state = SubscriptionState.From; break; case "none": case "": this.state = SubscriptionState.None; break; case "remove": this.state = SubscriptionState.Remove; break; default: this.state = SubscriptionState.Unknown; break; } switch (XML.Attribute(Item, "ask").ToLower()) { case "subscribe": this.pendingSubscription = PendingSubscription.Subscribe; break; case "unsubscribe": this.pendingSubscription = PendingSubscription.Unsubscribe; break; default: this.pendingSubscription = PendingSubscription.None; break; } List <string> Groups = new List <string>(); foreach (XmlNode N in Item.ChildNodes) { if (N.LocalName == "group") { Groups.Add(N.InnerText); } } this.groups = Groups.ToArray(); }
private void CheckPendingSubscriptionExpiration( ChannelSubscription subscription ) { if (!pendingSubscriptions.ContainsKey(subscription)) { throw new ArgumentException( "Given subscription is not pending." ); } PendingSubscription pendingSub = pendingSubscriptions[subscription]; // still young enough if ((pendingSub.createdAt - DateTime.UtcNow).TotalMinutes < 5.0) { return; } // too old, remove Debug.LogWarning( "[Unisave] Removing expired pending subscription: " + Serializer.ToJson(subscription).ToString(true) ); EndSubscriptions(new[] { subscription }); CheckTunnelNeededness(); }
/// <summary> /// Maintains information about an item in the roster. /// </summary> /// <param name="BareJID">Bare JID of the roster item.</param> /// <param name="Name">Name of the roster item.</param> /// <param name="Groups">Groups assigned to the roster item.</param> public RosterItem(string BareJID, string Name, params string[] Groups) { this.groups = Groups; this.state = SubscriptionState.Unknown; this.bareJid = BareJID; this.name = Name; this.pendingSubscription = PendingSubscription.None; }
/// <summary> /// Maintains information about an item in the roster. /// </summary> /// <param name="BareJID">Bare JID of the roster item.</param> /// <param name="Name">Name of the roster item.</param> /// <param name="Groups">Groups assigned to the roster item.</param> /// <param name="Prev">Inherit resources from the previous roster item.</param> internal RosterItem(string BareJID, string Name, string[] Groups, RosterItem Prev) { this.groups = Groups; this.state = SubscriptionState.Unknown; this.bareJid = BareJID; this.name = Name; this.pendingSubscription = PendingSubscription.None; this.resources = Prev?.resources ?? new Dictionary <string, PresenceEventArgs>(); }
internal void PresenceReceived(XmppClient Client, PresenceEventArgs e) { PresenceEventArgs[] ToTest = null; lock (this.resources) { if (e.Type == PresenceType.Unavailable) { this.resources.Remove(e.From); if (this.lastPresence != null && this.lastPresence.From == e.From) { this.lastPresence = null; } } else if (e.Type == PresenceType.Available) { int c = this.resources.Count; if (c > 0 && Client.MonitorContactResourcesAlive && !this.resources.ContainsKey(e.From)) { ToTest = new PresenceEventArgs[c]; this.resources.Values.CopyTo(ToTest, 0); } this.resources[e.From] = e; this.lastPresence = e; if (this.pendingSubscription == PendingSubscription.Subscribe) { this.pendingSubscription = PendingSubscription.None; // Might be out of synch. } } } if (ToTest != null) { foreach (PresenceEventArgs e2 in ToTest) { if (!e2.Testing) { e2.Testing = true; Client.SendPing(e2.From, this.PingResult, new object[] { Client, e2 }); } } } }
internal RosterItem(XmlElement Item, Dictionary <string, RosterItem> Roster) { this.bareJid = XML.Attribute(Item, "jid"); this.name = XML.Attribute(Item, "name"); switch (XML.Attribute(Item, "subscription")) { case "both": this.state = SubscriptionState.Both; break; case "to": this.state = SubscriptionState.To; break; case "from": this.state = SubscriptionState.From; break; case "none": case "": this.state = SubscriptionState.None; break; case "remove": this.state = SubscriptionState.Remove; break; default: this.state = SubscriptionState.Unknown; break; } switch (XML.Attribute(Item, "ask").ToLower()) { case "subscribe": this.pendingSubscription = PendingSubscription.Subscribe; break; case "unsubscribe": this.pendingSubscription = PendingSubscription.Unsubscribe; break; default: this.pendingSubscription = PendingSubscription.None; break; } List <string> Groups = new List <string>(); foreach (XmlNode N in Item.ChildNodes) { if (N.LocalName == "group") { Groups.Add(N.InnerText); } } this.groups = Groups.ToArray(); if (this.state == SubscriptionState.Both || this.state == SubscriptionState.To) { if (Roster.TryGetValue(this.bareJid, out RosterItem Prev)) { this.resources = Prev.resources; } this.lastPresence = Prev?.lastPresence; } if (this.resources is null) { this.resources = new Dictionary <string, PresenceEventArgs>(); } }