summaryrefslogtreecommitdiffstats
blob: c94d2997dc502d594a4a14639680f80f5edcd9c0 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Disco/DiscoInfoResponder.h>

#include <memory>

#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Queries/IQRouter.h>

namespace Swift {

DiscoInfoResponder::DiscoInfoResponder(IQRouter* router) : GetResponder<DiscoInfo>(router) {
}

void DiscoInfoResponder::clearDiscoInfo() {
    info_ = DiscoInfo();
    nodeInfo_.clear();
}

void DiscoInfoResponder::setDiscoInfo(const DiscoInfo& info) {
    info_ = info;
}

void DiscoInfoResponder::setDiscoInfo(const std::string& node, const DiscoInfo& info) {
    DiscoInfo newInfo(info);
    newInfo.setNode(node);
    nodeInfo_[node] = newInfo;
}

bool DiscoInfoResponder::handleGetRequest(const JID& from, const JID&, const std::string& id, std::shared_ptr<DiscoInfo> info) {
    if (info->getNode().empty()) {
        sendResponse(from, id, std::make_shared<DiscoInfo>(info_));
    }
    else {
        std::map<std::string,DiscoInfo>::const_iterator i = nodeInfo_.find(info->getNode());
        if (i != nodeInfo_.end()) {
            sendResponse(from, id, std::make_shared<DiscoInfo>((*i).second));
        }
        else {
            sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel);
        }
    }
    return true;
}

}