From 82191ce7ff4f8e5287be80b1901949f5e6f79c5d Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 5 Apr 2018 10:55:31 -0500 Subject: [PATCH] The http client code now asks the server to delete the build info. * client-http.cxx (http_client_backend::delete_op): Send a delete request to the server. (http_client_backend::unpack_response): After downloading everything, call delete_op(). * httpd/api.cxx (individual_build_rh::DELETE): New function. --- client-http.cxx | 33 +++++++++++++++++++++++++++++++++ httpd/api.cxx | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/client-http.cxx b/client-http.cxx index 13664a925..c2349f3d0 100644 --- a/client-http.cxx +++ b/client-http.cxx @@ -71,6 +71,7 @@ public: void get_kernel_buildid (void); long get_response_code (void); static int trace (CURL *, curl_infotype type, unsigned char *data, size_t size, void *); + bool delete_op (const std::string & url); private: size_t get_header (void *ptr, size_t size, size_t nitems); @@ -744,6 +745,35 @@ http_client::add_module (std::string module) } +// Ask the server to delete a URL. + +bool +http_client::delete_op (const std::string & url) +{ + if (curl) + curl_easy_reset (curl); + curl = curl_easy_init (); + curl_global_init (CURL_GLOBAL_ALL); + if (s.verbose > 2) + { + curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, trace); + } + curl_easy_setopt (curl, CURLOPT_URL, url.c_str ()); + curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); //Prevent "longjmp causes uninitialized stack frame" bug + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + + CURLcode res = curl_easy_perform (curl); + if (res != CURLE_OK) + { + clog << "curl_easy_perform() failed: " << curl_easy_strerror (res) + << endl; + return false; + } + return true; +} + + http_client_backend::http_client_backend (systemtap_session &s) : client_backend(s), files_seen(false) { @@ -1059,6 +1089,9 @@ http_client_backend::unpack_response () clog << "Couldn't find 'stdout' in JSON results data" << endl; return 1; } + + // Tell the server to delete this build (and any associated result). + http->delete_op (build_uri); return 0; } diff --git a/httpd/api.cxx b/httpd/api.cxx index 63fb852cc..e4400825b 100644 --- a/httpd/api.cxx +++ b/httpd/api.cxx @@ -480,6 +480,7 @@ public: individual_build_rh(string n) : request_handler(n) {} response GET(const request &req); + response DELETE(const request &req); }; response individual_build_rh::GET(const request &req) @@ -512,6 +513,37 @@ response individual_build_rh::GET(const request &req) return rsp; } +response individual_build_rh::DELETE(const request &req) +{ + // matches[0] is the entire string '/builds/XXXX'. matches[1] is + // just the buildid 'XXXX'. + string buildid = req.matches[1]; + build_info *b = NULL; + { + // Use a lock_guard to ensure the mutex gets released even if an + // exception is thrown. + lock_guard lock(builds_mutex); + for (auto it = build_infos.begin(); it != build_infos.end(); it++) { + if (buildid == (*it)->get_uuid_str()) { + b = *it; + build_infos.erase(it); + break; + } + } + } + + if (b == NULL) { + server_error(_F("Couldn't find build '%s'", buildid.c_str())); + return get_404_response(); + } + + // At this point we've found a matching build. Delete it. + delete b; + response rsp(300); + rsp.content = ""; + return rsp; +} + class individual_result_rh : public request_handler { public: -- 2.43.5