Exemple #1
0
static int sluift_client_get_version(lua_State *L) {
	try {
		SluiftClient* client = getClient(L);
		int timeout = -1;
		if (lua_type(L, 3) != LUA_TNONE) {
			timeout = luaL_checknumber(L, 3);
		}

		ResponseSink<SoftwareVersion> sink;
		GetSoftwareVersionRequest::ref request = GetSoftwareVersionRequest::create(std::string(luaL_checkstring(L, 2)), client->getClient()->getIQRouter());
		boost::signals::scoped_connection c = request->onResponse.connect(boost::ref(sink));
		request->send();

		Watchdog watchdog(timeout, networkFactories.getTimerFactory());
		while (!watchdog.getTimedOut() && !sink.hasResponse()) {
			eventLoop.runUntilEvents();
		}

		ErrorPayload::ref error = sink.getResponseError();
		if (error || watchdog.getTimedOut()) {
			lua_pushnil(L);
			if (watchdog.getTimedOut()) {
				lua_pushstring(L, "Timeout");
			}
			else if (error->getCondition() == ErrorPayload::RemoteServerNotFound) {
				lua_pushstring(L, "Remote server not found");
			}
			// TODO
			else {
				lua_pushstring(L, "Error");
			}
			return 2;
		}
		else if (SoftwareVersion::ref version = sink.getResponsePayload()) {
			Lua::Table result = boost::assign::map_list_of
				("name", boost::make_shared<Lua::Value>(version->getName()))
				("version", boost::make_shared<Lua::Value>(version->getVersion()))
				("os", boost::make_shared<Lua::Value>(version->getOS()));
			Lua::pushValue(L, result);
		}
		else {
			lua_pushnil(L);
		}
		return 1;
	}
	catch (const SluiftException& e) {
		return luaL_error(L, e.getReason().c_str());
	}
}
Exemple #2
0
        void testParse() {
            PayloadsParserTester parser;

            CPPUNIT_ASSERT(parser.parse(
                "<error type=\"modify\">"
                    "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
                    "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>"
                "</error>"));

            ErrorPayload::ref payload = std::dynamic_pointer_cast<ErrorPayload>(parser.getPayload());
            CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition());
            CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType());
            CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText());
            CPPUNIT_ASSERT(!payload->getPayload());
        }
Exemple #3
0
        void testParseWithPayload() {
            PayloadsParserTester parser;

            CPPUNIT_ASSERT(parser.parse(
                    "<error type=\"modify\">"
                    "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
                    "<delay xmlns='urn:xmpp:delay' from='[email protected]/balcony' stamp='2002-09-10T23:41:07Z'/>"
                    "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>"
                    "</error>"));

            ErrorPayload::ref payload = std::dynamic_pointer_cast<ErrorPayload>(parser.getPayload());
            CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition());
            CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType());
            CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText());
            CPPUNIT_ASSERT(std::dynamic_pointer_cast<Delay>(payload->getPayload()));
        }