Remove unnecessary copying when listing clients

transient-seats
Andri Yngvason 2023-03-25 13:08:15 +00:00
parent 842da93de4
commit c302c20939
3 changed files with 13 additions and 18 deletions

View File

@ -24,10 +24,10 @@ struct cmd_response;
struct ctl_server_client; struct ctl_server_client;
struct ctl_server_client_info { struct ctl_server_client_info {
char id[64]; int id;
char hostname[256]; const char *hostname;
char username[256]; const char *username;
char seat[256]; const char *seat;
}; };
struct ctl_server_output { struct ctl_server_output {

View File

@ -357,13 +357,15 @@ static struct cmd_response* generate_vnc_client_list(struct ctl* self)
struct ctl_server_client_info info = {}; struct ctl_server_client_info info = {};
ctl_server_client_get_info(self, client, &info); ctl_server_client_get_info(self, client, &info);
json_t* packed = json_pack("{s:s}", "id", info.id); char id_str[64];
snprintf(id_str, sizeof(id_str), "%d", info.id);
json_t* packed = json_pack("{s:s}", "id", id_str);
if (info.hostname[0] != '\0') if (info.hostname)
json_object_set_new(packed, "hostname", json_object_set_new(packed, "hostname",
json_string(info.hostname)); json_string(info.hostname));
if (info.username[0] != '\0') if (info.username)
json_object_set_new(packed, "username", json_object_set_new(packed, "username",
json_string(info.username)); json_string(info.username));

View File

@ -524,17 +524,10 @@ static void client_info(const struct ctl_server_client* client_handle,
(const struct nvnc_client*)client_handle; (const struct nvnc_client*)client_handle;
const struct wayvnc_client *client = nvnc_get_userdata(vnc_client); const struct wayvnc_client *client = nvnc_get_userdata(vnc_client);
snprintf(info->id, sizeof(info->id), "%u", client->id); info->id = client->id;
info->hostname = nvnc_client_get_hostname(vnc_client);
const char* hostname = nvnc_client_get_hostname(vnc_client); info->username = nvnc_client_get_auth_username(vnc_client);
if (hostname) info->seat = client->seat->name;
strlcpy(info->hostname, hostname, sizeof(info->hostname));
const char* username = nvnc_client_get_auth_username(vnc_client);
if (username)
strlcpy(info->username, username, sizeof(info->username));
strlcpy(info->seat, client->seat->name, sizeof(info->seat));
} }
static int get_output_list(struct ctl* ctl, static int get_output_list(struct ctl* ctl,