[Spice-commits] Branch '0.10' - 2 commits - common/messages.h configure.ac python_modules/demarshal.py server/main_channel.c server/main_channel.h server/reds.c server/reds.h server/red_tunnel_worker.c server/spice.h server/spice-server.syms spice.proto

Marc-André Lureau elmarco at kemper.freedesktop.org
Mon May 28 04:11:23 PDT 2012


 common/messages.h           |    9 +++++
 configure.ac                |    2 -
 python_modules/demarshal.py |    2 -
 server/main_channel.c       |   69 ++++++++++++++++++++++++++++++++++++++++++--
 server/main_channel.h       |    3 +
 server/red_tunnel_worker.c  |    4 +-
 server/reds.c               |   30 +++++++++++++++----
 server/reds.h               |    1 
 server/spice-server.syms    |    6 +++
 server/spice.h              |    5 ++-
 spice.proto                 |   10 ++++++
 11 files changed, 129 insertions(+), 12 deletions(-)

New commits:
commit 3d12509f987c9bee6e7c28589a02be2015284e43
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Mar 20 20:29:15 2012 +0100

    Use spice_strdup() to avoid crashing on NULL
    
    qemu can call spice_server_set_name(s, NULL) when the name is not
    given. Let's not crash in this case

diff --git a/server/main_channel.c b/server/main_channel.c
index 9998c9f..72b6735 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -639,10 +639,10 @@ static void main_channel_fill_mig_target(MainChannel *main_channel, RedsMigSpice
 {
     ASSERT(mig_target);
     free(main_channel->mig_target.host);
-    main_channel->mig_target.host = strdup(mig_target->host);
+    main_channel->mig_target.host = spice_strdup(mig_target->host);
     free(main_channel->mig_target.cert_subject);
     if (mig_target->cert_subject) {
-        main_channel->mig_target.cert_subject = strdup(mig_target->cert_subject);
+        main_channel->mig_target.cert_subject = spice_strdup(mig_target->cert_subject);
     }
     main_channel->mig_target.port = mig_target->port;
     main_channel->mig_target.sport = mig_target->sport;
diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
index 9162da4..ff40277 100644
--- a/server/red_tunnel_worker.c
+++ b/server/red_tunnel_worker.c
@@ -1077,8 +1077,8 @@ static inline TunnelService *__tunnel_worker_add_service(TunnelWorker *worker, u
     new_service->group = group;
     new_service->port = port;
 
-    new_service->name = strdup(name);
-    new_service->description = strdup(description);
+    new_service->name = spice_strdup(name);
+    new_service->description = spice_strdup(description);
 
     ring_add(&worker->services, &new_service->ring_item);
     worker->num_services++;
diff --git a/server/reds.c b/server/reds.c
index d095370..94d31fd 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2366,7 +2366,7 @@ static void reds_handle_auth_mechname(void *opaque)
     }
 
     free(sasl->mechlist);
-    sasl->mechlist = strdup(sasl->mechname);
+    sasl->mechlist = spice_strdup(sasl->mechname);
 
     red_printf("Validated mechname '%s'", sasl->mechname);
 
@@ -2501,7 +2501,7 @@ static void reds_start_auth_sasl(RedLinkInfo *link)
     }
     red_printf("Available mechanisms for client: '%s'", mechlist);
 
-    sasl->mechlist = strdup(mechlist);
+    sasl->mechlist = spice_strdup(mechlist);
 
     mechlistlen = strlen(mechlist);
     if (!sync_write(link->stream, &mechlistlen, sizeof(uint32_t))
@@ -3775,7 +3775,7 @@ SPICE_GNUC_VISIBLE int spice_server_set_sasl_appname(SpiceServer *s, const char
     ASSERT(reds == s);
 #if HAVE_SASL
     free(sasl_appname);
-    sasl_appname = strdup(appname);
+    sasl_appname = spice_strdup(appname);
     return 0;
 #else
     return -1;
@@ -3785,7 +3785,7 @@ SPICE_GNUC_VISIBLE int spice_server_set_sasl_appname(SpiceServer *s, const char
 SPICE_GNUC_VISIBLE void spice_server_set_name(SpiceServer *s, const char *name)
 {
     free(spice_name);
-    spice_name = strdup(name);
+    spice_name = spice_strdup(name);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_set_uuid(SpiceServer *s, const uint8_t uuid[16])
@@ -4022,9 +4022,9 @@ static int reds_set_migration_dest_info(const char* dest,
     spice_migration = spice_new0(RedsMigSpice, 1);
     spice_migration->port = port;
     spice_migration->sport = secure_port;
-    spice_migration->host = strdup(dest);
+    spice_migration->host = spice_strdup(dest);
     if (cert_subject) {
-        spice_migration->cert_subject = strdup(cert_subject);
+        spice_migration->cert_subject = spice_strdup(cert_subject);
     }
 
     reds->mig_spice = spice_migration;
commit b8c928ccd810a46794f77746377e614f90d37a5b
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Fri Mar 2 13:45:15 2012 +0100

    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.
    
    Conflicts:
    
    	spice-protocol

diff --git a/common/messages.h b/common/messages.h
index a54190f..ec58da5 100644
--- a/common/messages.h
+++ b/common/messages.h
@@ -149,6 +149,15 @@ typedef struct SpiceMsgChannels {
     SpiceChannelId channels[0];
 } SpiceMsgChannels;
 
+typedef struct SpiceMsgMainName {
+    uint32_t name_len;
+    uint8_t name[0];
+} SpiceMsgMainName;
+
+typedef struct SpiceMsgMainUuid {
+    uint8_t uuid[16];
+} SpiceMsgMainUuid;
+
 typedef struct SpiceMsgMainMouseMode {
     uint32_t supported_modes;
     uint32_t current_mode;
diff --git a/configure.ac b/configure.ac
index 0f8ad7d..b92c154 100644
--- a/configure.ac
+++ b/configure.ac
@@ -132,7 +132,7 @@ AM_CONDITIONAL(SUPPORT_CLIENT, test "x$enable_client" = "xyes")
 dnl =========================================================================
 dnl Check deps
 
-PKG_CHECK_MODULES(PROTOCOL, spice-protocol >= 0.10.1)
+PKG_CHECK_MODULES(PROTOCOL, spice-protocol >= 0.10.3)
 AC_SUBST(PROTOCOL_CFLAGS)
 
 AC_CHECK_LIBM
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 3a0178e..541735a 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -664,7 +664,7 @@ def read_array_len(writer, prefix, array, dest, scope, is_ptr):
         nelements = "%s__array__nelements" % prefix
     else:
         nelements = "%s__nelements" % prefix
-    if dest.is_toplevel():
+    if dest.is_toplevel() and scope.variable_defined(nelements):
         return nelements # Already there for toplevel, need not recalculate
     element_type = array.element_type
     scope.variable_def("uint32_t", nelements)
diff --git a/server/main_channel.c b/server/main_channel.c
index f7e1ab0..9998c9f 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -105,6 +105,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;
@@ -269,6 +279,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;
@@ -503,6 +536,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)
 {
@@ -694,6 +751,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 c5d407e..afff313 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 8cc87c2..d095370 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <ctype.h>
+#include <stdbool.h>
 
 #include <openssl/bio.h>
 #include <openssl/pem.h>
@@ -99,6 +100,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;
@@ -1643,6 +1647,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 */
@@ -3774,6 +3782,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 1fd18a7..1c59e68 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 d9beec3..272548e 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 7397655..151b3db 100644
--- a/server/spice.h
+++ b/server/spice.h
@@ -22,7 +22,7 @@
 #include <sys/socket.h>
 #include <spice/qxl_dev.h>
 
-#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
diff --git a/spice.proto b/spice.proto
index 0e15fe7..ae27c8d 100644
--- a/spice.proto
+++ b/spice.proto
@@ -134,6 +134,7 @@ channel BaseChannel {
     } notify;
 
     Data list; /* the msg body is SpiceSubMessageList */
+
  client:
     message {
 	uint32 generation;
@@ -222,6 +223,15 @@ channel MainChannel : BaseChannel {
 
     Empty migrate_end;
 
+    message {
+       uint32 name_len;
+       uint8 name[name_len];
+    } name;
+
+    message {
+       uint8 uuid[16];
+    } uuid;
+
  client:
     message {
 	uint64 cache_size;


More information about the Spice-commits mailing list