From 36d8da628380e7a63df893846f96ee608b2e1af8 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 2 Mar 2012 13:45:15 +0100 Subject: Send name & uuid to capable clients Add spice_server_set_name() and spice_server_set_uuid() that allows the client to identify a Spice server (useful to associate settings with a particular server) The SPICE_MSG_MAIN_NAME and SPICE_MSG_MAIN_UUID messages are only sent to capable clients, announcing SPICE_MAIN_CAP_NAME_AND_UUID. --- server/main_channel.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ server/main_channel.h | 3 +++ server/reds.c | 20 +++++++++++++++ server/reds.h | 1 + server/spice-server.syms | 6 +++++ server/spice.h | 5 +++- 6 files changed, 99 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/main_channel.c b/server/main_channel.c index 878f62d4..a871bc8c 100644 --- a/server/main_channel.c +++ b/server/main_channel.c @@ -103,6 +103,16 @@ typedef struct InitPipeItem { int ram_hint; } InitPipeItem; +typedef struct NamePipeItem { + PipeItem base; + SpiceMsgMainName msg; +} NamePipeItem; + +typedef struct UuidPipeItem { + PipeItem base; + SpiceMsgMainUuid msg; +} UuidPipeItem; + typedef struct NotifyPipeItem { PipeItem base; uint8_t *mess; @@ -267,6 +277,29 @@ static PipeItem *main_init_item_new(MainChannelClient *mcc, return &item->base; } +static PipeItem *main_name_item_new(MainChannelClient *mcc, const char *name) +{ + NamePipeItem *item = spice_malloc(sizeof(NamePipeItem) + strlen(name) + 1); + + red_channel_pipe_item_init(mcc->base.channel, &item->base, + SPICE_MSG_MAIN_NAME); + item->msg.name_len = strlen(name) + 1; + memcpy(&item->msg.name, name, item->msg.name_len); + + return &item->base; +} + +static PipeItem *main_uuid_item_new(MainChannelClient *mcc, const uint8_t uuid[16]) +{ + UuidPipeItem *item = spice_malloc(sizeof(UuidPipeItem)); + + red_channel_pipe_item_init(mcc->base.channel, &item->base, + SPICE_MSG_MAIN_UUID); + memcpy(item->msg.uuid, uuid, sizeof(item->msg.uuid)); + + return &item->base; +} + typedef struct NotifyPipeInfo { uint8_t *mess; int mess_len; @@ -501,6 +534,30 @@ static void main_channel_marshall_init(SpiceMarshaller *m, spice_marshall_msg_main_init(m, &init); } +void main_channel_push_name(MainChannelClient *mcc, const char *name) +{ + PipeItem *item; + + if (!red_channel_client_test_remote_cap(&mcc->base, + SPICE_MAIN_CAP_NAME_AND_UUID)) + return; + + item = main_name_item_new(mcc, name); + red_channel_client_pipe_add_push(&mcc->base, item); +} + +void main_channel_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16]) +{ + PipeItem *item; + + if (!red_channel_client_test_remote_cap(&mcc->base, + SPICE_MAIN_CAP_NAME_AND_UUID)) + return; + + item = main_uuid_item_new(mcc, uuid); + red_channel_client_pipe_add_push(&mcc->base, item); +} + // TODO - some notifications are new client only (like "keyboard is insecure" on startup) void main_channel_push_notify(MainChannel *main_chan, uint8_t *mess, const int mess_len) { @@ -692,6 +749,14 @@ static void main_channel_send_item(RedChannelClient *rcc, PipeItem *base) case SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST: main_channel_marshall_migrate_switch(m, rcc); break; + case SPICE_MSG_MAIN_NAME: + spice_marshall_msg_main_name(m, &SPICE_CONTAINEROF(base, NamePipeItem, base)->msg); + break; + case SPICE_MSG_MAIN_UUID: + spice_marshall_msg_main_uuid(m, &SPICE_CONTAINEROF(base, UuidPipeItem, base)->msg); + break; + default: + break; }; red_channel_client_begin_send_message(rcc); } diff --git a/server/main_channel.h b/server/main_channel.h index c5d407ec..afff3139 100644 --- a/server/main_channel.h +++ b/server/main_channel.h @@ -103,4 +103,7 @@ int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_ta void main_channel_migrate_cancel_wait(MainChannel *main_chan); /* returns the number of clients for which SPICE_MSG_MAIN_MIGRATE_END was sent*/ int main_channel_migrate_complete(MainChannel *main_chan, int success); +void main_channel_push_name(MainChannelClient *mcc, const char *name); +void main_channel_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16]); + #endif diff --git a/server/reds.c b/server/reds.c index 9d7521a7..5fc03ea2 100644 --- a/server/reds.c +++ b/server/reds.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -100,6 +101,9 @@ static int sasl_enabled = 0; // sasl disabled by default #if HAVE_SASL static char *sasl_appname = NULL; // default to "spice" if NULL #endif +static char *spice_name = NULL; +static bool spice_uuid_is_set = FALSE; +static uint8_t spice_uuid[16] = { 0, }; static int ticketing_enabled = 1; //Ticketing is enabled by default static pthread_mutex_t *lock_cs; @@ -1668,6 +1672,10 @@ static void reds_handle_main_link(RedLinkInfo *link) reds->mouse_mode, reds->is_client_mouse_allowed, reds_get_mm_time() - MM_TIME_DELTA, red_dispatcher_qxl_ram_size()); + if (spice_name) + main_channel_push_name(mcc, spice_name); + if (spice_uuid_is_set) + main_channel_push_uuid(mcc, spice_uuid); main_channel_client_start_net_test(mcc); /* Now that we have a client, forward any pending agent data */ @@ -3810,6 +3818,18 @@ SPICE_GNUC_VISIBLE int spice_server_set_sasl_appname(SpiceServer *s, const char #endif } +SPICE_GNUC_VISIBLE void spice_server_set_name(SpiceServer *s, const char *name) +{ + free(spice_name); + spice_name = strdup(name); +} + +SPICE_GNUC_VISIBLE void spice_server_set_uuid(SpiceServer *s, const uint8_t uuid[16]) +{ + memcpy(spice_uuid, uuid, sizeof(spice_uuid)); + spice_uuid_is_set = TRUE; +} + SPICE_GNUC_VISIBLE int spice_server_set_ticket(SpiceServer *s, const char *passwd, int lifetime, int fail_if_connected, diff --git a/server/reds.h b/server/reds.h index 1fd18a70..1c59e689 100644 --- a/server/reds.h +++ b/server/reds.h @@ -152,4 +152,5 @@ void reds_on_main_migrate_connected(void); //should be called when all the clien void reds_on_main_receive_migrate_data(MainMigrateData *data, uint8_t *end); void reds_on_main_mouse_mode_request(void *message, size_t size); void reds_on_client_migrate_complete(RedClient *client); + #endif diff --git a/server/spice-server.syms b/server/spice-server.syms index d9beec35..272548ed 100644 --- a/server/spice-server.syms +++ b/server/spice-server.syms @@ -101,3 +101,9 @@ global: spice_server_add_client; spice_server_add_ssl_client; } SPICE_SERVER_0.10.0; + +SPICE_SERVER_0.10.2 { +global: + spice_server_set_name; + spice_server_set_uuid; +} SPICE_SERVER_0.10.1; diff --git a/server/spice.h b/server/spice.h index 73976557..151b3db0 100644 --- a/server/spice.h +++ b/server/spice.h @@ -22,7 +22,7 @@ #include #include -#define SPICE_SERVER_VERSION 0x000a01 /* release 0.10.1 */ +#define SPICE_SERVER_VERSION 0x000a02 /* release 0.10.2 */ /* interface base type */ @@ -519,4 +519,7 @@ int spice_server_migrate_connect(SpiceServer *s, const char* dest, int spice_server_migrate_start(SpiceServer *s); int spice_server_migrate_end(SpiceServer *s, int completed); +void spice_server_set_name(SpiceServer *s, const char *name); +void spice_server_set_uuid(SpiceServer *s, const uint8_t uuid[16]); + #endif -- cgit