Re: [Bug debuginfod/27277] Describe retrieved files when verbose

2022-07-14 Thread Noah Sanci via Elfutils-devel
Hello,

Please find the patch for pr28284 attached

Debuginfod and debuginfod clients are now equipped to send
and receive http headers prefixed with X-DEBUGINFOD and
print them in verbose mode for more context

Noah Sanci
From 2d4902ca53b80b5cd5689a1ba77e4465c33fea64 Mon Sep 17 00:00:00 2001
From: Noah Sanci 
Date: Wed, 15 Jun 2022 10:07:29 -0400
Subject: [PATCH] PR28284 - Debuginfod header functionality implemented

---
 debuginfod/debuginfod-client.c   | 14 ++-
 debuginfod/debuginfod-find.c |  3 ++
 debuginfod/debuginfod.cxx| 18 +
 debuginfod/debuginfod.h.in   |  4 ++
 debuginfod/libdebuginfod.map |  3 ++
 doc/debuginfod_find_debuginfo.3  | 13 +++
 doc/debuginfod_get_headers.3 |  2 +
 tests/run-debuginfod-response-headers.sh | 48 +---
 8 files changed, 97 insertions(+), 8 deletions(-)
 create mode 100644 doc/debuginfod_get_headers.3

diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index b7b65aff..a3565f57 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -501,6 +501,12 @@ header_callback (char * buffer, size_t size, size_t numitems, void * userdata)
 {
   if (size != 1)
 return 0;
+  // X-DEBUGINFOD is 11 characters long.
+  // Some basic checks to ensure the headers received are of the expected format
+  if ( strncmp(buffer, "X-DEBUGINFOD", 11) || buffer[numitems-1] != '\n'
+   || (buffer == strstr(buffer, ":")) ){
+return numitems;
+  }
   /* Temporary buffer for realloc */
   char *temp = NULL;
   struct handle_data *data = (struct handle_data *) userdata;
@@ -,8 +1117,6 @@ debuginfod_query_server (debuginfod_client *c,
 if (c->winning_headers == NULL)
   {
 c->winning_headers = data[committed_to].response_data;
-if (vfd >= 0 && c->winning_headers != NULL)
-  dprintf(vfd, "\n%s", c->winning_headers);
 data[committed_to].response_data = NULL;
 data[committed_to].response_data_size = 0;
   }
@@ -1542,6 +1546,12 @@ debuginfod_get_url(debuginfod_client *client)
   return client->url;
 }
 
+const char *
+debuginfod_get_headers(debuginfod_client *client)
+{
+  return client->winning_headers;
+}
+
 void
 debuginfod_end (debuginfod_client *client)
 {
diff --git a/debuginfod/debuginfod-find.c b/debuginfod/debuginfod-find.c
index f60b5463..fb1f294c 100644
--- a/debuginfod/debuginfod-find.c
+++ b/debuginfod/debuginfod-find.c
@@ -215,6 +215,9 @@ main(int argc, char** argv)
 
   if (verbose)
 {
+  const char* headers = debuginfod_get_headers(client);
+  if (headers)
+fprintf(stderr, "Headers:\n%s", headers);
   const char* url = debuginfod_get_url (client);
   if (url != NULL)
 fprintf(stderr, "Downloaded from %s\n", url);
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 51f4302b..d64c5965 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -2085,6 +2085,24 @@ and will not query the upstream servers");
 {
   add_mhd_response_header (r, "Content-Type",
    "application/octet-stream");
+  const char * hdrs = debuginfod_get_headers(client);
+  string header_dup;
+  if (hdrs)
+header_dup = string(hdrs);
+  size_t pos = 0;
+  // Clean winning headers to add all X-DEBUGINFOD lines to the package we'll send
+  while( (pos = header_dup.find("X-DEBUGINFOD")) != string::npos)
+{
+  // Focus on where X-DEBUGINFOD- begins
+  header_dup = header_dup.substr(pos);
+  size_t newline =  header_dup.find('\n');
+  if (newline == string::npos)
+break;
+  add_mhd_response_header(r, header_dup.substr(0,header_dup.find(':')).c_str(),
+ header_dup.substr(header_dup.find(':')).c_str());
+  header_dup = header_dup.substr(newline);
+}
+
   add_mhd_last_modified (r, s.st_mtime);
   if (verbose > 1)
 obatched(clog) << "serving file from upstream debuginfod/cache" << endl;
diff --git a/debuginfod/debuginfod.h.in b/debuginfod/debuginfod.h.in
index c358df4d..6ae8b91c 100644
--- a/debuginfod/debuginfod.h.in
+++ b/debuginfod/debuginfod.h.in
@@ -93,6 +93,10 @@ void* debuginfod_get_user_data (debuginfod_client *client);
 /* Get the current or last active URL, if known.  */
 const char* debuginfod_get_url (debuginfod_client *client);
 
+/* Returns all headers sent to this client which were prefixed
+ * with X-DEBUGINFOD */
+const char* debuginfod_get_headers(debuginfod_client *client);
+
 /* Add an outgoing HTTP request  "Header: Value".  Copies string.  */
 int debuginfod_ad

[Bug debuginfod/27918] add control file for triggered traversal

2022-07-14 Thread nsanci at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=27918

Noah Sanci  changed:

   What|Removed |Added

 CC||nsanci at redhat dot com
   Assignee|unassigned at sourceware dot org   |nsanci at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug debuginfod/25607] debuginfod-client: paranoid federation mode

2022-07-14 Thread nsanci at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=25607

Noah Sanci  changed:

   What|Removed |Added

   Assignee|unassigned at sourceware dot org   |nsanci at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug debuginfod/27918] add control file for triggered traversal

2022-07-14 Thread nsanci at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=27918

Noah Sanci  changed:

   What|Removed |Added

   Assignee|nsanci at redhat dot com   |unassigned at 
sourceware dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug debuginfod/28204] extend webapi / verification with forthcoming signed-contents archives

2022-07-14 Thread fche at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28204

Frank Ch. Eigler  changed:

   What|Removed |Added

   Assignee|unassigned at sourceware dot org   |rgoldber at redhat dot 
com

-- 
You are receiving this mail because:
You are on the CC list for the bug.