aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0030_service_discovery/items_result.vala
blob: 105da89369c5c4e6629c5beb7e5ea908e80b0c31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Gee;

namespace Xmpp.Xep.ServiceDiscovery {

public class ItemsResult {
    public Iq.Stanza iq { get; private set; }

    public ArrayList<Item> items {
        owned get {
            ArrayList<Item> ret = new ArrayList<Item>();
            foreach (StanzaNode feature_node in iq.stanza.get_subnode("query", NS_URI_ITEMS).get_subnodes("item", NS_URI_ITEMS)) {
                try {
                    ret.add(new Item(new Jid(feature_node.get_attribute("jid", NS_URI_ITEMS)),
                                feature_node.get_attribute("name", NS_URI_ITEMS),
                                feature_node.get_attribute("node", NS_URI_ITEMS)));
                } catch (InvalidJidError e) {
                    warning("Ignoring service at invalid Jid: %s", e.message);
                }
            }
            return ret;
        }
    }

    private ItemsResult.from_iq(Iq.Stanza iq) {
        this.iq = iq;
    }

    public static ItemsResult? create_from_iq(Iq.Stanza iq) {
        if (iq.type_ != Iq.Stanza.TYPE_RESULT) return null;

        if (iq.stanza.get_subnode("query", NS_URI_ITEMS) == null) return null;

        return new ItemsResult.from_iq(iq);
    }
}

}