HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CMD_ServerSocketCommandListener.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: CMD_ServerSocketCommandListener.h ( CMD Library, C++ )
7  *
8  * COMMENTS:
9  * This event generator opens a socket an waits for connections.
10  * When a client makes a connection and sends a command, that
11  * command is run and the command output is sent back.
12  * Note that multiple active connections can exist at once.
13  */
14 
15 #ifndef __CMD_ServerSocketCommandListener_h__
16 #define __CMD_ServerSocketCommandListener_h__
17 
18 #include "CMD_API.h"
20 #include <UT/UT_Spawn.h>
21 
22 class UT_WorkBuffer;
23 class CMD_Manager;
24 
26 {
27 public:
28  // Use this static method to create a instance of this class.
29  // Note that this method might return null if the socket could not be
30  // created (eg. if the port is already in use).
31  // separate_errors: if set, error output will be separated from
32  // regular output by ~~~~.
33  // restrict_to_safe_commands: if set, "unsafe" commands will not be
34  // executed.
35  // ip_mask: restricts who is allowed to connect to this socket. If
36  // it is null, it defaults to +.+.+.+.
37  // remap_privileged_ports: if set, port numbers will be mapped into
38  // the range of unprivileged port numbers.
39  static CMD_ServerSocketCommandListener *createCommandListener(int port,
40  CMD_Manager& command_manager,
41  bool separate_errors = false,
42  bool restrict_to_safe_commands = false,
43  const char *ip_mask = 0,
44  bool remap_privileged_ports = true,
45  bool browser_mode = false);
46 
47  virtual const char *className() const
48  { return "CMD_ServerSocketCommandListener"; }
49 
51  { return myRestrictToSafeCmds; }
52  void setRestrictToSafeCommands(bool restrict_to_safe_cmds)
53  { myRestrictToSafeCmds = restrict_to_safe_cmds; }
54 
55 private:
56  // This private constructor is called by the createCommandListener()
57  // static method.
59  int requested_port,
60  CMD_Manager &command_manager,
61  bool separate_errors,
62  bool restrict_to_safe_commands,
63  const char *ip_mask,
64  bool browser_mode);
65 
66  // This method is overriden so we can create a
67  // UI_ConnectSocketCommandListener to listen for commands from an active
68  // connection.
69  void createConnectedSocketListener() override;
70 
71 
72  // Data:
73 
74  CMD_Manager &myCommandManager;
75  bool mySeparateErrors;
76  bool myRestrictToSafeCmds;
77  bool myBrowserMode;
78 };
79 
80 #endif
void setRestrictToSafeCommands(bool restrict_to_safe_cmds)
virtual void createConnectedSocketListener()
#define CMD_API
Definition: CMD_API.h:10