diff --git a/src/adhocmanager.cpp b/src/adhocmanager.cpp index 664b421ed327479000f5a06b9e66f07c1b5596f0..cf02a9375dfe4cca7ae069541fe55ea473bf530e 100644 --- a/src/adhocmanager.cpp +++ b/src/adhocmanager.cpp @@ -113,8 +113,15 @@ bool AdHocManager::handleGetRequest(const Swift::JID& from, const Swift::JID& to bool AdHocManager::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr payload) { AdHocCommand *command = NULL; // Try to find AdHocCommand according to 'from' and session_id - if (m_sessions.find(from) != m_sessions.end() && m_sessions[from].find(payload->getSessionID()) != m_sessions[from].end()) { - command = m_sessions[from][payload->getSessionID()]; + if (m_sessions.find(from) != m_sessions.end()) { + if (m_sessions[from].find(payload->getSessionID()) != m_sessions[from].end()) { + command = m_sessions[from][payload->getSessionID()]; + } + else { + LOG4CXX_ERROR(logger, from.toString() << ": Unknown session id " << payload->getSessionID() << " - ignoring"); + sendError(from, id, Swift::ErrorPayload::BadRequest, Swift::ErrorPayload::Modify); + return true; + } } // Check if we can create command with this node else if (m_factories.find(payload->getNode()) != m_factories.end()) { @@ -148,7 +155,7 @@ bool AdHocManager::handleSetRequest(const Swift::JID& from, const Swift::JID& to command->refreshLastActivity(); // Command completed, so we can remove it now - if (response->getStatus() == Swift::Command::Completed) { + if (response->getStatus() == Swift::Command::Completed || response->getStatus() == Swift::Command::Canceled) { m_sessions[from].erase(command->getId()); if (m_sessions[from].empty()) { m_sessions.erase(from);