Re: [phodav PATCH 2/3 v3] spice-webdavd-windows: Check for mapped shared folder

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 24, 2016 at 04:39:41PM +0100, Lukas Venhoda wrote:
> Check whether Spice Folder is already mapped.
> If yes, don't try to map another one.
> ---
> Changes since v3:
>  - changed function is_spice_folder_mapped to get_spice_folder_letter
>     - Now returns the mapped folder drive letter
>     - This can be used to call unmap_drive
>     - No need for global variable drive_letter
>  - Better handeling of adress string
>     - No hardcoded port
>  - Syntax cleanup
>
> Changes since v2:
>  - New patch
> ---
>  spice/spice-webdavd.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 44 insertions(+), 4 deletions(-)
> 
> diff --git a/spice/spice-webdavd.c b/spice/spice-webdavd.c
> index ee49469..be2bf90 100644
> --- a/spice/spice-webdavd.c
> +++ b/spice/spice-webdavd.c
> @@ -765,6 +765,43 @@ get_free_drive_letter(void)
>    return 0;
>  }
>
> +static gchar
> +get_spice_folder_letter(void)
> +{
> +  #define MAX_NAME_SIZE 64

Don't do #define here, do it with global functions and struct
definitions.

> +  const guint32 max_mask = 1 << 25;
> +  gchar local_name[3] = "z:";
> +  gchar remote_name[MAX_NAME_SIZE];
In the loop ^

> +  gchar * spice_folder_name;
> +  gchar spice_folder_letter = 0;
> +  guint32 size = sizeof(remote_name);
In the loop ^

> +  guint32 drives;
> +  guint32 mask;
In the loop ^

> +  guint32 i;
> +
> +  drives = GetLogicalDrives ();
> +  spice_folder_name = g_strdup_printf("\\\\localhost@%d\\DavWWWRoot", port);
> +
> +  for (i = 0; i < 26; i++)
> +  {
> +    mask = max_mask >> i;
> +    if (drives & mask)
> +    {
> +      local_name[0] = 'z' - i;
> +      if ((WNetGetConnection (local_name, remote_name, (LPDWORD)&size) == NO_ERROR) &&
> +          (g_strcmp0 (remote_name, spice_folder_name) == 0))
> +      {

Include debug here pointing that we'll be reusing this drive letter..

> +        spice_folder_letter = local_name[0];
> +        break;
> +      }

We should consider debugging for a few interesting errors (not sure
which ones). Last time I've tested, I got some issue with using the same
drive letter...

Apart from that, looks good.

> +    }
> +  }
> +
> +  g_free(spice_folder_name);
> +
> +  return spice_folder_letter;
> +}
> +
>  /* User is required to call clear_netresource, when no longer needed. */
>  static void
>  init_netresource(NETRESOURCE * net_resource, const gchar drive_letter)
> @@ -850,10 +887,13 @@ run_service (void)
> 
>  #ifdef G_OS_WIN32
>    GCancellable * cancel_map = g_cancellable_new ();
> -  GTask * map_drive_task = g_task_new (NULL, NULL, NULL, NULL);
> -  g_task_set_task_data (map_drive_task, cancel_map, NULL);
> -  g_task_run_in_thread (map_drive_task, map_drive_cb);
> -  g_object_unref (map_drive_task);
> +  if (get_spice_folder_letter () != 0)
> +  {
> +    GTask * map_drive_task = g_task_new (NULL, NULL, NULL, NULL);
> +    g_task_set_task_data (map_drive_task, cancel_map, NULL);
> +    g_task_run_in_thread (map_drive_task, map_drive_cb);
> +    g_object_unref (map_drive_task);
> +  }
>  #endif
> 
>    g_socket_service_start (socket_service);
> --
> 2.5.5
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]