<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> By default, when saving a URI using xmlSaveUri it escapes everything in the URI.  QEMU doesn't want anything escaped, so now I unescape everything after the URI is generated.  Unfortunately there's no flag to change the default behavior.<br>
<br>
I'm not sure that's the actual issue here, but I'm somehow included to<br>
think this is another consequence of the lack of query string handling<br>
for http/https URIs.<br>
<br>
In any case, do you have a simple reproducer for this escaping handling<br>
for qemu?<br></blockquote><div><br></div><div>I don't have a simple repro for qemu, but this is pretty close.  In guestfish do this:</div><div><br></div><div><div>add "/vhds/osdiskforconsul0-osdisk.vhd?se=2016-01-01T00%3A00%3A00Z&sp=r&sv=2014-02-14&sr=b&sig=LOlrHXrQeaqlSEP51hRi7E5KDa9lnkqSvLTaZBmTkrQ%3D" readonly:true protocol:https server:<a href="http://gabhartswarmstorage.blob.core.windows.net">gabhartswarmstorage.blob.core.windows.net</a></div></div><div><br></div><div>After you execute 'run', you should see qemu complaining about something like a 404 Error and the file not existing.  After the unescape change the above will start working.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> The other problem was that only the "path" portion of the URI struct was being used to indicate the path.  That's natural enough, but that practice is what was dropping the query string.  The query string is kept separately from the path.  I now concat the query string back onto the URI with a separating '?'.<br>
<br>
I don't think that appending the query string to the path is a good idea.<br>
For example, we do a minimum of parsing of the URI, and for some<br>
protocols (like the "We may have to adjust the path ..." comment says)<br>
we adjust path according to the elements in the query string.</blockquote><div> </div><div>Are you talking about this comment?</div><div><div>/* We may have to adjust the path depending on the protocol.  For</div><div> * example ceph/rbd URIs look like rbd:///pool/disk, but the</div><div> * exportname expected will be "pool/disk".  Here, uri->path will be</div><div> * "/pool/disk" so we have to knock off the leading '/' character.</div><div> */</div></div><div><br></div><div>This is talking about removing leading the '/' in the path sometimes depending on protocol.  Nothing to do with the query string.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> +  if (asprintf(&path, "%s?%s", uri->path, uri->query_raw) == -1) {<br>
> +    perror ("asprintf: path + query_raw");<br>
> +    free (*protocol_ret);<br>
> +    guestfs_int_free_string_list (*server_ret);<br>
> +    free (*username_ret);<br>
> +    free (*password_ret);<br>
> +    return -1;<br>
> +  }<br>
<br>
'path' created here is leaked. Also, this needs to take into account<br>
that either uri->path or uri->query_raw may be null.<br></blockquote><div><br></div><div>Good point.  Fixed.  See attached patch.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>    *path_ret = strdup (path ? path : "");<br>
> -  if (*path_ret == NULL) {<br>
> -    perror ("strdup: path");<br>
> -    free (*protocol_ret);<br>
> -    guestfs_int_free_string_list (*server_ret);<br>
> -    free (*username_ret);<br>
> -    free (*password_ret);<br>
> -    return -1;<br>
> -  } <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Why did you remove the error checking?<br></blockquote><div> </div><div>I didn't, it was just moved.  In any case see the attached fix.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ad additional checking for URIs, we have fish/test-add-uri.sh, which<br>
fails with your patch. You might want to also add additional checks with for query string http/https URIs.<br></blockquote><div><br></div><div>The test is now failing on this case:</div><div><div>+ guestfish -x -a 'nbd:///export?socket=/sk'</div><div>+ grep -sq 'add_drive <b>"/export"</b> "protocol:nbd" "server:unix:/sk"' test-add-uri.out</div></div><div><br></div><div>because I am now appending the query string as in:</div><div>add_drive<b> "/export?socket=/sk"</b> "protocol:nbd" "server:unix:/sk"<br></div><div><br></div><div>In which cases should the query string be appended and in what cases should it be dropped?  I believe in the http and https case it should be appended.  I'm not familiar with the nbd protocol.  Is dropping the query string always the right thing to do for this protocol?  Other protocols?</div><div> </div><div>-- Gabriel</div></div></div>