diff options
Diffstat (limited to 'sway/commands/ipc.c')
-rw-r--r-- | sway/commands/ipc.c | 162 |
1 files changed, 0 insertions, 162 deletions
diff --git a/sway/commands/ipc.c b/sway/commands/ipc.c deleted file mode 100644 index 0c678961..00000000 --- a/sway/commands/ipc.c +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <stdio.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/security.h" | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | #include "ipc.h" | ||
8 | #include "log.h" | ||
9 | #include "util.h" | ||
10 | |||
11 | static struct ipc_policy *current_policy = NULL; | ||
12 | |||
13 | struct cmd_results *cmd_ipc(int argc, char **argv) { | ||
14 | struct cmd_results *error = NULL; | ||
15 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 2))) { | ||
16 | return error; | ||
17 | } | ||
18 | if ((error = check_security_config())) { | ||
19 | return error; | ||
20 | } | ||
21 | |||
22 | char *program = NULL; | ||
23 | |||
24 | if (!strcmp(argv[0], "*")) { | ||
25 | program = strdup(argv[0]); | ||
26 | } else if (!(program = resolve_path(argv[0]))) { | ||
27 | return cmd_results_new( | ||
28 | CMD_INVALID, "ipc", "Unable to resolve IPC Policy target."); | ||
29 | } | ||
30 | if (config->reading && strcmp("{", argv[1]) != 0) { | ||
31 | return cmd_results_new(CMD_INVALID, "ipc", | ||
32 | "Expected '{' at start of IPC config definition."); | ||
33 | } | ||
34 | |||
35 | if (!config->reading) { | ||
36 | return cmd_results_new(CMD_FAILURE, "ipc", "Can only be used in config file."); | ||
37 | } | ||
38 | |||
39 | current_policy = alloc_ipc_policy(program); | ||
40 | list_add(config->ipc_policies, current_policy); | ||
41 | |||
42 | free(program); | ||
43 | return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL); | ||
44 | } | ||
45 | |||
46 | struct cmd_results *cmd_ipc_events(int argc, char **argv) { | ||
47 | struct cmd_results *error = NULL; | ||
48 | if ((error = checkarg(argc, "events", EXPECTED_EQUAL_TO, 1))) { | ||
49 | return error; | ||
50 | } | ||
51 | |||
52 | if (config->reading && strcmp("{", argv[0]) != 0) { | ||
53 | return cmd_results_new(CMD_INVALID, "events", | ||
54 | "Expected '{' at start of IPC event config definition."); | ||
55 | } | ||
56 | |||
57 | if (!config->reading) { | ||
58 | return cmd_results_new(CMD_FAILURE, "events", "Can only be used in config file."); | ||
59 | } | ||
60 | |||
61 | return cmd_results_new(CMD_BLOCK_IPC_EVENTS, NULL, NULL); | ||
62 | } | ||
63 | |||
64 | struct cmd_results *cmd_ipc_cmd(int argc, char **argv) { | ||
65 | struct cmd_results *error = NULL; | ||
66 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 1))) { | ||
67 | return error; | ||
68 | } | ||
69 | |||
70 | bool enabled; | ||
71 | if (strcmp(argv[0], "enabled") == 0) { | ||
72 | enabled = true; | ||
73 | } else if (strcmp(argv[0], "disabled") == 0) { | ||
74 | enabled = false; | ||
75 | } else { | ||
76 | return cmd_results_new(CMD_INVALID, argv[-1], | ||
77 | "Argument must be one of 'enabled' or 'disabled'"); | ||
78 | } | ||
79 | |||
80 | struct { | ||
81 | char *name; | ||
82 | enum ipc_feature type; | ||
83 | } types[] = { | ||
84 | { "*", IPC_FEATURE_ALL_COMMANDS }, | ||
85 | { "command", IPC_FEATURE_COMMAND }, | ||
86 | { "workspaces", IPC_FEATURE_GET_WORKSPACES }, | ||
87 | { "outputs", IPC_FEATURE_GET_OUTPUTS }, | ||
88 | { "tree", IPC_FEATURE_GET_TREE }, | ||
89 | { "marks", IPC_FEATURE_GET_MARKS }, | ||
90 | { "bar-config", IPC_FEATURE_GET_BAR_CONFIG }, | ||
91 | { "inputs", IPC_FEATURE_GET_INPUTS }, | ||
92 | { "clipboard", IPC_FEATURE_GET_CLIPBOARD }, | ||
93 | }; | ||
94 | |||
95 | uint32_t type = 0; | ||
96 | |||
97 | for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { | ||
98 | if (strcmp(types[i].name, argv[-1]) == 0) { | ||
99 | type = types[i].type; | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | if (enabled) { | ||
105 | current_policy->features |= type; | ||
106 | sway_log(L_DEBUG, "Enabled IPC %s feature", argv[-1]); | ||
107 | } else { | ||
108 | current_policy->features &= ~type; | ||
109 | sway_log(L_DEBUG, "Disabled IPC %s feature", argv[-1]); | ||
110 | } | ||
111 | |||
112 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
113 | } | ||
114 | |||
115 | struct cmd_results *cmd_ipc_event_cmd(int argc, char **argv) { | ||
116 | struct cmd_results *error = NULL; | ||
117 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 1))) { | ||
118 | return error; | ||
119 | } | ||
120 | |||
121 | bool enabled; | ||
122 | if (strcmp(argv[0], "enabled") == 0) { | ||
123 | enabled = true; | ||
124 | } else if (strcmp(argv[0], "disabled") == 0) { | ||
125 | enabled = false; | ||
126 | } else { | ||
127 | return cmd_results_new(CMD_INVALID, argv[-1], | ||
128 | "Argument must be one of 'enabled' or 'disabled'"); | ||
129 | } | ||
130 | |||
131 | struct { | ||
132 | char *name; | ||
133 | enum ipc_feature type; | ||
134 | } types[] = { | ||
135 | { "*", IPC_FEATURE_ALL_EVENTS }, | ||
136 | { "workspace", IPC_FEATURE_EVENT_WORKSPACE }, | ||
137 | { "output", IPC_FEATURE_EVENT_OUTPUT }, | ||
138 | { "mode", IPC_FEATURE_EVENT_MODE }, | ||
139 | { "window", IPC_FEATURE_EVENT_WINDOW }, | ||
140 | { "binding", IPC_FEATURE_EVENT_BINDING }, | ||
141 | { "input", IPC_FEATURE_EVENT_INPUT }, | ||
142 | }; | ||
143 | |||
144 | uint32_t type = 0; | ||
145 | |||
146 | for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { | ||
147 | if (strcmp(types[i].name, argv[-1]) == 0) { | ||
148 | type = types[i].type; | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | if (enabled) { | ||
154 | current_policy->features |= type; | ||
155 | sway_log(L_DEBUG, "Enabled IPC %s event", argv[-1]); | ||
156 | } else { | ||
157 | current_policy->features &= ~type; | ||
158 | sway_log(L_DEBUG, "Disabled IPC %s event", argv[-1]); | ||
159 | } | ||
160 | |||
161 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
162 | } | ||