diff options
author | Noah Sanci <nsanci@redhat.com> | 2022-06-15 10:07:29 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@redhat.com> | 2022-09-06 11:32:13 -0400 |
commit | bbc2ca6d553f0ce3e670303ac9a3c764cf10d779 (patch) | |
tree | b08f81afb310c8c46cffdbeeb8e7881f7401573f /debuginfod | |
parent | a176b6e30aa8983c95b81f18c34a2b5c6a0c907b (diff) | |
download | elfutils-bbc2ca6d553f0ce3e670303ac9a3c764cf10d779.tar.gz |
PR28284 - Debuginfod header functionality implemented
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
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Diffstat (limited to 'debuginfod')
-rw-r--r-- | debuginfod/ChangeLog | 14 | ||||
-rw-r--r-- | debuginfod/debuginfod-client.c | 14 | ||||
-rw-r--r-- | debuginfod/debuginfod-find.c | 3 | ||||
-rw-r--r-- | debuginfod/debuginfod.cxx | 18 | ||||
-rw-r--r-- | debuginfod/debuginfod.h.in | 4 | ||||
-rw-r--r-- | debuginfod/libdebuginfod.map | 3 |
6 files changed, 54 insertions, 2 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index c692a389..8c843f3a 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,17 @@ +2022-07-15 Noah Sanci <nsanci@redhat.com> + + * debuginfod-client.c (header_callback): Handle headers without + X-DEBUGINFOD prefix. + (debuginfod_query_server): Removed verbose printing headers when + undesired. + (debuginfod_get_headers): Created. + * debuginfod-find.c (main): Verboes printing headers. + * debuginfod.cxx (handle_buildid): Add headers prefixed with + X-DEBUGINFOD from federated servers to this server's response + headers. + * debuginfod.h.in (debuginfod_get_headers): Created. + * libdebuginfod.map: New elfutils version added. + 2022-09-02 Aaron Merey <amerey@redhat.com> * debuginfod.cxx (parse_opt): If '-C' is given with no arg, do not 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; @@ -1111,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 8680c048..27b671d3 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -2093,6 +2093,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_add_http_header (debuginfod_client *client, const char* header); diff --git a/debuginfod/libdebuginfod.map b/debuginfod/libdebuginfod.map index 7d2f5882..f95b5b9a 100644 --- a/debuginfod/libdebuginfod.map +++ b/debuginfod/libdebuginfod.map @@ -18,3 +18,6 @@ ELFUTILS_0.179 { ELFUTILS_0.183 { debuginfod_set_verbose_fd; } ELFUTILS_0.179; +ELFUTILS_0.189 { + debuginfod_get_headers; +} ELFUTILS_0.183; |