예제 #1
0
        public PrivacyList GetPrivacyList(string name)
        {
            this.AssertValid(true);
            name.ThrowIfNull <string>("name");
            XmlElement data    = Xml.Element("query", "jabber:iq:privacy").Child(Xml.Element("list", null).Attr("name", name));
            Iq         errorIq = this.IqRequest(IqType.Get, null, this.Jid, data, null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The privacy list could not be retrieved.");
            }
            data = errorIq.Data["query"];
            if (((data == null) || (data.NamespaceURI != "jabber:iq:privacy")) || (data["list"] == null))
            {
                throw new XmppException("Erroneous server response: " + errorIq);
            }
            PrivacyList list     = new PrivacyList(name);
            XmlElement  element2 = data["list"];

            foreach (XmlElement element3 in element2.GetElementsByTagName("item"))
            {
                try
                {
                    PrivacyRule item = this.ParsePrivacyItem(element3);
                    list.Add(item);
                }
                catch (Exception exception)
                {
                    throw new XmppException("Erroneous privacy rule.", exception);
                }
            }
            return(list);
        }
예제 #2
0
        public void EditPrivacyList(PrivacyList list)
        {
            this.AssertValid(true);
            list.ThrowIfNull <PrivacyList>("list");
            if (list.Count == 0)
            {
                throw new ArgumentException("The list must contain one or more privacy rules.");
            }
            XmlElement e = Xml.Element("list", null).Attr("name", list.Name);

            foreach (PrivacyRule rule in list)
            {
                XmlElement element2 = Xml.Element("item", null).Attr("action", (rule.Allow ? "allow" : "deny")).Attr("order", rule.Order.ToString());
                if (rule.Granularity.HasFlag(PrivacyGranularity.Message))
                {
                    element2.Child(Xml.Element("message", null));
                }
                if (rule.Granularity.HasFlag(PrivacyGranularity.Iq))
                {
                    element2.Child(Xml.Element("iq", null));
                }
                if (rule.Granularity.HasFlag(PrivacyGranularity.PresenceIn))
                {
                    element2.Child(Xml.Element("presence-in", null));
                }
                if (rule.Granularity.HasFlag(PrivacyGranularity.PresenceOut))
                {
                    element2.Child(Xml.Element("presence-out", null));
                }
                if (rule is JidPrivacyRule)
                {
                    JidPrivacyRule rule2 = rule as JidPrivacyRule;
                    element2.Attr("type", "jid");
                    element2.Attr("value", rule2.Jid.ToString());
                }
                else if (rule is GroupPrivacyRule)
                {
                    GroupPrivacyRule rule3 = rule as GroupPrivacyRule;
                    element2.Attr("type", "group");
                    element2.Attr("value", rule3.Group);
                }
                else if (rule is SubscriptionPrivacyRule)
                {
                    SubscriptionPrivacyRule rule4 = rule as SubscriptionPrivacyRule;
                    element2.Attr("type", "subscription");
                    element2.Attr("value", rule4.SubscriptionState.ToString().ToLowerInvariant());
                }
                e.Child(element2);
            }
            Iq errorIq = this.IqRequest(IqType.Set, null, this.Jid, Xml.Element("query", "jabber:iq:privacy").Child(e), null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The privacy list could not be edited.");
            }
        }