<div dir="ltr"><div dir="ltr">Hi<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 23, 2020 at 4:33 PM Richard W.M. Jones &lt;<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jul 09, 2020 at 11:42:34PM +0400, Marc-André Lureau wrote:<br>
&gt; Signed-off-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com" target="_blank">marcandre.lureau@redhat.com</a>&gt;<br>
&gt; ---<br>
&gt;  block/ssh.c | 75 +++++++++++++++++++++++++++++++++++++++++------------<br>
&gt;  1 file changed, 58 insertions(+), 17 deletions(-)<br>
&gt; <br>
&gt; diff --git a/block/ssh.c b/block/ssh.c<br>
&gt; index c8f6ad79e3c..d2bc6277613 100644<br>
&gt; --- a/block/ssh.c<br>
&gt; +++ b/block/ssh.c<br>
&gt; @@ -180,9 +180,37 @@ static void sftp_error_trace(BDRVSSHState *s, const char *op)<br>
&gt;  <br>
&gt;  static int parse_uri(const char *filename, QDict *options, Error **errp)<br>
&gt;  {<br>
&gt; +    g_autofree char *port_str = NULL;<br>
&gt; +    const char *scheme, *server, *path, *user, *key, *value;<br>
&gt; +    gint port;<br>
&gt; +<br>
&gt; +#ifdef HAVE_GLIB_GURI<br>
&gt; +    g_autoptr(GUri) uri = NULL;<br>
&gt; +    g_autoptr(GHashTable) params = NULL;<br>
&gt; +    g_autoptr(GError) err = NULL;<br>
&gt; +    GHashTableIter iter;<br>
&gt; +<br>
&gt; +    uri = g_uri_parse(filename, G_URI_FLAGS_ENCODED_QUERY, &amp;err);<br>
&gt; +    if (!uri) {<br>
&gt; +        error_setg(errp, &quot;Failed to parse SSH URI: %s&quot;, err-&gt;message);<br>
&gt; +        return -EINVAL;<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    params = g_uri_parse_params(g_uri_get_query(uri), -1,<br>
&gt; +                                &quot;&amp;;&quot;, G_URI_PARAMS_NONE, &amp;err);<br>
&gt; +    if (err) {<br>
&gt; +        error_report(&quot;Failed to parse SSH URI query: %s&quot;, err-&gt;message);<br>
&gt; +        return -EINVAL;<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    scheme = g_uri_get_scheme(uri);<br>
&gt; +    user = g_uri_get_user(uri);<br>
&gt; +    server = g_uri_get_host(uri);<br>
&gt; +    path = g_uri_get_path(uri);<br>
&gt; +    port = g_uri_get_port(uri);<br>
&gt; +#else<br>
&gt;      g_autoptr(URI) uri = NULL;<br>
&gt;      g_autoptr(QueryParams) qp = NULL;<br>
&gt; -    g_autofree char *port_str = NULL;<br>
&gt;      int i;<br>
<br>
As Dan said already, this conditional code looks horrible and is going<br>
to be a maintenance burden.  Was there a later version of this patch<br>
series that resolved this?  I don&#39;t think I saw one.<br></blockquote><div><br></div><div>The patch is quite experimental. glib didn&#39;t even yet receive a release with GUri! But since I am working on the glib side, I wanted to make sure it covers qemu needs.</div><div><br></div><div>I will revisit the series once GUri is frozen &amp; released (in mid-september),and use a copy version fallback.</div><div><br></div><div>Although, as I said in the cover, this is a bit riskier than having a transition period with both the old libxml-based parser and glib-based one for very recent distro.<br></div><div><br></div><div>Tbh, I think having both is not a big burden, because there is very low activity around those functions. Iow, we are not spreading qemu with a lot of extra conditionals, but only in very limited mostly static places.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Rich.<br>
<br>
<br>
&gt;      uri = uri_parse(filename);<br>
&gt; @@ -190,44 +218,57 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)<br>
&gt;          return -EINVAL;<br>
&gt;      }<br>
&gt;  <br>
&gt; -    if (g_strcmp0(uri-&gt;scheme, &quot;ssh&quot;) != 0) {<br>
&gt; -        error_setg(errp, &quot;URI scheme must be &#39;ssh&#39;&quot;);<br>
&gt; +    qp = query_params_parse(uri-&gt;query);<br>
&gt; +    if (!qp) {<br>
&gt; +        error_setg(errp, &quot;could not parse query parameters&quot;);<br>
&gt;          return -EINVAL;<br>
&gt;      }<br>
&gt;  <br>
&gt; -    if (!uri-&gt;server || strcmp(uri-&gt;server, &quot;&quot;) == 0) {<br>
&gt; -        error_setg(errp, &quot;missing hostname in URI&quot;);<br>
&gt; +    scheme = uri-&gt;scheme;<br>
&gt; +    user = uri-&gt;user;<br>
&gt; +    server = uri-&gt;server;<br>
&gt; +    path = uri-&gt;path;<br>
&gt; +    port = uri-&gt;port;<br>
&gt; +#endif<br>
&gt; +    if (g_strcmp0(scheme, &quot;ssh&quot;) != 0) {<br>
&gt; +        error_setg(errp, &quot;URI scheme must be &#39;ssh&#39;&quot;);<br>
&gt;          return -EINVAL;<br>
&gt;      }<br>
&gt;  <br>
&gt; -    if (!uri-&gt;path || strcmp(uri-&gt;path, &quot;&quot;) == 0) {<br>
&gt; -        error_setg(errp, &quot;missing remote path in URI&quot;);<br>
&gt; +    if (!server || strcmp(server, &quot;&quot;) == 0) {<br>
&gt; +        error_setg(errp, &quot;missing hostname in URI&quot;);<br>
&gt;          return -EINVAL;<br>
&gt;      }<br>
&gt;  <br>
&gt; -    qp = query_params_parse(uri-&gt;query);<br>
&gt; -    if (!qp) {<br>
&gt; -        error_setg(errp, &quot;could not parse query parameters&quot;);<br>
&gt; +    if (!path || strcmp(path, &quot;&quot;) == 0) {<br>
&gt; +        error_setg(errp, &quot;missing remote path in URI&quot;);<br>
&gt;          return -EINVAL;<br>
&gt;      }<br>
&gt;  <br>
&gt; -    if(uri-&gt;user &amp;&amp; strcmp(uri-&gt;user, &quot;&quot;) != 0) {<br>
&gt; -        qdict_put_str(options, &quot;user&quot;, uri-&gt;user);<br>
&gt; +    if (user &amp;&amp; strcmp(user, &quot;&quot;) != 0) {<br>
&gt; +        qdict_put_str(options, &quot;user&quot;, user);<br>
&gt;      }<br>
&gt;  <br>
&gt; -    qdict_put_str(options, &quot;server.host&quot;, uri-&gt;server);<br>
&gt; +    qdict_put_str(options, &quot;server.host&quot;, server);<br>
&gt;  <br>
&gt; -    port_str = g_strdup_printf(&quot;%d&quot;, uri-&gt;port ?: 22);<br>
&gt; +    port_str = g_strdup_printf(&quot;%d&quot;, port ?: 22);<br>
&gt;      qdict_put_str(options, &quot;server.port&quot;, port_str);<br>
&gt;  <br>
&gt; -    qdict_put_str(options, &quot;path&quot;, uri-&gt;path);<br>
&gt; +    qdict_put_str(options, &quot;path&quot;, path);<br>
&gt;  <br>
&gt;      /* Pick out any query parameters that we understand, and ignore<br>
&gt;       * the rest.<br>
&gt;       */<br>
&gt; +#ifdef HAVE_GLIB_GURI<br>
&gt; +    g_hash_table_iter_init(&amp;iter, params);<br>
&gt; +    while (g_hash_table_iter_next(&amp;iter, (void **)&amp;key, (void **)&amp;value)) {<br>
&gt; +#else<br>
&gt;      for (i = 0; i &lt; qp-&gt;n; ++i) {<br>
&gt; -        if (strcmp(qp-&gt;p[i].name, &quot;host_key_check&quot;) == 0) {<br>
&gt; -            qdict_put_str(options, &quot;host_key_check&quot;, qp-&gt;p[i].value);<br>
&gt; +        key = qp-&gt;p[i].name;<br>
&gt; +        value = qp-&gt;p[i].value;<br>
&gt; +#endif<br>
&gt; +        if (g_strcmp0(key, &quot;host_key_check&quot;) == 0) {<br>
&gt; +            qdict_put_str(options, &quot;host_key_check&quot;, value);<br>
&gt;          }<br>
&gt;      }<br>
&gt;  <br>
&gt; -- <br>
&gt; 2.27.0.221.ga08a83db2b<br>
<br>
-- <br>
Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones</a><br>
Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
libguestfs lets you edit virtual machines.  Supports shell scripting,<br>
bindings from many languages.  <a href="http://libguestfs.org" rel="noreferrer" target="_blank">http://libguestfs.org</a><br>
<br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Marc-André Lureau<br></div></div>