[Spice-commits] 4 commits - server/smartcard.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Feb 11 13:07:13 UTC 2019


 server/smartcard.c |   32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

New commits:
commit 9a605dcc67952ff699a640c2d658af5d872122ca
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Feb 8 17:26:27 2019 +0100

    smartcard: Improve on_message_from_device readability
    
    This removes a not really useful switch/case, and changes the function
    to exit early on error cases, rather than exiting early in the nominal
    case.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/smartcard.c b/server/smartcard.c
index eb0b06fa..34cfca23 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -198,11 +198,8 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
     vheader->length = ntohl(vheader->length);
     vheader->reader_id = ntohl(vheader->reader_id);
 
-    switch (vheader->type) {
-        case VSC_Init:
-            return NULL;
-        default:
-            break;
+    if (vheader->type == VSC_Init) {
+        return NULL;
     }
     /* We pass any VSC_Error right now - might need to ignore some? */
     if (dev->priv->reader_id == VSCARD_UNDEFINED_READER_ID) {
@@ -210,10 +207,10 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
                             "error: reader_id not assigned for message of type %d",
                             vheader->type);
     }
-    if (dev->priv->scc) {
-        return smartcard_new_vsc_msg_item(dev->priv->reader_id, vheader);
+    if (dev->priv->scc == NULL) {
+        return NULL;
     }
-    return NULL;
+    return smartcard_new_vsc_msg_item(dev->priv->reader_id, vheader);
 }
 
 static int smartcard_char_device_add_to_readers(RedsState *reds, SpiceCharDeviceInstance *char_device)
commit 6c79fd31e046fa2540f42b9753a0d7ed17026638
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Feb 8 17:26:26 2019 +0100

    smartcard: Rework smartcard_get_vsc_msg_item a bit
    
    This renames the method to smartcard_new_vsc_msg_item as this creates a
    new object. This also removes the creation of a temporary VHeader which
    is then going to be duplicated.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/smartcard.c b/server/smartcard.c
index 39ada9c2..eb0b06fa 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -103,7 +103,7 @@ typedef struct RedMsgItem {
     VSCMsgHeader* vheader;
 } RedMsgItem;
 
-static RedMsgItem *smartcard_get_vsc_msg_item(VSCMsgHeader *vheader);
+static RedMsgItem *smartcard_new_vsc_msg_item(unsigned int reader_id, const VSCMsgHeader *vheader);
 
 static struct Readers {
     uint32_t num;
@@ -194,8 +194,6 @@ static void smartcard_remove_client(RedCharDevice *self, RedClient *client)
 RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard *dev,
                                                          VSCMsgHeader *vheader)
 {
-    VSCMsgHeader *sent_header;
-
     vheader->type = ntohl(vheader->type);
     vheader->length = ntohl(vheader->length);
     vheader->reader_id = ntohl(vheader->reader_id);
@@ -213,11 +211,7 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
                             vheader->type);
     }
     if (dev->priv->scc) {
-        sent_header = g_memdup(vheader, sizeof(*vheader) + vheader->length);
-        /* We patch the reader_id, since the device only knows about itself, and
-         * we know about the sum of readers. */
-        sent_header->reader_id = dev->priv->reader_id;
-        return smartcard_get_vsc_msg_item(sent_header);
+        return smartcard_new_vsc_msg_item(dev->priv->reader_id, vheader);
     }
     return NULL;
 }
@@ -456,13 +450,16 @@ static void smartcard_free_vsc_msg_item(RedPipeItem *base)
     g_free(item);
 }
 
-static RedMsgItem *smartcard_get_vsc_msg_item(VSCMsgHeader *vheader)
+static RedMsgItem *smartcard_new_vsc_msg_item(unsigned int reader_id, const VSCMsgHeader *vheader)
 {
     RedMsgItem *msg_item = g_new0(RedMsgItem, 1);
 
     red_pipe_item_init_full(&msg_item->base, RED_PIPE_ITEM_TYPE_SMARTCARD_DATA,
                             smartcard_free_vsc_msg_item);
-    msg_item->vheader = vheader;
+    msg_item->vheader = g_memdup(vheader, sizeof(*vheader) + vheader->length);
+    /* We patch the reader_id, since the device only knows about itself, and
+     * we know about the sum of readers. */
+    msg_item->vheader->reader_id = reader_id;
     return msg_item;
 }
 
commit 44836fb55dc4680385d43c7b41b3039b94e72a58
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Feb 8 17:26:25 2019 +0100

    smartcard: Remove redundant test in smartcard_char_device_on_message_from_device()
    
    The function returns NULL if vheader->type is VSC_Init so no need to
    check it a second time.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/smartcard.c b/server/smartcard.c
index 21dc8de5..39ada9c2 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -207,7 +207,7 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
             break;
     }
     /* We pass any VSC_Error right now - might need to ignore some? */
-    if (dev->priv->reader_id == VSCARD_UNDEFINED_READER_ID && vheader->type != VSC_Init) {
+    if (dev->priv->reader_id == VSCARD_UNDEFINED_READER_ID) {
         red_channel_warning(red_channel_client_get_channel(RED_CHANNEL_CLIENT(dev->priv->scc)),
                             "error: reader_id not assigned for message of type %d",
                             vheader->type);
commit 2b7632b37651b0d2e68628deed9200958a573796
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Feb 8 17:26:24 2019 +0100

    smartcard: Remove unused smartcard_get_vsc_msg_item argument
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/smartcard.c b/server/smartcard.c
index ff680d8a..21dc8de5 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -103,7 +103,7 @@ typedef struct RedMsgItem {
     VSCMsgHeader* vheader;
 } RedMsgItem;
 
-static RedMsgItem *smartcard_get_vsc_msg_item(RedChannelClient *rcc, VSCMsgHeader *vheader);
+static RedMsgItem *smartcard_get_vsc_msg_item(VSCMsgHeader *vheader);
 
 static struct Readers {
     uint32_t num;
@@ -217,8 +217,7 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
         /* We patch the reader_id, since the device only knows about itself, and
          * we know about the sum of readers. */
         sent_header->reader_id = dev->priv->reader_id;
-        return smartcard_get_vsc_msg_item(RED_CHANNEL_CLIENT(dev->priv->scc),
-                                          sent_header);
+        return smartcard_get_vsc_msg_item(sent_header);
     }
     return NULL;
 }
@@ -457,8 +456,7 @@ static void smartcard_free_vsc_msg_item(RedPipeItem *base)
     g_free(item);
 }
 
-static RedMsgItem *smartcard_get_vsc_msg_item(RedChannelClient *rcc,
-                                              VSCMsgHeader *vheader)
+static RedMsgItem *smartcard_get_vsc_msg_item(VSCMsgHeader *vheader)
 {
     RedMsgItem *msg_item = g_new0(RedMsgItem, 1);
 


More information about the Spice-commits mailing list