From 2a40419b2bc417c0e2a5b82efe5fc8d77493d02b 2011-06-08 14:21:20 From: Jan Kaluza Date: 2011-06-08 14:21:20 Subject: [PATCH] Fixed crash in handleDisconnect handler --- diff --git a/backends/libircclient-qt/session.cpp b/backends/libircclient-qt/session.cpp index 64e87962656ba058d7d2982eb8332be08bf38122..e8e5b9e83beab2c5a9dbaee6fd266271e8b17079 100644 --- a/backends/libircclient-qt/session.cpp +++ b/backends/libircclient-qt/session.cpp @@ -17,6 +17,7 @@ MyIrcSession::MyIrcSession(const std::string &user, NetworkPlugin *np, QObject* { this->np = np; this->user = user; + connect(this, SIGNAL(disconnected()), SLOT(on_disconnected())); } void MyIrcSession::on_connected(){ @@ -26,6 +27,7 @@ void MyIrcSession::on_connected(){ void MyIrcSession::on_disconnected() { std::cout << "disconnected:\n"; + np->handleDisconnected(user, "", 0, ""); } void MyIrcSession::on_bufferAdded(Irc::Buffer* buffer) diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 2e635fcbe7694e992ded5017950e8c2f587d403e..ce39caa3b23848bfd965a3fd481348e838448e99 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -201,6 +201,10 @@ void NetworkPluginServer::handleDisconnectedPayload(const std::string &data) { } m_component->m_userRegistry->onPasswordInvalid(payload.user()); + user = m_userManager->getUser(payload.user()); + if (!user) { + return; + } user->handleDisconnected(payload.message()); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bdbd3c65a30df5437f044d7a0d679b270fea76cd..2151b4c67402c4f85385684bbf392335d7efc99b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,4 @@ ADD_SUBDIRECTORY(login) +ADD_SUBDIRECTORY(login_bad_name) add_custom_target(tests python runtests.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/login/main.cpp b/tests/login/main.cpp index 77ab9a4408d072e07690026c9dc02818cc72235d..3e55d9db3111fd26c47d3f77d7703bab02d5f420 100644 --- a/tests/login/main.cpp +++ b/tests/login/main.cpp @@ -10,12 +10,10 @@ using namespace boost; Client* client; static void handleDisconnected(const boost::optional &) { -// std::cout << "Disconnected..." << std::endl; exit(1); } static void handleConnected() { -// std::cout << "Connected..." << std::endl; exit(0); } diff --git a/tests/login_bad_name/CMakeLists.txt b/tests/login_bad_name/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7801614f879ac22f9acab99618852a21d1c73be6 --- /dev/null +++ b/tests/login_bad_name/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB SRC *.cpp) + +ADD_EXECUTABLE(login_bad_name_test ${SRC}) + +TARGET_LINK_LIBRARIES(login_bad_name_test transport ${SWIFTEN_LIBRARIES} -lgconf-2 -lgobject-2.0 -lglib-2.0) + diff --git a/tests/login_bad_name/main.cpp b/tests/login_bad_name/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4df61cdb662e900b51edf32165a652b5d8e93dd6 --- /dev/null +++ b/tests/login_bad_name/main.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include +#include + +using namespace Swift; +using namespace boost; + +Client* client; + +static void handleDisconnected(const boost::optional &error) { + exit(error->getType() != ClientError::AuthenticationFailedError); +} + +static void handleConnected() { + exit(1); +} + +static void handleMessageReceived(Message::ref message) { + // Echo back the incoming message + message->setTo(message->getFrom()); + message->setFrom(JID()); + client->sendMessage(message); +} + +int main(int, char **argv) { + SimpleEventLoop eventLoop; + BoostNetworkFactories networkFactories(&eventLoop); + + JID jid(JID(argv[1]).getNode() + "something", JID(argv[1]).getDomain()); + client = new Client(jid, argv[2], &networkFactories); + client->setAlwaysTrustCertificates(); + client->onConnected.connect(&handleConnected); + client->onDisconnected.connect(bind(&handleDisconnected, _1)); + client->onMessageReceived.connect(bind(&handleMessageReceived, _1)); + ClientOptions opt; + opt.allowPLAINOverNonTLS = true; + client->connect(opt); + + eventLoop.run(); + + delete client; + return 0; +} diff --git a/tests/runtests.py b/tests/runtests.py index cfd086147e96ba20ca3761b6b439eac10ff69f5b..5386ff9e81e311401b60d8638a28e261d7e80640 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -3,7 +3,8 @@ import sys from subprocess import * import time -def run_spectrum(backend): +def run_spectrum(backend, test): + os.system("rm test.sql") f = open("sample.cfg", "w") f.write("\ [service]\n\ @@ -21,13 +22,13 @@ def run_spectrum(backend): " % (backend, backend) ) f.close() - p = Popen("../spectrum/src/spectrum sample.cfg >> test.log 2> /dev/null", shell=True) + p = Popen("../spectrum/src/spectrum sample.cfg > " + backend + "_" + test + ".log 2>&1", shell=True) time.sleep(2) return p os.system("killall spectrum 2> /dev/null") -os.system("rm test.log") +os.system("rm *.log") for backend in os.listdir("../backends"): if not os.path.isdir("../backends/" + backend) or backend == "CMakeFiles": @@ -38,7 +39,7 @@ for backend in os.listdir("../backends"): if not os.path.exists(binary): continue - p = run_spectrum(backend); + p = run_spectrum(backend, d) if backend.find("purple") >= 0: p = Popen(binary + " pyjim%jabber.cz@localhost test", shell=True) @@ -46,13 +47,18 @@ for backend in os.listdir("../backends"): else: p = Popen(binary + " testnickname%irc.freenode.net@localhost test", shell=True) - time.sleep(5) + seconds = 0 + while p.poll() is None and seconds < 20: + time.sleep(1) + seconds += 1 - p.poll() if p.returncode == 0: print "[ PASS ]", backend, binary else: - print "[ FAIL ]", backend, binary + if seconds == 20: + print "[ TIME ]", backend, binary + else: + print "[ FAIL ]", backend, binary os.system("killall spectrum 2> /dev/null")