From: Paul Davis Date: Sat, 2 Jun 2018 17:24:17 +0000 (-0400) Subject: no error logging for CURL HTTP requests; future callers can request it if necessary X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=f448041ec0a6ce5caead0829f309a06cabcdd156;p=ardour.git no error logging for CURL HTTP requests; future callers can request it if necessary --- diff --git a/gtk2_ardour/add_video_dialog.cc b/gtk2_ardour/add_video_dialog.cc index 2e092bb4da..5c0db1ff26 100644 --- a/gtk2_ardour/add_video_dialog.cc +++ b/gtk2_ardour/add_video_dialog.cc @@ -519,7 +519,7 @@ AddVideoDialog::harvid_request(std::string u) harvid_list->clear(); - char* res = ArdourCurl::http_get (url, &status); + char* res = ArdourCurl::http_get (url, &status, false); if (status != 200) { printf("request failed\n"); // XXX harvid_path.set_text(" - request failed -"); @@ -699,7 +699,7 @@ AddVideoDialog::request_preview(std::string u) , (long long) (video_duration * seek_slider.get_value() / 1000.0) , clip_width, clip_height, u.c_str()); - char* data = ArdourCurl::http_get (url, NULL); + char* data = ArdourCurl::http_get (url, NULL, false); if (!data) { printf("image preview request failed %s\n", url); imgbuf->fill(RGBA_TO_UINT(0,0,0,255)); diff --git a/gtk2_ardour/ardour_http.cc b/gtk2_ardour/ardour_http.cc index a67522d90d..05e23b32d4 100644 --- a/gtk2_ardour/ardour_http.cc +++ b/gtk2_ardour/ardour_http.cc @@ -179,13 +179,16 @@ HttpGet::~HttpGet () } char* -HttpGet::get (const char* url) +HttpGet::get (const char* url, bool with_error_logging) { #ifdef ARDOURCURLDEBUG - std::cerr << "HttpGet::get() ---- new request ---"<< std::endl; + std::cerr << "HttpGet::get() ---- new request ---"<< std::endl; #endif _status = _result = -1; if (!_curl || !url) { + if (with_error_logging) { + PBD::error << "HttpGet::get() not initialized (or NULL url)"<< endmsg; + } #ifdef ARDOURCURLDEBUG std::cerr << "HttpGet::get() not initialized (or NULL url)"<< std::endl; #endif @@ -193,6 +196,9 @@ HttpGet::get (const char* url) } if (strncmp ("http://", url, 7) && strncmp ("https://", url, 8)) { + if (with_error_logging) { + PBD::error << "HttpGet::get() not a http[s] URL"<< endmsg; + } #ifdef ARDOURCURLDEBUG std::cerr << "HttpGet::get() not a http[s] URL"<< std::endl; #endif @@ -216,12 +222,18 @@ HttpGet::get (const char* url) CCERR ("CURLINFO_RESPONSE_CODE,"); if (_result) { + if (with_error_logging) { + PBD::error << string_compose (_("HTTP request failed: (%1) %2"), _result, error_buffer) << endmsg; + } #ifdef ARDOURCURLDEBUG std::cerr << string_compose (_("HTTP request failed: (%1) %2"), _result, error_buffer) << std::endl; #endif return NULL; } if (_status != 200) { + if (with_error_logging) { + PBD::error << string_compose (_("HTTP request status: %1"), _status) << endmsg; + } #ifdef ARDOURCURLDEBUG std::cerr << string_compose (_("HTTP request status: %1"), _status) << std::endl; #endif @@ -243,9 +255,9 @@ HttpGet::error () const { } char* -ArdourCurl::http_get (const char* url, int* status) { +ArdourCurl::http_get (const char* url, int* status, bool with_error_logging) { HttpGet h (true); - char* rv = h.get (url); + char* rv = h.get (url, with_error_logging); if (status) { *status = h.status (); } @@ -253,6 +265,6 @@ ArdourCurl::http_get (const char* url, int* status) { } std::string -ArdourCurl::http_get (const std::string& url) { - return HttpGet (false).get (url); +ArdourCurl::http_get (const std::string& url, bool with_error_logging) { + return HttpGet (false).get (url, with_error_logging); } diff --git a/gtk2_ardour/ardour_http.h b/gtk2_ardour/ardour_http.h index aa6b9f3936..41bb2a8f79 100644 --- a/gtk2_ardour/ardour_http.h +++ b/gtk2_ardour/ardour_http.h @@ -40,10 +40,10 @@ class HttpGet { std::map h; }; - char* get (const char* url); + char* get (const char* url, bool with_error_logging = false); - std::string get (const std::string& url) { - char *rv = get (url.c_str ()); + std::string get (const std::string& url, bool with_error_logging = false) { + char *rv = get (url.c_str (), with_error_logging); return rv ? std::string (rv) : std::string (""); } @@ -89,9 +89,14 @@ class HttpGet { static const char* ca_info; }; -char* http_get (const char* url, int* status); +char* http_get (const char* url, int* status, bool with_error_logging); +std::string http_get (const std::string& url, bool with_error_logging); + +/* For use from Lua scripts */ + +static char* http_get_unlogged (const char* url, int* status) { return http_get (url, status, false); } +static std::string http_get_unlogged (const std::string& url) { return http_get (url, false); } -std::string http_get (const std::string& url); } // namespace diff --git a/gtk2_ardour/luainstance.cc b/gtk2_ardour/luainstance.cc index 36436af285..8d1644276d 100644 --- a/gtk2_ardour/luainstance.cc +++ b/gtk2_ardour/luainstance.cc @@ -744,7 +744,7 @@ LuaInstance::register_classes (lua_State* L) luabridge::getGlobalNamespace (L) .beginNamespace ("ArdourUI") - .addFunction ("http_get", (std::string (*)(const std::string&))&ArdourCurl::http_get) + .addFunction ("http_get", (std::string (*)(const std::string&))&ArdourCurl::http_get_unlogged) .addFunction ("processor_selection", &LuaMixer::processor_selection) diff --git a/gtk2_ardour/luawindow.cc b/gtk2_ardour/luawindow.cc index d385b8e3c1..59ba451c6d 100644 --- a/gtk2_ardour/luawindow.cc +++ b/gtk2_ardour/luawindow.cc @@ -417,7 +417,7 @@ LuaWindow::import_script () // TODO convert a few URL (eg. pastebin) to raw. #if 0 char *url = "http://pastebin.com/raw/3UMkZ6nV"; - char *rv = ArdourCurl::http_get (url, 0); + char *rv = ArdourCurl::http_get (url, 0. true); if (rv) { new_script (); Glib::RefPtr tb (entry.get_buffer()); diff --git a/gtk2_ardour/pingback.cc b/gtk2_ardour/pingback.cc index e641fbd900..5e747bb433 100644 --- a/gtk2_ardour/pingback.cc +++ b/gtk2_ardour/pingback.cc @@ -172,7 +172,7 @@ _pingback (void *arg) #endif /* PLATFORM_WINDOWS */ - return_str = h.get (url); + return_str = h.get (url, false); if (!return_str.empty ()) { if ( return_str.length() > 140 ) { // like a tweet :) diff --git a/gtk2_ardour/utils_videotl.cc b/gtk2_ardour/utils_videotl.cc index b6eace7675..11b7230dde 100644 --- a/gtk2_ardour/utils_videotl.cc +++ b/gtk2_ardour/utils_videotl.cc @@ -273,7 +273,7 @@ VideoUtils::video_query_info ( , video_server_url.c_str() , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/" , filepath.c_str()); - std::string res = ArdourCurl::http_get (url); + std::string res = ArdourCurl::http_get (url, false); if (res.empty ()) { return false; } diff --git a/gtk2_ardour/video_image_frame.cc b/gtk2_ardour/video_image_frame.cc index 5d0aea3407..2473da0b4e 100644 --- a/gtk2_ardour/video_image_frame.cc +++ b/gtk2_ardour/video_image_frame.cc @@ -210,7 +210,7 @@ http_get_thread (void *arg) { int timeout = 1000; // * 5ms -> 5sec char *res = NULL; do { - res = ArdourCurl::http_get (url, &status); + res = ArdourCurl::http_get (url, &status, false); if (status == 503) Glib::usleep(5000); // try-again } while (status == 503 && --timeout > 0); diff --git a/gtk2_ardour/video_timeline.cc b/gtk2_ardour/video_timeline.cc index 0c5b080124..f16aea8dfa 100644 --- a/gtk2_ardour/video_timeline.cc +++ b/gtk2_ardour/video_timeline.cc @@ -544,7 +544,7 @@ VideoTimeLine::check_server () , video_server_url.c_str() , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/" ); - char* res = ArdourCurl::http_get (url, NULL); + char* res = ArdourCurl::http_get (url, NULL, false); if (res) { if (strstr(res, "status: ok, online.")) { ok = true; } free(res); @@ -566,7 +566,7 @@ VideoTimeLine::check_server_docroot () , video_server_url.c_str() , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/" ); - char* res = ArdourCurl::http_get (url, NULL); + char* res = ArdourCurl::http_get (url, NULL, false); if (!res) { return false; } @@ -662,7 +662,7 @@ VideoTimeLine::flush_cache () { , video_server_url.c_str() , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/" ); - char* res = ArdourCurl::http_get (url, NULL); + char* res = ArdourCurl::http_get (url, NULL, false); if (res) { free (res); }