public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] debuginfod: DEBUGINFOD_URLS should accept scheme-free urls
@ 2020-07-03 17:37 Alice Zhang
  2020-07-05 15:04 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Alice Zhang @ 2020-07-03 17:37 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Alice Zhang

Check scheme instead of effective url so that user may abbreviate
DEBUGINFOD_URL. Add one test for scheme free http url.

Notice that libcurl does not provide an almighty scheme free url
support, /path/to/something without FILE:// can not be recognized
in most circumstances, therefore for the neatness of our code
structure, DEBUGINFOD_ URL of scheme "FILE" must be input as URI.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
---
 debuginfod/debuginfod-client.c | 33 ++++++++++++++++++++++++++++-----
 tests/run-debuginfod-find.sh   |  6 ++++++
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index c2aa4e10..15e2db26 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -722,7 +722,6 @@ debuginfod_query_server (debuginfod_client *c,
       else
         snprintf(data[i].url, PATH_MAX, "%s%s/%s/%s", server_url,
                  slashbuildid, build_id_bytes, type);
-
       curl_easy_setopt(data[i].handle, CURLOPT_URL, data[i].url);
       curl_easy_setopt(data[i].handle,
                        CURLOPT_WRITEFUNCTION,
@@ -870,26 +869,50 @@ debuginfod_query_server (debuginfod_client *c,
                   char *effective_url = NULL;
                   long resp_code = 500;
                   CURLcode ok1 = curl_easy_getinfo (target_handle,
-						    CURLINFO_EFFECTIVE_URL,
-						    &effective_url);
+                                                    CURLINFO_EFFECTIVE_URL,
+                                                    &effective_url);
                   CURLcode ok2 = curl_easy_getinfo (target_handle,
 						    CURLINFO_RESPONSE_CODE,
 						    &resp_code);
                   if(ok1 == CURLE_OK && ok2 == CURLE_OK && effective_url)
                     {
-                      if (strncmp (effective_url, "http", 4) == 0)
+                      if (strncasecmp (effective_url, "HTTP", 4) == 0)
                         if (resp_code == 200)
                           {
                             verified_handle = msg->easy_handle;
                             break;
                           }
-                      if (strncmp (effective_url, "file", 4) == 0)
+                      if (strncasecmp (effective_url, "FILE", 4) == 0)
                         if (resp_code == 0)
                           {
                             verified_handle = msg->easy_handle;
                             break;
                           }
                     }
+		  /* - libcurl since 7.52.0 version start to support CURLINFO_SCHEME;
+		   * - before 7.61.0, effective_url would give us a url with upper 
+		   *   case SCHEME added in the front;
+		   * - effective_url between 7.61 and 7.69 can be lack of scheme if the 
+		   *   original url doesn't include one; 
+		   * - since version 7.69 effective_url will be provide a scheme in lower
+		   *   case.*/
+                  #if LIBCURL_VERSION_NUM >= 0x073d00 /* 7.61.0 */
+                  #if LIBCURL_VERSION_NUM <= 0x074500 /* 7.69.0 */
+                  char *scheme = NULL;
+                  CURLcode ok3 = curl_easy_getinfo (target_handle,
+                                                    CURLINFO_SCHEME,
+                                                    &scheme);
+                  if(ok3 == CURLE_OK && scheme)
+                    {
+                      if (strncmp (scheme, "HTTP", 4) == 0)
+                        if (resp_code == 200)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                    }
+                  #endif
+                  #endif
                 }
             }
         }
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index f0c77c51..730bb0e1 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -413,6 +413,12 @@ testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && fal
 export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
 testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
 
+# test again with scheme free url
+export DEBUGINFOD_URLS=127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+export DEBUGINFOD_URLS=127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
 
 # test parallel queries in client
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
-- 
2.25.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] debuginfod: DEBUGINFOD_URLS should accept scheme-free urls
  2020-07-03 17:37 [PATCH] debuginfod: DEBUGINFOD_URLS should accept scheme-free urls Alice Zhang
@ 2020-07-05 15:04 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2020-07-05 15:04 UTC (permalink / raw)
  To: Alice Zhang, elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

Hi Alice,

On Fri, 2020-07-03 at 13:37 -0400, Alice Zhang via Elfutils-devel
wrote:
> Check scheme instead of effective url so that user may abbreviate
> DEBUGINFOD_URL. Add one test for scheme free http url.
> 
> Notice that libcurl does not provide an almighty scheme free url
> support, /path/to/something without FILE:// can not be recognized
> in most circumstances, therefore for the neatness of our code
> structure, DEBUGINFOD_ URL of scheme "FILE" must be input as URI.

Thanks, this looks good, and seems to work against all the various
libcurl versions we support. I did make some whitespace changes and
added ChangeLog entries as attached.

Pushed to master.

Thanks,

Mark


[-- Attachment #2: 0001-debuginfod-DEBUGINFOD_URLS-should-accept-scheme-free.patch --]
[-- Type: text/x-patch, Size: 4974 bytes --]

From 8de6f9af46f12fe3b2a0871523f6df13c4b39e34 Mon Sep 17 00:00:00 2001
From: Alice Zhang <alizhang@redhat.com>
Date: Fri, 3 Jul 2020 13:37:34 -0400
Subject: [PATCH] debuginfod: DEBUGINFOD_URLS should accept scheme-free urls

Check scheme instead of effective url so that user may abbreviate
DEBUGINFOD_URL. Add one test for scheme free http url.

Notice that libcurl does not provide an almighty scheme free url
support, /path/to/something without FILE:// can not be recognized
in most circumstances, therefore for the neatness of our code
structure, DEBUGINFOD_ URL of scheme "FILE" must be input as URI.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
---
 debuginfod/ChangeLog           |  5 +++++
 debuginfod/debuginfod-client.c | 29 +++++++++++++++++++++++++++--
 tests/ChangeLog                |  4 ++++
 tests/run-debuginfod-find.sh   |  6 ++++++
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 372173e7..db8a76a7 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2020-07-03  Alice Zhang <alizhang@redhat.com>
+
+	* debuginfod-client.c (debuginfod_query_server): Use strncasecmp
+	to compare effective_url. Try CURLINFO_SCHEME as fallback.
+
 2020-06-19  Mark Wielaard  <mark@klomp.org>
 
 	* Makefile.am (bin_PROGRAMS): Guard with DEBUGINFOD and
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index c2e43f74..18e7b85f 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -899,19 +899,44 @@ debuginfod_query_server (debuginfod_client *c,
 						    &resp_code);
                   if(ok1 == CURLE_OK && ok2 == CURLE_OK && effective_url)
                     {
-                      if (strncmp (effective_url, "http", 4) == 0)
+                      if (strncasecmp (effective_url, "HTTP", 4) == 0)
                         if (resp_code == 200)
                           {
                             verified_handle = msg->easy_handle;
                             break;
                           }
-                      if (strncmp (effective_url, "file", 4) == 0)
+                      if (strncasecmp (effective_url, "FILE", 4) == 0)
                         if (resp_code == 0)
                           {
                             verified_handle = msg->easy_handle;
                             break;
                           }
                     }
+                  /* - libcurl since 7.52.0 version start to support
+                       CURLINFO_SCHEME;
+                     - before 7.61.0, effective_url would give us a
+                       url with upper case SCHEME added in the front;
+                     - effective_url between 7.61 and 7.69 can be lack
+                       of scheme if the original url doesn't include one;
+                     - since version 7.69 effective_url will be provide
+                       a scheme in lower case.  */
+                  #if LIBCURL_VERSION_NUM >= 0x073d00 /* 7.61.0 */
+                  #if LIBCURL_VERSION_NUM <= 0x074500 /* 7.69.0 */
+                  char *scheme = NULL;
+                  CURLcode ok3 = curl_easy_getinfo (target_handle,
+                                                    CURLINFO_SCHEME,
+                                                    &scheme);
+                  if(ok3 == CURLE_OK && scheme)
+                    {
+                      if (strncmp (scheme, "HTTP", 4) == 0)
+                        if (resp_code == 200)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                    }
+                  #endif
+                  #endif
                 }
             }
         }
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b27037ee..7cb4123a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2020-07-03  Alice Zhang  <alizhang@redhat.com>
+
+	* run-debuginfod-find.sh: Add scheme free url testcase.
+
 2020-06-19  Mark Wielaard  <mark@klomp.org>
 
 	* Makefile.am (TESTS): Don't add run-debuginfod-find.sh when
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index f0c77c51..730bb0e1 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -413,6 +413,12 @@ testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && fal
 export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
 testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
 
+# test again with scheme free url
+export DEBUGINFOD_URLS=127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+export DEBUGINFOD_URLS=127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
 
 # test parallel queries in client
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
-- 
2.18.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-05 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 17:37 [PATCH] debuginfod: DEBUGINFOD_URLS should accept scheme-free urls Alice Zhang
2020-07-05 15:04 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).