diff --git a/include/ctl-server.h b/include/ctl-server.h index ce6249e..8392b28 100644 --- a/include/ctl-server.h +++ b/include/ctl-server.h @@ -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 { diff --git a/src/ctl-server.c b/src/ctl-server.c index e308309..4c5e68d 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -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)); diff --git a/src/main.c b/src/main.c index 4ca2d17..f420d38 100644 --- a/src/main.c +++ b/src/main.c @@ -524,17 +524,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,