Remove unnecessary copying when listing clients
parent
51f868c6ff
commit
d53a04b5b0
|
@ -24,10 +24,10 @@ struct cmd_response;
|
|||
struct ctl_server_client;
|
||||
|
||||
struct ctl_server_client_info {
|
||||
char id[64];
|
||||
char hostname[256];
|
||||
char username[256];
|
||||
char seat[256];
|
||||
int id;
|
||||
const char *hostname;
|
||||
const char *username;
|
||||
const char *seat;
|
||||
};
|
||||
|
||||
struct ctl_server_output {
|
||||
|
|
|
@ -357,13 +357,15 @@ static struct cmd_response* generate_vnc_client_list(struct ctl* self)
|
|||
struct ctl_server_client_info 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_string(info.hostname));
|
||||
|
||||
if (info.username[0] != '\0')
|
||||
if (info.username)
|
||||
json_object_set_new(packed, "username",
|
||||
json_string(info.username));
|
||||
|
||||
|
|
15
src/main.c
15
src/main.c
|
@ -509,17 +509,10 @@ static void client_info(const struct ctl_server_client* client_handle,
|
|||
(const struct nvnc_client*)client_handle;
|
||||
const struct wayvnc_client *client = nvnc_get_userdata(vnc_client);
|
||||
|
||||
snprintf(info->id, sizeof(info->id), "%u", client->id);
|
||||
|
||||
const char* hostname = nvnc_client_get_hostname(vnc_client);
|
||||
if (hostname)
|
||||
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));
|
||||
info->id = client->id;
|
||||
info->hostname = nvnc_client_get_hostname(vnc_client);
|
||||
info->username = nvnc_client_get_auth_username(vnc_client);
|
||||
info->seat = client->seat->name;
|
||||
}
|
||||
|
||||
static int get_output_list(struct ctl* ctl,
|
||||
|
|
Loading…
Reference in New Issue