~singpolyma/biboumi

ref: 7b3e0e0cf3eddd3537455a3605b04a48ee663f47 biboumi/src/xmpp/adhoc_commands_handler.hpp -rw-r--r-- 2.3 KiB
7b3e0e0c — louiz’ Make botan’s policy configurable from a file 6 years ago
                                                                                
81f8f45b louiz’
e1a7114c Florent Le Coz
9714d020 Florent Le Coz
e1a7114c Florent Le Coz
af420738 louiz’
e1a7114c Florent Le Coz
ee4cf5dc louiz’
e1a7114c Florent Le Coz
ee4cf5dc louiz’
e1a7114c Florent Le Coz
19666d2f Florent Le Coz
e1a7114c Florent Le Coz
9714d020 Florent Le Coz
e1a7114c Florent Le Coz
9714d020 Florent Le Coz
e1a7114c Florent Le Coz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once

/**
 * Manage a list of available AdhocCommands and the list of ongoing
 * AdhocCommandSessions.
 */

#include <xmpp/adhoc_command.hpp>
#include <xmpp/xmpp_stanza.hpp>

#include <utility>
#include <string>
#include <map>

class AdhocCommandsHandler
{
public:
  explicit AdhocCommandsHandler(XmppComponent& xmpp_component):
    xmpp_component(xmpp_component),
    commands{}
  { }
  ~AdhocCommandsHandler() = default;

  AdhocCommandsHandler(const AdhocCommandsHandler&) = delete;
  AdhocCommandsHandler(AdhocCommandsHandler&&) = delete;
  AdhocCommandsHandler& operator=(const AdhocCommandsHandler&) = delete;
  AdhocCommandsHandler& operator=(AdhocCommandsHandler&&) = delete;

  /**
   * Returns the list of available commands.
   */
  const std::map<const std::string, const AdhocCommand>& get_commands() const;
  /**
   * Add a command into the list, associated with the given name
   */
  void add_command(std::string name, AdhocCommand command);
  /**
   * Find the requested command, create a new session or use an existing
   * one, and process the request (provide a new form, an error, or a
   * result).
   *
   * Returns a (moved) XmlNode that will be inserted in the iq response. It
   * should be a <command/> node containing one or more useful children. If
   * it contains an <error/> node, the iq response will have an error type.
   *
   * Takes a copy of the <command/> node so we can actually edit it and use
   * it as our return value.
   */
  XmlNode handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node);
  /**
   * Remove the session from the list. This is done to avoid filling the
   * memory with waiting session (for example due to a client that starts
   * multi-steps command but never finishes them).
   */
  void remove_session(const std::string& session_id, const std::string& initiator_jid);
private:
  /**
   * To access basically anything in the gateway.
   */
  XmppComponent& xmpp_component;
  /**
   * The list of all available commands.
   */
  std::map<const std::string, const AdhocCommand> commands;
  /**
   * The list of all currently on-going commands.
   *
   * Of the form: {{session_id, owner_jid}, session}.
   */
  std::map<std::pair<const std::string, const std::string>, AdhocSession> sessions;
};