<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:0cm;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:16.0pt;
        font-family:"Calibri Light",sans-serif;
        color:#2E74B5;
        font-weight:normal;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
        {mso-style-priority:1;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Calibri Light",sans-serif;
        color:#2E74B5;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="CS" link="blue" vlink="#954F72"><div class="WordSection1"><p class="MsoNormal">Hi</p><p class="MsoNormal"> </p><p class="MsoNormal">Answers are below</p><p class="MsoNormal"> </p><p class="MsoNormal">Lukáš Venhoda</p><p class="MsoNormal"> </p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal" style="border:none;padding:0cm"><b>From: </b><a href="mailto:pgrunt@redhat.com">Pavel Grunt</a><br><b>Sent: </b>pátek 18. března 2016 7:21<br><b>To: </b><a href="mailto:lvenhoda@redhat.com">Lukas Venhoda</a>; <a href="mailto:spice-devel@lists.freedesktop.org">spice-devel@lists.freedesktop.org</a><br><b>Subject: </b>Re: [Spice-devel] [phodav PATCH 5/7 v3] spice-webdavd-windows: Automount shared folder</p></div><p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> </span></p><p class="MsoNoSpacing">> +gchar drive_letter;<br><br></p><p class="MsoNoSpacing">P: You don't need this variable. map_drive can accept const gchar instead<br>of void.<br><br></p><p class="MsoNoSpacing">L: This variable is not because of map_drive, but because of unmap_drive.</p><p class="MsoNoSpacing">I need to remember to what letter I mapped the drive.</p><p class="MsoNoSpacing">I could pass a structure with cancel_map and drive_letter to map_drive_cb instead.</p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>> +<br>> +static gchar<br>> +get_free_drive_letter(void)</span></p><p class="MsoNoSpacing"> </p><p class="MsoNoSpacing">P: Also would you mind adding some comments to this function ? To make it<br>clear how it gets the free drive and what these masks represent.<br><br></p><p class="MsoNoSpacing">L: Sure, I’ll add it as a comment.</p><p class="MsoNoSpacing">Basically GetLogicalDrives() returns bitfield of drives (A-Z … 1-26)</p><p class="MsoNoSpacing">The max_mask is Z, shifting causes going from Z to A.</p><p class="MsoNoSpacing"> </p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">> +{<br>> +  const guint32 max_mask = 1 << 25;<br>> +  guint32 drives;<br>> +  guint32 mask;<br>> +  gint i;<br>> +<br>> +  drives = GetLogicalDrives ();<br>> +<br>> +  for (i = 0; i < 26; i++)<br>> +  {<br>> +      mask = max_mask >> i;<br>> +      if ((drives & mask) == 0)<br>> +        return 'z' - i;<br>> +  }<br>> +<br>> +  return 0;<br>> +}<br>> +<br>> +static map_drive_enum<br>> +map_drive(void)<br>> +{<br>> +  gchar local_name[3];<br>> +  gchar remote_name[] = "</span><a href="http://localhost:9843/" target="_blank"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">http://localhost:9843/</span></a><span style="font-size:12.0pt;font-family:"Times New Roman",serif">";<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: it is only used in the net_resource</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">L: Ok will change</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>> +  NETRESOURCE net_resource;<br>> +  guint32 retval;<br>> +<br>> +  local_name[0] = drive_letter;<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: drive_letter should be parameter to this function</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">L: See previous comment</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>> +  local_name[1] = ':';<br>> +  local_name[2] = 0;<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">I would prefer some sprintf-like function instead</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Ok will change</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> </span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">> +<br>> +  net_resource.dwType = RESOURCETYPE_DISK;<br>> +  net_resource.lpLocalName = local_name;<br>> +  net_resource.lpRemoteName = remote_name;<br>> +  net_resource.lpProvider = NULL;<br><br>P:In my opinion setting up net_resource should go to a separate<br>function,. You don't need 'local_name' and 'remote_name' to map the<br>drive, you need the net_resource.</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">L: Ok will change</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>> +<br>> +  retval = WNetAddConnection2 (&net_resource, NULL, NULL,<br>> CONNECT_TEMPORARY);<br>> +<br>> +  if (retval == NO_ERROR) {<br>> +    g_debug ("map_drive ok");<br>> +    return MAP_DRIVE_OK;<br>> +  } else if (retval == ERROR_ALREADY_ASSIGNED) {<br>> +    g_debug ("map_drive already asigned");<br>> +    return MAP_DRIVE_TRY_AGAIN;<br>> +  } else {<br>> +    g_critical ("map_drive error %d", retval);<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: Is it critical enough to exit the program? I would use g_warning</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">L: g_critical doesnt exit the program, but no other error then ALREADY_ASIGNED should happen here</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>> +    return MAP_DRIVE_ERROR;<br>> +  }<br>> +}<br>> +<br>> +static void<br>> +map_drive_cb(GTask *task,<br>> +          gpointer source_object,<br>> +          gpointer task_data,<br>> +          GCancellable *cancellable)<br>> +{<br>> +  guint32 timeout = 500; //half a second<br>> +  GCancellable * cancel_map = task_data;<br>> +  GPollFD cancel_pollfd;<br>> +<br>> +  if (!g_cancellable_make_pollfd (cancel_map, &cancel_pollfd))<br>> +  {<br>> +    g_critical ("GPollFD failed to create.");<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: critical/warning<br>L: See ^</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> </span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">> +    return;<br>> +  }<br>> +<br>> +  if (g_poll (&cancel_pollfd, 1, timeout) <= 0)<br>> +  {<br>> +    while (TRUE)<br>> +    {<br>> +      if ((drive_letter = get_free_drive_letter ()) == 0)<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: I would move assignment from the condition</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">L: Ok will change<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">> +      {<br>> +        g_critical ("all drive letters already assigned.");<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: critical/warning<br>L: Warning might be better here</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>> +        break;<br>> +      }<br>> +<br>> +      if (map_drive () != MAP_DRIVE_TRY_AGAIN)<br>> +        break;<br>> +    }<br>> +<br>> +    //TODO: Rename network drive after mapping<br><br></span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">P: Can you please add more info? What is the name ?<br>L: Sure</span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> </span></p><p class="MsoNoSpacing"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">> +  }<br>> +<br>> +  g_cancellable_release_fd (cancel_map);<br>> +  return;<br>> +}<br>> +#endif</span></p><p class="MsoNormal"> </p></div></body></html>