diff --git a/include/transport/adhoccommand.h b/include/transport/adhoccommand.h index e9c1adfe..03bc21b8 100644 --- a/include/transport/adhoccommand.h +++ b/include/transport/adhoccommand.h @@ -41,6 +41,8 @@ class AdHocCommand { virtual boost::shared_ptr handleRequest(boost::shared_ptr payload) = 0; + void addFormField(Swift::FormField::ref field); + const std::string &getId() { return m_id; } @@ -57,9 +59,10 @@ class AdHocCommand { Component *m_component; Swift::JID m_initiator; Swift::JID m_to; + std::vector m_fields; + std::string m_id; private: - std::string m_id; // This is used to remove AdHocCommand after long inactivity to prevent memory leaks // caused by users which disconnect before they finish the command. // AdHocManager uses this to garbage collect old AdHocCommands. diff --git a/include/transport/settingsadhoccommand.h b/include/transport/settingsadhoccommand.h index 8e653ecc..b34a7804 100644 --- a/include/transport/settingsadhoccommand.h +++ b/include/transport/settingsadhoccommand.h @@ -34,12 +34,19 @@ class Component; class SettingsAdHocCommand : public AdHocCommand { public: + typedef enum { Init, WaitingForResponse } State; + SettingsAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to); /// Destructor. virtual ~SettingsAdHocCommand(); virtual boost::shared_ptr handleRequest(boost::shared_ptr payload); + + private: + boost::shared_ptr getForm(); + boost::shared_ptr handleResponse(boost::shared_ptr payload); + State m_state; }; class SettingsAdHocCommandFactory : public AdHocCommandFactory { diff --git a/src/adhoccommand.cpp b/src/adhoccommand.cpp index e121beaf..badc5dc2 100644 --- a/src/adhoccommand.cpp +++ b/src/adhoccommand.cpp @@ -45,4 +45,8 @@ AdHocCommand::AdHocCommand(Component *component, const Swift::JID &initiator, co AdHocCommand::~AdHocCommand() { } +void AdHocCommand::addFormField(Swift::FormField::ref field) { + m_fields.push_back(field); +} + } diff --git a/src/settingsadhoccommand.cpp b/src/settingsadhoccommand.cpp index dd90540b..00aacece 100644 --- a/src/settingsadhoccommand.cpp +++ b/src/settingsadhoccommand.cpp @@ -31,15 +31,47 @@ namespace Transport { DEFINE_LOGGER(logger, "SettingsAdHocCommand"); SettingsAdHocCommand::SettingsAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to) : AdHocCommand(component, initiator, to) { + m_state = Init; } SettingsAdHocCommand::~SettingsAdHocCommand() { } +boost::shared_ptr SettingsAdHocCommand::getForm() { + boost::shared_ptr response(new Swift::Command("settings", m_id, Swift::Command::Executing)); + boost::shared_ptr form(new Swift::Form()); + + BOOST_FOREACH(Swift::FormField::ref field, m_fields) { + form->addField(field); + } + + response->setForm(form); + return response; +} + +boost::shared_ptr SettingsAdHocCommand::handleResponse(boost::shared_ptr payload) { + + + + boost::shared_ptr response; + response->setStatus(Swift::Command::Completed); + return response; +} + boost::shared_ptr SettingsAdHocCommand::handleRequest(boost::shared_ptr payload) { boost::shared_ptr response; - - + + switch (m_state) { + case Init: + response = getForm(); + m_state = WaitingForResponse; + break; + case WaitingForResponse: + response = handleResponse(payload); + break; + default: + break; + } return response; }