2022-11-26 21:26:30 +00:00
|
|
|
/*
|
2023-01-06 18:39:23 +00:00
|
|
|
* Copyright (c) 2022-2023 Jim Ramsay
|
2022-11-26 21:26:30 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ctl-commands.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2022-12-06 12:12:02 +00:00
|
|
|
#include <string.h>
|
2022-11-26 21:26:30 +00:00
|
|
|
|
|
|
|
struct cmd_info ctl_command_list[] = {
|
|
|
|
[CMD_HELP] = { "help",
|
|
|
|
"List all commands and events, or show usage of a specific command or event",
|
|
|
|
{
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "command",
|
|
|
|
"The command to show (optional)",
|
|
|
|
"<name>" },
|
|
|
|
{ "event",
|
|
|
|
"The event to show (optional)",
|
|
|
|
"<name>" },
|
|
|
|
{},
|
2022-11-26 21:26:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[CMD_VERSION] = { "version",
|
|
|
|
"Query the version of the wayvnc process",
|
2023-01-11 10:19:46 +00:00
|
|
|
{{}}
|
2022-11-26 21:26:30 +00:00
|
|
|
},
|
|
|
|
[CMD_EVENT_RECEIVE] = { "event-receive",
|
|
|
|
"Register to begin receiving asynchronous events from wayvnc",
|
|
|
|
// TODO: Event type filtering?
|
2023-01-11 10:19:46 +00:00
|
|
|
{{}}
|
2022-11-26 21:26:30 +00:00
|
|
|
},
|
2023-01-06 20:44:39 +00:00
|
|
|
[CMD_CLIENT_LIST] = { "client-list",
|
|
|
|
"Return a list of all currently connected VNC sessions",
|
2023-01-11 10:19:46 +00:00
|
|
|
{{}}
|
2023-01-06 20:44:39 +00:00
|
|
|
},
|
|
|
|
[CMD_CLIENT_DISCONNECT] = { "client-disconnect",
|
|
|
|
"Disconnect a VNC session",
|
2022-11-26 21:26:30 +00:00
|
|
|
{
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "id",
|
|
|
|
"The ID of the client to disconnect",
|
2023-01-15 18:10:26 +00:00
|
|
|
"<integer>", true },
|
2023-01-11 10:19:46 +00:00
|
|
|
{},
|
2022-11-26 21:26:30 +00:00
|
|
|
}
|
|
|
|
},
|
2023-01-06 20:44:39 +00:00
|
|
|
[CMD_OUTPUT_LIST] = { "output-list",
|
2022-11-26 21:26:30 +00:00
|
|
|
"Return a list of all currently detected Wayland outputs",
|
2023-01-11 10:19:46 +00:00
|
|
|
{{}}
|
2022-11-26 21:26:30 +00:00
|
|
|
},
|
2023-01-06 20:59:02 +00:00
|
|
|
[CMD_OUTPUT_CYCLE] = { "output-cycle",
|
|
|
|
"Cycle the actively captured output to the next available output, wrapping through all outputs.",
|
2023-01-11 10:19:46 +00:00
|
|
|
{{}}
|
2023-01-06 20:59:02 +00:00
|
|
|
},
|
2023-01-06 20:44:39 +00:00
|
|
|
[CMD_OUTPUT_SET] = { "output-set",
|
|
|
|
"Switch the actively captured output",
|
2022-11-26 21:26:30 +00:00
|
|
|
{
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "output-name",
|
|
|
|
"The specific output name to capture",
|
2023-01-15 18:10:26 +00:00
|
|
|
"<string>", true },
|
2023-01-11 10:19:46 +00:00
|
|
|
{},
|
2022-11-26 21:26:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[CMD_WAYVNC_EXIT] = { "wayvnc-exit",
|
|
|
|
"Disconnect all clients and shut down wayvnc",
|
2023-01-11 10:19:46 +00:00
|
|
|
{{}},
|
2022-11-26 21:26:30 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CLIENT_EVENT_PARAMS(including) \
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "id", \
|
|
|
|
"A unique identifier for this client", \
|
2023-01-15 18:10:26 +00:00
|
|
|
"<integer>" }, \
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "connection_count", \
|
|
|
|
"The total number of connected VNC clients " including " this one.", \
|
2023-01-15 18:10:26 +00:00
|
|
|
"<integer>" }, \
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "hostname", \
|
|
|
|
"The hostname or IP address of this client (may be null)", \
|
|
|
|
"<name|ip>" }, \
|
|
|
|
{ "username", \
|
|
|
|
"The username used to authentice this client (may be null).", \
|
2023-01-15 18:10:26 +00:00
|
|
|
"<string>" }, \
|
2023-01-11 10:19:46 +00:00
|
|
|
{},
|
2022-11-26 21:26:30 +00:00
|
|
|
|
|
|
|
struct cmd_info ctl_event_list[] = {
|
2023-01-06 20:44:39 +00:00
|
|
|
[EVT_CAPTURE_CHANGED] = {"capture-changed",
|
2023-01-15 18:01:44 +00:00
|
|
|
"Sent by wayvnc when the captured output is changed",
|
2023-01-06 20:44:39 +00:00
|
|
|
{
|
2023-01-11 10:19:46 +00:00
|
|
|
{ "output-name",
|
|
|
|
"The name of the output now being captured",
|
2023-01-15 18:10:26 +00:00
|
|
|
"<string>" },
|
2023-01-11 10:19:46 +00:00
|
|
|
{},
|
2023-01-06 20:44:39 +00:00
|
|
|
},
|
|
|
|
},
|
2022-11-26 21:26:30 +00:00
|
|
|
[EVT_CLIENT_CONNECTED] = {"client-connected",
|
2023-01-15 18:00:09 +00:00
|
|
|
"Sent by wayvnc when a new VNC client connects",
|
2022-11-26 21:26:30 +00:00
|
|
|
{ CLIENT_EVENT_PARAMS("including") }
|
|
|
|
},
|
|
|
|
[EVT_CLIENT_DISCONNECTED] = {"client-disconnected",
|
2023-01-15 18:00:09 +00:00
|
|
|
"Sent by waynvc when a VNC client disconnects",
|
2022-11-26 21:26:30 +00:00
|
|
|
{ CLIENT_EVENT_PARAMS("not including") }
|
|
|
|
},
|
|
|
|
};
|
2022-12-06 12:12:02 +00:00
|
|
|
|
|
|
|
enum cmd_type ctl_command_parse_name(const char* name)
|
|
|
|
{
|
|
|
|
if (!name || name[0] == '\0')
|
|
|
|
return CMD_UNKNOWN;
|
|
|
|
for (size_t i = 0; i < CMD_LIST_LEN; ++i) {
|
|
|
|
if (strcmp(name, ctl_command_list[i].name) == 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CMD_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum event_type ctl_event_parse_name(const char* name)
|
|
|
|
{
|
|
|
|
if (!name || name[0] == '\0')
|
|
|
|
return EVT_UNKNOWN;
|
|
|
|
for (size_t i = 0; i < EVT_LIST_LEN; ++i) {
|
|
|
|
if (strcmp(name, ctl_event_list[i].name) == 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EVT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_info* ctl_command_by_type(enum cmd_type cmd)
|
|
|
|
{
|
|
|
|
if (cmd == CMD_UNKNOWN)
|
|
|
|
return NULL;
|
|
|
|
return &ctl_command_list[cmd];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_info* ctl_command_by_name(const char* name)
|
|
|
|
{
|
|
|
|
return ctl_command_by_type(ctl_command_parse_name(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_info* ctl_event_by_type(enum event_type evt)
|
|
|
|
{
|
|
|
|
if (evt == EVT_UNKNOWN)
|
|
|
|
return NULL;
|
|
|
|
return &ctl_event_list[evt];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_info* ctl_event_by_name(const char* name)
|
|
|
|
{
|
|
|
|
return ctl_event_by_type(ctl_event_parse_name(name));
|
|
|
|
}
|