fix channel/smartcard: simplify channel variables
authorBernhard Miklautz <bernhard.miklautz@thincast.com>
Mon, 11 Dec 2017 13:00:09 +0000 (14:00 +0100)
committerBernhard Miklautz <bernhard.miklautz@thincast.com>
Wed, 13 Dec 2017 16:04:06 +0000 (17:04 +0100)
Path was not really used and name was duplicated. Use the device->Name
directly.

channels/smartcard/client/smartcard_main.c
channels/smartcard/client/smartcard_main.h
channels/smartcard/client/smartcard_pack.c
client/common/cmdline.c
include/freerdp/settings.h
libfreerdp/common/settings.c

index f21f0f2..9fe2c36 100644 (file)
@@ -677,17 +677,12 @@ static UINT smartcard_irp_request(DEVICE* device, IRP* irp)
  */
 UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
 {
-       char* name;
-       char* path;
        size_t length;
-       int ck;
        RDPDR_SMARTCARD* device;
        SMARTCARD_DEVICE* smartcard;
        LONG status;
        UINT error = CHANNEL_RC_NO_MEMORY;
        device = (RDPDR_SMARTCARD*) pEntryPoints->device;
-       name = device->Name;
-       path = device->Path;
        smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE));
 
        if (!smartcard)
@@ -712,23 +707,8 @@ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
        }
 
        Stream_Write(smartcard->device.data, "SCARD", 6);
-       smartcard->name = NULL;
-       smartcard->path = NULL;
 
-       if (path)
-       {
-               smartcard->path = path;
-               smartcard->name = name;
-       }
-       else if (name)
-       {
-               if (1 == sscanf(name, "%d", &ck))
-                       smartcard->path = name;
-               else
-                       smartcard->name = name;
-       }
-
-       status = SCardAddReaderName(&smartcard->thread, (LPSTR) name);
+       status = SCardAddReaderName(&smartcard->thread, (LPSTR) device->Name);
 
        if (status != SCARD_S_SUCCESS)
        {
index 10cdb50..8451234 100644 (file)
@@ -110,9 +110,6 @@ struct _SMARTCARD_DEVICE
 {
        DEVICE device;
 
-       char* name;
-       char* path;
-
        HANDLE thread;
        HANDLE StartedEvent;
        wMessageQueue* IrpQueue;
index 1f89d54..373064e 100644 (file)
@@ -850,7 +850,7 @@ void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReader
                CopyMemory(mszA, ret->msz, ret->cBytes);
        }
 
-       for (index = 0; index < length - 2; index++)
+       for (index = 0; index < length - 1; index++)
        {
                if (mszA[index] == '\0')
                        mszA[index] = ',';
index 6db75b9..17c3c16 100644 (file)
@@ -476,43 +476,29 @@ BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count,
                settings->RedirectSmartCards = TRUE;
                settings->DeviceRedirection = TRUE;
 
-               if (count > 1)
-               {
-                       smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD));
-
-                       if (!smartcard)
-                               return FALSE;
-
-                       smartcard->Type = RDPDR_DTYP_SMARTCARD;
+               smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD));
 
-                       if (count > 1)
-                       {
-                               if (!(smartcard->Name = _strdup(params[1])))
-                               {
-                                       free(smartcard);
-                                       return FALSE;
-                               }
-                       }
+               if (!smartcard)
+                       return FALSE;
 
-                       if (count > 2)
-                       {
-                               if (!(smartcard->Path = _strdup(params[2])))
-                               {
-                                       free(smartcard->Name);
-                                       free(smartcard);
-                                       return FALSE;
-                               }
-                       }
+               smartcard->Type = RDPDR_DTYP_SMARTCARD;
 
-                       if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard))
+               if (count > 1 && strlen(params[1]))
+               {
+                       if (!(smartcard->Name = _strdup(params[1])))
                        {
-                               free(smartcard->Path);
-                               free(smartcard->Name);
                                free(smartcard);
                                return FALSE;
                        }
                }
 
+               if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard))
+               {
+                       free(smartcard->Name);
+                       free(smartcard);
+                       return FALSE;
+               }
+
                return TRUE;
        }
        else if (strcmp(params[0], "serial") == 0)
index 2e1f796..3bbf536 100644 (file)
@@ -446,7 +446,6 @@ struct _RDPDR_SMARTCARD
        UINT32 Id;
        UINT32 Type;
        char* Name;
-       char* Path;
 };
 typedef struct _RDPDR_SMARTCARD RDPDR_SMARTCARD;
 
index 76d2439..fd4b008 100644 (file)
@@ -307,13 +307,6 @@ out_print_name_error:
                                goto out_smartc_name_error;
                }
 
-               if (smartcard->Path)
-               {
-                       _smartcard->Path = _strdup(smartcard->Path);
-                       if (!_smartcard->Path)
-                               goto out_smartc_path_error;
-               }
-
                return (RDPDR_DEVICE*) _smartcard;
 
 out_smartc_path_error:
@@ -428,7 +421,7 @@ void freerdp_device_collection_free(rdpSettings* settings)
                }
                else if (settings->DeviceArray[index]->Type == RDPDR_DTYP_SMARTCARD)
                {
-                       free(((RDPDR_SMARTCARD*) device)->Path);
+
                }
                else if (settings->DeviceArray[index]->Type == RDPDR_DTYP_SERIAL)
                {