Exemplo n.º 1
0
        void testParse_Form() {
            PayloadsParserTester parser;

            CPPUNIT_ASSERT(parser.parse(
                "<query xmlns=\"http://jabber.org/protocol/disco#info\">"
                    "<feature var=\"foo-feature\"/>"
                    "<x type=\"submit\" xmlns=\"jabber:x:data\">"
                        "<title>Bot Configuration</title>"
                        "<instructions>Hello!</instructions>"
                    "</x>"
                    "<feature var=\"bar-feature\"/>"
                "</query>"));

            DiscoInfo::ref payload = std::dynamic_pointer_cast<DiscoInfo>(parser.getPayload());
            CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getExtensions().size()));
            CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getExtensions()[0]->getTitle());
            CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFeatures().size()));
            CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]);
            CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]);
        }
JID WhiteboardSessionManager::getFullJID(const JID& bareJID) {
    JID fullReceipientJID;
    int priority = INT_MIN;

    //getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Remko Tronçon @ 11:11
    std::vector<Presence::ref> presences = presenceOracle_->getAllPresence(bareJID);

    //iterate over them
    foreach(Presence::ref pres, presences) {
        if (pres->getPriority() > priority) {
            // look up caps from the jid
            DiscoInfo::ref info = capsProvider_->getCaps(pres->getFrom());
            if (info && info->hasFeature(DiscoInfo::WhiteboardFeature)) {
                priority = pres->getPriority();
                fullReceipientJID = pres->getFrom();
            }
        }
    }

    return fullReceipientJID;
}
Exemplo n.º 3
0
boost::optional<JID> CombinedOutgoingFileTransferManager::highestPriorityJIDSupportingSI(const JID& bareJID) {
	JID fullReceipientJID;
	int priority = INT_MIN;
	
	//getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Remko Tronçon @ 11:11
	std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID);

	//iterate over them
	foreach(Presence::ref pres, presences) {
		if (pres->getPriority() > priority) {
			// look up caps from the jid
			DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom());
			if (info && info->hasFeature("http://jabber.org/protocol/si/profile/file-transfer")) {
			
				priority = pres->getPriority();
				fullReceipientJID = pres->getFrom();
			}
		}
	}
	
	return fullReceipientJID.isValid() ? boost::optional<JID>(fullReceipientJID) : boost::optional<JID>();
}
Exemplo n.º 4
0
void CapsManager::handleDiscoInfoReceived(const JID& from, const std::string& hash, DiscoInfo::ref discoInfo, ErrorPayload::ref error) {
    requestedDiscoInfos.erase(hash);
    if (error || !discoInfo || CapsInfoGenerator("", crypto).generateCapsInfo(*discoInfo.get()).getVersion() != hash) {
        if (warnOnInvalidHash && !error &&  discoInfo) {
            SWIFT_LOG(warning) << "Caps from " << from.toString() << " do not verify" << std::endl;
        }
        failingCaps.insert(std::make_pair(from, hash));
        std::map<std::string, std::set< std::pair<JID, std::string> > >::iterator i = fallbacks.find(hash);
        if (i != fallbacks.end() && !i->second.empty()) {
            std::pair<JID,std::string> fallbackAndNode = *i->second.begin();
            i->second.erase(i->second.begin());
            requestDiscoInfo(fallbackAndNode.first, fallbackAndNode.second, hash);
        }
        return;
    }
    fallbacks.erase(hash);
    capsStorage->setDiscoInfo(hash, discoInfo);
    onCapsAvailable(hash);
}
Exemplo n.º 5
0
        void testParse_Node() {
            PayloadsParserTester parser;

            CPPUNIT_ASSERT(parser.parse(
                "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"blahblah\">"
                    "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>"
                    "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>"
                    "<feature var=\"foo-feature\"/>"
                    "<feature var=\"bar-feature\"/>"
                    "<feature var=\"baz-feature\"/>"
                "</query>"));

            DiscoInfo::ref payload = std::dynamic_pointer_cast<DiscoInfo>(parser.getPayload());
            CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size()));
            CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName());
            CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType());
            CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory());
            CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage());
            CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName());
            CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType());
            CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory());
            CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage());
            CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size()));
            CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]);
            CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]);
            CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]);
            CPPUNIT_ASSERT_EQUAL(std::string("blahblah"), payload->getNode());
        }
Exemplo n.º 6
0
void CapsFileStorage::setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo) {
	DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get()));
	bareDiscoInfo->setNode("");
	DiscoInfoPersister().savePayload(bareDiscoInfo, getCapsPath(hash));
}